akhauriyash/Code-Regression huggingface dataset:
N = input()
NN = N
if len(N) == 1:
    print(N)
    exit()
for i in range(1,len(N)):
    if N[i] != '9':
        NN = str(int(N[0])-1)+'9'*len(N[1:])
        break
ans = 0
for nn in NN:
    ans += int(nn)
print(ans)

Measured memory_bytes: 3064
n = int(input())
d = []
for i in range(n):
    inp = list(map(int, input().split()))
    d.append(inp)

hoge = 0
ans = "No"
for i in range(n):
    if d[i][0] == d[i][1]:
        hoge += 1
    else:
        hoge = 0
    if hoge >= 3:
        ans = "Yes"
        break
print(ans)


Measured memory_bytes: 9180
#include<iostream>
#include<math.h>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<string>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
	long long x,t;
	cin>>x>>t;
	if(x>=t)
	cout<<x-t;
	else
	cout<<"0";
	return 0;
}


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

int main() {
   int N;
   cin >> N;
   int A[N],B[N],C[N];
   for (int i=0; i<N; i++) {
      cin >> A[i];
   }
   for (int i=0; i<N; i++) {
      cin >> B[i];
   }
   for (int i=0; i<N; i++) {
      cin >> C[i];
   }
   sort(A,A+N);
   sort(B,B+N);
   sort(C,C+N);
   long long total=0;
   for (int i=0; i<N; i++) {
      long long counta=0,countc=0;
      //counta=lower_bound(A,A+N,B[i])-A;
      int low=0,high=N-1;
      if (A[0]<B[i] && A[N-1]>=B[i]) {
      while (high-low>1) {
         if (A[(low+high)/2]<B[i]) low=(low+high)/2;
         else high=(low+high)/2;
      }
      counta=high;
      }
      else if (A[N-1]<B[i]) counta=N;
      //if (B[i]<C[N-1]) countc=N-(upper_bound(C,C+N,B[i])-C);
      low=0,high=N-1;
      if (B[i]<C[N-1] && B[i]>=C[0]) {
      while (high-low>1) {
         if (C[(low+high)/2]>B[i]) high=(low+high)/2;
         else low=(low+high)/2;
      }
      countc=N-high;
      }
      else if (B[i]<C[0]) countc=N;
      total+=counta*countc;
   }
   cout << total << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod*mod;
const int MAX =25610;

int h, w;
int a[100][100], b[100][100], d[100][100];
bool dp[2][85][MAX];

int main(){
    scanf("%d%d", &h, &w);
    rep(i, h)rep(j, w) scanf("%d", &a[i][j]);
    rep(i, h)rep(j, w) scanf("%d", &b[i][j]);
    rep(i, h)rep(j, w) d[i][j]=a[i][j]-b[i][j];

    rep(i, 2)rep(j, w+1)rep(k, MAX) dp[i][j][k]=false;
    dp[0][0][12805]=true;
    rep(i, h){
        rep(j, w)rep(k, MAX)if(dp[0][j][k]){
            rep(l, 2){
                int sgn=l*2-1;
                dp[0][j+1][k+sgn*d[i][j]]=true;
                dp[1][j][k+sgn*d[i][j]]=true;
            }
        }
        rep(j, w+1)rep(k, MAX){
            dp[0][j][k]=dp[1][j][k];
            dp[1][j][k]=false;
        }
    }

    int ans=MAX;
    rep(k, MAX)if(dp[0][w-1][k] && abs(ans)>abs(k-12805)) ans=abs(k-12805);
    printf("%d\n", ans);
}

Measured memory_bytes: 4480
#include<stdio.h>
int main()
{
  int a,b,c,d;
  scanf("%d %d %d",&a,&b,&c);
  for(a;a<b+1;a++)
    {
      if(c%a==0)d++;
    }
  printf("%d\n",d);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int n;
int calc(int x) {
//	printf("%d\n", x);
   int res = 0;
   for(int i = 0; i < n; ++i) {
		res+= (a[i]-x)*(a[i]-x);
   }
   return res;
}
map<char, vector<int> >v;
int main(){
 	//freopen("in", "r", stdin);
  	//freopen("out", "w", stdout);
	int tc;
	//scanf("%d", &tc);
	tc = 1;
	int h = -200;
	int l = 200;
	for(int tt = 1 ; tt <= tc; ++tt){
		string s;
		cin >> s;
		for(int i = 0; i < (int)s.size(); ++i) {
		 	v[s[i]].push_back(i);
		}
		for(int i = 0; i < (int)s.size()-1; ++i) {
		 	if(s[i] == s[i+1]){
		 	 	printf("%d %d\n", i+1, i+2);
		 	 	return 0;
		 	}
		 	if(i+2 < (int)s.size() && s[i] == s[i+2]){
		 	 	printf("%d %d\n", i+1, i+3);
		 	 	return 0;
		 	}
		}
		for(auto vv : v) {
			vector<int>now = vv.second;
			for(int i = 0; i < (int)now.size(); ++i){
			 	for(int j = i+1; j < (int)now.size(); ++j){
			 	     int tot = now[j] - now[i] + 1;
			 	     if(tot > 25)break;
			 	     int cur = j - i + 1;
			 	     if(cur > tot/2) {
			 	      	printf("%d %d\n", now[i]+1, now[j]+1);
			 	      	return 0;
			 	     }
			 	}
			}
		}
		printf("-1 -1\n");
	  	
	//	fprintf(stderr, "caso de teste %d resolvido\n", tt);
	//	fflush(stderr);
	}
	
	return 0;
}

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

#define rep(i,n,s)		for(i=s;i<n;i++)
#define repr(i,n,s)		for(i=s;i>=n;i--)
#define remax(x,y)		x = max(x,(y))
#define remin(x,y)		x = min(x,(y))
#define all(c)			(c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define ll long long
#define ittr(v) typeof(v)::iterator

#define pb	push_back
#define mp 	make_pair
#define vi 	vector<int>
#define vl 	vector<long>
#define vpii 	vector< pair<int,int> >
#define vpil 	vector< pair<int,long> >
#define vpll 	vector< pair<long,long> >

#define pii 	pair<int,int>
#define piii	pair< pair<int,int>,int >
#define pll 	pair<long,long>
#define plll 	pair< pair<long,long>,long >

#define umii 	unordered_map<int,int>

using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b) + min(c,d);
}

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

