akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct SegTree{
	vi data;
	int size;
	SegTree(int _size){
		for(int i=1;;i*=2)
			if(i>=_size){
				size=i;
				break;
			}
		data.assign(size*2,0);
	}
	void add(int i,int x){
		for(int j=size+i;j;j/=2)
			data[j]+=x;
	}
	int sum(int a,int b,int i,int l,int r){
		if(r<=a || b<=l) return 0;
		if(a<=l && r<=b) return data[i];
		int m=(a+b)/2,res=0;
		if(a<m) res+=sum(a,b,i*2+0,l,m);
		if(m<b) res+=sum(a,b,i*2+1,m,r);
		return res;
	}
	int ith(int i){
		int j=1;
		while(j<size){
			if(data[j*2+0]>i)
				j=j*2+0;
			else{
				i-=data[j*2+0];
				j=j*2+1;
			}
		}
		return j-size;
	}
};

int main()
{
	//for(int q,l;cin>>q>>l,q|l;){
	//	SegTree st(q);
	//	vi girls;
	//	map<int,int> m;
	//	rep(i,q){
	//		int qu,x; cin>>qu>>x;
	//		if(qu==0){
	//			st.add(girls.size(),1);
	//			m[x]=girls.size();
	//			girls.push_back(x);
	//			if(st.data[1]>l){
	//				int j=st.ith(0);
	//				st.add(j,-1);
	//			}
	//		}
	//		if(qu==1){
	//			int j=st.ith(x-1);
	//			st.add(j,-1);
	//		}
	//		if(qu==2){
	//			int j=st.ith(x-1);
	//			cout<<girls[j]<<endl;
	//		}
	//		if(qu==3){
	//			int j=m[x];
	//			st.add(j,-1);
	//		}
	//	}
	//	puts("end");
	//}
	
	vi girls(400000);
	for(int q,l;scanf("%d%d",&q,&l),q|l;){
		SegTree st(q);
		int gsize=0;
		map<int,int> m;
		rep(i,q){
			int qu,x; scanf("%d%d",&qu,&x);
			switch(qu){
			case 0:{
				st.add(gsize,1);
				m[x]=gsize;
				girls[gsize++]=x;
				if(st.data[1]>l){
					int j=st.ith(0);
					st.add(j,-1);
				}
			}break;
			case 1:{
				int j=st.ith(x-1);
				st.add(j,-1);
			}break;
			case 2:{
				int j=st.ith(x-1);
				printf("%d\n",girls[j]);
			}break;
			case 3:{
				int j=m[x];
				st.add(j,-1);
			}break;
			}
		}
		puts("end");
	}
	
	return 0;
}

Measured memory_bytes: 18000
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
using namespace std;

