akhauriyash/Code-Regression huggingface dataset:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

def factorize(n: int):
    d = Counter()
    m= 2
    
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
            
        m += 1
        
    if n > 1:
        d[n] += 1
        
    return d

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

# 重複組み合わせ
def nHr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if r<0 or n<0:
        return 0
    
    else:
        return nCr(n+r-1,r,mod,fac,facInv)

n,m = li()
MOD = 10**9+7

inv = inv_mod(2*10**5, MOD)
fac = fact(2*10**5, MOD)
facinv = fact_inv(2*10**5,inv,MOD)

md = factorize(m)

ans = 1
for k,v in md.items():
    ans *= nHr(n,v,MOD,fac,facinv)
    ans %= MOD
    
print(ans)


Measured memory_bytes: 27276
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
using namespace std;


int main()
{
	int n, r, p, c, A[51];
	while (true) {
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		else {
			for (int i = 0; i < n; i++)A[i] = n - i;
			for (int i = 0; i < r; i++) {
				cin >> p >> c;
				rotate(A, A + p - 1, A + p + c - 1);
			}
			cout << A[0] << endl;
			for (int i = 0; i < n; i++)A[i] = 0;
		}
	}
	return 0;
}

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

using namespace std;

#define pb      push_back
#define all(x)  x.begin(),x.end()
#define sz(x)   x.size()

const int   N   = 2e5 + 1;
const int   inf = 1e9 + 7;

int n, q, c[N];

struct SegmentTree  {
    int st[N << 2];
    int lz[N << 2];
    #define m   (l + r) / 2

    void push(int i,int l,int r)    {
        if(!lz[i])  return;
        st[i] = min(st[i] + lz[i],inf);
        if(l != r)  {
            lz[i << 1]     += lz[i];
            lz[i << 1 | 1] += lz[i];
        }
        lz[i] = 0;
    }
    void Assi(int i,int l,int r,int p,int v)    {
        push(i,l,r);
        if(l > p || r < p)  return;
        if(l == r)  {
            st[i] = v;
            return;
        }
        Assi(i << 1,l,m,p,v);
        Assi(i << 1 | 1,m + 1,r,p,v);
        st[i] = min(st[i << 1],st[i << 1 | 1]);
    }
    void Plus(int i,int l,int r,int L,int R,int v)  {
        push(i,l,r);
        if(l > R || r < L)  return;
        if(L <= l && r <= R)    {
            lz[i] = v;
            push(i,l,r);
            return;
        }
        Plus(i << 1,l,m,L,R,v);
        Plus(i << 1 | 1,m + 1,r,L,R,v);
        st[i] = min(st[i << 1],st[i << 1 | 1]);
    }
    int get_M(int i,int l,int r,int L,int R)    {
        push(i,l,r);
        if(l > R || r < L)  return inf;
        if(L <= l && r <= R)return st[i];
        return min(get_M(i << 1,l,m,L,R),get_M(i << 1 | 1,m + 1,r,L,R));
    }
}   seg;

vector<int> Q[N];

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

    cin >> n;

    for(int i = 1 ; i <= n ; ++i)
        cin >> c[i];

    int q;  cin >> q;

    while(q--)  {
        int l, r;   cin >> l >> r;
        Q[l].push_back(r);
    }

    for(int i = 1 ; i <= n << 2 ; ++i)
        seg.st[i] = inf,
        seg.lz[i] = 0;

    seg.Assi(1,0,n,0,0);
    for(int i = 1 ; i <= n ; ++i)   {
        sort(all(Q[i]),greater<int>());
        for(int r : Q[i])
            seg.Assi(1,0,n,r,seg.get_M(1,0,n,0,r));
        seg.Plus(1,0,n,0,i - 1,c[i] == 1);
        seg.Plus(1,0,n,i,n,c[i] == 0);
    }

    cout << seg.st[1] << endl;
}


