akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
class StronglyConnectedComponents{
    private:
        int siz;
        vector<vector<int>> g,rg;
        vector<int> vs,cmp;
        vector<bool> done;
    public:
        StronglyConnectedComponents(int n){
            siz = n;
            g.resize(n);
            rg.resize(n);
            cmp.resize(n);
        }
        void add_edge(int from,int to){
            g[from].push_back(to);
            rg[to].push_back(from);
        }
        void dfs(int v){
            done[v] = true;
            for(int u:g[v]){
                if (!done[u]) dfs(u);
            }
            vs.push_back(v);
        }
        void rdfs(int v,int k){
            done[v] = true;
            cmp[v] = k;
            for(int u:rg[v]){
                if (!done[u]) rdfs(u,k);
            }
        }
        int scc(){
            done.assign(siz,false);
            rep(v,siz) if (!done[v]) dfs(v);
            done.assign(siz,false);
            int k = 0;
            for (int v = siz-1;v >= 0;v--) if (!done[vs[v]]) rdfs(vs[v],k++);
            return k;
        }
        int operator[](int k){
            return cmp[k];
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v,e,s,t;
    cin >> v >> e;
    StronglyConnectedComponents graph(v);
    rep(i,e){
        cin >> s >> t;
        graph.add_edge(s,t);
    }
    int q;
    cin >> q;
    graph.scc();
    rep(i,q){
        cin >> s >> t;
        graph[s] == graph[t] ? PRINT(1) : PRINT(0);
    }
}



Measured memory_bytes: 4520
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int w = scan.nextInt();
        String[] s = new String[h];
        char[][] c = new char[h][w];
        for(int i = 0; i < h; i++){
                s[i] = scan.next();
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                c[i][j] = s[i].charAt(j);
            }
        }
        for(int i = 0; i < h * 2; i++){
            for(int j = 0; j < w; j++){
                System.out.print(c[i / 2][j]);
            }
            System.out.println();
        }
    }
}

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

#define INF (1LL<<50)
#define REP(i,n) for(int i=0;i<(int)n;i++)
typedef long long int ll;
typedef pair<ll,int> P;

ll wf[30][110][110],a[110][110],q[30][100],r[30][100],d;
int n,m,c,s,g,x,y,id,p[30];

int main(){
  while(scanf("%d%d%d%d%d",&n,&m,&c,&s,&g), n){
    REP(i,n)REP(j,n){
      a[i][j] = INF;
      for(int k=0;k<c;k++)wf[k][i][j] = INF;
    }
    
    REP(i,m){
      scanf("%d%d%lld%d",&x,&y,&d,&id);
      x--; y--; id--;
      wf[id][x][y] = min(wf[id][x][y],d);
      wf[id][y][x] = min(wf[id][y][x],d);
    }
    
    REP(l,c)REP(k,n)REP(i,n)REP(j,n){
      wf[l][i][j] = min(wf[l][i][j],wf[l][i][k] + wf[l][k][j]);
    }

    REP(i,c)scanf("%d",&p[i]);
    REP(i,c){
      q[i][0] = 0;
      REP(j,p[i]-1)scanf("%lld",&q[i][j+1]);
      q[i][p[i]] = INF;
      REP(j,p[i])scanf("%lld",&r[i][j]);
    }

    REP(k,c)REP(i,n)REP(j,n){
      if(wf[k][i][j] < INF ){
	ll tmp = 0;
	for(int l=1;l<=p[k];l++){
	  if(wf[k][i][j] <= q[k][l]){
	    tmp += r[k][l-1]*(wf[k][i][j] - q[k][l-1]);
	    break;
	  }else{
	    tmp += r[k][l-1]*(q[k][l] - q[k][l-1]);
	  }
	}
	a[i][j] = min(a[i][j],tmp);
      }
    }

    REP(k,n)REP(i,n)REP(j,n)
      a[i][j] = min(a[i][j],a[i][k] + a[k][j]);

    if(a[s-1][g-1]>=INF)printf("-1\n");
    else printf("%lld\n",a[s-1][g-1]);
  }
}

