akhauriyash/Code-Regression huggingface dataset:
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
    for j in range(3):
      for k in range(n):
        if a[i][j] == b[k]:
            a[i][j] = 0
ans = 'No'
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2] == 0:
        ans = 'Yes'
    if a[0][i]+a[1][i]+a[2][i] == 0:
        ans = 'Yes'
if a[0][0]+a[1][1]+a[2][2] == 0 or a[2][0]+a[1][1]+a[0][2] == 0:
    ans = 'Yes'
print(ans)


Measured memory_bytes: 3064
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(){
        string r,g,b; cin>>r>>g>>b;
        string s = r+g+b;
        int ans = stoi(s);
        cout << (ans%4==0 ? "YES":"NO") << endl;
        return 0;
}


Measured memory_bytes: 504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int t = scanner.nextInt();
		int a = scanner.nextInt();
		int x = 0;
		int ans = 0;
		int min = 100000000;
		int res = 0;
		for (int i = 0; i < n; i++) {
			x = scanner.nextInt();
			ans = (t * 1000) - (x * 6) - (a * 1000);
			if(ans < 0) ans = -ans;
			if(ans < min) {
				min = ans;
				res = i;
			}
		}
		
		System.out.println(res + 1);
		scanner.close();

	}

}


Measured memory_bytes: 22612
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll a_base2(ll n, ll a, ll i){return i==1?n%a:a_base2(n/a,a,i-1);}


