akhauriyash/Code-Regression huggingface dataset:
#if 0
AOJ??????accepted??????????????????
???????????????60??????????????§?????????

pair???????????????????????¨
????????¨?????????pair?????????????????????????????¨?????????????????????????????????
#endif

#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int P[10010];
void init(int N){//?????????
  for (int i=0; i<=N; ++i)
    P[i]=i;
}

int root(int a){//a???root????±???????
  if(P[a]==a)
    return a;
  return (P[a]=root(P[a]));
}

bool is_same_set(int a,int b){//??????set?????????
  return root(a)==root(b);
}

void unite(int a,int b){
  P[root(a)]=root(b);
}

int main(){
  int N;
  cin>>N;
  int A[N][N];
  
  for(int i=0; i<N;i++){//????????????
    for(int j=0;j<N;j++){
      cin>>A[j][i];
    }
  }

  int M = 0; // ????????????????????°
  int num=N*N;
  int cost[num];
  int src[num],dst[num];
  for (int r=0; r<N;r++){
    for (int c=0; c<r;c++){
      if (A[r][c] > -1) {
	cost[M] = A[r][c];
	src[M] = r;
	dst[M] = c;
	M += 1;
      }
    }
  }

  pair<int,int> edge[100000];//?§??????????????????¢????????????
  for(int i=0; i<M;i++){
    edge[i]=make_pair(cost[i],i);
  }
  sort(edge,edge+M);

  int edges[M][3];
  for(int i=0; i<M;i++){//?????????????????????
    edges[i][0]=edge[i].first;
    edges[i][1]=src[edge[i].second];
    edges[i][2]=dst[edge[i].second];
  }
  /*
  check!
  for(int i=0; i<M;i++){
    cout<<"news cost="<<edges[i][0]<<" ,"<<edges[i][1]<<"-"<<edges[i][2]<<endl;
  }
  */




  init(N);
  int sum=0;
  for(int i=0; i<M;i++){//???????????????????????????
    if(is_same_set(edges[i][1],edges[i][2])==0){
      unite(edges[i][1],edges[i][2]);
      sum=sum+edges[i][0];
    }
  }
    cout<<sum<<endl;
}