Measured memory_bytes: 16000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int N=60;
bitset<N> g[N],h[N],G[N],H[N],ok,d0,f,dd[N];
int n,u,v,D[N],fa[N],d[N],T;
void dfs(int u){
    f|=h[u];ok[u]=0;
    rep(v,0,n-1) if(g[u][v]&&h[u][v]) dfs(v),f[v]=0;
}
void DFS(int u){rep(v,0,n-1) if(g[u][v]) g[v][u]=0,fa[v]=u,DFS(v);}
void Dfs(int u){rep(v,0,n-1) if(h[u][v]) h[v][u]=0,Dfs(v);}
int goal(int i){
    rep(j,0,n-1) g[j]=G[j],h[j]=H[j],ok[j]=1,D[j]=d[j]-1;
    f=d0=0;g[i]=G[i];h[i]=H[i];DFS(i);Dfs(i);
    dfs(i);++D[i];
    rep(j,0,n-1) if(j^i) d0[j]=!D[j];d0&=ok;
    int cnt=0;
    while(1){
        int x=(f&d0)._Find_first();if(x>=n) break;ok[x]=0;
        f|=h[x];f&=ok;--D[fa[x]];++cnt;
        if(!D[fa[x]]) d0[fa[x]]=1;d0&=ok;
    }
    if(!ok.count()) return cnt;
    else return n+1;
}
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        int ans=n+1;
        rep(i,0,n-1) G[i]=H[i]=0,d[i]=0;ok=0;
        rep(i,1,n-1)
            scanf("%d%d",&u,&v),--u,--v,G[u][v]=1,G[v][u]=1,++d[u],++d[v];
        rep(i,1,n-1) scanf("%d%d",&u,&v),--u,--v,H[u][v]=1,H[v][u]=1;
        rep(i,0,n-1){
            ans=min(ans,goal(i));
            if(H[i].count()==1){
                int c=H[i]._Find_first();H[i][c]=0,H[c][i]=0;
                rep(j,0,n-1) if(i^j){
                    H[i][j]=1,H[j][i]=1;
                    ans=min(ans,goal(i)+1);
                    H[i][j]=0,H[j][i]=0;
                }H[i][c]=1,H[c][i]=1;
            }
        }
        printf("%d\n",ans>n?-1:ans);
    }
    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

struct LargeCombination{
    vector<ll> inv,pre,comb;
    LargeCombination(int n,int mx){
        inv.resize(mx+1);
        pre.resize(mx+1);
        comb.resize(mx+1);
        inv[1]=1;
        pre[1]=n;
        comb[0]=1,comb[1]=n;
        for(int i=2;i<=mx;i++){
            inv[i]=mod-inv[mod%i]*(mod/i)%mod;
            pre[i]=((n-i+1)*inv[i])%mod;
            comb[i]=(comb[i-1]*pre[i])%mod;
        }
    }
    ll operator()(int k){
        return comb[k];
    }
};

int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    LargeCombination comb(n*m-2,k-2);
    ll ans=n*m*(n*m-1)*(n+m)/6;
    ans%=mod;
    ans*=comb(k-2);
    ans%=mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;char T;int l,a,b,x[999],d[999],M,N,y[999],z[999],i,j;main(){while(1){M=0;memset(y,0,999);cin>>b>>l;if(!l){break;}for(i=1;i<=b;i++){cin>>T>>x[i];if(T=='L'){d[i]=0;M=max(M,x[i]);}else{d[i]=1;M=max(M,l-x[i]);}}N=0;for(i=1;i<M+2;i++){memset(z,0,sizeof(z));for(j=b;j>0;j--) {if(!y[j]) {if(!d[j]){x[j]--;}else{x[j]++;}if(x[j]<0||x[j]>l){y[j]=1;}z[x[j]]++;if(M<i){if(N){if(x[j]<0){N=j;}}else{N=j;}}}}for(j=b;j>0;j--){if(z[x[j]]>1){if(d[j]){d[j]=0;}else{d[j]=1;}}}}printf("%d %d\n",M,N);}}

Measured memory_bytes: 1160
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B) =  explode(" ",trim(fgets(STDIN)));
//$X = explode(" ",trim(fgets(STDIN)));

if (($B % $A)==0) {
  printf("%d\n",$A+$B);
}
else {
  printf("%d\n",$B-$A);
}


Measured memory_bytes: 4856
#include <stdio.h>

int main(void)
{
    int kai;
    double t, v, y;
    int i;
    
    
    while (scanf("%lf", &v) != EOF){
        t = v / 9.8;
        y = 4.9 * t * t;
        
        i = 1;
        while (1){
            kai = 5 * i - 5;
            if (y < kai){
                printf("%d\n", i);
                break;
            }
            i++;
        }
    }
    
    return (0);
}

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

int parent[200010],arr[200010],N,M,A,B;

void Initialize(){
	for(int i=1; i<=N; i++){
		parent[i]=i;
	}
}

int FindParent(int a){
	if(parent[a]==a)return a;
	return parent[a]=FindParent(parent[a]);
}

void Join(int a, int b){
	int pa=FindParent(a),pb=FindParent(b);
	if(pa!=pb)parent[pa]=pb;
}

void Input(){
	cin>>N>>M;
	Initialize();
	for(int i=0; i<M; i++){
		cin>>A>>B;
		Join(A,B);
	}
}

void Solve(){
	for(int i=1; i<=N; i++){
		int curr=FindParent(i);
		arr[curr]=arr[curr]+1;
	}
	int maximum=-1;
	for(int i=1; i<=N; i++){
		maximum=max(maximum,arr[i]);
	}
	cout<<maximum<<'\n';
}

int main(){
	Input();
	Solve();
}

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

