akhauriyash/Code-Regression huggingface dataset:
//2008dC
I;int parse(char *p){
  switch(*p){
    case 'F': return 0;
    case 'T': return 1;
    case 'a': return (I>>0)&1;
    case 'b': return (I>>1)&1;
    case 'c': return (I>>2)&1;
    case 'd': return (I>>3)&1;
    case 'e': return (I>>4)&1;
    case 'f': return (I>>5)&1;
    case 'g': return (I>>6)&1;
    case 'h': return (I>>7)&1;
    case 'i': return (I>>8)&1;
    case 'j': return (I>>9)&1;
    case 'k': return (I>>10)&1;
    case '-': return !parse(p+1);
    case '(': {
                int x=0;
                p++;
                char *q=p;
                for(;;p++){
                  if(*p=='(')x++;
                  if(*p==')')x--;
                  if(x==0&&*p!='-')break;
                }
                p++;
                switch(*p){
                  case '*': return parse(q)&parse(p+1);
                  case '+': return parse(q)|parse(p+1);
                  case '-': return !parse(q)|parse(p+2);
                }
              }
  }
}

int main(){
  char p[1001],*q;
  while(1){
    scanf("%s",p);
    if(*p=='#')return 0;
	q=strchr(p,'=')+1;
for(I=0;I<2048;I++)if(parse(p)!=parse(q))goto fail;
    puts("YES");continue;
	fail:puts("NO");
  }
}

Measured memory_bytes: 552
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	}
}



Measured memory_bytes: 101280
// AOL q0037
// YAMADA Terushige
// 2013.4.12

#include<iostream>
 
using namespace std;
int grid[5][5][4];
 
int main(){
 
  enum Direc {L,U,R,D};
  string s;

  int i,j,k,d;
  for(i=0;i<4;i++){
    cin >> s;
    for(j=0;j<4;j++){
      grid[i][j][R]=grid[i][j+1][L]=s[j]-'0';
    }
    cin >> s;
    for(j=0;j<5;j++){
      grid[i][j][D]=grid[i+1][j][U]=s[j]-'0';
    }
  }
  cin >> s;
  for(j=0;j<4;j++){
    grid[i][j][R]=grid[i][j+1][L]=s[j]-'0';
  }

  i=0;j=1;
  d=R;cout <<'R';
  while(i!=0 || j!=0){
    d=(d+2)%4;
    for(k=0;k<4;k++){
      d=(d+1)%4;
      if(grid[i][j][d]==1)break;
    }

    switch(d){
    case L:
      cout << 'L';j--;
      break;
    case U:
      cout << 'U';i--;
      break;
    case R:
      cout << 'R';j++;
      break;
    case D:
      cout << 'D';i++;
      break;
    }

  }
  cout << endl;
}


Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int m,k;
    cin>>m>>k;
    if(k>=(1<<m))
    {
        cout<<"-1\n";
        return 0;
    }
    if(m==1)
    {
        if(k==1)
            cout<<"-1\n";
        else
        {
            cout<<"0 0 1 1\n";
        }
        
        return 0;
    }
    for(int i=0;i<=((1<<m)-1);i++)
    {
        if(i!=k)
            cout<<i<<" ";
    }
    cout<<k<<" ";
    for(int i=(1<<m)-1;i>=0;i--)
    {
        if(i!=k)
            cout<<i<<" ";
    }
    cout<<k<<"\n";
    return 0;
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

int main(){
  char buf[1024];
  int A,B;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &A, &B);

  int ans;

  if(A>=13){
    ans=B;
  }
  else if(A>=6){
    ans=B/2;
  }
  else{
    ans=0;
  }

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

  return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n; 
    scanf("%d", &n);
    vector<int> dp(3,0);
    
    for(int day = 0; day < n; ++day){
        vector<int> new_dp(3,0);
        vector<int> c(3);
        for(int i = 0; i < 3; ++i){
            scanf("%d", &c[i]);
        }
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 3; ++j){
                if(i != j){
                    new_dp[j] = max(new_dp[j], dp[i] + c[i]);
                }
            }
        }
        dp = new_dp;
    }

    printf("%d\n", max({dp[0], dp[1], dp[2]}));

    return 0;
}

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

using namespace std;