int main(){
    int n;
    cin >> n;
    for(int i=1;i<n+1;i++){
        if(i%3==0) cout << " " <<i;
        else{
            int x;
            x=i;
            while(x!=0){
                if(x%10==3){
                    cout<<" "<<i;
                    break;
                }
                x/=10;
            }
        }
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3080
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
using namespace std;

int main(){
  long long i, j, k, l;
  cin >> i >> j >> k >> l;
  long long a, b, r, x, tmp;
 
  a = k;
  b = l;
  x = a * b;
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  cout << (j - i + 1) - ((j/k - (i-1)/k) + (j/l - (i-1)/l) - (j/(x/b) - (i-1)/(x/b))) << endl;
  return 0;
}
                     

Measured memory_bytes: 256
import itertools

n = int(input())
num = list(map(int, input().split()))
per = list(itertools.permutations(num))

per.sort()
index = per.index(tuple(num))

if index != 0:
    print(' '.join(str(n) for n in per[index-1]))
print(' '.join(str(n) for n in per[index]))
if index != len(per)-1:
    print(' '.join(str(n) for n in per[index+1]))



Measured memory_bytes: 53364
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     ll n,i,j;
     cin>>n;
     ll a[n+5];
     ll b[n+5];
     memset(b,0,sizeof(b));
     for(i=0;i<n-1;i++){
        cin>>j;
        b[j]++;
     }
     for(i=1;i<=n;i++){
        cout<<b[i]<<endl;
     }


}


Measured memory_bytes: 5160
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int solve( vector< PII > ary )
{
	const int N = ary.size();

	VVI G( N );

	REP( i, 0, N )
	{
		REP( j, 0, N )
		{
			if ( i == j )
			{
				continue;
			}

			if ( ary[i].fst < ary[j].fst && ary[i].snd < ary[j].snd )
			{
				G[i].PB( j );
			}
		}
	}

	VI dist( N, 1 );

	while ( true )
	{
		bool update = false;

		REP( i, 0, N )
		{
			REP( j, 0, G[i].size() )
			{
				if ( dist[ G[i][j] ] < dist[i] + 1 )
				{
					dist[ G[i][j] ] = dist[i] + 1;
					update = true;
				}
			}
		}

		if ( !update )
		{
			break;
		}
	}

	return *max_element( ALL( dist ) );
}

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

	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		vector< PII > ary;

		REP( i, 0, n )
		{
			int a, b;
			cin >> a >> b;
			ary.PB( MP( a, b ) );
		}

		int m;
		cin >> m;

		REP( i, 0, m )
		{
			int a, b;
			cin >> a >> b;
			ary.PB( MP( a, b ) );
		}

		cout << solve( ary ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int A;
  int B;
  cin >>A>>B;
  int x=A+B;
  int y=A-B;
  int z=A*B;
  int w=max(max(x,y), z);
  cout << w<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

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

    ll N; cin >> N;

    ll A, B;
    for(ll i = 1; i * i <= N; i++) {
        if(N%i == 0) {
            A = i;
            B = N/i;
        }
    }
    string s = to_string(A);
    string t = to_string(B);

    cout << max(s.size(), t.size()) << endl;
    return 0;
}

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

if N <= 111 :
    print("111")
elif 111 < N <= 222:
    print("222")
elif 222 < N <= 333:
    print("333")
elif 333 < N <= 444:
    print("444")
elif 444 < N <= 555:
    print("555")
elif 555 < N <= 666:
    print("666")
elif 666 < N <= 777:
    print("777")
elif 777 < N <= 888:
    print("888")
else:
    print("999")

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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int x = sc.nextInt();
        int count = 1;
        int pos = 0;
        for(int i=0; i<n; i++){
            pos += sc.nextInt();
            if(pos <= x) count++;
        }
        System.out.println(count);
    }


    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}