Measured memory_bytes: 3920
N=int(input())
m=list(map(int,input().split()))
ans=0
rainbow=0
table=[0,0,0,0,0,0,0,0]
for i in m:
  if i>3199:
    rainbow+=1
  else:
    if table[i//400]==0:
      ans=ans+1
      table[i//400]=1
print(max(1,sum(table)),sum(table)+rainbow)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};


int main(){
    LL n,k;cin >> n >> k;
    vector<LL> v;
    vector<LL> x;
    LL now=1;
    while(now<=n){
        LL l=now,r=n+1,t=n/l;
        while(r-l>1){
            LL m=(r+l)/2;
            if(n/m==t){
                l=m;
            }
            else{
                r=m;
            }
        }
        //cout << now << " " << r << endl;
        v.pb(r-now);
        x.pb(t);
        now=r;
    }
    vector<vector<LL>> dp(k+1,vector<LL> (v.size()+1,0));
    for (int i = 0; i < v.size(); i++) {
        dp[0][i] = v[i];
    }

    for (int i = 0; i < k-1; i++) {
        vector<LL> S(v.size()+1,0);
        for (int j = 0; j < v.size(); j++) {
            S[j+1] = (dp[i][j] + S[j])%mod;
        }
        for (int j = 0; j < v.size(); j++) {
            dp[i+1][j] = (S[v.size()-j] * v[j])%mod;
        }
    }
    LL ans = 0;
    for (int i = 0; i < v.size(); i++) {
        ans = (ans + dp[k-1][i])%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 52084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = s; i < b; i+=d)
#define lpsb(i, s, b) for(size_t i = s; i < b; i++)
#define lpn(i, n) for(size_t i = 0; i < n; i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int N;
    cin >> N;
    auto A = vc(int, N);
    fa(i, A) cin >> i;
    auto l = vc(int, N);
    auto r = vc(int, N);
    l[0] = r[0] = 0;
    lpn(i, N)
    {
        l[i+1] = max(l[i], A[i]);
        r[i+1] = max(r[i], A[N - i - 1]);
    }
    lpn(i, N) cout << max(l[i], r[N - i - 1]) << endl;
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int ok(string s, long long k){
  string r = "";
  rep(i,s.size()){
    if( i < k && i >= s.size() - k){
      r += s[i];
    }
  }
  if(s == ""){
    return true;
  }
  rep(i,r.size()){
    if(r[i] != r[0])return false;
  }
  return true;
}

int main(void){
  string s;
  cin>>s;
  long long  lb = 1, ub = s.size() + 1, mid;
  while(ub - lb > 1){
    mid = (ub + lb) / 2;
    if(ok(s, mid)){
      lb = mid;
    } else {
      ub = mid;
    }
  }
  cout<<lb<<endl;
}


Measured memory_bytes: 740
#include<iostream>

int main(){

    int a, b, c;
    std::cin >> a >> b >> c;

    if (((a * b * c) == 175) and ((a + b + c) == 17))
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        //int n = stdIn.nextInt();
        //int c = stdIn.nextInt();
        //int k = stdIn.nextInt();
        String s = stdIn.next();
        char c[] = s.toCharArray();
        //boolean heisei = true;
        
        for(int i = 0; i < s.length(); i++){
            if(c[i] == '1'){
                System.out.print(9);
            }else{
                System.out.print(1);
            }
        }        
        
        System.out.println();
        //System.out.print();
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int k;
    cin >> k;
    cin >> s;
    if(s.size() <= k){
        cout << s;
    }else{
        cout << s.substr(0, k) << "...";
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void a_atcoder_penki(void) {
	int a[3];
	for (int i = 0; i < 3; i++) cin >> a[i];
	int cnt = 3;
	sort(a, a + 3);

	for (int i = 0; i < 2; i++) {
		if (a[i] == a[i + 1]) cnt--;
	}

	cout << cnt << endl;

}

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

Measured memory_bytes: 3532
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
	int key;
	Node *next,*prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur=nil->next;
	while(cur!=nil && cur->key!=key){
		cur=cur->next;
	}
	return cur;
}

void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
}

void printList(){
	Node *cur=nil->next;
	int isf=0;
	while(1){
		if(cur==nil)break;
		if(isf++>0)printf(" ");
		printf("%d",cur->key);
		cur=cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if(t==nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x=(Node *)malloc(sizeof(Node));
	x->key=key;
	
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

int main(){
	int key,n,i;
	int size=0;
	char com[20];
	int np=0,nd=0;
	scanf("%d",&n);
	init();
	for(i=0;i<n;i++){
		scanf("%s%d",com,&key);
		if(com[0]=='i'){insert(key); np++; size++;}
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F')deleteFirst();
				else if(com[6]=='L')deleteLast();
			}else{
				deleteKey(key);nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}

Measured memory_bytes: 33984
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

def f(x)
  ans=x
  if ((x+1)%2).zero?
    ans=0
  end
  x=(x+1)/2
  if (x%2).zero?
    return 0^ans
  else
    return 1^ans
  end
end
a,b=get_i

puts f(a-1)^f(b)

Measured memory_bytes: 1788
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    char[] t = sc.next().toCharArray();
    for (int i = 0; i < 3; i++) {
      if (s[i] != t[2-i]) {
        System.out.println("NO");
        return;
      }
    }
    System.out.println("YES");
  }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
ll n,w,h,k;
bool bomb[55][55];

inline int query(int a,int b,int c,int d){
	cout << "? " <<  a << " " << b << " " << c-1 << " " << d-1 << endl << flush;
	int ret;
	cin >> ret;
	return ret;
}

inline int rec(int a,int b,int c,int d,int rest){
	if(c<=a or d<=b) return 0;
	if(rest==0) return 0;
	//cout << a << " " << b << " " << c << " " << d << endl;
	
	const int area=(c-a)*(d-b);
	if(area<=rest){
		int res=query(a,b,c,d);
		if(res==0) return 0;
		if(res==area){
			rep(y,a,c)rep(x,b,d) bomb[y][x]=true;
			return area;
		}
		chmin(rest,res);
	}

	const int ym=(a+c)/2,xm=(b+d)/2;
	rest-=rec(a,b,ym,xm,rest);
	rest-=rec(ym,b,c,xm,rest);
	rest-=rec(a,xm,ym,d,rest);
	rest-=rec(ym,xm,c,d,rest);
	return rest;
}

int main(void){
	cin >> h >> w >> n >> k;
	int rest=n;
	rep(y,h)rep(x,w) rest-=rec(y,x,y+1,x+1,rest);
	
	ll ans=0LL,cur=1LL;
	rep(i,h)rep(j,w){
		if(bomb[i][j]) ans=(ans+cur)%k;
		cur=(2LL*cur)%k;
	}

	cout << "! " << ans << endl  << flush;
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e3 + 3;

int A[N],B[N],n,k,q,i,j,ans;

int f(int b, int e){
    int i,las,t,x;
    las = t = x = 0;
    for(i=1;i<=n+1;i++){
        if(A[i] < b) { x += max(0, min(t , i-las-k)); las = i; t = 0; }
        else if(A[i] <= e) t++;
    }
    return x;
}

int main(){
    cin >> n >> k >> q;
    for(i=1;i<=n;i++) { cin >> A[i]; B[i] = A[i]; }
    sort(B+1 , B+n+1);
    ans = mod;
    for(i=q,j=1; i<=n; i++){
        for(; j <= i && f(B[j],B[i]) >= q ; j++)
            ans = min(ans , B[i]-B[j]);
    }

    if(ans == mod) assert(0);
    cout << ans << endl;
    return 0;
}   

Measured memory_bytes: 256
N = gets.to_i
a = gets.split(" ").map(&:to_i)
sum = a.inject(:+)
counts = Array.new(10**5 + 1, 0)
a.each do |x|
    counts[x] += 1
end

Q = gets.to_i
Q.times do |i|
    b, c = gets.split(" ").map(&:to_i)
    sum = sum + counts[b] * (c - b) 
    puts sum
    counts[c] += counts[b]
    counts[b] = 0
end


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

typedef long long int ll;
ll n;
string s;

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

    ll r = 0, g = 0, b = 0;
    for(ll i = 0; i < s.length(); ++i) {
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;
    }

    ll res = r * g * b;
    for(ll i = 1; i <= n/2; ++i) {
        for(ll j = 0; j + 2 * i < n; ++j) {
            if(s[j] != s[j + i] && s[j + i] != s[j + 2 * i] && s[j] != s[j + 2 * i]) res--;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se seoncd
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
int a[N],n,m,v,p;
ll s[N];

int chk(int x){
	int rem=v-x-p+1,t=n-p+1;
	return a[t]<=a[x]+m&&(ll)(t-x)*(a[x]+m)-(s[t]-s[x])>=(ll)rem*m;
}

int main(){
	read(n),read(m);
	read(v),read(p);
	rep(i,1,n) read(a[i]);
	sort(a+1,a+n+1);
	rep(i,1,n) s[i]=s[i-1]+a[i];
	int l=1,r=n-p+1,mid;
	while(l<r){
		mid=(l+r)>>1;
		if(chk(mid)) r=mid;
		else l=mid+1;
	}
	cout<<n-l+1<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int a,b;
int L1,R1,L2,R2;
int main()
{
    scanf("%d%d",&a,&b);
    L1=round(a*12.5);
    R1=round((a+1)*12.5);
    L2=round(b*10);
    R2=round((b+1)*10);
    if(R1<=L2||R2<=L1)
    printf("-1\n");
    else
    {
        printf("%d\n",max(L2,L1));
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	/*string?????§?°?????????§????????????????????????*/
	int n;
	cin >> n;
	int a = 0,b = 0;
	REP(i,n){
		string sa,sb;
		cin >> sa >> sb;
		if(sa==sb){
			a++; b++;
		}else if(sa < sb){
			b+=3;
		}else if(sa > sb){
			a+=3;
		}
	}
	cout << a << " " << b << endl;
}

Measured memory_bytes: 1212
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int a, b;
	cin >> a >> b;
	if (a * b % 2 == 0) cout << "Even" << endl;
	else cout << "Odd" << endl;
}

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


int main() {
  int N, M;
  cin >> N >> M;

  vector<int> s(M), c(M);
  rep(i, M) cin >> s[i] >> c[i];

  int n = N;
  int max_num = 1;
  while (n > 0) {
    max_num *= 10;
    n--;
  }

  int min_num = -1;
  bool ans;
  if (N == 1) {
    for (int num = 0; num < 10; num++) {
      ans  = true;
      rep(j, M) {
        if (s[j] != 1 || c[j] != num) {
          ans = false;
          break;
        }
      }
      if (ans) {
        min_num = num;
        break;
      }
    }
  } else {
    for (int num = max_num / 10; num < max_num; num++) {
      string S = to_string(num);
      ans  = true;
      rep(j, M) {
        // cout << (int)S[s[j] - 1] - '0' << endl;
        if (s[j] == 1 && c[j] == 0) {
          ans = false;
          break;
        }
        if (c[j] != (int)S[s[j] - 1] - '0') {
          ans = false;
          break;
        }
      }
      if (ans) {
        min_num = num;
        break;
      }
    }
  }
 
  cout << min_num << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
const ll mod=1000000007ll;
int n, a[100005];
int used[100005];
ll fact[100005], dfact[100005];
ll pw(ll xx, int val=mod-2) {
	if (!val)	return 1ll;
	if (val&1)
		return (xx*pw(xx, val-1))%mod;
	ll haha=pw(xx, val>>1);
	return (haha*haha)%mod;
}
void init() {
	fact[0]=1ll;
	dfact[0]=pw(fact[0]);
	for (int i=1; i<=100001; i++) {
		fact[i]=((ll)fact[i-1]*(ll)i)%mod;
		dfact[i]=pw(fact[i]);
	}
}
ll C(int i, int j) {
	if (i<j) return 0ll;
	ll ret;
	ret=((((ll)fact[i]*(ll)dfact[j])%mod)*(ll)dfact[i-j])%mod;
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int x1, x2;
	cin>>n;
	init();
	memset(used, -1, sizeof(used));
	for (int i=0; i<n+1; i++) {
		cin>>a[i];
		if (used[a[i]]!=-1) {
			x1=used[a[i]]+1;
			x2=i+1;
		}
		used[a[i]]=i;
	}
	for (int i=1; i<=n+1; i++) {
		if (i==1)
			cout<<n<<endl;
		else if (i==n+1)
			cout<<1<<endl;
		else {
			ll tmp=C(n+1, i);
			tmp-=C(x1+n-x2, i-1);
			tmp=(tmp+mod)%mod;
			cout<<tmp<<endl;
		}
	}
	return 0;
}

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


void solve(){
        if(n%2==0) {
                ans=n/2;
        }else{
                ans=n/2+1;
        }
        cout<<ans<<endl;
}

int main(){
        cin>>n;

        solve();
        return 0;
}


Measured memory_bytes: 256
// 最大公約数
#include <stdio.h>

int gcd(int x, int y) {
    int tmp;

    if (x < y) {
        tmp = x;
        x = y;
        y = tmp;
    }

    if (x % y != 0) return gcd(y, x%y);
    else return y;

    return 0;
}

int main() {
    int x, y;

    scanf("%d %d", &x, &y);
    printf("%d\n", gcd(x, y));

    return 0;
}


Measured memory_bytes: 1996
#include<bits/stdc++.h>
#define FO(i, a, b) for (int i = a; i <= b; i++)
#define FE(i, a, b) for (int i = a; i < b; i++)
#define R(i) i = read()
using namespace std;

typedef long long ll;

const int N = 100005;
const int MOD = 1e9 + 7;

int read() {
	int x = 0; char c = getchar();
	while((c != '-') && (c < 48 || c > 57)) c = getchar();
	if(c == '-') {c = getchar(); while(c >= 48 && c <= 57) x = x * 10 - c + 48, c = getchar();}
	else while(c >= 48 && c <= 57) x = x * 10 + c - 48, c = getchar();
	return x; 
}

struct Point {
	int x, y, v;
}P[N];

int fy[N], fx[N], cy[N], cx[N], min1[N], min2[N];

inline bool cmp_x(Point x, Point y) {
	return x.x < y.x;
}

inline bool cmp_y(Point x, Point y) {
	return x.y < y.y;
}

int pd;

inline int find_y(int x) {
	if(fy[x] == x) return x;
	int tmp = fy[x];
	fy[x] = find_y(tmp);
	cy[x] += cy[tmp];
	return fy[x];
}

inline int find_x(int x) {
	if(fx[x] == x) return x;
	int tmp = fx[x];
	fx[x] = find_x(fx[x]);
	cx[x] += cx[tmp];
	return fx[x];
}

inline void Link_y(int a, int b, int c) {
	int fa = find_y(a), fb = find_y(b);
	if(fa == fb) {
		if(cy[a] - cy[b] != c) 
			pd= 1;
	}
	else {
		fy[fa] = fb;
		cy[fa] = c + cy[b] - cy[a];
	}
}

inline void Link_x(int a, int b, int c) {
	int fa = find_x(a), fb = find_x(b);
	if(fa == fb) {
		if(cx[a] - cx[b] != c)
			pd = 1;
	}
	else {
		fx[fa] = fb;
		cx[fa] = c + cx[b] - cx[a];
	}
}

int T, R, C, n;

int main() {
//	freopen("then.in", "r", stdin);
//	freopen("then.out", "w", stdout);
//	R(T);
	T = 1;
	while(T--) {
		pd = 0;
		R(R), R(C);
		memset(cx, 0, sizeof(cx));
		memset(cy, 0, sizeof(cy));
		FO(i, 1, R) fx[i] = i;
		FO(i, 1, C) fy[i] = i;
		R(n);
		FO(i, 1, n)
			R(P[i].x), R(P[i].y), R(P[i].v), pd = P[i].v < 0 ? 1 : 0;
		sort(P + 1, P + n + 1, cmp_x);
		FE(i, 1, n)
			if(P[i].x == P[i + 1].x)
				Link_y(P[i].y, P[i + 1].y, P[i + 1].v - P[i].v);
		sort(P + 1, P + n + 1, cmp_y);
		FE(i, 1, n)
			if(P[i].y == P[i + 1].y)
				Link_x(P[i].x, P[i + 1].x, P[i + 1].v - P[i].v);
		if(pd) {
			printf("No\n");
			continue;
		}
		memset(min1, 127/2, sizeof(min1));
		memset(min2, 127/2, sizeof(min2));
		FO(i, 1, n) {
			int t = P[i].x;
			int f = find_x(t);
			min1[f] = min(min1[f], P[i].v + cx[t]);
		}
		FO(i, 1, R) {
			int f = find_x(i);
			min2[i] = min(min2[i], min1[f] - cx[i]);
		}
		FO(i, 1, R) {
			if(min2[i] < 0)
				pd = 1;
		}
		if(pd) printf("No\n");
		else printf("Yes\n");
	}
}

Measured memory_bytes: 3840
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

bool chk(int i, int j, vector<string> &s) {
	if(i < 0 || j < 0 || s.size()-1 < i || s[i].size()-1 < j)
		return false;
	if(s[i][j] == '*') {
		s[i][j] = ' ';
		return true;
	}
	return false;
}

int dfs(int i, int j, vector<string> &s, int x, int y) {
	if(chk(i, j+1, s))
		return dfs(i, j+1, s, x+1, y);

	if(chk(i+1, j+1, s))
		return dfs(i+1, j+1, s, x, y+1);
	if(chk(i+1, j, s))
		return dfs(i+1, j, s, x, y+1);
	if(chk(i+1, j-1, s))
		return dfs(i+1, j-1, s, x, y+1);

	if(chk(i, j-1, s))
		return dfs(i, j-1, s, x+1, y);

	if(chk(i-1, j-1, s))
		return dfs(i-1, j-1, s, x, y);
	if(chk(i-1, j, s))
		return dfs(i-1, j, s, x, y);
	if(chk(i-1, j+1, s))
		return dfs(i-1, j+1, s, x, y);

	return x * y / 2;
}

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

	int n;
	bool flg = false;
	while(cin >> n, n) {
		if(flg)
			cout << "----------" << endl;
		flg = true;
		cin.ignore();
		vector<string> s(n);
		REP(i, n)
			getline(cin, s[i]);

		map<int, int> m;
		REP(i, n) {
			REP(j, s[i].size()) {
				if(s[i][j] == '*') {
					int res = dfs(i, j, s, 2, 1);
					m[res] = m[res] + 1;
				}
			}
		}

		for(auto i: m)
			cout << i.first << ' ' << i.second << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
n,m = map(int,input().split())
kosu = [1 for _ in range(n)]
aka = [0 for _ in range(n)]
aka[0] += 1
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  if aka[a]==1:
    #論理和
    aka[b] |= 1
    if kosu[a]<2:
      aka[a] -=1
  kosu[a] -=1
  kosu[b] += 1
 # print("kosu",kosu)
  #print("aka",aka)
print(aka.count(1))

Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = (1 << 29);
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  string s, t;
  cin >> s >> t;

  for (int i = s.size() - t.size(); i >= 0; i--) {
    bool flag = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i+j] != t[j] && s[i+j] != '?') {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int j = 0; j < t.size(); j++) {
        s[i+j] = t[j];
      }
      for (int j = 0; j < s.size(); j++) {
        if (s[j] == '?') {
          s[j] = 'a';
        }
      }
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;

  return 0;
}


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

#define N 500000

int n;

struct Tree{
	int key;
	struct Tree *parent,*left,*right;
};
struct Tree *NILL,*root;

void insert(struct Tree *z){
	struct Tree *x,*y;
	y = NILL;
	x = root;
	while(x != NILL){
		y = x;
		if(z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;
	if(y == NILL)  {
		root = z;
	}
	else if(z->key < y->key) y->left = z;
	else y->right = z;
}

void mid(struct Tree *root){
	if(root == NILL) return;
	mid(root->left);
	printf(" %d", root->key);
	mid(root->right);
}

void inorder(struct Tree *root){
	if(root == NILL) return;
	printf(" %d",root->key);
	inorder(root->left);
	inorder(root->right);
}

void print(){
	struct Tree *r;
	r = root;
	mid(r);
	printf("\n");
	inorder(r);
	printf("\n");
}

int main(){
	struct Tree *t;
	scanf("%d",&n);
	int i;
	int key;
	char instruct[7];
	for(i=0;i<n;i++){
		scanf("%s",instruct);
		if(!strcmp(instruct,"insert")){
			scanf("%d",&key);
			t = (struct Tree *)malloc(sizeof(struct Tree));
			t->key = key;
			t->right = NILL;
			t->left = NILL;
			//T[i]->key  = key;
			insert(t);
		}
		else print();
	}
	return 0;
}	

Measured memory_bytes: 26104
#include <bits/stdc++.h>
#define int long long 
using namespace std;
int n , m;
const int N = 1e5 + 10;
int num[N];
int dis;
inline int ksm(int x,int y){
	int tmp=1;
	while(y){
		if (y&1)
			tmp=x*tmp;
		y>>=1;
		x=x*x;
	}
	return tmp;
}
priority_queue<int>qu;
signed main(void) {
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>num[i];
		qu.push(num[i]);
	}
	if ( n == 1 ) {
		if ( log2 ( num[1] ) + 1 <= m ) 
			puts ( "0");
		else
			printf ( "%lld\n" , num[1] / ksm ( 2 , m ) );
		
		return 0;
	}
	while(m){
		int now=qu.top();
		if ( now == 0 ) 
			break;
		qu.pop();
		int cost=0;
		if ( qu.top() == 0 ) {
			if ( log2 ( now ) + 1 <= m )
				qu.push(0);
			else 
				qu.push(now/ksm(2,m));
			break; 
		}
		while(now/ksm(2,cost)-now/ksm(2,cost+1)>=qu.top() - qu.top()/2&&cost+1<=m)
			cost++;
		m-=cost;
		qu.push(now/ksm(2,cost));
	}
	while(!qu.empty()){
		dis+=qu.top();
		qu.pop();
	}
	printf("%lld\n",dis);
	return 0;
}

Measured memory_bytes: 1912
n = int(input())
W = []
Hantei = True

for i in range(n):
    W.append(input())

for i in range(n):
    if W.count(W[i]) > 1:
        Hantei = False
        break

for i in range(n-1):
    if W[i][-1] != W[i+1][0]:
        Hantei = False

if Hantei:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import java.util.*;

class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int n = sc.nextInt();

        int s = 0;
        int k= 0;
            for(int i=100;i>=0;i--){
                if((A%i==0)&&(B%i==0)){
                    s=i;     
                    k++;        
                    if(k==n){   
                        break;
                    }
                }
            }
            System.out.println(s); 
     }
}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n,m;
  cin >> n >> m;
  vvi path(n+1,vi());
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    path.at(a).eb(b);
    path.at(b).eb(a);
  }
  vi ans(n+1,0);
  ans.at(1)=1000000000;

  queue<int> que;
  que.push(1);
  while(que.size()) {
    int x = que.front();que.pop();
    rep(i,path.at(x).size()) {
      int y = path.at(x).at(i);
      if(!ans.at(y))que.push(y);
      if(!ans.at(y))ans.at(y) = x;
    }

  }
  cout << "Yes" << endl;
  srep(i,2,n+1) cout << ans.at(i) << endl;

  return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    ll a;
    string b;
    cin>>a>>b;
  
  	int b100=0,kake=100;
	rep(i,b.length()){
      if(b[i]=='.')continue;
      b100+=kake*(b[i]-'0');
      kake/=10;
    }

    ll ans=a*b100;
    ans/=100;

    cout<<ans<<"\n";

    return 0;

}


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

int main(){ 
	int a,b;
	cin>>a>>b;
	if(a+b>=10){
		cout<<"error"<<endl;
	}
	else{
		cout<<a+b<<endl;
	}
}

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

typedef long long LL;

LL f[87];
int n;

int main() {
	f[0] = 2, f[1] = 1;
	cin >> n;
	for(int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2];
	cout << f[n];
	return 0;
} 

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

int main(){
    using namespace std;
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    puts(s[0] == s[1] && s[1] != s[2] && s[2] == s[3] ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    ans += min(A,K);
    K-=A;
    K-=B;
    if(K>0){
        ans-=min(C,K);
    }
    cout << ans << endl;
}


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


int main(){

	string s[1002];
	int k=0,size_max=0,s_max=0,count_max=0,count_max_number;
	int scount[1002]={0};
	
	
	
	while (cin>>s[k]){
		k++;
	}
	for (int i=0; i<k; i++) {
		for (int j=i+1; j<k; j++) {
			if (s[i]==s[j]) {
				scount[i]++;
			}
		}
	}
	
	for (int i=0; i<k; i++) {
		if (count_max<scount[i]) {
			count_max=scount[i];
			count_max_number=i;
		}
		if (size_max<s[i].size()) {
			size_max=s[i].size();
			s_max=i;
		}
	}
	
	cout << s[count_max_number] << ' '<< s[s_max] << endl;
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long
#define maxn 2100
using namespace std;
int cnt[maxn];
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	reverse(s.begin(),s.end());
	int ans = 0 , sum = 0;
	int fix = 1;
	cnt[0] = 1;
	for(char c : s) {
		int val = c - '0';
		sum = (val * fix + sum) % 2019;
		ans += cnt[sum];
		cnt[sum]++;
		fix = (fix * 10) % 2019;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3796
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (n, m, d) = ReadTuple<double,double,double>();
        if(d!=0)
            WriteLine((n-d)*2*Pow(n,-2)*(m-1));
        else
            WriteLine(n*Pow(n,-2)*(m-1));
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 27932
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

constexpr int MOD = 1e9+7;
constexpr int M = 61;

using ll = long long;


int main()
{
    int N;
    std::cin >> N;

    std::vector<int> zero(M), one(M);
    for (int i = 0; i < N; i++)
    {
        uint64_t a;
        std::cin >> a;
        for (int j = 0; j < M; j++)
        {
            if (((uint64_t)1)<<j & a)
                ++one[j];
            else
                ++zero[j];
        }
    }
    
    int ans = 0;
    for (int i = M - 1; i >= 0; --i)
    {
        ans = (ans * 2 + (ll)one[i] * zero[i]) % MOD;
    }

    std::cout << ans << std::endl;
}

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

#define mx 10000005
#define ll long long

int ar[mx];
char ch[mx];

int n,m,k,ii;

void solve()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j+=i)ar[j]++;
    }
    ll re=0;
    for(int i=1;i<=n;i++)re+=1LL*i*ar[i];
    printf("%lld\n",re);
}

int main()
{
   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   int t=1;
   //scanf("%d",&t);
   while(t--)solve();
   return 0;
}


Measured memory_bytes: 42788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int l = sc.nextInt();

		double part = (double)l / (double)3.0;
		
		double box = part * part * part;
		
		
		log( box );
		sc.close();
		
	}

	static void log(double d) {
		System.out.printf("%.12f\n",d);
	}

}


Measured memory_bytes: 22356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			double[] A = new double[6];
			for(int i = 0; i < 6; i++) {
				A[i] = Double.parseDouble(sc.next());
			}

			double[] B = A.clone();

			double a = A[3];
			double b = A[0];
			for(int j = 0; j < 3; j++) {
				B[j] *= a;
				B[j + 3] *= b;
			}

			double y = (B[5] - B[2]) / (B[4] - B[1]);
			double x = (A[2] - A[1] * y) / A[0];

			if(x == 0) {
				x = 0;
			}
			if(y == 0) {
				y = 0;
			}

			System.out.printf("%.3f %.3f\n", x, y);
		}
		sc.close();
	}

}



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

const int MAXN=3005;
const int MOD=1e9+7;

int n,m;
int d[MAXN][MAXN],right[MAXN],sum[MAXN];
char s[MAXN];

int main(){
    scanf("%d%d%s",&n,&m,s+1);
    for(int i=1;i<=n;i++) sum[i]=s[i]-'0';
    for(int i=1;i<=n+1;i++) sum[i]+=sum[i-1];
    for(int i=1;i<=n+1;i++) right[i]=i;
    for(int i=1;i<=m;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        right[l]=max(right[l],r);
    }
    for(int i=1;i<=n;i++)
        right[i]=max(right[i],right[i-1]);
    d[1][sum[right[1]]]=1;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=n;j++){
            if(d[i][j]){
                int l=right[i]+1,r=right[i+1];
                int x=j,y=right[i]-i+1-j;
                if(x) (d[i+1][j-1+sum[r]-sum[l-1]]+=d[i][j])%=MOD;
                if(y) (d[i+1][j+sum[r]-sum[l-1]]+=d[i][j])%=MOD;
            }
        }
    printf("%d\n",(d[n+1][0]+MOD)%MOD);
}


