akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int N;
int V[100], C[100];

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> V[i];
	}
	for (int i = 0; i < N; i++)
	{
		cin >> C[i];
	}

	int sum = 0;

	for (int i = 0; i < N; i++)
	{
		if (V[i] - C[i] > 0)
		{
			sum += V[i] - C[i];
		}
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    int ans=0;
    if(A>=B){ans+=A; A--;}
    else {ans+=B; B--;}
    if(A>=B){cout<<ans+A;}
    else {cout<<ans+B;}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  int s[n];
  vector<int> tens,nots;
  int a=0;
  int ns=0;
  REP(i,n){
    cin>>s[i];
    a += s[i];
    if(s[i]%10==0){
      tens.push_back(s[i]);
    }else{
      ns += s[i];
      nots.push_back(s[i]);
    }
  }
  
  if(nots.size()==0){
    cout<<0<<endl;
  }else if(nots.size()==1){
    cout<<a<<endl;
  }else{
    if(a%10!=0){
      cout<<a<<endl;
    }else{
      sort(nots.begin(),nots.end());
      cout<<a-nots[0]<<endl;
    }
  }
  return 0;
}


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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

string s;

int main()
{
    cin >> s;
    cout << s.substr(0, 3);
	return 0;
}


Measured memory_bytes: 3588
K, A, B = map(int, input().split())

if B - A <= 2 or K + 1 - A < 2:
    print(K+1)