int main(void){
    char s[105];
    ll n,k;
    scanf("%s%lld",s,&k);
    n=strlen(s);
    ll dp[n][2][4];
    ll x=s[0]-'0';
    rep(i,0,n) rep(j,0,2) rep(k,0,4) dp[i][j][k]=0;

    if(x>0){
        dp[0][0][0]=1;
        dp[0][0][1]=x-1;
        dp[0][1][0]=0;
        dp[0][1][1]=1;
    }
    if(x==0){
        dp[0][0][0]=0;
        dp[0][0][1]=0;
        dp[0][1][0]=1;
        dp[0][1][1]=0;
    }

    rep(i,1,n){
        x = s[i]-'0';
        // printf("%lld\n",x);
        rep(j,0,4){
            if(x==0){
                dp[i][0][j] = dp[i-1][0][j]*1 + dp[i-1][1][j]*0 + ( j>0 ? dp[i-1][1][j-1]*0 + dp[i-1][0][j-1]*9 : 0 ) ;
                dp[i][1][j] = dp[i-1][0][j]*0 + dp[i-1][1][j]*1 + ( j>0 ? dp[i-1][1][j-1]*0 + dp[i-1][0][j-1]*0 : 0 ) ;
            }else{
                dp[i][0][j] = dp[i-1][1][j]*1 + dp[i-1][0][j]*1 + ( j>0 ? dp[i-1][0][j-1]*9 + dp[i-1][1][j-1]*(x-1) : 0 ) ;
                dp[i][1][j] = dp[i-1][1][j]*0 + dp[i-1][0][j]*0 + ( j>0 ? dp[i-1][0][j-1]*0 + dp[i-1][1][j-1]*1 : 0 ) ;
            }
        }
    }

    // rep(i,0,n){
    //     rep(j,0,2){
    //         rep(k,0,4){
    //             printf("%lld ",dp[i][j][k]);
    //         }
    //         PN;
    //     }
    //     PN;
    // }
    // PN;
    printf("%lld\n",dp[n-1][0][k]+dp[n-1][1][k]);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int bfs(int c, int r);
vector< vector<int> > M(20, vector<int>(20, 0));
int H, W;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int main() {

    cin >> H >> W;
    vector< pair<int, int> > P;
    for (int i = 0; i < H; i++)  {
        string S;
        cin >> S;
        for (int j = 0; j < W; j++) {
            if (S[j] == '.') {
                M[i][j] = 1;
                P.push_back(make_pair(i, j));
            }
        }
    }

    /*
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << M[i][j] << ' ';
        }
        cout << '\n';
    }
    */

    int ans = 0;
    for (int i = 0; i < P.size(); i++) {
        int dist = bfs(P[i].first, P[i].second);
        ans = max(dist, ans);
    }
    cout << ans << '\n';

}

int bfs(int c, int r) {

    vector< vector<int> > visited(20, vector<int>(20, -1));

    queue<pair<int, int> > q;
    q.push(make_pair(c, r));
    visited[c][r] = 0;

    int next_c, next_r;
    int max_dist = 0;
    pair<int, int> point;
    while (!q.empty()) {

        point = q.front(); q.pop();

        for (int i = 0; i < 4; i++) {
            next_c = point.first + dx[i];
            next_r = point.second + dy[i];

            if (next_c < 0 || H <= next_c || next_r < 0 || W <= next_r ) {
                continue;
            }
            if (visited[next_c][next_r] != -1)
                continue;
            if (M[next_c][next_r] == 0)
                continue;

            visited[next_c][next_r] = visited[point.first][point.second] + 1;
            q.push(make_pair(next_c, next_r));
            max_dist = max(visited[next_c][next_r], max_dist);
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            max_dist = max(visited[i][j], max_dist);
        //     cout << visited[i][j] << ' ';
        }
        // cout << '\n';
    }
    // cout << "max_dist : " << max_dist << '\n';

    return max_dist;

}


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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
int dp[2][201][10010];  // dp[i][j][k]=i番目までで、最後に使わなかったのがj番目で重さの合計がkになる組み合わせの数
void solve() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    REP(i, N) { cin >> w[i]; }
    dp[0][0][0] = 1;
    sort(w.rbegin(), w.rend());
    REP(i, N) {
        int now = i % 2;
        int nxt = (i + 1) % 2;
        REP(j, N + 1) REP(k, W + 1) dp[nxt][j][k] = 0;
        REP(j, i + 1) {
            REP(k, W + 1) {
                if (dp[now][j][k] == 0) continue;
                //使う
                if (k + w[i] <= W) {
                    dp[nxt][j][k + w[i]] += dp[now][j][k];
                    dp[nxt][j][k + w[i]] %= MOD;
                }

                //使わない
                dp[nxt][i + 1][k] += dp[now][j][k];
                dp[nxt][i + 1][k] %= MOD;
            }
        }
    }
    int idx = N % 2;
    int ans = 0;
    REP(j, N + 1) {
        REP(k, W + 1) {
            int unuse = 1e9;
            if (j >= 1) {
                unuse = w[j - 1];
            }
            if (W - k < unuse) {
                // cerr << j << " " << k << " " << dp[idx][j][k] << endl;
                ans += dp[idx][j][k];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}

signed main() {
    // while (solve())
    solve();
}


Measured memory_bytes: 34408
#include <bits/stdc++.h>
#define USE_MATH_DEFINES
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

long long gcd(long long m, long long n) {
    if ((0 == m) || (0 == n))
        return 0;

    while (m != n) {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

long long lcm(long long m, int n) {
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ans = b - a + 1;
    a -= 1;
    ans -= (b / c - a / c);
    ans -= (b / d - a / d);
    ans += (b / lcm(c, d) - a / lcm(c, d));
    cout << ans << endl;
}


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

int main(){
	int n,ans = 0 ; cin >> n ;
	vector<int> a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	for(int i=1;i<n-1;i++)	if((a.at(i-1)<a.at(i)&&a.at(i)<a.at(i+1))||(a.at(i-1)>a.at(i)&&a.at(i)>a.at(i+1))) ans++ ;	
	cout << ans << endl ;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int side(int c) {
	if (c % 3 == 1)return 1;
	if (c % 3 == 2)return 2;
	if (c % 3 == 0)return 3;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		string s;
		cin >> s;
		if (s[0] == '#')break;
		int n = s.size();
		vvi dp(n, vi(2, INF));
		dp[n - 1][0] = 0;
		dp[n - 1][1] = 0;
		RREP(i, n - 1) {
			if (side(s[i] - '0') < side(s[i + 1] - '0')) {
				dp[i][0] = dp[i + 1][0] + 1;
				dp[i][1] = min(dp[i + 1][0], dp[i + 1][1]+1);
			}
			else if (side(s[i] - '0') > side(s[i + 1] - '0')) {
				dp[i][0] = min(dp[i + 1][0] + 1, dp[i + 1][1]);
				dp[i][1] = dp[i + 1][1] + 1;
			}
			else {
				dp[i][0] = min(dp[i + 1][0] + 1, dp[i + 1][1]);
				dp[i][1] = min(dp[i + 1][0], dp[i + 1][1] + 1);
			}
		}

		cout << min(dp[0][0], dp[0][1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 8724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    }
}



Measured memory_bytes: 21844
#include <stdio.h>

#define N 36

typedef struct {
	char mark;
	int num;
} trump;

void BubbleSort(trump *C, int n) {
	int i,j;
	trump tmp;

	for (i = 0; i < n; i++)  {
		for (j = n-1; j > i; j--){
			if (C[j].num < C[j-1].num) {
				tmp = C[j];
				C[j] = C[j-1];
				C[j-1] = tmp;
			}
		}
	}
	for (i = 0; i < n-1; i++) 
		printf("%c%d ", C[i].mark, C[i].num);
	printf("%c%d\n", C[i].mark, C[i].num);
	printf("Stable\n");
}

void SelectionSort(trump *C, int n) {
	int i,j;
	int min_index;
	trump tmp;

	for (i = 0; i < n; i++) {
		min_index = i;
		for(j = i; j < n; j++) {
			if (C[j].num < C[min_index].num) min_index = j;
		}
		tmp = C[i];
		C[i] = C[min_index];
		C[min_index] = tmp;
	}

	for (i = 0; i < n-1; i++) 
		printf("%c%d ", C[i].mark, C[i].num);
	printf("%c%d\n", C[i].mark, C[i].num);
}

int isStable(trump *C1, trump *C2, int n) {
	int i;

	for (i = 0; i < n; i++) {
		if(C1[i].mark == C2[i].mark && C1[i].num == C2[i].num) continue;
		
		return 0;
	}

	return 1;
}

int main() {
	int i,n;
	trump C1[N], C2[N];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf(" %c%d", &C1[i].mark, &C1[i].num);
		C2[i] = C1[i];
	}

	BubbleSort(C1, n);
	SelectionSort(C2, n);
	if(isStable(C1, C2, n) == 0) printf("Not stable\n"); 
	else printf("Stable\n");

	return 0;
}

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


int main () {
  int n ;
  cin >> n;
  vector<int> a (n);
  vector<int> b (n);
  vector<int> c (n - 1);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  rep(i,n - 1){
    cin >> c[i];
  }
  int ans = 0;
  rep(i, n){
    ans += b[i] ;
  }
  rep(i, n){
    if(i != 0){
    if(a[i] == a[i-1] + 1){
      ans += c[a[i] - 2];
    } 
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int64_t ssum (int64_t n) { return (n + 1) * n / 2; }

int main ()
{
    int32_t n;
    cin >> n;
    int64_t sum = ssum (n);
    int64_t ret = sum;
    ret -= 3 * ssum (n / 3);
    ret -= 5 * ssum (n / 5);
    ret += 15 * ssum (n / 15);
    cout << ret;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
using namespace std;
int main(){
    int A,B,C,K,count=0;
    cin >> A >> B >> C >> K;
    if(K>=A){
        count+=A;
        K-=A;
    }else{
        cout << K << endl;
        return 0;
    }
    
    if(K>=B){
        K-=B;
    }else{
        cout << count << endl;
        return 0;
    }
    
    if(K!=0){
        cout << count-K << endl;
    }else{
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3664
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int h[] = new int[n];
        for (int i=0; i<n; i++) h[i]=sc.nextInt();

        for (int i=0; i<n-1; i++){
            if (h[i]-2>=h[i+1]){
                System.out.println("No");
                return;
            }else if (h[i]-1<=h[i+1]){
                if (i!=0 && (h[i-1]<=h[i]-1)){
                    h[i] = h[i]-1;
                }else if (i==0 && (h[i]<=h[i+1]-1)){
                    h[i] -= 1;
//                    h[i+1] = h[i+1]-1;
                }
            }
//            if (h[n-2]>h[n-1]){
//                System.out.println("No");
//                return;
//            }
        }
        for (int i=0; i<n-1; i++){
            if (h[i]>h[i+1]){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");

    }
}

Measured memory_bytes: 50448
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[4] = {1,0,-1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a,b,answer;
        String op;
        boolean continueWhile = true;
        while(continueWhile){
            a = sc.nextInt();
            op = sc.next();
            b = sc.nextInt();
            switch(op){
                case "+":
                    answer = a+b;
                    System.out.println(answer);
                    break;
                case "-":
                    answer = a-b;
                    System.out.println(answer);
                    break;
                case "*":
                    answer = a*b;
                    System.out.println(answer);
                    break;
                case "/":
                    answer = a/b;
                    System.out.println(answer);
                    break;
                case "?":
                    continueWhile = false;
                    break;
            }

            
        }

        sc.close();
    }
}


Measured memory_bytes: 26148
n,m = map(int,input().split())
land = [[] for i in range(n)]
for i in range(m):
	a,b = (n-1 for n in map(int,input().split()))
	land[min(a,b)].append(max(a,b))

# print(land)
ans = "IMPOSSIBLE"
for l in land[0]:
	if n-1 in land[l]:
		ans = "POSSIBLE"
		break
print(ans)

Measured memory_bytes: 29048
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;

ll merge_cnt(vector<int> &a) {
	int n = a.size();
	if (n <= 1) { return 0; }
 
	ll cnt = 0;
	vector<int> b(a.begin(), a.begin() + n / 2);
	vector<int> c(a.begin() + n / 2, a.end());
 
	cnt += merge_cnt(b);
	cnt += merge_cnt(c);
 
	int ai = 0, bi = 0, ci = 0;
	while (ai < n) {
		if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
			a[ai++] = b[bi++];
		}
		else {
			cnt += n / 2 - bi;
			a[ai++] = c[ci++];
		}
	}
	return cnt;
}

int n; vector<int> a,b,c;
vector<pair<double,int>> z;
vector<int> ite;

bool rot(int i,int j){
	return (a[i]*b[j]>a[j]*b[i]);
}

int main() { 
	cin>>n;
	a.resize(n); b.resize(n); c.resize(n);
	z.resize(n); ite.resize(n);
	rep(i,0,n){
		cin>>a[i]>>b[i]>>c[i];
	}
	rep(i,0,n){
		if(b[i]<0){
			a[i]*=-1;
			b[i]*=-1;
			c[i]*=-1;
		}
		ite[i]=i;
	}
	sort(ite.begin(),ite.end(),rot);
	double x,y,l=-1e9,r=1e9;
	rep(i,0,80){
		double mi=(l+r)/2;
		rep(j,0,n){
			z[j]=make_pair((c[ite[j]]-mi*a[ite[j]])/b[ite[j]],j);
		}
		sort(z.begin(),z.end());
		vector<int> count;
		rep(j,0,n)count.push_back(z[j].second);
		if(merge_cnt(count)*2<=1LL*n*(n-1)/2) r=mi;
		else l=mi;
	}
	x=l;
	rep(i,0,n) swap(a[i],b[i]);
	rep(i,0,n){
		if(b[i]<0){
			a[i]*=-1;
			b[i]*=-1;
			c[i]*=-1;
		}
		ite[i]=i;
	}
	sort(ite.begin(),ite.end(),rot);
	l=-1e9,r=1e9;
	rep(i,0,80){
		double mi=(l+r)/2;
		rep(j,0,n){
			z[j]=make_pair((c[ite[j]]-mi*a[ite[j]])/b[ite[j]],j);
		}
		sort(z.begin(),z.end());
		vector<int> count;
		rep(j,0,n)count.push_back(z[j].second);
		if(merge_cnt(count)*2<=1LL*n*(n-1)/2) r=mi;
		else l=mi;
	}
	y=l;
	cout.precision(15);
	cout<<fixed<<x<<" "<<y<<endl;
	return 0;
}


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

#define INF 1e9

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

  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  for(int i = 0; i < m; ++i) cin >> c[i];

  vector<int> dp(n + 1, INF);
  dp[0] = 0;
  for(int i = 1; i <= n; ++i) {
    for(int j = 0; j < m; ++j) {
      if(i >= c[j]) dp[i] = min(dp[i], dp[i - c[j]] + 1);
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3208
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
flg=1
for i in range(m):
	if 4*m*a[i]<sum(a):
		flg=0
		break
if flg:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

/* エラトステネスのふるいによる素数リスト */
class PrimeList {
  private:
    i64 max;
    Vec<i64> vals;
    Vec<bool> is_prime;
  public:
    PrimeList(i64 val): max(val), is_prime(val + 1, true) {
        is_prime[0] = false; is_prime[1] = false;
        for(i64 i = 4; i <= max; i += 2) is_prime[i] = false;
        for(i64 i = 3; i * i <= max; i += 2) {
            if(!is_prime[i]) continue;
            for(i64 j = 3; i * j <= max; j += 2)
                if(is_prime[i * j]) is_prime[i * j] = false;
        }
        for (i64 i = 0; i <= max; i++) if (is_prime[i]) vals.push_back(i);
    }
    bool exists(i64 x) const { return is_prime[x]; }
    i64 size() const noexcept { return (i64)vals.size(); }
    i64 range_max() const noexcept { return max; }
    i64 operator[](i64 index) const { return vals[index]; }
    decltype(vals)::const_iterator begin() const noexcept { return vals.cbegin(); }
    decltype(vals)::const_iterator end() const noexcept { return vals.cend(); }
};

/* 素因数分解 */
Vec<pair<i64, i32>> prime_factorization(i64 num) {
    i64 n = sqrt(num);
    PrimeList p(n);
    Vec<pair<i64, i32>> res;
    for (auto it = p.begin(); it != p.end(); it++) {
        i32 sum = 0;
        i64 i = *it;
        while (num % i == 0) {
            sum++;
            num /= i;
        }
        if (sum > 0) res.push_back(make_pair(i, sum));
    }
    if (num > n) res.push_back(make_pair(num, 1));
    return res;
}

void Main() {
    i64 N, P;
    cin >> N >> P;
    Vec<pair<i64, i32>> pf = prime_factorization(P);
    i64 ans = 1;
    for (auto it = pf.begin(); it != pf.end(); it++) {
        if (it->second >= N) ans *= pow(it->first, it->second / N);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
    
int main(){
    
    string s;cin>>s;
  map<char,int> mp;
  
    for(char x:s){
        mp[x]++;
    }
    
     (mp['A']==3 || mp['B']==3)?cout<<"No":cout<<"Yes";
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

int main(void){
    int N,M;
    vector<pair<int,int>> A;
    cin>>N>>M;
    A.resize(M);
    for(int i=0;i<M;i++) cin>>A[i].second>>A[i].first;
    sort(A.begin(),A.end());
    int res=0;
    int endtime=0;
    for(int i=0;i<M;i++){
        if(A[i].second>=endtime){
            endtime=A[i].first;
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        int count = 0;
        int ans = 0;
        for(int i = 100; i > 0; i--){
            if((a%i == 0) && (b%i == 0)){
                count++;
                if(count == k){
                    ans = i;
                }
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

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

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

set<int> adj[100010];
ll h[100010];

int main() {
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> h[i];
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        bool ok = true;
        for(int j : adj[i]) {
            if(h[j] >= h[i]){
                ok = false;
                break;
            }
        }
        if(ok)ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 18476
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;



/**
 * --------------------------------------------------
 * Main Class
 * --------------------------------------------------
 */
public class Main {

	public void exec() throws IOException {
		Scanner input = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		long n = input.nextInt();
		long a = input.nextInt();
		long b = input.nextInt();
		long c = input.nextInt();
		long d = input.nextInt();
		
		boolean ret = false;
		for (long m=0; m<n; m++) {
			if (c*(n-1-m) - d*m <= b - a && b - a <= d*(n-1-m) - c*m) {
				ret = true;
				break;
			}
		}
		out.println(ret ? "YES":"NO");
		out.flush();
		input.close();
	}

	public static void main(String[] args) throws IOException {
//		long time = System.currentTimeMillis();
		new Main().exec();
//		System.out.println(System.currentTimeMillis() - time);
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

ll dp[1<<16];
ll score[1<<16];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vvi a(n,vi(n));
    cin >> a;
    rep(bit,1<<n) {
        dp[bit] = -linf;
        vi v;
        rep(i,n) if(bit>>i&1) v.pb(i);
        ll sc = 0;
        for(int i : v) for(int j : v) sc += a[i][j];
        sc /= 2;
        score[bit] = sc;
    }
    dp[0] = 0;
    rep2(bit,1,1<<n) {
        int sub = bit;
        do {
            chmax(dp[bit],dp[sub]+score[bit^sub]);
            sub = (sub-1)&bit;
        } while(sub != bit);
    }
    cout << dp[(1<<n)-1] << endl;
}


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n;
	int a[100010];
	int b[100010];
	cin >> n;
	for(int i = 0;i < n+1;i++) cin >> a[i];
	for(int i = 0;i < n;i++) cin >> b[i];

	int ans = 0;
	for(int i = 0;i < n;i++){
		ans += min(a[i], b[i]);
		if(a[i] < b[i]){
			int tmp = max(a[i+1]-b[i]+a[i], 0ll);
			ans += a[i+1]-tmp;
			a[i+1] = tmp;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define VI vector<int>
#define VII vector<int,int>
#define MSI map<string,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }


int main() {
	int n;
	cin >> n;
	if (n % 2 == 1) {
		cout << n / 2 + 1 << endl;
	}
	else {
		cout << n / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
require 'pp'

k = gets.to_i
queue = (1..9).to_a

cnt = 0
while true
    cnt += 1
    x = queue.shift
    if cnt == k
        puts x
        break
    end

    #pp x

    y = x * 10 + x % 10
    if (y - 1) % 10 != 9
       queue.push(y-1)
    end
    queue.push(y)
    if (y + 1) % 10 != 0
        queue.push(y+1)
    end
end


Measured memory_bytes: 4092
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    map<int,int>mp;
    rep(i,n){
        int hoge; cin>>hoge;
        mp[hoge]++;
    }
    int d; cin>>d;
    rep(i,d){
        int hoge; cin>>hoge;
        if(mp[hoge]==0)return puts("NO")*0;
        mp[hoge]--;
    }
    cout<<"YES"<<endl;
}

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

int main()
{
  int n, tmp;
  cin >> n;
  vector<int> aj;
  vector<int> ai;
  aj.push_back(0);
  ai.push_back(0);
  rep(j, n) {
    cin >> tmp;
    aj.push_back(j + 1 - tmp);
    ai.push_back(j + 1 + tmp);
  }
  sort(aj.begin(), aj.end());
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (upper_bound(aj.begin(), aj.end(), ai[i]) - aj.begin()) - (lower_bound(aj.begin(), aj.end(), ai[i]) - aj.begin());
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5040
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < n; i++)
	{
		cout << s[i] << t[i];
	}
	cout << endl;
}

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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[1],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[221111];
long long l[600511];
int j[222221];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s[222][22];
priority_queue<long long,vector<long long>,greater<long long> > q;
//queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}


int main()
{
    scanf("%d",&a);
    for(i=1;i<a;i*=2);
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    for(int t=1;t<=a;t++)
        scanf("%d",&j[t]);
    for(int t=i-1;t>0;t--)
        l[t]=(l[t*2]+l[t*2+1])%mod;
    for(int t=1;t<=a;t++)
    {
        x=0;
        n=i,m=i+o[t]-1;
        for(;n<m;)
        {
            if(n%2) x=max(l[n],x),n++;
            else if(m%2==0) x=max(l[m],x),m--;
            else n/=2,m/=2;
        }
        x=max(x,l[n]);
        l[o[t]+i-1]=j[t]+x;
        for(int h=(o[t]+i-1)/2;h>0;h/=2)
            l[h]=max(l[h*2],l[h*2+1]);
    }
    printf("%lld",l[1]);
}





Measured memory_bytes: 6528
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A = [0] + A
    b = A[:]
    n = N // 2 + 1
    m = sum(b[n:])
    for i in range(n - 1, 0, -1):
        sum_ = sum([b[j] for j in range(i, N + 1, i)])
        if A[i] != sum_ % 2:
            b[i] = (b[i] + 1) % 2
        m += b[i]

    print(m)
    if m:
        print(*[i for i, v in enumerate(b) if v])


main()


Measured memory_bytes: 13104
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;
int n,a[5008];
int b[5008];

int solve(){
  int res= -100001;
  for(int i=0;i<=n;i++){
    for(int j=n;j>i;j--){
      res=max(res,b[j]-b[i]);
    }
  }
  return res;
}

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

    b[0]=0;
    for(int i=1;i<=n;i++){
      b[i]=a[i]+b[i-1];
    }

    printf("%d\n",solve());

  }
  return 0;
}

Measured memory_bytes: 1216
/*BFS 的做法 */
/*
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<list>
#define N 10002  //憨批
using namespace std;
vector<int> G[N+1];
list<int> ans;
bool visited[N+1];
int indeg[N+1];
int n;

void bfs(int node){
    queue<int> q;
    q.push(node);
    visited[node]=true;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        ans.push_back(u);
        for(int i=0;i<G[u].size();i++){
            int v=G[u][i];
            indeg[v]--;
            if(indeg[v]==0 && visited[v]==false){ //这里缺少了一个条件
                q.push(v);
                visited[v]=true;
            }
        }
    }
}

void topologicalSort(){
    for(int i=0;i<n;i++){
        if(indeg[i]==0 && visited[i]==false){
            bfs(i);
        }
    }
    for(list<int>::iterator it=ans.begin();it!=ans.end();it++){
        cout<<*it<<endl;
    }
}


int main(){
    int q;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        //G[i].clear();
        visited[i]=false;
        indeg[i]=0;
    }
    for(int i=0;i<q;i++){
        int s,t;
        cin>>s>>t;
        G[s].push_back(t);
        indeg[t]++;
    }

    topologicalSort();

    return 0;
}
*/


/* DFS 的做法 */
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<list>
#define N 10002  //憨批
using namespace std;
vector<int> G[N+1];
list<int> ans;
bool visited[N+1];
int indeg[N+1];
int n;

void dfs(int node){
    visited[node]=true;
    for(int i=0;i<G[node].size();i++){
        int v=G[node][i];
        if(visited[v]==false){
            //visited[v]=true;
            dfs(v);
        }
    }
    ans.push_front(node);
}

int main(){
    int q;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        //G[i].clear();
        visited[i]=false;
        indeg[i]=0;
    }
    for(int i=0;i<q;i++){
        int s,t;
        cin>>s>>t;
        G[s].push_back(t);
        indeg[t]++;
    }

    for(int i=0;i<n;i++){
        if(visited[i]==false){
            dfs(i);
        }
    }
    for(list<int>::iterator it=ans.begin();it!=ans.end();it++){
        cout<<*it<<endl;
    }
    return 0;
}



Measured memory_bytes: 4136
#include<bits/stdc++.h>
using namespace std;
int n;
int num[110];
int a,b;
bool com(int a,int b){
    return a>b;
}
int main(){
	cin>>n;
	for(int i=0;i<n;++i){
	    cin>>num[i];
	}
	sort(num,num+n,com);
	for(int i=0;i<n;++++i){
	    a+=num[i];
	}
	for(int i=1;i<n;++++i){
	    b+=num[i];
	}
	cout<<a-b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#define rep( i, a, n ) for( int i = a; i < n; i++ )
#define per( i, a, n ) for( int i = n - 1; i >= a; i-- )
#define mem( f, x ) memset( f, x, sizeof( f ) )
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define e 2.71828
using namespace std;
const int N = 505;
const int M = 1e6+5;
const int MAX = 5;
const ll inv = 500000004;
const double g = 9.80;
const double PI = acos( -1.0 );
int a[N][N];

struct node{
    pii x, y;
    node( ){ x = y = make_pair( 0, 0 ); }
    node( pii xx, pii yy ){
        x = xx, y = yy;
    }
    void Pri( ){
        printf( "%d %d %d %d\n", x.fi, x.se, y.fi, y.se );
    }
}p[N*N];

int main(){
    int m, n, cnt;
    while( scanf( "%d %d", &m, &n ) != EOF ){
        cnt = 0;
        rep( i, 1, m + 1 ){
            rep( j, 1, n + 1 ){
                scanf( "%d", a[i] + j );
            }
        }
        rep( i, 1, m + 1 ){
            rep( j, 1, n ){
                if( a[i][j]&1 ){
                    a[i][j]--;
                    a[i][j+1]++;
                    p[cnt++] = node( make_pair( i, j ), make_pair( i, j + 1 ) );
                    //printf( "%d %d %d %d\n", i, j, i, j+1 );
                }
            }
        }
        rep( i, 1, m ){
            if( a[i][n]&1 ){
                a[i][n]--;
                a[i+1][n]++;
                p[cnt++] = node( make_pair( i, n ), make_pair( i+1, n ) );
            }
        }
        printf( "%d\n", cnt );
        rep( i, 0, cnt ) p[i].Pri();
    }
    return 0;
}


Measured memory_bytes: 7040
while True:
    N = int(input())
    if N==0:
        break
    
    Nlist = list(range(1,N))
    count = 0
    while True:
        for i in range(1,1001,1):
            if i>=N/2:
                break
            sum = 0
            j = i
            while True:
                sum += j
                j += 1
                if sum>=N:
                    if sum==N:
                        count += 1
                    break
        break
        
    print(count)
    continue


Measured memory_bytes: 5612
#include <cstdio>

int a, b, c;
int d, e, f;
int hoge(int x, int y)
{
    return (x > y ? x - y : y - x);
}

int main()
{
    scanf("%d %d %d", &a, &b, &c);
    d = hoge(a, b);
    e = hoge(b, c);
    f = hoge(c, a);
    //   printf("d: %d e: %d f: %d\n", d, e, f);
    int ans;
    int max;
    if (d < e) {
        if (e < f) {
            max = f;
        } else {
            max = e;
        }
    } else {
        if (d < f) {
            max = f;
        } else {
            max = d;
        }
    }
    //    printf("%d\n", max);
    ans = d + e + f - max;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int32_t main()
{
	IOS;
	int k, a ,b;
	cin>>k>>a>>b;
	int gain=(b-a);
	gain=max(gain, 2LL);
	int inc=min(k, a-1);
	k-=inc;
	int ans=1 + inc;
	int moves=k/2;
	ans+=moves*gain;
	k%=2;
	if(k>0)
		ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    while(tt--)
    {
        int n;
        cin >> n;
        int d1[n],d2[n];
        for(int i=0;i<n;i++)
        {
            cin >> d1[i] >> d2[i];
        }
        bool poss = false;
        for(int i=0;i<n-2;i++)
        {
            if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2])
            {
                poss = true;
                break;
            }
        }
        if(poss)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		long long int num,ans=10000000;
		cin >> num;
		if(!num)	break;
		for(long long int y=0;y*y<=num;y++){
			for(long long int z=0;z*z*z+y*y<=num;z++){
				long long int x = num-z*z*z-y*y;
				ans = min(ans,(x+y+z));
			}
		}
		cout << ans << endl;
	}
}


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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int nr = 0,nl = 0;
  int sr = 0,sl = 0;
  for(int i = 0;i < n;i++){
    if(s.at(i) == ')'){
      if(nl > 0){
        nl--;
      }
      else{
        sl++;
      }
    }
    else{
      nl++;
    }
  }
  nl = 0;
  nr = 0;
  for(int i = n-1;i >= 0;i--){
    if(s.at(i) == '('){
      if(nr > 0){
        nr--;
      }
      else{
        sr++;
      }
    }
    else{
      nr++;
    }
  }
  for(int i = 0;i < sl;i++){
    cout << '(';
  }
  cout << s;
  for(int i = 0;i < sr;i++){
    cout << ')';
  }
  cout << " " << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    int n,k;

    cin >> n >> k;

    while(n!=0||k!=0) {
        int temp;
        vector<int> num;
        vector<int> ord;

        set<int> ans;

        for(int i=0; i<n; ++i) {
            cin >> temp;
            num.push_back(temp);
            ord.push_back(i);
        }

        do {
            temp=0;
            for(int i=0; i<k; ++i) {
                temp*=(num[ord[i]]<10?10:100);
                temp+=num[ord[i]];
            }
            ans.insert(temp);
        } while(next_permutation(ord.begin(),ord.end()));

        cout << ans.size() << endl;

        cin >> n >> k;
    }
    return 0;
}

Measured memory_bytes: 3176