akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
int prime_num(long long int num)
{
    int flag=0,m,n;
    n=0;
    for(int i=2; i<num/2; i++)
    {
        if(num%i==0)
        {
            flag=1;
            m=1;
            break;
        }
    }
    if(flag==0)
    {
        return n;
    }
    else
    {
        return m;
    }
}
int main()
{
    long long int num,i;
    int flag=1;
    scanf("%lld",&num);
    if(num==2||num==3)
    {
        printf("%lld",num);
    }
    else if(num>3)
    {
        for(i=num;;i++)
        {
            flag=prime_num(i);
            if(flag==0)
            {
                printf("%lld",i);
                break;
            }
        }
    }
    printf("\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()
{
    int N;
    cin >> N;
    for (int i = 0; i <= N / 4; i++)
    {
        for (int j = 0; j <= N / 7; j++)
        {
            if (i * 4 + j * 7 == N)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pll pair<ll,ll>
#define mp make_pair
#define vpl vector<pll> 
using namespace std;
 
const int mod=1e9+7;
const int maxn=2e5+2;
map<string,int> mp;
void solve() {
    int N;
    cin>>N;
    int A[N];
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A,A+N);
    if(N==1) cout<<0<<"\n";
    else if(N==2) cout<<A[N-1]<<"\n";
    else {
        ll ans=A[N-1];
        int value_ptr=N-2;
        int c=2;
        for(int i=N-3;i>=0;i--) {
            if(c>0) {
                ans+=A[value_ptr];
                c--;
            }
            else {
                value_ptr--;
                ans+=A[value_ptr];
                c=1;
            }
        }
        cout<<ans<<"\n";
    }
}


int main() {
    fast
    int t; 
    t=1;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 4416
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(alpha(s))
}

func alpha(s string) string {
	a := map[byte]int{}
	for i := range s {
		a[s[i]]++
	}
	for i := 97; i <= 122; i++ {
		if a[byte(i)] == 0 {
			return string(i)
		}
	}
	return "None"
}


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

using namespace std;
 
 


//c++ templte for help............................................................................................................................................
typedef long long ll;

//template<typename... T>
//void print1(T... t){
	//((cout<<t<<" "),...);
//}

//template<typename... T>
//void print2(T... t){
		//vector<vector<ll>> ans={t...};
		//for(ll i=0;i<(ll)ans.size();i++){
			//if(i!=0) cout<<"\t\t";
			//else cout<<"\t";
			//for(ll j=0;j<(ll)ans[i].size();j++){
				//cout<<ans[i][j]<<" ";
			//}
			//if(i!=(ll)ans.size()-1)
			//cout<<endl;
		//}
//}	
//#define deb(...) cout<<" [ "#__VA_ARGS__<<" : "; print1(__VA_ARGS__); cout<<"]"<<endl; 
//#define vdeb(...) cout<<" [ "#__VA_ARGS__<<" : "; print2(__VA_ARGS__); cout<<"]"<<endl;





	
 
//for loop
//#define fo(i,n) for(int i=0;i<(ll)n;i++)
//#define Fo(i,k,n) for(int i=k;i<n;i++)
 
 
//to print vector element 
//template<typename T>
//void printV(T vec){
	//fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	//cout<<endl;
	//}
	
 
//#define M int(1e9+7)
//const int INF=1e9+5;
 
//iterate map
//template<typename T>
//void itR(T map){
	 //for(auto itr=map.begin();itr!=map.end();itr++){
				//deb(itr->first,itr->second);
			//}
	//cout<<endl;
//}


 

 
//c++ template for help...........................................................................................................................................

ll solve(){
	int l,r,d;
	cin>>l>>r>>d;
	
	int ans=0;
	for(int i=l;i<=r;i++){
		if(i%d==0) ans++;
	}
	
	return ans;
}


int main() {
	//stringstream ss;
	//ss<<"akhil";
	//cout<<ss.str()<<endl;
	cout<<setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	

	//ll testCase;
	//cin>>testCase;
	//for(ll tt=0;tt<testCase;tt++){
		//solve();
		ll ans=solve();
		cout<<ans<<endl;
	//}
	return 0;
}


Measured memory_bytes: 3604
n=int(input())
p,r=print,range
if n&-n==n:p("No");exit(0)
p("Yes")
if n==3:p(1,2);p(2,3);p(3,4);p(4,5);p(5,6);exit(0)
k=1
while k*2<n:k*=2
for i in r(k-2):p(i+1,i+2)
p(k-1,n+1)
for i in r(k-2):p(n+i+1,n+i+2)
p(n+k,n+1);p(n+k+1,k)
for i in r(n-k):p(n+i+1,n+k+i+1);p(n+k+i,k+i+1)

Measured memory_bytes: 9236
n,m = map(int,input().split())
if n%2 ==1:
    for i in range(1,m+1):
        print(i,n-i)
else:
    left_end = 1+m if m%2 == 1 else m
    left_start = left_end//2
    right_start = left_end+m//2
    for i in range(1,m+1):
        if i%2 == 1:
            print(left_start,left_start+i)
            left_start-=1
        else:
            print(right_start,right_start+i)
            right_start-=1

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;


int main(){
    int n,m,k;
    cin >> n >> m >> k;
    vector<int>d(m);
    map<int,int>mp;
    int v[101][101]={};
    for(int i=0;i<m;i++){
        cin >> d[i];
        d[i]--;
        mp[d[i]] = i;
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<k;j++){
            cin >> v[i][j];
            v[i][j]--;
        }
    }
    int bits = (1<<m)-1;
    vector<bool> flag((1<<m)+1);
    vector<int> dst((1<<m)+1);
    queue<int>q;
    q.push(bits);
    flag[bits]= 1;
    dst[bits]= 0;
    while(!q.empty()){
        auto x = q.front();
        q.pop();
        for(int i=0;i<k;i++){
            int sa = 0;
            for(int j=0;j<m;j++){
                if(x&(1<<j)){
                    if(mp.find(v[d[j]][i])!=mp.end()){
                        int y = mp[v[d[j]][i]];
                        if(!(sa&1<<y))sa += 1<<y;
                    }
                }
            }
            if(!flag[sa]){
                flag[sa]=1;
                dst[sa] = dst[x]+1;
                q.push(sa);
            }
        }
    }
    cout << dst[0] << endl;
    return 0;
}


Measured memory_bytes: 3440
#include<stdio.h>
int main(){
  int h,w,i,j,gx,gy,t,r,x[400],y[400],g[10];
  int X[]={ 0, 0,-1, 1, 0};
  int Y[]={ 0, 1, 0, 0,-1};
  char m[20][20],p;
  while(scanf("%d %d",&h,&w),w||h){
    int c[20][20]={0};
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf(" %c ",&m[i][j]);//printf("%c",m[i][j]);
	if(m[i][j]=='A'){
	  y[0]=i;
	  x[0]=j;
	  t=0;
	  c[i][j]=r=1;
	}
	if(m[i][j]=='B'){
	  gy=i;
	  gx=j;
	}
      }//printf("\n");
    }
    for(t=0;r-t;t++){
      for(i=1;i<5;i++){
	if(0<=x[t]+X[i]&&x[t]+X[i]<w&&
	   0<=y[t]+Y[i]&&y[t]+Y[i]<h){
	  if(m[y[t]+Y[i]][x[t]+X[i]]!='#'&&
	     c[y[t]+Y[i]][x[t]+X[i]]==0){
	    c[y[t]+Y[i]][x[t]+X[i]]=c[y[t]][x[t]]+1;
	    x[r]=x[t]+X[i];
	    y[r]=y[t]+Y[i];
	    r++;
	  }
	}
      }
    }
    /*for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	printf("%4d",c[i][j]);
      }
      printf("\n");
      }*/
    for(i=0;scanf("%c",&p),p-10;i++){//printf("%c",p);
      if(p=='5')g[i]=0;
      else	g[i]=(p-'0')/2;
    }//printf("\n");
    for(j=0;1;j++){
      gy+=Y[g[j%i]];
      gx+=X[g[j%i]];
      if(gx<0 )gx=0;
      if(w==gx)gx--;
      if(gy<0 )gy=0;
      if(h==gy)gy--;
      if(c[gy][gx]<=j+2&&c[gy][gx])break; 
      if(j==400)break;
    }
    if(j-400)printf("%d %d %d\n",j+1,gy,gx);
    else     printf("impossible\n");
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int C[N-1], S[N-1], F[N-1];
  rep(i, N-1) cin >> C[i] >> S[i] >> F[i];
  int ans[N] = {0};
  for(int i = 0; i < N-1; i++){
    int pos = i;
    while(pos != N-1){
      if(ans[i] < S[pos]) ans[i] = S[pos] + C[pos];
      else ans[i] = ((ans[i]+F[pos]-1)/F[pos])*F[pos] + C[pos];
      pos++;
    }
  }
  rep(i, N) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


def main():
    H, W, N = list(map(int, input().split(' ')))
    coord_list = [list(map(int, input().split(' '))) for _ in range(N)]
    # count squares (key: coord of top left cell, value: number of appearance)
    square_count = defaultdict(int)
    for coord in coord_list:
        coord = tuple(coord)
        # black cell is located on the top row
        if coord[0] + 2 <= H and coord[1] + 2 <= W:
            square_count[coord] += 1
        if coord[0] + 2 <= H and 1 <= coord[1] - 1 and coord[1] + 1 <= W:
            square_count[(coord[0], coord[1] - 1)] += 1
        if coord[0] + 2 <= H and 1 <= coord[1] - 2:
            square_count[(coord[0], coord[1] - 2)] += 1
        # black cell is located in the middle row
        if 1 <= coord[0] - 1 and coord[0] + 1 <= H and coord[1] + 2 <= W:
            square_count[(coord[0] - 1, coord[1])] += 1
        if 1 <= coord[0] - 1 and coord[0] + 1 <= H and 1 <= coord[1] - 1 and coord[1] + 1 <= W:
            square_count[(coord[0] - 1, coord[1] - 1)] += 1
        if 1 <= coord[0] - 1 and coord[0] + 1 <= H and 1 <= coord[1] - 2:
            square_count[(coord[0] - 1, coord[1] - 2)] += 1
        # black cell is located on the bottom row
        if 1 <= coord[0] - 2 and coord[1] + 2 <= W:
            square_count[(coord[0] - 2, coord[1])] += 1
        if 1 <= coord[0] - 2 and 1 <= coord[1] - 1 and coord[1] + 1 <= W:
            square_count[(coord[0] - 2, coord[1] - 1)] += 1
        if 1 <= coord[0] - 2 and 1 <= coord[1] - 2:
            square_count[(coord[0] - 2, coord[1] - 2)] += 1
    # remove duplicated counts
    count = defaultdict(int)  # key: number of black cells, value: number of squares
    for v in square_count.values():
        count[v] += 1
    count_white_only = (H - 2) * (W - 2) - sum(count.values())
    count[0] = count_white_only
    # print answer
    for c in range(0, 10):
        print(count[c])


if __name__ == '__main__':
    main()


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

int main(){
    int n,a=0,w=0,t=0,r=0;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s.at(i);
        if(s.at(i)=="AC") a++;
        if(s.at(i)=="WA") w++;
        if(s.at(i)=="TLE") t++;
        else if(s.at(i)=="RE") r++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}

Measured memory_bytes: 6432
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}
 
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  mint ans = f(n);
  ans -= 1;
  ans -= choose(n,a);
  ans -= choose(n,b);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

#pragma warning(disable:4996)

int main()
{
	string a, b;
	cin >> a >> b;
	int cnt = b.size();
	int t = 0;
	if (a == b) {
		cout << "Yes";
		return 0;
	}
		
	while (1)
	{
		t++;
		if (t == cnt)
			break;
		char t = b.back();
		b.pop_back();
		b = t + b;
		if (b == a) {
			cout << "Yes";
			return 0;
		}
			
	}
	
		cout << "No";
	return 0;
	

	
	
}

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

int main()
{	
	int h,w;
	scanf("%d %d", &h, &w);
	int matri[h][w];
	vector<string> respu(0);
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			scanf("%d",&matri[i][j]);
		}
	}

	int cont = 0;
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if(matri[i][j] % 2 != 0)
			{
				if(i == h - 1 && j == w - 1)
				{

				}else if(i == h - 1)
				{
					cont++;
					matri[i][j]--;
					matri[i][j+1] += 1;
					char buff[100];
  					snprintf(buff, sizeof(buff), "%d %d %d %d", i+1,j+1,i+1,j+1+1);
					string r = buff;
					respu.push_back(r);
				}else if(j == w - 1)
				{
					cont++;
					matri[i][j]--; 
					matri[i+1][j] += 1;
					char buff[100];
  					snprintf(buff, sizeof(buff), "%d %d %d %d", i+1,j+1,i+1+1,j+1);
					string r = buff;
					respu.push_back(r);
				}else
				{
					cont++;
					if(matri[i][j+1] % 2 != 0)
					{
						matri[i][j]--;
						matri[i][j+1]++;
						char buff[100];
	  					snprintf(buff, sizeof(buff), "%d %d %d %d", i+1,j+1,i+1,j+1+1);
						string r = buff;
						respu.push_back(r);
					}else if(matri[i+1][j] % 2 != 0)
					{
						matri[i][j]--;
						matri[i+1][j]++;
						char buff[100];
	  					snprintf(buff, sizeof(buff), "%d %d %d %d", i+1,j+1,i+1+1,j+1);
						string r = buff;
						respu.push_back(r);
					}else
					{
						matri[i][j]--;
						matri[i][j+1]++;
						char buff[100];
	  					snprintf(buff, sizeof(buff), "%d %d %d %d", i+1,j+1,i+1,j+1+1);
						string r = buff;
						respu.push_back(r);
					}
				}
			}
		}
	}
	cout<<cont<<endl;
	for(int i = 0 ; i < respu.size(); i++)
	{
		cout<<respu[i]<<endl;
	}

	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> void print(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void print(H head, T ...tail) { cout << head << " "; print(tail...); }

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

	int n; cin >> n;
	vector<int> v(n);
	rep(i, 0, n) cin >> v[i];
	int ans = 0x3f3f3f3f;
	rep(i, -100, 101) {
		int d = 0;
		rep(j, 0, n) d += (v[j] - i) * (v[j] - i);
		ans = min(ans, d);
	}
	print(ans);
}