else:
    sum = B
    K = K + 1 - A - 2
    if K % 2 == 1:
        K -= 1
        sum +=1
    sum += B * (K // 2) - A * (K // 2)

    print(sum)


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

int main(){
  int r,g,b;
  cin >> r >> g >> b;
  int n = 100*r + 10*g + b;
  if(n % 4 == 0)cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 256
import collections
import math

n = int(input())

m = list(map(str,input().split()))

c = dict(collections.Counter(m))
d = {}
hyouji = {}
def ans(a):
    if a<2:
        return 0
    else:
        return math.factorial(a) // (math.factorial(a - 2) * math.factorial(2))

cnt = 0
for i,j in c.items():
    n = ans(j)
    d[i] = n
    cnt += n


for k in m:
    if k in hyouji:
        print(hyouji[k])
    else: 
        if c[k] < 2:
            q = cnt
        elif c[k] == 2:
            q = cnt - 1
        else:
                q = cnt -d[k] + ans(c[k] - 1)

        hyouji[k] = q
        print(hyouji[k])

Measured memory_bytes: 121940
import org.omg.CORBA.MARSHAL;

import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);

    void solve() {
        char[] s = sc.next().toCharArray();
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < s.length; i++) {
            set.add(s[i]);
        }

        int ans = Integer.MAX_VALUE;
        for (char c = 'a'; c <= 'z'; c++) {
            if (set.contains(c)) {
                int count = 0;
                int maxCount = 0;
                for (int i = 0; i < s.length; i++) {
                    if (s[i] != c) count++;
                    if (s[i] == c) {
                        maxCount = Math.max(maxCount, count);
                        count = 0;
                    }
                }
                maxCount = Math.max(maxCount, count);
                ans = Math.min(ans, maxCount);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
def main():
    h, w = map(int, input().split())
    a = ['' for _ in range(h)]
    for i in range(h):
        a[i] = input()

    print('#' * (w + 2))
    for i in range(h):
        print('#' + a[i] + '#')
    print('#' * (w + 2))
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    ostringstream os;
    while(1) {
        int n, x;
        int count = 0;
        cin >> n >> x;
        if (n == 0 && x == 0)
            break;
        REP(i, n+1){
            if(i == 0)
                continue;
            REP(j, i){
                if(j == 0)
                    continue;
                REP(k, j){
                    if(k == 0)
                        continue;
                    if(i + j + k == x){
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }


    cout << os.str();
    return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<vector>

using namespace std;

using ll = long long;

int main()
{
    ll w, h, mod = 1000000007, i, j, ans = 0;
    cin >> h >> w;
    vector<vector<char>> A(h + 1, vector<char> (w + 1));
    vector<vector<ll>> sum(h + 1, vector<ll> (w + 1, 0));
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            cin >> A[i][j];
        }
    }
    sum[0][0] = 1;
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            if (A[i][j] == '#')
            continue;
            if (sum[i][j] == 0)
            continue;
            else
            {
                if (A[i + 1][j] != '#')
                sum[i + 1][j] = (sum[i + 1][j] + sum[i][j]) % mod;
                if (A[i][j + 1] != '#')
                sum[i][j + 1] = (sum[i][j] + sum[i][j + 1]) % mod;
            }    
        }
    }
    // for (i = 0; i < h; i++)
    // {
    //     for (j = 0; j < w; j++)
    //     cout << sum[i][j] << " ";
    //     cout << endl;
    // }
    cout << sum[h - 1][w - 1] << endl;
}

Measured memory_bytes: 9088
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        if(i%2==0):
            for k in range(W):
                if(k%2==0):
                    print("#",end="")
                else:
                    print(".",end="")
        else:
            for k in range(W):
                if(k%2==0):
                    print(".",end="")
                else:
                    print("#",end="")
        print("")
    print("")




Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul a, b;
  cin >> a >> b;
  ul ans = 0;
  while (a<=b) {
    ans++;
    a*=2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <map>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const ll inf=(1e14);

ll solve(){
	vector<vector<int> > ind(1e6+1);
	vector<bool> vis(1e6+1);
	int n,t;
	cin>>n;
	for(int i=0;i<n;i++) cin>>t,ind[t].push_back(i);
	for(int i=0;i<ind.size();i++){
		if(ind[i].size() && !vis[i]){
			for(int j=2*i;j<ind.size();j+=i) vis[j]=1;
		}
		if(ind[i].size() > 1) vis[i]=1;
	}
	int ans=0;
	for(int i=0;i<ind.size();i++) if(ind[i].size() && !vis[i]) ans++;
	return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 32996
import math

N = int(input())
K = int(input())
X = list(map(int, input().split(' ')))
ans = 0
for i in range(N):
    dis1 = X[i]
    dis2 = X[i]-K
    if dis2 < 0:
        dis2 = -dis2
    ans += min(dis1, dis2)*2
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <functional>

using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int t, x;
	cin >> t >> x;
	float ta;
	ta = (float)t / (float)x;
	cout << ta;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long n;
    cin >> n;

    long min_num = LONG_MAX;
    for (int i=0; i<5; i++) {
        long a;
        cin >> a;
        min_num = min(min_num, a);
    }

    long ans = (n/min_num)+5;
    if (n%min_num == 0) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	string s;
	string b[4] = {"A", "B", "AB", "O"};
	int ret[4];
	rep(i,4) {
		ret[i] = 0;
	}
	while(cin >> s) {
		string t;
		for(int i = 0; i < s.length(); i++) {
			if(isalpha(s[i])) t+= s[i];
		}
		rep(i,4) {
			if(t == b[i]) ret[i]++;
		}
	}
	rep(i,4) {
		cout << ret[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <cstdio>

int main()
{
	int n;
	int map[10010];

	int i;
	for (i = 0; i < 10010; i++) {
		map[i] = 0;
	}

	for (i = 1; i < 100; i++) {
		int j;
		for (j = 1; j < 100; j++) {
			int k;
			for (k = 1; k < 100; k++) {
				if (i * i + j * j + k * k + i * j + j * k + k * i > 10000) {
					break;
				} else {
					map[i * i + j * j + k * k + i * j + j * k + k * i]++;
				}
			}
		}
	}

	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		printf("%d\n", map[i]);
	}

	return 0;
}

Measured memory_bytes: 1720
#include<stdio.h>
int main(){
  int W,H,x,y,r,i;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x-r>=0 && x+r<=W){
    if(y-r>=0 && y+r<=H)printf("Yes\n");
    else printf("No\n");
    return 0;
  }
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  double a,b;
  double h[2][8]={
    {70,55,50,43,40,37.5,35.5,-1},
    {148,116,105,89,83,77,71,-1}
  };
  string s[8]={"NA","E","D","C","B","A","AA","AAA"};
  while(cin>>a>>b){
    int i;
    rep(i,8)if(a>=h[0][i]||b>=h[1][i])break;
      cout<<s[i]<<endl;
  }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int N; cin >> N;
    vector <int> A(N);
    rep(i,N) cin >> A[i];
    rep(i,N) A[i]--;
    
    vector <int> cnt(N);
    rep(i,N) cnt[A[i]]++;
    
    ll sum=0;
    rep(i,N) sum+=choose2(cnt[i]);
    
    rep(i,N){
        ll ans=sum;
        ans-=choose2(cnt[A[i]]);
        ans+=choose2(cnt[A[i]]-1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
const int MAXN = 4e5 + 10;
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int a[MAXN], b[MAXN], ta[MAXN], tb[MAXN], sa, sb, tot = 0, date[MAXN], fa[MAXN];
map<int, bool> ti;
int find(int x) {
    return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
}
int unionn(int x, int y) {
    fa[x] = y;
}
int main() {
    N = read();
    for(int i = 1; i <= N; i++) a[i] = read(), sa ^= a[i]; a[N + 1] = sa;
    for(int i = 1; i <= N; i++) b[i] = read(), sb ^= b[i]; b[N + 1] = sb;
    N++;
    memcpy(ta, a, sizeof(a)); memcpy(tb, b, sizeof(b));
    sort(ta + 1, ta + N + 1); sort(tb + 1, tb + N + 1);
    for(int i = 1; i <= N - 1; i++) if(ta[i] != tb[i]) return puts("-1"), 0;
 
    int ans = 0, num = 0;
    for(int i = 1; i <= N; i++) 
        if(a[i] != b[i] || (i == N)) {
            date[++num] = a[i]; date[++num] = b[i];
            if(i < N)ans++;//最后一块单独考虑
        }
    if(ans == 0) return puts("0"), 0;
 
    sort(date + 1, date + num + 1);
    num = unique(date + 1, date + num + 1) - date - 1;
    for(int i = 1; i <= num; i++) fa[i] = i;
    for(int i = 1; i <= N; i++)
        if(a[i] != b[i]) {
            a[i] = lower_bound(date + 1, date + num + 1, a[i]) - date,
            b[i] = lower_bound(date + 1, date + num + 1, b[i]) - date;
            if(!ti[a[i]]) ti[a[i]] = 1;
            if(!ti[b[i]]) ti[b[i]] = 1;
            unionn(find(a[i]), find(b[i]));
        }
        
    for(int i = 1; i <= num; i++)
        if(fa[i] == i) ans++;
    printf("%d", ans - 1);
 
    return 0;
}

Measured memory_bytes: 13568
package main

import (
    "fmt"
    "os"
    "bufio"
    "strings"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func StrStdin() (stringInput string){
  sc.Scan()
  OneLineString := sc.Text()
  stringInput = strings.TrimSpace(OneLineString)
  return 
}

func IntStdin() (int, error){
  stringInput := StrStdin()
  return strconv.Atoi(stringInput)
}

// ?????????????l??????????Split()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
    stringSplited := strings.Split(stringTargeted, delim)

    for _, str := range stringSplited {
        if str != "" {
            stringReturned = append(stringReturned, str)
        }
    }

    return
}

// ?f???~?^??????????????X???C?X???��
func SplitStrStdin(delim string) (stringReturned []string) {
    // ???????1?s?��
    stringInput := StrStdin()
  
    // ???????
    // stringSplited := strings.Split(stringInput, delim)
    stringReturned = SplitWithoutEmpty(stringInput, delim)

    return
}

// ?f???~?^?????????????l?X???C?X???��
func SplitIntStdin(delim string) (intSlices []int, err error) {
    // ??????X???C?X???��
    stringSplited := SplitStrStdin(delim)
	
    // ?????X???C?X????
    for i := range stringSplited {
        var iparam int
        iparam, err = strconv.Atoi(stringSplited[i])
        if err != nil {
            return
        }
        intSlices = append(intSlices, iparam)
    }
    return
}

func main(){
  sum, err1 := IntStdin()
  cake, err2 := IntStdin()
  donutus, err3 := IntStdin()
  
  nokori := 0
  if err1 == nil && err2 == nil {
  	nokori = sum - cake
  }
  
  if err3 ==nil {
    for ; nokori >= donutus; {
    	nokori -= donutus
    }
  }

  fmt.Println(nokori)
}

Measured memory_bytes: 640
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, std::string x){
    vector<int> res(300000);
    for(int i = 0; i < 300000; ++i){
        int y = i;
        int cnt = 0;
        while(y){
            y = y % __builtin_popcount(y);
            ++cnt;
        }
        res[i] = cnt;
    }

    vector<int> mod(3, 0);
    int pcnt = 0;

    for(int i = 0; i < n; ++i){
        if(x[i] == '1'){
            ++pcnt;
        }
    }

    vector<vector<int>> add_mod(n, vector<int>(3, 1));
    for(int i = 1; i < n; ++i){
        for(int j = 0; j < 3; ++j){
            if(pcnt + j - 1 < 2)
                continue;
            add_mod[i][j] = (add_mod[i - 1][j] * 2) % (pcnt + j - 1);
        }
    }

    auto update = [&](int i, bool fl){
        for(int j = 0; j < 3; ++j){
            if(pcnt + j - 1 < 2)
                continue;
            if(fl){
                mod[j] += add_mod[i][j];
                mod[j] %= (pcnt + j - 1);
            }
            else{
                mod[j] += (pcnt + j - 1) - add_mod[i][j];
                mod[j] %= (pcnt + j - 1);
            }
        }
    };

    for(int i = 0; i < n; ++i){
        if(x[i] == '1'){
            update(i, true);
        }
    }

    for(int i = n - 1; i >= 0; --i){
        auto pre = mod;
        if(x[i] == '1')
            update(i, false);
        else
            update(i, true);
        int ans = [&]{
            int pc = pcnt + (x[i] == '0' ? 1 : -1);
            if(pc == 0)
                return 0;
            else if(pc == 1)
                return 1;
            else
                return res[mod[x[i] == '0' ? 2 : 0]] + 1;
        }();
        printf("%d\n", ans);
        mod = move(pre);
    }
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::string X;
    std::cin >> X;
    reverse(X.begin(), X.end());
    solve(N, X);
    return 0;
}


Measured memory_bytes: 15864
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
x,y=map(int,input().split())
if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
elif x in c and y in c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll>P;
vector<P>vec;
ll sum[200009];

int main(){
  ll n,d,a;
  ll x[200009];
  ll ans=0;

  cin>>n>>d>>a;
  for(int i=0;i<n;i++){
    ll h;
    cin>>x[i]>>h;
    vec.push_back(P(x[i],h));
  }
  sort(vec.begin(),vec.end());
  sort(x,x+n);

  for(int i=0;i<n;i++){
    if(i>0)sum[i]+=sum[i-1];
    int nx=vec[i].first;
    int nh=max(vec[i].second-sum[i],0ll);
    int idx=upper_bound(x,x+n,nx+d*2)-x;
    int cnt=nh/a;
    if(nh%a!=0)cnt++;
    sum[i]+=a*cnt;
    sum[idx]-=a*cnt;
    ans+=cnt;
  }

  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 7408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				int m=sc.nextInt();
				if(n+m==0) break;
				
				int[] p=new int[n+2];
				for(int i=0; i<n; i++) {
					p[i]=sc.nextInt();
				}
				p[n]=0;
				int[] sum=new int[(n+1)*(n+1)];//後でsortするからサイズはちょうどにする
				int size=0;
				for(int i=0; i<n+1; i++) {
					for(int j=0; j<n+1; j++) {
						sum[size]=p[i]+p[j];
						size++;
					}
				}//2本分で取れる得点
				Arrays.sort(sum);
				int ans=0;
				for(int i=0; i<size; i++) {
					int rem=m-sum[i];//残り2本の得点maxを探す
					if(rem<0) continue;
					int left=0, right=size;
					
					while(left<right) {//binary search
						int mid=(left+right)/2;
						if(rem>sum[mid]) {
							left=mid+1;
						}
						else if(rem<sum[mid]) {
							right=mid;
						}
						else {
							break;
						}
					}
					ans=Math.max(ans, sum[i]+sum[right-1]);
				}
				System.out.println(ans);

			}
		}
	}
}




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

int main(){
  int t,n,s,f,r;

  cin >> t;
  while(t){
    r = 0;
    cin >> n;
    for(int i=0; i<n; i++){
      cin >> s >> f;
      r += (f-s);
    }
    if(r >= t)
      cout << "OK\n";
    else
      cout << t-r << endl;
    cin >> t;
  }

  return 0;
}

Measured memory_bytes: 1160
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> as(n), bs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i] >> bs[i];
    }
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());
    int ans = 0;
    if (n & 1)
    {
        ans = bs[n / 2] - as[n / 2] + 1;
    }
    else
    {
        int m1 = as[n / 2] + as[n / 2 - 1];
        int m2 = bs[n / 2] + bs[n / 2 - 1];
        if (m1 & 1)
        {
            ans--;
        }
        if (m2 & 1)
        {
            ans++;
        }
        m1 >>= 1;
        m2 >>= 1;
        ans += (m2 - m1) * 2 + 1;
        //print(m1, m2);
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int MAXN=1e5+55;
int a[MAXN];
int N;
bool vis[MAXN];
int Count(int pos){
    int val=a[pos];
    int cnt=0;
    for(int i=pos;i>=0;--i){
        if(abs(a[i]-val)<=1) cnt++;
        else break;
    }
    for(int i=pos+1;i<N;++i){
        if(abs(a[i]-val)<=1) cnt++;
        else break;
    }
    return cnt;
}

int main(){
    scanf("%d",&N);
    rep(i,0,N) scanf("%d",&a[i]);
    sort(a,a+N);
    int ans=0;
    rep(i,0,N){
        if(vis[a[i]]) continue;
        ans=max(ans,Count(i));
        vis[a[i]]=1;
    }
    cout<<ans<<endl;
}


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


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    ng = set()
    for a, b in zip(A, B):
        if H[a-1] < H[b-1]:
            ng.add(a)
        elif H[b-1] < H[a-1]:
            ng.add(b)
        else:
            ng.add(a)
            ng.add(b)
    print(N - len(ng))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()

Measured memory_bytes: 91044
//@author Khaled Alam(Ninjo) ~ KhaledAlam.net
#include <bits/stdc++.h>
using namespace std;
// Template(v0.0.1)  |  Github.com/khaledalam/templates/tree/master/cpp
typedef long long ll;
typedef vector<int> vi;
typedef stringstream ss;
typedef pair<int, int> pii;
//#########################
#define endl         '\n'
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define out(x)       return cout<<x,0
#define all(x)       x.begin(),x.end()
#define sz(x)        ((int)(x.size()))
#define clr(x)       memset(x,0,sizeof x)
#define rep(i,n)     for(int i=0;i<n;i++)
#define ifile(x)     freopen(#x,"r",stdin)
#define ofile(x)     freopen(#x,"w",stdout)
#define pin0(x)      size_t x = time(NULL)
#define pin1(x)      fprintf(stderr,"time: %.2fs\n",(float)time(NULL)-x)
#define foreach(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();i++)
#define ios          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define val(x)       cerr<<"[l#: "<<__LINE__<<"] "<< " "<<#x<<" = "<<x<<'\n'
//##########################################################################

int main()
{
//	ios;
//	ifile(input.txt); //ofile(output.txt);

//	cout << __gcd(0, 5);
//	return 0;
	char a, b;
	cin >> a >> b;
	puts(a == '9' || b == '9' ? "Yes" : "No");
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
typedef pair<int,int> P;
int n;
int x[MAX_N],y[MAX_N],w;
map<P,int> t;

int f(int x,int y){
  return t[P(x,y)]+t[P(x+1,y)]+t[P(x,y+1)]+t[P(x+1,y+1)];
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>w;
    t[P(x[i],y[i])]+=w;
  }
  int maxm=0;
  for(int i=0;i<n;i++){
    maxm=max(maxm,f(x[i]-1,y[i]-1));
    maxm=max(maxm,f(x[i],y[i]-1));
    maxm=max(maxm,f(x[i]-1,y[i]));
    maxm=max(maxm,f(x[i],y[i]));
  }
  cout<<maxm<<" / 1"<<endl;
  return 0;
}

Measured memory_bytes: 58228
var print = console.log;

function read_input(_input) {
    var lines = _input.split("\n");
    return function () {
        return lines.shift();
    };
}

String.prototype.dot = function dot(x) {
    var res = "";
    for (var i = 0; i < x; i++) {
        res += this.toString();
    }
    return res;
};

function IL(line, min1Flg) {
    var s = line.split(' ');
    var offset = min1Flg ? -1 : 0;
    var res = [];
    for (var i = 0; i < s.length; i++) {
        res.push(parseInt(s[i]));
    }
    return res;
}

function range(i, n) {
    var res = [];
    for (; i < n; i++) {
        res.push(i);
    }
    return res;
}

function IMAX(x, y) {
    return x > y ? x : y;
}

function IMIN(x, y) {
    return x < y ? x : y;
}

function item_getter_key(x) {
    return function (a, b) {
        if (a[x] < b[x]) return -1;
        else if (a[x] > b[x]) return 1;
        return 0;
    };
}

/**
 * @return {number}
 */
Array.prototype.SUM = function SUM() {
    var sum = 0;
    this.forEach(function (elm) {
        sum += elm;
    });
    return sum;
};

Array.prototype.FORM = function FORM(){
    return this.map(function(v){return ('        ' + v).slice(-5)});
};


/*

(((???????????)??? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

*/


// input?????\??????????????¨????????\???
function Main(_input) {

    var lines = _input.split("\n");
    while (lines.length > 0) {
        var csum = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        var N = lines.shift() - 0;
        if (N === 0) {
            return;
        }
        for (var i = 0; i < N; i++) {
            var tmp = IL(lines.shift());
            tmp.push(tmp.SUM());
            print(tmp.FORM().join(''));
            for (var j = 0; j < N + 1; j++) {
                csum[j] += tmp[j];
            }
        }
        print(csum.splice(0, N + 1).FORM().join(''));
    }
}

//*???????????\????????¨??????????????§????????????????¨??????\????????????????????????????????????Main????????????????????????
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//Main(require("fs").readFileSync("input.txt", "utf8"));

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

#define all(x) (x).begin(),(x).end()

long long inp()
{
    long long x;
    cin >> x;
    return x;
}

const long long INF = 1e18 + 420;
const long long maxn = 1e5 + 69, sz = 64, Ccnt = 6;

long long a,b;
int main(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);

    cin >> a >> b;
    long long ans = 0;
    for(long long i=59; i>=0; i--)
        if((a&(1ll<<i))==(b&(1ll<<i))){
            if(a&(1ll<<i))
                a-=(1ll<<i),b-=(1ll<<i);
        }
        else{
            long long tmp=(1ll<<i);
            long long r=tmp*2-1;
            long long l=tmp+a;
            long long L=tmp;
            long long R=tmp;
            for(long long j=i-1; j>=0; j--){
                if(b&(1ll<<j)){
                    R+=(1ll<<(j+1))-1;
                    break;
                }
            }
            if(l<=R)
                ans+=(r-L+1);
            else
                ans+=(r-l+1)+(R-L+1);
            ans+=L-a;
            cout << ans;
            exit(0);
        }
    cout <<"1\n";
}


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

enum Status {New, Active, Finished};

vector<vector<int> > adj;
vector<Status> stat;
vector<int> path_length;

int match_number(int n, int a, int b) {
    if (a > b)
        swap(a, b);
    //cout << a <<  ' ' << b << endl;
         
    int ret = a * (n - 1) + b - a * (a + 1) / 2;
    //cout << ret << endl;
    return ret;
}

bool is_acyclic(int v) {
    stat[v] = Active;
    for (int u: adj[v]) {
        if (stat[u] == Active) {
            //cout << u << endl;
            return false;
        }
        if (stat[u] == New) {
            if (!is_acyclic(u))
                return false;
        }
    }
    stat[v] = Finished;
    return true;
}

int longest_path_length(int v) {
    int ret = 0;
    for (int u: adj[v]) {
        if (path_length[u] >= 0)
            ret = max(ret, path_length[u] + 1);
        else
            ret = max(ret, longest_path_length(u) + 1);
    }
    path_length[v] = ret;
    return ret;
}

int main() {
    int n;
    cin >> n;
    int a[n][n - 1];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    const int m = (n - 1) * n / 2;
    adj = vector<vector<int> >(m + 1);
    stat = vector<Status>(m + 1);
    path_length = vector<int>(m + 1);
    fill(stat.begin(), stat.end(), New);
    fill(path_length.begin(), path_length.end(), -1);
    for (int i = 0; i < n; i++) {
        adj[0].push_back(match_number(n, i, a[i][0]));
    }
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n - 1; j++) {
            adj[match_number(n, i, a[i][j - 1])].push_back(match_number(n, i, a[i][j]));
        }
    }

    if (!is_acyclic(0)) {
        cout << -1 << endl;
        return 0;
    }

    cout << longest_path_length(0) << endl;
    return 0;
}




