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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

/* --------------- template start --------------- */
template <typename T> 
struct BinaryIndexTree { // [1, n]
    vector<T> array;
    int n;

    BinaryIndexTree(int _n) {
        array.resize(_n + 1, 0);
        n = _n;
    }

    T cumsum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i;
        }

        return s;
    }

    T sum(int i, int j) {
        T ret_i = cumsum(i - 1);
        T ret_j = cumsum(j);

        return ret_j - ret_i;
    }

    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

template<typename T>
struct UnionFind {
    vector<int> par;
    vector<T> sz;

    UnionFind(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }

    T size_of_tree(int x) {
        return sz[find_root(x)];
    }
};
/* --------------- template end --------------- */

/* --------------- function start --------------- */
llong my_gcd(llong a, llong b) {
    return (a ? my_gcd(b % a, a) : b);
}
llong my_lcm(llong a, llong b) {
    return a * b / my_gcd(a, b);    
}

llong facmod(llong n) {
    if (n == 0) return 1;

    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}
llong modinv(llong n) {
    return powmod(n, MOD - 2);
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    }
    res = (res * modinv(facmod(k))) % MOD;

    return res;
}
/* --------------- function end --------------- */

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

    llong h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    
    llong ans = h * w / 2LL;
    if (h % 2 && w % 2) ++ans;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
	int n,k;
  string s;
  cin>>n>>s>>k;
  for(int i=0;i<n;i++){
	if(s[k-1]!=s[i]){
      cout<<"*";
    }else{
      cout<<s[i];
    }
  }
  cout<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
using namespace std;
#define MAX 200005
#define MOD 1000000007
long long arr[MAX];
map<pair<long long,long long>,int> M;
set<pair<long long,long long> > S;
long long gcd(long long a,long long b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
    pair<long long,long long> p,q;
    arr[0]=1;
    int n,i,j;
    long long g;
    scanf("%d",&n);
    long long current=0,ans=1;
    for(i=0;i<n;i++)
    {
        arr[i+1]=(arr[i]*2)%MOD;
        scanf("%lld %lld",&p.first,&p.second);
        g=gcd(abs(p.first),abs(p.second));
        if(g==0)
        {
            current++;
            continue;
        }
        p.first=p.first/g;
        p.second=p.second/g;
        if(p.first<0||(p.first==0&&p.second<0))
        {
            p.first=-p.first;
            p.second=-p.second;
        }
        j=S.size();
        S.insert(p);
        if(S.size()==j)
        {
            M[p]++;
        }
        else
        {
            M[p]=1;
        }
    }
    long long zeros=current;
    while(S.size()>0)
    {
        j=S.size();
        p=*(S.begin());
        current=arr[M[p]];
        q.first=p.second;
        q.second=-p.first;
        swap(p,q);
        if(p.first<0||(p.first==0&&p.second<0))
        {
            p.first=-p.first;
            p.second=-p.second;
        }
        S.erase(p);
        if(S.size()<j)
        {
            current=(current+arr[M[p]]+MOD-1)%MOD;
        }
        ans=(ans*current)%MOD;
        S.erase(q);
    }
    ans=(ans+zeros)%MOD;
    ans=(ans+MOD-1)%MOD;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 30320
#include"bits/stdc++.h"
using namespace std;

void Main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> ans(n);

  for (int ri = 0; ri < 2; ri++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'R') cnt++;
      else {
        ans[i] += cnt / 2;
        ans[i - 1] += (cnt + 1) / 2;
        cnt = 0;
      }
    }

    reverse(ans.begin(), ans.end());
    reverse(s.begin(), s.end());
    for (int i = 0; i < n; i++) {
      if (s[i] =='L') s[i] = 'R';
      else s[i] = 'L';
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}

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

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

using namespace std;
typedef long long ll;
const int INF = 1e9;

int main(){
	ll T = 1;
	//cin >> T;
	while (T--){
	 int k; int x;
	 cin >> k >> x;
	 if(k*500 >= x) {
		 cout << "Yes" << endl;
	 } else {
		  cout << "No" << endl; 
		  } 
	}
}
	

Measured memory_bytes: 3512
#include<stdio.h>
int main(void)
{
	int a, b, c, temp;

	scanf("%d %d %d", &a, &b, &c);
	if (a <= b){	}
	else{
		temp = a;
		a = b;
		b = temp;
	}


	if (a <= c){	}
	else{
		temp = a;
		a = c;
		c = temp;
	}
	if (b <= c){	}
	else{
		temp = b;
		b = c;
		c = temp;
	}

	printf("%d %d %d\n", a, b, c);

	return(0);
}

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

int main() {
  int N,a,b,c,d,e,f,g,h,i,x ;
  cin >> N ;
  a= N %10 ;
  b= (N%100 -N%10)/10 ;
  c= (N%1000)/100 ;
  e= (N%10000)/1000;
  f= (N%100000)/10000;
  g= (N%1000000)/100000;
  h= (N%10000000)/1000000;
  i= (N%100000000)/10000000;
  
  x=a+b+c+d+e+f+g+h+i;
  
  if(N%x==0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        System.out.println( Math.max(A - 2  * B,0));
    }
}