Measured memory_bytes: 256
n, k, q = map(int, input().split())
a = []
p = [k-q]*n
for _ in range(q):
        a.append(int(input()))
 
for i in range(q):
        p[a[i] - 1] += 1

for el in p:
        print("Yes") if el>0 else print("No")

Measured memory_bytes: 56024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
csf = [list(map(int, readline().split())) for _ in range(n - 1)]
for i, (c, s, _) in enumerate(csf):
    s += c
    for cc, ss, ff in csf[i + 1:]:
        if s < ss:
            s = ss
        elif s % ff != 0:
            s += ff - (s % ff)
        s += cc
    print(s)
print(0)


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

#define ll long long

using namespace std;

const int MAXN = 1010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m, k;
int ans = INF, tot, cnt;

int a[MAXN][MAXN], b[MAXN], c[MAXN];

inline int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while ('0' > ch || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
	while ('0' <= ch && ch <= '9') {s = (s << 3) + (s << 1) + ch - 48; ch = getchar();}
	return s * f;
}

bool check() {
	int f = 0;
	for (int i = 1; i <= m; i++) {
		if (b[i] < k) return 0;
	}
	return 1;
}

int main(){
	int T;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &c[i]);
		for (int j = 1; j <= m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (int i = 1; i < (1 << n); i++) {
//		cout << i << endl;
		int cost = 0, num = i, cc = 0;
		memset(b, 0, sizeof(b));
		while (num) {
			++cc;
			if (num & 1) {
				cost += c[cc];
				for (int j = 1; j <= m; j++) {
					b[j] += a[cc][j];
				}
			}
			num >>= 1;
		}
		if (check() && cost < ans) ans = cost;
	}
	printf("%d\n", ans == INF ? -1 : ans);
	return 0;
}



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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            for (var i = 0; i < s.Length; i++)
            {
                Console.Write(s[i]);
                if (i == 3) Console.Write(" ");
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
K,N = map(int,input().split())
a = list(map(int,input().split()))
b = K - a[N - 1] + a[0]
d = 10**20
for i in range(N):
  if i == 0:
    if b < a[i + 1] - a[i]:
      c = K - (a[i + 1] - a[i])
    else:
      c = K - b
  if i == N - 1:
    if a[i] - a [i - 1] < b:
      c = K - b
    else:
      c = K - (a[i] - a[i - 1])
  else:
    if a[i] - a[i - 1] < a[i + 1] - a[i]:
      c = K - (a[i + 1] - a[i])
    if a[i] - a[i - 1] < a[i + 1] - a[i]:
      c = K - (a[i + 1] - a[i])
  if d > c:
    d = c
print(d)

Measured memory_bytes: 33672
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int dp[4][100003];
int a[100003];
int b[100003];
int c[100003];
int n;
int main(){std::ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++){
	cin>>a[i]>>b[i]>>c[i];
}
dp[1][1]=a[1];
dp[2][1]=b[1];
dp[3][1]=c[1];
for(int i=2;i<=n;i++){
	dp[1][i]=max(dp[2][i-1]+a[i],dp[3][i-1]+a[i]);
	dp[2][i]=max(dp[1][i-1]+b[i],dp[3][i-1]+b[i]);
	dp[3][i]=max(dp[1][i-1]+c[i],dp[2][i-1]+c[i]);
}
cout<<max(max(dp[1][n],dp[2][n]),dp[3][n])<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int h,w; cin>>h>>w;
    vector <int> alp(26); 
    rep(i,h)rep(j,w){
        char a; cin>>a;
        alp[a-'a']++;
    }
    int midy = 114514, midx = 114514;
    if(h%2==1) midy = h/2;
    if(w%2==1) midx = w/2;
    priority_queue <int> pq;
    rep(i, 26) pq.push(alp[i]);
    vector <vector<int>> done(h,vector <int>(w));
    rep(i,h)rep(j,w){
        if(i==midy||j==midx||done[i][j]) continue;
        else {
            int tmp = pq.top();
            pq.pop();
            tmp-=4;
            if(tmp<0) {cout<<"No"<<endl; return 0;}
            done[i][j]=done[h-1-i][j]=done[i][w-1-j]=done[h-1-i][w-1-j] = true;
            if(tmp >0) pq.push(tmp);
        }
    }
    if(midy != 114514){
        rep(i,w){
            if(i == midx||done[midy][i]) continue;
            int tmp = pq.top(); pq.pop();
            tmp -= 2;
            
            if(tmp<0) {cout<<"No"<<endl; return 0;}
            done[midy][i] = done[midy][w-1-i] = true;
            if(tmp>0) pq.push(tmp);
        }
    }
    
    if(midx != 114514){
        rep(i,h){
            if(i == midy||done[i][midx]) continue;
            int tmp = pq.top(); pq.pop();
            tmp -= 2;
            if(tmp <0) {cout<<"No"<<endl; return 0;}
            done[i][midx] = done[h-1-i][midx] = true;
            if(tmp >0) pq.push(tmp);
        }
    }
    if(midx!=114514&&midy!=114514){
        int tmp = pq.top();
        tmp -=1;
        if(tmp!=0 || pq.empty()) {cout<<"No"<<endl; return 0;}
    }
    cout<<"Yes"<<endl;
}


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