int main() {
  int K; cin >> K;
  vector<int> A(K);
  for (int i = 0; i < K; i++) cin >> A.at(i);
  reverse(A.begin(), A.end());
  long long N = 2, M = 2;
  for (int i = 0; i < K; i++) {
    // N から M の間に A[i] の倍数があるか
    int r = (N % A.at(i)) ? (N % A.at(i)) : A.at(i);
    if (M < N + A.at(i) - r) { cout << -1 << endl; return 0; }
    N = ((N + A.at(i) - 1) / A.at(i)) * A.at(i);
    M = (M / A.at(i)) * A.at(i) + A.at(i) - 1;
  }
  cout << N << " " << M << endl;
}

Measured memory_bytes: 640
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c = rr(), rr(), rr()
print(a[0] + b[1] + c[-1])















Measured memory_bytes: 26984
lines = []
colums = []
 
while True:
  H,W = map(int,input().split())
  if H == 0 and W == 0:
    break
  lines.append(H)
  colums.append(W)
 
for H,W in zip(lines,colums):
  for i in range(H):
    for j in range(W):
      print("#",end="")
    print("\n",end="")
  print("\n",end="")


Measured memory_bytes: 7016
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n ;
    vector<int>v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    int cnt = 0;
    for(int i=1;i<n-1;i++) {
        if(v[i] > v[i-1] && v[i] < v[i+1]) cnt++;
        else if(v[i] < v[i-1] && v[i] > v[i+1] ) cnt++;
    }

    cout << cnt << endl;
    
}

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

namespace TYC
{
	typedef long long ll;
	const int p = 1000000007;
	const int N = 2e5 + 5;

	int n, vis[N], fac[N], inv[N], invfac[N], size[N], fa[N], onloop[N];
	vector<int> E[N], tr[N], node, loop;

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	void init()
	{
		fac[0] = invfac[0] = inv[1] = 1;
		for (int i = 1; i <= n; i++)
			fac[i] = (ll)fac[i - 1] * i % p;
		for (int i = 2; i <= n; i++)
			inv[i] = (ll)inv[p % i] * (p - p / i) % p;
		for (int i = 1; i <= n; i++)
			invfac[i] = (ll)invfac[i - 1] * inv[i] % p;
	}

	void dfs1(const int u, const int f)
	{
		vis[u] = 1;
		node.push_back(u);
		for (auto v : E[u])
			if (v != f && !vis[v])
				dfs1(v, u);
	}

	bool findloop(const int u, const int f)
	{
		static int top, sta[N], in[N];
		sta[++top] = u, in[u] = 1;
		for (auto v : E[u])
			if (v != f)
			{
				if (in[v])
				{
					do 		
					{
						loop.push_back(sta[top]);
						onloop[sta[top--]] = 1;
					}
					while (sta[top + 1] != v);
					return true;
				}
				else if (findloop(v, u))
					return true;
			}
		--top, in[u] = 0;
		return false;
	}

	void dfs2(const int u)
	{
		for (auto v : E[u])
			if (v != fa[u] && !onloop[v])
				fa[v] = u, dfs2(v);
	}

	void dfs3(const int u)
	{
		size[u] = 1;
		for (auto v : tr[u])
			dfs3(v), size[u] += size[v];
	}	

	int calc()
	{
		static int in[N];
		for (auto i : node)
			for (auto j : E[i])
				if (j < fa[i])
					tr[i].push_back(j), ++in[j];
		for (auto i : node)
			if (!in[i])
				tr[0].push_back(i);
		dfs3(0);
		tr[0].clear();
		for (auto i : node)
			tr[i].clear(), in[i] = 0;
		int ans = fac[size[0] - 1];
		for (auto i : node)
			ans = (ll)ans * inv[size[i]] % p;
		return ans;
	}

	int solve(const int x)
	{
		node.clear();
		dfs1(x, 0);
		int nc = node.size(), ec = 0;
		for (auto i : node)
			ec += E[i].size();
		if ((ec >> 1) != nc)
			return 0;

		loop.clear();
		findloop(x, 0);
		for (auto i : loop)
			dfs2(i);

		int tot = loop.size(), u = loop[tot - 1], v = loop[0];
		for (int i = 1; i < tot; i++)
			if (loop[i - 1] + loop[i] > u + v)
				u = loop[i - 1], v = loop[i];
		E[u].erase(find(E[u].begin(), E[u].end(), v));
		E[v].erase(find(E[v].begin(), E[v].end(), u));

		fa[loop[0]] = loop[tot - 1];
		for (int i = 1; i < tot; i++)
			fa[loop[i]] = loop[i - 1];
		int sum = calc();

		fa[loop[tot - 1]] = loop[0];
		for (int i = 1; i < tot; i++)
			fa[loop[i - 1]] = loop[i];
		return int((ll)(sum + calc()) % p * invfac[nc] % p);
	}

	void work()
	{
		n = read() << 1;
		init();
		for (int i = 1; i <= n; i++)
		{
			int x = read(), y = read() + (n >> 1);
			E[x].push_back(y);
			E[y].push_back(x);
		}
		int ans = fac[n];
		for (int i = 1; i <= n && ans; i++)
			if (!vis[i])
				ans = (ll)ans * solve(i) % p;
		printf("%d\n", ans);
	}
}

