akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int x = sc.nextInt();
        
        int[] a = new int[N];
        
        for(int i = 0;i<N;i++){
        	a[i] = sc.nextInt();
        }
        sc.close();
        
        Arrays.sort(a);
        
      int sum = 0;   
      int i = 0;

      for(i = 0;i<N;i++){
        sum += a[i];
        if(sum > x){
          break;
        }
      }
      if(i==N&&sum!=x){
        i -= 1; 
      }      
      
      System.out.println(i);

	}
}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  int n;
  cin >> n;
  VI d(n);
  rep(i,n){
      cin >> d.at(i);
    }
    sort(d.begin(),d.end());
  int ans=d.at(n/2) - d.at((n/2)-1);
  cout << ans << endl;  
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();ite++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

//---------------------
#define MAXN 100000
//---------------------

ll n,k;

int main(){
	cin>>n>>k;
	cout<<(k*ll(pow(k-1,n-1)))<<endl;
	return 0;
}

Measured memory_bytes: 512
function Main(input) {
  var [a, b] = input.split(" ").map(Number);
  if(b > a) [a, b] = [b, a];
  var r;
  do {
    r = a % b;
    a = b;
    b = r;
  } while(r)
  console.log(a);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 15164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, b, t;
  string s;
  in2(n, s);
  a = 0;
  b = n - 1;
  t = 0;
  while(a < b){
    while(s[a] == 'R' && a < n){
      a++;
    }
    if(a == n)
      break;
    while(s[b] == 'W' && b > -1){
      b--;
    }
    if(b == -1)
      break;
    if(a < b){
      s[a] = 'R';
      s[b] = 'W';
      t++;
    }
  }
  out(t);
  memi;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);i++)

typedef long long int ll;
typedef pair<int, int> pil;
template<typename T> using  vec = std::vector<T>;