Measured memory_bytes: 35456
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int ans = 0;

        for (int i = 0; i < K; i++) {
            if (A > 0) {
                ans++;
                A--;
            } else if (B > 0) {
                B--;
            } else if (C > 0) {
                ans--;
                C--;
            }
        }

        System.out.println(ans);
    }
}




Measured memory_bytes: 36280
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位
vector<int> G[1000000];
int black[100001], white[100001];


signed main() {
	int N;
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	//白黒を始点にBFSをする
	queue<int> q,r;
	//黒
	black[1] = 1;
	q.push(1);
	while (!q.empty()) {
		int node = q.front();
		q.pop();
		for (int i : G[node]) {
			if (black[i] != 0) continue;
			black[i] = black[node] + 1;
			q.push(i);
		}
	}
	white[N] = 1;
	r.push(N);
	while(!r.empty()){
		int node = r.front();
		r.pop();
		for (int i : G[node]) {
			if (white[i] != 0) continue;
			white[i] = white[node] + 1;
			r.push(i);
		}
	}

	int fennec = 0, snuke = 0;
	for (int i = 1; i <= N; i++) {
		if (black[i] <= white[i]) {
			fennec++;
		}
		else {
			snuke++;
		}
	}
	if (fennec > snuke) cout << "Fennec\n";
	else cout << "Snuke\n";
	


	return 0;
}

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