int main()
{
#ifdef DINO
	freopen("3537.in", "r", stdin);
	freopen("3537.out", "w", stdout);
#endif
	TYC::work();
	return 0;
}

Measured memory_bytes: 30968
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>
using namespace std;
int read()
{
	char ch=getchar();
	int num=0,flus=1;
	while(ch<'0'||ch>'9')
	{if(ch=='-') flus=-flus;ch=getchar();}
	while(ch>='0'&&ch<='9')
	{num=num*10+ch-'0';ch=getchar();}
	return num*flus;
}
const int MAXN=2e5+2e2;
int a[MAXN];
int n,p=1,cnt=1,tot=0;
int main(void)
{
	// freopen("working.in","r",stdin);
	// freopen("working.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	while(p<=n)
	{
		if(a[p]==cnt)
			++cnt;
		else ++tot;
		++p;
	}
	if(cnt==1) puts("-1");
	else printf("%d\n",tot);
	return 0;
}
//	freopen("working.in","r",stdin);
//	freopen("working.out","w",stdout);

Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int W, H;
bool used[110][110];
char ma[110][110];

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

void dfs(int x, int y, char ch){
  if(used[y][x] || ma[y][x] != ch) return;
  used[y][x] = true;

  REP(i,4)
	dfs(x+dx[i], y+dy[i], ch);
}

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

  while(true){
	cin >> H >> W;
	if(W == H && H == 0) break;
	fill((char*)ma, (char*)ma+110*110, 0);
	REP(y,H)
	  REP(x,W)
	  cin >> ma[y+1][x+1];

	fill((bool*)used, (bool*)used + 110*110, false);
	int cnt = 0;
	for(int y=1;y<=H;++y)
	  for(int x=1;x<=W;++x)
		if(!used[y][x]){
		  ++cnt;
		  dfs(x,y, ma[y][x]);
		}
	cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1684
# これは, u749194f さんの改造です。
# オリジナルではございません。
# https://atcoder.jp/contests/abc162/submissions/11825963
n = int(input())
s = input()
flag = True
if len(set(s))<=2:
    print(0)
    flag = False
if flag:
    r = [i for i in range(n) if s[i]=='R']
    b = [i for i in range(n) if s[i]=='B']
    g = [i for i in range(n) if s[i]=='G']
    minus = 0
    def cnt_cmb(a, b, c):
        cnt = 0
        set_a = set(a)
        set_b = set(b)
        set_c = set(c)
        for i in set_a:
            for j in set_b:
                if (i+j)/2 in set_c:
                    cnt += 1
        return cnt
    minus += cnt_cmb(r, b, g)
    minus += cnt_cmb(b, g, r)
    minus += cnt_cmb(g, r, b)
    print(len(r)*len(b)*len(g)-minus)

Measured memory_bytes: 68080
from collections import Counter

S = input()
c = Counter(S)

if len(c) == 1:
    print(0)
    exit(0)

cbi = Counter([S[i:i+2] for i in range(len(S) - 1)])
counter = 0
if 'BW' in cbi:
    counter += cbi['BW']
if 'WB' in cbi:
    counter += cbi['WB']
print(counter)

Measured memory_bytes: 48752
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N;
std::string s;
mint dp[3010][3010], dpS[3010];

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

  rep( j, N )
    dp[1][j] = 1;

  repi( i, 1, N ) {
    dpS[0] = 0;

    rep( j, N-i+1 ) {
      dpS[j+1] = dpS[j]+dp[i][j];
    }

    rep( j, N-i+1 ) {
      if( s[i-1] == '<' )
        dp[i+1][j] += dpS[N-i+1]-dpS[j+1];
      else
        dp[i+1][j] += dpS[j+1];
    }
  }

  std::cout << dp[N][0].x << endl;

  return 0;
}

Measured memory_bytes: 74448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=2e5+1;
int n;
ll a[N];
pair<ll,int>b[N];
vector<int>adj[N];

