akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> s;
       if(s[0]=='9' || s[1]=='9'){
           Cout("Yes");
       }
       else{
           Cout("No");
       }
return 0;
}


Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	string s;
	cin>>s;
	int y = stoi(s.substr(0,4));
	int m = stoi(s.substr(5,2));
	int d = stoi(s.substr(8,2));
	if(y<2019||(y==2019&&m<=4)||(y==2019&&m==4&&d<=30)) {
		cout<<"Heisei";
	}else cout<<"TBD";
			
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
N=int(input())
X,Y=1,1
for i in range(N):
  T,A=map(int,input().split())
  k=max((X+T-1)//T,(Y+A-1)//A)
  X,Y=k*T,k*A
print(X+Y)

Measured memory_bytes: 3060
import static java.lang.Math.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main{
	static String []args;
	static Main app=new Main();
	static Scanner sc=new Scanner(System.in);
	List<Double> List=new ArrayList<Double>();
	void sol(double temp){
		List.add(temp);
	}
	
	void SystemOut(){
		Collections.sort(List);
		double ans=abs(List.get(0)-List.get(List.size()-1));
		System.out.println(ans);
	}

	public static void main(String[] args) {
		while(sc.hasNextDouble())app.sol(sc.nextDouble());
		app.SystemOut();
	}

}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll s(n+1);
  rep(i,n){
    ll a; cin>>a;
    s[i+1]=s[i]+a;
  }
  
  map<ll,ll> m;
  rep(i,n+1){
    m[s[i]]++;
  }
  
  ll ans=0;
  for(auto e: m){
    ans+=(e.second-1)*e.second/2;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 14336
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;

struct Node{
    int key;
    Node *parent,*left,*right;
};

Node *root,*NIL;

Node *find(Node *u,int k){
    while(u!=NIL && k!=u->key){
        if(k < u->key)u = u->left;
        else u = u->right;
    }
    return u;
}

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x!=NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y==NIL){
        root = z;
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,i,x;
    string com;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        cin>>com;
        if(com[0]=='f'){
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL)printf("yes\n");
            else printf("no\n");
        }else if(com == "insert"){
            scanf("%d",&x);
            insert(x);
        }else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}



Measured memory_bytes: 22008
#include <stdio.h>
 
int main(void){
 
    int num,i,tsum=0,hsum=0,cmp,f;
    char line[101],line1[101];      /* ????????????????????????????????????100??\??? */
 
    scanf("%d\n",&num);             /* ????????????????????????°n?????±???? */
    for(i=0;i<num;i++){
        scanf("%s %s",line,line1);  /* ???¢???????????????????????°??????????????????? */
        f=strcmp(line,line1);       /* num??????°??????????????????±????????? */
        if(!f){
            tsum++;
            hsum++;
        }                           /* line???line1??????´??????tsum???¨hsum??????????????? */
        else if(f>0)
            tsum+=3;                /* tsum??????????????? */
        else
            hsum+=3;                /* hsum??????????????? */
    }
 
    printf("%d %d\n",tsum,hsum);
 
    return 0;
}

Measured memory_bytes: 604
import collections
import sys
input = sys.stdin.readline
n,k,l=map(int,input().split())

parD,parT=[-1]*n,[-1]*n
def findD(x):
  if parD[x]<0:
    return x
  else:
    parD[x]=findD(parD[x])
    return parD[x]
def uniteD(x,y):
  x=findD(x)
  y=findD(y)
  if x==y:
    return False
  else:
    if parD[x]>parD[y]:
      x,y=y,x
    parD[x]+=parD[y]
    parD[y]=x
    return True
def sameD(x,y):
  return findD(x)==findD(y)
def sizeD(x):
  return -parD[findD(x)]
def findT(x):
  if parT[x]<0:
    return x
  else:
    parT[x]=findT(parT[x])
    return parT[x]
