akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	int n;
	while(~scanf("%d",&n)){
		bool f = false;
		for(int i=0; (1<<i)<=n; i++)if( n&(1<<i) ){
			if( f )putchar(' ');
			printf("%d",1<<i);
			f = true;
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdlib.h>

using namespace std;

long long n, h[100005], dp[100005];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> h[i];
    }
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; i++){
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n];

    return 0;
}


Measured memory_bytes: 1792
import std.stdio; // ??\????????????????????????
import std.string; // chomp????????????????????????(?????????????????????)
import std.conv; // to????????????????????????
import std.array; // split?????????????????????
import std.algorithm; // map?????????????????????

void main() {
    while (true) {
        auto input = readln.split.map!(to!int).array;

        if (input[0] == 0 && input[1] == 0) {
            break;
        }

        input.sort;

        // %( %) ?????????????????????????????\????????¨???????????????????????????????????§?????????????????¨????????????
        writefln("%(%s %)", input);
    }
}

Measured memory_bytes: 2612
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
 */

import java.util.Scanner;

class Card {
	static int[] appears = new int[37];
	String raw;
	int value;
	int appearNum;
	Card(int value, String raw) {
		this.raw = raw;
		this.value = value;
		appearNum = appears[value]++;
	}
}

public class Main {

	int count = 0;

	void swap(Card[] A, int a, int b) {
		Card tmp = A[a];
		A[a] = A[b];
		A[b] = tmp;
		count++;
	}

	void bubbleSort(Card[] A) {
		boolean f = true;
		while (f) {
			f = false;
			for (int i = A.length - 1; i >= 1; i--) {
				if (A[i].value < A[i-1].value) {
					Card tmp = A[i];
					A[i] = A[i-1];
					A[i-1] = tmp;
					f = true;
					count++;
				}
			}
		}
	}

	void selectionSort(Card[] A) {
		for (int i = 0; i < A.length; i++) {
			int minj = i;
			for (int j = i; j < A.length; j++) {
				if (A[j].value < A[minj].value) {
					minj = j;
				}
			}
			if (minj != i) swap(A, i, minj);
		}
	}
	
	boolean isStable(Card[] cards) {
		int prevVal = 0;
		int numCont = 0;
		for (int i = 0; i < cards.length; i++) {
			if (prevVal == cards[i].value) {
				if (numCont == cards[i].appearNum) {
					numCont++;
				} else {
					System.out.println(cards[i].value + " " + numCont);
					return false;
				}
			} else {
				if (cards[i].appearNum != 0) return false;
				prevVal = cards[i].value;
				numCont = 1;
			}
		}
		return true;
	}

	void printCards(Card[] cards) {
		System.out.print(cards[0].raw);
		for (int i = 1; i < cards.length; i++) {
			System.out.print(" " + cards[i].raw);
		}
		System.out.println();
	}

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] ary = new int[37];
		Card[] A = new Card[n];
		Card[] B = new Card[n];
		for (int i = 0; i < A.length; i++) {
			String in = scan.next("[A-Z][1-9]");
			int x = Integer.parseInt(in.substring(1));
			A[i] = B[i] = new Card(x, in);
		}
	
		count = 0;
		bubbleSort(A);
		printCards(A);
		if (isStable(A)) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}
		
		count = 0;
		selectionSort(B);
		printCards(B);
		if (isStable(B)) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}



Measured memory_bytes: 26376
n,k = map(int, input().split())
w = [int(input()) for _ in range(n)]

def check(p):
    c = t = 0
    for wi in w:
        t += wi
        if t > p:
            t = wi
            c += 1
            if c >= k:
                return False
    return True

s = max(w)
l = sum(w)
while s < l:
    m = (s+l)//2
    if check(m):
        l = m
    else:
        s = m = m+1
print(s)

Measured memory_bytes: 11568
import sys
n,m=map(int,input().split())
lst=[]
chukei=[]
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    lst.append(b)
  if b==n:
    chukei.append(a)
X=lst+chukei
if len(set(X))==len(lst)+len(chukei):
  print('IMPOSSIBLE')
else:
  print('POSSIBLE')

 
  