#define MOD 1000000007

string S;
long long dp[10001][2][101];

long long solve(int N, int lo, int rem, int K)
{
    if(N == S.size())
        return (rem == 0);
    
    if(dp[N][lo][rem] != -1)
        return dp[N][lo][rem];
    
    int val = S[N]-'0';
    long long ans = 0;
    
    for(int i=0; i<10; i++)
    {
        if(lo == 0 && i > val)
            break;
        
        ans += solve(N+1, (lo | (i < val)), (rem + i) % K, K);
    }
    
    return dp[N][lo][rem] = ans % MOD;
}

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int K;
    cin >> S >> K;
    
    memset(dp, -1, sizeof(dp));
    
    cout << (solve(0, 0, 0, K) + MOD - 1) % MOD << "\n";
    return 0;
}

Measured memory_bytes: 17024
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001

void CountingSort(int *, int *,int);

int n;

int main()
{
  int i,j;
  int *A,*B;

  scanf("%d",&n);
  
  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
  
  for(i = 0; i < n; i++){
    scanf(" %d",&A[i]);
  }

  CountingSort(A,B,10000);

  for(i = 1; i <= n; i++){
    if(i > 1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}

void CountingSort(int A[], int B[],int k)
{
  int i,j,C[k+1];

  for(i = 0; i <= k; i++){
    C[i] = 0;
  }

  for(j = 0; j < n; j++){
    C[A[j]]++;
  }

  for(i = 1; i <= k; i++){
    C[i] = C[i] + C[i-1];
  }

  for(j = n-1; j >= 0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}



Measured memory_bytes: 17396
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

template <class T> using Tree = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool a) {
    return a ? "T" : "F";
}

string to_string(const char* s) {
    return to_string((string) s);
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define X first
#define Y second

using ll = long long;
using ld = long double;

const int N = 1e5 + 10;

int n, m;
int p[N], x[N], y[N];
vector <int> v[N];
int fa[N];

void init() {
    for (int i = 1; i <= n; ++i) fa[i] = i;
}

int find(int x) {
    return fa[x] == x ? x : (fa[x] = find(fa[x]));
}

void mrg(int x, int y) {
    x = find(x), y = find(y);
    if (x != y) {
        fa[x] = y;
    }
}

void run() {
    cin >> n >> m;
    init();
    for (int i = 1; i <= n; ++i) cin >> p[i];
    for (int i = 1; i <= m; ++i) {
        cin >> x[i] >> y[i];
        mrg(x[i], y[i]);
    }
    for (int i = 1; i <= n; ++i) {
        v[find(i)].push_back(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        set <int> st(v[i].begin(), v[i].end());
        for (auto x : v[i]) {
            if (st.count(p[x])) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    run();
    return 0;
}


Measured memory_bytes: 9208
# A - Zero-Sum Ranges
import numpy as np

N = int(input())
A = list(map(int, input().split()))
S = np.zeros(N+1)
ans = 0

for i in range(N):
    S[i+1] = S[i] + A[i]

S.sort()
tmp = 1

for i in range(N):
    if S[i]==S[i+1]:
        tmp += 1
    else:
        ans += tmp * (tmp-1) // 2
        tmp = 1
ans += tmp * (tmp-1) // 2

print(ans)

Measured memory_bytes: 34556
#include <cstdio>
using namespace std;
int main(){

    int a, b, c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a < b && b < c){
    printf("Yes\n");
    }
    else{
    printf("No\n");
    }
    
    return 0;

}



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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){

    long long key, i, h;
	key = getKey(str);
	for(i = 0;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0) return 0;
	}
	return 0;

}

int insert(char str[]){

    long long key, i, h;
	key = getKey(str);
	for(i = 0;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 15456
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	VE b(n); rep(i, n)b[i] = a[i];
	sort(ALL(b));
	int tmp = b[n / 2 - 1]; int tmp2 = b[n / 2];
	rep(i, n) {
		if (a[i] <= tmp) {
			cout << tmp2 << endl;
		}
		else cout << tmp << endl;
	}
	return 0;
}

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

int main()
{
  uint64_t N, T;
  std::cin >> N >> T;
  
  std::vector<int64_t> A(N);
  for (uint64_t n = 0; n < N; ++n) {
    std::cin >> A[n];
  }
  
  int64_t min = 1e+9 + 7;
  std::vector<int64_t> B(N, 0);
  for (uint64_t n = 1; n < N; ++n) {
    min = std::min(A[n - 1], min);
    B[n] = A[n] - min;
  }
  
  int64_t max = 0;
  for (uint64_t n = 1; n < N; ++n) {
    max = std::max(B[n], max);
  }
  
  int64_t sum = 0;
  for (uint64_t n = 1; n < N; ++n) {
    if (B[n] == max) ++sum;
  }
  std::cout << sum << std::endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f, MOD  = 998244353;

long long power(ll a, ll b, ll m){  // Fast power with mod;
    if(!b)  return 1;
    ll t = power(a, b>>1, m)%m;
    return ((t*t)%m * (b&1 ? a : 1)%m)%m;
}

unsigned long long modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 

// int tc;
// int n, s;
// vector<int> vec;
// ll ans = 0;
// void solve(int idx = 0, int target = s)
// {
//     if(target == 0)
//     {
//         ans = (ans%MOD + power(2, (ll) n - (ll) vec.size(),MOD))%MOD;
//         cout<<vec.size()<<endl;
//             for(auto x : vec)
//                 cout<<x<<" ";
//             cout<<endl;
//             return;
//     }
//     if(idx == n)
//     {
//         return ;
//     }
//     if(arr[idx] <= target)
//     {
//         vec.push_back(arr[idx]);
//         solve(idx+1, target - arr[idx]);
//         vec.pop_back();
//         solve(idx+1, target);
//     }
//     else
//         solve(idx+1, target);
// }


ll mem[3005][3005];
ll arr[3005];


int main()
{
    FIO
    ll n, s;
    cin>>n>>s;
    for(int i = 0 ; i<n ; i++)
        cin>>arr[i];
    sort(arr, arr+n);
    if(arr[0] > s)
        return cout<<0, 0;
    for(int i = 0; i <= n ; i++)
        for(int j = 0; j <= s; j++)
            mem[i][j] = 0;

    ll tmp = modInverse(2, MOD);
    mem[0][0] = power(2, n, MOD);
    for(ll i = 0 ; i <= n ; i++)
    {
        for(ll j = 0 ; j <= s; j++)
        {
            mem[i+1][j] += mem[i][j];
            mem[i+1][j] %= MOD;
            if(j + arr[i] <= s)
            {
                mem[i+1][j + arr[i]] += (mem[i][j] * tmp);
                mem[i+1][j+arr[i]] %= MOD;
            }
        }
    }
    cout<<mem[n][s]<<endl;
    return 0;
}

Measured memory_bytes: 74168
#include<cstdio>
#include<iostream>
 
using namespace std;
 
typedef long long LL;
 
const LL mod=1e9+7;
const int N=2000;
int a[N+5];
int n,k;
 
int main()
{
	scanf("%d %d",&n,&k);
	
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	LL ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(a[i]>a[j])
				ans = (ans+k)%mod;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i]>a[j])
				ans = (ans+1ll*(k-1)*k/2%mod)%mod;
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <cstdio>
#include <map>
  
using namespace std; 
  
int main() 
{ 
    int n;

    scanf("%d", &n);
    
    pair<int,int> a[n];

    for(int i = 0; i < n; i++){

    	scanf("%d", &a[i].first);
		a[i].second = i;
    }

    sort(a, a + n);
    
    for(int i = 0; i < n; i++){

      if(i > 0)
          printf(" ");

      printf("%d", 1 + a[i].second);
    }

    return 0; 
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;

LL modpow(LL a, LL b, LL m){
    if(b==0) return 1;
    if(b%2==0){
        LL d = modpow(a, b/2, m);
        return (d*d)%m;
    }
    return (a*modpow(a, b-1, m)) % m;
}    

map<int, int> pfact(int M){
    map<int, int> res;
    for(int i=2; i*i <= M; i++){
        while(M%i == 0){
            M /= i;
            res[i]++;
        }
    }
    if(M > 1) res[M]++;
    return res;
}

LL f[151010];
LL inv_f[151010];

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

    int N, M;
    cin >> N >> M;

    f[0] = 1;
    REP(i, 150000){
        f[i+1] = (f[i]*(i+1))%mod;
    }
    inv_f[150000] = modpow(f[150000], mod-2, mod);
    for(int i=150000; i-1>=0; i--){
        inv_f[i-1] = inv_f[i]*i%mod;
    }

    LL ans = 1;
    map<int, int> fc = pfact(M);

    for(auto &i : fc){
        (ans *= f[N-1+i.second]*inv_f[N-1]%mod*inv_f[i.second]%mod)%=mod;
    }
    cout << ans << endl;        

    return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int max = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(sc.next());
            max = Math.max(max, num);
            min = Math.min(min, num);
        }
        System.out.println(max - min);
    }
}

Measured memory_bytes: 21844
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]

at = AB[-1][0]
bt = AB[-1][1]
if at % bt == 0:
    cnt = 0
elif at > bt:
    cnt = bt - (at % bt)
else:
    cnt = bt - at

res = cnt
for tmp, b in reversed(AB[:-1]):
    a = tmp + res
    if a % b == 0:
        continue
    if a > b:
        res += b - (a % b)
    elif a < b:
        res += b - a
    # res += cnt

print(res)


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

const int mod = 1e9 +7;
string s; 
int dp[103][4][2];
ll n; int k;
int solve(int pos, int cnt, bool f) {
    if(cnt > k) return 0;
    if(dp[pos][cnt][f] != -1)   return dp[pos][cnt][f];
    if(pos == n) {
        if(cnt == k)    return 1;
        else    dp[pos][cnt][f] = 0;
        return 0;
    }

    dp[pos][cnt][f] = 0;
    int lim;
    if(f == 0)  lim = s[pos] - '0';
    else    lim = 9;

    for(int dig = 0; dig <= lim; dig++) {
        int ncnt = cnt + (dig!=0);
        int nf = (f==1 || dig<lim);
        dp[pos][cnt][f] = (dp[pos][cnt][f] + solve(pos+1, ncnt, nf)) % mod;
    }
    return dp[pos][cnt][f];
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>s; n = s.length(); cin>>k;
    memset(dp, -1, sizeof(dp));
    cout<<solve(0, 0, 0);
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
long long dp[2200][2200];
const long long MOD=1000000007LL;
int n,k;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=0;i<=2000;i++){
		dp[i][0]=1LL;
		for(int j=1;j<=i;j++)
		{
			dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%MOD;
		}
	}
	for(int i=1;i<=k;i++){
		cout<<(dp[k-1][i-1]*dp[n-k+1][i])%MOD<<endl;
	}
	return 0;
}