def uniteT(x,y):
  x=findT(x)
  y=findT(y)
  if x==y:
    return False
  else:
    if parT[x]>parT[y]:
      x,y=y,x
    parT[x]+=parT[y]
    parT[y]=x
    return True
def sameT(x,y):
  return findT(x)==findT(y)
def sizeD(x):
  return -parT[findT(x)]


for i in range(k):
  p,q=map(int,input().split())
  uniteD(p-1,q-1)
for i in range(l):
  r,s=map(int,input().split())
  uniteT(r-1,s-1)
for i in range(n):
  findD(i)
  findT(i)
C=[]
for i in range(n):
  if parD[i]<0:
    parD[i]=i
  if parT[i]<0:
    parT[i]=i
Ans=[]
for i in range(n):
  Ans.append((parD[i],parT[i]))
ANS=collections.Counter(Ans)
for i in range(n):
  print(ANS[Ans[i]])

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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        double[] x = new double[n];
        String[] u = new String[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextDouble();
            u[i] = sc.next();
        }
        double ans = 0;
        for (int i = 0; i < n; i++) {
            if (u[i].equals("BTC")) {
                x[i] *= 380000.00000;
            }
            ans += x[i];
        }
        System.out.printf("%.5f%n", ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main(){
    int a,b;
    while(1){
        cin>>a>>b;
        if(a==b&&a==0){
            break;
        }else if(a>=b){
            cout<<b<<" "<<a<<endl;
        }else{
            cout<<a<<" "<<b<<endl;
        }
    }
    return 0;
}


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

struct UnionFind {
  UnionFind() {}
  UnionFind(int n) {
    init(n);
  }

  vector<int> parent, rank;

  void init(int n) {
    parent.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; ++i) {
      parent[i] = i;
      rank[i] = 1;
    }
  }

  int root(int v) {
    return parent[v] = (parent[v] == v ? v : root(parent[v]));
  }

  bool same(int u, int v) {
    return root(u) == root(v);
  }

  bool is_root(int v) {
    return root(v) == v;
  }

  void unite(int u, int v) {
    if (same(u, v)) return;
    u = root(u);
    v = root(v);

    if (rank[u] > rank[v]) swap(u, v);
    rank[u] += rank[v];
    parent[v] = u;
  }

  int element_count(int v) {
    return rank[root(v)];
  }
};

int main() {
  int n, m, ans = 0;
  cin >> n >> m;

  vector<pair<int, int>> v(m);
  for (int i = 0; i < m; ++i) {
    cin >> v[i].first >> v[i].second;
    v[i].first--;
    v[i].second--;
  }

  for (int i = 0; i < m; ++i) {
    UnionFind uf(n);
    for (int j = 0; j < m; ++j) {
      if (i == j) continue;
      uf.unite(v[j].first, v[j].second);
    }

    if (uf.element_count(0) != n) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
/*I wanna be the very best, like no one ever was...*/

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);
 

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

ll power(ll a, ll n){
    int res=1;
    while(n){
        if(n%2==1)
            res=(res*a)%MOD;
        a=(a*a)%MOD;

        n=n/2;
    }
    return res;
}
ll inv(ll x) {
    return power(x,MOD-2);
}


ll c(ll n , ll r){
    ll up=1;
    ll down = 1;
    r = min(r, n-r);
    for(int i=0;i<r;i++){
        up=(up*(n-i))%MOD;
        down=(down*(i+1))%MOD;
    }
    return up*inv(down)%MOD;
}


int main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    ll n, a,b;
    cin>>n>>a>>b;
	// ll ans=(power(2,n)-c(n,a)-c(n,b)-1)%MOD;
    // cout<<(ans+MOD)%MOD;

 ll ans = power(2,n)-1;
    cout<<((ans - (c(n,a))- (c(n,b)))%MOD+MOD)%MOD;
  
 
 
    
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T &a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T &a, T b) {
	a = std::min(a, b);
}

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)
			return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i;
		res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m = mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)
		return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod ;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int> engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, k;
