akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 105; i <= n; i+=2){
		int yaksuuu = 0;
		for(int j = 1; j <= i; j++){
			if(i % j == 0)yaksuuu++;
		}
		if(yaksuuu == 8)ans++;
	}
	ANS(ans);
	return 0;
}


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

const int INF=INT_MAX;

vector<P>to[100010];
int x[100010];

void dfs(int v, int cnt=0){
    x[v]=cnt;
    rep(i,to[v].size()){
        int u=to[v][i].first;
        int d=to[v][i].second;
        if(x[u]==-INF){
            dfs(u,cnt+d);
        }
        else{
            if(x[u]-x[v]!=d){
                cout<<"No"<<endl;
                exit(0);
            }
        }
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    rep(i,100010)x[i]=-INF;
    rep(i,m){
        int l,r,d;
        cin>>l>>r>>d;
        l--; r--;
        to[l].push_back(P(r,d));
        to[r].push_back(P(l,-d));
    }
    rep(i,n){
        if(x[i]==-INF){
            dfs(i);
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 15132
import sys


def rollDice(dice, direction):
    buf = [x for x in dice]
    if direction == "S":
        buf[0] = dice[4]
        buf[1] = dice[0]
        buf[4] = dice[5]
        buf[5] = dice[1]
    elif direction == "E":
        buf[0] = dice[3]
        buf[2] = dice[0]
        buf[3] = dice[5]
        buf[5] = dice[2]
    elif direction == "W":
        buf[0] = dice[2]
        buf[2] = dice[5]
        buf[3] = dice[0]
        buf[5] = dice[3]
    elif direction == "N":
        buf[0] = dice[1]
        buf[1] = dice[5]
        buf[4] = dice[0]
        buf[5] = dice[4]

    for i in range(6):
        dice[i] = buf[i]


def rollDiceSide(dice):
    buf = [x for x in dice]
    buf[1] = dice[2]
    buf[2] = dice[4]
    buf[3] = dice[1]
    buf[4] = dice[3]

    for i in range(6):
        dice[i] = buf[i]


def rollCheckSide(d):
    if d1 == d2:
        print("Yes")
        sys.exit()
    rollDiceSide(d2)


def rollCheck(d):
    if d1 == d2:
        print("Yes")
        sys.exit()
    rollDice(d2, "S")
    for _ in range(4):
        rollCheckSide(d2)


d1 = list(map(int, input().split()))
d2 = list(map(int, input().split()))


for _ in range(4):
    for _ in range(4):
        rollCheck(d2)
    rollDice(d2, "W")

print("No")



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n;
  ll d;
  cin >> n >> d;

  int cnt = 0;
  rep(i, n){
    ll x, y;
    cin >> x >> y;
    if(x*x + y*y <= d*d) cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl '\n'

int main() {

    fast
    int n;cin>>n;
    int a[n];
    int ans;
    for(int i=0; i<n; ++i) cin>>a[i];
    sort(a,a+n);
    ans=-a[n/2 - 1]+a[n/2];
    cout<<ans;

#ifndef ONLINE_JUDGE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define FOR(i,a,n) for(int i=(a); i<(n); ++i)

struct Rect {
	int x1, x2, y1, y2;
};
map<char, Rect> item;
vector<string> img;
int t, H, W;

bool ok(Rect &r, char c) {
	FOR(i,r.y1,r.y2+1) FOR(j,r.x1,r.x2+1) {
		if (img[i][j] != c && img[i][j] != '#') {
			return false;
		}
	}
	return true;
}

void fill(Rect &r, char c) {
	FOR(i,r.y1,r.y2+1) FOR(j,r.x1,r.x2+1) img[i][j] = c;
}

int main() {
	cin >> t;
	while (t--) {
		cin >> H >> W;
		img.resize(H);
		FOR(i,0,H) cin >> img[i];

		FOR(i,0,H) FOR(j,0,W) {
			char c = img[i][j];
			if (c != '.') {
				if ( ! item.count(c)) {
					item[c] = (Rect){j, j, i, i};
				} else {
					item[c].x1 = min(item[c].x1, j);
					item[c].x2 = max(item[c].x2, j);
					item[c].y1 = min(item[c].y1, i);
					item[c].y2 = max(item[c].y2, i);
				}
			}
		}

		map<char, Rect>::iterator it = item.begin();
		while (it != item.end()) {
			char c = (*it).first;
			Rect &r = (*it).second;
			if (ok(r, c)) {
				fill(r, '#');
				item.erase(c);
				it = item.begin();
				continue;
			}
			++ it;
		}
		cout << (item.empty() ? "SAFE" : "SUSPICIOUS") << endl;
		item.clear();
	}
	return 0;
}

Measured memory_bytes: 1220
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto xyz = readln.split.to!(int[]);
    int c;
    xyz[0] -= xyz[2];
    while (xyz[0] >= xyz[1] + xyz[2]) {
        xyz[0] -= (xyz[1] + xyz[2]);
        ++c;
    }
    writeln(c);
}

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

int c[33], s[444][33];
int sco(int t, const vector<int> &v) {
    int r = 0, l = 0, d = v.size();
    for(int i = 0; i < d; i++)
        if(v[i] == t)
            r += s[i][t] - c[t] * (i + 1 - l) * (i - l) / 2, l = i + 1;
    r -= c[t] * (d + 1 - l) * (d - l) / 2;
    return r;
}
int main() {
    auto ti = clock();
    int d;
    cin >> d;
    for(int i = 0; i < 26; i++)
        cin >> c[i];
    for(int i = 0; i < d; i++)
        for(int j = 0; j < 26; j++)
            cin >> s[i][j];
    vector<int> ss, tt;
    int M = -1e9;
    for(int a = 10; a < 16; a++) {
        for(int b = 0; b < 4; b++) {
            for(int z = 5; z < 16; z++) {
                int r = 0, l[33] = {};
                ss.clear();
                for(int i = 0; i < d; i++) {
                    auto m = 0.;
                    int t = 0;
                    for(int j = 0; j < 26; j++) {
                        double p = s[i][j];
                        p += c[j] * (i + 1 - l[j]) * .4 * a;
                        for(int k = 1; k < z; k++)
                            if(i + k < d)
                                p -= s[i + k][j] * (z - k) * .05 / z * b;
                        if(p > m)
                            m = p, t = j;
                    }
                    ss.push_back(t);
                    r -= c[t] * (i + 1 - l[t]) * (i - l[t]) / 2;
                    l[t] = i + 1;
                    r += s[i][t];
                }
                for(int j = 0; j < 26; j++)
                    r -= c[j] * (d + 1 - l[j]) * (d - l[j]) / 2;
                if(r > M)
                    M = r, tt.swap(ss);
            }
        }
    }
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rc(0, 25), r0(0, d - 1), r2(1, 6);
    uniform_real_distribution<> ru(0, 1);
    int cnt = 0;
    for(;;) {
        auto T = (clock() - ti + 0.) / CLOCKS_PER_SEC;
        if(T > 1.9)
            break;
        auto U = pow(2e3, 1 - T / 1.9) * pow(6e2, T / 1.9);
        for(int cn = 0; cn < 100; cn++, cnt++) {
            auto uu = tt;
            int di;
            if(rc(mt) < 12) {
                int x0 = r0(mt), xc = rc(mt);
                uu[x0] = xc;
                di = sco(tt[x0], uu) + sco(xc, uu) - sco(tt[x0], tt) -
                     sco(xc, tt);
            } else {
                int x2 = r2(mt);
                uniform_int_distribution<> r1(0, d - 1 - x2);
                int x1 = r1(mt);
                x2 += x1;
                swap(uu[x1], uu[x2]);
                di = sco(tt[x1], uu) + sco(tt[x2], uu) - sco(tt[x1], tt) -
                     sco(tt[x2], tt);
            }
            if(ru(mt) <= exp(di / U))
                tt.swap(uu);
        }
    }
    M = 0;
    for(int j = 0; j < 26; j++)
        M += sco(j, tt);
    for(int i : tt)
        cout << i + 1 << '\n';
    cerr << M << endl;
    cerr << cnt << endl;
    return 0;
}


Measured memory_bytes: 4320
#include <iostream>
#include <string>
#include <string.h>
#include <sstream>
#include <algorithm>

#define L 110

using namespace std;

int main(void)
{
	int i1,i2,i3;
	int c;
	string s;
	string temp;
	int f[L][L];
	int dp[L][L];

	c=0;
	memset(f,-1,sizeof(f));
	memset(dp,0,sizeof(dp));

	while(1){
		cin>>s;
		
		temp="";
		s=s+",";

		for(i1=0,i2=0;i1<s.size();i1++){
			if(s[i1]==','){
				istringstream istr(temp);
				istr >> f[c][i2];				
				temp="";
				i2++;
			}
			else temp+=s[i1];
		}
		c++;
		if(c!=1 && count(s.begin(),s.end(),',')==1) break;
	}

	dp[0][0]=f[0][0];
	
	for(i1=1;i1<=c/2;i1++){
		for(i2=0;i2<c/2+1;i2++){
			if(i2==0) dp[i1][i2]=dp[i1-1][i2]+f[i1][i2];
			else if(f[i1][i2]!=-1){
				dp[i1][i2]=max(dp[i1-1][i2],dp[i1-1][i2-1])+f[i1][i2];
			}
		}
	}

	for(i1;i1<c;i1++){
		for(i2=0;i2<c/2+1;i2++){
			if(f[i1][i2]!=-1){
				dp[i1][i2]=max(dp[i1-1][i2],dp[i1-1][i2+1])+f[i1][i2];
			}
		}
	}



	/*for(i1=0;i1<=c;i1++){
		for(i2=0;i2<c/2+1;i2++){
			cout<<f[i1][i2]<<" ";
		}
		cout<<endl;
	}*/

	cout<<dp[c-1][0]<<endl;


	return 0;

}

Measured memory_bytes: 1324
#include <stdio.h>

int main()
{
	int n,a[100],memo,i,k;
	scanf("%d",&n);
	for(i = 0; i < n; ++i)
	{
		scanf("%d",&a[i]);
		i<n-1? printf("%d ", a[i]):printf("%d\n", a[n-1]);
    }

	for (i = 1; i < n; ++i)
	{
		memo = a[i]; 
		k = i-1;
		while(k >= 0 && a[k] > memo)
		{
			a[k+1] = a[k];
			a[k] = memo;
			k--;
		}

		for (k = 0; k < n-1; ++k)
		{
			printf("%d ", a[k]);
		}
		printf("%d\n", a[n-1]);

	}

	return 0;
}

Measured memory_bytes: 1768
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

v,e=map(int,input().split())
G=[[] for i in range(v)]
for i in range(e):
    s,t,d=map(int,input().split())
    G[s].append((t,d))
dp=[[inf]*v for i in range(2**v)]
dp[1][0]=0
for bit in range(1,2**v):
    for i in range(v):
        if dp[bit][i]==inf: continue
        for gi,di in G[i]:
            if not (bit >> gi & 1):
                dp[bit|1<<gi][gi]=min(dp[bit|1<<gi][gi],dp[bit][i]+di)
            if bit == (1 << v) - 1 and gi == 0:
                dp[bit][0] = min (dp[bit][0],dp[bit][i]+di)
print(dp[2**v-1][0] if dp[2**v-1][0]!=inf else -1)
# print(*dp,sep="\n")
# print(*G,sep="\n")


Measured memory_bytes: 15896
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=2e5+9;
typedef long long ll;

int n;
int a[N];

inline ll calc(ll x)
{
	ll ret=0;
	for(int i=1;i<=n;i++)
		ret+=abs((ll)a[i]-(x+i));
	return ret;
}

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();

	ll l=-1e9,r=1e9,lmid,rmid;
	while(r-l>20)
	{
		int midd=(r-l)/3.0;
		lmid=l+midd,rmid=r-midd;
		ll cl=calc(lmid),cr=calc(rmid);
		if(cl<cr)
			r=rmid;
		else
			l=lmid;
	}


	ll ans=1e18,v=0;
	for(ll i=l;i<=r;i++)
	{
		ll tmp=calc(i);
		if(tmp<ans)
			ans=tmp,v=i;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 896
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
  input! {
    s: String
  };

  let res = if s.contains("7") { "Yes" } else { "No" };
  println!("{}", res);
}


Measured memory_bytes: 2140
import java.util.*;

//update 2019/12/13

public class Main{

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    long n = nextLong();
    long a = nextLong();
    long b = nextLong();

    long sa = Math.abs(a-b);

    long ans = 0;

    if(sa%2==0){
      ans = sa/2;
    }
    else{
      long AAA = Math.min((n-a),(a-1));
      long BBB = Math.min((n-b),(b-1));

      ans = Math.min(AAA,BBB); //片方が端っこに来るまで。

      //差を1減らす⇒差が偶数になる
      sa -= 1;
      ans += 1;

      //差は偶数
      ans += sa/2;

    }

    System.out.println(ans);

    //System.out.println(1/2);



  }

  static String next(){
    return sc.next();
  }

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

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

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

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char aaa){
    return aaa - 48;
  }

  public static int maxInt(int[] a,int lng){
    int max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static int minInt(int[] a,int lng){
    int min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

  public static long maxLong(long[] a,int lng){
    long max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static long minLong(long[] a,int lng){
    long min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    
    std::cin >> n >> m;
    int l=1,r=n;
    for (int i = 0; i < m; i++) {
        int tmpL,tmpR;
        std::cin >> tmpL >> tmpR;
        if(tmpL>l)l=tmpL;
        if(tmpR<r)r=tmpR;
    }
    int ans=r-l+1;
    if(ans<0)ans=0;
    std::cout << ans << std::endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Ios cin.tie(0);ios_base::sync_with_stdio(0)
#define endl '\n'
#define fixeddecimals cout.setf(ios::fixed); cout.precision(18)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i>=b;i--)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ri(X) cin>>X
#define rii(X, Y) cin>>X>>Y
#define riii(X, Y, Z) cin>>X>>Y>>Z
#define dri(X) int X; cin>>X
#define drii(X, Y) int X, Y; cin>>X>>Y
#define driii(X, Y, Z) int X, Y, Z; cin>>X>>Y>>Z
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int,int> > >
#define pii pair<int,int> 
#define piii pair<int,pair <int,int> >
#define preturn(X) cout<<X<<endl<<flush; return 0
typedef long long ll;
//typedef int64_t ll; 
ll MOD=1e9+7;


int main(){
	Ios;
	ll n,m;
	cin>>n>>m;
	m-=(m%2);
	if(2*n == m){
		preturn(n);
	}
	else if(2*n < m){
		preturn((((m/2)-n)/2)+n);
	}
	else{
		preturn(m/2);
	}
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
    };

    let mut lr: Vec<(usize, usize, usize)> = Vec::new();
    for _ in 0..m {
        input! {
            l: usize,
            r: usize,
        };

        lr.push((l, r, r - l + 1));
    }

    lr.sort_by(|a, b| a.2.cmp(&b.2));

    let mut v: Vec<usize> = vec![];

    for i in 1..=n {
        v.push(i);
    }

    let mut result = lr[0].2;
    let mut cur_l = lr[0].0;
    let mut cur_r = lr[0].1;

    for i in lr.iter() {
        if cur_l <= i.0 && i.0 <= cur_r {
            result = cur_r - i.0 + 1;
            cur_l = i.0;
        } else if cur_l <= i.1 && i.1 <= cur_r {
            result = i.1 - cur_l + 1;
            cur_r = i.1;
        } else if i.1 <= cur_l && cur_l != i.0 {
            result = 0;
            break;
        } else if cur_r <= i.0 && cur_l != i.1 {
            result = 0;
            break;
        }
    }

    println!("{}", result);
}


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

int main() {
  string s;
  cin>>s;
  int q;
  cin>>q;
  vector<char> left, right;
  int cnt_reverse = 0;
  for (int i=0; i<q; i++) {
    int t;
    cin>>t;
    if (t == 1) {
      ++cnt_reverse;
      continue;
    }
    int f;
    char c;
    cin>>f>>c;
    if (f == 1) {
      if (cnt_reverse % 2 == 0) {
        left.push_back(c);
      } else {
        right.push_back(c);
      }
    } else {
      if (cnt_reverse % 2 == 0) {
        right.push_back(c);
      } else {
        left.push_back(c);
      }
    }
  }
  if (cnt_reverse % 2 == 0) {
    reverse(left.begin(), left.end());
    for (char c: left) {
      cout<<c;
    }
  } else {
    reverse(right.begin(), right.end());
    for (char c: right) {
      cout<<c;
    }
    reverse(s.begin(), s.end());
  }
  cout<<s;
  if (cnt_reverse % 2 == 0) {
    for (char c: right) {
      cout<<c;
    }
  } else {
    for (char c: left) {
      cout<<c;
    }
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, X, M;
  cin >> N >> X >> M;
  if (M == 0) {
    cout << X << "\n";
    return 0;
  }
  vector<ll> already(M + 1, -1);
  already.at(X) = 1;
  ll cnt = 1;
  ll len = 0, seg_sum = X;
  ll now = X;
  vector<ll> seg_sums = {0, now};
  while (true) {
    now = (ll)pow(now, 2) % M;
    if (already.at(now) != -1) {
      len = cnt + 1 - already.at(now);
      break;
    }
    already.at(now) = cnt + 1;
    cnt += 1;
    seg_sum += now;
    seg_sums.push_back(seg_sum);
  }
  if (N < cnt) {
    cout << seg_sums.at(N) << "\n";
  }
  else {
    ll ans = seg_sum + (seg_sums.at(seg_sums.size() - 1) - seg_sums.at(max(0ll, (ll)seg_sums.size() - len - 1))) * ((N - cnt) / len) + seg_sums.at(max(0ll, (ll)seg_sums.size() - len - 1 + (N - cnt) % len)) - seg_sums.at(max(0ll, (ll)seg_sums.size() - len - 1));
    cout << ans << "\n";
  }
}


Measured memory_bytes: 4544
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

//   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
     String[] s=sc.nextLine().split("");
//     String[] E=sc.nextLine().split(" ");

//int n=Integer.parseInt(nyuA);

//int H=Integer.parseInt(O[0]);
//int W=Integer.parseInt(O[1]);

int flag=0;

for(int i=0;i<s.length/2;i++){
String A="";
String B="";
for(int j=0;j<i;j++)A+=s[j];
for(int j=i;j<2*i;j++)B+=s[j];
if(A.equals(B))flag=2*i;
}

System.out.println(flag);

//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 25300
import math  
def div(a) :
    for i in range(1, int(math.sqrt(n) + 1)) : 
        if (n % i == 0) :
            a.append(i)
            if (n / i != i) :
                a.append(int(n / i))

n = int(input())
a = []
div(a)
s = 0
for i in a:
    if n//i<(i-1):
        s+=i-1

print(s)
                

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M,C=0;cin>>N>>M>>C;
    int B[M];
    int A[M];
    int ans=0,count=0;
    for(int i = 0; i < M; i++)
    {
        cin>>B[i];
    }
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < M; j++)
        {
            cin>>A[j];
            ans+=A[j]*B[j]; 
        }
        if ((ans+C)>0) {
            count++;
        }
        
      ans=0;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  int Sum = 0;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    Sum += A.at(i);
  }
  if(Sum >= H){
   cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

public class Pg
{

    void Run()
    {
        var n = Console.ReadLine().Split().Select(int.Parse);

        var fish = new int[n.First()];
        var max = 0;

        Rep(n.Last(), i =>
        {
            var inputs= Console.ReadLine().Split().Select(int.Parse);
            
            int index = inputs.First() - 1;
            int count = inputs.Last();

            fish[index] += count;

            if (0 < count)
            {
                if (fish[max] < fish[index])
                    max = index;
                else if (fish[max] == fish[index])
                    max = Math.Min(index, max);
            }
            else if (index == max)
                max = Array.IndexOf(fish, fish.Max());

            Console.WriteLine($"{(max + 1).ToString()} {fish[max]}");
        });
    }
    public static void Main() => new Pg().Run();
    public static void Rep(int n, Action<int> action) { for (int i = 0; i < n; i++) { action(n); } }
}


Measured memory_bytes: 25904
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string[] a = Read.Strs();
         for(int i = 0; i < n; i++)
        {
            if (n % 2 == 0)
            {
                if (0 < n - i * 2) { Console.Write(a[n - 1 - i * 2]); }
                else { Console.Write(a[(i - n / 2) * 2]); }
          //      if (i == n - 2) { i = n - 1; } }
            }
            else
            {
               if (n-1-(i * 2) >= 0) { Console.Write(a[n-i*2-1]); }
                else {Console.Write(a[(1+(i-(n/2+1))*2)]); }
            }
            if (i == n - 1)
            {
                Console.WriteLine();
            }
            else { Console.Write(" "); }
        }
        Console.ReadLine();
    }

    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a * b / gcd(a, b);
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 28000
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int r;
    cin >> r;
    cout << r * r << "\n";
    return 0;
}

Measured memory_bytes: 256
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            string[] In = Console.ReadLine().Split(' ');
            int a = int.Parse(In[0]);
            int b = int.Parse(In[1]);
            //つねにa>=bにする
            if (a < b)
            {
                int temp = a;
                a = b;
                b = temp;
            }
            int val = 0;
            for(int i=0; i<a; i++)
            {
                val += b * (int)Math.Pow(10, i);
            }
            Console.WriteLine(val);
        }

    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const ll INF = 1e16;

void solver(int N, int P, vector<int> &A, ull &ans){

    int even{};
    for(int i = 0; i != N; ++i){
        if(A.at(i)%2 == 0){
            ++even;
        }
    }

    ull base = 1;
    for(int i = 1; i <= N; ++i){
        base *= 2;
    }

    if(even == N){
        if(P == 0){
            ans = base;
        }
        else{
            ans = 0;
        }
    }
    else{
        ans = base/2;
    }
    return;
}

int main(){

    int N, P;
    cin >> N >> P;
    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A.at(i);
    }

    ull ans;
    solver(N, P, A, ans);

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


Measured memory_bytes: 3596
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
        int N,W,res=0,sum=0;
        Scanner in=new Scanner(System.in);
        N=in.nextInt();
        W=in.nextInt();
        int[] w=new int[N+1];
        int[] v=new int[N+1];
        for(int i=1;i<=N;i++){
            w[i]=in.nextInt();
            v[i]=in.nextInt();
            sum+=v[i];
        }
        long[][] dp=new long[N+1][sum+1];//价值为j的最小容积
        dp[0][0]=0;
        for(int i=1;i<=sum;i++)dp[0][i]=Integer.MAX_VALUE;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=sum;j++){
                if(j<v[i])dp[i][j]=dp[i-1][j];
                else dp[i][j]=Math.min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
                if(dp[i][j]<=W)res=res>j?res:j;
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 127572
#include<bits/stdc++.h>
using namespace std;
long long n,ans,a[111],ch;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		ch+=a[i];
	}
	sort(a,a+n);
	if(ch%n==0)
	{
		long long w=ch/n;
		for(int i=0;i<n;i++)
		{
			ans+=(a[i]-w)*(a[i]-w);
		}
		cout<<ans<<endl;
	}
	else
	{
		long long ans1=0,ans2=0,w=ch/n;
		for(int i=0;i<n;i++)
		{
			ans1+=(a[i]-w)*(a[i]-w);
		}
		w++;
		for(int i=0;i<n;i++)
		{
			ans2+=(a[i]-w)*(a[i]-w);
		}
		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int t[5]={0},i;
  for(i=0;i<4;i++)scanf("%d",&t[i]);
  for(i=0;i<4;i++)t[4]+=t[i];
  printf("%d\n",t[4]/60);
  printf("%d\n",t[4]%60);
  return 0;
}

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

int main() {
	int n;cin>>n;
	vector<int> v(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
		v[i]*=n;
	}
	for(int i=0;i<n;i++){
		v[i]-=sum;
		if(v[i]<0)v[i]*=-1;
	}
	int min=101;
	for(int i=0;i<n;i++){
		if(v[i]<min)min=v[i];
	}
	for(int i=0;i<n;i++){
		if(v[i]==min){
			cout<<i<<endl;
			return 0;
		}
	}


	return 0;
}

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

int main() {
    int n, i, j, s = 1e6, sum = 0;
    cin >> n;
    long long x[n];
    for(i = 0; i < n; i++){
        cin >> x[i];
    }
    for(i = 0; i < 100; i++){
        sum = 0;
        for(j = 0; j < n; j++){
            sum += pow(i - x[j], 2);
        }
        s = min(sum, s);
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

static const ll INFTY = ll(1e18) + 1;

int N;
ll K;
vector<ll> a;

// count the number of those elements whose values are <= x
inline ll get_count (ll x) {
  ll cnt = 0;

#ifdef DEBUG
  printf("\nx=%lld\n", x);
#endif

  REP(i, 0, N) {
    if (a[i] < 0) {
      // start from (i, N)
      int l = i;
      int r = N;

      while (r - l > 1) {
        int m = (l + r) / 2;

        if (a[i] * a[m] <= x) r = m;
        else l = m;
      }

      // [r, N) fulfills the condition
      cnt += N - r;

#ifdef DEBUG
      printf("a[i]=%lld, Δ=%d\n", a[i], N - r);
#endif
    } else {
      // start from (i, N)
      int l = i;
      int r = N;

      while (r - l > 1) {
        int m = (l + r) / 2;

        if (a[i] * a[m] <= x) l = m;
        else r = m;
      }

      // (i, l] fulfills the condition
      cnt += l - i;

#ifdef DEBUG
      printf("a[i]=%lld, Δ=%d\n", a[i], l - i);
#endif
    }
  }

#ifdef DEBUG
  printf("cnt=%lld\n", cnt);
#endif

  return cnt;
}

inline ll bs (ll left0, ll right0) {
  // start from (left0, right0)
  ll left = left0;
  ll right = right0;

  while (right - left > 1) {
    ll mid = (left + right) / 2;

    if (get_count(mid) < K) left = mid;
    else right = mid;
  }

  // (left0, left] fulfills the condition
  return left + 1;
}

/**
 * main
 */
int main () {
  cin >> N;
  cin >> K;

  a.resize(N);

  REP(i, 0, N) scanf("%lld", &a[i]);

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

  cout << bs(-INFTY, INFTY) << endl;
}


Measured memory_bytes: 1920
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

struct Range {
  int64_t from{-1};
  int64_t until{-1};
};

bool LessThan(const Range &a, const Range &b) {
  return a.until < b.until;
}

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

  int64_t N;
  cin >> N;
  vector<Range> A(N);
  for (int64_t i = 0; i < N; ++i) {
    int64_t x, l;
    cin >> x >> l;
    A[i].from = x - l;
    A[i].until = x + l;
  }
  sort(A.begin(), A.end(), LessThan);
  int64_t count = 0;
  int64_t until = INT64_MIN;
  for (int64_t i = 0; i < N; ++i) {
    if (until <= A[i].from) {
      ++count;
      until = A[i].until;
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1792
while 1:
    n=int(input())
    if n==0:break
    s=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            s.append(i)
            s.append(n//i)
    s=list(set(s))
    s.remove(n)
    if sum(s)==n:
        print("perfect number")
    elif sum(s)<n:
        print("deficient number")
    elif sum(s)>n:
        print("abundant number")


Measured memory_bytes: 5656
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;

int main(){
  	ll N, A, B;
  	cin >> N >> A >> B;

  	ll ans = 0;
  	ans += (N/(A+B))*A;
  	ll co = N%(A+B);
  	ans += min(co, A);

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



Measured memory_bytes: 256
c = 0
while True:
    try:
        input_line = raw_input()
        if c != 0:
            print
    except EOFError:
        break
    
    Abacus = [['' for i in range(5)] for i in range(8)]
    line = ['*', ' ', '=', ' ', '*', '*', '*', '*']
    for c in range(5):
        for r in range(8):
            Abacus[r][c] = line[r]
    d = {1:(3, 4), 2:(3, 5), 3:(3, 6), 4:(3, 7), 5:(0, 1)}
    
    input_line = map(int, input_line.zfill(5))
    for c, v in enumerate(input_line):
        if 1 <= v <= 5:
            Abacus[d[v][0]][c], Abacus[d[v][1]][c] = Abacus[d[v][1]][c], Abacus[d[v][0]][c]
        elif 6 <= v <= 9:
            v = v-5
            Abacus[0][c], Abacus[1][c] = Abacus[1][c], Abacus[0][c]
            Abacus[d[v][0]][c], Abacus[d[v][1]][c] = Abacus[d[v][1]][c], Abacus[d[v][0]][c]
    
    for line in Abacus:
        print ''.join(line)
    c = 1

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

int main() {
  int N,A,B,C;
  string S;
  cin >>N>>S;
  A=0;
  B=0;
  for(int i=0;i<N-2;i++){
      if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
        A++;
      }
  }
  cout <<A<< endl;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)


int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(b/a,c)<<endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
#A, B = [], []
#for i in range(N):
    #ai, bi = map(int, input().split())
    #A.append(ai)
    #B.append(bi)
AB = sorted(AB)

A, B = [], []
for a, b in AB:
    A.append(a)
    B.append(b)

sa = [0] * (N + 1)
sb = [0] * (N + 1)
for i in range(N):
    sa[i + 1] = sa[i] + B[i]
    sb[i + 1] = sb[i] + B[i] * A[i]

from bisect import bisect_left
aim = bisect_left(sa, M)

print(sb[aim] - A[aim - 1] * (sa[aim] - M))


Measured memory_bytes: 27856
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int a, b;
  cin >> a >> b;
  int c, d;
  cin >> c >> d;
  
  int e=abs(a-b),f=abs(b-c),g=abs(c-a);
  if(g<=d||(e<=d&&f<=d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
W,H,x,y,r = map(float,raw_input().split())
x_min = x-r
x_max=x+r
y_min=y-r
y_max=y+r

if x_min >= 0 and y_min >= 0 and x_max <= W and y_max <= H:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 6444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll N,L,T; cin >> N >> L >> T;
  ll x[N], w[N];
  for (ll i = 0; i < N; i++) {
    cin >> x[i] >> w[i];
  }
  ll c0 = 0;
  if (w[0] == 1) {
    for (ll i = 1; i < N; i++) {
      if (w[i] == 2 && (x[i]-x[0]+L)%L< 2*T) {
        c0 += 1 + (2*T-1-((x[i]-x[0]+L)%L))/L;
      }
    }
  }
  if (w[0] == 2) {
    for (ll i = 1; i < N; i++) {
      if (w[i] == 1 && (x[0]-x[i]+L)%L< 2*T) {
        c0 += 1 + (2*T-1-((x[0]-x[i]+L)%L))/L;
      }
    }
  }
  //cout << c0 << endl;

  vector<P> v;
  for (ll i = 0; i < N; i++) {
    if (w[i] == 1) {
      v.push_back(P((x[i]+T)%L, w[i]));
    }
    if (w[i] == 2) {
      v.push_back(P((x[i]+(L-1)*T)%L, w[i]));
    }
  }
  ll xs = v[0].first; ll ws = v[0].second;
  ll ns;
  sort(v.begin(), v.end());
  for (ll i = 0; i < N; i++) {
    if (v[i].first == xs && v[i].second == ws) {
      ns = i; break;
    }
  }
  map<ll, ll> res;
  if (ws == 1) {
    for (ll i = ns; i < N; i++) {
      res[(c0+i-ns) % N] = v[i].first;
    }
    for (ll i = 0; i < ns; i++) {
      res[(c0+N-ns+i) % N] = v[i].first;
    }
  }
  if (ws == 2) {
    for (ll i = ns; i < N; i++) {
      res[(T*N-c0+i-ns) % N] = v[i].first;
    }
    for (ll i = 0; i < ns; i++) {
      res[(T*N-c0+N-ns+i) % N] = v[i].first;
    }
  }
  
  for (ll i = 0; i < N; i++) {
    cout << res[i] << endl;
  }
}

Measured memory_bytes: 10608
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (ll i(a), _##i(b); i <= _##i; ++i)

#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                             \
  _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)              \
  (MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...)                                                             \
  cerr << "\033[2;31mLine " << __LINE__ << ": \033[0m";                        \
  FOR_EACH_MACRO(watch, __VA_ARGS__)                                           \
  cerr << endl
#else
#define debug(...)
#endif

using namespace std;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
  os << '[';
  for (auto it = begin(c); it != end(c); ++it)
    os << (it == begin(c) ? "" : ", ") << *it;
  return os << ']';
}
using ll = long long;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> adj[n];
  vector<int> radj[n];
  while (m--){
    int u, v;
    cin >> u >> v;
    --u; --v;
    adj[u].EB(v);
    radj[v].EB(u);
  }

  vector<int> topo;
  vector<int> vis;

  function<void(int)> dfs = [&](int u){
    for(int v : adj[u]){
      if (!vis[v]){
        vis[v] = true;
        dfs(v);
      }
    }
    topo.EB(u);
  };

  vis.assign(n, false);
  REP(u, n){
    if (vis[u]) continue;
    vis[u] = true;
    dfs(u);
  }
  reverse(ALL(topo));
  debug(topo);
  vector<int> d(n);
  int ans = 0;
  for(int u : topo){
    for(int v : radj[u]){
      d[u] = max(d[u], d[v] + 1);
    }
    ans = max(ans, d[u]);
  }
  cout << ans << "\n";
}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	#endif
	vector<int> a(3);
	int o=0;
	for(int i=0;i<3;i++){
		cin>>a[i];
		o+=a[i]%2;
	}
	int ans = 0;
	if(o == 1){
		for(int i=0;i<3;i++){
			if(a[i]%2 == 0)a[i]++;
		}
	}else if(o == 2){
		for(int i=0;i<3;i++){
			if(a[i]%2 == 1)a[i]++;
		}
	}
	ans += (o == 1 || o == 2);
	sort(a.begin(),a.end());
	ans += (a[2] - a[0]) / 2 + (a[2] - a[1]) /2;
	cout << ans << endl;
}

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

s = input()
a = [str(c) for c in s]

c = 0

for i in range(n-2):
  if a[i] == 'A' and a[i+1] == 'B' and a[i+2] == 'C':
    c +=1
  else:
    continue
    
print(c)



Measured memory_bytes: 9024
n,k = map(int,input().split())
p = list(map(int,input().split()))
data = [(x+1)/2 for x in p]
#print(data)
ans = sum(data[:k])
now = ans

for i in range(k,n):
    now += data[i]-data[i-k]
    ans = max(ans,now)

print(ans)

Measured memory_bytes: 77448
X, N = map(int, input().split())
p = list(map(int, input().split()))
plus = minus = X
ans = X

for i in range(100):
    if ans not in p:
        print(ans)
        exit()
    plus += 1
    minus -= 1
    if minus not in p:
        print(minus)
        exit()
    elif plus not in p:
        print(plus)
        exit()

Measured memory_bytes: 9196
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int parent,left,right;
};
struct Node T[MAX];
int n,D[MAX],H[MAX];

void depth(int u,int p){
  if(u==NIL)return;
  D[u]=p;
  depth(T[u].right,p+1);
  depth(T[u].left,p+1);
}

int height(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)
    h1=height(T[u].left)+1;
  if(T[u].right!=NIL)
    h2=height(T[u].right)+1;
  return H[u]=(h1>h2?h1:h2);
}

int sibling(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL)
    return T[T[u].parent].right;
  return NIL;
}
void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",sibling(u));
  int g=0;
  if(T[u].left!=NIL)g++;
  if(T[u].right!=NIL)g++;
  printf("degree = %d, ",g);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL)printf("root\n");
  else if(T[u].left==NIL&&T[u].right==NIL)printf("leaf\n");
  else printf("internal node\n");
}
int main(){
  int i,v,l,r,t,d,c,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }

  for(i=0;i<n;i++){
    if(T[i].parent==NIL)r=i;
  }

  depth(r,0);
  height(r);

  for(i=0;i<n;i++) print(i);

  return 0;
}



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