ll dp[N];
ll tmp[N];
const int ts=1<<19;
ll mx[ts];
void upd(int id,int l,int r,int p,int v){
	if(l==r){
		mx[id]=v;
		return;
	}
	int mid=(l+r)/2;
	if(p<=mid) upd(id*2,l,mid,p,v);
	else upd(id*2+1,mid+1,r,p,v);
	mx[id]=max(mx[id*2],mx[id*2+1]);
}
ll qry(int id,int l,int r,int ql,int qr){
	if(l>qr || r<ql) return 0;
	if(ql<=l && r<=qr) return mx[id];
	int mid=(l+r)/2;
	return max(qry(id*2,l,mid,ql,qr),qry(id*2+1,mid+1,r,ql,qr)); 
}
void dfs(int id,int p){
	if(a[id]!=1) dp[id]=qry(1,1,n,1,a[id]-1)+1;
	else dp[id]=1;
	tmp[id]=qry(1,1,n,a[id],a[id]);
	upd(1,1,n,a[id],dp[id]);
	for(auto x:adj[id]){
		if(x==p) continue;
		dfs(x,id);
	}
	upd(1,1,n,a[id],tmp[id]);
}
void dfs2(int id,int p){
	dp[id]=max(dp[id],dp[p]);
	for(auto x:adj[id]){
		if(x==p) continue;
		dfs2(x,id);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n ;i++){
		cin >> a[i];
		b[i]={a[i],i};
	}
	sort(b+1,b+n+1);
	for(int i=1; i<=n ;i++){
		a[i]=lower_bound(b+1,b+n+1,pair<ll,int>{a[i],0})-b;
	}
	for(int i=1; i<n ;i++){
		int u,v;cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1,0);
	dfs2(1,0);
	for(int i=1; i<=n ;i++){
		cout << dp[i] << '\n';
	}
}

Measured memory_bytes: 37696
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) cin >> c[i];
    sort(all(a)), sort(all(b)), sort(all(c));
    ll ans = 0;
    rep(i, 0, n)
    {
        ll r = lower_bound(all(a), b[i]) - a.begin();
        ll l = c.end() - upper_bound(all(c), b[i]);
        ans += r * l;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
(let ((n (read))
      (ans t))
  (loop :for i :from 1 :to n
        :for a := (read)
        :if (and (evenp a)
                 (/= (mod a 3) 0)
                 (/= (mod a 5) 0))
        :do (setf ans nil))
  (if ans
      (format t "APPROVED~%")
      (format t "DENIED~%")))


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

int main() {
    vector<int> cnt(3,0);
    string s; cin>>s;
    for (char c : s) {
        cnt[(int) (c-'a')]++;
    }
    if (abs(cnt[0] - cnt[1]) <= 1 && 
    abs(cnt[0] - cnt[2]) <= 1 && 
    abs(cnt[1] - cnt[2]) <= 1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 3732
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.LinkedList;

public class Main{
	public class pair implements Comparable<pair> {
		int wt;
		int val;
		double rat;

		pair(int a, int v) {
			wt = a;
			val = v;
			rat = v / wt;
		}

		@Override
		public int compareTo(pair o) {
			// TODO Auto-generated method stub
			return (int) (this.rat - o.rat);
		}

	}

	public static long mod = (long) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		double head[] = new double[n];
		double tail[] = new double[n];
		for (int i = 0; i < n; i++) {
			head[i] = scn.nextDouble();
			tail[i] = 1 - head[i];
		}
		double dp[][] = new double[n][n + 1];
		dp[0][0] = tail[0];
		dp[0][1] = head[0];
		for (int i = 1; i < n; i++) {
			for (int j = 0; j <= n; j++) {
				dp[i][j] = dp[i - 1][j] * tail[i] + (j>0?dp[i - 1][j - 1] * head[i]:0);
			}
		}
		double ans = 0;
		for (int i = n / 2 + 1; i <= n; i++) {
			ans += dp[n - 1][i];
		}
		System.out.println(ans);

	}

	private static int dfs(int sr, HashSet<Integer> hset, int[] dp, ArrayList<Integer>[] g) {
		if (hset.contains(sr)) {
			return dp[sr];
		}
		hset.add(sr);
		int res = -1;
		for (int nei : g[sr]) {
			res = Math.max(res, dfs(nei, hset, dp, g));
		}
		dp[sr] = Math.max(dp[sr], res + 1);
		return dp[sr];

	}

}

Measured memory_bytes: 125524
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DGameOnTree {
public:
    vector<vector<int>> G;

    int dfs(int v, int p) {
        int res = 0;
        for (auto to : G[v]) {
            if (to == p) continue;
            int tmp = dfs(to, v);
            res ^= (tmp + 1);
        }
        return res;
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        G.resize(N);
        REP(i, N - 1) {
            int x, y;
            cin >> x >> y;
            x--, y--;
            G[x].push_back(y);
            G[y].push_back(x);
        }
        int ans = dfs(0, -1);
        cout << (ans > 0 ? "Alice" : "Bob") << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DGameOnTree solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
#define ll long long
#define F(type, i, a, b) for(type i = a; i <= b; i ++)
#define RF(type, i, a, b) for(type i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cerr<<" ["<<#a<<"->"<<a<<"] "
#define next_line cerr<<'\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it ++)

using namespace std;

typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;

void solve()
{
    //If you cannot approach a problem
    //directly in the way it is proposed then try to think from backwards
    ll n, d;
    cin>>n>>d;
    d *= d;
    ll c = 0;
    F(ll, i, 1, n){
        ll  x,y;
        cin>>x>>y;
        ll dis = (x * x) + (y * y);
        if(dis <= d)
            c++;
    }
    cout<<c<<'\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        freopen("Debug.txt", "w", stderr);
    #else
    #endif
    solve();
}


Measured memory_bytes: 3652
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n, m int
	fmt.Fscan(read, &n, &m)

	dp := make([]int, n+1)
	for i := 0; i < m; i++ {
		var a int
		fmt.Fscan(read, &a)
		dp[a] = -1
	}
	dp[0] = 1
	mod := 1000000007
	for i := 0; i < n; i++ {
		if dp[i] == -1 {
			continue
		}
		for j := 1; j <= 2; j++ {
			if i+j > n || dp[i+j] == -1 {
				continue
			}
			dp[i+j] += dp[i]
			dp[i+j] %= mod
		}
	}
	fmt.Fprintln(write, dp[n])
}


Measured memory_bytes: 3072
n=int(input())
x=[int(i) for i in input().split()]

nn=n//2
y=x[:]
x.sort()
low_median=x[nn-1]
high_median=x[nn]

[print(high_median) if y[i]<high_median  else print(low_median)  for i in range(n) ] 

"""
for i in range(n):
  if y[i]<high_median:
    print(high_median)
  else:
    print(low_median)
"""

Measured memory_bytes: 25348
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<ll, ll> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	
	vector<pii> v(n);
	
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		v[i] = {a + b, a - b};
	}
	
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++)
		swap(v[i].first, v[i].second);
	
	int ans = 1;
	int last = 0;
	
	for(int i = 1; i < n; i++){
		if(v[i].first >= v[last].second){
			ans++;
			last = i;
		}
	}
	
	cout << ans << endl;

	return 0;
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    int d;
    cin>>d;
    vector<int> c(26);
    rep(i,26){ 
        cin>>c[i];
    }
    vector<vector<int>> s(d ,vector<int>(26));
    rep(i,d) rep(j,26) cin>>s[i][j];
    int t;
    vector<vector<int>> last(d ,vector<int>(26));
    int v=0;
    vector<int> kaisai_bi(26);
    int ans=18398+s[1][16];
    rep(j,26){
        if(j==16)continue;
        else if(j==0)ans-=c[j]*(2-1);
        else ans-=c[j]*(2-0);
    }
    rep(i,d) {
        cin>>t;
        t--;
        v+=s[i][t];
        kaisai_bi[t]=i+1;
        rep(j,26) last[i][j]=kaisai_bi[j];
        rep(j,26){ 
            v-=c[j]*(i+1-last[i][j]);
//            if(i==1)cout<<j<<" "<<c[j]*(i+1-last[i][j])<<endl;
            }
        cout<<v<<endl;
    }
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001;
const ll INF=1LL<<50;

vector<pair<int,ll>> S[MAX];
vector<int> T;
vector<ll> U;
int color[MAX];
ll score[MAX];
bool ok=true;

void DFS(int u,ll v){
    stack<int> ST;
    color[u]=1;
    score[u]=v;
    ST.push(u);
    while(!ST.empty()){
        int a=ST.top();
        ST.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i].first;
            ll c=S[a][i].second;
            if(color[b]==0){
                if(color[a]==1) color[b]=2;
                else color[b]=1;
                score[b]=c-score[a];
                ST.push(b);
            }else{
                if(color[a]==color[b]){
                    ok=false;
                    if(T.size()==0){
                        T.push_back(b);
                        U.push_back(score[b]);
                        U.push_back(c-score[a]);
                    }
                }
            }
        }
    }
}