int r, s, p;
string t;
signed main() {
	cin >> n >> k >> r >> s >> p >> t;
	int ans = 0;
	rep(i,k)
	{
		bool flag = false;
		for (int j = i; j < n; j += k) {
			if (!flag) {
				if (t[j] == 'r')
					ans += p;
				else if (t[j] == 's')
					ans += r;
				else
					ans += s;
				if(j+k<n&&t[j]==t[j+k])flag=true;
			} else {
				flag=false;
			}
		}
	}
	cout<<ans<<endl;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans{};
  bitset<10> digi_1;
  for (int i{}; i < N - 2; ++i) {
    int d = S[i] & 0xF;
    if (digi_1[d]) continue;
    digi_1.set(d);
    bitset<10> digi_2;
    for (int j{i + 1}; j < N - 1; ++j) {
      int d = S[j] & 0xF;
      if (digi_2[d]) continue;
      digi_2.set(d);
      bitset<10> digi_3;
      for (int k{j + 1}; k < N; ++k) {
        int d = S[k] & 0xF;
        if (digi_3[d]) continue;
        digi_3.set(d);
        ++ans;
        if (digi_3.count() == 10) break;
      }
    }
  }

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


Measured memory_bytes: 256
#print "str1 >>>> " #探したい文字列
str1 = gets.chomp
#print "n >>>> " #指輪の数
n = gets.chomp.to_i
cnt = 0
for i in 1..n
  #print "str2[#{i}]"
  str2 = gets.chomp
  if (str2+str2).include?(str1)
    cnt += 1;
  end
end

print cnt,"\n";



Measured memory_bytes: 8888
d,g = map(int,input().split())
probs = []
ans = float('inf')
for i in range(d):
    p,c =map(int,input().split())
    probs.append(((i+1)*100,p,c))

for i in range(2**d):
    count = 0
    score = 0
    yet = []
    for j in range(d):
        if ((i >>j) & 1):
            count +=probs[j][1]
            score +=probs[j][2] +probs[j][0]*probs[j][1]
        else:
            yet.append((probs[j][0],probs[j][1]-1))
    if ans <= count:
        continue
    elif score>=g:
        ans = count
        continue
    yet.sort(reverse=True)
    if score+sum([x*y for x,y in yet]) <g:
        continue
    for point,num in yet:
        solve = min((g - score-0.1)//point +1,num)
        count += solve
        score += solve*point
        if count >= ans:
            break
        if score >=g:
            ans = count
            break
    
print(int(ans))
    
    
            
    

Measured memory_bytes: 3064
n = int(input())
t = [0]*10001
for i in range(1,41):
    t[6*i**2] += 1
for i in range(1,99):
    for j in range(1,99):
        if(i != j):
            a = (i+j)**2 + 2*j**2
            if(a <= 10000):
                t[a] += 3
            else:
                break
for i in range(3,100):
    for j in range(2,i):
        for k in range(1,j):
            a = ((i+j)**2 + (j+k)**2 + (k+i)**2)//2
            if(a <= 10000):
                t[a] += 6
            else:
                break
for i in range(1,n+1):
    print(t[i])

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

const int INF = 1<<30;

int dp[1001][1<<12];

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), C(m,0);
    for(int i=0; i<m; i++){
        int b;
        cin >> a[i] >> b;
        for(int j=0; j<b; j++){
            int c;
            cin >> c;
            c--;
            C[i] |= 1<<c;
        }
    }
    for(int i=0;i<=m;i++){
        fill(dp[i], dp[i]+(1<<n), INF);
    }
    dp[0][0] = 0;
    for(int i=0; i<m; i++){
        for(int S=0; S<(1<<n); S++){
            dp[i+1][S|C[i]] = min(dp[i+1][S|C[i]], dp[i][S] + a[i]);
            dp[i+1][S] = min(dp[i+1][S], dp[i][S]);
        }
    }
    if(dp[m][(1<<n)-1] < INF){
        cout << dp[m][(1<<n)-1] << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;

}


Measured memory_bytes: 16256
program bbb

implicit none
integer :: n, i, j
character(200) :: s, t, st

read*, n
read*, s, t
do i = 1, 200
st(i:i) = ' '
end do
s = trim(s)
t = trim(t)

j = 0
do i = 1, n
j = j + 1
st(j:j) = s(i:i)
j = j + 1
st(j:j) = t(i:i)
end do

write(*,*) trim(st)

end program

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

constexpr int MAXN = 1e5 + 1;
vector<int> adj[MAXN];
int in_degree[MAXN];
int dist[MAXN];
bool visited[MAXN];

void dfs(int s)
{
    visited[s] = true;
    for (int u : adj[s])
    {
        dist[u] = max(dist[u], 1 + dist[s]);
        in_degree[u]--;
        if (in_degree[u] == 0)
            dfs(u);
    }
}

int main(void)
{
    int N, M;
    cin >> N >> M;
    while (M--)
    {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        in_degree[y]++;
    }

    for (int i = 1; i <= N; i++)
        if (!visited[i] && in_degree[i] == 0)
            dfs(i);

    int ans = 0;
    for (int i = 1; i <= N; i++)
        ans = max(ans, dist[i]);
    cout << ans << "\n";
}

Measured memory_bytes: 9728
s = input()
out = ""
while len(s) > 0:
  if s[0:1] == '0':
    s = s[1:]
    out += '0'
  if s[0:1] == '1':
    s = s[1:]
    out += '1'
  if s[0:1] == 'B':
    s = s[1:]    
    if len(out) > 0:
      out = out[:-1]
print(out)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> x(m);
  rep(i, m) std::cin >> x[i];
  std::vector<int> diff(m - 1);

  sort(x.begin(), x.end());
  rep(i, m - 1) { diff[i] = x[i + 1] - x[i]; }
  sort(diff.begin(), diff.end());

  int64_t sum = 0;
  rep(i, m - n) { sum += diff[i]; }

  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

priority_queue <pii> q;
vector <int> adj[MAXN];
int n, m, f[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), mset(f, INF);
	for (int i = 1, x, y; i < n; i ++)
		x = Read(), y = Read(), adj[x].pb(y), adj[y].pb(x);
	m = Read();
	for (int i = 1, x, y; i <= m; i ++)
		x = Read(), y = Read(), f[x] = y, q.push(mp(y, x));
	while (!q.empty())
	{
		int x = q.top().yy; q.pop();
		for (auto y : adj[x])
			if (f[y] == INF)
				f[y] = f[x] - 1, q.push(mp(f[y], y));
			else if (abs(f[x] - f[y]) ^ 1)
				return puts("No"), 0;
	}
	puts("Yes");
	for (int i = 1; i <= n; i ++)
		printf("%d\n", f[i]);
	return 0;
}