Measured memory_bytes: 21844
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        Long A, B;
                        String op;
                        A = sc.nextLong();
                        op = sc.next();
                        B = sc.nextLong();
                        if (op.equals("+")) {
                                System.out.println(A + B);
                        } else {
                                System.out.println(A - B);
                        }
                }
        }
}

Measured memory_bytes: 9812
import sys
l, r = map(int,input().split())
if r-l>=2019:
    print(0)
    sys.exit()
a=l%2019
b=r%2019
if a>b:
    b+=2019
elif a==b:
    print(0)
    sys.exit()
m=2018
for i in range(a,b):
    for j in range(i+1,b+1):
        if m>(i*j)%2019:
            m=(i*j)%2019

print(m)

Measured memory_bytes: 3060
def cmb(n, r):
    ans1 = 1
    for i in range(n - r + 1, n + 1):
        ans1 *= i
    ans2 = 1
    for i in range(1, r + 1):
        ans2 *= i
    return ans1 // ans2

def main():
    N = int(input())
    A = list(map(int, input().split()))
    S = [0]*N
    s = 0
    for i in range(N):
        a = A[i]
        s += a
        S[i] = s

    # print(S)
    ans = 0
    B = {}
    for s in S:
        if s not in B:
            B[s] = 0
        B[s] += 1
    # print(B)
    for b in B:
        if b == 0:
            ans += B[b]
        if B[b] > 1:
            ans += cmb(B[b], 2)
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;

#define N 300000
#define ls (x<<1)
#define rs (x<<1|1)

int n,a[N],seg[N<<2][2],pos[N];
struct node{
	int x,l,r;
	node(int x=0,int l=0,int r=0):x(x),l(l),r(r){}
	bool operator < (const node &w) const{
		return x>w.x;
	}
};
priority_queue<node> pq;

void build(int x,int l,int r){
	if (l==r){seg[x][l&1]=a[l]; seg[x][(l&1)^1]=n+1; return;}
	int mid=(l+r)>>1;
	build(ls,l,mid); build(rs,mid+1,r);
	seg[x][0]=min(seg[ls][0],seg[rs][0]);
	seg[x][1]=min(seg[ls][1],seg[rs][1]);
}

int qry(int x,int l,int r,int L,int R,int k){
	if (l>=L&&r<=R) return seg[x][k];
	int mid=(l+r)>>1,ret=n+1;
	if (L<=mid) ret=min(ret,qry(ls,l,mid,L,R,k));
	if (R>mid) ret=min(ret,qry(rs,mid+1,r,L,R,k));
	return ret;
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d",a+i);
		pos[a[i]]=i;
	}
	build(1,1,n);
	pq.push(node(qry(1,1,n,1,n,1),1,n));
	while (!pq.empty()){
		int l=pq.top().l,r=pq.top().r; pq.pop();
		int u=qry(1,1,n,l,r,l&1),v=qry(1,1,n,pos[u]+1,r,r&1);
		printf("%d %d ",u,v);
		u=pos[u]; v=pos[v];
		if (l<u) pq.push(node(qry(1,1,n,l,u-1,l&1),l,u-1));
		if (u+1<v) pq.push(node(qry(1,1,n,u+1,v-1,v&1),u+1,v-1));
		if (v<r) pq.push(node(qry(1,1,n,v+1,r,u&1),v+1,r));
	}
	puts("");
	
	return 0;
}
			

Measured memory_bytes: 8696
#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> t(n);
  rep(i, n){
    cin >> t.at(i);
  }

  int sum = 0;
  rep(i, n){
    sum += t.at(i);
  }

  int m;
  cin >> m;

  rep(i, m){
    int a, b;
    cin >> a >> b;
    cout << sum - t.at(a-1) + b << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    string s;
    int lim, rta = 0, aux = 0;
    cin >> s;
    lim = s.size();
    for(int i = 0; i < lim; i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            aux++;
        }
        else aux = 0;
        rta = max(rta, aux);
    }
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string d[10];
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }
    int ans = n;
    while (true) {
        string s;
        bool flag = 0;
        s = to_string(ans);
        for (int i = 0; i < k; i++) {
            if (s.find(d[i]) != string::npos) {
                flag = 1;
                break;
            }
        }
        if (!flag)
            break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

X = get_int

money = 100
year = 0
while money < X
  money *= 101
  money /= 100
  year += 1
end

puts year


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

#define Int register int
#define MAXN 200005

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}

int n,top = 1,mx[MAXN],to[MAXN << 1],nxt[MAXN << 1],f[MAXN],g[MAXN],h[MAXN],fa[MAXN],ans[MAXN],head[MAXN];
void Add_Edge (int u,int v){
	to[++ top] = v,nxt[top] = head[u],head[u] = top;
	to[++ top] = u,nxt[top] = head[v],head[v] = top;
} 