int main(){
    
    int N,M;cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;
        ll c;cin>>a>>b>>c;
        a--;b--;
        S[a].push_back(make_pair(b,c));
        S[b].push_back(make_pair(a,c));
    }
    
    DFS(0,1);
    
    if(ok){
        ll amini=INF,bmini=INF,amaxi=-INF,bmaxi=-INF;
        for(int i=0;i<N;i++){
            if(color[i]==1){
                amini=min(amini,score[i]);
                amaxi=max(amaxi,score[i]);
            }else{
                bmini=min(bmini,score[i]);
                bmaxi=max(bmaxi,score[i]);
            }
        }
        
        for(int i=0;i<N;i++){
            for(int j=0;j<S[i].size();j++){
                int a=S[i][j].first;
                ll b=S[i][j].second;
                if(score[i]+score[a]!=b) ok=false;
            }
        }
        
        if(amini>0&&bmini>0&&ok){
            cout<<bmini<<endl;
        }else if((amini>0&&bmini<=0)||!ok){
            cout<<0<<endl;
        }else if(amini<=0&&ok){
            cout<<max(0LL,bmini-abs(amini-1))<<endl;
        }
    }else{
        for(int i=0;i<N;i++){
            score[i]=0;
            color[i]=0;
        }
        DFS(T[0],(U[0]+U[1])/2);
        bool flag=true;
        if((U[0]+U[1])%2) flag=false;
        for(int i=0;i<N;i++){
            for(int j=0;j<S[i].size();j++){
                int a=S[i][j].first;
                ll b=S[i][j].second;
                if(score[i]+score[a]!=b||score[i]<=0||score[a]<=0) flag=false;
            }
        }
        
        if(flag) cout<<1<<endl;
        else cout<<0<<endl;
        
    }
    
}