Measured memory_bytes: 7924
#include<iostream>
using namespace std;
int main()
{
int W, H, x, y, r;
cin >> W >> H >> x >> y >> r;
if ( ( x - r ) >= 0 && H >= ( x + r) 
	&& H >= ( y + r) && ( y - r) >= 0)
	cout << "Yes" << '\n';

else
cout << "No" << '\n';
return 0;
}

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




int main() {
  
  char a,b;
  cin>>a>>b;
  
  if (a=='H' and b=='H'){
    cout<<'H'<<endl;
  }
  
    else if (a=='H' and b=='D'){
    cout<<'D'<<endl;
  }
  
    else if (a=='D' and b=='H'){
    cout<<'D'<<endl;
  }
  
    else if (a=='D' and b=='D'){
    cout<<'H'<<endl;
  }
  

  
}










Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>
#define enld endl

lint power(lint x, lint n, lint m) {
	//(x^n)%mを返す
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

int main() {
	lint MOD = 998244353;
	lint N;
	cin >> N;
	vector<lint>D(N);
	rep(i, N) {
		cin >> D[i];
	}
	vector<lint>A(N);
	rep(i, N) {
		A[D[i]]++;
	}
	vector<lint>AA;
	reverse(A);
	bool flag = false;
	rep(i, N) {
		if (A[i] == 0 &&flag==false) {

		}
		else {
			flag = true;
			AA.push_back(A[i]);
		}
	}
	reverse(AA);
	if (D[0] == 0 && AA[0] == 1) {

		lint ans = 1;
		rep(i, AA.size() - 1) {
			ans *= power(AA[i], AA[i + 1], MOD);
			ans %= MOD;
		}
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 2936
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    p: [usize1; n],
  }
  let mut d = 0;
  for i in 0 .. n {
    if p[i] != i {
      d += 1;
    }
  }

  if d <= 2 {
    puts!("YES\n");
  } else {
    puts!("NO\n")
  }
}


Measured memory_bytes: 4352
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
const int N = 1e5 + 50;
int a[N], cnt1[N], cnt2[N];
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0; i < n; i += 2)
		cnt1[a[i]]++;
	for (int i = 1; i < n; i += 2)
		cnt2[a[i]]++;
	vector<pair<int, int>> v1(n), v2(n);
	v1.push_back({ 0, 0 }), v2.push_back({ 0, 0 });
	for (int i = 0; i < N; i++)
		if (cnt1[i])
			v1.push_back({ cnt1[i], i });
	for (int i = 0; i < N; i++)
		if (cnt2[i])
			v2.push_back({ cnt2[i], i });
	sort(v1.begin(), v1.end(), greater<pair<int, int>>());
	sort(v2.begin(), v2.end(), greater<pair<int, int>>());
	if (v1[0].second != v2[0].second)
		printf("%d", n - v1[0].first - v2[0].first);
	else
		printf("%d", min(n - v1[0].first - v2[1].first, n - v1[1].first - v2[0].first));
	return 0;
}

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