int main() {
    string s,t;
    cin >> s;
    cin >> t;
    ll ans=0,count=0;
    rep(i, s.length() - t.length()+1){
        rep(j,t.length()){
            if (s[i+j] == t[j]) {
                count += 1;
            }
        }
        if (ans <= count) {
            ans = count;
        }
        count = 0;
    }
    cout << t.length() - ans << endl;
    return 0;
}

Measured memory_bytes: 3616
h, w, k = map(int, input().split())
C = [input() for i in range(h)]
ans = 0

for rows in range(1 << h):
    for cols in range(1 << w):
        cnt = 0
        for i in range(h):
            if (rows >> i) & 1: continue
            for j in range(w):
                if (cols >> j) & 1:
                    continue
                else:
                    if C[i][j] == "#": cnt += 1
        if cnt == k: ans += 1

print(ans)
                
                


Measured memory_bytes: 9104
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
    ll s;   cin >> s;
    ll ans = 0;
    ll k = s/3;

    COMinit();

    for (ll l = 1; l <= s/3; l++) {
        ll n = s - 3*l;
        ans = (ans + COM(n+l-1, l-1)) % MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27056
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    A[i+1] = "[{}]".format(A[i+1])


n = int(input())
A = list(map(int, input().split()))
partition(A, 0, n-1)
print(*A)



Measured memory_bytes: 16388
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,m = MI()
py = LI(m)

py_new = []
no = 0
for i in range(m):
    no += 1
    p = py[i][0]
    y = py[i][1]
    py_new.append([no,p,y])

py_new_sorted = mysort(py_new,2,False)

g = [ [] for _ in range(n) ]

no = 0
py_now = []
for i in range(m):
    no = py_new_sorted[i][0]
    p = py_new_sorted[i][1] - 1
    y = py_new_sorted[i][2]
    x = len(g[p]) + 1
    py_now.append([no,p,y,x])
    g[p].append(y)

py_now = mysort(py_now,0,False)

for i in range(m):
    p = str( py_now[i][1] + 1 )
    x = str(py_now[i][3])
    p = p.zfill(6)
    x = x.zfill(6)
    a = p + x
    print(a)

Measured memory_bytes: 104536
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var pre = sc.nextInt()
    val set = mutableSetOf(pre)
    var m = 2
    while (true) {
        pre = if (pre % 2 == 0) pre / 2 else 3 * pre + 1
        if (set.contains(pre)) {
            println(m)
            break
        }
        set.add(pre)
        m++
    }
}