Measured memory_bytes: 33536
extern crate core;

use std::io::{self, Read};
use std::cmp;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split_whitespace()
        .skip(1)
        .map(|x| x.parse::<i64>().unwrap())
        .collect::<Vec<_>>();
    let mut free = 0;
    let mut a = 0;
    let mut b = 0;
    let mut c = 0;
    let mut d = 0;
    let mut e = 0;
    let mut f = 0;
    let mut g = 0;
    let mut h = 0;

    /*
    1-399：a 
    400-799：b
    800-1199：c
    1200-1599：d
    1600-1999：e
    2000-2399：f
    2400-2799：g
    2800-3199：h
    3200- free
     */

    for x in list {
        if x <= 399 {
            a = 1;
        } else if x <= 799 {
            b = 1;
        } else if x <= 1199 {
            c = 1;
        } else if x <= 1599 {
            d = 1;
        } else if x <= 1999 {
            e = 1;
        } else if x <= 2399 {
            f = 1;
        } else if x <= 2799 {
            g = 1;
        } else if x <= 3199 {
            h = 1;
        } else {
            free += 1;
        }
    }
    let count = a + b + c + d + e + f + g + h;
    let min = cmp::max(count, 1);
    let max = count + free;
    format!("{} {}", min, max).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!(super::run($input.to_string()), $output.to_string());
                }
            )*
        }
    }
}