Measured memory_bytes: 24896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, a;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    if(a%2 == 0) {
      if(a%3 != 0) {
        if(a%5 != 0) {
          cout << "DENIED" << endl;
          return 0;
        }
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

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

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int a[3];
     cin >> a[0]>>a[1]>>a[2];
     sort(a,a+3);
     if(a[0]+a[1]==a[2]) cout<<"Yes\n";
     else cout<<"No\n";
    return 0;
}

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

int main(void)
{
	int n, k, sum, ans;
	cin >> n;
	int a[2][n];

	rep(i, 2) rep(j, n) cin >> a[i][j];
	ans = 0;
	rep(i, n)
	{
		k = 0;
		sum = 0;
		rep(j, n)
		{
			sum += a[k][j];
			if (i == j)
			{
				k = 1;
				sum += a[k][j];
			}
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int count;
  for(int i=0;i<4;i++){
    count=0;
    for(int j=0;j<4;j++){
      if(s.at(i) == s.at(j)){
        count++;
      }
    }
    if(count != 2){
      cout << "No" <<endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  vector<char> m(k);
  for(int i=0; i<k+2; i++)
  {
    cout<<"#";
  }
  cout<<endl;
  for(int j=0; j<n; j++)
  {
    cout<<"#";
  for(int i=0; i<k; i++)
  {
    cin>>m.at(i);
    cout<<m.at(i);
  }
    cout<<"#";
    cout<<endl;
  }
    for(int i=0; i<k+2; i++)
  {
    cout<<"#";
  }
  cout<<endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int const maxn=1e5+54;
ll x[100005];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld",&x[i]);
	ll ans=999999999999;
	for (int i=0;i<n-k+1;i++){
		ll temp=0;
		if (x[i]*x[i+k-1]<0) temp=max(-x[i],min(2*-x[i]+x[i+k-1],-x[i]+2*x[i+k-1]));
		else temp=max(abs(x[i+k-1]),abs(x[i]) );
		ans=min(ans,temp);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
	
	int n;
	cin>>n;
	string s;
	cin>>s;
	int len = s.size();
	for(int i=0;i<len;i++){
		int x = s[i] - 'A';
		x += n;
		x%=26;
		s[i] = s1[x];
	}

	cout<<s<<endl;

	return 0;
}

Measured memory_bytes: 3532
#include <iostream>
#include <cstring>
#include <cmath> 
#include <algorithm>

using namespace std;

const int maxn=1e5+10;
int n,k;
int a[maxn],f[maxn];

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	f[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++)
	{
		int ac=1e9;
		for(int j=1;j<=k&&i-j>=1;j++)
		{
			ac=min(ac,f[i-j]+abs(a[i]-a[i-j]));
		}
		f[i]=ac;
	} 
	cout<<f[n]<<endl;
    return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int res;
  if (k <= a) {
    res = k;
  } else if (k <= a + b) {
    res = a;
  } else {
    res = a + (k - a - b) * -1;
  }
  cout << res << endl;
  return 0;
}


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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 100
int B[siz];


int main()
{
    int i,j,n,m,c,tem,A,cn=0;
    cin>>n>>m>>c;
    fr(i,m) cin>>B[i];
    while(n--)
    {
        tem=c;
        fr(i,m)
        {
            cin>>A;
            tem+=(A*B[i]);
        }
        if(tem>0) cn++;

    }
    cout<<cn<<"\n";
    return 0;
}




Measured memory_bytes: 3628
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int D; std::cin >> D;
    std::vector<int> c(26), t(D+1);
    std::vector<std::set<int>> days(26);
    for(int i(0); i < 26; ++i){
        days[i].emplace(0);
        days[i].emplace(D+1);
    }
    std::vector<std::vector<int>> s(D+1, std::vector<int>(26));
    for(int i(0); i < 26; ++i) std::cin >> c[i];
    for(int i(1); i <= D; ++i){
        int mx(0), id(-1);
        for(int j(0); j < 26; ++j){
            std::cin >> s[i][j];
            if(chmax(mx, s[i][j])) id = j;
        }
        t[i] = id;
        days[t[i]].emplace(i);
    }

    long long v(0);
    for(int i(1); i <= D; ++i){
        long long dcr(0);
        for(int j(0); j < 26; ++j){
            auto itr(std::upper_bound(std::begin(days[j]), std::end(days[j]), i));
            dcr += c[j] * (i - *(--itr));
        }
        v += s[i][t[i]] - dcr;
    }
    int M(100000);
    srand((unsigned int)time(NULL));
    {
        int d, q;
        for(int qq(0); qq < M; ++qq){
            d = rand() % D + 1;
            q = rand() % 26;

            long long oldv(v);

            auto itr(days[t[d]].find(d));
            long long d1(*(--itr));
            itr = std::upper_bound(std::begin(days[t[d]]), std::end(days[t[d]]), d);
            long long d2((*itr)-1);
            v -= c[t[d]] * ((d1-d)*(d-d2) + d - d1);

            itr = std::lower_bound(std::begin(days[q]), std::end(days[q]), d);
            d1 = *(--itr);
            itr = std::upper_bound(std::begin(days[q]), std::end(days[q]), d);
            d2 = (*itr)-1;
            v += c[q] * ((d1-d)*(d-d2) + d - d1);

            v += s[d][q] - s[d][t[d]];
            if(oldv <= v){
                days[t[d]].erase(d);
                days[q].emplace(d);
                t[d] = q;
            }else{
                v = oldv;
            }
        }
    }
    for(int i(1); i <= D; ++i){
        std::cout << t[i] + 1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 3708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	
	public static void Main(string[] args)
	{
 		var p = Input().ToInt();
 		
 		Array.Sort(p);
 		
 		if(p[0] == 1 && p[1] == 4 && p[2] == 7 && p[3] == 9)
 		{
 			Console.WriteLine("YES");
 		}
 		else
 		{
 			Console.WriteLine("NO");
 		
 		}
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;
//typedef pair<int, int> P;
static const int max_n = 1000001, max_m = 102;
static const int  INF = 1000000000;
int ci;
vector<bool> non_p(102, true);
int x, n, p, t;
int main(){
    cin >> x >> n;
    rep(i, n){
        cin >> p;
        non_p[p] = false;
    }
    t = 102;
    int ans=-1;
    for(int i=0; i<102; ++i){
        if( non_p[i] && t > abs(x-i)){
            t = min(t, abs(x-i));
            ans = i;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<cstdio>
int main()
{
	int n,a,b,c,d;
	scanf("%d",&n);
	a = n / 1000;
	b = (n / 100) % 10;
	c = (n % 100) / 10;
	d = n % 10;
	if((a == b && b == c && c == d)||(a == b && b == c )||(b == c && c == d))
		printf("Yes\n");
		else
			printf("No\n");
			return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main()
{
	int n,m,a,b;
	cin>> n >> m;
	int h[n+1],ans=n;
	bool obs[n+1]={0};
	for ( int i=1 ; i<=n ; i++ )
		cin>> h[i];
	for ( int i=0 ; i<m ; i++ )
	{
		cin>> a >> b;
		if ( h[a]<h[b] )
			obs[a]=1;
		else if ( h[a]>h[b] )
			obs[b]=1;
		else
			obs[a]=obs[b]=1;
	}
	for ( int i=1 ; i<=n ; i++ )
	{
		if ( obs[i] )
			ans--;
	}
	cout<< ans;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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<<30;
const double PI=acos(-1);
//SegmentTree 
template<class T>class SegmentTree{
	vector<T> seg;
	public:
	int size; //size of segmenttree
	T init;
	SegmentTree(int _legth,T _init=0){
		size=1;
		init=_init;
		while(size <=_legth){
			size<<=1;
		}
		seg.assign(size<<1,init);
	} 
	T get(int index){
		return seg[size+index];
	}
	void show(){
		rep(i,size*2){
			clog<<seg[i]<<" ";
		}
	clog<<endl;
	}
	//change value 
	void update(int index, T value){
		seg[size+index]=value;
		int ter=index+size;
		while(ter!=1){
			ter/=2;
			seg[ter]=upquary(ter*2);
		} //show();
	}


	T findquary(int left,int right,int index,int atStart,int atStop){
		if ((left <= atStart) and (atStop <= right)){//対象範囲に完全に囲まれる
			return seg[index];
		}if((atStop <= left) or ( right < atStart)){//対象範囲に全く関わらない
			return init;
		}if (index >= size){//範囲外・子がいない
			return seg[index];
		}
		//対象に一部が含まれる
		T aL=findquary(left, right, index * 2, atStart, atStart + (atStop - atStart) / 2);
		T aR= findquary(left, right, index * 2 +1,  atStart +(atStop - atStart) / 2, atStop);
		return max(aL,aR);
	}
	T upquary(int index){ //q1
		return max(seg[index],seg[index+1]);
	}
	T find(int l, int r){ //q2
		T res = seg[size + l];
		res = findquary(l, r,1,0, size);
		return res;
	}
};
int main(){
	int n;
	string s;
	int ans=0;
	cin >>n>>s;
	vector<SegmentTree<int>> dis('z'-'a'+1,SegmentTree<int>(s.size(),0));
	rep(i,s.size()){
		dis[s[i]-'a'].update(i,1);
		//dis[s[i]-'a'].show();
	}
	int q;
	char c;
	int l,r,id,at;
	cin>>q;
	rep(i,q){
		cin>>id;
		if(id==1){
			cin>>at>>c;
			at--;
			dis[s[at]-'a'].update(at,0);
			dis[c-'a'].update(at,1);
			s[at]=c;
		//	dis[c-'a'].show();

		}else if (id==2){
			//clog<<"2:: "<<endl;
			cin>>l>>r;
			l--;
			r--;
			ans=0;
			rep(j,'z'-'a'+1){
			//	clog << (j + 'a') << " ::";
			//	clog << dis[j].find(l, r) << endl;
				ans+=dis[j].find(l,r);
				
			}
			cout<<ans<<endl;
		}
	}
//	cout<<ans<<endl;
}

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

const int N = 1e5 + 7;

long long f[N], a[N], w[N], l, n, t;


int main() {
	cin >> n >> l >> t;
	long long one = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> w[i];
		if (w[i] == 1) {
			f[i] = (a[i] + t) % l;
			if (l - a[i] <= t) {
				one += 1 + (t - (l - a[i])) / l;
			}
		}
		else {
			f[i] = (((a[i] - t) % l) + l) % l;
			if (t > a[i])
				one -= 1 + (t - (a[i] + 1)) / l;
		}
	}
	sort(f, f + n);
	one = (((one % n) + n) % n);
	for (int i = one; i < n; i++)
		cout << f[i] << endl;
	for (int i = 0; i < one; i++)
		cout << f[i] << endl;
	return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int r,c;
int s[11][11111];
int main(void)
{
  while(1){
    cin >> r >> c;
    if(!r && !c) break;
    for(int i = 0; i < r; i++){
      for(int j = 0; j < c; j++){
	cin >> s[i][j];
      }
    }

    int best = 0;
    for(int bit = 0; bit != 1<<r; bit++){
      int sum = 0;
      for(int i = 0; i < c; i++){
	int count = 0;
	for(int j = 0; j < r; j++){
	  int f = (bit & 1<<j)?1:0;
	  count += (s[j][i]+f)%2;
	}
	sum += max(count, r - count);
      }
      best = max(best, sum);
    }
    cout << best << endl;
  }
}

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

public class Main{
	
  public static void main(String args[]){
    	Scanner in = new Scanner(System.in);
    	int n = in.nextInt();
      	int av = in.nextInt();
      	int a[] = new int[n+1];
      	for(int i =1;i<=n;i++){
        	a[i] = in.nextInt();
        }
    long dp[][] = new long[55][3550];
    	dp[0][0]=1;
      	for(int i = 1;i <= n;i++){
        	for(int j = i-1;j>=0;j--)		
            for(int tar = 0;tar<=2500;tar++){
                      dp[j+1][tar+a[i]]+=dp[j][tar];
              }
        }
      	long ans =0;
    	for(int i=1;i<=n;i++){
        	ans+=dp[i][av*i];
        }
    	System.out.println(ans);
    }
}

Measured memory_bytes: 24532
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 234567;
int A[MAXN];
LL suf[MAXN];
LL dp[MAXN][5];

int cost(int i, int tg) {
    int cost1 = (A[i] % 2 == 0);
    int cost2 = A[i] % 2;
    if (tg == 1 || tg == 3) {
         if (A[i] == 0) return 2;
         else return cost2;
    } else return cost1;
}

int main() {
    int L;
    scanf("%d", &L);
    for (int i = 1; i <= L; i++) {
        scanf("%d", &A[i]);
    }
    for (int i = 1; i <= L; i++) {
        dp[i][0] = dp[i - 1][0] + A[i];
        for (int j = 1; j < 4; j++) {
            dp[i][j] = (LL)1e15;
            for (int k = 0; k <= j; k++) {
                dp[i][j] = min(dp[i][j], dp[i - 1][k] + cost(i, j));
            }
        }
        LL mn = (LL)1e15;
        for (int j = 0; j < 5; j++) mn = min(mn, dp[i - 1][j]);
        dp[i][4] = mn + A[i];
    }
    LL ans = dp[L][0];
    for (int i = 1; i < 5; i++) ans = min(ans, dp[L][i]);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 9216
MOD = 10 ** 9 + 7
N, K = map(int, input().split())

# cnt(n): gcd = n となる数列の個数
cnt = [0] * (K + 1)

# A1,...,ANのすべてがxの倍数である数列の個数 = floor(k/x)^N個
for n in range(1, K + 1):
    cnt[n] = pow(K // n, N, MOD)

res = 0
for k in range(K, 0, -1):
    p = 2
    while p * k <= K:
        cnt[k] -= cnt[p * k]
        cnt[k] %= MOD
        p += 1
    res += cnt[k] * k
    res %= MOD

print(res)


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

int main(void){
    int a, b, result = 0;
    cin >> a >> b;

    for(int i = 0; i < 2; i++){
        if(a > b) {
            result += a;
            a--;
        }else{
            result += b; 
            b--;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(4*a<b)cout<<"No"<<endl;
	else if(2*a>b)cout<<"No"<<endl;
	else if(b%2)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
#include <map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>
 
class DisjointSet {
    public:
    std::vector<int> par;
    DisjointSet() {}
    DisjointSet(int n){
        par.resize(n, 0);
        for(int i = 0; i < n; i++){
            par[i] = i;
        }
    }

    void simplify(int x) {
        std::vector<int> path;
        while (par[x] != x) {
            path.push_back(x);
            x = par[x];
        }
        for (int p : path) {
            par[p] = x;
        }
    }
    
    int find(int x){
        simplify(x);
        return par[x];
    }
    
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x != y) {
            par[y] = x;
        }
    }
};

const int MAX_N = 200050;
const int MAX_K = 100050;

int N, K, L;
int p[MAX_K], q[MAX_K], r[MAX_K], s[MAX_K];

DisjointSet ds1 = DisjointSet(MAX_N);
DisjointSet ds2 = DisjointSet(MAX_N);
 
int main(void){
    std::cin >> N >> K >> L;

    for (int i = 1; i <= K; i++) {
        std::cin >> p[i] >> q[i];
    }
    for (int i = 1; i <= L; i++) {
        std::cin >> r[i] >> s[i];
    }
    
    for(int i = 1; i <= K; i++){
        ds1.unite(p[i], q[i]);
    }
    
    for(int i = 1; i <= L; i++){
        ds2.unite(r[i], s[i]);
    }
    
    std::map<std::pair<int, int>, int> S;
    for(int i = 1; i <= N; i++){
        S[std::pair<int, int>({ds1.find(i), ds2.find(i)})] += 1;
    }
    
    for(int i = 1; i <= N; i++){
        std::cout << S[std::pair<int, int>({ds1.find(i), ds2.find(i)})] << " ";
    }
    std::cout << std::endl;
    
    return 0;
}

Measured memory_bytes: 15104
#include <stdio.h>
int main(void){
    
   int num[3];
   int tmp,i,p,q;
   
   for(i = 0; i < 3; i++){
    scanf("%d",&num[i]);
   }
   for(p = 0; p <3; p++){
       for(q = p + 1;q < 3;q++){
          if(num[p] > num[q]){
				tmp = num[p];
				num[p] = num[q];
				num[q] = tmp;
          }
       }
   }
  		printf("%d %d %d\n",num[0],num[1],num[2]);

    return 0;
}



Measured memory_bytes: 2104
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;


int main() {
	long long  n, m;
	pair<pair<int, int>, int> path[3000];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		long long a, b, c; cin >> a >> b >> c;
		path[i].first = make_pair(a, b);
		path[i].second = c;
	}

	long long maxi[2000];
	for (int i = 0; i < n + 1; i++)maxi[i] = -(1LL << 50);
	maxi[1] = 0;
	long long fmxin = -(1LL << 50); long long ncc = 0;

	for (int t = 0; t < 10 * m; t++) {
		bool f = false;
		for (int i = 0; i < m; i++) {
			if (maxi[path[i].first.first] + path[i].second > maxi[path[i].first.second]) {
				f = true; 
				maxi[path[i].first.second] = maxi[path[i].first.first] + path[i].second;
			}
		}
		if (!f) {
			cout << maxi[n] << endl;;
			return 0;
		}
		if (fmxin == maxi[n]) {
			ncc++;
			if(ncc > n) {
				cout << maxi[n] << endl;;
				return 0;
			}
		}
		else {
			ncc = 0;
		}
		fmxin = maxi[n];
	}
	cout << "inf" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int N; cin >> N;
	vector<bool> v(101);
	int i, j=0;
	for(i = 0; i+j <= 100; i += 4){
		for(j = 0; i+j <= 100; j += 7){
			v[i+j] = true; 
		}
		j = 0;
	} 

	//REPI(itr, v) cerr << itr - v.begin() << ':' << *itr << endl;
	cout << ( v[N] ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
S = rs()[:-1]
while S[:len(S)//2] != S[len(S)//2:]:
    S = S[:-1]
print(len(S))

Measured memory_bytes: 63084
#include<stdio.h>
int main()
{
	int a[100000],b,c,t=0,n,m,sum=0;
	scanf("%d%d", &n,&m);
for(int i=1;i<=n;i++)
{
	scanf("%d", &a[i]);
	sum+=a[i];
}

for(int i=1;i<=n;i++)
{
	if(a[i]*4*m>=sum)
	{
		t++;
		if(t==m)
		break;
	}
}
if(t==m)
printf("Yes");
else
printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 2e5+5;

int n, k, a[MM];
multiset<int> st;

bool go(ll v){
	int cnt = 0;
	for(int i = 0; i < n; i++){
		int kk = (a[i]-1)/v;
		// divide into kk parts
		// print(v, a[i], kk);
		cnt += kk;
	}
	return cnt <= k;
}

int main(){
	scan(n, k);
	for(int i = 0; i < n; i++)
		scan(a[i]);
	int l = 1, m, r = 1e9;
	while(l <= r){
		m = (l+r)/2;
		if(go(m))
			r = m-1;
		else
			l = m+1;
	}
	print(l);
}

Measured memory_bytes: 4360
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <math.h>

typedef unsigned long long int uint64;
typedef long long int          int64;

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

int64 p[10][10];  //N,D


void get_ND (int64 *n, int64 *d)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, d);

  return;
}

int main()
{
  int cnt;
  int i,j,k;
  int64 N,D;
  double ds;
  int64  is;
  int result = 0;

  get_ND(&N, &D);

  for(i=0; i<N; i++) {
    for (j=0; j<D; j++) {
      cnt = scanf("%lld", &p[i][j]);
//      printf("%d %d = %d\n", i,j, p[i][j]); //dbg
    }
  }

  for(i=0; i<N-1; i++) {
    for (j=i+1; j<(N); j++) {
      ds = 0;
      for(k=0; k<D; k++) {
        ds += (double)(((double)p[i][k] - p[j][k]) * ((double)p[i][k] - p[j][k]));
//        printf("ds= %f\n", ds);
      }
      ds = sqrt (ds);
      is = (int64)ds;
//      printf("%f %f\n", ds, is);
      if ((is*is) == (ds*ds)) {
        result++;
      }
    }
  }

  printf("%d", result);
  
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N, K;
    cin >> N >> K;
    VLL A(N);
    rep(i,N){
        cin >> A[i];
    }
    if(K<N){
        ll ans_town=1;
        ans_town=A[ans_town-1];
        rep(i,K-1){
            ans_town=A[ans_town-1];
        }
        cout << ans_town << endl;
        return 0;
    }
    else{
        map<ll, ll> visit_number;
        set<ll> visit;
        visit_number[1]=0;
        visit.insert(1);
        ll count=1;
        ll town=A[0];
        ll roop=0;
        while(1){  
            //cout << "town" << " " << town << endl;
            //cout << "count" << " " << count << endl;
            if(visit.find(town)!=visit.end()){
                roop=count-visit_number[town];
                break;
            }
            visit_number[town]=count;
            visit.insert(town);
            town=A[town-1];
            count++;
        }
        ll ans=town;
        rep(i,(K-visit_number[town])%roop){
            ans=A[ans-1];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 22060
#include<bits/stdc++.h>
#define N 105
using namespace std;
short line[N][N],li[N][N],ans[N][N][N][N],n,m,op,sx,sy;
char s[N][N];
int main(){
    cin>>n>>m;
    for (short i=1;i<=n;i++) scanf("%s",s[i]+1);
    for (short i=1;i<=n;i++) for (short j=1;j<=m;j++) { line[i][j]=line[i][j-1]+(s[i][j]=='o'); li[i][j]=li[i-1][j]+(s[i][j]=='o'); if (s[i][j]=='E') sx=i,sy=j; }
    for (short i=sx;i;i--) for (short j=sy;j;j--) for (short k=sx;k<=n;k++) for (short p=sy;p<=m;p++) {
        if (1<i && k+1<sx+i) op=max(op,ans[i-1][j][k][p]=max((int)ans[i-1][j][k][p],ans[i][j][k][p]+line[i-1][min((int)p,m-sy+j)]-line[i-1][max(j-1,p-sy)]));
        if (k<n && sx+k<n+i) op=max(op,ans[i][j][k+1][p]=max((int)ans[i][j][k+1][p],ans[i][j][k][p]+line[k+1][min((int)p,m-sy+j)]-line[k+1][max(j-1,p-sy)]));
        if (1<j && p+1<sy+j) op=max(op,ans[i][j-1][k][p]=max((int)ans[i][j-1][k][p],ans[i][j][k][p]+li[min((int)k,n-sx+i)][j-1]-li[max(i-1,k-sx)][j-1]));
        if (p<m && sy+p<m+j) op=max(op,ans[i][j][k][p+1]=max((int)ans[i][j][k][p+1],ans[i][j][k][p]+li[min((int)k,n-sx+i)][p+1]-li[max(i-1,k-sx)][p+1]));
    }
    cout<<op;
}

Measured memory_bytes: 227584
#include<iostream>
#include<unordered_map>
#include<string>
using namespace std;

int main(void){

string str;
unordered_map<char,string>hs;
unordered_map<string,string>hs2;
	hs[' ']="101";
	hs['\'']="000000";
	hs[',']="000011";
	hs['-']="10010001";
	hs['.']="010001";
	hs['?']="000001";
	hs['A']="100101";
	hs['B']="10011010";
	hs['C']="0101";
	hs['D']="0001";
	hs['E']="110";
	hs['F']="01001";
	hs['G']="10011011";
	hs['H']="010000";
	hs['I']="0111";
	hs['J']="10011000";
	hs['K']="0110";
	hs['L']="00100";
	hs['M']="10011001";
	hs['N']="10011110";
	hs['O']="00101";
	hs['P']="111";
	hs['Q']="10011111";
	hs['R']="1000";
	hs['S']="00110";
	hs['T']="00111";
	hs['U']="10011100";
	hs['V']="10011101";
	hs['W']="000010";
	hs['X']="10010010";
	hs['Y']="10010011";
	hs['Z']="10010000";
	hs2["00000"]="A";
	hs2["00001"]="B";
	hs2["00010"]="C";
	hs2["00011"]="D";
	hs2["00100"]="E";
	hs2["00101"]="F";
	hs2["00110"]="G";
	hs2["00111"]="H";
	hs2["01000"]="I";
	hs2["01001"]="J";
	hs2["01010"]="K";
	hs2["01011"]="L";
	hs2["01100"]="M";
	hs2["01101"]="N";
	hs2["01110"]="O";
	hs2["01111"]="P";
	hs2["10000"]="Q";
	hs2["10001"]="R";
	hs2["10010"]="S";
	hs2["10011"]="T";
	hs2["10100"]="U";
	hs2["10101"]="V";
	hs2["10110"]="W";
	hs2["10111"]="X";
	hs2["11000"]="Y";
	hs2["11001"]="Z";
	hs2["11010"]=" ";
	hs2["11011"]=".";
	hs2["11100"]=",";
	hs2["11101"]="-";
	hs2["11110"]="\'";
	hs2["11111"]="?";

	while(getline(cin,str)){
		if(str.length()<=0)break;
		string enc,enc2;
		for(int i=0;i<str.length();i++){
		enc+=hs[str[i]];
		}
		int enclen=enc.length()%5;
		if(enclen>0){while(enclen<5){enc+="0";enclen++;}}
		for(int j=0;j<enc.length();j+=5)enc2+=hs2[enc.substr(j,5)];
	cout<<enc2<<endl;
	}

return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,A,B;
  cin >>K>>A>>B;
  int count=0;
 
 for (int i = 0; i < 1000; i++) {
 if(A<=K*i && K*i<=B){
   count++;
 }
}
 if(count>0)
 {
   cout<<"OK"<<endl;
 }
  else{
    cout<<"NG"<<endl;
  }
}

Measured memory_bytes: 3640
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

hq = list(LI())
heapq.heapify(hq)

cnt = 0
while 1:
    if hq[1] == hq[0] and hq[0] == hq[2]:
        break
    else:
        i = heapq.heappop(hq)
        j = heapq.heappop(hq)
        if i == j:
            heapq.heappush(hq, i+1)
            heapq.heappush(hq, i+1)
        else:
            heapq.heappush(hq, i+2)
            heapq.heappush(hq, j)
        cnt += 1

print(cnt)


Measured memory_bytes: 9180
#include<stdio.h>

#define MAX 101
#define INF 2001

int minimum(){
  int l,m,c,count,i,j,min,sum,a[MAX][MAX],b[MAX][MAX];
  int k[MAX] = {};
  k[0] = 1;
  
  sum = 0;
  c = 0;
  scanf("%d",&l);

  for(i = 0; i < l; i++){
    for(j = 0; j < l; j++){
      scanf("%d",&a[i][j]);
    }
  }

 
  while(1){
     min = INF;
    for(i = 0; i < l; i++){
      if(k[i] == 1 ){
	for(j = 0; j < l; j++){
	  if(a[i][j] <= min && a[i][j] >= 0 && k[j] == 0){
	    min = a[i][j];
	    m = j;
	  }
	}
      }
    }
    if(min == INF) return sum;
    sum += min;
    k[m] = 2;
    for(i = 0; i < l; i++)
      if(k[i] == 2) k[i] = 1;
  }
  return sum;
}

int main(){

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



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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,z;
string s;

main() {
    cin >> s;
    rep(i,s.size()) if (s[i] == 'A') {a=i; break;}
    repm(i,s.size()) if (s[i] == 'Z') {z=i;break;}
    ct(z-a+1)
}


Measured memory_bytes: 640
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}
 
int main(){
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  int ans = (M1 != M2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
 
long long int check(int arr[], int N){
	if (N%2 and arr[0]!=0) return 0;
	long long int n=1;
	int d = N%2 ? 1 : 0;
	for (int i = d; i<N-1; i+=2){
		//cout << 'D'<< d << "i" <<i << endl;
		//cout << arr[i] << arr[i+1] << endl;
		d = 1;
		if (arr[i]!=i+d or arr[i+1]!=arr[i]){
			return 0;
		}
		n=(n*2)%1000000007;
	}
	return n;
}
int main() {
	int N;
	cin>>N;
	int arr[N];
	for (int i=0; i<N; i++){
		cin>>arr[i];//{02244}{11335577}
	}
	sort(arr, arr+N);
 
	cout << check(arr, N) << endl;
}
 


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  int n = s.size();
  int ans = 1252525;
  for(char c='a';c<='z';c++){
    string t = s;
    int tmp = 0;
    while(true){
      if(count(ALL(t),c)==t.size())break;
      string u;
      REP(i,t.size()-1){
        if(t[i]==c || t[i+1]==c)u += c;
        else u += "_";
      }
      t = u;
      tmp++;
    }
    CHMIN(ans,tmp);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;
int app[26];
int main() {
  string s; cin >> s;
  for ( int i = 0; i < s.length(); i++ ) {
    app[s[i]-'a']++;
  }
  vector<char>ch;

  for ( int i = 0; i < 26; i++ ) {
    if ( app[i] > 0 )ch.push_back(i+'a');
  }

  int ans  = 10000;

  for ( int i = 0; i < ch.size(); i++ ) {
    string tmp = s;
    char c = ch[i];
    int cnt = 0;
    while(1) {
      bool f = true;
      for ( int i = 0; i < tmp.size(); i++ ) {
	if ( c != tmp[i] )  f = false;	  
      }

      if (f) {
	ans = min(ans,cnt);
	break;	
      }

      cnt++;
      for ( int i = 0; i < tmp.size()-1; i++ ) {
	if ( tmp[i+1] == c ) tmp[i] = c;
      }
      tmp.pop_back();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let (n, mut m) = get!(usize, u64);
    let mut ab = get!(u64, u64; n);
    
    ab.sort_by(|&(a1,_b1), &(a2,_b2)| a1.cmp(&a2));
    let mut sum = 0;
    for (a, b) in ab {
        let num = min(m, b);
        sum += a*num;
        m -= num;
    }
    println!("{}", sum);
}


Measured memory_bytes: 10492
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,q,s[2000],ans=1e15,N;
vector<ll>v,vv;
int main(void){
    cin>>n>>k>>q;
    if(q==1){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            if(s[i]<=s[j]){
                v.push_back(s[j]);
            }
            else {
                N=v.size();
                if(N-k+1>0){
                    sort(v.begin(),v.end());
                    //cout<<N-k<<" "<<endl;
                    for(int ii=0;ii<N-k+1;ii++)vv.push_back(v[ii]);
                }
                v={};
            }
        }
        N=v.size();
            if(N-k+1>0){
                sort(v.begin(),v.end());
                for(int ii=0;ii<N-k+1;ii++)vv.push_back(v[ii]);
            }
            v={};
            if(vv.size()>=q-1){
                sort(vv.begin(),vv.end());
                //cout<<vv[q-2]<<" "<<s[i]<<endl;
                ans=min(ans,vv[q-2]-s[i]);
            }
        vv={};
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
a = [0]+list(map(int,input().split()))
ls = [0]*(N+1)
for i in range(N, 0, -1):
    sm = 0
    for j in range(i, N+1, i):
        sm += ls[j]
    ls[i] = (sm % 2) ^ a[i]
b = [i for i in range(N+1) if ls[i] == 1]
print(len(b))
print(*b)

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

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> vec(n);
  
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  
  for (int i = 0; i < n; i++) {
    cout << vec.at(i) << endl;
  }

}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vector<int> x(m), y(m);
    REP(i, m) cin >> x[i] >> y[i];
    REP(i, m) {
        x[i]--;
        y[i]--;
    }

    map<int, bool> box;
    REP(i, n) box[i] = false;
    box[0] = true;

    map<int, int> cnt;
    REP(i, n) cnt[i]++;

    REP(i, m) {
        cnt[x[i]]--;
        cnt[y[i]]++;
        if(box[x[i]]) {
            box[y[i]] = true;
            if (cnt[x[i]] <= 0)
                box[x[i]] = false;
        }
    }

    int ans = 0;
    REP(i, n)
        if (box[i] == true)
            ans++;

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 10368
X, _ = map(int, input().split())
ps = list(map(int, input().split()))

m = 0
d = X
for i in range(1, 102):
    if i in ps:
        continue

    if abs(X - i) < abs(X - m):
        m = i
        d = abs(X - i)

print(m)

Measured memory_bytes: 9180