akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

int n, a[300005];
ll sum = 0;

int main() {
	//file_put();

	scanf("%d", &n);
	for (int i = 1; i <= 3 * n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + 3 * n + 1);
	for (int i = n + 1, j = 1; j <= n; j++, i += 2) sum += a[i];
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m), y(m);
    rep(i, 0, m){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    vector<int> d(n, 1);
    vector<bool> f(n, false);
    f[0] = true;
    rep(i, 0, m){
        if(f[x[i]]){
            if(d[x[i]] == 1) f[x[i]] = false;
            f[y[i]] = true;
        }
        d[x[i]]--;
        d[y[i]]++;
    }
    int ans = 0;
    rep(i, 0, n) if(f[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i, x, a[100000], m;
    long long sum=0;
    scanf("%d %d", &n, &x);
    for(i=0;i<n;i++)
        scanf(" %d", &a[i]);
    if(a[0] > x)
    {
        sum = a[0] - x;
        a[0] = x;
    }
    for(i=1;i<n;i++)
    {
        if(a[i] + a[i-1] > x)
        {
            m = a[i] + a[i-1] - x;
            a[i] -= m;
            sum += m;
        }
    }
    printf("%lld", sum);


    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

int n,m;
int dt[11][11];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    while(scanf("%d %d",&n,&m)&&n*m!=0)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                scanf("%d",&dt[i][j]);
            }
        }

        int ans=0;
        for(int i=1;i+2<=n;i++)//行
        {
            for(int j=1;j+2<=m;j++)//列
            {
                for(int k=i+2;k<=n;k++)//行
                {
                    for(int t=j+2;t<=m;t++)//列
                    {
                        int mn=100;
                        for(int t1=j;t1<=t;t1++)
                            mn=min(mn,min(dt[i][t1],dt[k][t1]));
                        for(int t1=i;t1<=k;t1++)
                            mn=min(mn,min(dt[t1][j],dt[t1][t]));

                        bool flag=false;
                        int tmp=0;
                        for(int t1=i+1;t1<=k-1;t1++)
                        {
                            for(int t2=j+1;t2<=t-1;t2++)
                            {
                                if(dt[t1][t2]>=mn)
                                {
                                    tmp=0;
                                    flag=true;
                                    break;
                                }
                                else
                                    tmp+=mn-dt[t1][t2];
                            }
                            if(flag)
                                break;
                        }
                        ans=max(ans,tmp);
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3192
#include<iostream>
using namespace std;

int main(void)
{
    int n, m, tmp;
    int a[100];
    cin >> n >> m;
    
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        a[i] = tmp;
        sum += tmp;
    }
    int count = 0;
    for (int i = 0; i < n; i++)
        if (sum <= 4 * m * a[i]) count++;
        
    if (count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def count_f(n):
    ret = 0
    for i in range(1, n + 1):
        if n % i == 0:
            ret += 1
    return ret

def solve(N: int):
    ret = 0
    for i in range(1, N + 1):
        if i % 2 == 1 and count_f(i) == 8:
            ret += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stack>
#include <time.h>
using namespace std;
typedef long long ll;
#define mem(x,y) memset(x,y,sizeof(x))

const int N=200000,M=25;
ll a[N];

int main(){
    int n;
    ll l=2,r=2;
    scanf("%d",&n);
    for (int i=1; i<=n; i++){
        scanf("%lld",&a[i]);
    }

    bool ok=true;
    for (int i=n; i>=1; i--){

        if (r>=a[i]){
            //cout<<r<<endl;
            //printf("ts %d %lld %lld\n",i,l,r);
            if (l % a[i]) l=l-(l%a[i])+a[i];
            r=r-(r%a[i])+(a[i]-1);
            //printf("ts %d %lld %lld\n",i,l,r);
            if (l>r){
                ok=false;
                break;
            }
        }else {
            ok=false;
            break;
        }
    }
    if  (ok) printf("%lld %lld\n",l,r);
    else printf("-1\n");

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
static const int MAX = 100000;
#define ROOT 0

vector<int> G[MAX];
bool visited[MAX];
int prenum[MAX];
int lowest[MAX];
int parents[MAX];
bool is_artpoint[MAX];
int NCHILD_ROOT = 0;

void visit(int n, int parent) {
  static int v = 0;
  visited[n] = true;
  prenum[n] = v++;
  parents[n] = parent;
}

void judge_parent(int n) {
  if (n != ROOT && parents[n] == ROOT)
    NCHILD_ROOT++;

  if (prenum[parents[n]] <= lowest[n])
    is_artpoint[parents[n]] = true;
}

int calc_lowest(int n, int childmin) {
  int l = min(childmin, prenum[n]);
  for (auto i : G[n]) {
    if (i != parents[n])
      l = min(l, prenum[i]);
  }
  return l;
}

int dfs(int n, int parent) {
  int childmin = MAX;
  visit(n, parent);
  for (auto i : G[n]) {
    if (!visited[i])
      childmin = min(childmin, dfs(i, n));
  }
  lowest[n] = calc_lowest(n, childmin);
  judge_parent(n);
  return lowest[n];
}

int main() {
  int nv, ne;
  cin >> nv >> ne;
  for (int i = 0; i < ne; i++) {
    int s, t;
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  for (int i = 0; i < nv; i++) {
    visited[i] = false;
    is_artpoint[i] = false;
  }

  dfs(ROOT, ROOT);

  is_artpoint[ROOT] = NCHILD_ROOT >= 2;

  for (int i = 0; i < nv; i++) {
    if (is_artpoint[i])
      cout << i << endl;
  }
}

Measured memory_bytes: 6672
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    using namespace std;
    const int N=100010;
    int fa[N],p[N],f[N],g[N];
    inline int gi() {
        int x=0,o=1;
        char ch=getchar();
        while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
        if(ch=='-') o=-1,ch=getchar();
        while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
        return x*o;
    }
    inline int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
    int main() {
        int n,m,ans=0;
        cin>>n>>m;
        for(int i=1;i<=n;i++) fa[i]=i,p[i]=gi();
        for(int i=1;i<=m;i++) fa[find(gi())]=find(gi());
        for(int i=1;i<=n;i++) {
    	int x=find(i);
    	f[i]=x,g[p[i]]=x;
        }
        for(int i=1;i<=n;i++) ans+=(f[i]==g[i]);
        cout<<ans;
        return 0;
    }

Measured memory_bytes: 1792
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
N=int(input())
ans=num2alpha(N)
ans=ans.lower()
ans=ans.replace("'","")
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 1000005 

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

bool isprime(li n)
{
  if (n == 1)
    return false;
  int i = 2;
  while (i*i <= n){
      if (n % i == 0)return false;
      i += 1;
  }
  return true;
}

li lcm(li a,li b)
{
    return ((a*b)/__gcd(a,b));
}

void solve()
{
  li k;
  cin>>k;

  li sum = 0;

  rep(i,1,k+1)
  rep(j,1,k+1)
  rep(l,1,k+1)
    sum+=__gcd(l,__gcd(j,i));

  cout<<sum<<endl;
}
int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    solve();
    
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef long long ll;

//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく

//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

using namespace std;

int main(void){
 
  ll k;
  cin >> k;
  int a = 0;
  int ans = -1;
  REP(i,k){
    a = a * 10 + 7;
    a = a%k;
    if( a == 0){
      ans = i+1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3552
T, X, Y = 0, 0, 0
cnt = 0
for n in range(int(input())):
  t, x, y = map(int,input().split())
  dist = abs(x-X) + abs(y-Y)
  dt = t - T
  cnt += all([dist <= dt, (dist - dt) % 2 == 0])
  T, X, Y = t, x, y
print("YNeos"[n+1!=cnt::2])

Measured memory_bytes: 3064
#include<iostream>
#include<string>
int main(){
	std::string s;
	std::cin >> s;
	int K=0, U=0, P=0, C=0,a=0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'K')K += 1;
		if (s[i] == 'U')U += 1;
		if (s[i] == 'P')P += 1;
		if (s[i] == 'C')C += 1;
	}
	while (true){
		if (K > 0 && U > 0 && P > 0 && C > 0){
			a++;
			K -= 1, U -= 1, P -= 1, C -= 1;
		}
		else break;
	}
	std::cout << a << "\n";
}

Measured memory_bytes: 1192
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll a[6],n1=0,n2=0,n3=0,n4=0;
    rep(i,6){
        cin >> a[i];
        if(a[i] == 1) n1++;
        if(a[i] == 2) n2++;
        if(a[i] == 3) n3++;
        if(a[i] == 4) n4++;
    }

    if(n1==3 || n2==3 || n3==3 || n4==3) cout << "NO" << endl;
    else cout << "YES" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int d, tmp, s = 0;
  while (cin >> d) {
    tmp = d;
    for (; d <= 600 - tmp; d += tmp) {
      s += d * d * tmp;
    }
    cout << s << endl;
    s = 0;
  }
  return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin>>N;

vector<vector<int>> Q(N, vector<int>(2));
for(int i=0;i<N;i++){
  int l,r;
  cin>>l>>r;
  Q[i][0]=l;
  Q[i][1]=r;
}

sort(Q.begin(),Q.end());

for(int i=0;i<N-1;i++){
  if(Q[i][0]==Q[i+1][0]){
    int idx= i+1;
    while(Q[i][0]==Q[idx][0] && idx<N){
      idx++;
    }
    reverse(Q.begin()+i,Q.begin()+idx);
  }
}

vector<vector<int>> A(N, vector<int>(2));
vector<vector<int>> B(N, vector<int>(2));

A[0][0]= Q[0][0],A[0][1]=Q[0][1];
for(int i=1;i<N;i++){
  A[i][0]= max(A[i-1][0],Q[i][0]);
  A[i][1]= min(A[i-1][1],Q[i][1]);
}

B[N-1][0]= Q[N-1][0],B[N-1][1]=Q[N-1][1];
for(int i=N-2;i>=0;i--){
  B[i][0]= max(B[i+1][0],Q[i][0]);
  B[i][1]= min(B[i+1][1],Q[i][1]);
}

vector<int> joy(N);
for(int i=0;i<N-1;i++) {
  joy[i]=max(A[i][1]-A[i][0]+1,0)+max(B[i+1][1]-B[i+1][0]+1,0);
  joy[i]=max(joy[i],max(0,A[N-1][1]-Q[N-1][0]+1)+max(0,Q[i][1]-Q[i][0]+1));
}

int ans=0;

for(int i=0;i<N;i++){
  ans = max(joy[i],ans);
}
cout<<ans<<endl;


}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;

  int count = 0;

  for (int i = 1; i <= N; i++) {
	if (i < 10)
	  count++;
	else if (i > 99 && i < 1000)
	  count++;
	else if (i > 9999 && i < 100000)
	  count++;
  }

  cout << count << endl;


  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element



signed main()
{
	int R, D, X;
	cin >> R >> D >> X;

	int cur = X;
	for (int i = 0; i < 10; i++)
	{
		cur = cur * R - D;
		cout << cur << endl;
	}
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
#include <climits>
using namespace std;

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void){
    ll n;cin>>n;
    ll ans=LONG_LONG_MAX;
    repi(i,1,1e6+1){
        if(n%i!=0)continue;
        ll x=i, y=n/i;
        chmin(ans, (ll)x+y-2);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class MyProgram
{	
  
    public static void Main()
	{
        int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = n[0];
        int K = n[1]-1;
        n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        long min = 999999999999;
        
        int a = 0 ,b = 0 , c = 0;
        for(int i = 0 ; i < N - K; i++)
        {
            a = Math.Abs(n[i])+Math.Abs(n[i+K]-n[i]);
            b = Math.Abs(n[i+K])+Math.Abs(n[i+K]-n[i]);
            c = Math.Min(a,b);
            min = Math.Min(min , c);
        }
    
        Console.WriteLine(min);
    }
    
}

Measured memory_bytes: 23008
L,R = map(int,input().split())
array = []
array2 = []
if R+1 - L <= 2019:
    for i in range(L,R+1):
        if i%2019 not in array2:
            array2.append(i%2019)

    for i in range(len(array2)):
        for j in range(len(array2)):
            if i < j:
                array.append((array2[i]*array2[j])%2019)
    print(min(array))
else:
    for i in range(1,2020):
        if i%2019 not in array2:
            array2.append(i%2019)

    for i in range(len(array2)):
        for j in range(len(array2)):
            if i < j:
                array.append((array2[i]*array2[j])%2019)
    print(min(array))

Measured memory_bytes: 77488
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,k,q;
    cin >> n >> k >> q;
    vi num(n);
    rep(i,q){
        int a;
        cin >> a;
        num[a-1]++;
    }
    rep(i,n){
        if(k-q+num[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

}


Measured memory_bytes: 1408
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

int main() {
    ll N,K;
    cin >> N >> K;

    if(K == 1){
        cout << 0 << endl;
        return 0;
    }else if(K == 2 && N%2 == 0){
        cout << 0 << endl;
        return 0;
    }

    ll result = N % K;

    result = min(result,abs(result-K));

    cout << result << endl;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }

int n, a[15] = {}, x[15][15] = {}, y[15][15] = {};
int is_honest[15] = {};
int max_honest(int pos)
{
   int case0, case1, tmp[15];
   if (pos == n)
   {
      int num = 0;
      FOR(i, 0, n)
      {
         num += is_honest[i];
      }
      return num;
   }
   FOR(i, 0, a[pos])
   if (is_honest[x[pos][i] - 1] >= 0 && is_honest[x[pos][i] - 1] != y[pos][i])
   {
      if (is_honest[pos] == 1)
      {
         return -1;
      }
      else
      {
         memcpy(tmp, is_honest, sizeof(tmp));
         is_honest[pos] = 0;
         case0 = max_honest(pos + 1);
         memcpy(is_honest, tmp, sizeof(tmp));
         return case0;
      }
   }

   if (is_honest[pos] == -1)
   {
      memcpy(tmp, is_honest, sizeof(tmp));
      is_honest[pos] = 0;
      case0 = max_honest(pos + 1);
      FOR(i, 0, a[pos])
      is_honest[x[pos][i] - 1] = y[pos][i];
      is_honest[pos] = 1;
      case1 = max_honest(pos + 1);
      memcpy(is_honest, tmp, sizeof(tmp));
      return max(case0, case1);
   }
   else if (is_honest[pos] == 1)
   {
      memcpy(tmp, is_honest, sizeof(tmp));
      FOR(i, 0, a[pos])
      is_honest[x[pos][i] - 1] = y[pos][i];
      case1 = max_honest(pos + 1);
      memcpy(is_honest, tmp, sizeof(tmp));
      return case1;
   }
   else if(is_honest[pos] == 0)
   {
      return max_honest(pos + 1);
   }
}

int main()
{
   cin >> n;
   FOR(i, 0, n)
   {
      is_honest[i] = -1;
      cin >> a[i];
      FOR(j, 0, a[i])
      {
         cin >> x[i][j] >> y[i][j];
      }
   }

   cout << max_honest(0) << endl;

   return 0;
}


Measured memory_bytes: 256
num = input()
num_array = [i for i in num]

splits = len(num) - 1
n = 2 ** splits

sum = 0

if splits > 0:
    for i in range(n):
        bin = format(i, "0{}b".format(splits))
        bin_array = [i for i in bin]
        tmp_num = str(num_array[0])
        for index, value in enumerate(bin_array):
            if value == "0":
                tmp_num += num_array[index+1]
            else:
                sum += int(tmp_num)
                tmp_num = num_array[index+1]
        sum += int(tmp_num)
else:
    sum = num

print(sum)

Measured memory_bytes: 3064
N = int(input())
*A, = map(int, input().split())
*W, = map(int, input().split())
INF = 10**9
l = r = INF
for a, w in zip(A, W):
    if a:
        r = min(w, r)
    else:
        l = min(w, l)
if l == INF or r == INF:
    print(0)
else:
    print(l+r)



Measured memory_bytes: 5596
#include <bits/stdc++.h>  // ver1.9
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin >> n;
  vector<tuple<int,int,int>> di(n-1);
  int qw,er,ty;
  rep(i,0,n-1){
    cin >> qw>>er>>ty;
    di[i] = make_tuple(qw,er,ty);
  }
  
  int nowt = 0, nowp = 0;
  rep(i,0,n-1){
    nowp = i;
    nowt = 0;
    rep(j,i,n-1){
      if(nowt <= get<1>(di[j])){
        nowt = get<1>(di[j]);
        nowt += get<0>(di[j]);
      }
      else {
        if(nowt%get<2>(di[j])!=0) nowt += get<2>(di[j])-nowt%get<2>(di[j]);
        nowt += get<0>(di[j]);
      }
    }
    cout << nowt << endl;
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

class Combination{
public:
    ll N;
    ll mod;
    vector<ll> fact;

    Combination(ll n, ll m) : N(n), mod(m), fact(n+1){
        fact.at(0) = 1;
        for(ll i=1; i<=N; i++){
            fact.at(i) = i * fact.at(i-1) % mod;
        }
    }

    ll POW(ll a, ll b){
        ll res = 1;
        while(b > 0){
            if(b & 1){
                res = res * a % mod;
            }
            a = a * a % mod;
            b >>= 1;
        }
        return res;
    }

    ll combin(ll n, ll k){
        if(n < 0 || k < 0 || n < k){
            return 1;
        }
        return fact.at(n) * POW(fact.at(k) * fact.at(n-k) % mod, mod - 2) % mod;
    }
};

signed main(){
    ll n, m, k;
    cin >> n >> m >> k;

    Combination C(n*m, MOD);

    ll ans = 0;

    for(ll i=1; i<n; i++){
        ll d = i * m * m * (n - i) % MOD;
        d *= C.combin(n*m-2, k-2);
        ans = (ans + d) % MOD;
    }

    for(ll i=1; i<m; i++){
        ll d = i * n * n * (m - i) % MOD;
        d *= C.combin(n*m-2, k-2);
        ans = (ans + d) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
int a, b, c, x;
void solve(){
    int cnt = 0;
    cin >> a, cin >> b, cin >> c, cin >> x;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(500 * i + 100 * j + 50 * k == x){
                    cnt++;
                    break;
                }
            }
            if(500 * i + 100 * j > x)
            break;
        }
        if(500 * i > x)
        break;
    }
    cout << cnt << endl;
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void iswap(int *a, int *b);   
    
int main() {
  int a;
  int b;
  int c;
  scanf("%d %d %d", &a, &b, &c);
  if (a > b) {
    iswap(&a, &b);
  }
  if (a > c) {
    iswap(&a, &c);
  }
  if (b > c) {
    iswap(&b, &c);
  }
  printf("%d %d %d\n", a, b, c);
  return 0;
}

void iswap(int *a, int *b) {
  int t;
  t = *a;
  *a = *b;
  *b = t;
}

Measured memory_bytes: 596
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long [] in = new long [n];
        long sum = 0;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<n;i++){
                             in[i] = sc.nextLong();
                             sum=sum^in[i];
        }
        for(int i=0;i<n;i++){
                             sb.append(String.valueOf(sum^in[i])+" ");
                            }
       System.out.println(sb.toString());		
	}
}

Measured memory_bytes: 64608
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,m,a;
    string s,t;
    lli i,j;
    cin>>s>>t;
    if(s.size()<t.size()){
        s="UNRESTORABLE";
    }
    else{
        rrep(i,s.size()-t.size(),-1){
            a=0;
            rep(j,0,t.size()){
                if((s[i+j]==t[j])||(s[i+j]=='?')){
                    a++;
                }
            }
            if(a==t.size()){
                rep(j,0,t.size()){
                    s[i+j]=t[j];
                }
                rep(j,0,s.size()){
                    if(s[j]=='?'){
                        s[j]='a';
                    }
                }
                break;
            }
            if(i==0){
                s="UNRESTORABLE";
            }
        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            while (true)
            {
                string[] array = Console.ReadLine().Split(' ');
                a = int.Parse(array[0]);
                b = int.Parse(array[1]);
                if (a == 0 && b == 0)
                {
                    break;
                }
                for (int i = 0; i < a; i++)
                {
                    if (i == 0 || i + 1 == a)
                    {
                        string output = new string('#', b);
                        Console.WriteLine(output);
                    }
                    else
                    {
                        string inner = new string('.', b - 2);
                        Console.WriteLine('#' + inner + '#');
                    }
                }
                Console.WriteLine("");
            }
        }
    }
}

Measured memory_bytes: 8864
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n;cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++) {
        string s;cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 19120
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using P = pair<ll, ll>;


void solve(std::string S){
    int ans = 0;
    loop (S.size(), i) {
        for (int j = i + 1; j <= S.size(); j++) {
            int ng = 0;
            for (int k = i; k < j; k++) {
                if (S[k] != 'A' && S[k] != 'C' && S[k] != 'G' && S[k] != 'T') {
                    ng = 1;
                    break;
                }
            }
            if (!ng) ans = max(ans, j - i);
        }
    }
    cout << ans << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class BShiritori {
public:
    void solve(istream& cin, ostream& cout) {
        int n;
        cin >> n;
        vector<string> s;
        for(int i=0; i<n; i++) {
            string tp; cin >> tp;
            s.push_back(tp);
        }
        bool flag = true;
        for(int i=1; i<n; i++) {
            if(s[i][0] != s[i-1][s[i-1].length()-1]) flag = false;
            for(int j=i-1; j>=0; j--) {
                if(s[j].compare(s[i]) == 0) flag = false;
            }
        }
        cout << ((flag) ? "Yes" : "No") << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    BShiritori solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
def main():
  N = int(input())
  s = input()

  # S: 1, W: 0
  for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)):
    l = [a0, a1]

    for c in s[1:] + s[0]:
      if c == 'o':
        a0, a1 = a1, not (a0 ^ a1)
      else:
        a0, a1 = a1, (a0 ^ a1)
      l.append(a1)

    if (l[0] == a0) and (l[1] == a1):
      print(''.join('S' if i else 'W' for i in l[:-2]))
      exit()

  print(-1)

if __name__ == '__main__':
  main()

Measured memory_bytes: 5620
#include <iostream>

using namespace std;

int table[501][501];
int C[501][501];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, M, Q;
  cin >> N >> M >> Q;

  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    table[l][r]++;
  }
  for (int i = 1; i <= N; i++) {
    C[i][1] = table[i][1];
    for (int j = 2; j <= N; j++) {
      C[i][j] = C[i][j - 1] + table[i][j];
    }
  }
  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;

    int ans = 0;
    for (int i = p; i <= q; i++) {
      ans += C[i][q] - C[i][p - 1];
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5556
using System;
class Program
{
  static void Main (string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int sum = 0;
    for (int i = 0; i < 2; i++) {
      sum += (a <= b) ? b-- : a--;
    }
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n, k; cin >> n >> k;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }

  vector<int> imos(1111, 0);
  for(int i = 1; i < 1100; i++){
    imos[i] += imos[i-1] + i;
  }

  double ans = -INF, res = 0.0;
  int right = 0;
  for(int i = 0; i < n; i++){
    while(right < n && right - i + 1 <= k){
      res += imos[p[right]] * 1.0 / p[right];
      right++;
    }
    if(right - i == k) ans = max(ans, res);
    if(right-k >= 0) res -= imos[p[right - k]] * 1.0 / p[right - k];
  }
  printf("%.9f\n", ans);

  return 0;
}


Measured memory_bytes: 1792
<?php
fscanf(STDIN, '%d', $n);
// echo $n;
// echo $m;
$max = 0;
$sum = 0;
$a = explode(' ', fgets(STDIN));
for ($j = 0; $j < (int)$n; $j++) {
  // echo $a[$j];
  $sum = $sum + (int)$a[$j];
  if ($max < (int)$a[$j]) {
    $max = (int)$a[$j];
    // echo $max;
  }
}

if ($max < $sum - $max) {
  echo 'Yes';
} else {
  echo 'No';
}
?>

Measured memory_bytes: 4856
#include <iostream>
using namespace std;

int main() {
	int N, C[500], S[500], F[500];
	cin >> N;
	for(int i=1; i < N; ++i) {
		cin >> C[i] >> S[i] >> F[i];
	}
	for(int i=1; i<N; ++i) {
		int t = 0;
		for(int j=i; j<N; ++j) {
			for(int cur=max(t,S[j]); ; ++cur) {
				if(cur % F[j] == 0) {
					t = cur + C[j];
					break;
				}
			}
		}
		cout << t << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
using namespace std;

const double pi=4*atan(1.0);

int main() {
	int N,K;
	cin>>N>>K;
	vector<bool> arr(10,true);
	for(int i=0;i<K;++i){
		int tmp;
		cin>>tmp;
		arr[tmp]=false;
	}
	vector<int> use;
	for(int i=0;i<10;++i){
		if(arr[i])use.push_back(i);
	}

	vector<int> Num;
	int tmp=N;
	while(N){
		Num.push_back(N%10);
		N/=10;
	}

	int Index=-1;
	for(int i=Num.size()-1;i>=0;--i){
		if(!arr[Num[i]]){
			Index=i;
			break;
		}
	}

	int ans=0;
	if(Index<0){
		ans=tmp;
	}
	else{
		if(Num[Index]>use.back()){
			if(Index==Num.size()-1){
				if(use.front()==0)ans=use[1];
				else ans=use.front();

				for(int i=0;i<Num.size();++i){
					ans*=10;
					ans+=use.front();
				}
			}else{
				int Index1=-1;
				for(int i=Index+1;i<Num.size();++i){
					if(Num[i]<use.back()){
						Index1=i;
						break;
					}
				}

				if(Index1<0){
					if(use.front()==0)ans=use[1];
					else ans=use.front();
					ans*=10;

					for(int i=0;i<Num.size();++i){
						ans+=use.front();
						ans*=10;
					}
					ans/=10;
				}
				else{
					for(int i=Num.size()-1;i>Index1;--i){
						ans+=Num[i];
						ans*=10;
					}

					for(const auto& val:use){
						if(val>Num[Index1]){
							ans+=val;
							ans*=10;
							break;
						}
					}

					for(int i=0;i<Index1;++i){
						ans+=use.front();
						ans*=10;
					}
					ans/=10;
				}
			}
		}
		else{
			for(int i=Num.size()-1;i>Index;--i){
				ans+=Num[i];
				ans*=10;
			}

			for(const auto& val:use){
				if(val>Num[Index]){
					ans+=val;
					ans*=10;
					break;
				}
			}

			for(int i=0;i<Index;++i){
				ans+=use.front();
				ans*=10;
			}
			ans/=10;
		}
	}
	
	cout<<ans<<endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
K = int(input())

def gcd(a,b):#a>b
    if b==0:
        return a
    else:
        return gcd(b,a%b)

gcdtable = [[1 for i in range(K+1)] for j in range(K+1)]
for i in range(1,K+1):
    for j in range(1,K+1):
        gcdtable[i][j] = gcd(i,j)

ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(gcdtable[i][j],k)


print(ans)

Measured memory_bytes: 72020
n,d,p,q,m[9999],h;main(b){for(;~scanf("%d",&n),n;d&&printf("%d\n",p)){for(memset(m,d=0,39996);n--;){scanf("%d%d%d",&d,&p,&q);b=(d-2?~-(1<<p):1)<<q;for(h=9998;~h&&!(m[h]&b);h--)d-2?p=1:0;for(h++;p--;m[h]-62?h++:memmove(m+h,m+h+1,9998-h))m[h]|=b;}for(p=0,h=9999;h--;)for(b=m[h];q=-b&b;b-=q)p++;}}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
  	Scanner in = new Scanner(System.in);
    
    int n = in.nextInt();
    while (n != 0) {
      if (n % 10 == 7) {
      	System.out.println("Yes");
        break;
      }
      n /= 10;
    }
    
    if (n == 0) {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
    {
        cout<<"Cloudy"<<endl;
    }
    else if(s=="Rainy")
    {
        cout<<"Sunny"<<endl;
    }
    else if(s=="Cloudy")
    {
        cout<<"Rainy"<<endl;
    }
return 0;
}


Measured memory_bytes: 256
def main(input = STDIN)
  keys = [".", ",", " "]
  str = [input.gets]
  keys.each {|key|
    str.map!{|s|s.split(key)}.flatten!
  }
  puts str.select{|word|(word.length > 2) and (7 > word.length)}.join(" ")
end
main

Measured memory_bytes: 6100
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int n;
  int w[100];
  cin >> n;
  REP(i, n)
  {
    cin >> w[i];
  }
  int result = 1000000;
  REP(i, n)
  {
    int l = 0;
    int r = 0;
    REP(j, n)
    {
      if (j <= i)
      {
        l += w[j];
      }
      else
      {
        r += w[j];
      }
    }
    result = min(result, abs(l - r));
  }

  cout << result << endl;
}


Measured memory_bytes: 256
fun main(args : Array<String>){
    while(true){
        val n = readLine()!!.toInt()
        if(n==0) break
        val a = readLine()!!.split(" ").map(String::toInt)
        val ave = a.sum() / n
        val ans= a.filter { v -> v <= ave }.size
        println(ans)
    }
}


Measured memory_bytes: 43936
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
int n,m,k;
set<int>Map[666666];
int main() {
	read(n);read(m);read(k);int res=n;
	while(k--){
		int x,y;read(x);read(y);Map[x].insert(y);
	}
	for(int i=2,l=1,r=1;i<=n;i++){
		set<int>::iterator it=Map[i].lower_bound(l);
		if(it!=Map[i].end()&&(*it)<=r){printf("%d\n",i-1);return 0;}
		if(r+1<=m&&!Map[i].count(r+1))r++;
	}
	cout<<n;
	return 0;
}


Measured memory_bytes: 40832
#include<stdio.h>
int main(void){
    int H,W,i=0,j=0;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&W==0)break;

    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
                if(j==0||j==W-1||i==0||i==H-1){
                    printf("#");
                } else {
                    printf(".");
                }
        }
        printf("\n");
    }
    printf("\n");
    }
return 0;

}

Measured memory_bytes: 572
#include <stdio.h>
main()
{
  int i,n[100],N,mini,j,s=0,l=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&n[i]);
  }
  
  for(i=0;i<N;i++){
    mini = i;
    for(j=i;j<N;j++){
      if(n[j]<n[mini]) mini=j;
    }

    l=n[i];
    n[i]=n[mini];
    n[mini]=l;
    if(i!=mini)s++;

  }
  for(i=0;i<N-1;i++){
    printf("%d ",n[i]);
  }
  printf("%d\n",n[i]);
  printf("%d\n",s);
  return 0;
  
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int l[300005], r[300005];

int st[400004], lazy[400004];
void push(int n, int s, int e, int val){
    st[n] += val;
    if(s != e){
        lazy[n+n] += val;
        lazy[n+n+1] += val;
    }
    lazy[n] = 0;
}
void update(int n, int s, int e, int l, int r, int v){
    push(n, s, e, lazy[n]);
    if(s > r || l > e) return;
    if(l <= s && e <= r){
        push(n, s, e, v);
        return;
    }
    int mid = (s+e)/2;
    update(n+n, s, mid, l, r, v);
    update(n+n+1, mid+1, e, l, r, v);
    st[n] = st[n+n] + st[n+n+1];
}
int query(int n, int s, int e, int l, int r){
    push(n, s, e, lazy[n]);
    if(s > r || l > e) return 0;
    if(l <= s && e <= r) return st[n];
    int mid = (s+e)/2;
    return query(n+n, s, mid, l, r) + query(n+n+1, mid+1, e, l, r);
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &l[i], &r[i]);
        v[r[i]-l[i]+1].emplace_back(i);
    }
    int ans = n;
    for(int d=1;d<=m;d++){
        for(int i=0;i<v[d-1].size();i++){
            int j = v[d-1][i];
            update(1, 1, m, l[j], r[j], 1);
            ans--;
        }
        int res = ans;
        for(int i=d;i<=m;i+=d){
            res += query(1, 1, m, i, i); 
        }
        printf("%d\n", res);
    }
}

Measured memory_bytes: 11264
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int xor = a[0];
        int sum = a[0];
        int l = 0, r = 0;
        long ans = 0;
        while (l < n) {
            while (r + 1 < n && (xor ^ a[r + 1]) == sum + a[r + 1]) {
                r++;
                xor ^= a[r];
                sum += a[r];
            }
            ans += r - l + 1;
            xor ^= a[l];
            sum -= a[l];
            l++;
        }
        System.out.println(ans);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 45652
import java.util.Scanner;
class Main
{
public static void main(String[] args)
 {
 Scanner sc = new Scanner(System.in);
  int  n  = sc.nextInt();
  int a[] = new int[n];
  
  for(int i=0; i<n; i++){
   a[i] = sc.nextInt();
   }
  for(int i=0;i<n-1;i++){
  System.out.print(a[n-1-i]+" ");
  }
  System.out.println(a[0]);
}
}




Measured memory_bytes: 26300
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

int main(){
    int a, b, angle;
    double s, l, h;

    scanf("%d %d %d", &a, &b, &angle);
    // sin(), cos(), tan()????§???????????????¢???
    // ?????°?????????????????¢??????????????????????§????(????????¢???)????§????(?????°)*??/180
    // ?????°??¨??????????????????????????math.h???define????????¨?????????
    // ?????????dandelion's log ?? VC++??§M_PI?????????????????£????????±?????? http://www.atinfinity.info/blog/archives/14
    h=b*sin(angle*M_PI/180.0);
    s=a*h/2;
    l=a+b+sqrt((a*a+b*b-2*a*b*cos(angle*M_PI/180.0)));
    printf("%f\n", s);
    printf("%f\n", l);
    printf("%f\n", h);

    return 0;
}

Measured memory_bytes: 2964
n = input()
for i in xrange(n):
    s = raw_input()
    tr = [s[0]]
    for j in xrange(3,len(s),3):
        if s[j] in tr:
            continue
        if s[j-1]==">":
            tr.append(s[j])
        else:
            tr.insert(0,s[j])
    print "".join(tr)

Measured memory_bytes: 4216
// Chat in a Circle
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<ll>());
    ll ans=a[0];
    a.erase(a.begin());
    for(ll i=1; i<n-1; i++){
        ans+=a[(i-1)/2];
        //cout << a[(i-1)/2] << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int main()
{
	priority_queue<int> PQ;
	while (true)
	{
		string com;
		cin >> com;
		if (com == "insert")
		{
			int t;
			cin >> t;
			PQ.push(t);
		}
		else if (com == "extract")
		{
			cout << PQ.top() << endl;
			PQ.pop();
		}
		else if (com == "end")
			break;
	}
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>

using namespace std;
#define ll long long int


int main()
{
	int k,a,b;
  	cin >> k >> a >> b;
  	bool ok = false;
  	for(int i=1;i<=1000;i++){
      int x = i*k;
      if(x>=a && x<=b){ok = true;break;}
    }
  	if(ok) cout << "OK" << endl;
  else cout << "NG" << endl;
}


Measured memory_bytes: 3632