Measured memory_bytes: 9216
import random


def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)


def lcm(a, b):
    return (a * b) / gcd(a, b)
a,b,c,d=map(int, input().split())
#print(min(a,b)*min(d,c),max(a,b)*max(c,d))
print(max(min(a,b)*max(d,c),max(a,b)*min(c,d),min(a,b)*min(d,c),max(a,b)*max(d,c)))

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

const int maxn = 2e5 + 5;
int p[maxn], len[maxn];

int findSet(int x) {
    if (x == p[x]) return x;
    return p[x] = findSet(p[x]);
}

void unionSet(int x, int y) {
    x = findSet(x), y = findSet(y);
    if (x == y) return;
    p[y] = x;
    len[x] += len[y];
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    iota(p, p + maxn, 0);
    fill_n(len, maxn, 1);

    int n, m;
    cin >> n >> m;
    while (m--) {
        int u, v;
        cin >> u >> v;

        unionSet(--u, --v);
    }

    int mx = 0;
    for (int i = 0; i < n; i++) mx = max(mx, len[i]);
    cout << mx;
}


Measured memory_bytes: 5212
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector <int>
#define vl vector <long long>
#define pb push_back
#define mk make_pair
#define pi pair <int,int>
#define pl pair <ll,ll>
#define rep(i,a,n) for(int i=a;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define rep_(i,a,n) for(int i=(n-1);i>=a;i--)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b});
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int h = s / 3600;
    s -= h*3600;
    int m = s / 60;
    s -= m*60;
    System.out.println(h+":"+m+":"+s);
  }
}


Measured memory_bytes: 26352
#include <stdio.h>

int main(){
  int i,k,a;
  for(i = 1; i <= 9; i++){
    for(k = 1; k <= 9; k++){
      a = i*k;
      printf("%dx%d=%d\n", i, k, a);
    }
  }
  return 0;
}

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
const int INF=1001001001001001001ll;

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};

int N,M,r;
vector<edge>G[100000];
int dist[100000];