int a[2][222222], s[2];
int f(int i) {
    int j = 0;
    for(; i; j++)
        i %= __builtin_popcount(i);
    return j;
}
int main() {
    int n;
    string x;
    cin >> n >> x;
    int c = count(x.begin(), x.end(), '1');
    for(int i = 0; i < 2; i++) {
        int d = i ? c + 1 : c - 1;
        if(d <= 0)
            continue;
        a[i][n - 1] = 1 % d;
        if(x[n - 1] & 1)
            s[i] = a[i][n - 1];
        for(int j = n - 1; j--;) {
            a[i][j] = a[i][j + 1] * 2 % d;
            if(x[j] & 1)
                (s[i] += a[i][j]) %= d;
        }
    }
    for(int i = 0; i < n; i++) {
        int d = x[i] & 1 ? c - 1 : c + 1;
        if(!d) {
            cout << "0\n";
            continue;
        }
        if(x[i] & 1)
            cout << f((s[0] - a[0][i] + d) % d) + 1 << '\n';
        else
            cout << f((s[1] + a[1][i]) % d) + 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 5316
N, M, V, P = map(int, input().split())
As = list(map(int, input().split()))

As.sort(reverse=True)

scoreP = As[P-1]

def isOK(k):
    if k < P or As[k] == scoreP:
        return True

    scoreK = As[k] + M
    if scoreK < scoreP:
        return False

    rest = M*(V-1)
    rest -= M*(P-1)
    if rest <= 0:
        return True

    for i in range(P-1, N):
        if i != k:
            rest -= min(M, scoreK-As[i])
    if rest <= 0:
        return True

    return False


ng, ok = N, -1
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok+1)


Measured memory_bytes: 14964
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()

int main(){
	int n,m,l;
	int data[110][110];
	int data2[110][110];
	cin >> n >> m >> l;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> data[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<l;j++){
			cin >> data2[i][j];
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			ll int tmp = 0;
			for(int k=0;k<m;k++){
				tmp += data[i][k]*data2[k][j];
			}
			cout << tmp;
			if(j!=l-1) cout << " ";
		}
		cout << endl;

	}
	return 0;
}