int main()
{
  long n;

  cin >> n;
  vector<long> a(n);

  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }

  int pos = 1;
  long ans = -1;
  for (int i = 0; i < n; ++i)
  {
    pos = a[pos - 1];
    if (pos == 2) {
      ans = i+1;
      break;
    }
  }


  cout << ans;


  return 0;
}






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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	cin >> s;
	ll sum = 0;
	for (auto ss : s) {
		sum += ss - '0';
	}
	if (sum % 9  == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 3732
#include <stdio.h>

int main(void)
{
	long inp,inp2;
	scanf("%ld %ld", &inp, &inp2);
	if (inp == inp2)
	{
		printf("a == b\n");
	}
	else if(inp < inp2)
	{
		printf("a < b\n");
	}
	else if(inp > inp2)
	{
		printf("a > b\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef int in;
typedef long long ll;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007;
in p2(in a){
  return 1<<a;
}
vector<ll> wys;
in n;
void goup(){
  in pn=p2(n);
  in pi;
  forn(i,n){
    pi=p2(i);
    in pl=p2(n-1-i);
    in pr=p2(i);
    in msk;
    in nxt;
    forn(msk,pn){
      if(msk&pi)
	continue;
      nxt=i;
      while(nxt<n && !(msk&p2(nxt)))
	++nxt;
      if(nxt<n)
	wys[(msk|pi)^p2(nxt)]+=wys[msk];
      else
	wys[msk|pi]+=wys[msk];
    }
  }
}

VI condmembers;
VI condvalue;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in m,k;
  cin>>n>>m>>k;
  --n;
  wys.resize(p2(n));
  wys[0]=1;
  condmembers.resize(m);
  condvalue.resize(m);
  in a,b,c;
  forn(z,k){
    cin>>a>>b>>c;
    --a;
    --b;
    condmembers[a]|=p2(b);
    condvalue[a]|=c*p2(b);
  }
  forn(z,m){
    goup();
    forn(msk,p2(n)){
      if((msk&condmembers[z])!=condvalue[z])
	wys[msk]=0;
      wys[msk]%=mdl;
    }
  }
  ll sm=0;
  forn(i,p2(n))
    sm+=wys[i];
  sm%=mdl;
  if(sm<0)
    sm+=mdl;
  cout<<sm<<endl;
  return 0;
}


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

for k in range(K):
    if k % 2 == 0:
        if A % 2 == 1:
            A -= 1
        B += int(A / 2)
        A -= int(A / 2)
    if k % 2 == 1:
        if B % 2 == 1:
            B -= 1
        A += int(B / 2)
        B -= int(B / 2)

print(A, B)


Measured memory_bytes: 3316
import itertools

S = [ (n) for n in input()]
ans = []
n= len(S)-1

l = ["+", ""]
pattern = list(itertools.product(l, repeat=n))
for p in pattern:
    t = ""
    for i in range(n):
        t += S[i]+p[i]
    t=t+S[n]
    ans.append(eval(t))

print(sum(ans))

Measured memory_bytes: 3064
import std.stdio,std.conv, std.algorithm;
import std.container,std.array,std.range;
import std.string,std.typecons,std.numeric;
import std.math,std.random,std.functional,std.regex;


double getExpected(int[] vs,double[] rs,int n,int m){
	double res = 0;	
	double sum = rs.sum;
	foreach(i;0..m){
		res += vs[i] * rs[i] / sum; 
	}
	return res; 
}


void main(){	
	int t = read(); // ?????????????????°
	t ++; 
	double max_p = 0;
	double last_p = 0;
    foreach(i;0..t){
		int n,m;   // m (??°?????????)< n
		read(n,m);
		auto vs = new int [m];
		auto rs = new double [m];
		foreach(j;0..m) read(vs[j],rs[j]);
	    auto p = getExpected(vs,rs,n, m);
		if (i == t-1)last_p = p; 
		else max_p = max_p.max(p);
		//p.writeln;
	}
	//max_p.writeln;
	//last_p.writeln;
	if(last_p + 0.0000001 <=  max_p) "YES".writeln;
	else "NO".writeln;
}














int   read(){int n;read(n);return n;}
void  read(T...)  (auto ref T args){mixin(readMixin);}
void  readArray(T)(auto ref T args){mixin(readMixin);}
const readMixin = q{
	auto line = readln().split();
	foreach(i,ref arg; args){
		if (i >= line.length) return;
		arg = line[i].to!(typeof(arg));
	}
};
void times(int n,void delegate() stmt){ foreach(i;0..n)stmt();}
void Swap(T)(ref T a,ref T b){T t = a;a = b;b = t;}

Measured memory_bytes: 2516
#include<bits/stdc++.h>
using namespace std;
int main()
    {
    long long n,p;
    cin>>n>>p;
    long long w[n],v[n];
    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];
    long long track[n+1][p+1];
    for(int i=0;i<p+1;i++)
        track[0][i]=0;
    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<p+1;j++)
        {
            if (w[i-1]<=j)
                track[i][j]=max(v[i-1]+track[i-1][j-w[i-1]],track[i-1][j]);
            else
                track[i][j]=track[i-1][j];
        }
    }
    cout<<track[n][p];
    return(0);
    }


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(v,a) for(auto &v:a)
#define fi first
#define se second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(a) a.begin(),a.end()
int re(){int x=0; char c; bool neg=false;while(c!='-'&&(c<'0'||'9'<c)) c=getchar();if (c=='-'){neg=true; c=getchar();}while ('0'<=c && c<='9'){x=x*10+c-'0';c=getchar();}if (neg) x=-x;return x;}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ran(int l, int r) {return l+rng()%(r-l+1);}
typedef long long ll;
const int N=3010;
int n,m;
string s,t;
int f[N][N];
struct aa{int u,v,o;};
aa tr[N][N];
vector<char> ans;
int main()
{
    //freopen("lcs.inp","r",stdin);
    cin>>s>>t;
    n=s.size(); m=t.size(); s=' '+s; t=' '+t;
    forinc(i,1,n) forinc(j,1,m)
    {
        if (s[i]==t[j]) f[i][j]=f[i-1][j-1]+1,tr[i][j]={i-1,j-1,1};
        else
        {
            if (f[i-1][j]>=f[i][j-1])
            {
                f[i][j]=f[i-1][j];
                tr[i][j]={i-1,j,0};
            }
            else f[i][j]=f[i][j-1],tr[i][j]={i,j-1,0};
        }
    }
    int i=n,j=m;
    while (i && j)
    {
        aa tg=tr[i][j];
        if (tg.o) ans.pb(s[i]);
        i=tg.u,j=tg.v;
    }
    reverse(all(ans));
    forv(v,ans) cout<<v;
}