using namespace std;

vector<int> tab[100005];
queue<int> kolejka;
int wej[100005];
int maksy[100005];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    for(int i=1; i<=m; i++)
    {
        cin>>a>>b;
        tab[a].push_back(b);
    }

    for(int i=1; i<=n; i++) {
        for(int j=0; j<tab[i].size(); j++) {
            wej[tab[i][j]]++;
        }
    }

    for(int i=1; i<=n; i++) {
        if(wej[i]==0)kolejka.push(i);
    }

    while(!kolejka.empty()) {

        int v=kolejka.front();
        kolejka.pop();

        for(int i=0; i<tab[v].size(); i++) {

            maksy[tab[v][i]]=max(maksy[tab[v][i]], maksy[v]+1);
            wej[tab[v][i]]--;

            if(wej[tab[v][i]]==0)kolejka.push(tab[v][i]);
        }
    }

    int w=0;

    for(int i=1; i<=n; i++) {
        w=max(w, maksy[i]);
    }

    cout<<w;

    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
 
using namespace std;
 
long long int dp[1000005][2];
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	string s;
 
	cin >> s;
 	
 	s += '0';
 	
	for(int i=0;i<1000005;i++)
	{
		dp[i][0] = 1e18;
		dp[i][1] = 1e18;
	}

	dp[0][0] = s[0] - '0';
	dp[0][1] = 10 - (s[0] - '0');

	for(int i=1;i<s.length();i++)
	{
		dp[i][0] = min(dp[i-1][0] + (s[i]-'0'),dp[i-1][1] + (s[i]-'0') + 1);
		dp[i][1] = min(dp[i-1][0] + (10 - (s[i]-'0')),dp[i-1][1] + (10 - (s[i]-'0'+1)));
	}
 
	cout << min(dp[s.length()-1][0],dp[s.length()-1][1]) << '\n';
 
	return 0;
}