tests! {
    test1: "4
2100 2500 2700 2700" => "2 2",
    test2: "5
1100 1900 2800 3200 3200" => "3 5",
    test3: "20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990" => "1 1",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N;
vector<double> A, B, C;

// 1-indexed BIT (i : [1, len])
template<typename T>
struct BIT
{
    int len;
    vector<T> val;
    BIT(int num) : len(num), val(num + 1) {}
    BIT() : BIT(0) {}
    void reset() { fill(val.begin(), val.end(), 0); }
    void add(int pos, T v) { while (pos > 0 and pos <= len) val[pos] += v, pos += pos & -pos; }
    T sum(int pos) const // (0, pos]
    {
        T res = 0;
        while (pos > 0) res += val[pos], pos -= pos & -pos;
        return res;
    }
};
template<typename T> ostream &operator<<(ostream &os, const BIT<T> &b){ T prv = 0; os << "["; REP(i, b.len) { T nxt = b.sum(i + 1); os << nxt - prv << ","; prv = nxt; } os << "]"; return os; }


BIT<int> bit(40002);
lint count_inversion(const vector<int> &vec)
{
    bit.reset();
    lint ans = 0;
    for (auto v : vec)
    {
        ans += bit.sum(v);
        bit.add(v + 1, 1);
    }
    return ans;
}

double solve(const vector<double> &A, const vector<double> &B, const vector<double> &C)
{
    using p = pair<double, double>;
    vector<p> info(N);
    REP(i, N) info[i] = p((double)A[i] / B[i], (double)C[i] / B[i]);
    sort(info.begin(), info.end());

    double l = -2E8, r = 2E8;
    while (r - l > 1E-10 and (r - l) > (abs(l) + abs(r)) * 1E-10)
    {
        double c = (l + r) / 2;
        vector<pair<double, int>> vec(N);
        REP(i, N) vec[i] = make_pair(info[i].second - info[i].first * c, i + 1);
        sort(vec.begin(), vec.end());
        vector<int> vec2(N);
        REP(i, N) vec2[i] = vec[i].second;
        if (count_inversion(vec2) > N * (N - 1) / 2 / 2) l = c;
        else r = c;
    }
    return l;
}

int main()
{
    cin >> N;
    A.resize(N);
    B.resize(N);
    C.resize(N);
    REP(i, N) cin >> A[i] >> B[i] >> C[i];

    cout << solve(A, B, C) << " " << solve(B, A, C) << endl;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    int amax, amin;
    amax = *max_element(A.begin(), A.end());
    amin = *min_element(A.begin(), A.end());

    //cout << amax << " " << amin << '\n';

    if (amax - amin > 1) cout << "No" << '\n';
    else{
        if (amax == amin){
            if (amax == N-1 or 2 * amax <= N) cout << "Yes" << '\n';
            else cout << "No" << '\n';
        }
        else {
            vector<int> D(amax);
            int alone, not_alone;
            alone = 0; not_alone = 0;
            
            for (int i = 0; i < N; i++){
                if (A[i] == amin) alone += 1;
                else not_alone += 1;
            }

            if (alone < amax and 2 * (amax - alone) <= not_alone) cout << "Yes" << '\n';
            else cout << "No" << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	int times = 1;
	int result;
	if( b != 0 ){
		while(times <= b)	times *= 10;
		result = (a*times + b);
	} else {
		times = 10;
	}
	//printf("time: %d result: %d\n", times, result);
	int guess = sqrt(result);
	if(guess*guess == result){
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine().Split().First());
            var sum = Console.ReadLine().Split().Sum(int.Parse);
            var ans = N - sum;
            Console.WriteLine(ans >= 0 ? ans : -1);
        }
    }
}


Measured memory_bytes: 28944
#include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

int field[10][10];
int H, W, C;


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

int count_field() {
  int c = field[1][1];
  bool visit[10][10];
  fill(&visit[0][0], &visit[9][10], false);
  visit[1][1] = true;
  int cnt = 1;
  queue<P> Q;
  Q.push(P(1, 1));
  while (!Q.empty()) {
    P cur = Q.front();
    int x = cur.first;
    int y = cur.second;
    Q.pop();
    
    for (int i = 0; i < 4; i++) {
      int tx = x + dx[i];
      int ty = y + dy[i];
      // printf("%d, %d = %d\n",tx, ty,  field[ty][tx]);
      if (field[ty][tx] > 0 && !visit[ty][tx] && field[ty][tx] == C) {
        visit[ty][tx] = true;
        cnt++;
        Q.push(P(tx, ty));
      }
    }
  }
  return cnt;
}

int fill_color(int color, vector<P>& filled) {
  queue<P> Q;
  Q.push(P(1, 1));
  bool visit[10][10];
  fill(&visit[0][0], &visit[9][10], false);
  visit[1][1] = true;
  int bc = field[1][1];
  field[1][1] = color;
  filled.push_back(P(1,1));
  while (!Q.empty()) {
    P cur = Q.front();
    int x = cur.first;
    int y = cur.second;
    Q.pop();

    for (int i = 0; i < 4; i++) {
      int tx = x + dx[i];
      int ty = y + dy[i];
      if (field[ty][tx] > 0 && !visit[ty][tx] && field[ty][tx] == bc) {
        visit[ty][tx] = true;
        field[ty][tx] = color;
        Q.push(P(tx, ty));
        filled.push_back(P(tx, ty));
      }
    }
  }
}

void reverse_color(int c, vector<P> & filled) {
  for (int i = 0; i < filled.size(); i++) {
    int x = filled[i].first;
    int y = filled[i].second;
    field[y][x] = c;
  }
}

void print_field() {
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      printf("%d ", field[i][j]);
    }
    printf("\n");
  }
  printf("\n");
}