signed main(){
    scanf("%lld%lld%lld",&N,&M,&r);
    rep(i,M){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        G[a].pb(edge(b,c));
        //G[b].pb(edge(a,c));
    }

    fill_n(dist,N,INF);
    priority_queue<pint,vector<pint>,greater<pint> >que;
    que.push(pint(0,r));
    dist[r]=0;

    while(que.size()){
        pint p=que.top();que.pop();
        if(dist[p.second]<p.first)continue;
        rep(i,G[p.second].size()){
            edge &e=G[p.second][i];
            if(dist[e.to]<=p.first+e.cost)continue;
            dist[e.to]=p.first+e.cost;
            que.push(pint(dist[e.to],e.to));
        }
    }

    rep(i,N){
        if(dist[i]==INF)cout<<"INF"<<endl;
        else cout<<dist[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 17696
N,M = map(int,input().split())
KL = [list(map(int,input().split())) for _ in [0]*N ]

E = [[[] for _ in [0]*N] , [[] for _ in [0]*M]]
for i,kl in enumerate(KL):
    for l in kl[1:]:
        E[0][i].append(l-1)
        E[1][l-1].append(i)

Check = [[False]*N,[False]*M]
Check[0][0] = True
q = [[0,0]]
while q:
    cl,i = q.pop()
    for j in E[cl][i]:
        if Check[1-cl][j]:continue
        q.append([1-cl,j])
        Check[1-cl][j] = True

if sum(Check[0]) == N:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 57968
#include <stdio.h>

int main(void)
{
    int n[3];
    int tmp, i, j;
    
    for(i=0; i<3; i++){
        scanf("%d", &n[i]);
    }
    
    for(i=0; i<3-1; i++){
        for(j=i+1; j<3; j++){
            if(n[i]>n[j]){
                tmp = n[i];
                n[i] = n[j];
                n[j] = tmp;
            }
        }
    }
    
    printf("%d %d %d\n", n[0], n[1], n[2]);
    
    return 0;
}

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

int main(){
  char b;
  cin >> b;
  
  if(b=='A'){
    cout << 'T' << endl;
  }else if(b=='T'){
    cout << 'A' << endl;
  }else if(b=='G'){
    cout << 'C' << endl;
  }else{
    cout << 'G' << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 10000000000;
const ll MOD = 1000000007;
const ll MAX = 55;

ll pow2(ll N){
    ll ans;
    if(N == 0){
        ans = 1;
    }
    else if(N == 1){
        ans = 2;
    }
    else{
        ans = pow2(N/2) * pow2((N+1)/2);
    }
    return ans;
}

int main() {
    ll N,P;
    cin >> N >> P;
    bool a = false;
    int tmp;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        if(tmp % 2 == 1){
            a = true;
            break;
        }
    }
    if( (P == 1) && !a ){
        printf("0");
        return 0;
    }
    
    if(a){
        printf("%lld", pow2(N-1));
    }
    else{
        printf("%lld", pow2(N));
    }
    
}


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

int main(){
  long r=0,buf,n,i;
  cin>>n;

  if(n>2) r=n-1;
  for(i=2;i<=(long)(sqrt((double)n));i++){
    if(n%i==0){//iはnの約数
      buf=(n-i)/i;//mの候補
      if(n/buf==n%buf) r+=buf;
      if(i*i!=n){
        buf=n/i;
        buf=(n-buf)/buf;
        if(n/buf==n%buf) r+=buf;
      }
    }
  }

  cout<<r<<endl;
  return 0;
}

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

int keta(int i){
  int sum = 0;
  while(i>0){
    int n = i%10;
    sum += n;
    i /= 10;
  }
  return sum;
}
    

int main(){
  int N;
  cin >> N;
  
  int min = 100;
  
  for(int i=1; i<N;i++){
    int ketawa = keta(i) + keta(N-i);
    if(ketawa < min){
      min = ketawa;
    }
  }
  cout << min << endl;
  
  
}

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

long long n;
string s;
vector<int> p, res;
vector<vector<int>> memo;

void prepair(int dep, int id, const vector<int> &v);
int calc(int x, int y);

int main() {
  cin >> n >> s;
  p.resize(1 << n);
  res.assign(1 << n, 0);
  memo.assign(n, vector<int>(2, -1));
  for(int i = 0; i < (1 << n); ++i) cin >> p[i];
  prepair(0, 0, p);
  for(int i = 0; i < (1 << n); ++i) cout << res[i] << endl;
  return 0;
}

void prepair(int dep, int id, const vector<int> &v) {
  if(dep == n) {
    assert(v.size() == 1);
    res[id] = v[0];
    return;
  }
  int vsize = v.size();
  vector<int> to;
  // pattern 0
  for(int i = 0; i < vsize; i += 2)
    to.push_back(calc(v[i], v[i + 1]));
  prepair(dep + 1, id, to);
  // pattern 1
  to.clear();
  for(int i = 0; i < vsize; i += 2)
    to.push_back(calc(v[i + 1], v[(i + 2) % vsize]));
  prepair(dep + 1, id + (1 << dep), to);
}

int calc(int x, int y) {
  if(x > y) swap(x, y);
  return (s[y - x - 1] == '1') ? y : x;
}


Measured memory_bytes: 6308
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
int INF = 1LL<<60;
int MOD = 1e9+7;
 
string to_string(char &c) {string x(1, c); return x;}
string to_string(string &s) {return s;}
string to_string(const char s[]) {return (string)s;}
template <class C> string to_string(C &v) {
    string res;
    for (auto &x : v) res += to_string(x) + ' ';
    return res;
}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {
    for (auto &x : v) is >> x;
    return is;
}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {
    os << '(' << pr.first << ", " << pr.second << ')';
    return os;
}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
template <class Container> ostream &operator<<(ostream &os, Container &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ',' << ' ';
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

vi fact;
int nCk(int n, int k) {
    if (k<0||k>n) return 0;
    return fact[n]*inv(fact[k]) % MOD * inv(fact[n-k]) % MOD;
}
 
main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi a(n);
    cin >> a;
    sort(a.rbegin(), a.rend());
    vi pref = a, suff=a;
    REP(i, 1, n) pref[i] = (pref[i]+pref[i-1]) % MOD;
    RREP(i, n-2, -1) suff[i] = (suff[i]+suff[i+1]) % MOD;

    fact.resize(n+1); fact[0] = 1;
    REP(i, 1, n+1) fact[i] = i*fact[i-1] % MOD;

    int res = 0;
    REP(gap, k-2, n-1) {
        int temp = nCk(gap, k-2) * (pref[n-gap-2] - suff[gap+1] + MOD) % MOD;
        res = (res+temp) % MOD;
    }
    print(res);
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s1, s2;
  cin >> s1 >> s2;
  int n = s1.size(), m = s2.size();
  vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
  rep(i, n+1) dp[i][0] = i;
  rep(j, m+1) dp[0][j] = j;
  
  rep(i, n) rep(j, m) {
    if(s1[i] == s2[j]) dp[i+1][j+1] = min(dp[i][j], min(dp[i+1][j]+1, dp[i][j+1]+1));
    else dp[i+1][j+1] = min(dp[i][j]+1, min(dp[i+1][j]+1, dp[i][j+1]+1));
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 6756
#include <stdio.h>

int main(void) {
    int a, b, c, x, res;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (((500 * i) + (100 * j) + (50 * k)) == x) {
                    res++;
                }
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 128