Measured memory_bytes: 34000
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using namespace std;

int main() {
    unsigned int x;
    cin >> x;
    if (x == 0) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3156
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

ll n, dp[100005], a[100005], k;

ll rec(ll n)
{
	if(dp[n] != -1) return dp[n];
	ll val = 1e18;
	for(int i=max(0ll, n - k);i<n;i++)
		val = min(val, rec(i) + abs(a[i] - a[n]));
	return dp[n] = val;
}

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

    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> a[i];
    memset(dp, -1, sizeof(dp));
	dp[0] = 0;
    cout << rec(n - 1) << endl;	
    return 0;
}

Measured memory_bytes: 4608
using System;
using System.Collections.Generic;
using System.Drawing;

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var hwk = ReadLongArray();
		var h = (int)hwk[0];
		var w = (int)hwk[1];
		var k = (int)hwk[2];

		var xyxy = ReadLongArray();
		var x1 = (int)xyxy[1];
		var y1 = (int)xyxy[0];
		var x2 = (int)xyxy[3];
		var y2 = (int)xyxy[2];

		var q = new Queue<Point>();
		q.Enqueue(new Point(x1, y1));

		var c = new int[h + 2, w + 2];
		for (var y = 1; y <= h; y++) {
			var s = Console.ReadLine();
			for (var x = 0; x < s.Length; x++) {
				if (s[x] != '@') c[y, x + 1] = int.MaxValue;
			}
		}
		c[y1, x1] = 0;

		while (q.Count != 0) {
			var p = q.Dequeue();
			var n = c[p.Y, p.X] + 1;

			for (var x = 1; x <= k; x++) {

				if (c[p.Y, p.X + x] <= n) {
					if (c[p.Y, p.X + x] != n) break;
					continue;
				}
				c[p.Y, p.X + x] = n;
				q.Enqueue(new Point(p.X + x, p.Y));
			}
			for (var x = 1; x <= k; x++) {
				if (c[p.Y, p.X - x] <= n) {
					if (c[p.Y, p.X - x] != n) break;
					continue;
				}
				c[p.Y, p.X - x] = n;
				q.Enqueue(new Point(p.X - x, p.Y));
			}
			for (var y = 1; y <= k; y++) {
				if (c[p.Y + y, p.X] <= n) {
					if (c[p.Y + y, p.X] != n) break;
					continue;
				}
				c[p.Y + y, p.X] = n;
				q.Enqueue(new Point(p.X, p.Y + y));
			}
			for (var y = 1; y <= k; y++) {
				if (c[p.Y - y, p.X] <= n) {
					if (c[p.Y - y, p.X] != n) break;
					continue;
				}
				c[p.Y - y, p.X] = n;
				q.Enqueue(new Point(p.X, p.Y - y));
			}
		}

		Console.WriteLine(c[y2, x2] == int.MaxValue ? -1 : c[y2, x2]);
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


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