Measured memory_bytes: 141696
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    set<int> st;
    imfor(i, n) {
        int a;
        cin >> a;
        st.insert(a);
    }
    if (st.size() % 2 == 0) {
        cout << st.size() - 1 << endl;
    }
    else {
        cout << st.size() << endl;
    }
}

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

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

    int A, B;
    cin >> A >> B;

    if(A + B >= 10){
        cout << "error" << endl;
    }
    else {
        cout << A + B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    
    ll L = 0, R = 0;

    rep(i, s.size()){
        if(i == 0){
            R ++;
            continue;
        }
        if((s[i] != s[i-1] and s[i] == 'R' ) or (i == s.size()-1) ){
            if(i == s.size()-1) L++;
            ll r,l;
            r = (L+R)/2;
            l = (L+R)/2;
            if((L+R)%2 == 1){
                if(L%2 == 1) l++;
                if(R%2 == 1) r++;
            }
            
            rep(i, R){
                if(i == R-1) cout << r << " ";
                else cout << "0 ";
            }
            rep(i,L){
                if(i == 0) cout << l << " ";
                else cout << "0 ";
            }
            
                
                
            
            R = 1;
            L = 0;
        }else{
            if(s[i] == 'L') L++;
            else R++;
        }
        
    }

    cout << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}
/*

RRL RL
012 11
RRLLLL RL RRLL
033000 11 0220
RRRLL RLL RRRLLLLL
00320 210 00440000


// even/odd
RRRRRRL
1111111
0111121
0011122
0001132
0000133
0000043
0000034

RRRRL
11111
01121
00122
00032
00023

RRLLL
11111
02210
02300


//odd/even
RRRRRLL
1111111
0111220
0011320
0001330
0000430
0000340
*/



/*
 RRL
 111
 021
 012
 */


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<string, int> counter;
  string x;
  for (int i = 0; i < N; ++i) {
    cin >> x;
    counter[x]++;
  }
  int max_count = 0;
  for (const auto& m : counter) {
    max_count = max(max_count, m.second);
  }
  for (const auto& m : counter) {
    if (m.second == max_count) {
      cout << m.first << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 25216
#include <stdio.h>
int main(){
  int n,in[1000001],cnt=0,i,j,sum;
  while(1){
    scanf("%d",&n);
    if(n==0){
      break;
    }
    
    for(i=0;i<n;i++){
      scanf("%d",&in[i]);
    }
    
    for(i=0;i<n;i++){
      for(j=0;j<n-1;j++){
	if(in[j]>in[j+1]){
	sum=in[j];
          in[j]=in[j+1];
          in[j+1]=sum;
          cnt=cnt+1;
      }
      }
    }
    
    printf("%d\n",cnt);
    cnt=0;
  }
  
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>


using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "SUN") {
		cout << "7" << endl;
	}
	if (s == "MON") {
		cout << "6" << endl;

	}
	if (s == "TUE") {
		cout << "5" << endl;

	}
	if (s == "WED") {
		cout << "4" << endl;

	}
	if (s == "THU") {
		cout << "3" << endl;

	}
	if (s == "FRI") {
		cout << "2" << endl;

	}
	if (s == "SAT") {
		cout << "1" << endl;

	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  string s; cin>>s;
  ll K; cin>>K;
  rep(i,s.size()){
    if(s[i]!='1'&&i<K){
      cout<<s[i]<<endl;
      return 0;
    }
  }
  cout<<1<<endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque
s = deque(input())
q = int(input())
k = 0

for _ in range(q):
    Q = list(map(str,input().split()))
    if int(Q[0]) == 1:
        if k == 0:
            k = 1
        else:
            k = 0
    else:
        if k == 0:
            if int(Q[1]) == 1:
                s.appendleft(Q[2])
            else:
                s.append(Q[2])
        else:
            if int(Q[1]) == 1:
                s.append(Q[2])
            else:
                s.appendleft(Q[2])


if k == 1:
    s = list(s)[::-1]
    
print("".join(s))

Measured memory_bytes: 10228
import bisect
from collections import deque

N, H = map(int, input().split())
furi = deque()
nage = deque()
for _ in range(N):
  a, b = map(int, input().split())
  furi.append(a)
  nage.append(b)
furu = sorted(furi)[-1]
nage = sorted(nage)
nage = deque(nage[bisect.bisect(nage, furu):])
ans = 0
while H > 0 and nage:
  ans += 1
  n = nage.pop()
  H -= n
if H > 0:
  ans += H//furu+(0 if H%furu==0 else 1)
print(ans)

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

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] h = new int[n+1];
        for(int i = 1; i <= n; i++){
            h[i] = Integer.parseInt(sc.next());
        }
        
        boolean[] good = new boolean[n+1];
        Arrays.fill(good, true);
        for(int i = 0; i < m; i++){
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            if(h[a] <= h[b]){
                good[a] = false;
            }
            if(h[b] <= h[a]){
                good[b] = false;
            }
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
            if(good[i]) ans++;
        }
        System.out.println(ans);
    }
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>


using namespace std;
const ll maxn=5e5+100,inf=1e18,LOG=23,mod=1e9 + 7;
int block = 300, timer = 0;
const ld EPS = 1e-7;

#define bt(i) (1 << (i))
//#define int ll

int a, b;

main()
{
	cin >> a >> b;
	a--;
	b--;
	cout << b / a + (bool)(b % a);
}

Measured memory_bytes: 256
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

# n, k = map(int, input().split())
# nums = list(map(int, stdin.readline().split()))
# nums.sort()
# print(sum(nums[:k]))

n = input()
if n.isupper():
    print('A')
else:
    print('a')

Measured memory_bytes: 72784
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	if(y%2==1)cout<<"No";
	else if(y>4*x||y<2*x)cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll sum1(ll x)
{
    ll sum = 0;
    while (x != 0)
    {
        ll r = x % 10;
        x = x / 10;
        sum = sum + r;
    }
    return (sum);
}

int main()
{
//#ifndef ONLINE_JUDGE
  //  freopen("q1.txt", "r", stdin);
   // freopen("pelu13.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    map<string, ll>m1;
    while (n--)
    {
        string s;
        cin >> s;
        m1[s]++;
    }
    cout << "AC x " << m1["AC"] << endl;
    cout << "WA x " << m1["WA"] << endl;
    cout << "TLE x " << m1["TLE"] << endl;
    cout << "RE x " << m1["RE"] << endl;

}







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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,a,b,c,x;
    cin >> n >> a >> b >> c >> x;
    if(n==0) return 0;
    int ans=0;
    int y;
    for(int i=0;i<n;i++){
      cin >> y;
      while(x!=y&&ans<=10000){
        x=(a*x+b)%c;
        ans++;
      }
      x=(a*x+b)%c;
      ans++;
    }
    if(ans>10001){
      cout << -1 << endl;
      continue;
    }
    cout << ans-1 << endl;
  }
  return 0;
}



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