int main()
{
    int m,n;
    cin>>m>>n;
    if(m==1&&n==1){
        cout<<1<<endl;
    }
    else if(m==1){
        cout<<n-2<<endl;
    }
    else if(n==1){
        cout<<m-2<<endl;
    }
    else{
        long long ans=(long long)m*n;
        ans -= (n-2)*2;
        ans -= (m-2)*2;
        ans -=4;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	int f=0,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
#define MAXN 5000
#define MAXM 100000
#define INF 0x3f3f3f3f
struct Edge{
	int nxt,v,cap,w;
}edge[MAXM+5];
int ncnt=-1,head[MAXN+5];
void Addedge(int u,int v,int cap,int w){
	edge[++ncnt]=(Edge){head[u],v,cap,w},head[u]=ncnt;
	edge[++ncnt]=(Edge){head[v],u,0,-w},head[v]=ncnt;
	return ;
}
int N,S,T;
bool vis[MAXN+5];
int cur[MAXN+5];
LL dep[MAXN+5];
bool BFS(){
	queue<int> Q;
	for(int i=0;i<=N;i++)
		vis[i]=0,dep[i]=1ll*10000*INF;
	dep[S]=0,vis[S]=1,Q.push(S);
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		vis[u]=0;
		for(int i=head[u];~i;i=edge[i].nxt){
			int v=edge[i].v,cap=edge[i].cap,w=edge[i].w;
			if(cap&&dep[v]>dep[u]+w){
				dep[v]=dep[u]+w;
				if(!vis[v])
					vis[v]=1,Q.push(v);
			}
		}
	}
	return dep[T]<1ll*10000*INF;
}
LL cost;
int DFS(int u,int aug){
	if(u==T) return aug;
	vis[u]=1;
	int flow=0,f;
	for(int i=cur[u];i!=-1;i=edge[i].nxt){
		cur[u]=i;
		int v=edge[i].v,cap=edge[i].cap,w=edge[i].w;
		if(!vis[v]&&dep[v]==dep[u]+w&&cap&&(f=DFS(v,min(cap,aug)))){
			aug-=f,flow+=f,cost+=1ll*f*w;
			edge[i].cap-=f,edge[i^1].cap+=f;
			if(!aug) break;
		}
	}
	vis[u]=0;
	return flow;
}
#define Flow 0x3f3f3f3f
void Dinic(){
	//int Max_Flow=0;
	while(BFS())
		memcpy(cur,head,sizeof(head)),DFS(S,Flow);
	return ;
}
int main(){
	memset(head,-1,sizeof(head));
	int n=read();
	N=2*n+6,S=2*n+1,T=2*n+2;
	int n1=2*n+3,n2=2*n+4,n3=2*n+5,n4=2*n+6;
	for(int i=1;i<=n;i++){
		int x=read(),y=read(),c=read();
		Addedge(S,i,c,0);
		Addedge(i,n1,INF,-x-y);
		Addedge(i,n2,INF,-x+y);
		Addedge(i,n3,INF,x-y);
		Addedge(i,n4,INF,x+y);
	}
	for(int i=1;i<=n;i++){
		int x=read(),y=read(),c=read();
		Addedge(n+i,T,c,0);
		Addedge(n1,n+i,INF,x+y);
		Addedge(n2,n+i,INF,x-y);
		Addedge(n3,n+i,INF,-x+y);
		Addedge(n4,n+i,INF,-x-y);
	}
	Dinic();
	printf("%lld\n",-cost);
    return 0;
}

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

// 1-indexed
template <class T, class E>
struct SegmentTreeLaze {
  // a,b:T c,d:E e:E(unit)
  // g(f(a,b),c) = f(g(a,c),g(b,c))
  // g(g(a,c),d) = g(a,h(c,d))
  // g(a,e) = a
  typedef function<T(T, T)> F;
  typedef function<T(T, E)> G;
  typedef function<E(E, E)> H;
  int n, height;
  F f;
  G g;
  H h;
  T tunit;
  E eunit;
  vector<T> dat;
  vector<E> laz;
  SegmentTreeLaze(){};
  SegmentTreeLaze(int newn, F f, G g, H h, T nt, E ne)
      : f(f), g(g), h(h), tunit(nt), eunit(ne) {
    init(newn);
  }
  void init(int newn) {
    n = 1, height = 0;
    while(n < newn) n <<= 1, ++height;
    dat.assign(n << 1, tunit);
    laz.assign(n << 1, eunit);
  }

  inline T reflect(int k) {
    return laz[k] == eunit ? dat[k] : g(dat[k], laz[k]);
  }

  inline void eval(int k) {
    if(laz[k] == eunit) return;
    laz[k << 1] = h(laz[k << 1], laz[k]);
    laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = eunit;
  }

  inline void thrust(int k) {
    for(int i = height; i; --i) eval(k >> i);
  }

  void recalc(int k) {
    while(k >>= 1)
      dat[k] = f(reflect(k << 1), reflect((k << 1) | 1));
  }
  // [a,b)
  void update(int a, int b, E newdata) {
    thrust(a += n);
    thrust(b += n - 1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l], newdata), l++;
      if(r & 1) --r, laz[r] = h(laz[r], newdata);
    }
    recalc(a);
    recalc(b);
  }

  void set_val(int k, T newdata) {
    thrust(k += n);
    dat[k] = newdata;
    laz[k] = eunit;
    recalc(k);
  }

  // [a,b)
  T query(int a, int b) {
    thrust(a += n);
    thrust(b += n - 1);
    T vl = tunit, vr = tunit;
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) vl = f(vl, reflect(l++));
      if(r & 1) vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }
};