const int inf = 1 << 30;
const long long int infll = 1LL << 62;
const double eps = 1e-9;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

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

	int n, m;

	cin >> n >> m;

	bool zeroflag = true;
	bool oneflag = true;

	vec<int> bits(n);
	vec<int> p(m);
	int zerocount = 0;
	int onecount = 0;

	rep(i, 0, n) {
		cin >> bits[i];

		if (bits[i] == 0) {
			zerocount++;
		}
		else {
			onecount++;
		}
	}

	rep(i, 0, m) {
		cin >> p[i];
	}

	vec<int> ans(n);
	int cur = 0;
	int zc = 0;
	int oc = 0;

	rep(i, 0, m) {
		rep(j, 0, p[i]) {
			if (i % 2 == 0) {
				ans[cur] = 0;
				cur++;
				zc++;
			}
			else {
				ans[cur] = 1;
				cur++;
				oc++;
			}
		}
	}

	int answer = inf;

	if (zc == zerocount&&oc == onecount) {
		int tempans = 0;
		vec<int> tempbits = bits;

		rep(i, 0, n) {
			if (tempbits[i] == ans[i]) {
				continue;
			}

			rep(j, i + 1, n) {
				if (tempbits[j] == ans[i]) {
					int temp = tempbits[j];

					for (int k = j; k > i; k--) {
						tempbits[k] = tempbits[k - 1];
					}

					tempbits[i] = temp;
					tempans += j - i;
					break;
				}
			}
		}

		answer = min(answer, tempans);
	}

	cur = 0;
	zc = 0;
	oc = 0;

	rep(i, 0, m) {
		rep(j, 0, p[i]) {
			if (i % 2 == 0) {
				ans[cur] = 1;
				cur++;
				oc++;
			}
			else {
				ans[cur] = 0;
				cur++;
				zc++;
			}
		}
	}

	if (zc == zerocount&&oc == onecount) {
		int tempans = 0;
		vec<int> tempbits = bits;

		rep(i, 0, n) {
			if (tempbits[i] == ans[i]) {
				continue;
			}

			rep(j, i + 1, n) {
				if (tempbits[j] == ans[i]) {
					int temp = tempbits[j];

					for (int k = j; k > i; k--) {
						tempbits[k] = tempbits[k - 1];
					}

					tempbits[i] = temp;
					tempans += j - i;
					break;
				}
			}
		}

		answer = min(answer, tempans);
	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 3212
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

void printIntInLine(vector<int> &arr) {
	for(vector<int>::iterator itr=arr.begin(); itr!=--(arr.end()); ++itr) {
		printf("%d ", *itr);
	}
	printf("%d\n", *(--(arr.end())));
}

int main() {
    int n, tmp, nSwap;
    vector<int> arr;

    scanf("%d", &n);

    for(int i=0; i<n; ++i) {
        scanf("%d", &tmp);
        arr.push_back(tmp);
    }

    nSwap = 0;

    for(auto itr=arr.begin(); itr!=arr.end(); ++itr) {
        auto mini = itr;
        for(auto itr2=itr; itr2!=arr.end(); ++itr2) {
            if(*itr2 < *mini) {
                mini = itr2;
            }
        }
        if(itr != mini) {
            swap(*itr, *mini);
            ++nSwap;
        }
    }

    printIntInLine(arr);
    printf("%d\n", nSwap);
}

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

int main(){
  int N, ans = 0;;
  cin >> N;
  map<int,int>mp;
  for (int i = 0; i < N; i++){
    int a;
    cin >> a;
    mp[a] += 1;
  }
  for (auto itr = mp.begin(); itr != mp.end(); itr++){
    if (itr->second % 2 != 0)
      ans++;
  }
  cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

template<class T>
T gcd(T a, T b){
  if(a > b) swap(a,b);
  if(a == 0) return b;
  return gcd(a, b%a);
}

ll meet(int ad, int av, int bd, int bv){
  ll aa = (ll)ad * bv;
  ll bb = (ll)bd * av;
  return (aa * bb / gcd(aa, bb)) / aa;
}

int main(){
  int n;
  while(scanf("%d",&n), n){
    int d[n],v[n];
    ll ans = 1;
    scanf("%d%d",&d[0],&v[0]);
    REP(i, n-1){
      int bd, bv;
      ll tmp;
      scanf("%d%d",&d[i+1],&v[i+1]);
      tmp = meet(d[0], v[0], d[i+1], v[i+1]);
      ans = (ans * tmp) / gcd(ans, tmp);
    }
    //printf("ans = %d\n",ans);
    REP(i,n)
      printf("%d\n",(int)(ans*d[0]*v[i]/d[i]/v[0]));
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main()
{
	char input[10000];
	int i = 0, JOI = 0, IOI = 0;
	for (i = 0; i<10000; i++)
	{
		input[i] = '\0';
	}
	while (scanf("%s", input) != EOF){
		i = JOI = IOI = 0;
		while (i + 2 < 10000 && input[i + 2] != '\0'){
			if (input[i] == 'J' && input[i + 1] == 'O' && input[i + 2] == 'I')
				JOI++;
			if (input[i] == 'I' && input[i + 1] == 'O' && input[i + 2] == 'I')
				IOI++;
			i++;
		}
		printf("%d\n%d\n", JOI, IOI);
	}
	return 0;
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
using namespace std;
string s,t;


int main(){
	cin>>s>>t;
	int ans=0;
	int len=s.length();
	for(int i=0;i<len;i++){
		if(s[i]!=t[i])ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3844
from sys import stdin
from math import ceil, floor
n, a, b = [int(x) for x in stdin.readline().rstrip().split()]
s = list(stdin.readline().rstrip())
d = 0
e = 0
for i in range(n):
    if d < a + b and s[i] == "a":
        print("Yes")
        d += 1
    elif d < a + b and e < b and s[i] == "b":
        print("Yes")
        d += 1
        e += 1
    else:
        print("No")

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    int cur=0;
    int ans=0;
    while(cur<N){
        int nex=cur;
        while(nex<N&&A[cur]==A[nex])nex++;
        ans+=(nex-cur)/2;
        cur=nex;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define lli long long int
vector<vector<int> > pstn;
int find_next(int lttr,int cur)
{
	// cout<<"enter find next "<<(char(lttr + (int)'a'))<<endl;
	int sz = pstn[lttr].size();
	// cout<<sz<<endl;
	if(cur>=pstn[lttr][sz-1])
		return pstn[lttr][0];
	int lo = 0;
	int hi = sz-1;
	int mid;
	while(lo<hi)
	{
		mid = lo + (hi-lo)/2;
		int vl = pstn[lttr][mid];
		if(vl>cur)
			hi = mid;
		else
			lo = mid + 1;
	}
	// cout<<"exit find next"<<endl;
	return pstn[lttr][lo];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s,t;
	cin>>s>>t;
	int i,j,k;
	int n = s.length();
	int m = t.length();
	vector<bool> sp;
	sp.resize(26);
	vector<bool> tp;
	tp.resize(26);
	pstn.resize(26);
	for(i=0;i<n;i++)
	{
		int nm = (int)s[i] - (int)'a';
		sp[nm] = true;
		pstn[nm].push_back(i);
	}
	for(i=0;i<m;i++)
	{
		int nm = (int)t[i] - (int)'a';
		tp[nm] = true;
	}
	bool pos = true;
	for(i=0;i<26;i++)
	{
		if(tp[i]&&(!sp[i]))
			pos = false;
	}
	if(pos)
	{
		vector<int> findpos;
		findpos.resize(m);
		int prev = -1;
		for(i=0;i<m;i++)
		{
			int nm = (int)t[i] - (int)'a';
			findpos[i] = find_next(nm,prev);
			prev = findpos[i];
		}
		lli ans = 0;
		lli gl_cnt = 0;
		lli rem = 0;
		prev = -1;
		for(i=0;i<m;i++)
		{
			if(findpos[i]<=prev)
				gl_cnt++;
			rem = findpos[i];
			prev = findpos[i];
		}
		ans = gl_cnt*n + rem + 1;
		cout<<ans<<endl;
	}
	else
		cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 1488
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#define PB push_back
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=55;
int n;
namespace Gr {
	vector<int> G[N];
	queue<int> que;
	int du[N];
	void init() { for(int i=1;i<=n;++i) G[i].clear(),du[i]=0; }
	void ad(int x,int y) {
//		cout<<x<<' '<<y<<endl;
		G[x].PB(y);
		du[y]++;
	}
	bool sol() {
		int cnt=0;
		for(int i=1;i<=n;++i) if(!du[i]) que.push(i);
		while(!que.empty()) {
			cnt++; int u=que.front(); que.pop();
			for(int i=0;i<G[u].size();++i) {
				int v=G[u][i];
				if(!(--du[v])) que.push(v);
			}
		}
		return cnt==n;
	}
}
vector<int> G[2][N];
int fa[2][N];
int mp[2][N][N];
int flg;
int dfs2(int u) {
	int tot=1;
	for(int v=1;v<=n;++v)
		if(fa[0][v]==u&&fa[1][v]==u)
			tot+=dfs2(v);
	return tot;
}
void dfs(int p,int u,int last) {
	fa[p][u]=last;
	for(int i=0;i<G[p][u].size();++i)
		if(G[p][u][i]!=last) dfs(p,G[p][u][i],u);
}
int vis[N],tot_siz;
void check(int u) {
	if(vis[u]) return; tot_siz++,vis[u]=1;
	for(int i=0;i<G[0][u].size();++i) check(G[0][u][i]);
}
int sol(int rt) {
//	cout<<"SOL:"<<rt<<endl;
	for(int d=0;d<2;++d)
		for(int u=1;u<=n;++u) {
			G[d][u].clear();
			for(int v=1;v<=n;++v) if(mp[d][u][v])
				G[d][u].PB(v);
		}
	{
		tot_siz=0;
		for(int i=1;i<=n;++i) vis[i]=0;
		check(1);
		if(tot_siz<n) return 0;
	}		
		
	dfs(0,rt,0);
	dfs(1,rt,0);
	Gr::init();
	int cnt=0;
	for(int i=1;i<=n;++i)
		if(fa[0][i]!=fa[1][i]) {
			if(fa[1][fa[1][i]]!=fa[0][fa[1][i]]) Gr::ad(fa[1][i],i);
			if(fa[1][fa[0][i]]!=fa[0][fa[0][i]]) Gr::ad(i,fa[0][i]);
		}
		else cnt++;
	if(dfs2(rt)!=cnt) return 0;
	
	if(Gr::sol()) {
//		cout<<"OK"<<endl;
		flg=1; int cnt=0;
		for(int i=1;i<=n;++i) cnt+=fa[1][i]==fa[0][i];
		return cnt;
	}
  	return 0;
}

int main() {
	int T; rd(T);
	while(T--) {
		flg=0;
		rd(n);
		for(int i=1,x,y;i<n;++i) rd(x),rd(y),mp[0][x][y]=mp[0][y][x]=1;
		for(int i=1,x,y;i<n;++i) rd(x),rd(y),mp[1][x][y]=mp[1][y][x]=1;
		int ans=sol(1);
		for(int u=1;u<=n;++u) {
			int t=0; for(int v=1;v<=n;++v) t+=mp[0][u][v];
			if(t>1) continue;
			for(int v=1;v<=n;++v) if(mp[0][u][v])
				for(int w=1;w<=n;++w) if(!mp[0][u][w]) {
					mp[0][u][v]=mp[0][v][u]=0;
					mp[0][u][w]=mp[0][w][u]=1;
					ans=max(ans,sol(u)-1);
					mp[0][u][v]=mp[0][v][u]=1;
					mp[0][u][w]=mp[0][w][u]=0;
				}
		}
		if(!flg) printf("-1\n");
		else printf("%d\n",n-ans);
		for(int d=0;d<2;++d)
			for(int i=1;i<=n;++i)
				for(int j=1;j<=n;++j)
					mp[d][i][j]=0;
	}
	return 0;
}

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

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int h[n];
    rep(i, n){
        cin >> h[i];
    }
    h[0]--;
    for (int i = 1; i < n - 1; i++){
        if(h[i-1] < h[i]){
            h[i]--;
        }
    }
    rep(i, n-1){
        if(h[i] > h[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

signed main(){
  string s; cin >> s;
  lint N = s.size();
  lint ans = 0;
  string t;
  for(lint bit = 0; bit < (1 << (N - 1)); bit++){
    t = s[0];
    for(lint j = 0; j < N - 1; j++){
      if(bit & (1 << j)){
        ans += stoll(t);
        t = s[j + 1];
      }
      else t += s[j + 1];
    }
    ans += stoll(t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define lson root<<1
#define rson root<<1|1
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define MAXN 100100
using namespace std;
int n;
int cnt[3];
int main() {
    scanf("%d",&n);
    Mem(cnt,0);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        if(x%4==0) cnt[2]++;
        else if(x%2==0) cnt[1]++;
        else cnt[0]++;
    }
    if(cnt[2]>=cnt[0]) puts("Yes");
    else if(cnt[2]==cnt[0]-1&&cnt[1]==0) puts("Yes");
    else puts("No");
    return 0;
}


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

static const int MAX_N = 100;

int main()
{

	int r, c, sum = 0;
	int sumc[MAX_N];
	int ss[MAX_N][MAX_N];

	memset(sumc, 0, sizeof(sumc));

	cin >> r >> c;
	for(int i = 0; i < r; i++) {
		for(int j = 0; j < c; j++) {
			cin >> ss[i][j];
			sum += ss[i][j];
		}
	}

	for(int i = 0; i < r + 1; i++ ) {
		int sumr = 0;
		for(int j = 0; j < c + 1; j++) {
			if(i != r && j != c) {
				sumr += ss[i][j];
				cout << ss[i][j] << " ";
				sumc[j] += ss[i][j];
			}
			else if( i != r && j == c ) {
				cout << sumr << endl;
			}
			else {
				j != c ? cout << sumc[j] << " " : cout << sum << endl;
			}
		}
	}

	return 0;

}

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

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  for(int i=a;i<=b;i++){
    if(i>=a+k && i<=b-k){
      i=b-k;
      continue;
    }
    cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    string s;
    cin>>s;
    int n=SZ(s);
    int ans=INF;
    REPF(x,'a','z'+1) {
        int t=0;
        int M=0;
        s+=x;
        REP(i,n+1) {
            if(s[i]==x) {
                chmax(M,t);
                t=0;
            }
            else {
                t++;
            }
        }
        s=s.substr(0,n);
        chmin(ans,M);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
class UnionFind:
    MAX_N = 0
    PAR  = [] 
    RANK = []

    def __init__(self,n):
        self.MAX_N = n
        self.PAR = [ i for i in range(n)]
        self.RANK= [ 0 ] * n

    def find(self,x):
        if self.PAR[x] == x:
            return x
        else:
            self.PAR[x] = self.find(self.PAR[x])
            return self.PAR[x] 

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.RANK[x] < self.RANK[y]:
            self.PAR[x] = y
        else:
            self.PAR[y] = x
            if self.RANK[x] == self.RANK[y]:
                self.RANK[x] += 1

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

def kruskal(Edge):
    Edge.sort(key=lambda x:x[2])
    data = UnionFind(V)
    res = 0
    for i in range(E):
        u = Edge[i][0]
        v = Edge[i][1]
        d = Edge[i][2]
        if data.same(u,v) == False:
            data.unite(u,v)
            res += d
    return res

V,E = map(int,input().split())
Edge = []
for _ in range(E):
    Edge.append(list(map(int,input().split())))

ans = kruskal(Edge)
print(ans)



Measured memory_bytes: 28200
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int dp[110][100010];

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    dp[0][1] = 1;
    rep(i, k + 1) dp[0][i + 1] += dp[0][i];
    rep(i, n)
    {
        rep(j, k + 1)
        {
            int tmp = max(0LL, j - a[i]);
            dp[i + 1][j + 1] = (dp[i][j + 1] - dp[i][tmp]) % mod;
        }
        rep(j, k + 1)(dp[i + 1][j + 1] += dp[i + 1][j]) %= mod;
    }
    int ans = (dp[n][k + 1] - dp[n][k] + mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define mp(a, b) make_pair(a, b)
#define lowbit(x) ((x) & -(x))
typedef pair<int, int> pii;
typedef long long ll;
const ll mod = 1e9 + 7;
int a[3][3];
bool vis[3][3];
int main()
{
	for(int i = 0; i < 3; ++i)
		for(int j = 0; j < 3; ++j)
			cin >> a[i][j];
	int n, x;
	cin >> n;
	while(n--)
	{
		cin >> x;
		for(int i = 0; i < 3; ++i)
			for(int j = 0; j < 3; ++j) 
				if(a[i][j] == x)
					vis[i][j] = 1;
	}
	for(int i = 0; i < 3; ++i)
		if(vis[i][0] && vis[i][1] && vis[i][2])
		{
			puts("Yes");
			return 0;
		}
	for(int i = 0; i < 3; ++i)
		if(vis[0][i] && vis[1][i] && vis[2][i])
		{
			puts("Yes");
			return 0;
		}
	if((vis[0][0] && vis[1][1] && vis[2][2]) || (vis[0][2] && vis[1][1] && vis[2][0]))
		{
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    P = [int(x)-1 for x in input().strip().split()]
    C = [int(x) for x in input().strip().split()]
    ans = -float('inf')
    f_cnt = [0] * N
    f_score = [0] * N
    for i in range(N):
        if f_cnt[i]:
            continue
        flag = [False] * N
        j = i
        cnt = 0
        score = 0
        while not flag[j]:
            flag[j] = True
            score += C[j]
            cnt += 1
            j = P[j]
        for j in range(N):
            if flag[j]:
                f_cnt[j] = cnt
                f_score[j] = score
    # print(*f_cnt)
    # print(*f_score)

    def f(cur, cnt):
        ret = -float('inf')
        ret_ = 0
        if f_score[cur] >= 0:
            ret_ += f_score[cur] * (cnt // f_cnt[cur] - 1)
            cnt = cnt % f_cnt[cur] + f_cnt[cur]
            ret = ret_
        else:
            cnt = min(cnt, f_cnt[cur])

        while cnt:
            # print('  cur = {}, cnt = {}, ret = {}'.format(cur, cnt, ret_))
            cur = P[cur]
            ret_ += C[cur]
            ret = max(ret, ret_)
            cnt -= 1

        return ret

    for i in range(N):
        # print('i = {}'.format(i))
        ans = max(ans, f(i, K))
    
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 74732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int counter = 0;
		while (scanner.hasNext()) {

			counter = scanner.nextInt();
			if (counter == 0) {
				break;
			}

			int point = 0;

			for (int c = 2; c < counter; c++) {

				int b = 0;
				for (int x = 1; x <= c; x++) {
					b = b + x;
				}
				if (b > counter) {
					break;
				}

				if ((counter - b) % c == 0) {
					point = point + 1;
				}
			}

			System.out.println(point);
		}

		scanner.close();
	}
}



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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      int right = lower_bound(L.begin(), L.end(), L[i]+L[j]) - L.begin();
      //L[i]+L[j]以上の最初の要素になる
      int left = i + 1;
      //range = [l, r)
      ans += right - left;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

struct Edge {
  int to, len;
};
vector<Edge> edge[2505];
vector<int> e[2505];

int n, m, p, cnt[2505];
long long dis[2505];
queue<int> q;
bool mark[2505], inq[2505];

int main(void) {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= m; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    edge[a].push_back((Edge){b, c - p});
    e[b].push_back(a);
  }
  q.push(n);
  mark[n] = true;
  while (!q.empty()) {
    int h = q.front();
    q.pop();
    for (vector<int>::iterator i = e[h].begin();
         i != e[h].end(); ++i) {
      const int y = *i;
      if (mark[y])
        continue;
      mark[y] = true;
      q.push(y);
    }
  }
  q.push(1);
  inq[1] = true;
  memset(dis, 0xc1, sizeof dis);
  dis[1] = 0;
  while (!q.empty()) {
    int h = q.front();
    if (++cnt[h] == n) {
      printf("-1\n");
      return 0;
    }
    inq[h] = false;
    q.pop();
    for (vector<Edge>::iterator i = edge[h].begin();
         i != edge[h].end(); ++i) {
      const int y = i->to;
      if (!mark[y]) continue;
      if (dis[h] + i->len > dis[y]) {
        dis[y] = dis[h] + i->len;
        if (!inq[y]) {
          q.push(y);
          inq[y] = 1;
        }
      }
    }
  }
  printf("%lld\n", max(0LL, dis[n]));
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   int n,m;
   cin>>n>>m;
   for(int i=1;i<=m+2;i++)
   {
      cout<<"#";
   }
   cout<<endl;
   while(n--)
   {
    cout<<"#";
    string str;
    cin>>str;
    cout<<str;
    cout<<"#"<<endl;
   }
   for(int i=1;i<=m+2;i++)
   {
      cout<<"#";
   }


    return 0;
}








Measured memory_bytes: 3656
s = int(input())
left = s // 100
right = s % 100
left_is_MM = (1 <= left <= 12)
right_is_MM = (1 <= right <= 12)
if(left_is_MM) and (right_is_MM):
    print('AMBIGUOUS')
elif(left_is_MM):
    print('MMYY')
elif(right_is_MM):
    print('YYMM')
else:
    print('NA')


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream&
operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream&
operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream&
operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

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

    ll N, M; cin >> N >> M;

    ll ans = 0;
    if(N > 2 and M > 2) ans += (N - 2) * (M - 2);
    if(N == 1 and M > 2) ans += M - 2;
    if(M == 1 and N > 2) ans += N - 2;
    ans += N == 1 and M == 1;
    cout << ans << endl;
    return 0;
}


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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for(int i = s; i < (e); ++i)
#define FASTIO                                                                                     \
	ios_base::sync_with_stdio(false);                                                              \
	cin.tie(NULL);
#define FILEIO                                                                                     \
	freopen("./input.txt", "r", stdin);                                                            \
	freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                                                  \
	for(auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second;  \
		debug("%s : %lld ms\n ",                                                                   \
			  d,                                                                                   \
			  chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() -   \
														  blockTime.first)                         \
				  .count()),                                                                       \
			 blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T& x) {
	return x > 0 ? x : -x;
}
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }
ll ceil2(ll a, ll b) { return (a + b - 1) / b; }

int main() {
	FASTIO
#ifdef LOCAL
	FILEIO
#endif
	ll n, m;
	cin >> n >> m;
	if(n == 1 && m == 1) { cout << 1 << endl; }
	else if(n == 1 || m == 1) {
		cout << n * m - 2 << endl;
	}
	else {
		cout << (n - 2) * (m - 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define re return

template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcount __builtin_popcount
#define mp make_pair
#define eb emplace_back
#define emp emplace
#define ss second
#define ff first
#define endl "\n"
#define PI 3.14159265359
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)

void reads(string& x){
    char kk[N];
    scanf("%s",kk);
    x = kk;
}
int n, d, val, k;
int ans;
int v[N];

void solve(){
    scanf("%d %d", &n, &k);
    forn(i,0,k){
        scanf("%d", &d);
        forn(j,0,d){
            scanf("%d",&val);
            v[val]++;
        }
    }
    forn(i,1,n+1)ans+=(v[i]==0);
    printf("%d\n",ans);
}
int main(){_
    int t=1;// scanf("%d",&t);
    while(t--){
        solve();
    }
}

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

#define pii pair <int,int>
#define F first
#define S second
#define mp make_pair

using namespace std;

const int N = 1e6 + 123;

int n;
int id, fin, cnt;
pii p[N];

bool cmp (pii a, pii b) {
    return (a.F - a.S) < (b.F - b.S);
}

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        string s;
        cin >> s;
        int bal = 0;
        for (int j = 0;j < (int)s.size ();j ++) {
            bal += (s[j] == ')' ? -1 : 1);
            if (bal < 0) {
                bal = 0;
                p[i].F ++;
            }
        }
        bal = 0;
        for (int j = (int)s.size () - 1;j >= 0;j --) {
            bal += (s[j] == ')' ? -1 : 1);
            if (bal > 0) {
                bal = 0;
                p[i].S ++;
            }
        }
        if (p[i].F + p[i].S == 0)cnt ++;
    }
    if (cnt == n) {
        cout << "Yes";
        return 0;
    }
    int cur = 0;
    for (int i = 1;i <= n;i ++) {
        if (!p[i].F && p[i].S) {
            cur += p[i].S;
            p[i].S = 0;
        }
    }
    sort (p + 1, p + n + 1, &cmp);
    if (!cur) {
        cout << "No";
        return 0;
    }
    for (int i = 1;i <= n;i ++) {
        if (p[i].F && !p[i].S) {
            fin += p[i].F;
            p[i].F = 0;
        }
        if (cur - p[i].F < 0) {
            cout << "No";
            return 0;
        }
        cur -= p[i].F;
        cur += p[i].S;
    }
    if (!fin) {
        cout << "No";
        return 0;
    }
    cout << (cur == fin ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 11288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var hs = Console.ReadLine().Split(' ').Select(item=>long.Parse(item)).ToArray();

        int maxCount = 0;
        long prev = hs[0];
        int current = 0;
        for (int i = 1; i < n; i++)
        {
            var c = hs[i];
            if (prev >= c)
            {
                current++;
                maxCount = Math.Max(current, maxCount);
            }
            else
            {
                current = 0;
            }
            prev = c;
        }
        Console.WriteLine(maxCount.ToString());
    }
}


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

using namespace std;
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 INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}
int main(){
	int n,k;
	cin >>n>>k;
	int bef=n;
	int ans=0;
	while(bef!=0){
		bef/=k;
		ans++;
	}

	
	cout<<ans<<endl;
}

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  string s,t;
  cin>>s>>t;
  Int n=s.size(),m=t.size();
  Int ans=n;
  for(Int i=0;i+m<=n;i++){
    Int res=0;
    for(Int j=0;j<m;j++) res+=s[i+j]!=t[j];
    chmin(ans,res);
  }
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3604
use proconio::{input, fastout};
use proconio::marker::{Chars, Isize1};
use std::collections::VecDeque;
use num::abs;

fn bfs(h: isize, w: isize, field: Vec<Vec<char>>, si: isize, sj: isize, ti: isize, tj: isize) -> isize {
    let mut q = VecDeque::<(isize, isize, isize)>::new();
    q.push_back((0, si, sj));
    let mut visited = vec![vec![false; w as usize]; h as usize];
    let mut queued = vec![vec![false; w as usize]; h as usize];
    queued[si as usize][sj as usize] = true;

    while !q.is_empty() {
        let (cost, i, j) = q.pop_front().unwrap();
        if i == ti && j == tj { return cost; };
        if visited[i as usize][j as usize] { continue; };
        visited[i as usize][j as usize] = true;
        for ni in i as isize - 2..=i + 2 {
            if ni < 0 || h <= ni { continue; }
            for nj in j as isize - 2..=j + 2 {
                if nj < 0 || w <= nj || field[ni as usize][nj as usize] == '#' || queued[ni as usize][nj as usize] { continue; }
                match abs(ni - i) + abs(nj - j) {
                    0 => (),
                    1 => {
                        q.push_front((cost, ni, nj));
                        queued[ni as usize][nj as usize] = true;
                    }
                    _ => q.push_back((cost + 1, ni, nj)),
                }
            }
        }
    }

    -1
}

#[fastout]
fn main() {
    input! {
        h: isize,
        w: isize,
        ch: Isize1,
        cw: Isize1,
        dh: Isize1,
        dw: Isize1,
        field: [Chars; h],
    }
    let ans = bfs(h, w, field, ch, cw, dh, dw);
    println!("{}", ans);
}


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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,k,t,ans;
    cin >> n >> k >> t;
    ans = ((n+k-1)/k)*t;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  char a,b;
  cin >> a >> b;
  
  if(a>b) cout << ">" << endl;
  else if(a < b) cout << "<" << endl;
  else cout << "=" << endl;

 return 0;
}

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

public class Main {
    static int [] a;
    static int[][] dp;
    static int n, w;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        n = sc.nextInt(); int z = sc.nextInt(); w = sc.nextInt();
        a = new int[n + 1];
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        dp = new int[n + 1][2];
        for (int i = 0; i <= n; i++) Arrays.fill(dp[i], -1);
        out.println(go(0, 1));
        out.close();
    }

    static int go(int cur, int turn) {
        if (dp[cur][turn] != -1) return dp[cur][turn];
        // X's turn
        if (turn == 1) {
            if (cur != 0) dp[cur][turn] = Math.abs(a[cur] - a[n]); else dp[cur][turn] = Math.abs(w - a[n]);
            for (int i = cur + 1; i <= n - 1; i++) {
                dp[cur][turn] = Math.max(dp[cur][turn], go(i, 0));
            }
        } else {
            dp[cur][turn] = Math.abs(a[cur] - a[n]);
            for (int i = cur + 1; i <= n - 1; i++) {
                dp[cur][turn] = Math.min(dp[cur][turn], go(i, 1));
            }
        }
        return dp[cur][turn];
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n][m], b[m], c[n] = {};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            c[i] += a[i][j] * b[j];
        }
        cout << c[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;

ll a[maxn];

void solve() {
	ll n,cur=0,fee=1000; cin >> n;
	vector<ll> up, down, res;
	rep(i,0,n) cin >> a[i];
	if (a[0] < a[1]) down.push_back(0);
	rep(i,1,n-1) {
		if (a[i] >= a[i-1] && a[i] >= a[i+1]) up.push_back(i);
		else if (a[i] <= a[i-1] && a[i] <= a[i+1]) down.push_back(i);
	}
	if (a[n-1] > a[n-2]) up.push_back(n-1);
	// for(auto c:up) cout << c << ' ';
	// 	cout << '\n';
	// for(auto c:down) cout << c << ' ';
	// 	cout << '\n';
	ll p1=0,p2=0,l1=up.size(),l2=down.size();
	res.push_back(1000);
	rep(i,0,n) {
		if (p1 < l1 && up[p1] == i) {
			fee += cur * a[i];
			cur = 0;
			p1++;
//			cout << cur << "---" << fee << '\n';
			res.push_back(fee);
			continue;
		}
		if (p2 < l2 && down[p2] == i) {
			cur += fee/a[i];
			fee -= fee/a[i]*a[i];
			p2++;
			continue;
		}
	}
	sort(res.begin(), res.end(), greater<ll>());
	cout << res[0] << '\n';
}

int main(int argc, char * argv[]) 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

	//int t; cin >> t; while(t--)
	solve();

    return 0;
}

Measured memory_bytes: 3660
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int ans = 50, n = sc.nextInt();
        for(int i = 0; i < n; i++){
            int x = sc.nextInt();
            int tmp = 0;
            while(x % 2 == 0){
                tmp++;
                x /= 2;
            }
            ans = Math.min(ans, tmp);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion

N, Q = map(int, input().split())

v = [[] for i in range(N)]
score = [0]*N

def dfs(cur,par):
  for chi in v[cur]:
    if chi == par:
      continue
    score[chi] += score[cur]
    dfs(chi, cur)
      
for i in range(N-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  v[a].append(b)
  v[b].append(a)

for j in range(Q):
  p, x = map(int, input().split())
  score[p-1] += x

dfs(0,-1)
score_int=[str(a) for a in score]
output= ' '.join(score_int)
print(output)
  

Measured memory_bytes: 233776
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 
int main() {
  int N,ma=0,ke=0;
  cin >> N;
  int A[N+10],B[N+10];
  for(int i=0; i<N; i++){
    cin >> A[i] >> B[i];
    if(ma<A[i]){
      ma=A[i];
      ke=B[i];
    }
  }
  cout << ma+ke << endl;
  }

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

const int mod = 1000003;
const int FacN = mod;//使わないなら0

constexpr int power(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)res *= a;
        a *= a;
        res %= mod;
        a %= mod;
        b /= 2;
    }
    return res;
}

constexpr int inv(int x) {
    return power(x, mod - 2);
}

const struct Fac {
    int val[FacN];

    constexpr Fac() : val() {
        if (FacN == 0)return;
        val[0] = 1;
        for (int i = 1; i < FacN; ++i) val[i] = val[i - 1] * i % mod;
    }

    const int &operator[](size_t i) const {
        return val[i];
    }
} fac;

const struct FacInv {
    int val[FacN];

    constexpr FacInv() : val() {
        if (FacN == 0)return;
        val[FacN - 1] = 1;
        for (int i = 1; i < FacN; ++i)val[FacN - 1] = val[FacN - 1] * i % mod;
        val[FacN - 1] = inv(val[FacN - 1]);
        for (int i = FacN - 1; i >= 1; --i)val[i - 1] = val[i] * i % mod;
    }

    const int &operator[](size_t i) const {
        return val[i];
    }
} fac_inv;

int Perm(int n, int r) {
    if (n < r) return 0;
    return fac[n] * fac_inv[n - r] % mod;
}

int Comb(int n, int r) {
    return Perm(n, r) * fac_inv[r] % mod;
}
//mod,Factorial書き換え
//要検証

signed main() {
    int Q;
    cin >> Q;
    rep(i, Q) {
        int x, d, n;
        cin >> x >> d >> n;
        if (d == 0) {
            int ans = power(x, n);
            cout << ans << endl;
            continue;
        }
        int a1 = -x * inv(d);
        a1 %= mod;
        a1 = (a1 + mod) % mod;
        int ans1 = Perm(a1, n);
        int ans2 = power(((-d % mod) + mod) % mod, n);
        int ans = ans1 * ans2 % mod;
        ans = (ans + mod) % mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#ifdef LOCAL
    #define _GLIBCXX_DEBUG
    #define dbg(x) cerr << #x << " = " << x << char(10);
#else
    #define dbg(x) ;
    #define cerr if(0) cerr
    // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
    // #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#endif
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mkt make_tuple
using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const ld eps = 1e-8l;
const int INF = 1e9 + 10;
const ll INFL = 9 * 1e18;
const ll MOD = 1e9 + 7;
const ld Pi = acosl(-1.0l);

struct graph
{
    vector<vi> gr;
    vector<tuple<int, int>> ed;
    int n;
    graph(int nx) : n(nx)
    {
        gr.resize(n);
    }
    void addedge(int a, int b)
    {
        gr[a].pb(b);
        gr[b].pb(a);
        ed.pb(make_tuple(a, b));
    }

    int find(int v, int px, int h, int lim)
    {
        int ans = h > lim;
        for(int to: gr[v])
            if(to != px)
                ans += find(to, v, h + 1, lim);
        return ans;
    }

    int findcost(int k)
    {
        int ans = INF;
        forn(i, n)
            ans = min(ans, find(i, -1, 0, k / 2));
        for(auto x: ed)
        {
          	int a, b;
          	tie(a, b) = x;
            ans = min(ans, find(a, b, 0, (k - 1) / 2) + find(b, a, 0, (k - 1) / 2));
        }
         return ans;
    }
};
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(9);
    cout << fixed;
    #ifdef LOCAL
        assert(freopen("in", "r", stdin));
        assert(freopen("out", "w", stdout));
        assert(freopen("err", "w", stderr));
    #endif

    int n, k;
    cin >> n >> k;
    graph g(n);
    forn(i, n - 1)
    {
        int a, b;
        cin >> a >> b; a--; b--;
        g.addedge(a, b);
    }
    cout << g.findcost(k);
}



Measured memory_bytes: 512
h,w = [int(i) for i in input().split(' ')]
a = [list(input()) for i in range(h)]

# 横除外
b = [i for i in a if not i.count('.') == w]
# 縦除外
h2 = len(b)
w2 = len(b[0])
ret = []
for i in range(w2):
    for x in range(h2):
        if b[x][i] == '#':
            ax = [b[xx][i] for xx in range(h2)]
            ret += [ax]
            break
    else:
        continue

for i in range(len(ret[0])):
    print(''.join([ret[x][i] for x in range(len(ret))]))


Measured memory_bytes: 3188
n, k = list(map(int, input().split(' ')))
d = [0 for i in range(k)]
s = [0 for i in range(n)]

for i in range(k):
    d[i] = int(input())
    a = list(map(int,input().split(' ')))
    for x in a:
        s[x - 1] += 1

print(s.count(0))



Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll inf = 1LL<<60;

int main()
{
  vector<ll> ans;

  while(1) {
    int n; cin >> n;
    if (!n) break;
    vector<ll> w(n, 0);
    rep(i, n) cin >> w[i];
    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
    for (int len=2; len<=n; len++) {
      for (int l=0; l+len<=n; l++) {
        int r = l+len;
        if (dp[l+1][r-1] == len-2 && abs(w[l]-w[r-1]) <= 1) {
          dp[l][r] = len;
        }
        for (int m=l; m<=r; m++) {
          dp[l][r] = max(dp[l][r], dp[l][m] + dp[m][r]);
        }
      }
    }
    ans.push_back(dp[0][n]);
  }

  for (auto v:ans) cout << v << endl;

  return 0;
}



Measured memory_bytes: 3600