Measured memory_bytes: 2960
#include<bits/stdc++.h>
using namespace std;
int main() {
	char a[3],b[3];
	scanf("%s\n%s",a,b);
	if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 256
t = [int(input()) for i in range(5)]

min=t[0]
length=len(t)
for i in range(length):
    if min%10>t[i]%10 and t[i]%10!=0:
        min=t[i]
t.remove(min)
t.append(min)
ans=0
for _ in range(length-1):
    if t[_]%10!=0:
        ans+=t[_]+10-t[_]%10
    else:
        ans+=t[_]
print(ans+t[length-1])



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, M, ans;
    cin >> N >> M;
    vector<bitset<40>> A(N+1);
    A.at(0).set();
    REP(int,i,1,N+1){
        int K;
        cin >> K;
        A.at(i).reset();
        REP(int,j,0,K){
            int c;
            cin >> c;
            A.at(i).set(c,1);
        }
        //cout << A.at(i) << endl;
        A.at(0) = A.at(0) & A.at(i);
    }
    ans = 0;
    REP(int,i,1,M+1){
        if ( A.at(0).test(i) ) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,k;
  ll l,r;
  cin>>n>>k>>l>>r;
  vector<ll> a(n);
  int i,j;
  rep(i,n)cin>>a[i];
  int nl=n/2;
  int nr=n-nl;
  vector<vector<ll>> left(nl+1);
  vector<vector<ll>> right(nr+1);
  rep(i,1<<nl)
  {
    int num=0;
    ll val=0;
    rep(j,nl)
    {
      if(i&(1<<j))
      {
        num++;
        val+=a[j];
      }
    }
    left[num].emplace_back(val);
  }
  rep(i,1<<nr)
  {
    int num=0;
    ll val=0;
    rep(j,nr)
    {
      if(i&(1<<j))
      {
        num++;
        val+=a[nl+j];
      }
    }
    right[num].emplace_back(val);
  }
  rep(i,nl+1)sort(all(left[i]));
  rep(i,nr+1)sort(all(right[i]));
  ll ans=0;
  rep(i,nl+1)
  {
    if(i>k||i+nr<k)continue;
    rep(j,left[i].size())
    {
      int indl=lower_bound(all(right[k-i]),l-left[i][j])-right[k-i].begin();
      int indh=upper_bound(all(right[k-i]),r-left[i][j])-right[k-i].begin();
      ans+=(indh-indl);
    }
  }
  cout<<ans<<endl;
}



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

using namespace std;

typedef long long int lli ;

lli i,j,k,l,m,n,t,a,b,c,d,x,y,sum=0,total=0;

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

    //freopen("Input.txt","r",stdin);

    cin>>t;

    lli ar[t]={0},br[t]={0};

    for(i=0 ; i<t ; i++)
    {
        cin>>ar[i];
    }
    if(t>1)
    {
        if(t%2==0)  d=0;
        else    d=1;
        for(i=t-1 ; i>=0 ; i-=2)
        {
            cout<<ar[i]<<" ";
        }
        for(i=d ; i<t ; i+=2)
        {
            cout<<ar[i]<<" ";
        }
    }
    else
    {
        cout<<ar[0]<<" ";
    }
    cout<<endl;

}


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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

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

    int N=n%10;

    if(N==3)cout<<"bon"<<endl;
    else if(N==0||N==1||N==6||N==8)cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  ll N,A;
  cin >> N >> A;
  vector<ll> x(N);
  FOR(i,0,N)cin >> x[i];
  FOR(i,0,N)x[i] -= A;
  ll DP[N+1][10000];
  FOR(i,0,N+1)FOR(j,0,10000)DP[i][j] = 0;
  DP[0][5000] = 1;
  FOR(i,0,N){
    FOR(j,0,10000){
      DP[i+1][j] = DP[i][j];
    }
    vector<int> v;
    FOR(j,0,10000){
      if(DP[i][j])v.push_back(j);
    }
    for(auto p:v){
      DP[i+1][p+x[i]] += DP[i][p];
    }
  }
  cout << DP[N][5000]-1 << endl;
}


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

int gcd(int a, int b)
{
  int m = max(a, b);
  int n = min(a, b);

  while (m != n) {
    int t = n;
    n = m - n;
    m = t;
  }

  return m;
}

long long lcm(int a, int b)
{
  return 1LL * a * b / gcd(a, b);
}


int main()
{
  int n;  // sの長さ
  int m;  // tの長さ
  string s, t;
  int l;  // xの長さ
  int g;  // 最大公約数

  cin >> n >> m;
  cin >> s;
  cin >> t;

  //g = gcd(n, m);
  g = __gcd(n, m);

  //printf("gcd=%d\n", g);

  for (int i = 0; i < g; i++) {
    //printf("%d %d\n", n / g * i, m / g * i);
    //printf("%c %c\n", s[n / g * i], t[m / g * i]);
    if (s[n / g * i] != t[m / g * i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << 1LL * n * m / g << endl;

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N;
vector<long long> a;
vector<int> r;
map<int, int> mp;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i=0; i<N; i++){
		long long v;
		cin >> v;
		a.push_back(v);
		int u = v % 4;
		r.push_back(u);
		if(mp.count(u)==0){
			mp[u] = 1;
		}
		else{
			mp[u]++;
		}
	}

	int ok = 0;
	if(mp.count(0) == 0){
		//余り0がない場合
		if(mp.count(1) != 0 || mp.count(3) != 0){
			ok = 0;
		}
		else{ //余り2のみ。OK
			ok = 1;
		}
	}
	else{
		//余り0がある場合
		if(mp[2] > 0){
			//余り2がある場合、余り2をすべて最後に詰めて、その直前に0、その前は1,3を0で挟めればよい
			if(mp[0] >= mp[1] + mp[3]){
				ok = 1;
			}
			else{
				ok = 0;
			}
		}
		else{
			//余り2がない場合、1,3の間に0で挟めればよい
			if(mp[0] >= mp[1] + mp[3] - 1){
				ok = 1;
			}
			else{
				ok = 0;
			}
		}
	}
	if(ok == 1)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 1908
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		if (b <= a) {
			System.out.println("delicious");
		} else if (b <= a + x) {
			System.out.println("safe");
		} else {
			System.out.println("dangerous");
		}
	}

}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n;
	cin>>k;
	char s[n];
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	for(int i=0;i<n;i++){
		if(i+1==k){
			s[i]=s[i]+32;
			cout<<s[i];
		}
		else{
			cout<<s[i];
		}
	}
} 

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int A = 0; int B = 0;
    scanf("%ld %ld", &A, &B);
    if(B % A == 0){
        printf("%d\n", A + B);
    }else {
        printf("%d\n", B - A);
    }
    return 0;
}