Measured memory_bytes: 33920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
struct state
{
	int a,b,c;
};

vector<state>v;
ll m[100009][5];


ll fun(int i, int j)
{
	if(i==n)
	return 0;
	
	if(j!=-1 && m[i][j]!=-1)
	  return m[i][j];
	  
	  ll ans=0;
	  
	  if(j!=1)
	   ans=fun(i+1, 1)+v[i].a;
	   
	   if(j!=2)
	     ans=max(ans, fun(i+1,2)+v[i].b);
	     
	     if(j!=3)
	       ans=max(ans,fun(i+1,3)+v[i].c);
	       
	       
	       return m[i][j]=ans;
	       
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	v.resize(n);
	memset(m, -1, sizeof(m));
	for(int i=0;i<n;i++)
	{
		cin>>v[i].a>>v[i].b>>v[i].c;
	}
	
	ll ans=fun(0,4);
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
int main(){
   string b;
   cin>>b;
   if(b=="A"){
       cout<<"T"<<endl;
   }else if(b=="C"){
       cout<<"G"<<endl;
   }else if(b=="T"){
       cout<<"A"<<endl;
   }else{
       cout<<"C"<<endl;
   }
}

Measured memory_bytes: 3576
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string a;
	while(cin >> a) {
		reverse(ALL(a));
		int n = SZ(a);
		vector<vector<int>> dp(n+1,vector<int>(26,1));
		vector<vector<P>> pre(n+1,vector<P>(26,P(-1,-1)));
		vector<int> pos(26,-1);
		REP(i,n){
			DEBUG(i);
			pos[a[i]-'a'] = i+1;
			dpite(ALL(pos));
			REP(j,26){
				if(pos[j] == -1) {
					dp[i+1][j] = 1;
				} else {
					int mi = INF;
					P t = P(-1,-1);
					REP(k,26) {
						if(chmin(mi,dp[pos[j]-1][k])) {
							t = {pos[j]-1,k};
						}
					}
					dp[i+1][j] = mi+1;
					pre[i+1][j] = t;
				}
			}
		}
		string ans = "";
		int mi = INF;
		P p = P(-1,-1);
		REP(k,26) {
			if(chmin(mi,dp[n][k])) {
				p = {n,k};
			}
		}
		// ans += 'a'+p.S;
		REP(i,n+1) dpite(ALL(dp[i]));
		REP(i,n+1) dpite(ALL(pre[i]));
		while(p.F != -1) {
			DEBUG(p);
			ans += 'a'+p.S;
			p = pre[p.F][p.S];
		}
		// reverse(ALL(ans));
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 75540
from collections import deque
string = input()
s = deque(string)
iteration = int(input())
reverse = 1

for c in range(0,iteration):
    sousa = input().split()
    #操作１のとき
    if sousa[0] == "1":
        reverse = reverse*(-1)
    #操作２を行うとき
    elif sousa[1] == "1":
        if reverse == 1:
            s.appendleft(sousa[2])
        else:
            s.append(sousa[2])
    else:
        if reverse == 1:
            s.append(sousa[2])
        else:
            s.appendleft(sousa[2])

result = "".join(s)
if reverse == -1:
    result = result[::-1]


print(result)

Measured memory_bytes: 8820
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A , B , C , D ;
  cin >> A >> B >> C >> D ;

  int X=(A+D-1)/D;
  int Y=(C+B-1)/B;
  if (X>=Y){
    cout << "Yes" <<endl;
  }
    else {
      cout << "No" <<endl;
    }
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  int answer = 0;
  for(int i=0;i<n;i++){
    int h;
    cin >> h;
    if(h >= k) answer++;
  }
  cout << answer << endl;
  return 0;
}

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

using namespace std;
 
int main(){
 
  int D,X;
  cin >> D >> X;
  
  int L[D];
  for(int i = 0; i < D; i++) cin >> L[i];
  
  int cnt = 1;
  int p = 0;
  for( int i = 0; i < D; i++){
    p += L[i];
    if( p <= X ) cnt++;
    else{
      cout << cnt;
      return 0;
    }
  }
  cout << cnt;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> l(2*n);
  for(int i=0;i<2*n;i++){
    cin>>l.at(i);
  }
  int sum=0;
  sort(l.begin(),l.end());
  for(int i=0;i<2*n;i++){
    if(i%2==0)sum+=l.at(i);
  }
  cout<<sum<<endl;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() / 2; i++)
  {
    if (s.at(i) != s.at(s.size() - 1 - i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
require 'pp'
# sumの追加
class Array
  define_method(:sum){self.inject(:+)} unless method_defined?(:sum)
end

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

N, M = gets_i_list
x_list = gets_i_list.sort

if N >= M
  puts "0"
  exit
end

if M == 1
  puts x_list.max - x_list.min
  exit
end

distances = x_list.map.with_index do |x, i|
  (x_list[i+1] - x).abs unless x_list[i+1].nil?
end.compact.sort.reverse
puts distances.slice(N-1, M - N + 1).sum



Measured memory_bytes: 12904
import java.util.Scanner;

public class Main{
	static int[] fact = new int[10];
	static int[] sum = new int[10];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String	str = sc.next();
		long[] num = new long[str.length()];

		for(int i=0; i<str.length(); i++){
			num[i] = str.charAt(i) - '0';
		}

		Factrial();

		int bfr = 0, aft = str.length()-1;
		long ans = 0;
		while(aft>-1){
			for(int i=aft; i>=0; i--){
				ans += num[bfr]*fact[(i>0)?i-1:0]*fact[bfr];
				num[bfr] *= 10;
			}
			bfr++;
			aft--;
		}

		System.out.println(ans);
	}

	public static void Factrial(){
		fact[0] = 1;
		sum[0] = fact[0];
		for(int i=1; i<10; i++){
			fact[i] = fact[i-1]*2;
			sum[i] = sum[i-1]+fact[i];
		}
	}
}

Measured memory_bytes: 9424
use std::io;
use std::cmp;
use std::cmp::Ordering;
use std::collections::HashSet;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
struct State {
    cost     : i32,
    node     : i32,
    vismask  : i32
}

impl Ord for State {
    fn cmp(&self, other: &State) -> Ordering {
        other.cost.cmp(&self.cost)
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other : &State) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}


fn main() {
    
    let n = read_t_in_line::<i32>()[0];
    let mut h = HashSet::new();
    for _ in 0..n {
        let a = read_t_in_line::<i32>()[0];
        if h.contains(&a) {
            h.remove(&a);
        }
        else{
            h.insert(a);
        }
    }
    
    println!("{}", h.len());

}


Measured memory_bytes: 6396