Measured memory_bytes: 22612
// 27/07/19 // 16:32 PM //
// O(n)

#include <iostream>

using namespace std;

#define MAXN 100010

int n;
int value[MAXN][10];
int memo[MAXN][10];

int funcao(){  // ant = 0, 1, 2


    for(int i=1; i<=n; i++)
        for(int k=0; k<3; k++)
            for(int j=0; j<3; j++)
                if(j!=k)
                   memo[i][k] = max(memo[i][k], memo[i-1][j] + value[i][k]);


    return max(memo[n][0], max(memo[n][1], memo[n][2]));
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    for(int i=1; i<=n; i++)
        cin >> value[i][0] >> value[i][1] >> value[i][2];


    cout << funcao() << "\n";

    return 0;
}


Measured memory_bytes: 8064
#include<iostream>
const char SHARP = '#';
const char DOT = '.';

int main()
{
	int h, w;
	while(std::cin >> h >> w) {
		if(h == 0 && w == 0) break;
		for(int i=0; i<h; i++){
			if(i == 0 || i == h-1){
				for(int j=0; j<w; j++){
					std::cout << SHARP;
				}
				std::cout << '\n';
			} else {
				for(int j=0; j<w; j++){
					if(j == 0 || j == w-1){
						std::cout << SHARP;
					} else {
						std::cout << DOT;
					}
				}
				std::cout << '\n';
			}
		}
	std::cout << '\n';
	}
	return 0;
}

			

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

int min(int x, int y) {
    return (x > y ? y : x);
}

int main() {
    int n, a[1001];
    int ans;

    while (1) {
        scanf("%d", &n);
        if (n == 0) { break; }

        for (int i = 0; i < n; i++) { scanf("%d", &a[i]); }

        ans = 1e8;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                ans = min(ans, abs(a[i] - a[j]));
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

public class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var stack = new Stack<string>();
        for (int i = 0; i < n; i++)
        {
            stack.Push(Console.ReadLine());
        }

        var words = new List<string>(stack);
        while (stack.Count != 1)
        {
            var last = stack.Pop();
            var second = stack.Pop();
            if (last[0] != second[second.Length - 1] || words.Where(x => x == last).Count() != 1)
            {
                Console.WriteLine("No");
                return;
            }

            stack.Push(second);
        }

        Console.WriteLine("Yes");
    }
}


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

using namespace std;