int Query (int u,int val){
	if (u > val) return 0;
	int res = 1;for (Int i = head[u];i;i = nxt[i]) if (to[i] ^ fa[u]) res += Query (to[i],val);
	return res;
}

void dfs1 (int u){
	for (Int i = head[u];i;i = nxt[i]){
		int v = to[i];
		if (v == fa[u]) continue;
		fa[v] = u,mx[v] = max (mx[u],v),dfs1 (v);
	}
	if (u > mx[fa[u]]){
		h[u] = 1;
		for (Int i = head[u];i;i = nxt[i]){
			int v = to[i];
			if (v == fa[u]) continue;
			f[v] = Query (v,u),g[v] = Query (v,mx[fa[u]]),h[u] += g[v];
		}
	}
}

void dfs2 (int u){
	for (Int i = head[u];i;i = nxt[i]){
		int v = to[i];
		if (v == fa[u]) continue;
		ans[v] = ans[u];
		if (u > mx[fa[u]]) ans[v] += f[v] - g[v];
		if (mx[v] > mx[u]) ans[v] += h[v];
		dfs2 (v);
	}
}

signed main(){
	read (n);
	for (Int i = 2,u,v;i <= n;++ i) read (u,v),Add_Edge (u,v);
	mx[1] = f[1] = 1,dfs1 (1),dfs2 (1);for (Int i = 2;i <= n;++ i) write (ans[i]),putchar (' ');
	putchar ('\n');
	return 0;
}

Measured memory_bytes: 25432
using System;

class Class3
{
    static void Main(string[] args)
    {
    
    string[] strs = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51".Split((char)44);
    int _input = int.Parse(Console.ReadLine()) - 1;
    Console.WriteLine(strs[_input].ToString());
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;





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

    int d,g;
    cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    vector<pair<int,pair<int,int>>> pp(d);
    rep(i,d){
        cin >> p[i] >> c[i];
        pp[i] = make_pair(c[i],make_pair(p[i],i+1));
    }
    sort(all(pp),greater<>());
    for(int i = 0;i < d-1;++i){
        for(int j = i;j < d;++j){
            if(pp[i].first==pp[j].first){
                if(pp[i].second.first > pp[j].second.first){
                    auto a = pp[i];
                    pp[i] = pp[j];
                    pp[j] = a;
                }
            }
        }
    }

    int sum=0;
    int tmp=0;
    int ans = INF;
    for(int i = 1;i < 1<<d;++i){
        sum = 0;
        tmp = 0;
        rep(j,d){
            if(i>>j&1){
                rep(k,pp[j].second.first){
                    sum += pp[j].second.second*100;
                    tmp++;
                    if(k==pp[j].second.first-1) sum += pp[j].first;
                    if(sum >= g){
                        ans = min(ans,tmp);
                    }
                }
            }
        }
    }
    cout << ans << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

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

const int N = 100001;

vector<pair<LL, LL > > A,B;
LL dpA[N], dpB[N];

int main() {
  int n;
  LL C;
  scanf("%d%lld",&n,&C);
  rep(i,0,n) {
    LL x,v;
    scanf("%lld%lld",&x,&v);
    A.pb(mp(x, v));
    B.pb(mp(C - x, v));
  }
  reverse(all(B));
  LL smA = 0;
  LL smB = 0;
  rep(i,0,n) {
    smA += A[i].SS;
    dpA[i] = max(i ? dpA[i - 1] : 0LL, smA - 2 * A[i].FF);

    smB += B[i].SS;
    dpB[i] = max(i ? dpB[i - 1] : 0LL, smB - 2 * B[i].FF);
  }
  LL ans = 0;
  smA = 0; smB = 0;
  rep(i,0,n) {
    smA += A[i].SS;
    ans = max(ans, smA - A[i].FF + ((n - 2 - i >= 0) ? dpB[n - 2 - i] : 0));

    smB += B[i].SS;
    ans = max(ans, smB - B[i].FF + ((n - 2 - i >= 0) ? dpA[n - 2 - i] : 0));
  }
  printf("%lld\n",ans);
  return 0;
}


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

int main()
{
  int S;
  int hour,min,sec;

  cin >> S;
  hour = S / 3600;
  min = (S%3600)/60;
  sec = S-hour*3600 -min*60;
  cout << hour << ":" << min << ":" << sec<<"\n"; 
  return 0;
}


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

#define fst first
#define snd second
#define fore(i,a,b) for(int i=a, ThxDem=b; i<ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define SZ(s) int(s.size())
#define DBG(x) cerr <<#x << " = " << (x) << "\n"

#define SQR(x) ((x) * (x))

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 11

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<bool> vbool;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vbool> vvbool;

vvll adj;
vll dp;
vbool vis;

void dfs(ll r){
	vis[r] = 1;
	fore(i,0,SZ(adj[r])){
		if(!vis[adj[r][i]]) dfs(adj[r][i]);
		dp[r] = max(dp[r],1+dp[adj[r][i]]);
	}
}

int main(){FIN
	ll n,m,a,b;
	cin >> n >> m;
	dp.assign(n,0);
	adj.assign(n,vll());
	vis.assign(n,0);
	fore(i,0,m){
		cin >> a >> b;
		adj[a-1].pb(b-1);
	}
	fore(i,0,n){
		if(!vis[i])dfs(i);
	}
	ll ans = 0 ;
	fore(i,0,n) ans = max(ans,dp[i]);
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 12048
s = input().split()
W = int(s[0])
H = int(s[1])
x = int(s[2])
y = int(s[3])

if abs(W/2 - x) < 10**-9 and abs(H/2 - y) < 10**-9:
    print(str(W*H/2) + " " + "1")
else:
    print(str(W*H/2) + " " + "0")

Measured memory_bytes: 3060
import scala.io.StdIn
import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer

object Main{
  def main(args: Array[String]){
    StdIn.readLine()
    val line = StdIn.readLine().split(" ").toList.map(_.toInt)

    println(line.sorted.mkString(" "))
    println(sSort(List(), line, 0))
  }

  @tailrec
  def sSort(sorted: List[Int], unsorted: List[Int], n: Int): Int={
    if(unsorted.length == 0) n
    else if(unsorted.sorted == unsorted) n
    else {
      val pos = unsorted.indexWhere(_ == unsorted.min)
      val swapped = unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head)

      if(pos == 0) sSort(sorted :+ unsorted.min, unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head).tail, n)
      else sSort(sorted :+ unsorted.min, unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head).tail, n+1)
    }
  }
}