int _solve(int depth) {
  // print_field();
  if (depth == 4) {
    int c = field[1][1];
    vector<P> filled;
    fill_color(C, filled);
    int res = count_field();
    reverse_color(c, filled);
    return res;
  }
  /*
  if (depth == 5) {
    return count_field();
  }
  */
  int c = field[1][1];
  int mx = 0;
  for (int i = 1; i <= 6; i++) {
    if (c != i) {
      vector<P> prev;
      fill_color(i, prev);
      mx = max(_solve(depth + 1), mx);
      reverse_color(c, prev);
    }
  }
  return mx;
}

void solve() {
  printf("%d\n", _solve(0));
}

void init() {
  for (int i = 0; i <= H + 1; i++) {
    for (int j = 0; j <= W + 1; j++) {
      field[i][j] = 0;
    }
  }
}

int main() {
  while (true) {
    scanf("%d %d %d ", &H, &W, &C);
    init();
    if (H == 0 && W == 0 && C == 0) {
      return 0;
    }
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        scanf("%d ", &field[i][j]);
      }
    }
    solve();
  }
}

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

int main()
{
	int n;
	cin >> n;
	if (n % 7 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	else {
		for (int i = 1; i < 26; i++) {
			n -= 4;
			if (n < 0)break;
			if (n % 7 == 0) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

vector<ll> l, p;

ll func(ll n, ll x) {
    if (n == 0)
        return x;

    if (x <= 1)
        return 0;
    else if (1 < x && x <= l[n-1]+1)
        return func(n-1, x-1);
    else if (x == l[n-1]+2)
        return p[n-1] + 1;
    else if (l[n-1]+2 < x && x <= 2*l[n-1]+2)
        return p[n-1] + func(n-1, x-l[n-1]-2) + 1;
    else 
        return 2*p[n-1] + 1;
}

int main() {
    ll n, x;    cin >> n >> x;
    l.resize(51, 1);
    p.resize(51, 1);
    for (int i = 0; i < 50; i++) {
        l[i+1] = 2*l[i]+3;
        p[i+1] = 2*p[i]+1;
    }

    cout << func(n, x) << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
using namespace std;

int L1_distance(int x1,int y1,int x2,int y2){
    return (x1<x2?x2-x1:x1-x2)+(y1<y2?y2-y1:y1-y2);
}

int main(){
    int n;cin>>n;
    vector<int> t(n+1),x(n+1),y(n+1);
    for(int i=1;i<n+1;i++)cin>>t[i]>>x[i]>>y[i];

    for(int i=0;i<n;i++){
        if( L1_distance(x[i],y[i],x[i+1],y[i+1]) > t[i+1]-t[i]){cout<<"No"<<endl;return 0;}
        if(((t[i+1]-t[i])-L1_distance(x[i],y[i],x[i+1],y[i+1]))%2==1){cout<<"No"<<endl;return 0;}

    }
    cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 1408