int main()
{
#ifdef jcg
    assert(freopen("input.in", "r", stdin));
//    assert(freopen("output.out", "w", stdout));
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << '\n';

    return 0;
}


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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = LI()
p = [((i-1)%n, (i-1)//n) for i in p]
ans = 0
dp = [[min(i, j, n - (i + 1), n - (j + 1)) for j in range(n)] for i in range(n)]
dp2 = [[False]*n for _ in range(n)]
for (q, r) in p:
    ans += dp[r][q]
    dp2[r][q] = True
    h = [(dp[r][q], r, q)]
    while h:
        d, y, x = h.pop()
        if not dp2[y][x]:
            d += 1
        if x != 0:
            if dp[y][x-1] > d:
                dp[y][x-1] = d
                h.append((d, y, x-1))
        if x != n-1:
            if dp[y][x+1] > d:
                dp[y][x+1] = d
                h.append((d, y, x+1))
        if y != 0:
            if dp[y-1][x] > d:
                dp[y-1][x] = d
                h.append((d, y-1, x))
        if y != n-1:
            if dp[y+1][x] > d:
                dp[y+1][x] = d
                h.append((d, y+1, x))
print(ans)
    
    

Measured memory_bytes: 245144
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, Z, W = rl()
A = rl()
answer = abs(A[-1] - W)
if N >= 2:
    answer = max(answer, abs(A[-2]-A[-1]))
print(answer)
#04

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

//繰り返し二乗法
//x^n mod
ll mod_pow(ll x, ll n, ll mod) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 1) { //奇数
        return mod_pow(x, n - 1, mod) * x % mod; //偶数の再帰にできるように変形
    } else { //偶数
        ll t = mod_pow(x, n / 2, mod); //半分のものを求めて、2乗する
        return t * t % mod;
    }
}

//aCb mod
ll comb(ll a, ll b, ll mod) {
    if (b > a - b) {
        return comb(a, a - b, mod); //aCb <=> aCa-b
    }

    ll c = 1;
    ll d = 1;

    for (ll i = 0; i < b; ++i) {
        c *= a - i;
        c %= mod;

        d *= b - i;
        d %= mod;
    }

    return c * mod_pow(d, mod - 2, mod) % mod; //フェルマーの小定理より
}