Measured memory_bytes: 19852
#include<iostream>

int main(){
	unsigned int x, y, c, tmp;
	while(true){
		std:: cin >> x >> y;
		if(x == 0 && y == 0)
			return 0;
		if(y>x)
			tmp = x, x= y, y = tmp;
		c = 0;
		while(true){
			if(y == 0)
				break;
			x = x%y;
			tmp = x;
			x = y;
			y = tmp;
			c++;
		}
		std:: cout << x << ' ' << c << std::endl;
	}
}

Measured memory_bytes: 0
#ifndef _BLESS_MCLAREN_MCL32_
#define _BLESS_MCLAREN_MCL32_ true
#endif

#ifndef _BLESS_FERNANDO_ALONSO_14_
#define _BLESS_FERNANDO_ALONSO_14_ true
#endif

#ifndef _FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_
#define _FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_ true
#endif

#ifndef _1731_TRUE_LOVE_
#define _1731_TRUE_LOVE_ true
#endif

#ifndef _CIVILIZATION_
#define _CIVILIZATION_ true
#endif

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstdarg>
#include <climits>
#include <cassert>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
using namespace std;

const int MAX_N = (int)2e5 + 5;

int n, a[MAX_N];

int main() {
    {
        assert(_BLESS_MCLAREN_MCL32_);
        assert(_BLESS_FERNANDO_ALONSO_14_);
        assert(_FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_);
        assert(_1731_TRUE_LOVE_);
        assert(_CIVILIZATION_);
    }

    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    for (int i = n - 1; i >= 0; i -= 2) printf("%d ", a[i]);
    for (int i = (n & 1); i < n; i += 2) printf("%d ", a[i]);
    return 0;;
}


Measured memory_bytes: 2944
#include<stdio.h>

int n,A[20];

int solve(int i,int a){
    if(a==0) return 1;
    if(i >= n) return 0;
    int res = solve(i + 1,a) || solve(i + 1,a - A[i]);
    return res;
}