Measured memory_bytes: 1248
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int S, W; cin >> S >> W;

  if (W >= S) cout << "unsafe" << endl;
  else cout << "safe" << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0){
			break;
		}
		else{
			if(H != 0){
				for(i = 0;i < H;i++){
					for(j = 0;j < W;j++){
						printf("#");
					}
					puts("");
				}
				puts("");
			}
			else{
				for(j = 0;j < W;j++){
					printf("#");
				}
				puts("");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;
typedef pair<int,int> pii;

vector<pii> G[40000];
int V;
int color[40000];

bool dfs(int v, int c) {
  color[v] = c;
  FOR(it, G[v]) {
    int cc = c;
    if (it->second == 0) cc=-c;
    int u = it->first;
    if (color[u] == cc) {
      return 0;
    }
    if (color[u] == 0 && !dfs(u, -cc)) return 0;
  }
  return 1;
}
void solve() {
  REP(i,V) color[i] = 0;
  REP(i, V) {
    if (color[i] == 0) {
      if (!dfs(i,1)) {
        cout << "No" << endl;
        return;
      }
    }
  }
  cout << "Yes" << endl;
}

int main() {
  int n;
  while(cin >> n, n) {
    V = 2*n;
    REP(i,V) G[i].clear();
    map<pii, int> mp;
    REP(i,n) {
      int x[2], y[2];
      char d;
      cin >> x[0] >> y[0] >> d;
      x[1]=x[0],y[1]=y[0];
      if (d=='x') x[1]++;
      else y[1]++;
      REP(j,2) {
        int id = i*2+j;
        const int dy[] = {0,1,0,-1};
        const int dx[] = {1,0,-1,0};
        REP(k,4) {
          int yy=y[j]+dy[k];
          int xx=x[j]+dx[k];
          if (mp.count(pii(yy,xx))) {
            int id2=mp[pii(yy,xx)];
            G[id].push_back(pii(id2,0));
            G[id2].push_back(pii(id,0));
          }
        }
      }
      REP(j,2) mp[pii(y[j],x[j])] = i*2+j;
      G[i*2].push_back(pii(i*2+1,1));
      G[i*2+1].push_back(pii(i*2,1));
    }
    // REP(i, V) {
    //   cout << i << " : ";
    //   FOR(it, G[i]) {
    //     printf("(%d,%d) ", it->first, it->second);
    //   }
    //   cout << endl;
    // }
    
    solve();
    //REP(i, V) cout << color[i] << " ";cout << endl;
  }
}

Measured memory_bytes: 4800
n = int(input())

q = ['a']
for i in range(n-1):
    nq=[]
    for j in q:
        stop=ord(max(j))+2

        for k in range(ord('a'),stop):
            nq.append(j+chr(k))
        q=nq

for i in q:
    print(i)





Measured memory_bytes: 12984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		int x = s.at(i) - 'A';
		x += n;
		if (x >= 26)x -= 26;
		char y = x+'A';
		cout << y;
	}
	cout << endl;

}

Measured memory_bytes: 256