using namespace std;


void solve() {
    int a,b;
    cin >> a >> b;
    if (a > b)swap(a,b);
    for (int _ = 0; _ < b; _++) {
        cout << a;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int d[105][3];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>d[i][1]>>d[i][2];
	}
	int maxn=0;
	int cnt=0; 
	for(int i=1;i<=n;i++){
		if(d[i][1]==d[i][2])cnt++;
		else{
			maxn=max(maxn,cnt);
			cnt=0;
		}
	}
	maxn=max(maxn,cnt);
	if(maxn>=3)cout<<"Yes";
	else cout<<"No";
	return 0;
} 

Measured memory_bytes: 3628
n = int(input())
s = input()

dicts = {'R':0, 'G':0, 'B':0}
for i in s:
    dicts[i] += 1

ans = dicts['R'] * dicts['G'] * dicts['B']

for i in range(1, (n - 3) // 2 + 2):
    for j in range(0, n):
        if j + i * 2 >= n:
            break
        if s[j] != s[j + i] and s[j] != s[j + 2 * i] and s[j + i] != s[j + 2 * i]:
            ans -= 1

print(ans)


Measured memory_bytes: 9204
N = int(input())
A_l = [int(i) for i in input().split()]
a_sum = 0

A_l = [i for i in A_l if i != 0]

sum_l = [0] * len(A_l)
for i in range(len(A_l)):
    if i == 0:
        sum_l[i] = A_l[i]
    else:
        sum_l[i] = sum_l[i-1] + A_l[i]

for i in range(len(A_l)-1):
    a_sum = a_sum + sum_l[i] * A_l[i+1]
print(a_sum % (10**9+7))

Measured memory_bytes: 31548
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int line = Integer.parseInt(br.readLine());

        if(line == 1){
            System.out.println(line);
        }
        else{
            int x = 1;
            for(; x <= line;){
                x = x * 2;            
            }
            
            x = x / 2;
            System.out.println(x);
        }
    }
}