int main() {

    int x, y; cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int n = (x + y) / 3; //移動回数

    x -= n;
    y -= n;

    if (x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = comb(x + y, x, MOD);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, lint>>>;
const lint INF = 1001001001001001LL;
const lint MOD = 1000000007LL;
int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void possible(){ cout << "possible" << endl; }
void Possible(){ cout << "Possible" << endl; }
void POSSIBLE(){ cout << "POSSIBLE" << endl; }
void impossible(){ cout << "impossible" << endl; }
void Impossible(){ cout << "Impossible" << endl; }
void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()

int main(){
  int n; cin >> n;
  vector<double> v(n);
  rep(i, n) cin >> v[i];
  sort(all(v));
  srep(i, 1, n){
    v[i] = (v[i - 1] + v[i]) / 2.0;
  }

  printf("%.10f\n", v[n - 1]);
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;


vector<ll> a, b;
int main(){

    int n;
    cin >> n;
    a.resize(n+1);
    b.resize(n);
    rep(i, n+1){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }

    ll ans = 0;
    rep(i, n){
        int mn = min(a[i],  b[i]);
        ans += mn;
        b[i] -= mn;
        int mnn = min(a[i+1], b[i]);
        ans += mnn;
        a[i+1] -= mnn;
    }
    ppp(ans);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename T> using lim = numeric_limits<T>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> jobs(n);
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        jobs[i] = {b, a};
    }
    sort(jobs.begin(), jobs.end());
    ll t = 0;
    bool can = true;
    for(int i = 0; i < n and can; i++) {
        t += jobs[i].second;
        can &= t <= jobs[i].first;
    }
    cout << (can ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")

#define repk(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n)  for(int i=0;i<=(n);++i)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define for1(i,n)  for(int i=1;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
#define ll long long
#define ld long double
#define point pair<double,double>
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
const int  inf = INT_MAX;
const int MOD = 1000000007;
const int N = 100100;

using namespace std;


void sol() {
	int x, n; cin >> x >> n;
	int mn = inf;
	set<int> p;
	rep (i, 0, n) {
		int a;
		cin >> a;
		p.insert(a);
	}
	int ans = 0;
	rep(i, 0, 102) {
		if (!p.count(i)) {
			int d = abs(i - x);
			if (d < mn)
				ans = i, mn = d;
		}
	}
	cout << ans << '\n';




}


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

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int t = 1; // cin >> t;
	while (t--)
		sol();
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pa;

#define fst first
#define snd second
#define pb push_back

const int maxn=1000005,maxm=55;
const double pi=acos(-1.0);
const ll mod=1000000007;
const double eps=1e-6;

int x,y,n[3];
vector<pa> ve;

int main()
{
	int i,j,k;
	scanf("%d %d",&x,&y);
	for(i=0;i<3;i++) scanf("%d",n+i);
	for(i=0;i<3;i++)
    {
        for(j=0;j<n[i];j++)
        {
            int xx;
            scanf("%d",&xx);
            ve.pb(pa(-xx,i));
        }
    }
    sort(ve.begin(),ve.end());
    ll ans=0;
    int xx=x,yy=y,nt=0;
    for(i=0;i<ve.size();i++)
    {
        if(xx+yy==nt) break;
        if(ve[i].snd==0)
        {
            if(xx>0)
            {
                --xx;ans-=ve[i].fst;
            }
        }
        else if(ve[i].snd==1)
        {
            if(yy>0)
            {
                --yy;ans-=ve[i].fst;
            }
        }
        else
        {
            ans-=ve[i].fst;
            ++nt;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 20:55:57 2019

@author: YudNK
"""

N = int(input())
D = [int(i) for i in input().split()]

D.sort()

l = D[0:int(N/2)]
r = D[int(N/2):]

print(r[0] - l[-1])

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

int main() {
  int d;
  cin >> d;
  vector<int> c(26);
  for (int i = 0;i < 26;i++){
    cin >> c.at(i);
  }
  vector<vector<int>> s(d, vector<int>(26));
  for (int i = 0;i < d;i++){
    for (int j = 0;j < 26;j++){
      cin >> s.at(i).at(j);
    }
  }
  
  vector<int> ans(d);
  
  for (int i = 0;i < d;i++){
    int x = s.at(i).at(0);
    for (int j = 0;j < 26;j++){
      if (s.at(i).at(j) > x){
        x = s.at(i).at(j);
        ans.at(i) = j;
      }
    }
  }
  
  for (int i = 0;i < d;i++){
    cout << ans.at(i) + 1 << endl;
  }

}

Measured memory_bytes: 3680
#include<iostream>
#include<string>
using namespace std;
string n;
int main()
{
    cin>>n;
    for(register int i=2;i<n.size();++i)
    {
        if(n[i]==n[i-1]&&n[i]==n[i-2])
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+4;
int a[M],dp[M],n,k;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		dp[i]=INT_MAX;
	}
	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		int tp=1;
		while(i>tp && tp<=k)
		{
			dp[i]=min(dp[i],dp[i-tp]+abs(a[i-tp]-a[i]));
			tp++;
		}
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int R; cin >> R;
    float ans = 2*R*M_PI;
    cout << ans << endl;
    return 0;
    
}

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

int main()
{
	double t,d;
	cin>>t>>d;
	int cnt=0;
	while(t--)
	{
		double x , y;
		cin>>x>>y;
		double ans = double(sqrt(x*x + y*y));
		if(ans <= d)
			cnt++;
	}
	cout<<cnt;
}

Measured memory_bytes: 3776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		while (true) {

			int x = scan.nextInt();
			int y = scan.nextInt();
			if ((x == 0) && (y == 0)) {
				break;
			} else {
				if (x < y) {
					System.out.println(x + " " + y);
				} else if (x > y) {
					System.out.println(y + " " + x);
				} else {
					System.out.println(x + " " + y);
				}
			}
		}
	}
}

Measured memory_bytes: 36572
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 4000010
pair <int,int> edge[N],edge1[N],tree[N]; vector <int> tmp1,tmp2; bool need[N];
int ans=0,many[N],in[N],n,m,tot,level[N],fa[N],head[N],to[N<<1],nxt[N<<1],ff[N],idx;
void add(int a,int b) {nxt[++idx]=head[a],to[idx]=b,head[a]=idx;}
void dfs(int p,int from)
{
	fa[p]=from,level[p]=level[from]+1;
	for(int i=head[p];i;i=nxt[i]) if(to[i]!=from) dfs(to[i],p);
}
void calc(int x,int y)
{
	if(level[x]>level[y]) swap(x,y);
	while(level[y]>level[x]) many[y]++,y=fa[y];
	while(x!=y) many[x]++,many[y]++,x=fa[x],y=fa[y];
}
void solve(vector <int> tr,vector <int> ed)
{
	//for(int i=0;i<(int)tr.size();i++) printf("%d ",tr[i]); printf("\n");
	//for(int i=0;i<(int)ed.size();i++) printf("%d ",ed[i]); printf("\n");
	if(!tr.size()) return; if(ed.size()<=1) {for(int i=0;i<(int)ed.size();i++) need[ed[i]]=false;return;}
	for(int i=1;i<=n;i++) in[i]=0;
	for(int i=0;i<(int)tr.size();i++) in[tree[tr[i]].first]++,in[tree[tr[i]].second]++;
	int fr=0,to=0; vector <int> new_edge,new_tree;
	for(int i=1;i<=n;i++) if(in[i]==1) {fr=i;break;}
	for(int i=0;i<(int)tr.size();i++)
		if(tree[tr[i]].first==fr||tree[tr[i]].second==fr) to=tree[tr[i]].first^tree[tr[i]].second^fr;
		else new_tree.push_back(tr[i]);
	vector <int> vis(2*m+1); int j=-1;
	for(int i=0;i<(int)ed.size();i++)
		if(edge[ed[i]].first==fr||edge[ed[i]].second==fr)
		{
			if(j!=-1)
			{
				int a=edge[ed[j]].first^edge[ed[j]].second^fr,b=edge[ed[i]].first^edge[ed[i]].second^fr;
				if(a!=b)
				{
					ff[ed[i]]=ff[ed[j]]=++tot,new_edge.push_back(tot),
					edge[tot]=make_pair(a,b),need[ed[j]]=edge[ed[j]].first!=a,need[ed[i]]=edge[ed[i]].second!=b;
					vis[ed[i]]=vis[ed[j]]=true;
				} else need[ed[i]]=true,need[ed[j]]=edge[ed[j]].first!=edge[ed[i]].first;
				j=-1;
			} else j=i;
		}
		else new_edge.push_back(ed[i]);
	if(j!=-1)
	{
		if(edge[ed[j]].first==fr) edge[ed[j]].first=to;
		if(edge[ed[j]].second==fr) edge[ed[j]].second=to;
		if(edge[ed[j]].first!=edge[ed[j]].second) new_edge.push_back(ed[j]);
	}
	solve(new_tree,new_edge);
	for(int i=0;i<(int)ed.size();i++) if(vis[ed[i]]) need[ed[i]]^=need[ff[ed[i]]];
}
int main()
{
	scanf("%d%d",&n,&m),tot=m;
	for(int i=1,a,b;i<n;i++) scanf("%d%d",&a,&b),add(a,b),add(b,a),tree[i]=make_pair(a,b),tmp1.push_back(i);
	for(int i=1,a,b;i<=m;i++) scanf("%d%d",&a,&b),edge1[i]=edge[i]=make_pair(a,b),tmp2.push_back(i);
	dfs(1,0);
	for(int i=1;i<=m;i++) calc(edge[i].first,edge[i].second);
	for(int i=1;i<=n;i++) ans+=min(many[i],2);
	printf("%d\n",ans),solve(tmp1,tmp2);
	for(int i=1;i<=m;i++)
		if(!need[i]) printf("%d %d\n",edge1[i].first,edge1[i].second);
		else printf("%d %d\n",edge1[i].second,edge1[i].first);
}

Measured memory_bytes: 93184
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String str = sc.next();
	int slen = str.length();
	String keyence = "keyence";
	int l = 0;
	if(keyence.length() > slen) {
	    System.out.println("NO");
	    return;
	}
	for(int i = 0; i<slen; i++) {
	    if(str.charAt(i) != keyence.charAt(i)) break;
	    l++;
	}
	for(int i = 1; i<=keyence.length(); i++) {
	    if(str.charAt(slen-i) != keyence.charAt(keyence.length()-i)) break;
	    l++;
	}

	if(l >= keyence.length()) {
	    System.out.println("YES");
	    return;
	}
	System.out.println("NO");
    }
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    ll total = 0;
    rep(i,N) total += a[i];
    ll key = total/N;
    ll key2 = total/N+1;

    ll ans = INF;

    ll tmp_ans = 0;
    rep(i,N)
    {
        tmp_ans += pow(key-a[i],2);
    }
    chmin(ans, tmp_ans);
     
    tmp_ans = 0;
    rep(i,N)
    {
        tmp_ans += pow(key2-a[i],2);
    }
    chmin(ans, tmp_ans);           
    cout << ans << endl;
}


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

#define x first
#define y second
#define pb push_back
#define mp make_pair

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int INF = 1000000009;

LL nodivisors(LL n){
    LL ret = 0;
    for(LL i = 1; i*i <= n; i++){
        if(n%i == 0){
            ret++;
            if(n/i != i)
                ret++;
        }
    }
    return ret;
}

LL simul(LL n, LL k){
    while(n >= k){
        if(n%k == 0) 
            n/=k;
        else
            n %= k;
    }
    return n;
}

int main(){
    LL n;
    scanf("%lld", &n);
    LL ans = 0;
    for(LL k = 2; k*k <= n; k++){
        if(n%k == 0){
            ans += (simul(n, k) == 1);
            if(n/k != k)
                ans += (simul(n, n/k) == 1);
        }
    }
    
    ans += nodivisors(n-1);
    printf("%lld\n", ans);
    
return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string srs,saj;
	getline(cin,srs);
	getline(cin,saj);
	//long long sum=0,sum1=0;
	//if(srs[0]>0 && saj[0]>0){
		if(srs.length()>saj.length()) cout<<"GREATER"<<endl;
		else if(srs.length()<saj.length()) cout<<"LESS"<<endl;
		else if(srs.length()==saj.length()){
	for(int i=0;i<srs.length();i++)
	{
		srs[i]=(srs[i]-'0');
	}
	for(int i=0;i<saj.length();i++)
	{
		saj[i]=(saj[i]-'0');
	}
	//cout<<sum<<" "<<sum1<<endl;
	if(srs>saj) cout<<"GREATER"<<endl;
	else if(srs<saj) cout<<"LESS"<<endl;
	else if(srs==saj) cout<<"EQUAL"<<endl;
}
	return 0;
}


Measured memory_bytes: 256
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o B.exe B.cpp 
Execute: ./B
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	long long int n, d, x, y; 
	int result = 0; 
	cin >> n >> d; 
	
	for(int i = 0; i < n; i++) {
		cin >> x >> y; 
		if(x*x + y*y <= d*d) 
			result++; 
	}
	
	cout << result << endl; 
	
	return 0; 
} 


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

int main(){
  int K,A,B;
  bool b = 0;
  cin >> K >> A >> B;

  for(int i=A;i<=B;++i){
    if(i%K==0){
      b = 1;
      break;
    }
  }
  if(b){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3596
#include<stdio.h>
#define MAX 1073741824
int min(const int a, const int b){return a>b?b:a;}
int n, l, i, j, k;
int m;
int a[1000], b, c;
int key[1000];
int d[4096];
int main(void){
	scanf("%d%d", &n, &m);
	for(i=0; i<m; i++){
		scanf("%d%d", a+i, &b);
		for(j=0; j<b; j++){
			scanf("%d", &c);
			key[i] |= 1<<(c-1);
		}
	}
	l = 1<<n;
	for(j=1; j<l; j++){
		if(((~key[0])&j)!=0){
			d[j]=MAX;
		}else{
			d[j]=a[0];
		}
	}
	for(i=1; i<m; i++){
		for(j=1; j<l; j++){
			k=j&(~key[i]);
			if(k!=j){
				d[j] = min(d[j], d[k]+a[i]);
			}
		}
	}
	if(d[l-1]==MAX){
		printf("%d\n", -1);
	}else{
		printf("%d\n", d[l-1]);
	}
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)

int main(){
    int n;
    cin >> n;
    vector<int> x(n),sorted(n);
    rep(i,n){
        cin >> x[i];
    }
    rep(i,n){
        sorted[i] =x[i];
    }
    sort(sorted.begin(),sorted.end());
    double med = (sorted[n/2-1]+sorted[n/2])/2.0;
    rep(i,n){
        if(x[i]>=med)cout << sorted[n/2-1] << endl;
        else cout << sorted[n/2] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main(){

    int R(0);
 
    cin >> R;

    if(R>=0 && R<1200) cout << "ABC" << endl;

    else if(R>=1200 && R<2800)cout << "ARC" << endl;

    else cout << "AGC" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    S = input()

    """
    chokudaiさんのコードも尺取りで写経してみる！
    """

    A = []
    char = 1 # 必ず１から始まるようにするのかなるほど。。。
    cnt = 0
    for i in range(N):
        if S[i] == str(char):
            cnt += 1
        else:
            A.append(cnt)
            char = 1 - char
            cnt = 1
    if cnt != 0: A.append(cnt)
    if len(A) % 2 == 0: A.append(0)
    #print(A)

    """
    この時点でA = [(1の個数), (0の個数), (1の個数), (0の個数),...,(1の個数)]
    のように並んでいるので、Sの先頭が0か1かの場合分けが不要になるし、
    以降の尺取りは(1の個数)のところから常にカウントを始めて良い。
    """

    add = K * 2 + 1
    ans = 0
    left = 0
    right = 0
    tmp = 0 # [left, right)の値

    i = 0
    l = len(A)
    while i < l:
        nextLeft = i
        nextRight = min(i + add, l)
        while nextLeft > left:
            tmp -= A[left]
            left += 1
        while nextRight > right:
            tmp += A[right]
            right += 1
        ans = max(ans, tmp)
        i += 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45680
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int _gcd(ll x, ll y){
    while(1){
        if(x%y == 0)return y;
        else{
            ll z = x%y;
            x = y;
            y = z;
        }
    }
}
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(ll i = 1; i < a.size() && res != 1; i++) {
        res = _gcd(a[i], res);
    }
    return res;
}

int main() {

    ll n,x;
    cin >> n >> x;
    vector<ll> v;
    rep(i,n){
        ll in;
        cin >> in;
        v.push_back(abs(x-in));
    }
    cout << ngcd(v) << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int main(){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    printf("%d %d %.7f", d, r, f);
    return 0;
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n, m;
    while(cin>>n>>m, n&&m) {
        vi a(n);
        vi b(m);
        rep(i,n) cin>>a[i];
        rep(i,m) cin>>b[i];

        int sum_a = accumulate(ALL(a),0);
        int sum_b = accumulate(ALL(b),0);
        int f = 0;
        rep(i, n) {
            if(f==1) break;
            rep(j, m) {
                if(sum_a-a[i]+b[j]==sum_b-b[j]+a[i]) {
                    f = 1;
                    cout << a[i] << " " << b[j] << endl;
                    break;
                }
            }
        }
        if(f==0) P(-1);
    }
    return 0;
}

Measured memory_bytes: 3040
N, M = map(int, input().split())
L = M * [0]
R = M * [0]
for i in range(M):
    Left, Right = map(int, input().split())
    L[i] = Left
    R[i] = Right

L_max = max(L)
R_min = min(R)

count = 0
for i in range(1, N + 1):
    if i >= L_max and i <= R_min:
        count += 1
print(count)

Measured memory_bytes: 10868
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int main()
{
  string s;

  cin >> s;

  printf("%c%c%c\n", s[0], s[1], s[2]);

  return 0;
}


Measured memory_bytes: 3720
/*
        Oink!Oink!!
▂╱▔▔╲╱▔▔▔▔╲╱▔▔╲▂
╲┈▔╲┊╭╮┈┈╭╮┊╱▔┈╱
┊▔╲╱▏┈╱▔▔╲┈▕╲╱▔┊
┊┊┊┃┈┈▏┃┃▕┈┈┃┊┊┊
┊┊┊▏╲┈╲▂▂╱┈╱▕┊┊┊

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>
#include <random>
#include <valarray>
#include <unordered_map>
//#include <fstream>
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define next next239
#define prev prev239
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

int main()
{
    int n;
    cin>>n;
    vector<int> v(n,0);
    map<int,long long int> m;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        m[v[i]]++;
    }
    
    long long int total=0;
    for(auto x:m)
    {   
        total+=(x.second*(x.second-1))/2;
    }
    for(int i=0;i<n;i++)
    {
       long long int temp;
       temp=total;

        temp=temp-m[v[i]]+1;

        cout<<temp<<"\n";
    }


    return 0; 
}

Measured memory_bytes: 10240
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{

  int ac = 0;
  int wa = 0;

  int N;
  scanf("%d", &N);
  int M;
  scanf("%d", &M);

  int size = sizeof(int) * N;
  int *is_ac_array = (int*)malloc(size);
  int *wa_array = (int*)malloc(size);
  memset(is_ac_array, 0, size);
  memset(wa_array, 0, size);

  for(int i = 0; i < M; i++)
    {
      
      int p = 0;
      char ans[3];
      scanf("%d%s", &p, ans);
      p--;

      if(strcmp(ans, "AC") == 0 && !is_ac_array[p])
        {
          is_ac_array[p] = 1;
          ac++;
          wa += wa_array[p];
        }
      else if(!is_ac_array[p])
        {
          wa_array[p]++;
        }
    }

  free(is_ac_array);
  free(wa_array);

  printf("%d %d\n", ac, wa);
  
  return 0;
}


Measured memory_bytes: 896
import Control.Monad

main :: IO ()
main = do
  [n, d] <- map read . words <$> getLine
  xs <- replicateM n $ map read . words <$> getLine
  print $ solve xs

solve :: [[Float]] -> Int
solve [] = 0
solve (_:[]) = 0
solve (x:rest) = g x rest + solve rest
  where
    g x [] = 0
    g x (y:rest) = h x y + g x rest

    h xs ys =
      if any (\m -> n == m**2) [1..n] then 1 else 0
      where
        n = sum $ zipWith (\x y -> (abs (x - y))**2) xs ys

Measured memory_bytes: 1020