Measured memory_bytes: 128
#入力を受け取る
i = input()

#入力を" "でリスト化
list = i.split()

#整数に変換
#int()関数は、文字列のみ受け取る
x = int(list[0])
a = int(list[1])

#もしXがA未満なら
if x < a:
    print(0)
elif x >= a:
    print(10)

Measured memory_bytes: 2940
def main():
    N = int(input())
    A = list(map(int, input().split()))

    c = 0
    while 1:
        if all(A[i] % 2 == 0 for i in range(N)):
            for j in range(N):
                A[j] /= 2
            c += 1
        else:
            break
    print(c)


if __name__ == "__main__":
    main()

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

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);

const int N = 1e5 + 10;
int dsu[N], A[N], deg[N];
int f(int x){
  return dsu[x] = (dsu[x] == x ? x : f(dsu[x]));
}
int main()
{
  int n, m;
  si(n);si(m);
  priority_queue<II> S;
  LL ans = 0;
  REP(i, n){
    si(A[i]);
    ans += A[i];
    dsu[i] = i;
    S.push(MP(A[i], i));
  }
  REP(i, m){
    int x, y;
    si(x);si(y);
    x = f(x);y = f(y);
    dsu[x] = y;
  }
  REP(i, n)deg[f(i)]++;
  if(n / 2 < n - m - 1){
    puts("Impossible");
    return 0;
  }
  int sum = n;

  while(!S.empty() && (sum + 1) / 2 > n - m - 1){
    auto it = S.top();S.pop();
    int idx = it.S;
    int x = f(idx);
    if(deg[x] == 1 && m < n - 1)continue;
    deg[x]--;sum--;
    ans -= it.F;
  }
  lldout(ans);
	return 0;
}

Measured memory_bytes: 2292
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int H = sc.nextInt();
      int W = sc.nextInt();
      if (H == 0 && W == 0) {
        break;
      } else {
        for (int h = 0; h < H; h++) {
          for (int w = 0; w < W; w++) {
            if (h % 2 == 0) {
              if (w % 2 == 0)
                System.out.print("#");
              else
                System.out.print(".");
            } else {
              if (w % 2 == 0)
                System.out.print(".");
              else
                System.out.print("#");
            }
          }
          System.out.println();
        }
        System.out.println();
      }
    }
    sc.close();
  }
}


Measured memory_bytes: 34732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {
	//static int [] sortedArray;

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		//int[] inputArray = new int[n];
		Element[] inputArray = new Element[n];
		//sortedArray = new int[n];
		String[] tmpArray = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			//inputArray[i] = Integer.parseInt(tmpArray[i]);
			inputArray[i] = new Element(i, Integer.parseInt(tmpArray[i]));
			//sortedArray[i] = inputArray[i];
		}
		//Arrays.sort(inputArray);
		System.out.println( MergeSort(inputArray, 0, n));
		
//		System.out.println(inversion(inputArray));
	}
	
	static int inversion(Element[] array){
		int result = 0;
		for(int i = 0 ; i < array.length ; i++){
			if(i > array[i].id){
				result += i - array[i].id;
			}
		}
		
		return result;
	}
	
	static long Merge (Element[] array, int left, int mid, int right){
		int n1 = mid - left;
		int n2 = right - mid;
		long result = 0;
		Element[] L = new Element[n1 + 1];
		Element[] R = new Element[n2 + 1];
		
		for(int i = 0; i < n1 ; i++){
			L[i] = array[left + i];
		}
		
		for(int i = 0; i < n2 ; i++){
			R[i] = array[mid + i];
		}
		L[n1] = new Element(-1, Integer.MAX_VALUE);
		R[n2] = new Element(-1, Integer.MAX_VALUE);
		int i = 0;
		int j = 0;
		for(int k = left ; k < right ; k++){
			if(L[i].data <= R[j].data){
				array[k] = L[i];
				//System.out.print(L[i].data+" ");
				i++;
				
			}
			else {
				array[k] = R[j];
				if(n1 + j - k + left > 0 ){
					result += n1 + j - (k - left);
					//System.out.println("n1 + j:"+(n1+j)+" k - left= "+(k - left));
					//System.out.println("R["+j+"](" +R[j].data+ ") moves " +(n1 + j - (k - left)) );
					//result ++;
				}
				//System.out.println("R["+j+"]="+R[j].data);
				//System.out.print(R[j].data+" ");
				j++;
				
			}
		}
		//System.out.println();
		return result;
	}
	
	static long MergeSort (Element[] array, int left, int right){
		long result = 0;
		if(left + 1 < right){
			int mid = (left + right)/2;
			result += MergeSort(array, left, mid);
			result += MergeSort(array, mid, right);
			result += Merge(array, left, mid, right);
		}
		
		return result;
	}
	

}