Measured memory_bytes: 21076
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

map<long long int, int>mp;
int getans(const long long int n) {
	if (n < 0)assert(false);
	if (mp.find(n) != mp.end())return mp[n];
	else {
		int ans = n==1?0:n % 2 ? (1 + getans(3 * n + 1)) : (1 + getans(n / 2));
		return mp[n] = ans;
	}
}

int main() {
	while (1) {
		long long int N; cin >> N;
		if (!N)break;
		int ans = getans(N);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3008
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

ll a[25][25];
ll dp[22][1<<22];
ll n;

ll rec(ll now, ll S){
	if(S==0) return 1;
	if(now==n) return 0;
	if(dp[now][S] != inf) return dp[now][S];
	ll res = 0;
	rep(i,n){
		if(a[now][i] && (S>>i & 1)){
			res += rec(now+1,S-(1<<i));
			res %= mod;
		}
	}
	return dp[now][S] = res;
}

int main(){
	cin >> n;
	rep(i,n) rep(j,n) cin >> a[i][j];
	rep(i,n) rep(j,1<<n) dp[i][j] = inf;
	cout << rec(0,(1<<n)-1) << endl;
}

Measured memory_bytes: 387328
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int N, M, P[100005];
long long int Y[100005];
vector<long long int> V[100005];

int main(void) {

	cin >> N >> M;

	

	for (int i = 1; i <= M; i++) {
		cin >> P[i] >> Y[i];
	}

	for (int i = 1; i <= M; i++) {
		V[P[i]].push_back(Y[i]);
	}

	for (int i = 1; i <= N; i++) {
		sort(V[i].begin(), V[i].end());
	}

	for (int i = 1; i <= M; i++) {
		int H = P[i];
		int pos = lower_bound(V[H].begin(), V[H].end(), Y[i]) - V[H].begin()+1;
		//cout << pos << endl;

		cout << setfill('0') << right << setw(6) << P[i];
		cout << setfill('0') << right << setw(6) << pos << endl;
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 8192