long long n, q;

int main() {
  cin >> n >> q;
  auto f = [](long long l, long long r) {
    return min(l, r);
  };
  auto g = [](long long l, long long r) { return r; };
  auto h = [](long long l, long long r) { return r; };
  SegmentTreeLaze<long long, long long> seg(n, f, g, h,
                                            2147483647, -1);
  for(int i = 0; i < n; ++i) seg.set_val(i, 2147483647);
  for(int i = 0; i < q; ++i) {
    long long c, s, t, x;
    cin >> c >> s >> t;
    if(c) { cout << seg.query(s, t + 1) << endl; }
    else {
      cin >> x;
      seg.update(s, t + 1, x);
    }
  }
  return 0;
}


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

  
  if(a > b){
    
    rep(i,a) cout << b;
    
  }else{

    rep(i,b) cout << a;
    
  }
  
}
    
    

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int search(int a[],int n,int target)
{
    a[n]=target;
    int i=0;
    while(a[i]!=target)
        i++;
    return i!=n;
}

int main()
{
    int n,q,count=0;
    int a[10005],b[505];

    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);

    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d",&b[i]);
        if(search(a,n,b[i])) count++;
    }
    printf("%d\n",count);
}



Measured memory_bytes: 2076
#https://atcoder.jp/contests/abc128
# -*- coding: utf-8 -*-

n,m = map(int,input().split())

k = []
s = []
for i in range(m):
    x = list(map(int,input().split()))
    k.append(x[0])
    y = []
    for j in range(x[0]):
        y.append(x[j+1])
    s.append(y)

p = list(map(int,input().split()))

cnt = 0
for i in range(1024):
    x = format(i,"010b")[::-1]
    if n < 10 and x[n] == "1":
        break
    
    for j in range(m):
        tmpSum = 0
        for k in s[j]:
            tmpSum += int(x[k-1])
        if tmpSum%2 is not p[j]:
            break
    else:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=1e5+10;
int a[maxn];
int main(){
    int n=read(),L=read(),Max=1;
	REP(i,1,n) a[i]=read();
	REP(i,1,n-1) if(a[i]+a[i+1]>a[Max]+a[Max+1]) Max=i;
	if(a[Max]+a[Max+1]<L) return printf("Impossible\n"),0;
	printf("Possible\n");
	REP(i,1,Max-1) printf("%d\n",i);
	DREP(i,n-1,Max) printf("%d\n",i);
    return 0;
}

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

map<string,int> m;
string a,b;

int main(){
	m["1"]=14;
	m["2"]=2;
	m["3"]=3;
	m["4"]=4;
	m["5"]=5;
	m["6"]=6;
	m["7"]=7;
	m["8"]=8;
	m["9"]=9;
	m["10"]=10;
	m["11"]=11;
	m["12"]=12;
	m["13"]=13;
	cin >> a;
	cin >> b;
	if (m[a]>m[b]) cout << "Alice";
	else if (m[a]<m[b]) cout << "Bob";
	else cout << "Draw";
	return 0;
}

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

ifstream fin("pentagon.in");
ofstream fout("pentagon.out");

#define MOD 100019
#define NMAX 10005



