akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, C, res;
  rd(A);
  rd(B);
  rd(C);
  res = 1;
  if(B!=A){
    res++;
  }
  if(C!=A && C!=B){
    res++;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int A, B, C, res;
//   rd(A,B,C);
//   res = 1;
//   if(B!=A) res++;
//   if(C!=A && C!=B) res++;
//   wt(res);
// }


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

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

int main(){

    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    REP(i,n)cin >> p[i];

    sort(ALL(p));

    int ans = 0;
    REP(i,k)ans +=p[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
import java.util.*;


public class Main {
	public static void main(String args[]){
		List<HashSet<Integer>> able = new ArrayList<HashSet<Integer>>();
		long[][] dp = new long[30+1][50+1];
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			if(n==0) break;
			for(int i=0;i<31;i++){
				for(int j=0;j<51;j++){
					dp[i][j] = 0;
				}
			}
			for(int i=0;i<n+1;i++){
				long ppp = 1L << i;
				dp[0][i] =ppp;
			}
			//ここまで初期化
			int p,q;
			//List<HashSet<Integer>> able = new ArrayList<HashSet<Integer>>();
			//HashSet<Integer> hs = new HashSet<Integer>();
			for(int i=0;i<31;i++){
				HashSet<Integer> hs = new HashSet<Integer>();
				able.add(hs);
			}
			HashSet<Integer> hs = new HashSet<Integer>();
			for(int i=1;i<n+1;i++){
				p=sc.nextInt();
				for(int j=0;j<p;j++){
					q=sc.nextInt();//日程
					//long ppp = 1 << i;
					hs = able.get(q);
					hs.add(i);
					able.set(q, hs);
				}
			}
			long bitc;
			int result=-1;
			for(int i=1;i<31;i++){
				long ch = 0;
				hs = able.get(i);
				for(int contents : hs){
					ch |= dp[i-1][contents];
				}
				for(int contents : hs){
					dp[i][contents]  = ch;
				}
				for(int j=1;j<n+1;j++){
					if(dp[i][j]==0){
						dp[i][j] = dp[i-1][j];
					}
				}

				bitc = Long.bitCount(ch);
				//System.out.println("i="+i+" j="+j+" bitc="+bitc+" dp="+dp[i][j]);
				if(bitc == n){
					result = i;
					break;
				}
			}
			//if(result == 0) result = -1;
			System.out.println(result);
			able.clear();
		}
	}
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n;
  char s[n];
  cin >> s;
  cin >> k;
  k--;
  for(int i = 0; i < n; i++){
    if(s[i] != s[k]) s[i] = '*';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int F(int P,int w[],int k){
  int i,sum=0,a=0;
  for(i=0;i<k;i++){
    if(w[a]<=P){
      while(sum+w[a]<=P && w[a]!=-1){
    sum+=w[a];
    a++;
      }
    }
    sum=0;
  }
  return a;
}

int main(){
  int sum=0,i,mid,l,r,n,k,w[1000000];
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&w[i]);
  }
  w[n]=-1;
  l=0;
  r=2000000000;
  while(l<r){
    mid=(l+r)/2;
    sum=F(mid,w,k);
    if(sum==n && F(mid-1,w,k)!=sum){
      break;   
    }
    if(sum<n){
      l=mid+1;
    }
    else if(sum==n &&F(mid-1,w,k)==sum){
      r=mid;
    }
  }
  printf("%d\n",mid);
  return 0;
}

Measured memory_bytes: 996
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;

int n, m, u[maxn], v[maxn], fa[maxn];
long long ans[maxn];

long long c2(long long a) {
	return a * (a-1) / 2;
}

int getfa(int x) {
	if (fa[x] < 0)
		return x;

	fa[x] = getfa(fa[x]);
	return fa[x];
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
		cin >> u[i] >> v[i];

	memset(fa, -1, sizeof(fa));

	ans[m-1] = c2(n);
	for (int i = m-2; i >= 0; --i) {
		int x = getfa(u[i+1]), y = getfa(v[i+1]);

		if (x == y)
			ans[i] = ans[i+1];
		else {
			long long a = -fa[x], b = -fa[y];
			fa[x] += fa[y];
			fa[y] = x;

			ans[i] = ans[i+1] + c2(a) + c2(b) - c2(a+b);
		}
	}

	for (int i = 0; i < m; ++i)
		cout << ans[i] << endl;

	return 0;
}

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

int main(){
	int N;
	int x[21],y[21];
	int M;
	char d[30];
	int l[30];

	while (1)
	{
		int now_x = 10;
		int now_y = 10;

		int grid[21][21] = { 0 };
		grid[10][10] = 1;

		int discovered_N = 0;

		//InputData
		cin >> N;
		if (!N) break;
		for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
		cin >> M;
		for (int i = 0; i < M; i++) cin >> d[i] >> l[i];

		for (int i = 0; i < M; i++){
			for (int j = 0; j < l[i]; j++){
				if (d[i] == 'N'){
					now_y++;
					grid[now_x][now_y] = true;
				}
				else if (d[i] == 'E'){
					now_x++;
					grid[now_x][now_y] = true;
				}
				else if (d[i] == 'S'){
					now_y--;
					grid[now_x][now_y] = true;
				}
				else if (d[i] == 'W'){
					now_x--;
					grid[now_x][now_y] = true;
				}
			}
		}


		//判定
		for (int i = 0; i < N; i++){
			if (grid[x[i]][y[i]]) discovered_N++;
		}


		//出力
		(discovered_N == N) ? cout << "Yes\n" : cout<<"No\n";

	}

	return 0;
}

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

int change[256];
char s[2000];
int dp[2000][9];

int main()
{
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		char c;
		scanf(" %c", &c);
		
		if (c == 'J'){
			s[i] = 1;
		}
		else if (c == 'O'){
			s[i] = 2;
		}
		else {
			s[i] = 4;
		}
	}
	
	dp[0][1] = 1;
	
	for (int i = 0; i < n; i++){
		for (int a = 0; a < 8; a++){
			for (int b = 0; b < 8; b++){
				if ((b & s[i]) && (a & b)){
					dp[i + 1][b] += dp[i][a];
					if (dp[i + 1][b] > 10007){
						dp[i + 1][b] -= 10007;
					}
				}
			}
		}
	}
	
	int sum = 0;
	for (int i = 1; i <= 8; i++){
		sum += dp[n][i];
		
		if (sum > 10007){
			sum -= 10007;
		}
	}
	
	printf("%d\n", sum);
	
	return 0;
}

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

struct edge{
    int to;
    int cost;
};

vector<edge> G[100100];

int main(){
    int N; cin >> N;
    for(int i=0; i<N-1; i++){
        int u,v; int w;
        cin >> u >> v >> w;
        u--;v--;
        edge f1, f2;
        f1.to=v; f1.cost=w;
        G[u].push_back(f1);
        f2.to=u; f2.cost=w;
        G[v].push_back(f2);        
    }
    int color[100100]; //-1か1
    for(int i=0; i<N; i++){
        color[i] = 100;
    }
    bool used[100100];
    for(int i=0; i<N; i++){
        used[i]=false;
    }

//    for(int i=1; i<N+1; i++){
//        for(auto e : G[i]){
//            cout << e.to << " " << e.cost << endl;
//        }
//    }


    queue<int> que; //頂点
    color[0]=1;
    used[0]=true;
    que.push(0);
    while(!que.empty()){
        int a = que.front(); que.pop();
        for(auto e : G[a]){
            int w1 = e.cost;
            int v1 = e.to;
            if(used[v1]) continue;
            if(w1%2==0) color[v1] = color[a];
            if(w1%2==1) color[v1] = color[a]*(-1);
            used[v1]=true;
            que.push(v1);
        }
    }
    for(int i=0; i<N; i++){
        if(color[i]==-1) cout << 0 << endl;
        else cout << 1 << endl;
    }
}

Measured memory_bytes: 6912
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		String[] str = num.split(" ", 0);
		int n = Integer.parseInt(str[0]);
		int a = Integer.parseInt(str[1]);
		int b = Integer.parseInt(str[2]);
		int x = n - a;
		int y = n - b;
		x=Math.abs(x);
		y=Math.abs(y);
		if (x < y) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 int main() {
int n;cin>>n;
   vector<int>p(n);
   for(int i=0;i<n;i++)
     cin>>p.at(i);
   sort(p.begin(),p.end());
   int ans=p.at(p.size()/2)-p.at(p.size()/2-1);

   cout<<ans;
 }

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=2005;
int n,m,q,a[MN],b[MN],c[MN],t[MN],top;
inline void ins(int l,int r){
	reg int tot=0;
	for(reg int i=l;i<=r;i++)t[++tot]=a[i];
	sort(t+1,t+1+tot);
	for(reg int i=1;i<=r-l+2-m;i++)c[++top]=t[i];
}
inline int calc(int x){
	reg int pre=1;top=0;
	for(reg int i=1;i<=n;i++)
		if(a[i]<x)ins(pre,i-1),pre=i+1;
	if(top<q)return 0x3f3f3f3f;
	sort(c+1,c+1+top);
	return c[q]-x;
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(reg int i=1;i<=n;i++)
		scanf("%d",a+i),b[i]=a[i];
	sort(b+1,b+1+n);
	reg int N=unique(b+1,b+1+n)-b-1,ans=0x3f3f3f3f;
	a[++n]=-0x3f3f3f3f;
	for(reg int i=1;i<=N;i++)ans=min(ans,calc(b[i]));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i);
int main(){
  int a,b;cin>>a>>b;
  vector<vector<char>>c(a+2,vector<char>(b+2));
  for(int i=1;i<a+1;i++){
    for(int j=1;j<b+1;j++){
      cin>>c[i][j];
    }
  }
  vector<vector<int>>d(a+2,vector<int>(b+2));
  for(int i=1;i<a+2;i++){
    for(int j=1;j<b+2;j++){
      d[i-1][j-1]=0;
    }
  }
  for(int i=1;i<a+1;i++){
    for(int j=1;j<b+1;j++){
      int e=0,f=d[i][j];
      if(c[i-1][j-1]=='#')e++;
      if(c[i][j-1]=='#')e++;
      if(c[i-1][j]=='#')e++;
      if(c[i+1][j+1]=='#')e++;
      if(c[i][j+1]=='#')e++;
      if(c[i+1][j]=='#')e++;
      if(c[i-1][j+1]=='#')e++;
      if(c[i+1][j-1]=='#')e++;  
      d[i][j]=f+e;
    }
  }
  for(int i=1;i<a+1;i++){
    for(int j=1;j<b+1;j++){
      if(c[i][j]=='#')cout<<"#";
      else cout<<d[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
n = int(input())
t_list = []
a_list = []
for i in range(n):
    t, a = map(int, input().split())
    t_list.append(t)
    a_list.append(a)

t_num = t_list[0]
a_num = a_list[0]
for i in range(1, n):
    t, a = t_list[i], a_list[i]
    num = max((a_num+a-1)//a, (t_num+t-1)//t)
    t_num = num * t
    a_num = num * a
print(t_num + a_num)


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

int    t[100005], a[100005];
double precalc[10];

map<int, double> v1, ps;

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

    int n;
    cin >> n;

    for (int i = 0; i <= 7; i++) {
        double mul = 1.0 * (100 - i * 10) / 100;
        precalc[i] = log(mul);
    }

    for (int i = 0; i < n; i++) {
        cin >> t[i] >> a[i];
        v1[t[i]] = precalc[a[i]];
    }

    for (auto it = v1.begin(); it != v1.end(); it++) {
        if (it == v1.begin()) {
            ps[it->first] = it->second;
        } else {
            auto ip = it;
            ip--;
            ps[it->first] = ps[ip->first] + it->second;
        }
    }

    int q;
    cin >> q;

    cout << fixed << setprecision(13);

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        double val = 1e9;
        auto   il  = ps.lower_bound(l);
        auto   ir  = ps.lower_bound(r);
        if (ir == ps.begin()) {
            cout << val << endl;
        } else if (il == ps.begin()) {
            ir--;
            val *= exp(ir->second);
            cout << val << endl;
        } else {
            ir--;
            il--;
            val *= exp(ir->second - il->second);
            cout << val << endl;
        }
    }
}


Measured memory_bytes: 16972
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n,t,a;
    cin >> n >> t >> a;
    int ans;
    double now = 1001001001;
    rep(i,n) {
        int h;
        cin >> h;
        double nt = t-h*0.006;
        double dif = abs(nt-a);
        if(dif < now) {
            now = dif;
            ans = i+1;
        }
    }
    cout << ans << endl;
}

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

int main (){
    string s;
    cin >> s;
    for(int i=0;i<s.length();i++){
        if(s.find(s[i])!=i){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long> a(n+1,0),b(n,0);
	long long sum=0;
	
	for(int i=0;i<n+1;i++){
		cin >> a[i];
		sum+=a[i];
	}
	
	for(int i=0;i<n;i++)cin >> b[i];
	
	for(int i=0;i<n;i++){
		long long temp=a[i]-b[i];
		if(temp<0){
			a[i+1]+=temp;
			if(a[i+1]<0)a[i+1]=0;
			a[i]=0;
		}else{
			a[i]-=b[i];
		}
	}
	
	for(int i=0;i<n+1;i++)sum-=a[i];
	
	cout << sum << endl;
	return 0;
}


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

int gcd(int a,int b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b,a%b);
    }
}

int main(){
   int n,h;
   cin>>n;
   vector<int>a(200000);
   for(int i=0;i<n;i++){
       cin>>h;
       a[h]++;
       a[h+3]--;
   }
   for(int i=1;i<200000;i++){
       a[i]+=a[i-1];
   }
   sort(a.begin(),a.end(),greater<>());
   cout<<a[0]<<endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int X, H;
  
  X = N;
  H = 0;
  while(X > 0){
    H += X - int(X / 10) * 10;
    X = X / 10;
  }
  
  if(N % H == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 1E5;

int n;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	vector<int> dp(3, 0);//previous day
	forn(d, n)
	{
		vector<int> opts(3);
		forn(i, 3) cin >> opts[i];
		vector<int> ndp(3, 0);//new day
		forn(i, 3)
		{
			forn(j, 3)
			{
				if (i!=j) 
					ndp[i] = max(ndp[i], dp[j]+opts[i]);
			}
		}
		dp = ndp;
	}
	cout << max({dp[0], dp[1], dp[2]});
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,K = map(int,input().split())
    a = np.array(list(map(int,input().split())))
    s = sum(a)
            
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)

        return divisors
            
    div = make_divisors(s)
    
    div.sort()
    ans = 1
    for use in div:
        rest = -(a%use)
        rest = np.sort(rest)
        ch = -sum(rest)//use
        do = use*ch+sum(rest[:ch])
        if do <= K:
            ans = use
    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 12516
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    string s,t;
    cin>>s>>t;
    if(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 3624
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    string ans = (a + b >= c) ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

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

int main(void) {
  char a, b;
  cin >> a >> b;
  ((a == 'H') ? (cout << b << endl)
              : ((b == 'H') ? (cout << 'D' << endl) : (cout << 'H' << endl)));
  return 0;
}

Measured memory_bytes: 256
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
     ios;
     lld h,w;
     cin>>h>>w;
     vector<vector<lld> > dp(h+1,vector<lld>(w+1,0));
     rep(i,1,h)
     {
         rep(j,1,w)
         {
             char x;
             cin>>x;
             if((i==1)&&(j==1))
             {
                 dp[i][j]=1;
                 continue;
             }
             if(x=='#')
             {
                 dp[i][j]=0;
             }
             else
             {
                 dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
             }
         }
     }
     cout<<dp[h][w]<<endl;
    return 0;
}


Measured memory_bytes: 8064
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-7)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define reo(i,n) for(int (i) = 1 ; (i) <= (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define mkp make_pair
#define mem0(x) memset(x,0,sizeof(x))
#define vec vector
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'a')
#define itoc(c) (char)(c+'a')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll inf = 3 * 1e18;
const int Inf = 15 * 1e8;
const vec<int>dx{ 0,0,-1,1 }, dy{ 1,-1,0,0 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 600000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------------------
signed main() {
	int a, b;
	cin >> a >> b;
	cout << ceil(a * 1. / b) << endl;
}

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

int main(){
    string t; cin >> t;
    int n = t.size();
    rep(i,n){
        if(t[i] != '?') cout << t[i];
        else cout << 'D';
    }
     cout << endl;
}

Measured memory_bytes: 3724
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
  x = input()
  if(x=='AC'):
    AC += 1
  elif(x=='WA'):
    WA += 1
  elif(x=='TLE'):
    TLE += 1
  else:
    RE += 1
print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))

Measured memory_bytes: 69844
program ddcc2020qualc
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: h,w,k
    integer(int32):: i,num,x,y,endy,endx
    integer(int32), allocatable:: a(:,:)
    character(300),allocatable:: s(:)

    read*, h,w,k
    allocate(s(h))
    allocate(a(w,h), source=0)
    do i=1,h
        read*, s(i)
    end do
    num = 1
    endy = 0
    do y=1,h
        endx=0
        do x=1,w
            if (s(y)(x:x) == '#') then
                a(endx+1:x,endy+1:y) = num
                endx = x
                num=num+1
            end if
        end do
        if (endx < w .and. endy < h)then
            a(endx+1:w,endy+1:y) = num-1
        end if
        if (endx /= 0) endy=y 
    end do

    if (endy < h) then
        do y = endy+1, h
            a(:,y) = a(:,endy)
        end do
    end if

    do i=1,h
        print'(*(i0,1x))', a(:,i)
    end do
end program ddcc2020qualc

Measured memory_bytes: 1152
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[100009], pre[100009] = {0};
const ll MOD = 1e9+7;
ll qpow(ll a, ll b)
{
	ll res = 1;
	while(b)
	{
		if(b%2) res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%lld", a+i);
	
	sort(a+1, a+1+n);
	for(int i = 1; i <= n; i++)
		pre[i] = (pre[i-1] + a[i]) % MOD;
		
	if(k==1) printf("0\n");
	else
	{
		ll res = 0, tmp = 1;
		for(int i = k, j = k-2; i <= n; i++, j++)
		{
			ll sum = (pre[n] - pre[i-1]  - pre[n-i+1] + MOD * 2) % MOD;
			res = (res + tmp * sum % MOD) % MOD;
			tmp = (tmp * (j + 1) % MOD) * qpow(j-k + 3, MOD-2) % MOD;
		}
			printf("%lld\n", res);
	}
	
 
}

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

ll xorf(ll x){
    if(x%4==0)
        return x;
    else if(x%4==1)
        return 1;
    else if(x%4==2)
        return x+1;
    return 0;
}

int main(){

    ll l,r;
    cin>>l>>r;
    cout<<(xorf(max(0ll,l-1))^xorf(r));


return 0;
}


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

const ll mod = 998244353;

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

  vector<ll> dp(s+1);
  dp[0] = 1;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int j = s; j >= 0; j--) {
      if (j - a >= 0) {
        dp[j] = (dp[j] * 2LL + dp[j-a]) % mod;
      }
      else {
        dp[j] = dp[j] * 2LL % mod;
      }
    }
  }

  cout << dp[s] % mod << endl;

  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int n,c[30][55];
string s;
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    for(int j=0;j<s.size();j++) c[s[j]-'a'][i]++;
  }
  for(int i=0;i<=25;i++){
    int m=1000000000;
    for(int j=0;j<n;j++) m=min(m,c[i][j]);
    for(int j=1;j<=m;j++) cout<<(char)('a'+i);
  }
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
long long p[200000], n, cnt, a, b;
int main() {
	cin >> n >> a >> b; for (int i = 0; i < n; i++)cin >> p[i];
	for (int i = 0; i < n - 1; i++) {
		long long s = p[i + 1] - p[i];
		if (s > b / a)cnt += b;
		else cnt += s*a;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, A, M;
  cin >> N;
  cin >> A;
  
  M = N % 500;
  
  if (M - A <= 0){
    cout << "Yes" <<endl;
  }else{ 
    cout << "No" <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int N;
    scanf("%d", &N);
    int bArray[200001] = {};
    for(int i=2; i<=N; i++){
        int data;
        scanf("%d", &data);
        bArray[data]++;
    }
    for (int i=1; i<=N; i++) {
        printf("%d\n", bArray[i]);
    }
}

Measured memory_bytes: 2508
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string s,t;
int nx[100001][26];
int main(){
    cin>>s>>t;
    int ns=s.size(),nt=t.size();
    memset(nx,-1,sizeof(nx));
    
    if(s.size()==1){
        rep(i,nt){
            if(t[i]!=s[0]){
                cout<<-1<<endl;
                return 0;
            }
        }
        cout<<nt<<endl;
        return 0;
    }
    
    int pre=s[ns-1]-'a';
    for(int i=ns-2;i>=0;--i){
        rep(j,26){
            if(pre==j) nx[i][j]=i+1;
            else nx[i][j]=nx[i+1][j];
        }
        pre=s[i]-'a';
    }
    rep(j,26){
        if(pre==j) nx[ns-1][j]=0;
        else nx[ns-1][j]=nx[0][j];
    }
    for(int i=ns-2;i>=0;--i){
        rep(j,26){
            if(nx[i][j]==-1) nx[i][j]=nx[i+1][j];
        }
    }
    int cur=nx[ns-1][t[0]-'a'];
    if(cur==-1){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=cur+1;
    FOR(i,1,nt){
        int ch=t[i]-'a';
        if(nx[cur][ch]==-1){
            cout<<-1<<endl;
            return 0;
        }
        int p=nx[cur][ch]-cur;
        if(p<=0) p+=ns;
        ans+=p;
        cur=nx[cur][ch];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Matrix = vector<vector<ll> >;
constexpr int MOD = 1e9 + 7;

Matrix mul(Matrix &a,Matrix &b){
    int H = a.size(); int W = b[0].size();
    Matrix c(H,vector<ll>(W));
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            for(int k=0;k<a[0].size();++k){
                (c[i][j] += a[i][k] * b[k][j]) %= MOD;
            }
        }
    }
    return c;
}

Matrix pow(Matrix &a,ll exp){
    int N = a.size();
    Matrix ret(N,vector<ll>(N));
    for(int i=0;i<N;++i) ret[i][i] = 1;
    while(exp){
        if(exp&1) ret = mul(ret,a);
        a = mul(a,a);
        exp >>= 1;
    }
    return ret;
}

int main(void){
    ll N,K;
    cin >> N >> K;
    Matrix A(N,vector<ll>(N));
    for(int i=0;i<N;++i) for(int j=0;j<N;++j) cin >> A[i][j];
    Matrix v(1,vector<ll>(N,1));
    A = pow(A,K);
    v = mul(v,A);

    ll ans = 0;
    for(int i=0;i<N;++i) (ans += v[0][i]) %= MOD;
    cout << ans << endl;
    return 0;
}

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

int H, W;
string S[2000];
int cnt_h[2000][2000], cnt_w[2000][2000];


int main(){
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        cin >> S[i];
    }
    for(int h = 0; h < H; h++){
        if(S[h][0] == '.'){
            cnt_w[h][0] = 1;
        }
        for(int w = 1; w < W; w++){
            if(S[h][w] == '.'){
                cnt_w[h][w] = cnt_w[h][w - 1] + 1;
            }
        }
        for(int w = W - 1 - 1; w >= 0; w--){
            if(S[h][w] == '.'){
                cnt_w[h][w] = max(cnt_w[h][w], cnt_w[h][w + 1]);
            }
        }
    }
    for(int w = 0; w < W; w++){
        if(S[0][w] == '.'){
            cnt_h[0][w] = 1;
        }
        for(int h = 1; h < H; h++){
            if(S[h][w] == '.'){
                cnt_h[h][w] = cnt_h[h - 1][w] + 1;
            }
        }
        for(int h = H - 1 - 1; h >= 0; h--){
            if(S[h][w] == '.'){
                cnt_h[h][w] = max(cnt_h[h][w], cnt_h[h + 1][w]);
            }
        }
    }
    int ans = 0;
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            ans = max(ans, cnt_h[h][w] + cnt_w[h][w] - 1);
        }
    }
    cout << ans << endl;
        
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,pset[100007];
long long x[100007],y[100007],ans=0;
pair < pair < long long,long long > , int > p[100007];
vector < pair < long long, pair < int,int > > > cur;
int fset(int x){
    if(pset[x]==x) return x;
    return pset[x]=fset(pset[x]);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>y[i];
        p[i]=mp(mp(x[i],y[i]),i);
        pset[i]=i;
    }
    sort(p+1,p+1+n);
    for(int i=2;i<=n;i++){
        cur.pb(mp(p[i].fi.fi-p[i-1].fi.fi,mp(p[i].se,p[i-1].se)));
    }
    for(int i=1;i<=n;i++){
        p[i]=mp(mp(y[i],x[i]),i);
    }
    sort(p+1,p+1+n);
    for(int i=2;i<=n;i++){
        cur.pb(mp(p[i].fi.fi-p[i-1].fi.fi,mp(p[i].se,p[i-1].se)));
    }
    sort(cur.begin(),cur.end());
    for(int i=0;i<cur.size();i++){
        int a=cur[i].se.fi,b=cur[i].se.se;
        long long val=cur[i].fi;
        a=fset(a);
        b=fset(b);
        if(a!=b){
            pset[b]=a;
            ans+=val;
        }
    }
    cout<<ans;
}


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

int main(){
  vector<vector<int>> A(4, vector<int> (4));
  for(int i= 1; i <= 3; i++){
    for(int j = 1; j <= 3; j++){
      cin >> A[i][j];
    }
  }
  int N; cin >> N;
  vector<int> b(N + 1);
  for(int i = 1; i <= N; i++){
    cin >> b[i];
  }
  for(int i = 1; i <= 3; i++){
    for(int j = 1; j <= 3; j++){
      for(int k = 1; k <= N; k++){
        if(A[i][j] == b[k]) A[i][j] = -1;
      }
    }
  }
  bool bingo = false;
  if(A[1][1] == -1 && A[1][2] == -1 && A[1][3] == -1) bingo = true;
  if(A[2][1] == -1 && A[2][2] == -1 && A[2][3] == -1) bingo = true;
  if(A[3][1] == -1 && A[3][2] == -1 && A[3][3] == -1) bingo = true;
  if(A[1][1] == -1 && A[2][1] == -1 && A[3][1] == -1) bingo = true;
  if(A[1][2] == -1 && A[2][2] == -1 && A[3][2] == -1) bingo = true;
  if(A[1][3] == -1 && A[2][3] == -1 && A[3][3] == -1) bingo = true;
  if(A[1][1] == -1 && A[2][2] == -1 && A[3][3] == -1) bingo = true;
  if(A[1][3] == -1 && A[2][2] == -1 && A[3][1] == -1) bingo = true;
  if(bingo) cout << "Yes" << endl;
  if(!bingo) cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

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

char a[23];

int main()
{
	scanf("%s",a); printf("%c%c%c\n",a[0],a[1],a[2]);
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){

    string s;
    cin>>s;
    int total=0;
    for(int i=0;i<s.size();i++){
        total+=s[i]-48;
    }
    if(total==0)
        cout<<"Yes"<<endl;
    else if(total%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


}

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

int main() {
    char s[4]; cin >> s;

    int ans = 0;
    int tmp = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == 'R') ++tmp;
        else {
            ans = max(ans, tmp);
        }
    }
    if (ans == 0) ans = tmp;

    cout << ans << endl;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000000
const int MAX = 1000000;
const int MOD = 1000000007;


int main(){
	int n,k;
    cin>>n>>k;
    vector<ll> s(n+1);
    s[0]=0;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        s[i+1]=s[i]+t;
    }
    REP(i,n+1){
        s[i]=(s[i]-i)%k;
    }
    ll ans=0;
    map<int,int> m;
        for(int i=0;i<min(n+1,k);i++){
            m[s[i]]++;
        }
        for(int i=0;i<n+1;i++){
            ans+=m[s[i]]-1;
            if(i+k<=n) m[s[i+k]]++;
            m[s[i]]--;
        }
    OUT(ans);
	return 0;
}

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

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD = 1000000007
#define INF (1e9)
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll A, B, X;
    cin >> A >> B >> X;
    if (A <= X & A+B >= X) YES;
    else NO;
    return 0;
}