class Element implements Comparable{
	int id;
	int data;
	
	public Element (int id, int data){
		this.id = id;
		this.data = data;
	}

	public int compareTo(Element data) {
		// TODO Auto-generated method stub
		if(this.data < data.data){
			return -1;
		}
		else if(this.data == data.data){
			return 0;
		}
		else {
			return 1;
		}
	}

	public int compareTo(Object arg0) {
		// TODO Auto-generated method stub
		return 0;
	}
}

Measured memory_bytes: 81244
D,G=map(int,input().split())
G//=100

P=[0]*(D+1)
C=[0]*(D+1)

for i in range(1,D+1):
    p,c=map(int,input().split())
    P[i]=p
    C[i]=c//100

Min_Solved=float("inf")

for i in range(2**D):
    Rest=G
    Solved=0

    A=[0]*(D+1)

    x=i
    for j in range(1,D+1):
        A[j]=x%2
        if x%2:
            Rest-=j*P[j]+C[j]
            Solved+=P[j]
        x>>=1

    for k in range(D,0,-1):
        if Rest<=0:
            break

        if A[k]==0:
            if k*P[k]<=Rest:
                Rest-=k*P[k]+C[k]
                Solved+=P[k]
            else:
                z=(Rest+(k-1))//k
                Rest-=k*z
                Solved+=z

    Min_Solved=min(Min_Solved,Solved)
    assert 1

print(Min_Solved)