int main(){

    int q,a,i,j;

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

    scanf("%d",&q);

    for(j=0;j<q;j++){
        scanf("%d",&a);
        if(solve(0,a)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    REP(i,n){cin >> v[i];}

    int result = 0, flag=0;
    FOR(i,1,n){

        if(flag==1){
            flag++;
        }else if(flag==2){
            flag = 0;
        }

        if(v[i]==v[i-1]&&flag==0){
            result++;
            flag++;
        }


    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

chunk = []
now = 1
for i in range(1, N):
    if A[i] == A[i - 1]:
        now += 1
    else:
        if now != 1:
            chunk.append(now)
            now = 1
    if i == N - 1 and now != 1:
        chunk.append(now)
ans = 0
for c in chunk:
    ans += c // 2

print(ans)



Measured memory_bytes: 9084
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7

"""
どこかに同じ数値が出てくる。
AAAxBBBxCCC
xが同一文字とする
・xがどちらか1つ登場
・Bを使用しない
ものについてはどちらのxを使用しても同じ数列になるので除く
"""
modp = mod
max_n = 2*10 ** 5               # 必要分だけ用意する
fact = [1, 1] + [0]*max_n     # fact[n] = (n! mod modp)
factinv = [1, 1] + [0]*max_n  # factinv[n] = ((n!)^(-1) mod modp)
inv = [0, 1] + [0]*max_n      # factinv 計算用

def cmb(n, r, p):
    assert n < p, 'n is less than modp'
    assert n < max_n, 'n in less than max_n'
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

for i in range(2, max_n + 1):
    fact[i] = (fact[i-1] * i) % modp
    inv[i] = (-inv[modp % i] * (modp // i)) % modp
    factinv[i] = (factinv[i-1] * inv[i]) % modp

counter = [0] * n
for i in range(n+1):
    counter[a[i]-1]+=1
    if counter[a[i]-1] == 2:
        second = i
        first = a.index(a[i])
        break

# xの重複を考慮せず全てカウント
ans = [cmb(n+1, i, mod) for i in range(1, n+2)]

n_left = first
n_right = n-second
n_lr = n_left + n_right

# i個の重複する組合せはn_lrからi-1個選び、xをどちらか1つ選ぶ。
doubled = [1]+[cmb(n_lr, i, mod) for i in range(1, n_lr+1)]

for i in range(n_lr+1):
    ans[i] = (ans[i] - doubled[i])%mod

for i in range(len(ans)):
    print(ans[i])






Measured memory_bytes: 47380
MOD = 10 ** 9 + 7

def calc(a):
    smallest = a * (a-1) // 2
    largest = smallest + a * (n-a+1)
    return largest - smallest + 1 

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

ans = 0
for a in range(k, n+2):
    ans += calc(a)
    ans %= MOD

print(ans)

 



Measured memory_bytes: 9188
N,K=map(int,input().split())
S=input()
if S[K-1]=='A':
  print(S[:K-1]+'a'+S[K:])
elif S[K-1]=='B':
  print(S[:K-1]+'b'+S[K:])
else:
  print(S[:K-1]+'c'+S[K:])

Measured memory_bytes: 3060
import java.io.IOException;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			n = scanner.nextInt();
			if ((w | h | n) == 0)
				break;
			size = new int[n + 1];
			for (int i = 0; i < n; i++) {
				int b = scanner.nextInt();
				int k = scanner.nextInt();
				size[b] = k;
			}
			map = new int[h][w];
			pos = new int[n + 1][2];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int s = scanner.nextInt();
					map[i][j] = s;
					if (s > 0) {
						pos[s][0] = i;
						pos[s][1] = j;
					}
				}
			}
			count = 0;
			ans = new int[h][w];
			f(1);
			if (count == 1) {
				for (int i = 0; i < h; i++) {
					for (int j = 0; j < w; j++) {
						System.out.print(ans[i][j]);
						System.out.print(j == w - 1 ? '\n' : ' ');
					}
				}
			} else {
				System.out.println("NA");
			}
		}
	}

	private void f(int k) {
		PriorityQueue<Point> pq = new PriorityQueue<Point>();
		pq.add(new Point(map, 1));
		while (!pq.isEmpty()) {
			Point point = pq.poll();
			int[][] map = point.map;
			k = point.k;
			if (k == n + 1) {
				count++;
				if (count == 2)
					return;
				ans = map;
				continue;
			}
			int s = size[k];
			for (int r = 1; r <= s; r++) {
				if (s % r != 0)
					continue;
				int y = pos[k][0];
				int x = pos[k][1];
				for (int ui = y + 1 - s / r; ui <= y; ui++) {
					if (ui < 0)
						continue;
					loop: for (int lj = x + 1 - r; lj <= x; lj++) {
						if (lj < 0)
							continue;
						int di = ui + s / r;
						int rj = lj + r;
						if (di > h || rj > w)
							continue;
						for (int i = ui; i < di; i++) {
							for (int j = lj; j < rj; j++) {
								if (map[i][j] != 0 && map[i][j] != k)
									continue loop;
							}
						}
						int[][] tmp = new int[h][w];
						for (int i = 0; i < h; i++)
							tmp[i] = Arrays.copyOf(map[i], w);
						for (int i = ui; i < di; i++) {
							for (int j = lj; j < rj; j++) {
								if (tmp[i][j] != k)
									tmp[i][j] = k;
							}
						}
						pq.add(new Point(tmp, k + 1));

					}
				}
			}
		}
	}
	class Point implements Comparable<Point> {
		int[][] map;
		int k;

		public Point(int[][] map, int k) {
			super();
			this.map = map;
			this.k = k;
		}

		@Override
		public int compareTo(Point o) {
			return o.k - this.k;
		}

	}

	int count;
	int h, w, n;
	int[] size;
	int[][] map;
	int[][] pos;
	int[][] ans;

}

Measured memory_bytes: 59948
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     fac[0] = fac[1] = 1;
//     finv[0] = finv[1] = 1;
//     inv[1] = 1;
//     for (int i = 2; i < MAX; i++){
//         fac[i] = fac[i - 1] * i % MOD;
//         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
//         finv[i] = finv[i - 1] * inv[i] % MOD;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }

int h, w;
int c[10][10];

void wf() {
    for (int k = 0; k <= 9; ++k) {
        for (int i = 0; i <= 9; ++i) {
            for (int j = 0; j <= 9; ++j) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
}

int main() {
    cin >> h >> w;
    for (int i = 0; i <= 9; ++i) {
        for (int j = 0; j <= 9; ++j) {
            cin >> c[i][j];
        }
    }
    wf();
    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int t;
            cin >> t;
            if (t != -1) ans += c[t][1];
        }
    }
    cout << ans << endl;
    return 0;
}


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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define bitcount(n) __builtin_popcount(n)

int main(){
    int N;
    cin >> N;
    vector<bool> rate_count(8, false);
    int rainbow = 0;
    for(int i = 0; i < N; i++){
        int rate;
        cin >> rate;
        if(rate < 3200){
            rate_count[rate / 400] = true;
        }else{
            rainbow++;
        }
    }
    int rate_count_sum = 0;
    for(int i = 0; i < 8; i++){
        rate_count_sum += rate_count[i];
    }
    cout << max(1, rate_count_sum) << " " << rate_count_sum + rainbow << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
a_max = max(a)
a_max_cnt = a.count(a_max)
a_max_i = a.index(a_max)

if a_max_cnt == 1:
  for i in range(n):
    if i==a_max_i:
      print(sorted(set(a))[-2])
    else:
      print(a_max)
else:
  for i in range(n):
    print(a_max)

Measured memory_bytes: 18072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

void chmax(ll& a, ll b) { a = max(a, b); }
void chmin(ll& a, ll b) { a = min(a, b); }



int main() {
    ll x; cin >> x;
    ll now = 100;
    ll ans = 0;
    while(now < x) {
        now += now * 0.01;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int N,sum=0;
	cin>>N;
	int L[203];
	for(int i=0;i<2*N;i++){
		cin>>L[i];
	}
	sort(L,L+2*N);
	for(int i=0;i<2*N;i+=2){
		sum+=L[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,i;
  while(cin>>a>>b,a){
    int c[a],s=0,k=0,p=0;
    r(i,a){cin>>c[i];p+=c[i];}
    sort(c,c+a);
    for(i=a-1;i>=0;i--){
      k++;
      if(k==b){
        s+=c[i];
        k=0;
      }
    }
    cout<<p-s<<endl;;
  }
}

Measured memory_bytes: 3132
#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 = 1001001001;

int main(){
  char a;
  cin >> a;
  string ans = "consonant";
  
  if (a == 'a') ans = "vowel";
  if (a == 'i') ans = "vowel";
  if (a == 'u') ans = "vowel";
  if (a == 'e') ans = "vowel";
  if (a == 'o') ans = "vowel";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    string S;
    cin >> S;
    int n = S.length();
    ll a[n + 1]{};
    ll ans = 0;
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (S[i] == '<') {
            a[i + 1] = a[i] + 1;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (S[i] == '>') {
            if (a[i + 1] >= a[i]) {
                a[i] = a[i + 1] + 1;
            }
        }
    }
    for (ll i : a) {
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> A(n + 1);
    rep(i, n) cin >> A.at(i + 1);

    int now = 1;
    int ans = 0;
    while(ans != n && now != 2) {
        ans++;
        now = A.at(now);
    }
    if(ans == n) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3772