Measured memory_bytes: 256
/*

 Remember, Hope is a good thing... May be the best of things... And No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
const ll inf=(1LL<<60)-1;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
void solve()
{
    ll n;
    cin>>n;
    if(n>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
int main()
{
    IOS;
    //ll t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}


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

#define vint vector<int>
#define vvint vector<vint>
#define sint stack<int>
#define qint queue<int>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
//#define ul unsigned long
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}
// str.substr(開始位置, 取り出す長さ);

void Main(){
    char a;
    cin >> a;
    if('a' <= a && a <= 'z')
    {
        ct('a');
    }else{
        ct('A');
    }

}

int main() {
    Main();
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	
	int N;
	
	int a[1000];
	
	long long int ans;
	
	long long int num1[21][101];
	
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < N - 1; i++){
		for(int j = 0; j < N; j++){
			for(int k = 0; k <= 20; k++){
				num1[k][j] = 0;
			}
		}
		num1[a[0]][0] = 1;
		for(int j = 1; j <= i; j++){
			for(int k = 0; k <= 20; k++){
				if(k + a[j] <= 20){
					num1[k + a[j]][j] += num1[k][j - 1];
				}
				if(k - a[j] >= 0){
					num1[k - a[j]][j] += num1[k][j - 1];
				}
			}
		}
		num1[a[i + 1]][i + 1] = 1;
		for(int j = i + 2; j < N; j++){
			for(int k = 0; k <= 20; k++){
				if(k + a[j] <= 20){
					num1[k + a[j]][j] += num1[k][j - 1];
				}
				if(k - a[j] >= 0){
					num1[k - a[j]][j] += num1[k][j - 1];
				}
			}
		}
		/*
		for(int j = 0; j < N; j++){
			for(int k = 0; k <= 20; k++){
				printf("%lld ", num1[k][j]);
			}
			printf("\n");
		}
		*/
		ans = 0;
		for(int j = 0; j <= 20; j++){
			ans += num1[j][i] * num1[j][N - 1];
		}
	}
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int points[n][3];//points of happines
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>points[i][j];
    }
    vector<int> hapinesA(n),hapinesB(n),hapinesC(n);
    hapinesA[0]=points[0][0];hapinesB[0]=points[0][1];
    hapinesC[0]=points[0][2];
    for(int i=1;i<n;i++)
    {
        hapinesA[i]=points[i][0]+max(hapinesB[i-1],hapinesC[i-1]);
        hapinesB[i]=points[i][1]+max(hapinesA[i-1],hapinesC[i-1]);
        hapinesC[i]=points[i][2]+max(hapinesB[i-1],hapinesA[i-1]);
    }
    int maxi=max(hapinesA[n-1],hapinesB[n-1]);
    maxi=max(maxi,hapinesC[n-1]);
    cout<<maxi;
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int
main()
{
	for (;;) {
		int w, h;
		scanf("%d %d", &h, &w);

		if (w == 0 && h == 0)
			break;

		int x, y;
		for (y = 0; y < h; y++)
		{
			for (x = 0; x < w; x++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 572
import sys
import bisect
N, K = map(int, sys.stdin.readline().split())
V = list(map(int, sys.stdin.readline().split()))

# 累積和を計算しとく
sum_list = [V[0]]
for i in range(1, N):
    add = V[i] + sum_list[-1]
    sum_list.append(add)

ans = 0

max_take = min(N, K)

for A in range(max_take + 1):
    for B in range(max_take - A + 1):
        if A > 0 and B > 0:
            list = V[:A] + V[N - B:]
            total_sum = sum(list) #sum_list[A - 1] + (sum_list[N - 1] - sum_list[N - 1 - B])
            list.sort()
            n = bisect.bisect_left(list, 0)
            if n <= K - (A + B):
                total_sum -= sum(list[:n])
            else:
                total_sum -= sum(list[:K - (A + B)])
        elif A == 0 and B > 0:
            list = V[N - B:]
            total_sum = sum(list) #sum_list[N - 1] - sum_list[N - 1 - B]
            list.sort()
            n = bisect.bisect_left(list, 0)
            if n <= K - (A + B):
                total_sum -= sum(list[:n])
            else:
                total_sum -= sum(list[:K - (A + B)])
        elif A > 0 and B == 0:
            list = V[:A]
            total_sum = sum(list) #sum_list[A - 1]
            list.sort()
            n = bisect.bisect_left(list, 0)
            if n <= K - (A + B):
                total_sum -= sum(list[:n])
            else:
                total_sum -= sum(list[:K - (A + B)])
        else:
            continue
        
        #print("A = " + str(A) + " B = " + str(B))
        #print(total_sum)
        if total_sum > ans:
            ans = total_sum
            
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int N, M;
int C[21];
int dp[51000];

int main(void){
	scanf("%d %d", &N, &M);

	for(int i = 0;i < M;++i){
		scanf("%d", &C[i]);
	}

	memset(dp, 0x3f, sizeof(dp));

	dp[0] = 0;
	for(int i = 0;i < M;++i){
		for(int j = C[i];j < N+1;++j){
			dp[j] = min(dp[j], dp[j - C[i]] + 1);
		}
	}

	printf("%d\n", dp[N]);
}


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

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

Node *NIL = NULL;

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

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

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

void insert(Node* &T, Node *z) {
	Node *y = NIL;
	Node *x = T;
	while (x != NIL) {
		y = x;
		if (z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;

	if (y == NIL)
		T = z;
	else if (z->key < y->key)
		y->left = z;
	else
		y->right = z;
}

bool find(Node* T, int key) {
	Node *x = T;
	if (x == NIL) return false;
	if (x->key == key)
		return true;
	else if (key < x->key)
		return find(x->left, key);
	else
		return find(x->right, key);
}


int main()
{
	int n;
	scanf("%d", &n);

	Node *T = NIL;
	for (int i = 0; i < n; ++i) {
		char cmd[20];
		int v;
		scanf("%s", cmd);
		if (cmd[0] == 'i') {
			scanf("%d", &v);
			Node *p = new Node;
			p->key = v;
			p->left = NIL;
			p->right = NIL;
			insert(T, p);
		} else if (cmd[0] == 'f') {
			scanf("%d", &v);
			printf("%s\n", find(T, v) ? "yes" : "no");
		} else if (cmd[0] == 'p') {
			inorder(T);
			printf("\n");
			preorder(T);
			printf("\n");
		}
	}

	return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  long long ans = K * pow(K - 1, N - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        s: String,
    }

    let vc: Vec<char> = s.chars().collect();
    let mut vx = vec![0; 26];
    let mut vy = vec![0; 26];
    for c in &vc {
        vy[(*c as u8 - b'a') as usize] += 1;
    }

    let mut ans = 0;
    for i in 0..n {
        vx[(vc[i] as u8 - b'a') as usize] += 1;
        vy[(vc[i] as u8 - b'a') as usize] -= 1;

        let mut current = 0;
        for j in 0..26 {
            if vx[j] * vy[j] > 0 {
                current += 1;
            }
        }
        ans = ans.max(current);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2176
# kopipe
from numpy import array as n

N, C = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0],[0],[0],[0]
sum = 0
for x, cal in xy:
    sum += cal
    r1.append(max(r1[-1], sum-x))
    r2.append(max(r2[-1], sum-2*x))
sum = 0
for x, cal in xy[::-1]:
    sum += cal
    l1.append(max(l1[-1], sum-C+x))
    l2.append(max(l2[-1], sum-2*(C-x)))
a = max(n(r1)+n(l2[::-1]))
b = max(n(r2)+n(l1[::-1]))
print(max(a,b))

Measured memory_bytes: 51688
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}



const ll N=1e6+5;

ll dp[N][2];

int main()
{ 

IOS;

string s;cin>>s;

ll n=sz(s);

s='0'+s;
rev(s);

for(int i=0;i<=n;i++){
  ll dig=s[i]-'0';
  if(!i){
    dp[i][0]=10-dig;
    dp[i][1]=dig;
    continue;
  }
  dp[i][1]=min(dig+1+dp[i-1][0],dig+dp[i-1][1]);
  dp[i][0]=min(10-dig+dp[i-1][1],9-dig+dp[i-1][0]);
}

cout<<dp[n][1];


//end_routine();

return 0;
 
 }

Measured memory_bytes: 20120
#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);
  rep(i,n) cin >> a[i];
  vector<int> b(n);
  rep(i,n) b[i]=a[i];
  sort(begin(b),end(b));
  int c=0;
  rep(i,n) {
    if(a[i]!=b[i]) c++;
  }
  if(c<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
    using namespace std;
     
    #define MP make_pair
    #define PB push_back
    #define ALL(x)      (x).begin(),(x).end()
    #define REP(i,n)    for(int i=0;i<(n);i++)
    #define REP1(i,n)   for(int i=1;i<(n);i++)
    #define REP2(i,d,n) for(int i=(d);i<(n);i++)
    #define RREP(i,n)   for(int i=(n);i>=0;i--)
    #define CLR(a)      memset((a),0,sizeof(a))
    #define MCLR(a)     memset((a),-1,sizeof(a))
    #define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
     
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef vector<int> VI;
    typedef vector<VI > VVI;
    typedef vector<string> VS;
    typedef vector<LL> VLL;
    typedef pair<int,int> PII;
     
    const int INF = 0x3f3f3f3f;
    const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
    const double EPS = 1e-9;
     
    const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
     
    int main() {
      int N, x;
      cin >> N;
      VI memo;
      int ans = 0;
      REP(i, N){ 
        cin >> x;
        memo.PB(x-1);
        ans += (x-1 < i && memo[x-1] == i);
      }
      cout << ans << endl;
    }

Measured memory_bytes: 892
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().ToArray();
		string s = char.ToUpper(input[0][0]).ToString();
		string ss = char.ToUpper(input[1][0]).ToString();
		string sss = char.ToUpper(input[2][0]).ToString();
		Console.WriteLine(s + ss + sss);
	}
}


Measured memory_bytes: 13268