int main()
{
   int a,b;
   cin>>a>>b;
   int sum = 0;
   sum+=(a*(a-1)/2 + b*(b-1)/2);
   cout<<sum;

   return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - One Clue
https://atcoder.jp/contests/abc137/tasks/abc137_b

"""
import sys


def solve(K, X):
    return [i for i in range(X - K + 1, X + K) if -1000000 <= i <= 1000000]


def main(args):
    K, X = map(int, input().split())
    ans = solve(K, X)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		while(scan.hasNext()){
			int a = scan.nextInt();
			int b = scan.nextInt();
			int n = scan.nextInt();
			a%=b;
			int s = 0;
			for (int i = 0; i < n; i++) {
				s+=a*10/b;
				a=a*10%b;
			}
			System.out.println(s);
		}
	}
}

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

string S;
ll p = 0;

bool parse() {
  if(p < S.length() && S[p] == 'm') {
    bool ok = true;
    p++;
    ok = parse() && ok;
    ok = S[p++] == 'e' && ok;
    ok = parse() && ok;
    ok = S[p++] == 'w' && ok;
    return ok;
  } else {
    return true;
  }
}

int main(void) {
  cin >> S;
  cout << (parse() && p == S.length() ? "Cat" : "Rabbit") << endl;
}



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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

int n;
bool fld[600][600];

int main()
{
	while (cin >> n, n)
	{
		memset(fld, false, sizeof(fld));
		vector<P> v;
		v.push_back(P(300, 300));
		REP(i, n-1)
		{
			int a, b;
			cin >> a >> b;
			if (b == 0) v.push_back(P(v[a].first - 1, v[a].second));
			if (b == 1) v.push_back(P(v[a].first, v[a].second - 1));
			if (b == 2) v.push_back(P(v[a].first + 1, v[a].second));
			if (b == 3) v.push_back(P(v[a].first, v[a].second + 1));
		}
		int maxx = 0, maxy = 0, minx = 1000, miny = 1000;
		REP(i, n)
		{
			maxx = max(maxx, v[i].first);
			minx = min(minx, v[i].first);
			maxy = max(maxy, v[i].second);
			miny = min(miny, v[i].second);
		}
		cout << maxx - minx + 1 << " " << maxy - miny + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1564
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    h,w,d=map(int,readline().split())
    a=[list(map(int,readline().split())) for _ in range(h)]
    q=int(readline())
    l=[0]*q
    r=[0]*q
    for i in range(q):
        l[i],r[i]=map(int,readline().split())

    #座標メモ
    co=dict()
    for i in range(h):
        for j in range(w):
            co[a[i][j]]=(i,j)

    #累積和
    s=[0]*(h*w+1)
    for i in range(1,d+1):
        j=i+d
        while j<=h*w:
            distance=abs(co[i][0]-co[j][0])+abs(co[i][1]-co[j][1])
            s[j]+=s[i]+distance
            i+=d
            j+=d

    #実技試験
    for i in range(q):
        print(s[r[i]]-s[l[i]])

if __name__=="__main__":
    main()

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

int main() {
    int N;
    cin >> N;
    char c;
    bool flag = false;
    for(int i = 0; i < N; i++) {
        cin >> c;
        if (c == 'Y') {
            flag = true;
            break;
        }
    }
    if (flag)
        cout << "Four" << "\n";
    else
        cout << "Three" << "\n";
}



Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<pair<T, T> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int gcd(int a, int b) {
	return (b == 0) ? a : gcd(b, a % b); 
}

int gcd(int a, int b, int c) {
	return gcd(a, gcd(b, c));
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int k;
	cin >> k;

	int sum = 0;
	for (int i = 1; i <= k; ++i) {
		for (int j = 1; j <= k; ++j) {
			for (int l = 1; l <= k; ++l) {
				sum += gcd(i, j, l);
			}
		}
	}

	cout << sum << "\n";

	return 0;

}

Measured memory_bytes: 3648
#include <stdio.h>
typedef long long ll;

int main(){
    int n,i,ans=0;
    scanf("%d",&n);
    int x=n;
    for(i=1;i<=6;i++){
        if(x<10) break;
        x/=10;
    }
    switch(i){
        case 1: ans+=n; break;
        case 3: ans+=n-99;
        case 2: ans+=9; break;
        case 5: ans+=n-9999;
        case 4: ans+=909; break;
        case 6: ans+=90909; break;
    }
    printf("%d",ans);
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

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

	int n, m;
	cin >> n >> m;
	vector< vector<int> > A;
	vector<int> b;
	
	REP(i, n) {
		vector<int> v;
		REP(j, m) {
			int in;
			cin >> in;
			v.push_back(in);
		}
		A.push_back(v);
	}
	
	REP(j, m) {
		int in;
		cin >> in;
		b.push_back(in);
	}
	
	REP(i, n) {
		int sum = 0;
		REP(j, m) {
			sum += A[i][j] * b[j];
		}
		cout << sum << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1288
import heapq


def dijkstra(start_v, G):
    n = len(G)
    dist = [0 if i == start_v else float("inf") for i in range(n)]

    que = []
    heapq.heappush(que, (0, start_v))

    while que:
        cur_d, cur_v = heapq.heappop(que)
        if dist[cur_v] < cur_d:
            continue
        for adj in G[cur_v]:
            nxt_v, cost = adj
            if dist[cur_v] + cost < dist[nxt_v]:
                dist[nxt_v] = dist[cur_v] + cost
                heapq.heappush(que, (dist[nxt_v], nxt_v))

    return dist


def main():
    n = int(input())
    g = [[] for _ in range(n)]

    for i in range(n):
        data = [int(x) for x in input().split()]
        u, k = data[0], data[1]
        vc = data[2:]
        for j in range(k):
            v, c = vc[2 * j], vc[2 * j + 1]
            g[u].append((v, c))

    dist = dijkstra(0, g)

    for i in range(n):
        print(i, dist[i])


main()


Measured memory_bytes: 6204
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;



int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int x;
  cin >> x;
  if (x < 1200) {
    cout << "ABC\n";
  } else {
    cout << "ARC\n";
  }
  return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int n = b-a;
    int at = 0;
    for(int i=1; i<n; i++){
        at = at+i;
    }   
        System.out.println(at-a);
 }
}


Measured memory_bytes: 35716
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#define ll long long
using namespace std;

#define MOD 1000000007

class Solve
{
private:
	int n;
	vector<ll> a;
	ll ans;

public:
	Solve(){
		cin >> n;
		a.resize(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i];
		}
		sort(a.begin(), a.end());
	}

	void exec(){
		ll imos = 0;
		ans = 0;
		for (int i = 0; i < n-1; ++i)
		{
			imos += a[i];
			if(imos * 2 >= a[i+1]){
				ans++;
			}else{
				ans = 0;
			}
		}
		ans++;

		cout << ans << endl;
	}
};

int main(){
	Solve solver = Solve();
	solver.exec();
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

    int K = 0;
    int N = 0;
    int max = 0;

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

    int A[N];
    int distance[N];

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

        if (i > 0){
            distance[i] = A[i] - A[i - 1];
        }
        if (distance[i] > max){
            max = distance[i];
        }
        //printf("max:%d\n", max);
    }
    distance[0] = (K - A[N - 1]) + A[0];

    if (distance[0] > max){
        max = distance[0];
    }
    max = K - max;

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

    return 0;
}

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

int main() {
  int N,M,i,j;
  int ans=0;
  cin>>N>>M;
  vector<int>a(M),b(M),c(M),r(N);
  for(i=0;i<M;i++){
    cin>>a[i]>>b[i];
    c[i]=a[i]*b[i]*100+a[i]+b[i];
  }
  for(i=0;i<N;i++)r[i]=i+1;
  for(i=0;i<N-1;i++){
    for(j=0;j<M;j++){
      if(r[i]*r[i+1]*100+r[i]+r[i+1]==c[j])break;
    }
    if(j==M)break;
}
if(i==N-1)ans++;
  while(next_permutation(r.begin(),r.end())){
    if(r[0]!=1)continue;
    for(i=0;i<N-1;i++){
      for(j=0;j<M;j++){
        if(r[i]*r[i+1]*100+r[i]+r[i+1]==c[j])break;
      }
      if(j==M)break;
  }
  if(i==N-1)ans++;
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define all(x) x.begin(), x.end()
#define watch(x) cout<<#x<<" : "<<x<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define testCases int tt;cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef vector<string> vs;

int main() {
    fastio;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    ll one = 1ll*a*c;
    ll two = 1ll*a*d;
    ll three = 1ll*b*c;
    ll four = 1ll*b*d;
    ll ans = max(one,two);
    ans = max(ans, three);
    ans = max(ans, four);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
N =int(input())

T,A = map(int,input().split())

H = list(map(int,input().split()))

diff_list = []

cur = 0

for i in range(N):
  diff = abs(A - (T - H[i] * 0.006))
  diff_list.append(diff)
  if diff == min(diff_list):
    cur = i + 1

print(cur)



Measured memory_bytes: 3060
N = int(input())
H = list(map(int, input().split()))
ans = "Yes"
for i in range(0, N - 1):
  diff = H[i + 1] - H[i]
  if diff >= 1:
    H[i + 1] -= 1
  elif diff < 0:
    ans = "No"
print(ans)

Measured memory_bytes: 14396
s = input()
tt = ['dream', 'dreamer', 'erase', 'eraser']
t = ''
i = len(s) - 1
while (i > 0):
    if s[i] == 'm':
        t = tt[0] + t
        i -= 5
    elif s[i] == 'e':
        t = tt[2] + t
        i -= 5
    elif s[i] == 'r':
        if s[i - 2] == 'm':
            t = tt[1] + t
            i -= 7
        elif s[i - 2] == 's':
            t = tt[3] + t
            i -= 6
        else:
            break
    else:
        break
if s == t:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3556
#pragma GCC optimize ("Ofast")
#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;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define gnr(i,l,r) for(int i=int(r)-1; i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\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,key;
string s,sb;
bool ok;



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

  int ans,l,r; V(int)s,p; V(int)::iterator it;
  while(1){
    cin>>n;
    if(!n)return 0;
    cin>>m>>q;
    s.assign(m+1,0); p.assign(q,0);
    rep(i,m-1)cin>>s[i+1]; s[m]=n;
    rep(i,q)cin>>p[i];
    ans=0;
    sort(ALL(s));
    rep(i,q){
      it=lower_bound(ALL(s),p[i]);
      r=*it;
      if(it==s.begin())l=0;
      else l=*(--it);
      ans+=min(r-p[i],p[i]-l);
    }
    pri1(ans);
  }
}


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

int main()
{
  long A,B,C,D;
  cin>>A>>B>>C>>D;
  long AC,BC,AD,BD,ACD,BCD;
  long ans;
  long r,c,d,temp,Z;
  c=C;
  d=D;
  if(c<d){
    temp=c;
    c=d;
    d=temp;
  }
  r=c%d;
  while(r!=0){
    c=d;
    d=r;
    r=c%d;
  }
  Z=C*D/d;
  AC=(A-1)/C;
  AD=(A-1)/D;
  ACD=(A-1)/Z;
  BC=B/C;
  BD=B/D;
  BCD=B/Z;
  ans=B-A+1-(BC-AC)-(BD-AD)+(BCD-ACD);
  cout << ans <<endl;
}


Measured memory_bytes: 256
n = int(input())
S = list(input().upper())

def shift_char(ch, num):
  z_ord = ord('Z')
  num_ord = ord(ch) + num 
  if num_ord > z_ord:
    num_ord -= 26
  return chr(num_ord)

for i in range(len(S)):
  S[i] = shift_char(S[i], n)
print(''.join(S))

Measured memory_bytes: 3060
#include <cstdio>

using namespace std;

int main()
{
  int a, b, c, d, e;
  scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
  if (a == 0)
    printf("1\n");
  if (b == 0)
    printf("2\n");
  if (c == 0)
    printf("3\n");
  if (d == 0)
    printf("4\n");
  if (e == 0)
    printf("5\n");
  return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, k, p[26] = {};
    cin >> n >> k;
    REP(i,n){
        string s;
        cin >> s;
        p[s[0]-'A']++;
    }

    priority_queue<int> pq;
    REP(i,26){
        pq.push(p[i]);
    }
    int ans = 0;
    while(1){
        VI a(k);
        REP(i,k){
            a[i] = pq.top();
            pq.pop();
        }
        if (a[k-1] == 0) break;
        ans++;
        REP(i,k){
            pq.push(a[i]-1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORTR(x) sort(ALLR(x));
#define SORT(x) sort(ALL(x));
#define SUM(x) accumulate(ALL(A), 0);
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
typedef vector<ll> VI;
typedef vector<VI> VVI;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}


void Main()
{
	ll N;
	string result="Three";
	cin>>N;
	vector<string> S(N);
	REP(i, N) cin >> S[i];
	REP(i,N){
		if(S[i]=="Y"){
			result="Four";
		}
	}

	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    
    vector<string> t_k(k, "");
    for(int i = 0; i < n; i++){
        t_k[i % k] += t[i];
    }

    int ans = 0;
    for(int i = 0; i < k; i++){
        vector<vector<int>> memo(t_k[i].length(), vector<int>(3, 0));
        if(t_k[i][0] == 'r') memo[0][2] = p;
        if(t_k[i][0] == 's') memo[0][0] = r;
        if(t_k[i][0] == 'p') memo[0][1] = s;
        for(int j = 1; j < t_k[i].length(); j++){
            if(t_k[i][j] == 'r'){
                memo[j][0] = max(memo[j-1][1], memo[j-1][2]);
                memo[j][1] = max(memo[j-1][0], memo[j-1][2]);
                memo[j][2] = max(memo[j-1][0]+p, memo[j-1][1]+p);
            }else if(t_k[i][j] == 's'){
                memo[j][0] = max(memo[j-1][1]+r, memo[j-1][2]+r);
                memo[j][1] = max(memo[j-1][0], memo[j-1][2]);
                memo[j][2] = max(memo[j-1][0], memo[j-1][1]);
            }else{
                memo[j][0] = max(memo[j-1][1], memo[j-1][2]);
                memo[j][1] = max(memo[j-1][0]+s, memo[j-1][2]+s);
                memo[j][2] = max(memo[j-1][0], memo[j-1][1]);
            }
        }

        int coans = 0;
        for(int l = 0; l < 3; l++){
            if(memo[t_k[i].length()-1][l] > coans) coans = memo[t_k[i].length()-1][l];
        }
        ans += coans;
    }

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

Measured memory_bytes: 5888
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typedef modint<MOD> m;
#pragma endregion

int main() {
  bool flag = true;
  cin >> N;
  rep(i, N){
    cin >> A;
    if(A%2 == 0 && (A%3 != 0 && A%5 != 0)){
      flag = false;
    }
  }
  if(flag){
    cout << "APPROVED";
  }else{
    cout << "DENIED";
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<double> P;

#define EPS (1e-10)

double dot(P a,P b){
	return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a,P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a) < EPS) return abs(c-a);
	if(dot(a-b,c-b) < EPS) return abs(c-b);
	return abs(cross(b-a,c-a)) / abs(b-a);
}

bool pol_contains_cir(vector<P> p,P o,double r){
	int n = p.size();
	int cr = 0, cl = 0;
	for(int i=0;i<n;i++){
		P a = p[i];
		P b = p[(i+1)%n];
		if(EPS > cross(b-a,o-a)) cr++;
		if(0 < cross(b-a,o-a) + EPS) cl++;
		if(distance_ls_p(a,b,o) < r) return false;
	}
	if(cr != n && cl != n) return false;

	return true;
}

bool cir_contains_pol(vector<P> p,P o,double r){
	for(int i=0;i<p.size();i++){
		if(r < abs(p[i]-o)) return false;
	}
	return true;
}

bool is_intersected_ls_cir(P a,P b,P o,double r){
	double ao = abs(a-o);
	double bo = abs(b-o);

	return ((ao < r + EPS && r < bo + EPS || r < ao + EPS && bo < r + EPS) ||
					(r < ao + EPS && r < bo + EPS && distance_ls_p(a,b,o) < r + EPS));
}

bool is_intersected_pol_cir(vector<P> p,P o,double r){
	int n = p.size();

	for(int i=0;i<n;i++){
		if(is_intersected_ls_cir(p[i],p[(i+1)%n],o,r)) return true;
	}

	return false;
}

int main(void){
	/*
	P a = P(0,0);
	P b = P(0,2);
	P c = P(-0.1,1);

	cout << cross(b-a,c-a) << endl;
	*/

	while(1){
		vector<P> p;
		for(int i=0;i<3;i++){
			P tmp;
			cin>>tmp.real()>>tmp.imag();
			if(tmp.real()==0 && tmp.imag()==0) return 0;
			p.push_back(tmp);
		}

		P o;
		double r;

		cin>>o.real()>>o.imag()>>r;

		if(pol_contains_cir(p,o,r))
			cout<<"a\n";
		else if(cir_contains_pol(p,o,r)){
			cout<<"b\n";
		}
		else if(is_intersected_pol_cir(p,o,r)){
			cout<<"c\n";
		}
		else{
			cout<<"d\n";
		}
	}
}

Measured memory_bytes: 0
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = a[1::2]

ans = [sum(a)-sum(b)*2]

for i in range(1,n):
    ans.append((a[i-1]-ans[-1]//2)*2)

print(' '.join([str(s) for s in ans]))

Measured memory_bytes: 19516
import java.util.*;
public class Main{
    public static void main(String args[]) {
    Scanner obj = new Scanner(System.in);   
    int i;
    int n=obj.nextInt();
    String s=obj.next();
   	String str="";
   	char a[]=s.toCharArray();
    for(i=0;i<s.length();i++)
    {
        if(i==n)
        {
            str=str+"...";
            break;
        }
        else
        {
            str=str+s.charAt(i);
        }
    }
    System.out.print(str);
    
}
}

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

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

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 A,B,C;
    cin >> A >> B >> C;
    int ans=0;
    for(;;){
        if(A%2 or B%2 or C%2){
            cout << ans << endl;
            return;
        }
        if(A==B and B==C and C==A){
            cout << -1 << endl;
            return;
        }
        ++ans;
        i64 A_=A,B_=B,C_=C;
        A=(B_+C_)/2;
        B=(A_+C_)/2;
        C=(B_+A_)/2;
    }
}

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,t;
    cin >> n;
    int a[n],b[n];
    for(int i=0 ; i<n ; i++){
        cin >> a[i];
    }
    for(int i=0 ; i<n ; i++){
        b[a[i]-1] = i+1;
    }
    for(int i=0 ; i<n ; i++){
        cout << b[i] <<" ";
    }
        
    return 0;
}


Measured memory_bytes: 1536
//https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N, K;
const long long MAX_N = 10*10000;
const long long MAX_K = 100;
const long long MAX_COST = LONG_LONG_MAX;
vector<ll> cost(MAX_N);
vector<ll> H;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

void memo(ll n) {
  if (n == 0) cost[n]=0;
  else if (n == 1) cost[n]=abs(H[n]-H[n-1]);
  else {
    //printf("%lld -> %lld: %lld, %lld -> %lld: %lld\n", n-1, n, cost[n-1]+abs(H[n]-H[n-1]), n-2, n,cost[n-2]+abs(H[n]-H[n-2]));
    cost[n] = MAX_COST;
    rep1(i, min(n, K)) {
      //cout << n-i << " -> " << n << ": " << cost[n-i]+abs(H[n]-H[n-i]) << endl;
      cost[n] = min(cost[n-i]+abs(H[n]-H[n-i]), cost[n]);
    }
  }
}

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

  cin >> N >> K;
  H.resize(N);
  rep(i, N) cin >> H[i];
  rep(i, N) {
    memo(i);
  }
  //cout <<"----"<<endl;
  //rep(i,N) {
  //  cout << cost[i] << endl;
  //}
  //cout << "----" << endl;
  cout << cost[N-1] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define rep(a,b,c) for(int a=(int)b;a<(int)c;a++)
#define repk(a,b,c,k) for(int a=(int)b;a<(int)c;a+=(int)k)
#define comeback std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int,int>
#define ful(a) a.begin(),a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x,int n)
{
    if(n==0)
    return 1;
    else if(n%2==0)
    return em((x%mod*x%mod)%mod,n/2);
    else
    return (x%mod*em((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int dp[102][100009];
signed main()
{
	comeback
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif*/
        string s1,s2;
        int i,j,k,l,n,m;
        cin>>s1>>s2;
        n=s1.length();
        m=s2.length();
        int dp[n+2][m+2];
        string ans;
        memset(dp,-1,sizeof(dp));
        dp[0][0]=0;
        for(i=1;i<=n;i++){
        	for(j=1;j<=m;j++){
        		if(s1[i-1]==s2[j-1])
        			{
        				dp[i][j]=1+dp[i-1][j-1];
        			}
        		else{
        			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        		}
        	}
        }
       	i=n;
       	j=m;
       	while(i>0&&j>0){
       		if(s1[i-1]==s2[j-1])
       			{
       				ans+=s1[i-1];
       				i--;
       				j--;
       			}
       		else if(dp[i-1][j]>dp[i][j-1])
       			i--;
       		else
       			j--;
       	}
       	reverse(ans.begin(),ans.end());
       	cout<<ans;

}

Measured memory_bytes: 70784
///////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////
#define ll long long
#define ull unsigned lon long
///////////////////////////////////////////////////////////
int absolute(int n); double absolute(double n);
void input(vector<int>& vec);
void print(vector<int> vec); void print(vector<double> vec);
int sum(vector<int> vec); double sum(vector<double> vec);
void upsort(vector<int>& vec);
void downsort(vector<int>& vec);
int maxvec(vector<int> vec);
int minvec(vector<int> vec);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int main()
{
    int n;
    cin >> n;
    double pro;
    if(n%2==0){
        pro=0.5;
    }else{
        pro=(n+1.0)/(2.0*n);
    }
    cout << pro << endl;
    return 0;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int absolute(int n)
{
    if (n < 0) {
        return (-n);
    }
    return n;
}

double absolute(double n)
{
    if (n < 0) {
        return (-n);
    }
    return n;
}

void input(vector<int>& vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cin >> vec.at(i);
    }
}

void print(vector<int> vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

void print(vector<double> vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

int sum(vector<int> vec)
{
    int s = accumulate(vec.begin(), vec.end(), 0);
    return s;
}

double sum(vector<double> vec)
{
    double s = accumulate(vec.begin(), vec.end(), 0.0);
    return s;
}

void upsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end());
}

void downsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end(), greater<int>());
}

int maxvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = max(m, vec.at(i));
    }
    return m;
}

int minvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = min(m, vec.at(i));
    }
    return m;
}
///////////////////////////////////////////////////////////

Measured memory_bytes: 256
import bisect

N = int(input())
L = []
L.append(-int(input()))
c = 1

for i in range(N - 1):
	A = -int(input())
	x = bisect.bisect_right(L, A)
	if x == c:
		L.append(A)
		c += 1
	else:
		L[x] = A

print(c)

Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll x;
  cin >> x;
  ll ans = (x / 500) * 1000;
  x %= 500;
  ans += (x / 5) * 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int A,B,C,D;

signed main(){
	cin>>A>>B>>C>>D;
	while(true){
		C-=B;
		if(C<=0){
			cout<<"Yes"<<endl;
			return 0;
		}
		A-=D;
		if(A<=0){
			cout<<"No"<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

/* -- template -- */

int main(){
    string S;cin >> S;
    const int N = 13;
    const int MOD = 1e9 + 7;
    vector<ll> dp(N, 0);
    dp[0] = 1;
    int mul = 1;
    for(int i = S.size() - 1;i >= 0;--i){
        char s = S[i];
        vector<ll> nextdp(N, 0);
        if(s == '?'){
            for(int j = 0;j < 10;++j){
                for(int k = 0;k < N;++k){
                    nextdp[(j * mul + k) % N] += dp[k];
                    nextdp[(j * mul + k) % N] %= MOD;
                }
            }
        }else{
            int j = s - '0';
            for(int k = 0;k < N;++k){
                nextdp[(j * mul + k) % N] += dp[k];
                nextdp[(j * mul + k) % N] %= MOD;
            }
        }
        mul *= 10;
        mul %= N;
        dp = nextdp;
    }
    cout << dp[5];
}


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

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

    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    cout << ((K % 2) ? B - A : A - B) << endl;

    /*
    A B C A-B
    B+C A+C A+B (B+C)-(A+C) = B-A
    2*A+B+C A+2*B+C A+B+2*C A-B
    */

    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;

  vector<int> a(N);
  rep(i, N) cin >> a[i];

  int ans = 0;
  rep(i, N) ans += a[i] - 1;

  cout << ans << endl;
}

Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
N, K, Q = gets_i_list

winners = []
Q.times do
  winners.push gets_i
end

win_count = winners.group_by(&:itself).map{|k,v| [k, v.count] }.to_h

dpp win_count
1.upto(N) do |i|
  puts K + win_count[i].to_i - Q > 0 ? "Yes" : "No"
end

Measured memory_bytes: 22136