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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int X, Y, Z; cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    platform_count, jumping_power = [int(x) for x in input().split()]
    platforms = [int(x) for x in input().split()]
    dp = [0]
    for i in range(1, platform_count):
        indexes = (i - x for x in range(1, jumping_power + 1) if i - x >= 0)
        dp.append(
            min(abs(platforms[i] - platforms[before]) + dp[before]
                for before in indexes))
    print(dp[platform_count - 1])


if __name__ == '__main__':
    main()


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

int main() {
    long long s; cin >> s;
    unordered_set<long long> t;
    int count = 1;
    while (t.find(s) == t.end()) {
        count++;
        t.insert(s);
        if (s % 2 == 0) s /= 2;
        else s = 3 * s + 1;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000000;
int h, w;
vector<string> maze(22);

int di[] = {-1, 0, 1, 0};
int dj[] = {0, -1, 0, 1};

int bfs(int si, int sj) {
  vector<vector<int>> d(h, vector<int>(w, INF));
  queue<P> que;
  que.push(P(si, sj));
  d[si][sj] = 0;
  while(que.size()) {
    P p = que.front();
    que.pop();
    rep(dir, 4) {
      int ni = p.first + di[dir];
      int nj = p.second + dj[dir];
      if(0 <= ni && ni < h && 0 <= nj && nj < w
         && maze[ni][nj] == '.' && d[ni][nj] == INF) {
        que.push(P(ni, nj));
        d[ni][nj] = d[p.first][p.second] + 1;
      }
    }
  }
  int res = 0;
  rep(i, h) rep(j, w) if(maze[i][j] == '.') res =
    max(res, d[i][j]);
  return res;
}

int main(void) {
  cin >> h >> w;
  rep(i, h) cin >> maze[i];
  int ans = 0;
  rep(i, h) rep(j, w) {
    if(maze[i][j] == '.') {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()

if len(s)%2 == 1:
    if s[:len(s)//2] == s[len(s)//2 + 1:]:
        print("Yes")
    else:
        print("No")
else:
    if s[:len(s)//2] == s[len(s)//2:]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
bool IsNumber(char c)
{
    return c >= '0' && c <= '9';
}

bool IsValidPostalCode(int A, int B, const string& S)
{
    if (S[A] != '-') return false;
    rep(i, 0, A)
    {
        if (!IsNumber(S[i])) return false;
    }
    rep(i, A + 1, S.size())
    {
        if (!IsNumber(S[i])) return false;
    }
    return true;
}

void _main()
{
    int A, B;
    string S;
    cin >> A >> B >> S;
    cout << (IsValidPostalCode(A, B, S) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const K = parseInt(args[0][1], 10)
	console.log(K * Math.pow(K - 1, N - 1))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <stdio.h>

int main()
{
	int n, l, r, i, sum = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%d %d", &l, &r);
		sum += r - l + 1;
	}

	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
const int N=105,MOD=998244353,H0=19260817,H1=2333;
char s[N],t[N];
ll f[N][2],g[N][2];
int n,ans;
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	ll t0=1,t1=1;
	for(int i=n;i;i--)
	{
		f[i][0]=(f[i+1][0]+t0*s[i])%MOD;
		f[i][1]=(f[i+1][1]+t1*s[i])%MOD;
		t0=t0*H0%MOD;
		t1=t1*H1%MOD;
	}
	for(int i=1;i<=n;i++)
	{
		g[i][0]=(g[i-1][0]*H0+t[i])%MOD;
		g[i][1]=(g[i-1][1]*H1+t[i])%MOD;
	}
	ans=0;
	for(int i=1;i<=n;i++)
		if(f[i][0]==g[n-i+1][0] && f[i][1]==g[n-i+1][1])
		{
			ans=n-i+1;
			break;
		}
	printf("%d\n",n*2-ans);
	return 0;
}


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

typedef long long ll;

#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846264338327950L

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int a, b, h, m; cin >> a >> b >> h >> m;
    long double degreeA = (h * 60 + m) * 0.5;
    long double degreeB = m * 6;
    if (degreeB == 0) degreeB = 360;
    long double difference = max(degreeA, degreeB) - min(degreeA, degreeB);
    long double ans = sqrt(pow(a, 2) + pow(b, 2) - 2.0 * a * b * cos((long double)PI * difference / 180.0));
    cout << setprecision(20) << ans << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/



Measured memory_bytes: 4124
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

ll dp[100005];




int main()
{
    run;
    ll n;
    cin>>n;
    ll a[n];
    fr(i,0,n)
    {
        cin>>a[i];


    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);

    fr(i,2,n)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1];





}


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

public class Main {

	public static void main(String[] args)
	{
			Scanner in = new Scanner(System.in);
			int n = in.nextInt(), d = in.nextInt(), x = in.nextInt();
			int A[] = new int[n];  
			for(int i = 0; i < n; i++)
				A[i] = in.nextInt();

			int ans = 0;

			for(int i = 0; i < n; i++)
			{
				int val = 0;
				int coeff = 0;
				while(val <= d)
				{
					val = coeff * A[i] + 1;
					if(val > d)
						break;
					coeff++;
					ans += 1;
				}
			}
			ans += x;
			System.out.println(ans);
	}
    
}

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

const int N = 100010;

int d[N], ans[N];
vector<int> G[N];
queue<int> q;

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=1; i<=m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	d[1] = 1;
	q.push(1);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int& v: G[u]) {
			if(d[v])
				continue;
			d[v] = d[u]+1;
			ans[v] = u;
			q.push(v);
		}
	}
	printf("Yes\n");
	for(int i=2; i<=n; i++)
		printf("%d\n", ans[i]);
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  ll N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (N <= K)
  {
    cout << N * X << endl;
  }else{
    cout << (N - K) * Y + K * X << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N, K, C = map(int, input().split())
S = list(input())


dp1 = [0] * (N + 1)  # iまでで何回働けるか
dp1[0] = 0
for i, s in enumerate(S, start=1):
    if s == 'x':
        dp1[i] = dp1[i - 1]
        continue
    b = max(0, i - C - 1)
    dp1[i] = dp1[b] + 1


dp2 = [0] * (N + 1)  # i以降で何回働けるか
for i in reversed(range(N)):
    s = S[i]
    if s == 'x':
        dp2[i] = dp2[i + 1]
        continue
    b = min(N, i + C + 1)
    dp2[i] = dp2[b] + 1


ans = []
# i番目のやつを使わなくてもK個取れるか？
for i in range(1, N + 1):
    if dp1[i - 1] + dp2[i] < K:
        ans.append(i)

print(*ans, sep="\n")


Measured memory_bytes: 33112
#include <bits/stdc++.h>
using namespace std;
 
#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
 #define PI acos(-1)
 #define MOD ((int)1e9+7)
typedef long long     ll;
 
//-*-*-*-*-*-*-*-*-
 
 

 
const int N=2e5+100;
ll visited[100005];
//ll a[200000];
 

#define lop(i,n) for(int i=0;i<n;++i)
//ll n,m,mod;

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

const int MAX = 2e5 + 10 ;
void finis(){cout<<-1;}
vector<ll>v[1000000];


ll h,w,n,m;

int main()
{  ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;ll o=1000;//o*=1000;
while(o<n){o+=1000;}
cout<<o-n;}


Measured memory_bytes: 27040
def main():
    A, B, K = map(int, input().split())
    cnt = 0
    while K > 0:
        if cnt % 2 == 0:
            if A % 2 == 0:
                A //= 2
                B += A
            else:
                A -= 1
                A //= 2
                B += A
        else:
            if B % 2 == 0:
                B //= 2
                A += B
            else:
                B -= 1
                B //= 2
                A += B
        cnt += 1
        K -= 1

    print(A, B)

if __name__ == "__main__":
    main()

Measured memory_bytes: 61820
from collections import deque

S = input()
D = deque(S)
C = deque(S)
Q = int(input())

conr = 0

for i in range(Q):
  q = list(input().split())
  if q[0] == "1":
    conr += 1
  else:
    s = q[-1]
    f = int(q[1])
    if conr % 2 == 0:
      if f == 1:
        D.appendleft(s)
      else:
        D.append(s)
    else:
      if f == 1:
        D.append(s)
      else:
        D.appendleft(s)

D = list(D)
if conr % 2 == 1:
  D = D[::-1]
ans = "".join(D)
print(ans)

Measured memory_bytes: 11116
#include<bits/stdc++.h>
using namespace std;
#define N 100000 + 5
#define inf 123456789
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define Next(i, u) for(int i = h[u]; i; i = e[i].next)
struct edge{
    int v, next;
}e[N << 1];
bool flag, book[N];
int n, m, u, v, tot, l[N], r[N], h[N], col[N], val[N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
void add(int u, int v){
    e[++tot].v = v, e[tot].next = h[u], h[u] = tot;
}
void dfs(int u, int fa){
    book[u] = true;
    Next(i, u){
        int v = e[i].v; if(v == fa) continue;
        if(book[v]){
            if(col[v] != (col[u] ^ 1)) flag = true;
        }
        else col[v] = col[u] ^ 1, dfs(v, u);
    }
}
void dfs1(int u, int fa){
    Next(i, u){
        int v = e[i].v; if(v == fa) continue;
        dfs1(v, u), l[u] = max(l[v] - 1, l[u]), r[u] = min(r[v] + 1, r[u]);
    }
}
void dfs2(int u, int fa){
    Next(i, u){
        int v = e[i].v; if(v == fa) continue;
        l[v] = max(l[u] - 1, l[v]), r[v] = min(r[u] + 1, r[v]), dfs2(v, u);
    }
}
void dfs3(int u, int fa){
    if(!fa){
        if(r[u] < l[u]) flag = true;
        if(l[u] == r[u] && ((l[u] & 1) != col[u])) flag = true;
        if((l[u] & 1) != col[u]) val[u] = l[u] + 1;
        else val[u] = l[u];
    }
    Next(i, u){
        int v = e[i].v; if(v == fa) continue;
        if(r[v] < l[v]) flag = true;
        if(val[u] + 1 >= l[v] && val[u] + 1 <= r[v]) val[v] = val[u] + 1;
        else if(val[u] - 1 >= l[v] && val[u] - 1 <= r[v]) val[v] = val[u] - 1;
        else flag = true;
        dfs3(v, u);
    }
}
int main(){
    n = read();
    rep(i, 1, n) l[i] = -inf, r[i] = inf;
    rep(i, 1, n - 1) u = read(), v = read(), add(u, v), add(v, u);
    m = read();
    rep(i, 1, m) u = read(), v = read(), l[u] = r[u] = v, book[u] = true, col[u] = (v & 1);
    rep(i, 1, n) if(l[i] == r[i]) dfs(i, 0);
    dfs1(1, 0), dfs2(1, 0), dfs3(1, 0);
    if(flag) puts("No");
    else{
        puts("Yes");
        rep(i, 1, n) printf("%d\n", val[i]);
    }
    return 0;
}

Measured memory_bytes: 15060
#include <bits/stdc++.h>
using namespace std;
int n, a[1025][1025], t = 0;
bool flag[1025], fl = 0;
bool judge() {
  for (int i = 1; i <= n; ++i)
    if (a[i][0] != n)
      return 0;
  return 1;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < n; ++j)
      cin >> a[i][j];
    a[i][0] = 1;
  }
  while (1) {
    if (judge()) {
      printf("%d\n", t);
      return 0;
    }
    fl = 0;
    memset(flag, 0, sizeof(flag));
    ++t;
    for (int i = 1; i <= n; ++i) {
      if (flag[i] || a[i][0] == n)
        continue;
      int x = a[i][a[i][0]], y = a[x][a[x][0]];
      if (!flag[x] && !flag[i] && i == y) {
        fl = 1;
        flag[x] = 1;
        flag[i] = 1;
        ++a[i][0];
        ++a[x][0];
      }
    }
    if (!fl) {
      printf("-1\n");
      return 0;
    }
  }
  return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int X,Y,Z,K; cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    REP(i,X) cin >> A[i]; REP(i,Y) cin >> B[i]; REP(i,Z) cin >> C[i];

    vector<ll> c;
    REP(i,X)REP(j,Y){
        c.push_back(A[i]+B[j]);
    }
    SORT(c); REVERSE(c); SORT(C); REVERSE(C);

    ll xl = 0, xr = 3e10, x = (xl+xr)/2;
    while(xr-xl>1){
        int tmp = 0;
        REP(i,Z){
            ll l = -1, r = c.size(), n = (l+r)/2;
            while(r-l>1){
                if(x <= C[i]+c[n]) l = n;
                else r = n;
                n = (l+r)/2;
            }
            tmp += r;
        }
        if(K <= tmp) xl = x;
        else xr = x;
        x = (xl+xr)/2;
    }

    vector<ll> ans;
    REP(i,Z){
        ll l = -1, r = c.size(), n = (l+r)/2;
        while(r-l>1){
            if(xl <= C[i]+c[n]) l = n;
            else r = n;
            n = (l+r)/2;
        }
        REP(j,r) ans.push_back(c[j]+C[i]);
    }

    SORT(ans); REVERSE(ans);
    REP(i,K) cout << ans[i] << en;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) A = 14;
  if (B == 1) B = 14;
  if (A == B) cout << "Draw" << endl;
  else if (A > B) cout << "Alice" << endl;
  else cout << "Bob" << endl;
}


Measured memory_bytes: 256
import math
class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

def d(p1, p2):
    a = p2.x - p1.x
    b = p2.y - p1.y
    c = math.sqrt(a * a + b * b)
    return(c)

data = [float(i) for i in input().split()]
p1 = Point(data[0], data[1])
p2 = Point(data[2], data[3])
print(d(p1,p2))


Measured memory_bytes: 5652
#include<bits/stdc++.h>
using namespace std;
int main()
{
  multimap<string,int>m;
  multimap<string,int>::iterator it;
  string s;
  int n;
  cin>>n;
  while(n--)
  {
    int q,x;
    cin>>q;
    if(q==0)
    {
      cin>>s>>x;
      m.insert(make_pair(s,x));
    }
    else if(q==1)
    {
      cin>>s;
			map<string,int>::iterator end,it;
			it=m.lower_bound(s);
			end=m.upper_bound(s);
			for(;it!=end;it++){
			cout<<(*it).second<<endl;
    }
  }
    else if(q==2)
    {
      cin>>s;
      m.erase(s);
    }
    else
    {
      string l,r;
      cin>>l>>r;
      for(it=m.lower_bound(l);it!=m.upper_bound(r);it++)
      {
        cout<<it->first<<" "<<it->second<<endl;
      }
    }
  }
}



Measured memory_bytes: 24876
while True:
  H, W=map(int,input().split())
  if H==0 and W==0:
    break
  for i in range(H):
    for j in range(W):
      if (i+j)%2==0:
        print("#",end='' )
      else:
        print(".",end='')
    print()
  print()


Measured memory_bytes: 7008
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, M; cin >> N >> M;
    int K; cin >> K;
    bool A[N][M]; F0R(i, N) F0R(j, M) {
        char C; cin >> C;
        A[i][j] = C == '#';
    }

    int ans = 0;
    F0R(a, (1 << N)) {
        F0R(b, (1 << M)) {
            int cur = 0;
            F0R(i, N) {
                F0R(j, M) {
                    if (A[i][j] && (a & (1 << i)) && (b & (1 << j))) {
                        cur++;
                    }
                }
            }
            if (cur == K) ans++;
        }
    }
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3652
#include<bits/stdc++.h>
   using namespace std;
    int main(){
	    int x;
	    cin>>x;
	    int hap=0;
	    hap=(x/500)*1000;
	    x=x%500;
	    hap +=(x/5)*5;
	    cout<<hap<<endl;
    }



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  vector<int> freq(100001);
  int num;
  int res = 0;
  for(int i = 0;i < n;i++){
    cin >> num;
    if(num <= 100000)
      freq[num]++;
    else
      res++;
  }
  for(int i = 0;i <= 100000;i++){
    if(freq[i] >= i)
      res += freq[i] - i;
    else
      res += freq[i];
  }
  cout << res;
}


Measured memory_bytes: 640
for e in iter(input,'0'):
 n=int(e);m,f=[[0]*n for _ in[0]*n],'{:4}'*n
 j=n//2;i=j+1
 m[i][j]=1
 for k in range(2,n*n+1):
  i,j=-~i%n,-~j%n
  if m[i][j]:i,j=-~i%n,~-j%n
  m[i][j]=k
 for r in m:print(f.format(*r))


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

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

    int d;
    std::vector<int> tako;
    for (int i = 0; i < N; ++i) {
        std::cin >> d;
        tako.push_back(d);
    }

    int sum = 0;
    for (std::size_t i = 0; i < tako.size(); ++i) {
        for (std::size_t j = i + 1; j < tako.size(); ++j) {
            sum += (tako[i] * tako[j]);
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define all(x) (x).begin(), (x).end()

using namespace __gnu_pbds;
using namespace std;

using ull = unsigned long long;
using ll = long long;
using ld = long double;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

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

    int n;
    cin >> n;

    if (n % 1000 == 0)
        cout << 0 << "\n";
    else cout << 1000 - n % 1000 << "\n";
    return 0;
}

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


int main() {
    int a;
    int b;
    int out = 0;
    cin >> a >> b;

    if(a >= 13){
        out = b;
    }else if((a >= 6)&(a <= 12)){
        out = b/2;
    }else if(a <= 5){
        out = 0;
    }

    cout << out << endl;

    return 0;
}

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

int N,K,cnt;
bool B[100];


int main(){
	cin>>N>>K;
	for(int i=0;i<K;i++){
		int d;
		cin>>d;
		for(int j=0;j<d;j++){
			int a;
			cin>>a;
			a--;
			B[a]=true;
		}
	}
	for(int i=0;i<N;i++){
		cnt+=!B[i];
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3588
import heapq
N, M = map(int, input().split())
Edge = [list(map(int, input().split())) for i in range(M)]

S, T = map(int, input().split())
S, T = S - 1, T - 1


G3 = [[] for i in range(3 * N)]
for u, v in Edge:
    u, v = u - 1, v - 1
    G3[u].append([v + N, 1])
    G3[u + N].append([v + N * 2, 1])
    G3[u + 2 * N].append([v, 1])


def dijkstra(x):
    d = [float('inf')] * (3 * N)
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G3[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u] + cost, node))
    return d


dist = dijkstra(S)
print(dist[T] // 3 if dist[T] != float('inf') else - 1)


Measured memory_bytes: 115876
#define DEBUG 0

/**
 * File    : E2.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-27 00:40:23
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, Q;
typedef tuple<ll, int, ll> event; // 0: 壁が置かれる。 1: 壁が取り除かれる。 2: 半直線発射
vector<event> V;
multiset<ll> S; // 壁が置かれた座標。

int main()
{
  cin >> N >> Q;
  for (auto i = 0; i < N; i++)
  {
    ll s, t, x;
    cin >> s >> t >> x;
    V.push_back(event(s - x, 0, x));
    V.push_back(event(t - x, 1, x));
  }
  for (auto i = 0; i < Q; i++)
  {
    ll d;
    cin >> d;
    V.push_back(event(d, 2, 0));
  }
  sort(V.begin(), V.end());
  for (auto e : V)
  {
    ll time, dist;
    int c;
    tie(time, c, dist) = e;
#if DEBUG == 1
    cerr << "time = " << time << ", c = " << c << ", dist = " << dist << endl;
#endif
    if (c == 0)
    {
      S.insert(dist);
    }
    else if (c == 2)
    {
      if (S.empty())
      {
        cout << -1 << endl;
      }
      else
      {
        cout << *S.begin() << endl;
      }
    }
    else
    {
      S.erase(S.find(dist));
    }
  }
}

Measured memory_bytes: 26600
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using Real = double;
using Point = complex<Real>;
const Real EPS = 1e-8;

using Points = vector<Point>;


int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);


	int r; cin >> r; cout << r * r << endl;
	return 0;
}

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

int main(){
    map<string,int> keihin;
    long long n;
    cin>>n;
    for(long long i=0;i<n;i++){
        string temp;
        cin>>temp;
        keihin.insert(make_pair(temp,1));
    }
    cout<<keihin.size()<<endl;
    return 0;
}

Measured memory_bytes: 19176
// 組み合わせ問題
import 'dart:io';
import 'dart:math';

void main() {
  List nk = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  int ans;
  ans = nk[1] * pow(nk[1] - 1, nk[0] - 1);
  print(ans);
}

Measured memory_bytes: 13148
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
char s[300010];
int len;
long long f[2][3][3];
bool p;
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	p=0;
	f[p][0][0]=1;
	for(int i=1;i<=len;++i)
	{
		p^=1;
		char ch=s[i];
		for(int j=0;j<=2;++j)
		for(int k=0;k<=2;++k)f[p][j][k]=0;
		if(ch=='1')
		{
			f[p][1][0]=f[p^1][0][0]+f[p^1][1][1];
			f[p][2][0]=f[p^1][1][0]+f[p^1][2][1]+f[p^1][2][0];
			f[p][0][0]=f[p^1][0][1];
			f[p][2][1]=f[p^1][2][2];
			f[p][1][1]=f[p^1][1][2];
			f[p][0][1]=f[p^1][0][2];
		}
		else if(ch=='0')
		{
			f[p][0][1]=f[p^1][0][0]+f[p^1][0][2];
			f[p][1][1]=f[p^1][1][0]+f[p^1][1][2];
			f[p][0][2]=f[p^1][0][1];
			f[p][1][2]=f[p^1][1][1];
			f[p][2][2]=f[p^1][2][1];
			f[p][2][1]=f[p^1][2][2]+f[p^1][2][0];
		}
		else
		{
			f[p][1][0]=f[p^1][0][0]+f[p^1][1][1];
			f[p][2][0]=f[p^1][1][0]+f[p^1][2][1]+f[p^1][2][0];
			f[p][0][0]=f[p^1][0][1];
			f[p][0][1]=f[p^1][0][0]+f[p^1][0][2]+f[p^1][0][2];
			f[p][1][1]=f[p^1][1][0]+f[p^1][1][2]+f[p^1][1][2];
			f[p][0][2]=f[p^1][0][1];
			f[p][1][2]=f[p^1][1][1];
			f[p][2][2]=f[p^1][2][1];
			f[p][2][1]=f[p^1][2][2]+f[p^1][2][0]+f[p^1][2][2];
		}
		for(int j=0;j<=2;++j)
		for(int k=0;k<=2;++k)f[p][j][k]%=MOD;
	}
	long long ans=0;
	for(int i=0;i<=2;++i)
	for(int j=0;j<=i;++j)
	ans=(ans+f[p][i][j])%MOD;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A, B, K;
	cin >> A >> B >> K;
	if (K > B - A) K = B - A + 1;
	set<int> opt;
	for (int i = 0; i < K; i++) opt.insert(A + i);
	for (int i = 0; i < K; i++) opt.insert(B - i);
	vector<int> vec(opt.begin(), opt.end());
	cout << vec.at(0);
	for (int i = 1; i < vec.size(); i++) cout << endl << vec.at(i);
	cout << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> x(n),y(n);
	for(int i = 0 ; i < n ; i += 1){
		cin >> x[i];
		y[i] = x[i];
	}
	sort(x.rbegin(),x.rend());
	if(x[0] == x[1]){
		for(int i = 0 ; i < n ; i += 1){
			cout << x[0] << endl;
		}
	}else{
		for(int i = 0 ; i < n ; i += 1){
			if(y[i] == x[0]){
				cout << x[1] << endl;
			}else{
				cout << x[0] << endl;
			}
		}
	}
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <math.h>

int main(void){
	int N;
	double v;
	while(scanf("%lf" , &v)!=EOF){
		for(N=1;;N++){
			if(sqrt(19.6*(5*N-5))>=v){
				printf("%d\n" , N);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import math
import numpy as np

def main():
  N,M = (int(x) for x in input().split())
  A = [int(x) for x in input().split()]
  
  for i in range(M):
    N = N - A[i]
  
  if N < 0:
    print('-1')
  else:
    print(N)  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 27700
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

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

int main() {
	string s;
	cin >> s;
	puts(((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
 
int dp[10001];
int N,W;
int main() {
    scanf("%d%d",&N,&W);
 
    for(int i = 0;i < N;i++) {
        int v,w;
        scanf("%d%d",&v,&w);
        for(int j = w;j <= W;j++) {
            dp[j] = max(dp[j],dp[j - w] + v);
        }
    }
    printf("%d\n",dp[W]);
    return 0;
}



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

#define LIMIT 1000000

char in[LIMIT], *p = in;

template <class T>
__inline void get(T &res) {
	
	res = 0;
	
	while (*p < '0')++p;
	
	while (*p >= '0')
		res = res * 10 + *p++ - '0';
	
}

#define ri register int
#define rl register long long

int n, m, num[100005];

signed main(void) {
	
	fread(in, 1, LIMIT, stdin);
	
	get(n);
	get(m);
	
	for (ri i = 1; i <= n; ++i)
		get(num[i]);
		
	for (ri t = 1; t <= m; ++t) {
		
		rl q, ans = 0, sum = 0; get(q);
		
		for (ri i = 1, j = 0; i <= n; ++i) {
			
			while (j < n && sum + num[j + 1] <= q)
				sum += num[++j];
				
			ans += (j - i + 1);
			sum -= num[i];
			
		}
		
		printf("%lld\n", ans);
		
	}
	
}

Measured memory_bytes: 4492
#include<iostream>
#include<math.h>

using namespace std;

int main(){
	int N,M;
	cin >> N >> M;
	int num[N];
	for (int i = 0; i < N; i++){
      num[i] = 10;
    }

  
  for (int i = 0; i < M; i++){
		int s,c;
		cin >> s >> c;
		if(num [s-1] == c || num [s-1] == 10){
			num [s-1] = c;
		}else{
			cout << "-1"<< endl;
			exit(0);
		};
	}
	
	int sc = 0;

	if(N > 1 && num[0] == 10){
		num[0] = 1;
		};

	for (int i = 0; i < N; i++){
		if(num[i] == 10){
          num[i] = 0;
        };
		sc = (sc*10) + num[i];
	}
  
  	if(!(sc==0 && N == 1) && sc < pow(10,(N-1))){
		cout << "-1"<< endl;
		exit(0);
    }
    
	cout << sc << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	Ns := sc.Next()
	N, _ := strconv.Atoi(Ns)
	sum := 0

	A := len(Ns)
	if A%2 == 1 {
		sum += N - pow(10, A-1) + 1
		A -= 2
	} else {
		A--
	}

	for s := A; s > 0; s -= 2 {
		sum += pow(10, s-1) * 9
	}
	fmt.Println(sum)
}

//aのb乗をします O(log b)
func pow(a int, b int) int {
	total := 1
	tmp := a
	for b > 0 {
		if b%2 == 1 {
			total *= tmp
		}
		b /= 2
		tmp *= tmp
	}
	return total
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll mod = 998244353;

int main(){
    int N;
    ll a[310];
    cin>>N;
    int sum=0;
    for(int  i=0;i<N;i++){
        cin>>a[i];
        sum += a[i];
    }
    ll dp[90001]={};
    dp[0]=1;
    for(int i=0;i<N;i++) {
        for(int j=300*N;j>=0;j--){
            if(j-a[i]>=0){
                dp[j]=(2*dp[j]+dp[j-a[i]])%mod;
            }else{
                dp[j]=(2*dp[j])%mod;
            }
        }
    }
    ll ans=0;
    if(sum%2==0){
        for(int i=sum;i>=sum/2;i--){
            ans=(dp[i]+ans)%mod;
        }
        ans = (3*ans) % mod;
        // sum/2 sum/2 パターンを数える
        ll dp[90001]={};
        dp[0]=1;
        for(int i=0;i<N;i++) {
            for(int j=300*N;j>=0;j--) {
                if(j-a[i]>=0){
                    dp[j]=(dp[j]+dp[j-a[i]])%mod;
                }
            }
        }
        ll tmp = (dp[sum/2]*3)%mod;
        ans = (ans + mod - tmp)%mod;
    }else{
        for(int i=sum ; i >= (sum+1)/2 ; i--){
            ans = (dp[i]+ans) % mod;
        }
        ans = (3*ans)%mod;
    }
    ll tt=1;
    for(int i=1;i<=N;i++){
        tt = (tt * 3) % mod;
    }
    cout<<(tt+mod-ans)%mod<<endl;
    
    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt() , c = sc.nextInt();
		if(a > b) {
			int x = a;
			a = b;
			b = x;
		}
		if((a < c) && (c < b)) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 22356
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int x, y, W, H, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(x >= 1 && x <= W-r)
	{
		if(y >= 1 && y <= H-r)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


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

using namespace std;

int main(){
string s; cin>>s;
  
  if(s[0]=='A') printf("T");
  else if(s[0]=='T') printf("A");
  else if(s[0]=='C') printf("G");
  else if(s[0]=='G') printf("C");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

map<string, int> InputMaterial(int n);
map< string, map<string, int> > InputWrought(int n);
int Calculate(const string, map<string, int>, map< string, map<string, int> >);

int main(){
  int n, m;
  string str;
  map<string, int> material;
  map< string, map<string, int> > wrought;

  while(1){
    cin >> n;
    if(n == 0) break;
    material = InputMaterial(n);

    cin >> n;
    wrought = InputWrought(n);

    cin >> str;
    cout << Calculate(str, material, wrought) << endl;
  }
  return 0;
}

map<string, int> InputMaterial(int n){
  int i, m;
  string str;
  map<string, int> data;

  for(i=0; i<n; ++i){
    cin >> str >> m;
    data.insert(make_pair(str, m));
  }
  return data;
}

map< string, map<string, int> > InputWrought(int n){
  int i, j, m;
  string str, _str;
  map<string, int> _data;
  map< string, map<string, int> > data;
  map<string, int>::iterator iter;

  for(i=0; i<n; ++i){
    cin >> str >> m;
    for(j=0; j<m; ++j){
      cin >> _str;
      iter = _data.find(_str);
      if(iter == _data.end()) _data.insert(make_pair(_str, 1));
      else ++iter->second;
    }
    data.insert(make_pair(str, _data));
    _data.clear();
  }
  return data;
}

int Calculate(const string one_material, map<string, int> material,
	      map< string, map<string, int> > wrought){
  int n, sum;
  map<string, int>::iterator i, j;
  map< string, map<string, int> >::iterator k;

  i = material.find(one_material);
  if(i == material.end()) return -1;

  k = wrought.find(one_material);
  if(k == wrought.end()) return i->second;

  for(j=k->second.begin(), sum=0; j!=k->second.end(); ++j){
    n = Calculate(j->first, material, wrought);
    if(n == -1) return i->second;
    sum += (n * j->second);
  }
  if(sum > i->second) return i->second;
  else return sum;
}

Measured memory_bytes: 1284
package main

import (
	"fmt"
	"math"
	"sort"
)

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

func main() {
	var n int
	fmt.Scan(&n)
	x := make([]int, n)
	y := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i], &y[i])
	}
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, i)
	}
	sort.Ints(a)

	var sum float64
	var cnt int
	for { // do-while NextPermutation
		cnt++
		for i := 1; i < len(a); i++ {
			s, t := a[i-1], a[i]
			v := math.Pow(float64(x[s]-x[t]), 2)
			v += math.Pow(float64(y[s]-y[t]), 2)
			v = math.Sqrt(v)
			sum += v
		}
		if !NextPermutation(sort.IntSlice(a)) {
			break
		}
	}
	fmt.Println(sum / float64(cnt))
}


Measured memory_bytes: 1792
#include <limits.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, W, H, N, x[100], y[100], a[100];
	cin >> W >> H >> N;
	for (i = 0; i < N; i++) cin >> x[i] >> y[i] >> a[i];

	int xmax = 0, xmin = W, ymax=0, ymin=H;
	for (i = 0; i < N; i++) {
		switch (a[i]) {
		case 1:if (xmax < x[i]) xmax = x[i]; break;
		case 2:if (xmin > x[i]) xmin = x[i]; break;
		case 3:if (ymax < y[i]) ymax = y[i]; break;
		case 4:if (ymin > y[i]) ymin = y[i]; break;
		}
	}
	ans = (xmin + 1 - xmax - 1)*(ymin + 1 - ymax - 1);
	if ((xmin + 1 - xmax - 1)<0||(ymin + 1 - ymax - 1)<0)ans = 0;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, a, b) = readLine.split(" ").map(_.toLong)
  val h = for(i <- 0 until n.toInt) yield readLine.toLong
  val c = a - b

  val maxH = h.max
  val maxT = maxH / b + 1

  // rightT is always valid
  // leftT is always invalid

  def calc(leftT: Long, rightT: Long): Long = {
    if(rightT - leftT <= 1) rightT
    else {
      val midT = (leftT + rightT) / 2
      val curT = h.foldLeft(0L){(t, v) => {
        val l = v - midT * b
        if(l > 0) t + (l - 1) / c + 1
        else t
      }}
      if(midT < curT) calc(midT, rightT)
      else if(midT == curT) midT
      else calc(leftT, midT)
    }
  }
  println(calc(0, maxT))
}

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

int main() {
    int n;
    string s;
    bool repeatable = true;
    cin >> n >> s;
    int mid = n / 2;
    for (int i = 0; i < n/2; i++) {
        if (s.at(i) != s.at(i+mid)) {
            repeatable = false;
        }
    }
    if (n % 2 == 0 && repeatable) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
	FIO
	
	
	int H, W, N;cin >> H >> W >> N;
	int a[N];for(int i = 0; i < N; i++)cin >> a[i];
	vector<int> ans;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < a[i]; j++)ans.emplace_back(i + 1);
	}
	for(int i = W; i < (int)ans.size(); i += 2 * W){
		reverse(ans.begin() + i, ans.begin() + i + W);
	}
	//deb(ans);
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cout << ans[i * W + j] << " ";
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 512
n = gets.chomp.to_i

a_b_arr = []
n.times do |i|
  a_b_arr << gets.chomp.split(" ").map(&:to_i)
end

c_d_arr = []
n.times do |i|
  c_d_arr << gets.chomp.split(" ").map(&:to_i)
end

a_b_arr.sort_by!{|(a, b)| -a }
c_d_arr.sort_by!{|(c, d)| d }

count = 0
a_b_arr.each do |(a, b)|
  index = -1
  c_d_arr.each_with_index do |(c, d), i|
    if a < c && b < d then
      index = i
      break
    end
  end
  if index != -1 then
    c_d_arr.delete_at(index)
    count += 1
  end
end

puts count


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
int32_t main()
{
fastio;
int a;in a;
for(int i=1;i<=9;i++){
    int d=a/i;
    if(a%i==0){
        if(d>0 && d<=9) out "Yes",exit(0);
    }
}
out "No";
    return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


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

    int a = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2, 2));
    if(0 < a && a <= 12 && 0 < b && b <= 12){
        cout << "AMBIGUOUS" << endl;
    }else if(0 < a && a <= 12){
        cout << "MMYY" << endl;
    }else if(0 < b && b <= 12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#define ll long long
using namespace std;

int k;
string s;

int main()
{
    cin>>k;
    cin>>s;
    if(s.length()<=k)
        cout<<s;
    else
    {
        for(int i=0;i<k;i++)
            cout<<s[i];
        cout<<"...";
    }
   return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
bool isprime(ll n){
    if(n==1)return false;
    for (ll i = 2; i * i <= n; i++) {
        if(n%i==0)return false;
    }
    return true;
}
int main(){
  ll n;cin>>n;
  rep(i,2,55556){
    if(i%5==1&&isprime(i)){
      cout<<i<<" ";n--;
    }
    if(n==0)break;
  }
  cout<<endl;
}



Measured memory_bytes: 3520