Measured memory_bytes: 45856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<pair<ll,ll>>data(n);
    for(ll i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        data[i]={a,b};
    }
    sort(data.begin(),data.end());
    ll ans=data[n-1].first+data[n-1].second;
    cout << ans << endl;
}

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

const int maxn=100010,mod=1000000007;
typedef long long ll;
ll s[maxn],ans;
int n,k,a[maxn],inv[maxn],fac[maxn];

int c(int x,int y)
{
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main()
{
	int i,j;
	scanf("%d%d",&n,&k);
	if (k==1||n<k)
	{
		puts("0");
		return 0;
	}
	for (i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if (n==k)
	{
		printf("%d\n",(a[n]-a[1])%mod);
		return 0;
	}
	for (i=1;i<=n;i++)
		s[i]=s[i-1]+1ll*a[i];
	inv[0]=inv[1]=fac[0]=fac[1]=1;
	for (i=2;i<=n;i++)
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for (i=2;i<=n;i++)
	{
		inv[i]=1ll*inv[i-1]*inv[i]%mod;
		fac[i]=1ll*fac[i-1]*i%mod;
	}
	for (i=k-2;i<=n-2;i++)
	{
		ans=(ans+1ll*c(i,k-2)*(((s[n]-s[i+1]-s[n-i-1])%mod+mod)%mod)%mod)%mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N, K, A[Nmax];

int main(){
	cin >> N >> K;
	for(int i=0; i<N; i++) cin >> A[i];

	cout << (N-1) / (K-1) + ((N-1)%(K-1)==0?0:1) << endl;

	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    s = input()
    if s.endswith('s'):
        print(s+"es")
    else:
        print(s+"s")


if __name__ == '__main__':
    main()


Measured memory_bytes: 8968
#include <stdio.h>

int isprime(int);

int main()
{
  int n,x,i,cnt;

  scanf("%d",&n);
  cnt = 0;
  for(i=0;i<n;i++)
    {
      scanf("%d",&x);
      if((isprime(x))==1) cnt++;
    }
  printf("%d\n",cnt);
  return 0;
}

int isprime(int x)
{
  int i=3;
  if(x==2) return 1;
  if(x<2 || x%2==0) return -1;
  while(i*i<=x)
    {
      if(x%i==0) return -1;
      i+=2;
    }
  return 1;
}
      



Measured memory_bytes: 2064
import numpy as np
n = int(input())
a = np.array([int(input()) for _ in range(n)])
a1n = a.argmax()
a_s = sorted(a)
a1 = a_s[-1]
a2 = a_s[-2]
for i in range(n):
    if i == a1n:
        print(a2)
    else:
        print(a1)

Measured memory_bytes: 36656
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n) cin >> a[i];
	vvl dp(n+1,vl(3,-linf));
	dp[0][0] = a[0];
	dp[1][1] = a[1];
	dp[2][2] = a[2];
	REP(i,2,n){
		chmax(dp[i][0],dp[i-2][0] + a[i]);
		if(i > 2){
			chmax(dp[i][1],dp[i-2][1] + a[i]);
			chmax(dp[i][1],dp[i-3][0] + a[i]);
		}
		if(i > 3){
			chmax(dp[i][2],dp[i-2][2] + a[i]);
			chmax(dp[i][2],dp[i-3][1] + a[i]);
			chmax(dp[i][2],dp[i-4][0] + a[i]);
		}
	}
	ll ans;
	if(n & 1) ans = max({dp[n-3][0],dp[n-2][1],dp[n-1][2]});
	else ans = max(dp[n-2][0],dp[n-1][1]);
	cout << ans << endl;
}


Measured memory_bytes: 15652
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<deque>
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
int dx[] = {0,1,2};
int N;

void ladder(VVI& tower,P& p)
{
  while(p.F < N && tower[p.S][p.F] == 1)
    p.F++;
  p.F--;
}

void slip(VVI& tower,P& p)
{
  while(tower[p.S][p.F] == 2 && p.F > 0)
    p.F--;
}

int main()
{
 
 
  while(cin >> N,N)
    {
      vector<vector<int> > tower,mincost;
      tower.resize(2),mincost.resize(2); 
      tower[0].resize(N+1),tower[1].resize(N+1);
      mincost[0].resize(N+1),mincost[1].resize(N+1);

      for(int j=0;j<2;j++)
	for(int i=0;i<N;i++)
	  cin >> tower[j][i],mincost[j][i] = (1<<28);

      mincost[0][0] = mincost[1][0] = 0;
      deque<P> deq;
      P fst = P(0,0);
      if(tower[fst.S][fst.F] == 1)
	ladder(tower,fst);
      deq.push_back(fst); // false が左
      mincost[fst.S][fst.F] = 0;
      fst = P(0,1);
      if(tower[fst.S][fst.F] == 1)
	ladder(tower,fst);
      deq.push_back(fst);  // true  が右
      mincost[fst.S][fst.F] = 0;      

      while(!deq.empty())
	{
	  P p = deq.front(); deq.pop_front();
	  P pre = p;
	  if(p.F >= N)  
	    continue;

	  p.S = !p.S;
	  for(int i=0;i<3;i++)
	    {
	      int nx = p.F + dx[i];
	      if(nx >= N)
		nx = N-1;
	      P next = P(nx,p.S);
	      if(tower[p.S][nx] == 2)
		slip(tower,next);
	      if(tower[next.S][next.F] == 1)
		ladder(tower,next);

	      if(mincost[next.S][next.F] > mincost[pre.S][pre.F] + 1)
		{
		  mincost[next.S][next.F] = mincost[pre.S][pre.F] + 1;
		  deq.push_back(next);
		}	  

	    }
	}

      if(mincost[0][N-1] != (1<<28) || mincost[1][N-1] != (1<<28))
	cout << min(mincost[0][N-1],mincost[1][N-1]) << endl;
      else 
	cout << "NA" << endl;
    }
  return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int flag;
    char ans[(int)(s.length())];
    for(int j=0;j<(int)s.length();j++)ans[j]=s[j];
    if((int)s.length()-(int)t.length()>0){
    for(int i=0;i<(int)s.length()-(int)t.length();i++){
        flag=0;
        for(int j=0;j<(int)t.length();j++){
            if(s[(int)s.length()-1-i-j]!=t[(int)t.length()-1-j] && s[(int)s.length()-1-i-j]!='?'){
                flag++;
                break;
            }
        }
        if(flag==0){
            for(int j=0;j<(int)t.length();j++)if(ans[(int)s.length()-1-i-j]=='?')ans[(int)s.length()-1-i-j]=t[(int)t.length()-1-j];
            for(int j=0;j<(int)s.length();j++){
                if(ans[j]!='?')cout << ans[j];
                else cout << 'a';
            }
            return 0;
        }
    }
    }
    else if((int)s.length()-(int)t.length()==0){
        flag=0;
        for(int j=0;j<(int)t.length();j++){
            if(s[j]!=t[j] && s[j]!='?'){
                flag++;
                break;
            }
        }
        if(flag==0){
            for(int j=0;j<(int)t.length();j++)if(ans[j]=='?')ans[j]=t[j];
            for(int j=0;j<(int)s.length();j++)cout << ans[j];
            return 0;
        }
    }
    cout << "UNRESTORABLE";
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(){
  double x[4],y[4],ax,ay,bx,by;
  int i,f;
  while(scanf("%lf %lf",&x[0],&y[0])!=EOF){
    for(i=1;i<4;i++)scanf("%lf %lf",&x[i],&y[i]);
    for(i=f=0;i<3;i++){
      ax=x[(i+1)%3]-x[i];
      ay=y[(i+1)%3]-y[i];
      bx=x[3]-x[i];
      by=y[3]-y[i];
      if((ax*by-ay*bx)>0)f++;
    }
    if(f%3)printf("NO\n");
    else   printf("YES\n");
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;

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

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> a(N);
    ll sum=0;
    rep(i,N){
        cin >> a[i];
        if (a[i]>0){
            sum+=a[i];
        }
    }
    ll countn=0,countp=0;
    rep(i,K){
        if (a[i]<0){
            countn+=a[i];
        }
        else {
            countp+=a[i];
        }
    }
    ll ans=0;
    chmax(ans,sum+countn);
    chmax(ans,sum-countp);
    rep(i,N-K){
        if (a[i]<0){
            countn-=a[i];
        }
        else {
            countp-=a[i];
        }
        if (a[K+i]<0){
            countn+=a[K+i];
        }
        else {
            countp+=a[K+i];
        }
        chmax(ans,sum+countn);
        chmax(ans,sum-countp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
// Last Change: 05/02/2020 21:13:15.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll K, A, B;
  cin >> K >> A >> B;

  auto temp = A / K;
  for (int i = 0; i < 3; ++i) {
    if (K * (temp + i) >= A and K * (temp + i) <= B) {
      cout << "OK" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3132
import java.util.*;
import java.io.*;
import java.lang.*;
// ArrayList<Integer>[] arr=new ArrayList[n];
public class Main{	
public static void main(String[] args) throws FileNotFoundException, IOException{
        Scanner s = new Scanner(System.in);
         StringBuilder sb=new StringBuilder();
         BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
         int n=s.nextInt(),w=s.nextInt();
        int[][] arr=new int[n+1][2];
        long[][] dp=new long[w+1][n+1]; 
        //dp[i][j] holds given set of i points what is max_value we can get from a 
        //subset of given points satisfying the constrain ∑(x co-ord of points)<=j  (1<=k<=i)
        for(int i=1;i<=n;i++){
            arr[i][0]=s.nextInt(); arr[i][1]=s.nextInt();
        }

       /* for(int i=1;i<=n;i++){
            for(int j=1;j<=w;j++){
                if(arr[i][0]>j){
                    dp[i][j]=dp[i-1][j];
                }
                else{
                    dp[i][j]=Math.max(dp[i-1][j],arr[i][1]+dp[i-1][j-arr[i][0]]);
                }
            }
        }*/

        for(int i=1;i<=w;i++){
            for(int j=1;j<=n;j++){
                if(arr[j][0]>i){
                    dp[i][j]=dp[i][j-1];
                }
                else{
                    dp[i][j]=Math.max(dp[i][j-1],arr[j][1]+dp[i-arr[j][0]][j-1]);
                }
            }
        }
        System.out.println(dp[w][n]);
    }
}

Measured memory_bytes: 128972
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto A = RDA;
	auto index = A.MAKE_IDX();
	foreach (ref i; index)
	{
		++i;
	}

	index.map!(to!string).join(" ").writeln;
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 5996
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
r, g, b = map(str, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
#list = [input() for i in range(N)]
a = ("").join([r, g, b])
if int(a)%4==0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38384
let N = stdin.ReadLine() |> int
let A = stdin.ReadLine().Split() |> Array.map int |> Array.toList

let rec loop i items count =
    match items with
    | [head] -> if head = i then count + 1 else count
    | head :: [tail] -> 
        if head = i 
        then loop (i + 1) [head] (count + 1)
        else loop (i + 1) [tail] count
    | head :: sec :: tail -> 
        if i = head 
        then loop (i + 1) (head::tail) (count + 1) 
        else loop (i + 1) (sec::tail) count

loop 1 A 0 |> stdout.WriteLine

Measured memory_bytes: 29404
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{

    //freopen("inputfile.txt","r",stdin);
    IOS;
   int n;cin>>n;
   int ar[n];
   for(int i=0;i<n;i++)cin>>ar[i];
   int count = 0;
   for(int i=0;i<=n-3;i++)
   {
       for(int j=i+1;j<=n-2;j++)
       {
           for(int k=j+1;k<=n-1;k++)
           {
               if(ar[i]!=ar[j] && ar[j]!=ar[k] && ar[k]!=ar[i]){
                if(((ar[i]+ar[j])>ar[k]) && ((ar[j]+ar[k])>ar[i]) && ((ar[k]+ar[i])>ar[j]))count++;
               }
           }
       }
   }
   cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const ll mod =  1e9+7;
#define ios std::ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
const int maxn = 1e6 + 5;
ll quickpow(ll a, ll b)
{
    ll ret = 1;
    while (b != 0)
    {
        if (b & 1)
            ret = ret * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ret % mod;
}
ll inv(ll a){
	return quickpow(a, mod - 2);
}
ll fac[maxn], ifac[maxn];
void init(){
	fac[0] = fac[1] = 1;
	for(int i = 2; i < maxn; i ++) fac[i] = fac[i - 1] * i % mod;
	ifac[maxn - 1] = inv(fac[maxn - 1]);
	for(int i = maxn - 2; i >= 0; i --) ifac[i] = ifac[i + 1] * (i + 1) % mod;
}
ll getc(int n, int m){
	if(n < m || m < 0) return 0;
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main(){
	int n;
	cin >> n;
	init();
	if(n == 1) cout << 0 << endl;
	else if(n == 2) cout << 2 << endl;
	else{
		ll ans = quickpow(10, n);
		ans = (ans + mod - quickpow(8, n)) % mod;
		ll res = 1;
		for(int i = 1; i <= n; i ++){
			res = (res + getc(n, i) % mod * quickpow(8, n - i) % mod) % mod;
		}
		ans = (ans + mod - res * 2 % mod) % mod;
		cout << (ans + 2) % mod << endl; 

	}
	return 0;
}

Measured memory_bytes: 19080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 200;
int dp[2][N][N][N], n, m, rec[2][N][N][N], sz;
int mat[N][N];
char str[N];
int main() {
  read(n), read(m);
  sz = max(n, m);
  rep (i, 1, n) {
    scanf("%s", str + 1);
    rep (j, 1, m) mat[i][j] = (str[j] == '.' ? 1 : 2);
  }
  rrp (c, m, 1) {
    rep (i, 1, n) {
      int v = mat[i][c];
      rep (j, i, n) {
	if (mat[j][c] != v) break;
	dp[0][c][i][j] = 1;
	if (v == mat[i][c+1])
	  dp[0][c][i][j] += dp[0][c+1][i][j];
      }
    }
  }
  rrp (r, n, 1) {
    rep (i, 1, m) {
      int v = mat[r][i];
      rep (j, i, m) {
	if (mat[r][j] != v) break;
	dp[1][r][i][j] = 1;
	if (v == mat[r+1][i])
	  dp[1][r][i][j] += dp[1][r+1][i][j];
      }
    }
  }
  int ans = 0;
  while (true) {
    if (dp[0][1][1][n] >= m || dp[1][1][1][m] >= n)
      break;
    rep (a, 0, 1) rep (i, 1, sz) rep (j, 1, sz) rep (k, 1, sz)
      rec[a][i][j][k] = dp[a][i][j][k];
    ++ ans;
    rep (c, 1, m) {
      rep (i, 1, n) rep (j, i, n) {
	int t = rec[0][c][i][j];
	ckmx(dp[0][c][i][j], t + rec[0][c+t][i][j]);
      }
    }
    rep (r, 1, n) {
      rep (i, 1, m) rep (j, i, m) {
	int t = rec[1][r][i][j];
	ckmx(dp[1][r][i][j], t + rec[1][r+t][i][j]);
      }
    }
    rep (c, 1, m) rep (i, 1, n) rep (j, i, n)
      ckmx(dp[1][i][c][c + dp[0][c][i][j]-1], j - i + 1);
    rep (r, 1, n) rep (i, 1, m) rep (j, i, m)
      ckmx(dp[0][i][r][r + dp[1][r][i][j]-1], j - i + 1);
    rep (c, 1, m) rrp (s, n-1, 1) {
      for (int i = 1, j = s; j <= n; ++ i, ++ j) {
	if (i > 1) ckmx(dp[0][c][i][j], dp[0][c][i-1][j]);
	if (j < n) ckmx(dp[0][c][i][j], dp[0][c][i][j+1]);
      }
    }
    rep (r, 1, n) rrp (s, m-1, 1) {
      for (int i = 1, j = s; j <= m; ++ i, ++ j) {
	if (i > 1) ckmx(dp[1][r][i][j], dp[1][r][i-1][j]);
	if (j < m) ckmx(dp[1][r][i][j], dp[1][r][i][j+1]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 124928
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	string s;
	cin>>s;
	ll i,j,k,l,n=s.length();
	k=0;
	for(i=0;i<n;i++){
		k=(k+(s[i]-'0'))%9;
	}
	if(k%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;	
}

Measured memory_bytes: 3776
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val A = Array.fill(N)(sc.nextLong)

  val z = A.foldLeft((0L, 0L))((z, x) => if (x >= z._2) (z._1, x) else (z._1 + z._2 - x, z._2))._1

  println(z)
}


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

const int mod = 1e9 + 7;
const int MX  = 2e6;

ll power(ll x, ll y, ll p = mod) {
    ll res = 1;
    x      = x % p;
    while (y) {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p = mod) { return power(n, p - 2, p); }

ll fac[MX + 5];
void init(ll p = mod) {
    fac[0] = 1;
    for (int i = 1; i <= MX; i++) fac[i] = fac[i - 1] * i % p;
}

ll C(ll n, ll r, ll p = mod) {
    if (r == 0) return 1;
    if (n - r < r) return C(n, n - r, p);
    return fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p;
}

int main() {
    init(mod);
    int n, k;
    string s;
    cin >> k >> s;
    n    = s.size() + k;
    ll r = 0;
    for (int i = s.size(); i <= n; ++i)
        (r += C(n, i) * power(25, n - i)) %= mod;
    cout << r;
}

Measured memory_bytes: 20876
n,m=(int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
#print(e)
x=[]

for i in range(n):
  x=x+e[i][1:]

#print(x)
ans=0
if n==1:
  ans=e[0][0]
else:
  for i in range(1,m+1):
    if x.count(i)==n:
      ans+=1
    
print(ans)
  

Measured memory_bytes: 3060
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑





int main() {
	int a, b, c, mon;
	cin >> a >> b >> c;
	for (int i = 1; i <= 10; ++i) {
		c = a * c - b;
		cout << c << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String output;

		Scanner scanner = new Scanner(System.in);

		String string = scanner.next();

		output = String.valueOf(string.charAt(0)) + String.valueOf(string.length()-2) + String.valueOf(string.charAt(string.length()-1));

		System.out.println(output);

		scanner.close();
	}

}


Measured memory_bytes: 21460
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    A = list(map(int, input().split()))

    d = dict()
    for x in A:
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
    A.sort()

    ans = 0
    M = max(A)
    dp = [True]*(M+1)
    for x in A:
        for xx in range(x+x, M+1, x):
            dp[xx] = False
    for x in A:
        if d[x] == 1 and dp[x]:
            ans += 1
    print(ans)


main()


Measured memory_bytes: 37788
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  int n, r;
  cin >>n >> r;
  if(n>=10)cout << r << endl;
  else{
    cout << r+100*(10-n) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver1.9.3
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(15);
  int h,w;
  cin >> h >> w;
  vector<Vi> mapp(10,Vi(10));
  rep(i,0,10){
    rep(j,0,10){
      cin >> mapp[i][j];
    }
  }
  Vi minp(10,INF),ord(10);
  ord={0,1,2,3,4,5,6,7,8,9};
  int now,nowp;
  do {
    
    nowp = 0;
    now = ord[0];
    rep(i,0,9){
      if(now==1) break;
      nowp += mapp[now][ord[i+1]];
      now = ord[i+1];
    }
    minp[ord[0]]=min(minp[ord[0]],nowp);
    
  } while (next_permutation(ALL(ord)));
  int ans =0,memo;
  rep(i,0,h*w){
    cin >> memo;
    if(memo==-1) continue;
    ans += minp[memo];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,H,W;
  cin>>H>>W>>N;
  vii A(H,vi(W));
  int h=0,w=0;
  REP(i,1,N){
    int X;
    cin>>X;
    rep(j,0,X){
      A[h][w]=i;
      if(h%2==0){
        w++;
        if(w==W){
          h++;
          w--;
        }
      }
      else{
        w--;
        if(w==-1){
          h++;
          w++;
        }
      }
    }
  }
  rep(i,0,H){
    rep(j,0,W) cout<<A[i][j]<<" ";
    cout<<endl;
  }
  }



Measured memory_bytes: 384
n=int(input())
g=[set() for _ in range(n)]
for _ in range(n-1):
  u,v,w=map(int,input().split())
  g[u-1].add((v-1,w%2))
  g[v-1].add((u-1,w%2))
l=[-1]*n
q=[(0,0)]
while q:
  a,b=q.pop()
  l[a]=b
  for c,d in g[a]:
    if l[c]>=0: continue
    q+=[(c,b^d)]
print(*l,sep='\n')

Measured memory_bytes: 48676
def findDigits(num):
	l = []
	while(num > 0):
		l.append(num % 10)
		num = num / 10
	return l	


n = input()
i = 1
sum1 = 1000000000
while(i <= n/2):
	l1 = findDigits(i)
	l2 = findDigits(n - i)
	s1 = sum(l1)
	s2 = sum(l2)
	if(s1 + s2 < sum1):
		sum1 = s1 + s2
	i = i + 1
print(sum1)		

Measured memory_bytes: 2692
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))
 
typedef long long ll;
 
const int INF = 1000000000;
const int MOD = 1000000007;

int main (){
	int d, n;
	cin >> d >> n;
	int ans = pow(100, d) * n;
	if (n == 100) ans += pow(100, d);
	cout << ans << endl;
}


Measured memory_bytes: 384
n = int(input())

def mnd(a, b):
    mod = a % b
    if mod == 0:
        return b
    else:
        return mnd(b, mod)

nd = int(input())
for _ in range(n - 1):
    tmp  = int(input())
    kouyaku = mnd(max(nd, tmp), min(nd, tmp))
    nd = nd * tmp // (kouyaku)
print(nd)

Measured memory_bytes: 3060
n = int(input())
a = []
for i in range(n): #วน loop รับ input แต่ละบรรทัด
    a.append(int(input()))

def insertionsort(a, n, g): #ทำการ insertion sort โดยใช้ gap
    global c
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            c += 1
        a[j + g] = v

c = 0
g = [1]
while g[-1] * 3 + 1 < n: #สูตรในการหา gap จากจำนวนข้อมูล ถ้ามี 5 gap ก็จะเป็น 4 และ 1 
    g.append(g[-1] * 3 + 1)
g.reverse() #ทำการเปลี่ยนให้เป็น 1,4 เรียงข้อมูล

for i in range(len(g)):#วน loop ทำตามรอบของจำนวน gap 
    insertionsort(a, n, g[i])
    #ทำการแสดงผล output แบบ เป็นบรรทัดตามโจทย์
print(len(g))
print(" ".join(map(str, g)))
print(c)
for i in range(n):
    print(a[i])



Measured memory_bytes: 45512
fun main(args: Array<String>){
    val a = readLine()!!.split(" ")
    val n =readLine()!!.toInt()
    var A = IntArray(3)

    for(i in A.indices){
        A[i]=a[i].toInt()
    }

    A.sort()

    repeat(n){
        A[2] = A[2] * 2
    }
    println(A[0]+A[1]+A[2])


}




Measured memory_bytes: 37620