using namespace std;

int n,k,i,j,d,suma,odp;
int tablica[10003][103];
char slowo[10003];

int main() {
	cin >> slowo+1 >> k;
	n=strlen(slowo+1);
	tablica[1][0]=1;
	for(i=2;i<=n;i++){
		for(d=0;d<=9;d++){
			for(j=0;j<=k;j++){
                tablica[i][(d+j)%k]=(tablica[i][(d+j)%k]+(tablica[i-1][j]+1000000007)%1000000007)%1000000007;
			}
        }
    }
	for(i=1;i<=n;i++){
		for(j=0;j<slowo[i]-'0';j++){
            odp=(odp+(tablica[n-i+1][(-(suma+j)%k+k)%k]+1000000007)%1000000007)%1000000007;
		}
		suma=(suma+slowo[i]-'0')%k;
	}
	if(suma){
        odp=(odp+(-1+1000000007)%1000000007)%1000000007;
	}
    cout << odp;
	return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if (a == b){
    ans = a*2;
  }
  else{
    ans = 2*max(a, b)-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "stdio.h"
 

int N, K;
int A[200000];
int cnt[200000];
 
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
#define SWAP(type,a,b) { type work = a; a = b; b = work; }

static void quick_sort(int* array, size_t size);
static void quick_sort_rec(int* array, int begin, int end);
static int select_pivot(int* array, int begin, int end);

/*
	クイックソート (昇順)
*/
void quick_sort(int* array, size_t size)
{
	/* 配列全体を対象にする */
	quick_sort_rec( array, 0, size - 1 );
}

/*
	クイックソート (再帰部分、昇順)
*/
void quick_sort_rec(int* array, int begin, int end)
{
	int pivot = select_pivot( array, begin, end );
	int i = begin;
	int j = end;

	while( 1 ){
		while( array[i] < pivot ){ ++i; }  /* 基準値以上の値が見つかるまで右方向へ進めていく */
		while( array[j] > pivot ){ --j; }  /* 基準値以下の値が見つかるまで左方向へ進めていく */

		if( i >= j ){ break; }  /* 左右から進めてきたiとjがぶつかったらループを終える */
		
		/* 基準値位置よりも左側にあり、基準値よりも大きい値 (array[i]) と、
		   基準値位置よりも右側にあり、基準値よりも小さい値 (array[j]) の
		   位置関係を交換する。
		*/
		SWAP( int, array[i], array[j] );
		
		/* 次回に備えて、注目点をずらす */
		i++;
		j--;
	}


	/* 基準値の位置より左側に要素が２つ以上あれば、その部分についてクイックソートを再帰させる */
	if( i - begin >= 2 ){
		quick_sort_rec( array, begin, i - 1 );
	}

	/* 基準値の位置より右側に要素が２つ以上あれば、その部分についてクイックソートを再帰させる */
	if( end - j >= 2 ){
		quick_sort_rec( array, j + 1, end );
	}
}

/*
	基準値を選ぶ
*/
int select_pivot(int* array, int begin, int end)
{
	return array[(begin + end) / 2];  /* 中央の要素を基準値とする */
}
int main(void){
	int i;
	int sum = 0;

	scanf("%d%d", &N, &K);

	for(i=0;i<N;i++){
		scanf("%d", &A[i]);
		cnt[A[i]-1]++;
	}

    quick_sort(cnt, N);

	for(i=N-1;i>=N-K;i--){
		sum += cnt[i];
	}
	sum = N - sum;

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

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  if(x == 3 || x == 5 || x == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main()
{
  long int N, K;

  cin >> N >> K;

  long int num1, num2;

  if (N > K)
  {
    num1 = N % K;
    num2 = K - num1;
  }
  else if (N < K)
  {
    num1 = N;
    N = K - N;
    num2 = N;
  }
  else
  {
    num1 = N;
    num2 = N - K;
  }

  if (num1 <= num2)
  {
    cout << num1 << endl;
  }
  else
  {
    cout << num2 << endl;
  }
}


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

#define ll long long

ll gcd(ll A, ll B) {

    if (A < B) {
        ll tmp = A;
        A = B;
        B = tmp;
    }

    ll r = A % B;
    while(r != 0) {
        A = B;
        B = r;
        r = A % B;
    }

    return B;
}

ll lcm(ll A, ll B) {
    ll ab_gcd = gcd(A, B);
    return (A * B) / ab_gcd;
}

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

    ll ans = lcm(A, B);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream&o,const pair<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
template<typename T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

void RE(){cout<<1/0;}
void TLE(){sleep(100);}
void WA(){cout<<char(0);exit(0);}

const int N = 1e5;
string s, t;
set<int> c[26];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s >> t;
  int ss = sz(s);
  FOR(i, 0, ss){
    int cc = s[i]-'a';
    c[cc].insert(i);
    c[cc].insert(i+ss);
  }
  ll idx = 0;
  FOR(i, 0, sz(t)){
    int cc = t[i]-'a', j = idx%ss;
    auto itr = c[cc].lower_bound(j);
    if(itr == c[cc].end()){
      cout << -1 << endl;
      return 0;
    }
    idx += *itr-j+1;
  }
  cout << idx << endl;
}

Measured memory_bytes: 9808
#include <iostream>
using namespace std;
int main(void){
  int k, n;
  cin >> k >> n;
  for(int i = n - k + 1; i <= n + k - 1; i++){
    if(i >= -1000000 && i <= 1000000){
      cout << i << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
A = Array.new(N) { Array.new }
N.times do |i|
  a = gets.chomp.to_i
  a.times do
    x,y = gets.chomp.split.map(&:to_i)
    A[i] << [x,y]
  end
end

ans = 0
[0, 1].repeated_permutation(N) do |arr|
  ok = true
  A.each_with_index do |a, index|
    a.each do |x, y|
      if arr[index] == 1 && arr[x-1] != y 
        ok = false
      end
    end
  end
  ans = [arr.count(1),ans].max if ok
end
puts ans


Measured memory_bytes: 3836
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int a = 0;
		int i = 0;
		for( i = 0;;i++) {
			a = y * i + z * (i + 1);
			if(a > x)break;
		}
		System.out.println(i - 1);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long double

int main()
{
	int N;
	cin>>N;
	
	ll prob[N];
for(int i=0;i<N;i++)
{
	cin>>prob[i];
	}
	
	ll dp[N+1][N+1];
	
	dp[1][0]=1-prob[0]; dp[1][1]=prob[0];
	
	dp[2][0]=(1-prob[0])*(1-prob[1]);
	dp[2][1]=(1-prob[0])*(prob[1])+(prob[0])*(1-prob[1]);
	dp[2][2]=prob[0]*prob[1];
	
	for(int i=3;i<=N;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(j==0)
			{
				dp[i][j]=dp[i-1][0]*(1-prob[i-1]);
			}
			
			else if(j==i)
			{
				dp[i][j]=dp[i-1][j-1]*prob[i-1];
			}
			
			else
			{
				dp[i][j]=dp[i-1][j-1]*prob[i-1]+dp[i-1][j]*(1-prob[i-1]);
			}
		}
	}
	ll ans=0;
	int mid=N/2;
	
	for(int i=mid+1;i<=N;i++)
	{
		ans=ans+dp[N][i];
	}
	cout<<setprecision(11)<<ans<<endl;
}



Measured memory_bytes: 140672
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m,k=map(int,input().split())
uf=UnionFind(n)
fr=[set() for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    fr[a-1].add(b-1)
    fr[b-1].add(a-1)
    uf.union(a-1,b-1)
br=[set() for _ in range(n)]
for i in range(k):
    a,b=map(int,input().split())
    br[a-1].add(b-1)
    br[b-1].add(a-1)
ans=[0]*n
for i in range(n):
    t=uf.size(i)-len(fr[i])-1
    for j in br[i]:
        if uf.same(i,j):
            t-=1
    ans[i]=t
print(*ans)

Measured memory_bytes: 127852
#include <bits/stdc++.h>
using namespace std;
//static const int INF = (1 << 21);
typedef long long ll;
int main(void){
    // Your code here!
    ll N;
    cin >> N;
    vector<ll> vec(5);
    for(int i = 0; i < 5; i++)cin >> vec.at(i);
    sort(vec.begin(),vec.end());
    ll ans = 5;
    
    if(vec.at(0) < N){
        ans += N / vec.at(0);
    }
    if(N % vec.at(0) == 0){
        ans--;
    }
    
    cout << ans << endl;
}

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

using namespace std;

int get_divisor(int k) {
    int count = 0;
    for (int i = 1; i <= k; i++) {
        if (k % i == 0) {
            count++;
        }
    }
    return count;
}

int main()
{
    int n;
    cin >> n;
    int count = 0;
    for (int i = 1; i <= n; i += 2) {
        if (get_divisor(i) == 8) {
            count++;
        }
    }
    cout << count << endl;
}

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

int n,m,l;

void solve(int p, int d){
  
  if(p == m){
    printf("%d\n",p);
    return;
  }
  
  printf("%d ",p);
  
  if(p == 9) solve(5, 0);
  else if(!p || d) solve(p+1, 1);
  else solve(p-1, 0);

}

int main(){
  
  scanf("%d",&l);
  
  while(l--){
    scanf("%d%d",&n,&m);
    if(n == 9 || (n < 6 && n > m)) solve(n, 0);
    else solve(n, 1);
  }
  
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int n;
double ans,p[3005],dp[3005][3005];

int main(){
  cin >> n;
  for(int i=1;i<=n;++i){
    cin >> p[i];
  }
  dp[0][0]=1;
  for(int i=1;i<=n;++i){
    dp[i][0]=dp[i-1][0]*(1-p[i]);
    dp[0][i]=0;
  }
  for(int i=1;i<=n;++i){
    for(int j=1;j<=i;++j){
        dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*(p[i]);
        if(i==n && j>n/2){
            ans+=dp[i][j];
        }
    }
  }
  cout << fixed << setprecision(10) << ans;
  return 0;
}


Measured memory_bytes: 69120
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    start, goal = (0, 0), (high - 1, width - 1)

    now_data = set()
    now_data.add(start)
    next_data = set()
    pre_data = set()
    pre_data.add(start)

    move_tada = [[-1, 0], [1, 0], [0, 1], [0, -1]]

    count = 1
    while len(now_data) > 0:
        if goal in pre_data:
            break
        count += 1
        for now_x, now_y in now_data:
            for add_x, add_y in move_tada:
                move_x, move_y = now_x + add_x, now_y + add_y
                if 0 <= move_x < high and 0 <= move_y < width:
                    if data[move_x][move_y] == '.' and (move_x, move_y) not in pre_data:
                        ok_data = (move_x, move_y)
                        pre_data.add(ok_data)
                        next_data.add(ok_data)
        now_data = next_data
        next_data = set()

    if goal in pre_data:
        white_data = 0
        for i in range(high):
            white_data += data[i].count('.')
        print(white_data - count)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
package main

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

func BufScan(n int) []string {
	var in []string
	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		in = append(in, sc.Text())
	}

	return in
}

func IntBufScan(n int) []int {
	var inInts []int
	inStrings := BufScan(n)
	for _, i := range inStrings {
		tmp, _ := strconv.Atoi(i)
		inInts = append(inInts, tmp)
	}
	return inInts
}

func main() {
	n := 0
	fmt.Scanf("%d", &n)
	a := IntBufScan(n)
	m := 1
	for i := 1; ; i++ {
		m = a[m-1]
		if m == 1 || i > n {
			fmt.Println("-1")
			return
		}
		if m == 2 {
			fmt.Println(i)
			return
		}
	}
}


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int q, h, s, d;
int n;

long long ans;

int main(){
	scanf("%d %d %d %d", &q, &h, &s, &d);
	scanf("%d", &n);
	h = min(h, 2 * q);
	s = min(s, 2 * h);
	d = min(d, 2 * s);
	ans = 1LL * (n / 2) * d + (n % 2) * s;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n;
  int a;
  int min = 1000000;
  int max = -1000000;
  long sum = 0;

  scanf("%d", &n);

  while (n--) {
    scanf("%d", &a);
    if (min > a) min = a;
    if (max < a) max = a;
    sum += a;
  }
  printf("%d %d %ld\n", min, max, sum);
  return (0);
}



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

int main(){
  int A,B,C,hold;
  cin >> A>>B>>C;
 
  hold=A;
  A=B;
  B=hold;
  hold=A;
  A=C;
  C=hold;
  cout<<A<<" "<<B<<" "<<C<<endl;
  
  

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>



int main() {
  long i, j, N, X, Y, ans[2005] = { 0 },dis[3];
  scanf("%ld %ld %ld", &N, &X, &Y);
  for (i = 1; i < N; i++) {
    for (j = i + 1; j <= N; j++) {
      dis[0] = j - i;
      dis[1] = (X - i > 0 ? X - i : (i - X)) + (Y - j > 0 ? Y - j : (j - Y)) + 1;
      if (dis[0] < dis[1]) {
        ans[dis[0]]++;
      }
      else{
        ans[dis[1]]++;
      }
    }
  }
  for (i = 1; i < N; i++) {
    printf("%ld\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 128
import heapq
import math
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())

tobool = lambda s: s == "#"

S = [
  list(map(tobool, input())) for _ in range(H)
]
visited_m = [[False for w in range(W) ] for h in range(H)]
cost_m = [[math.inf for w in range(W) ] for h in range(H)]

def enum_moveA(Ch, Cw):
  return [(Ch-1, Cw), (Ch+1, Cw), (Ch, Cw-1), (Ch, Cw+1)]

def enum_moveB(Ch, Cw):
  return [
    (Ch-2, Cw-2), (Ch-2, Cw-1), (Ch-2, Cw), (Ch-2, Cw+1), (Ch-2, Cw+2),
    (Ch-1, Cw-2), (Ch-1, Cw-1), (Ch-1, Cw+1), (Ch-1, Cw+2),
    (Ch, Cw-2), (Ch, Cw+2),
    (Ch+1, Cw-2), (Ch+1, Cw-1), (Ch+1, Cw+1), (Ch+1, Cw+2),
    (Ch+2, Cw-2), (Ch+2, Cw-1), (Ch+2, Cw), (Ch+2, Cw+1), (Ch+2, Cw+2),
  ]

d = deque()
d.appendleft((0, Ch, Cw))
while True:
  if len(d) == 0:
    break
  visited_m[Ch][Cw] = True
  c_cost, Ch, Cw = d.popleft()
  if Ch == Dh and Cw == Dw:
    break
  for h, w in enum_moveA(Ch, Cw):
    if 0 <= h <H and 0 <= w <W:
      tmp_cost = cost_m[h][w]
      visited = visited_m[h][w]
      kabe = S[h][w]
      if c_cost + 0 < tmp_cost and not visited and not kabe:
        cost_m[h][w] = c_cost + 0
        d.appendleft((c_cost + 0, h, w))
        
  for h, w in enum_moveB(Ch, Cw):
    if 0 <= h <H and 0 <= w <W:
      tmp_cost = cost_m[h][w]
      visited = visited_m[h][w]
      kabe = S[h][w]
      if c_cost + 1 < tmp_cost and not visited and not kabe:
        cost_m[h][w] = c_cost + 1
        d.append((c_cost + 1, h, w))
    
total_cost = cost_m[Dh][Dw]
if total_cost < math.inf:
  print(total_cost)
else:
  print(-1)

Measured memory_bytes: 147548
# imos 法
N, K, Q = map(int, input().split())
cs = [0] * N
cs[0] = K
for _ in range(Q):
    A = int(input())
    if A == 1:
        cs[1] -= 1
    elif A == N:
        cs[0] -= 1
        cs[N - 1] += 1
    else:
        cs[0] -= 1
        cs[A - 1] += 1
        cs[A] -= 1
for i in range(1, N):
    cs[i] += cs[i - 1]
for i in cs:
    if i > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8820
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define li long long
#define gc getchar()
#define pc putchar
li read(){
	li x = 0,y = 0,c = gc;
	while(!isdigit(c)){y = c;c = gc;}
	while(isdigit(c)){x = (x << 1) + (x << 3) + (c ^ '0');c = gc;}
	return y == '-' ? -x : x;
}
void print(li x){
	if(x < 0){pc('-');x = -x;}
	if(x >= 10) print(x / 10);
	pc(x % 10 + '0');
}
void file(){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int n,a[200010];
li ans;
int main(){
	//file();
	int i,j;
	n = read();
	for(i = 1;i <= n;++i) a[i] = read();
	//sort(a + 1,a + n + 1);
	for(i = 1;i <= n;++i) a[i] -= i;
	sort(a + 1,a + n + 1);
	j = a[(n + 1) / 2];
	for(i = 1;i <= n;++i) ans += abs(a[i] - j);
	print(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

using namespace std;

const int n = 100;///change to 100

int res[n + 1][n + 1];

void fill1(int i)
{
	for(int l = 1; l <= n; l++)
		res[i][l] = 1;
}

main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	
	b--;
	a -= (b > 0);
	
	int i = 1;
	while(b)
	{
		fill1(i);
		for(int j = 2; j < n && b; j += 2)
		{
			res[i][j] = 0;
			b--;
		}
		i++;
		fill1(i);
		i++;
	}
	i++;
	
	while(a)
	{
		for(int j = 1; j < n && a; j += 2)
		{
			res[i][j] = 1;
			a--;
		}
		i += 2;
	}
	i++;
	
	printf("%d %d\n", n, n);
	
	//for(int i = 1; i <= n; i++)
	//{
		//for(int j = 0; j < n; j++)
		//{
			//printf("%d ", 1 - res[i][j]);
		//}
		//puts("");
	//}
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if(res[i][j]) printf(".");
			else printf("#");
		}
		puts("");
	}
}
/**
7 1 2 3 4 5 6 7
**/


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define N 50000
using namespace std;
typedef long long ll;
bool used[N];

ll SumD(ll a,ll d,ll n){return (n*(2*a+(n-1)*d))/2;}

bool mark(ll n){
  bool res=1;
  for(ll i=1;i*i<=N;i++)res&=!used[i],used[i]=1;
  return res;
}

int main(){
  while(1){
    ll n,m,p[21];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<m;i++)cin>>p[i];
    sort(p,p+m);
  
    ll sum=0,cnt=0;
    for(int i=0;i<m;i++){
      sum+=SumD(p[i],p[i],n/p[i]);
      cnt+=n/p[i];
      memset(used,0,sizeof(used));
      for(int j=0;j<i;j++){
	ll lcm=(p[i]/__gcd(p[i],p[j]))*p[j];
	if(!mark(lcm))continue;
	sum-=SumD(lcm,lcm,n/lcm);
	cnt-=(n/lcm);
      }
    }

    printf("%.8f\n",(1.0*SumD(1,1,n)-sum)/max(1LL,(n-cnt)));
  }
  return 0;
}

Measured memory_bytes: 3328
# import numpy as np
# import math
# import copy
from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    H,W = map(int,input().split())
    s = [ input().rstrip() for _ in range(H) ]

    INF = 10 ** 9 + 7

    dp = [ [ INF for i in range(W) ] for j in range(H) ]

    if s[0][0] == '#':
        dp[0][0] = 1
    else:
        dp[0][0] = 0

    for i in range(H):
        for j in range(W):
            if i != 0:
                if (s[i][j] == '#') & (s[i-1][j] == '.'):
                    cost = 1
                else:
                    cost = 0
                dp[i][j] = min(dp[i][j],dp[i-1][j] + cost)
            if j != 0:
                if (s[i][j] == '#') & (s[i][j-1] == '.'):
                    cost = 1
                else:
                    cost = 0
                dp[i][j] = min(dp[i][j],dp[i][j-1] + cost)

    print(dp[H-1][W-1])



main()


Measured memory_bytes: 3444
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(void){
    int n,q;
    cin>>n;
    int* S=(int*)malloc(n*sizeof(int));
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    cin>>q;
    int* T=(int*)malloc(q*sizeof(int));
    for(int i=0;i<q;i++){
        cin>>T[i];
    }
    bool exist;
    int C=0;
    for(int i=0;i<q;i++){
        exist=false;
        for(int j=0;j<n;j++){
            if(S[j]==T[i]){
                exist=true;
            }
        }
        if(exist){
            C++;
        }
    }
    cout<<C<<endl;
}



Measured memory_bytes: 3104
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

#define N 100

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d",&a[i]);
        sum += a[i];
    }
    int target_c = ceil((float)sum/n);
    int target_f = sum/n;
    int res_c = 0;
    int res_f = 0;
    for (int i = 0; i < n; i++) {
        res_c += (a[i] - target_c) * (a[i] - target_c);
        res_f += (a[i] - target_f) * (a[i] - target_f);
    }
    printf("%d\n", min(res_c,res_f));
    return 0;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll n,a,b;
    cin>>n>>a>>b;
    if(a+b==0)
        return cout<<0,0;
    cout<<(n/(a+b))*a+min(n%(a+b),a);
}

Measured memory_bytes: 3616
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string,string,char
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int SED(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;
	
	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	YES(a == f && b == e && c == d);

	please AC;
}

Measured memory_bytes: 256
N,D = map(int,input().split())
X = list(list(map(int,input().split()))for i in range(N))

def leng(A,B):
    ans = 0
    for i in range(len(A)):
        ans += (A[i]-B[i])**2
    return ans**0.5
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if leng(X[i],X[j]) % 1 == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3188
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, K = map(int, input().split(' '))

if K < A:
    print(K)
elif A <= K <= (A+B):
    print(A)
elif (A+B) < K:
    print(A-(K-A-B))


Measured memory_bytes: 27128
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int,input().split())]

ans = 100000000 # inf
for d in range(100): # [0,100)
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = x-d
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = x+d
print(ans)


Measured memory_bytes: 9200