Measured memory_bytes: 73916
def main():
    n,x,y=map(int,input().split())
    Ans=[0]*n
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i<=x and y<=j:
                d=x-i+j-y+1
            elif i<=x and x<=j<=y:
                d=min(j-i,x-i+1+y-j)
            elif x<=i<=y and j>=y:
                d=min(j-i,i-x+1+j-y)
            elif x<=i<=y and x<=j<=y:
                d=min(j-i,i-x+1+y-j)
            else:
                d=j-i
            #print(i,j,d)
            Ans[d]+=1
    for ans in Ans[1:]:
        print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 45552
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int,int> MP;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    string s; cin>>s; int ans=-1; int a[26]={},n=s.size();
    if(n==26){
        for (int i = 24; i >= 0; i--){
            if(s[i]<s[i+1]){
                char c=s[i+1];
                for (int j = i+2; j < 26; j++){
                    if(s[j]>s[i])cmin(c,s[j]);
                }
                s[i]=c; string ans="";
                for (int j = 0; j <= i; j++)ans.push_back(s[j]);
                END
            }
        }
        END
    }else{
    for (int i = 0; i < n; i++)a[s[i]-'a']++;
    for (int i = 0; i < 26; i++)if(!a[i]){
        s+=i+'a'; cout<<s<<'\n'; return 0;
    }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
using namespace std;

std::vector<std::vector<int> > seg(524287, {100, -1});
std::vector<int> er(524287, 0);
string s;
int k;
void update(int a, int k){
  int n=(seg.size()+1)/2;
  k+=n-1;
  seg[k][0]=a;
  seg[k][1]=k-n+1;
  while(k>0){
    k = (k-1)/2;
    if(seg[k*2+1][0]>seg[k*2+2][0]) seg[k]=seg[k*2+2];
    else seg[k]=seg[k*2+1];
  }
}
void erase(int k, int a){
  int n=(seg.size()+1)/2;
  k+=n-1;
  er[k]+=a;
  while(k>0){
    k=(k-1)/2;
    er[k]+=a;
  }
}

int qer(int k, int x){
  if(k==0 && x>er[0]) return -1;
  int n = (seg.size()+1)/2;
  if(n-1 <= k && k <= seg.size()-1) return k - (n-1);
  if(er[k*2+1]>=x) return qer(k*2+1, x);
  else return qer(k*2+2, x-er[k*2+1]);
}
int qq(int a, int b, int l, int r, int k){
  if(r<=a || b<=l) return 0;
  if(a<=l && r<=b) return er[k];
  return qq(a, b, l, (l+r)/2, k*2+1) + qq(a, b, (l+r)/2,r,k*2+2);
}
std::vector<int> query(int a, int b, int l, int r, int k){
  if(r<=a||b<=l) return std::vector<int> {100, -1};
  if(a<=l && r<=b) return seg[k];
  auto A=query(a, b, l, (l+r)/2, k*2+1);
  auto B=query(a, b, (l+r)/2, r, k*2+2);
  return (A[0]>B[0]?B:A);
}
int main(int argc, char const *argv[]) {
  std::cin >> s >> k;
  string ans = "";
  for(int i=0;i<s.size();i++) update(s[i]-'a',i);
  for(int i=0;i<s.size();i++) erase(i, 1);
  for(int i=0;i<s.size();i++){
    int num = qer(0, k+1);
    if(num==-1) num=s.size()-1;
    std::vector<int>  ch = query(0, num+1, 0, (seg.size()+1)/2, 0);
    ans += ('a'+ch[0]);
    update(100,ch[1]);
    erase(ch[1], -1);
    k -= qq(0, ch[1]+1, 0, (seg.size()+1)/2, 0);
  }
  std::cout << ans << '\n';
  return 0;
}



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

int main(void){
    int N, ans = 0;
    cin >> N;
    int s[N];
    for(int i=0; i<N; i++){
        cin >> s[i];
        ans += s[i];
    }

    if(ans%10==0){
        sort(s, s+N);
        for(int i=0; i<N; i++){
            if(s[i]%10){
                ans -= s[i];
                break;
            }
        }
    }

    if(ans%10==0) ans = 0;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define  ll    long long int
#define  mod   1000000007   //10^9
#define  N     100005       //10^5
int main()
{
    int n,k,i=0,j;
    ll a[N];
    cin>>n;
    while(n>0)
    {
        k=n%10;
        n/=10;
        if(k==1)
        {
            a[i]=9;
            i++;
        }
        else if(k==9)
        {
            a[i]=1;
            i++;
        }
    }
    for(j=i-1;j>=0;j--)
        cout<<a[j];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	int x;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		
		x = x*x*x;
		
		System.out.println(x);
	}
	
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17156
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
    // code
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int sum = 0;
    ll ans = 0;
    map<int, int> cnt;
    ++cnt[0];
    REP(i, n) {
        sum += a[i];
        sum %= m;
        ans += cnt[sum];
        ++cnt[sum];
    }

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

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

bool option(char x, char y){
	return x > y;
}
int32_t main(){ fast;
	string  a, b; cin>>a>>b;
	sort(all(a));
	sort(all(b), option);
	cout<<(a < b ? "Yes" : "No")<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll M;

long long gcd(long long x,long long y){
	if(x==0) return y;
	return gcd(y%x, x);
}

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

    cin >> M;

    ll ans = -1;
    ll tmp = 0;
    ll now = 0;

    for (int i = 0;i < M;i++){
        ll d,c; cin >> d >> c;
        ans += c;
        tmp += (now+c*d)/10;
        now = (now+c*d)%10;
    }

    ll last = now;
    now = 0;

    while(tmp != 0){
        ans += tmp;
        if(tmp%10+last >= 10){
            last = (tmp%10+last)%10;
            tmp = tmp/10+1;
        }
        else{
            last = (tmp%10+last)%10;
            tmp = tmp/10;
        }
    }

    cout << ans << endl;

    return 0;

}

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

int main(){
  string s;
  cin >> s;
  
  vector<int> ans(s.size(), 0);
  int m = 0;
  for (int i=0 ; i<s.size() ; i++){
    if (s.at(i)=='A' || s.at(i)=='C' || s.at(i)=='G' || s.at(i)=='T')
      ans.at(m)++;
    else
      m++;
  }
  
  sort(ans.begin(), ans.end());
  
  cout << ans.at(s.size()-1) << endl;
}

Measured memory_bytes: 3624
fn main() {
    let st: Vec<String> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim().split_whitespace().map(|e| e.parse().unwrap()).collect()
    };
    let ab: Vec<i32> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim().split_whitespace().map(|e| e.parse().unwrap()).collect()
    };
    let u: String = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim().parse().unwrap()
    };
    if st[0] == u {
        println!("{} {}", ab[0] - 1, ab[1]);
    }
    else {
        println!("{} {}", ab[0], ab[1] - 1);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int h, w, d, q;
  cin >> h >> w >> d;
  vector<vi> a(h, vi(w));
  vi index(h*w);

  rep(i, h) rep(j, w) {
    cin >> a[i][j];
    index[a[i][j]-1] = i*w + j;
  }

  cin >> q;
  vi l(q), r(q);
  rep(i, q) {
    cin >> l[i] >> r[i];
  }

  // 1 indexed
  vector<vi> sum(d, vi(h*w/d+2));
  rep(i, d) {
    for (int j = 0; (j+1)*d+i < h*w; j++) {
      int a = index[j*d+i];
      int b = index[(j+1)*d+i];
      sum[i][j+1] = abs(a/w - b/w) + abs(a%w - b%w);
    }
  }

  rep(i, d) rep(j, h*w/d+1) {
    sum[i][j+1] += sum[i][j];
  }

  //rep(i, d) {
  //  rep(j, h*w/d+2) cerr << sum[i][j] << " ";
  //  cerr << endl;
  //}

  rep(i, q) {
    int ll = l[i]-1, rr = r[i]-1;
    //cerr << ll << " " << rr << endl;
    //cerr << ll%d << " " << rr%d << endl;
    //cerr << ll/d << " " << rr/d << endl;
    //cerr << "   ";
    cout << sum[ll%d][rr/d] - sum[ll%d][ll/d] << endl;
  }
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<LL,LL>
#define LL long long
using namespace std;

LL power(LL x, LL y, LL p) 
{ 
    LL res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
LL modInverse(LL n, LL p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
LL nCrModPFermat(LL n, LL r, LL p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    LL fac[n+1]; 
    fac[0] = 1; 
    for (LL i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    LL x,y;
    cin >> x >> y;
    if ((x + y) % 3 > 0) cout << 0 << endl;
    else {
        LL n = (2*y-x)/3, m = (2*x-y)/3;
        if (n < 0 || m < 0) cout << 0 << endl;
        else cout << nCrModPFermat(n+m, m, MOD) << endl;
    }
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 5504
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7

int main(){

    int n,a,b;
    cin >> n >> a >> b;

    int i = 0;
    bool flag = true;/*ゲームが終了したらfalse*/
    bool winner = true;/*アリス勝利ならtrue、ボリス勝利ならfalse*/

    while(flag){
        if(i % 2 == 0){
            /*iが偶数の場合はアリスの手番*/
            if(a+1 != b){
                /*今いる場所のとなりにボリスがいなければ右に動く*/
                a++;
            }else{
                /*今いる場所の右にボリスがいるので左に動く*/
                if(a == 1){
                    /*１番左にいてもう動けないのでアリスの負けになる*/
                    flag = false;//ゲームの終了
                    winner = false;
                }else{
                    a--;
                }
            }
            i++;
        }else{
            /*iが奇数の場合はボリスの手番*/
            if(b-1 != a){
                /*今いる場所のとなりにアリスがいなければ左に動く*/
                b--;
            }else{
                /*今いる場所の左にアリスがいるので左に動く*/
                if(b == n){
                    /*１番右にいてもう動けないのでアリスの負けになる*/
                    flag = false;//ゲームの終了
                    winner = true;;
                }else{
                    b++;
                }
            }
            i++;
        }
    }
    if(winner){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
static constexpr Int Inf = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;

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

  cin>>n>>m; int c[m][m];
  rep(i,m)rep(j,m)cin>>c[i][j];
  V(int)grp[3];
  rep(i,n)rep(j,n){
    cin>>x;
    grp[(i+j)%3].eb(x-1);
  }
  Int cl[3][m]; fill(cl[0],cl[3],0);
  rep(i,3)rep(j,m)for(int e:grp[i])cl[i][j]+=c[e][j];
  Int ans=1e18;
  rep(i,m)for(int j=0; j<m; j++)for(int k=0; k<m; k++){
    if(i==j||j==k||i==k)continue;
    cmin(ans,cl[0][i]+cl[1][j]+cl[2][k]);
  }
  END
}

Measured memory_bytes: 1520
#include<stdio.h>
int main(){
  int a, b, c, d, p, sumx, sumy, fee;
  scanf("%d %d %d %d %d", &a, &b, &c, &d, &p);
  sumx = a * p;
  if(p > c){
    sumy = b + ((p - c) * d);
  }else if(p <= c){
    sumy = b;
  }
  if(sumx <= sumy){
    fee = sumx;
  }else if(sumx > sumy){
    fee = sumy;
  }
  printf("%d\n", fee);
  return 0;
}

Measured memory_bytes: 596
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<assert.h>
#include<ctime>
using namespace std;
#define LL long long
const int maxn = 2e5+10;
const int maxm = 1e5+10;
double pi = acos(-1.0);

//struct edge{
//    int from, to, cost, next;
//}e[maxn*2];
//int head[maxn], tot;
//inline void add(int a, int b, int c) {
//    e[tot].from = a, e[tot].to = b, e[tot].cost = c, e[tot].next = head[a], head[a] = tot++;
//}
//namespace fastIO {
//    #define BUF_SIZE 100000
//    //fread -> read
//    bool IOerror = 0;
//    inline char nc() {
//        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
//        if(p1 == pend) {
//            p1 = buf;
//            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
//            if(pend == p1) {
//                IOerror = 1;
//                return -1;
//            }
//        }
//        return *p1++;
//    }
//    inline bool blank(char ch) {
//        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
//    }
//    inline void read(int &x) {
//        char ch;
//        while(blank(ch = nc()));
//        if(IOerror)
//            return;
//        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
//    }
//    #undef BUF_SIZE
//};
//using namespace fastIO;

int re[maxn];
int t[maxn], a[maxn];
int l, r, u, v;
    int x, k, q;
void solve(int dv) {
    if(u+dv < 0) {
        l -= u+dv; u = 0;
    }
    else if(u+dv > x) {
        u = x; l = x;
    }
    else {
        u += dv;
    }
    if(v+dv < 0) {
        v = 0; r = 0;
    }
    else if(v+dv > x) {
        r -= v+dv-x; v = x;
    }
    else {
        v += dv;
    }
}

int cal(int x) {
    if(x <= l) return u;
    if(x >= r) return v;
    return u+x-l;
}

int main(){
    while(~scanf("%d%d", &x, &k)) {
        l = u = 0; r = v = x;
        for(int i = 1; i <= k; i++) {
            scanf("%d", &re[i]);
        }
        scanf("%d", &q);
        for(int i = 0; i < q; i++) {
            scanf("%d%d", &t[i], &a[i]);
        }
        t[q] = 0x7fffffff;
        for(int i = 1, j = 0, tp = 0; i <= k || j < q; ){
            if(i <= k && re[i] <= t[j]) {
                solve((i&1) ? tp-re[i] : re[i]-tp);
                tp = re[i++];
            }
            else {
                solve((i&1) ? tp-t[j] : t[j]-tp);
                printf("%d\n", cal(a[j]));
                tp = t[j++];
            }
        }
    }
}


Measured memory_bytes: 2304
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int i,j,k;
  int h,w;
  int dx[4]={0,1,0,-1};
  int dy[4]={1,0,-1,0};

  while(1){
    int sum=0;
    int c[20][20]={};
    char str[20];
    rep(i,12){
      if(scanf("%s",str)==EOF)return 0;
      rep(j,12)
        c[i+1][j+1]=str[j]-'0';
    }

    while(1){
      bool next=false;
      queue<pii> q;

      rep(i,14){
        rep(j,14)
          if(c[i][j]==1){
            next=true;
            break;
          }
        if(next)break;
      }
      if(next==false)break;
     q.push(pii(i,j));//y,x                                              
      sum++;
      while(q.size()){
        i=q.front().first;
        j=q.front().second;
        q.pop();
        c[i][j]=0;
        rep(k,4){
          int y=i+dy[k];
          int x=j+dx[k];
          if(c[y][x]==1){
            q.push(pii(y,x));
            c[y][x]=0;
          }
        }
      }

    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> h(n+10, 0);
	for( int i = 0; i < n; ++i ){
		cin >> h[i];
	}
	vector<int> cost(n+10, INF);
	cost[0] = 0;
	for( int i = 0; i < n; ++i ){
		cost[i+1] = min(cost[i+1], cost[i]+abs(h[i+1]-h[i]));
		cost[i+2] = min(cost[i+2], cost[i]+abs(h[i+2]-h[i]));
	}
	cout << cost[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
////   template  ///////////////////////////////////////////////////////
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <sys/resource.h>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

class timer{
	enum KIND{ REAL, CPU }; // real_time or cpu_time
	double t0; // start
	double t1; // end
	KIND kind_of_time; // default is real_time
	double get_realtime(){struct timeval tv; gettimeofday(&tv, NULL);
		return tv.tv_sec + (double)tv.tv_usec*1e-6;}
	double get_cputime(){struct rusage RU; getrusage(RUSAGE_SELF, &RU); 
		return RU.ru_utime.tv_sec + (double)RU.ru_utime.tv_usec*1e-6;}
public:
	timer(){kind_of_time = REAL;}
	void set(KIND k){kind_of_time = k;}
	void start(){t0 = get_realtime();}
	void stop(){t1 = get_realtime();}
	void print(){printf("TotalTime : %.3fsec\n", t1-t0);}
};
////////////////////////////////////////////////////////////////////////

void createPrimeTable(vector<int> *v, int size);
int eulerPhi(int n);

int main()
{
	int n;
	cin >> n;
	timer T;
	T.start();
	cout << eulerPhi(n) << endl;
	T.stop();
	//T.print();

	return 0;
}


 /*
   与えられた自然数ｎを素因数分解した時, それぞれ異なる素因数 a, b, c,...,z が得られたとすると, 
   φ(n) = n*(1-1/a)*(1-1/b)*...*(1-1/z) となる.
 */
 int eulerPhi(int n)
 {
	 if( n == 1 ) return 1;

	 vector<int> v;
	 int sn = (int)sqrt(n)+1;
	 createPrimeTable(&v, sn+1);

	 double ret = n;
	 vector<int>::iterator i;
	 for(i=v.begin(); i!=v.end() && n!=1; i++){
		 if(!(n%(*i))){
			 ret *=  ((double)(*i)-1)/(double)(*i) ;
			 if(n==*i){n /= *i; break;}
			 while(!(n%(*i))) n /= *i;
		 }
	 }

	 if(n!=1) ret = ret*((double)(n)-1)/(double)(n);

	 return ret;
 }

 void createPrimeTable(vector<int> *v, int size)
 {
	 int table[size]; 
	 for(int i=0; i<size; i++) table[i] = 1;
	 table[0] = table[1] = 0;
	 for(int i=2; i<size; i++)
		 if( table[i] ) for(int j=i+i;j<size; j+=i ){ table[j] = 0; }

	 for(int i=0; i<size; i++)
		 if( table[i] ) v->push_back(i);
 }    

Measured memory_bytes: 1376
// H - Grid 1
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define MOD 1'000'000'007
#define chsum(x,y) x=(x + y)%MOD
int dp[1001]; // [0,1000] init 0

int main(){
	int H,W; cin>>H>>W;
	dp[1] = 1;
	while(H--){ // H times
		string a; cin>>a;
		rep(w, W){ // [0,W-1]
			if(a[w] == '#') dp[w+1] = 0;
			else chsum(dp[w+1], dp[w]);
		}
	}
	cout<< dp[W] <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	rep(i,0,a){
		rep(j,0,b)printf("%d",j<c^i<d);
		puts("");
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int32_t main()
{
	int n, ans = 0, cnt = 0;
	cin >> n;
	vector<int> arr(n);
	for(int &w : arr) cin >> w;
	sort(arr.rbegin(), arr.rend());
	for(int i = 0; i < n; i++)
	{
		if(!i) ans += arr[i], cnt++;
		else if(cnt < n - 1)
		{ 
			ans += 2 * arr[i], cnt += 2;
			if(cnt >= n) ans -= arr[i];
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4848
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <memory.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int a, b, t;
    int ans;

    scanf("%d %d %d", &a, &b, &t);

    ans = (t / a) * b;

    printf("%d\n", ans);

    return 0;
}


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

const long long INF = 1LL << 60;

long long numTrack(vector<long long>& w, int n, int P) {
	long long  ans = 1, tmp_w = 0;
	for (int i = 0; i < n; i++) {
		if (tmp_w + w[i] > P) {
			ans++;
			tmp_w = w[i];
		}
		else {
			tmp_w += w[i];
		}
	}
	return ans;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<long long> w(n);
	long long max_w = 0, sum_w = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		max_w = max(max_w, w[i]);
		sum_w += w[i];
	}

	long long upper = sum_w;
	long long lower = max_w;
	long long ans = INF;
	while (upper >= lower) {
		long long middle = (upper + lower) / 2;
		if (numTrack(w, n, middle) <= k) {
			ans = min(ans, middle);
			upper = middle - 1;
		}
		else {
			lower = middle + 1;
		}
	}
	cout << ans << endl;
}



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


int main()
{
	int n; cin >> n;
	string s;
	map<string, int> m;
	while(cin >> s) m[s]++;
	for (auto x : {"AC", "WA", "TLE", "RE"})
		cout << x << " x " << m[x] << endl;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;

vector<int> V[105];
queue<int> Q;
vector<int> color(105, 1), d(105, -1);

int main() {
	int n;
	cin >> n;
	Loop(i, n) {
		int u, k;
		cin >> u >> k;
		Loop(j, k) {
			int v;
			cin >> v;
			V[u].push_back(v);
		}
	}
	//
	Q.push(1);
	color[1] = 2;
	d[1] = 0;
	while (Q.size() > 0) {
		int u = Q.front();
		Q.pop();
		Loop(i, V[u].size()) {
			if (color[V[u][i]] == 1) {
				Q.push(V[u][i]);
				color[V[u][i]] = 2;
				d[V[u][i]] = d[u] + 1;
			}
		}
	}
	Loop1(i, n) {
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    cin >> N >> K;
    vector<Vi> dest(N, Vi(60));
    for (ll i = 0; i < N; i++) {
        int a;
        cin >> a;
        --a;
        dest[i][0] = a;
    }

    for (ll j = 0; j < 59; j++) {
        for (ll i = 0; i < N; i++) {
            dest[i][j + 1] = dest[dest[i][j]][j];
        }
    }

    ll cur = 0;
    for (ll i = 0; i <= 60; i++) {
        if (K & 1) cur = dest[cur][i];
        K >>= 1;
    }

    cout << cur + 1 << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 57816
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;

void solve(){
    
    int n,t,a;
    cin >> n >> t >> a;
    vi v(n,0);

    rep(i,0,n) cin >> v[i];
    D cal = 0.0,acal = (float)1e8;
    int ans = 0;
    rep(i,0,n){
    	cal = t - v[i]*0.006;
    	if(abs(a-cal) < acal){
    		acal = abs(a-cal);
    		ans = i+1;
    	}
    }

    cout << ans << "\n";
}

int main(){
    
    fast_io;
    // cin.exceptions(cin.failbit);
    
    solve();
    
    
    cpuTime();
return 0;
}


/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/

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

int main(){
    int n,m;
    cin>>n>>m;
    double sum=0;
    vector<double> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    int cnt=0;
    double tmp=1.0/(4.0*(double)m);
    for(int i=0;i<n;i++){
        if(a[i]/sum>=tmp)cnt++;
        if(cnt==m)break;
    }
    if(cnt==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256