akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

const int maxn = 2e5+5;
const LL MOD = 1e9+7;
LL F[maxn], Finv[maxn], inv[maxn];

void prework() {
    inv[1] = 1;
    for(int i = 2; i < maxn; ++i) {
        inv[i] = (MOD - MOD / i) * 1LL * inv[MOD % i] % MOD;
    }
    F[0] = Finv[0] = 1;
    for(int i = 1; i < maxn; ++i) {
        F[i] = F[i-1] * 1LL * i % MOD;
        Finv[i] = Finv[i-1] * 1LL * inv[i] % MOD;
    }
}

LL comb(int n, int m) { //C(n, m)
    if(n < m || m < 0) return 0;
    return F[n] * 1LL * Finv[n-m] % MOD * Finv[m] % MOD;
}

void run_case() {
    prework();
    LL n, k, ans = 0;
    cin >> n >> k;
    for(int i = 0; i < n; ++i) {
        if(i > k) break;
        ans = (ans + comb(n, i) * comb(n-1, n-i-1)%MOD + MOD) % MOD;
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
static const int N=100000;

int n,a[N+5];
int t,k;

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>k;
        cout<<lower_bound(a, a+n, k)-a<<" "<<upper_bound(a, a+n, k)-a<<endl;
    }
    return 0;
}




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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M), D(M);
  vector<vector<pair<int, int>>> G(N);
  for (int i = 0; i < M; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    L[i] = l, R[i] = r, D[i] = d;
    G[l].emplace_back(make_pair(r, d));
    G[r].emplace_back(make_pair(l, -d));
  }
  vector<bool> visited(N, false);
  vector<int> dist(N, 0);
  function<void(int)> dfs = [&](int u) {
    visited[u] = true;
    for (auto g : G[u]) {
      int v = g.first, d = g.second;
      if (!visited[v]) {
        dist[v] = dist[u] + d;
        dfs(v);
      }
    }
  };
  for (int i = 0; i < N; i++) {
    if (!visited[i]) dfs(i);
  }
  bool ok = true;
  for (int i = 0; i < M; i++) {
    ok &= (dist[R[i]] - dist[L[i]] == D[i]);
  }
  cout << (ok ? "Yes" : "No") << '\n';
  return 0;
}


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

const int MAX_V = 500;
const int INF = 100000;

// 辺を表す構造体（行き先，容量，逆辺）
struct edge { int to, cap, rev; };

vector<vector<edge>> G(MAX_V);
vector<bool> used(MAX_V);

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap) {
    int n = G[to].size();
    int m = G[from].size();
    G[from].push_back((edge){to, cap, n});
    G[to].push_back((edge){from, 0, m});
}

// 増加パスをDFSで探す
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f,e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        for(int j=0; j<used.size(); j++) used[j] = 0;
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
    return 0;
}

int main() {
    int N; cin >> N;
    vector<int> a(N), b(N), c(N), d(N);

    rep(i,N) cin >> a[i] >> b[i];
    rep(i,N) cin >> c[i] >> d[i];
    rep(i,N) {
        rep(j,N) {
            if (a[i] < c[j] && b[i] < d[j]) add_edge(i+1,j+201,1);
        }
    }
    rep(i,N) add_edge(0,i+1,1);
    rep(i,N) add_edge(i+201,401,1);

    cout << max_flow(0,401) << endl;
}

Measured memory_bytes: 384
# https://atcoder.jp/contests/abc113/tasks/abc113_c

n, m = gets.split.map(&:to_i)

prefs = Array.new(10**6).map { Array.new }
City = Struct.new("City", :pref, :year, :index)
cities = []
m.times do
  pref, year = gets.split.map(&:to_i)
  city = City.new(pref, year, nil)
  prefs[pref] << city
  cities << city
end

prefs.reject(&:nil?).each do |pref|
  sorted_pref_cities = pref.sort_by { |c| c.year }
  sorted_pref_cities.each_with_index { |c, idx| c.index = idx + 1 }
end
cities.each { |i| printf "%06d%06d\n", i.pref, i.index }

Measured memory_bytes: 134780
n = int(raw_input())
a = map(int, raw_input().split())
a.sort(reverse=True)
count = 0
if n % 2 == 0:
	for i in range(n / 2):
		count += (a[2 *i] - a[2 * i + 1])
else:
	for i in range((n - 1) / 2):
			count += (a[2 * i] - a[2 * i + 1])
	count += a[n - 1]
print count

Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#define llint long long
#define inf 1000000000000000000

using namespace std;

struct man{
	llint h, p;
	man(){};
	man(llint a, llint b){
		h = a, p = b;
	}
	bool operator<(const man &obj)const{
		return h+p < obj.h+obj.p;
	}
};

llint N;
man m[5005];
llint dp[5005][5005];

int main(void)
{
	cin >> N;
	llint h, p;
	for(int i = 1; i <= N; i++){
		cin >> h >> p;
		m[i] = man(h, p);
	}
	sort(m+1, m+N+1);
	
	for(int i = 1; i <= N; i++) dp[0][i] = inf;
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= N; j++){
			dp[i][j] = dp[i-1][j];
			if(j > 0 && m[i].h >= dp[i-1][j-1]) dp[i][j] = min(dp[i][j], dp[i-1][j-1] + m[i].p);
		}
	}
	
	for(int i = N; i >= 0; i--){
		if(dp[N][i] < inf){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 195840
S = input()
K = int(input())
num = [1]
p = S[0]
for i in range(1, len(S)):
    if S[i] == p:
        num[-1] += 1
    else:
        num.append(1)
        p = S[i]
if len(num) == 1:
    print(len(S)*K // 2)
elif S[0] != S[-1]:
    print( sum( [num[i]//2 for i in range(len(num))] ) * K )
else:
    num_s = num[1:-1] + [num[0] + num[-1]]
    ans = sum( [num_s[i]//2 for i in range(len(num_s))] ) * (K-1)
    ans += sum( [num[i]//2 for i in range(len(num))] )
    print(ans)

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

using namespace std;

multiset <int> st, slimes;

int extract(int up_lim)
{
    auto it = st.lower_bound(up_lim);
    if (it == st.begin())
    {
        cout << "No\n";
        exit(0);
    }
    it--;
    st.erase(it);
    return *it;
}

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

    int n;
    cin >> n;
    n = (1 << n);

    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        st.insert(x);
    }

    slimes.insert(extract((int) 1e9 + 100));

    while (!st.empty())
    {
        vector <int> cur;
        for (auto &it : slimes)
        {
            cur.push_back(it);
        }

        for (auto &it : cur)
        {
            slimes.insert(extract(it));
        }
    }

    cout << "Yes\n";

}


Measured memory_bytes: 13304
using System;
class change{
  public String replace(String str, int first, int last, String comp){
    String strf = str.Substring(0,first);
    String strl = str.Substring(last+1,str.Length-last-1);
    String newstring = strf+comp+strl;
    return newstring;
  }
  public String reverse(String str, int first, int last){
    String temp,rev=null;
    temp = str.Substring(first,last-first+1);
    for(int i=last; i>=first; i--){
      rev+=str[i];
    }
    str = str.Replace(temp,rev);
    return str;
  }
  public void print(String str, int first, int last){
    for(int i=first; i<=last; i++){
      Console.Write(str[i]);
    }
    Console.WriteLine();
  }
}

class code{
  public static void Main(){
    change c = new change();
    String str = Console.ReadLine();
    String[] command;
    int numofcom = int.Parse(Console.ReadLine());
    for(int i=0; i<numofcom; i++){
      command = Console.ReadLine().Split(' ');
      switch (command[0]){
        case "replace":
          str = c.replace(str, int.Parse(command[1]), int.Parse(command[2]), command[3]);
          break;
        case "reverse":
          str = c.reverse(str, int.Parse(command[1]), int.Parse(command[2]));
          break;
        case "print":
          c.print(str, int.Parse(command[1]), int.Parse(command[2]));
          break;
        default:
          break;
      }
    }
  }
}



Measured memory_bytes: 19972
while True:
    x=int(input())
    y=1000-x
    if x==0:
        break
    else:
       a=y//500
       b=y%500
       c=b//100
       d=b%100
       e=d//50
       f=d%50
       g=f//10
       h=f%10
       i=h//5
       j=h%5
       k=j//1
    print(a+c+e+g+i+k)


Measured memory_bytes: 5588
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>

int main(){
    std::string s,a;
    for(int i=0;i<3;i++){
        std::cin >> s;
        if(i==0){
            a+=s[0];
        }else if(i==1){
            a+=s[1];
        }else if(i==2){
            a+=s[2];
        }
    }
    std::cout << a <<std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

class UnionFindTree{
private:
  // indexの数の親ノード(ある集合の親を見つけたいときはここを直接参照せず、findを使う)
  vector<int> par;
  // indexを根とする木のランク
  vector<int> rank;
  // 集合のサイズ
  vector<int> cnts;
  // 木の最大値
  int treeSize;
public:
  UnionFindTree(int initTreeSize = 1000){
    // 引数で与えられた値を最大格納数とするUnionFindTreeの作成
    treeSize = initTreeSize;
    init();
  }
  void init(){
    for(int i = 0; i < treeSize; i++){
      par.push_back(i);
      rank.push_back(0);
      cnts.push_back(1);
    }
  }
  // 与えられた数が格納されている木のルートを探索
  int find(int x){  
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
  }
  // 和集合をとる。ただしここでは各集合の親の付け替えは起こらない
  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y)return;
    if(rank[x] < rank[y]){
      par[x] = y;
      cnts[y]+=cnts[x];
    }
    else{
      par[y] = x;
      cnts[x]+=cnts[y];
      if(rank[y] == rank[x])rank[x]++;
    }
  }
  // xの属する集合のサイズ
  int getCnt(int x){
    return cnts[find(x)];
  }
  bool same(int x,int y){
    return find(x) == find(y);
  }
    
};

typedef pair<int,pii> pip;
int N;
int AS[1000001];
int BS[1000001];
int CS[1000001];
int main(){
  fastStream();
  cin>>N;
  vector<pip> v;
  for(int i=0;i<N-1;i++){
    cin>>AS[i]>>BS[i]>>CS[i];
    v.push_back(pip(CS[i],pii(AS[i],BS[i])));
  }
  sort(v.begin(),v.end());
  UnionFindTree uft(N+1);
  ll res=0;
  for(int i=0;i<N-1;i++){
    ll a=uft.getCnt(v[i].second.first);
    ll b=uft.getCnt(v[i].second.second);
    res+=a*b*v[i].first;
    uft.unite(v[i].second.first,v[i].second.second);
  }
  cout<<res<<endl;
  
  return 0;
}

Measured memory_bytes: 16632
Main=(e=>{e=+e;let t=0,l=e=>{let t=e.sort((e,t)=>e-t);return r(r(t[0],t[1]),t[2])},r=(e,t)=>{let l=e%t;return 0===l?t:r(t,l)};for(let r=1;r<=e;r++)for(let o=r;o<=e;o++)for(let n=o;n<=e;n++){let e=[r,o,n],f=e.filter((e,t,l)=>l.indexOf(e)===t).length;f=1===f?1:2===f?3:6,t+=l(e)*f}console.log(t)}); Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 35684
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int fun = N;
    while(sc.hasNext()){
        // System.out.println(sc.nextInt());
        fun -= sc.nextInt();
    }
    if(fun >= 0){
        System.out.println(fun);
    } else {
        System.out.println(-1);
    }
  }
}

Measured memory_bytes: 40532
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int v = 100;
    int n;
    cin>>n;
    vector<int> cnt(n+1,0);
    rep(x,1,v+1){
        rep(y,1,v+1){
            rep(z,1,v+1){
                int val = x*x + y*y + z*z + x*y + y*z + z*x;
                if ( val > n ){
                    continue;
                }
                cnt[val]++;
            }
        }
    }

    rep(i,1,cnt.size()){
        cout<<cnt[i]<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<vector>

int main(){
  int N, M;
  std::cin >> N >> M;
  std::vector<std::string> A(N), B(M);
  for(int i = 0; i < N; i++) std::cin >> A.at(i);
  for(int i = 0; i < M; i++) std::cin >> B.at(i);
  bool isIncluded = false;
  for(int i = 0; i < N - M + 1; i++){
    for(int j = 0; j < N - M + 1; j++){
      for(int k = 0; k < M; k++){
        bool isBiEqualAi = true;
        for(int l = 0; l < M; l++){
          if(B.at(k).at(l) != A.at(i + k).at(j + l)){
            isBiEqualAi = false;
            break;
          }
        }//l
        if(isBiEqualAi){
          if(k == M - 1){
            isIncluded = true;
            break;
          }else continue;
        }else break;
      }//k
      if(isIncluded) break;
    }//j
    if(isIncluded) break;
  }//i
  if(isIncluded) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  rep(i, n - 2) {
    ll a = abs(h[i] - h[i + 2]) + dp[i];
    ll b = abs(h[i + 1] - h[i + 2]) + dp[i + 1];
    dp[i + 2] = min(a, b);
  }
  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    s = gete()

    def shift(c, k):
        ret = ord(c) + k
        if ret > ord('Z'): ret = ord('A') + ret - ord('Z') - 1
        return chr(ret)

    print("".join([shift(c, n) for c in s]))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3436
import java.util.*;

class Main {
	public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        
        int h,w;
        while(true){
            h = sc.nextInt();
            w = sc.nextInt();

            if(h == 0 && w == 0)    break;
            for(int i = 0;i < h;i++){
                for(int j = 0;j < w;j++){
                    if(i % 2 == 0){
                        if(j % 2 == 0)  System.out.print("#");
                        else    System.out.print(".");
                    }
                    else{
                        if(j % 2 == 0)  System.out.print(".");
                        else    System.out.print("#");
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}



Measured memory_bytes: 37300
from queue import Queue
N = int(input())
G = [[] for _ in range(N)]
Q = [{} for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
    Q[a-1][b-1] = i

K = max(list(map(len, G)))
print(K)
ans = [0] * (N-1)
q = Queue()
q.put(0)
while not q.empty():
    v = q.get()
    c = set()
    for u in G[v]:
        if u < v:
            c.add(ans[Q[u][v]])
    
    i = 1
    for u in G[v]:
        if u > v:
            while i in c: i += 1
            ans[Q[v][u]] = i
            i += 1
            q.put(u)

for a in ans:
    print(a)

Measured memory_bytes: 49740
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long n,a,b;
    cin>>n;
    if(n==0) {
        cout<<0;
        return 0;
    }
    a = n/500;
    n = n%500;
    b = n/5;
    cout<<1000*a + b*5;



}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nab = readln.split.to!(int[]);
    auto N = nab[0];
    auto A = nab[1];
    auto B = nab[2];
    auto ts = new int[](N);
    foreach (i; 0..N) ts[i] = readln.chomp.to!int;
    int r;
    foreach (t; ts) if (A <= t && t < B) ++r;
    writeln(N - r);
}

Measured memory_bytes: 256
n, m = map(int, input().split())
k,s = [],[]

for i in range(m):
    nk, *ns = map(int, input().split())
    k += [nk]
    s += [ns]

p = list(map(int, input().split()))

ans = 0
for bit in range(2 ** n):
    for rep in range(m):
        counter = 0
        for rep2 in s[rep]:
            if((bit >> (rep2-1)) & 1):
                counter += 1

        if counter % 2 != p[rep]:
            break

    else:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int i,j,n,max=-2000000000;
	
	scanf("%d",&n);
	
	int a[n],min[n],mi=1000000000;
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(i==0){
			mi=a[i];
		}
		
		if(mi>a[i]){
			min[i]=a[i];
			mi=a[i];
		}else{
			min[i]=mi;
		}
	}
	
	for(i=0;i<n-1;i++){
		if(max<a[i+1]-min[i]){
			max=a[i+1]-min[i];
		}
	}
	
	printf("%d\n",max);
	
}

Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int l, la, lb, lc, cnta=0, cntb=0, cntc=0, player=0;
  string sa, sb, sc, win;
  cin >> sa >> sb >> sc;
  la = sa.size();
  lb = sb.size();
  lc = sc.size();
  l = max(la, max(lb, lc));
  while(1){
    if(player==0){
      if(cnta == la){
        win = "A";
        break;
      }else{
        if(sa[cnta]=='a'){
          player = 0;
        }else if(sa[cnta]=='b'){
          player = 1;
        }else if(sa[cnta]=='c'){
          player = 2;
        }
        cnta++;
      }
    }else if(player==1){
      if(cntb == lb){
        win = "B";
        break;
      }else{
        if(sb[cntb]=='a'){
          player = 0;
        }else if(sb[cntb]=='b'){
          player = 1;
        }else if(sb[cntb]=='c'){
          player = 2;
        }
        cntb++;
      }
    }else if(player==2){
      if(cntc == lc){
        win = "C";
        break;
      }else{
        if(sc[cntc]=='a'){
          player = 0;
        }else if(sc[cntc]=='b'){
          player = 1;
        }else if(sc[cntc]=='c'){
          player = 2;
        }
        cntc++;
      }
    }
  }
  
  cout << win <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

ll dp[60][2];

int main(){
  int n; cin >> n;
  string s1,s2; cin >> s1 >> s2;

  if(s1[0] == s2[0]){
    dp[0][0] = 3LL;
    dp[0][1] = 0LL;
  }
  else{
    dp[0][0] = 0LL;
    dp[0][1] = 6LL;
  }

  for(int i = 1; i < n; i++){
    // dp[i][0] の決定
    if(s1[i] == s2[i]){
      if(s1[i-1] == s2[i-1]) dp[i][0] += dp[i-1][0]*2;
      else dp[i][0] += dp[i-1][1];
      dp[i][0] %= MOD;
    }
    else{
      if(s1[i-1] == s1[i]) dp[i][1] = dp[i-1][1];
      else{
        if(s1[i-1] == s2[i-1]) dp[i][1] += dp[i-1][0]*2;
        else dp[i][1] += dp[i-1][1]*3;
      }
      dp[i][1] %= MOD;
    }
  }
  if(s1[n-1] == s2[n-1]) std::cout << dp[n-1][0] << '\n';
  else std::cout << dp[n-1][1] << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
using namespace std;

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}

void chmax(ll &a,const ll &b){
    if(a<b) a=b;
}
void chmin(ll &a,const ll &b){
    if(a>b) a=b;
}


int main()
{

    ll N;
    cin >>N;

    double p[N+1];
    double dp[N+1][N+1];

    for(ll i=1;i<=N;i++){
        cin >> p[i];
    }

    dp[1][0] = 1-p[1];
    dp[1][1] = p[1];

    for(ll i=2;i<=N;i++){
        for(ll j=0;j<=i;j++){
            if(j==0){
                dp[i][j] = (1-p[i]) * dp[i-1][j];
            }else if(j==i){
                dp[i][j] = p[i] * dp[i-1][j-1];
            }else{
                dp[i][j] = (1-p[i]) * dp[i-1][j] + p[i] * dp[i-1][j-1];
            }
        }
    }

    double ans=0;

    for(ll i=N/2+1;i<=N;i++){
        ans += dp[N][i];
    }

    printf("%.10f\n",ans);


    return 0;


}

Measured memory_bytes: 70144
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, d;
    cin >> n >> d;
    int x[20][20] = {};
    rep(i, n) rep(j, d) cin >> x[i][j];
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int sum = 0;
            for (int k = 0; k < d; k++)
            {
                sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            for (int i = 0; i * i <= sum; i++)
            {
                if (i * i == sum)
                    ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int k;
ll s[150];

void solve() {
    for (int i = 1; i < 150; i++) {
        int v = i;
        while (v > 0) {
            s[i] += v % 10;
            v /= 10;
        }
    }
    
    vector<P> cand;
    ll q = 0;
    ll sq = 0;
    ll t = 1;
    while (q < 1e16) {
        for (ll i = 1; i < 150; i++) {
            ll v = i * t + q;
            cand.push_back(make_pair(v, s[i]+sq));
        }
        q = 10 * q + 9;
        sq += 9;
        t *= 10;
    }
    sort(ALL(cand));
    UNIQ(cand);

    const int sz = (int)cand.size();
    vector<ll> res;
    for (int i = 0; i < sz; i++) {
        bool f = true;
        for (int j = i+1; j < sz; j++) {
            if ((ld)cand[i].first/cand[i].second > (ld)cand[j].first/cand[j].second) {
                f = false;
                break;
            }
        }
        if (f) {
            res.push_back(cand[i].first);
        }
    }

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

void input() {
    cin >> k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

ll count_num(ll N, ll C, ll D, ll lcm) {
    ll divid = (N / C) + (N / D) - (N / lcm);
    return N - divid;

}

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll gcd = __gcd(C, D);
    ll lcm = C * D / gcd;
    cout << count_num(B, C, D, lcm) - count_num(A-1, C, D, lcm) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s, s1, s2, ss, s11, s22;

int main()
{
    cin>>s;
    ss=s;
    s1=s;
    int n, i;
    n=s.size();
    s1.erase((n-1)/2);
    s11=s1;
    reverse(s.begin(),s.end());
    s2=s;
    s2.erase(n-((n+3)/2)+1);
    s22=s2;
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(),s2.end());
    //cout<<s<<" "<<ss<<" "<<s1<<" "<<s11<<" "<<s2<<" "<<s22;
    if(s==ss && s1==s11 && s2==s22) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

	int a;
	int b;
	int c;

	scanf ( "%d%d%d" , &a , &b , &c );
	if ( a < b ) {
		if ( b < c ) {
			printf ( "Yes\n" );
		} else {
			printf ( "No\n");
		}
	} else {
		printf ( "No\n");
	}

	return 0 ;

}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  int c[101],a[101],n[101];
  cin>>q;
  int sum[101];
  for(int i=0;i<q;i++){
    cin>>c[i]>>a[i]>>n[i];
  }
  for(int i=0;i<q;i++){
    if(n[i]<=c[i] && n[i]<a[i]){
      sum[i]=n[i];
      c[i]-=n[i];
      a[i]-=n[i];
      int mn=min(a[i],c[i]/2);
      sum[i]+=mn;
      sum[i]+=(c[i]-mn*2)/3;
    }
    else if(a[i]<=c[i] && a[i]<=n[i]){
      sum[i]=a[i];
      sum[i]+=(c[i]-a[i])/3;
    }
    else sum[i]=c[i];
  }
  for(int i=0;i<q;i++) cout<<sum[i]<<endl;

  return 0;
}



Measured memory_bytes: 3080
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def rot(s, N):
    p = ord(s) - ord('A')
    p = (p + N) % 26
    return chr(ord('A') + p)


def main():
    N = int(readline())
    S = readline().rstrip().decode()
    print(''.join([rot(s, N) for s in S]))


if __name__ == '__main__':
    main()


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

int main(){
	
	int N;
	int r,d,cnt=1 ;
	int table[9][13][4] = {} ;
	
	for( int j=12 ; j>=0 ; j-=2 ){
		for( int i=8 ; i>=0 ; i-=2 ){
			table[i][j][0] = cnt++ ;
		}
		for( int i=7 ; i>=0 ; i-=2 ){
			table[i][j][0] = table[i+1][j][0];
			table[i][j][1] = table[i-1][j][0];
		}
	}
	for( int i=0 ; i<9 ; i+=2 ){
		for( int j=1 ; j<12 ; j+=2 ){
			table[i][j][0] = table[i][j+1][0];
			table[i][j][1] = table[i][j-1][0];
		}
	}
	for( int i=1 ; i<9 ; i+=2 ){
		for( int j=1 ; j<12 ; j+=2 ){
			table[i][j][0] = table[i+1][j+1][0];
			table[i][j][1] = table[i-1][j+1][0];
			table[i][j][2] = table[i+1][j-1][0];
			table[i][j][3] = table[i-1][j-1][0];
		}
	}
	
	cin >> N ;
	while( N-- ){
		cin >> r >> d ;
		r =  8 - ( (r-100)/100*2 + (r%100!=0) ) ;
		d = 12 - (     d/30*2    + (d% 30!=0) ) ;
		
		for( int i=0 ; i<4 ; i++ ){
			if( table[r][d][i] ){
				cout << ((i)?" ":"") << table[r][d][i] ;
			}
		}cout << endl ;
	}
	
	return 0;
}

Measured memory_bytes: 1160
S_ = input()
T = input()

def match(s,t):
    flag=True
    for i in range(len(s)):
        if s[i]!=t[i] and s[i]!='?':
            flag=False
            break
    return flag
    
cand = []
for i in range(len(S_)-len(T)+1):
    if match(S_[i:i+len(T)], T):
        s = S_[:i]+T+S_[i+len(T):]
        s = s.replace('?','a')
        cand.append(s)

if len(cand)==0:
    print('UNRESTORABLE')
else:
    print(sorted(cand)[0])


Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;
 
 
inline ll ksum(ll n, ll k){
  return k * (2*n - k - 1);
}

pii updtp2(pii p, int nw){
  if(p.first == -1) p.first = nw;
  else if(p.second == -1) p.second = nw;
  else if(p.first >= nw) {
    p.second = p.first;
    p.first = nw;
  }
  else if(p.second >= nw) p.second = nw;
  return p;
}
 
#define isValid(y,x) (y >=0 && y < n && x >= 0 && x < m)

const pii Dir[4] = {{-1,0}, {0,1}, {1,0}, {0,-1}};

int main(){
	
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;

    if(w >= v) cout << "NO" << endl;
    else {
        if(abs(a-b) <= (v-w)*t) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
	return 0;
} 

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

const int MAX_N = 2e5+10;
int N, A[MAX_N];
int occ[25];

void solve()
{
	ll ans = 0;
	memset(occ,-1,sizeof(occ));
	int i = 0;
	for(int j=0;j<N;++j){
		int a = A[j];
		for(int k=0;k<25;++k)if(a>>k&1){
			if(occ[k]!=-1){
				i=max(i, occ[k]+1);
			}
			occ[k]=j;
		}
		ans+=(j-i+1);
	}
	cout << ans << '\n';
}

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

Measured memory_bytes: 4356
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int,int> P;
int n;
vector<P> a;
vector<P> ans;
int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(P(x,i));
  }

  sort(a.begin(),a.end());

  int mid = n / 2;

  for(int i = 0; i < n; i++) {
    if(i < mid) {
      ans.push_back(P(a[i].second,a[mid].first));
    }
    else {
      ans.push_back(P(a[i].second,a[mid-1].first));
    }
  }
  sort(ans.begin(),ans.end());

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


Measured memory_bytes: 5488
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b;
    
    scanf("%d%d", &a, &b);
    
    if (a>=13) {
        printf("%d", b);
    } else if (a<=5) {
        printf("%d", 0);
    } else {
        printf("%d", b/2);
    }
    
    return 0;
}



Measured memory_bytes: 1696
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

using Edges = std::vector<std::vector<int>>;

struct Memo {
    int cnt;
    int parent;
    int low;
};

int dfs(int i, const Edges& edges, std::vector<Memo>& memo, int& cnt) {
    memo[i].cnt = cnt++;
    int ans = memo[i].cnt;
    for(auto v: edges[i]) {
        if(memo[v].cnt < 0) {
            memo[v].parent = i;
            ans = std::min(ans, dfs(v, edges, memo, cnt));
        } else {
            if(v != memo[i].parent) ans = std::min(ans, memo[v].cnt);
        }
    }
    memo[i].low = ans;
    return ans;
}

int main() {
    int V, E;
    std::cin >> V >> E;
    Edges edges(V, std::vector<int>());
    while(E--) {
        int s, t;
        std::cin >> s >> t;
        edges[s].push_back(t);
        edges[t].push_back(s);
    }

    std::vector<Memo> memo(V, Memo{-1, -1, -1});
    int cnt = 0;
    dfs(0, edges, memo, cnt);

    std::vector<std::pair<int, int>> ans;
    ans.reserve(V);
    for(int i = 0; i < V; ++i) {
        if(0 <= memo[i].parent && memo[memo[i].parent].cnt < memo[i].low) {
            if(i < memo[i].parent) ans.push_back(std::make_pair(i, memo[i].parent));
            else ans.push_back(std::make_pair(memo[i].parent, i));
        }
    }

    std::sort(begin(ans), end(ans), [](auto x, auto y){return x.first == y.first ? x.second < y.second : x.first < y.first;});

    for(auto val: ans) {
        std::cout << val.first << " " << val.second << "\n";
    }
    std::cout << std::flush;

    return 0;
}



Measured memory_bytes: 4708
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define f first
#define s second

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	freopen("text","r",stdin);

	int h,w;
	cin >> h >> w;
	int ch,cw,dh,dw;
	cin >> ch >> cw >> dh >> dw;
	ch--,cw--,dh--,dw--;
	vector<string> ar(h);
	for(auto &it : ar){
		cin >> it;
	}
	int adjx[] = {1,0,-1,0};
	int adjy[] = {0,1,0,-1};
	vector<int> dp[h];
	for(int i=0;i<h;i++){
		dp[i] = vector<int> (w,1e9);
	}
	priority_queue<pair<int,pair<int,int> >, vector<pair<int,pair<int,int> > >, greater<pair<int,pair<int,int> > > > pq;
	pq.push({0,{ch,cw}});
	dp[ch][cw] = 0;
	while(!pq.empty()){
		auto nw = pq.top();
		pq.pop();
		for(int i=0;i<4;i++){
			int nx = nw.s.f+adjx[i];
			int ny = nw.s.s+adjy[i];
			if(0 <= nx && nx < h && 0 <= ny && ny < w && ar[nx][ny] == '.' && dp[nx][ny] > dp[nw.s.f][nw.s.s]){
				dp[nx][ny] = dp[nw.s.f][nw.s.s];
				pq.push({dp[nx][ny],{nx,ny}});
			}
		}
		for(int i=-2;i<=2;i++){
			for(int j=-2;j<=2;j++){
				int nx = nw.s.f+i;
				int ny = nw.s.s+j;
				if(0 <= nx && nx < h && 0 <= ny && ny < w && ar[nx][ny] == '.' && dp[nx][ny] > dp[nw.s.f][nw.s.s]+1){
					dp[nx][ny] = dp[nw.s.f][nw.s.s]+1;
					pq.push({dp[nx][ny],{nx,ny}});
				}
			}
		}
	}
//	for(int i=0;i<h;i++){
//		for(int j=0;j<w;j++){
//			cout << dp[i][j] << ' ';
//		}
//		cout << '\n';
//	}
	cout << (dp[dh][dw] == 1e9 ? -1 : dp[dh][dw]) << '\n';
	
	return 0;
}

Measured memory_bytes: 8768
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  s <- getLine
  print $ solve s

solve :: String -> Int
solve s = ans where
  (_, _, _, ans) = foldl f (1, 0, 0, 0) s
  f (n, a, ab, abc) 'A' = (n, n `add` a, ab, abc)
  f (n, a, ab, abc) 'B' = (n, a, ab `add` a, abc)
  f (n, a, ab, abc) 'C' = (n, a, ab, abc `add` ab)
  f (n, a, ab, abc) '?' = (mul3 n, mul3 a `add` n, mul3 ab `add` a, mul3 abc `add` ab)
  f _ _ = undefined

add :: Int -> Int -> Int
add x y = (x + y) `mod` modN

mul3 :: Int -> Int
mul3 x = (x * 3) `mod` modN

modN :: Int
modN = 10 ^ 9 + 7


Measured memory_bytes: 27004
from itertools import product
from collections import defaultdict
MOD = 10**9 + 7
N = int(input())
D, L = 4, 3
AGC = list(range(L))
ATGC = range(D)
cur = defaultdict(lambda: 1)
# XAGC, XGAC, AXGC, AGXC, XACG: prohibited
flip = lambda x, n: x[:n] + [x[n+1],x[n]] + x[n+2:]
prohibited1 = [tuple(AGC)] + [tuple(flip(AGC,i)) for i in range(L-1)]
prohibited2 = ({(X,) + p for p in prohibited1 for X in ATGC} | 
             {tuple(flip([X]+AGC,0)) for X in ATGC} |
             {tuple(flip(AGC+[X],L-1)) for X in ATGC})
for p in prohibited1:
    cur[p] = 0
for _ in range(L,N):
    prev = cur
    cur = defaultdict(int)
    for recent in product(ATGC, repeat=L+1):
        if recent in prohibited2:
            continue
        else:
            cur[recent[1:]] += prev[recent[:-1]]
    for latest in product(ATGC, repeat=L):
        cur[latest] %= MOD

ans = sum(cur.values()) % MOD
if N < L:
    print(D**N)
elif N == L:
    print(D**L - len(prohibited1))
else:
    print(ans)

Measured memory_bytes: 43120
A, B, C = map(int, input().split())

if any(map(lambda x: x % 2 == 1, (A, B, C))):
    print(0)
elif A == B == C:
    print(-1)
else:
    count = 0
    while True:
        A, B, C = B // 2 + C // 2, A // 2 + C // 2, A // 2 + B // 2
        count += 1
        if any(map(lambda x: x % 2 == 1, (A, B, C))):
            break
    print(count)


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

int main() {
  double n,m,d;
  cin >> n >> m >> d;
  double ans = (m-1)*2*(n-d)/(n*n);
  if(d == 0) ans = (m-1)/n;
  cout << fixed;
  cout << setprecision(9) << ans << endl;
}

Measured memory_bytes: 3736
#include <stdio.h>

int main (void)

{

int n,ai,i;

long int x,y,z;

x=1000000;

y=-1000000; z=0;

scanf("%d",&n);

for(i=1;i<=n;i++)

{

scanf("%d",&ai);

if(ai>y)

{

y=ai;

}

if(ai<x)

{

x=ai;

}

z=z+ai;

}

printf("%d %d %ld\n",x,y,z);

return 0;

}

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

int main() {
    int N, T;
    cin >> N >> T;
    multimap <int, int> tc;
    int t, c;
    for (int i=0; i<N; i++) {
        cin >> c >> t;
        tc.insert(pair<int, int>(t,c));
    }
    int res=1000;
    bool ac = false;
    for (auto x : tc) {
        if (x.first<=T) {
            res=min(x.second, res);
            ac = true;
        }
    }
    if (ac) cout << res;
    else cout << "TLE";
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans =0;
  ans = (a * b) % 2;
  if (ans == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	char a;
	cin >> a;

	char b;
	if(a == 'A')
		b = 'T';
	else if(a == 'C')
		b = 'G';
	else if(a == 'T')
		b = 'A';
	else if(a == 'G')
		b = 'C';

	cout << b << endl;

	return 0;
}

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

int main(){
    int x;
    cin>>x;
    if(400<=x&&x<=599)
    cout<<8<<endl;
    if(600<=x&&x<=799)
    cout<<7<<endl;
    if(800<=x&&x<=999)
    cout<<6<<endl;
    if(1000<=x&&x<=1199)
    cout<<5<<endl;
    if(1200<=x&&x<=1399)
    cout<<4<<endl;
    if(1400<=x&&x<=1599)
    cout<<3<<endl;
    if(1600<=x&&x<=1799)
    cout<<2<<endl;
    if(1800<=x&&x<=1999)
    cout<<1<<endl;
    return 0;    
}

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

int main()
{
   int x,k;
   cin>>k>>x;
   int stp=k-1;
   int st=x-stp;
   for(int i=1;i<=stp;i++){ 
   cout<<st<<" ";
   st++;
   } 
   cout<<x<<" ";
   x++;
   for(int i=1;i<=stp;i++){ 
       cout<<x++<<" ";
   } 
   
   
 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200050
#define ll long long
#define pb push_back
#define x first
#define y second
using namespace std;
double pi = acos(-1);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    double r; cin>>r;
    cout<<fixed<<setprecision(20)<<2.0*pi*r;
    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

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

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

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

    string s;
    int w;
    cin >> s >> w;
    REP(i, s.size()){
        if(i % w == 0) cout << s[i];
    }
    cout<< endl;
}


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

int main(void){

    int H,W;
    cin >> H >> W;
    
    string S[H];
    int calc = 0;
    for(int i = 0; i < H;i++){
        cin >> S[i];
    }
    
    
    int F[H][W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W ; j++){
            F[i][j] = -1;
            if(S[i][j]=='#')calc++;
            
        }
        
        
    }
    
    
    
    queue<pair<int,int>> que;
    que.push(make_pair(0,0));
    int h;
    int w;
    int cont;
    int ans = 0;
    F[0][0] = 0;
    while(que.size()){
        
        // for(int i = 0; i < H; i++){
        //     for(int j = 0; j < W;j++){
        //         cout << right << setw(2) << F[i][j] <<  " ";
        //     }
        //     cout << endl;
        // }
        // cout <<"-----------------------"<<endl;
        
        
        h = que.front().first;
        w = que.front().second;
        que.pop();
        cont = F[h][w];
        // cout << h << " "<< H <<endl;
        // cout << w << " "<< W <<endl;
        if(h == H-1 && w == W-1){
            ans = cont;
            break;
        }
        
        
        
        if(h < H - 1){
            if(S[h+1][w]!='#'&&F[h+1][w]==-1){
                F[h+1][w] = cont + 1;
                que.push(make_pair(h+1,w));
            }
        }
        
        if(0 < h){
            if(S[h-1][w]!='#'&&F[h-1][w]==-1){
                F[h-1][w] = cont + 1;
                que.push(make_pair(h-1,w));
            }
        }
        
        if(w < W - 1){
            if(S[h][w+1]!='#'&&F[h][w+1]==-1){
                F[h][w+1] = cont + 1;
                que.push(make_pair(h,w+1));
            }
        }
        
        if(0 < w){
            if(S[h][w-1]!='#'&&F[h][w-1]==-1){
                F[h][w-1] = cont + 1;
                 que.push(make_pair(h,w-1));
            }
        }
        
    }
    
    if(h!=H-1||w!=W-1){
        cout << -1 <<endl;
        return 0;
    }
    
    
    // cout << H*W << endl;
    // cout << ans << endl;
    // cout << calc << endl;
    cout << H*W - ans - calc -1 << endl;
    
    
}


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

ll get_lucas(vector <ll> &memo, int n);


int main(){
    int n; cin >> n;
    vector <ll> memo(90, -1);
    memo.at(0) = 2; memo.at(1) = 1;
    cout << get_lucas(memo, n) << endl;
}

ll get_lucas(vector <ll> &memo, int n){
    if (memo.at(n) != -1) return memo.at(n);

    memo.at(n) = get_lucas(memo, n - 1) + get_lucas(memo, n - 2);
    return memo.at(n);
}


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

      
    if((N%1000) <= 0){
      cout << "Yes" << endl;
    }
      
    else if((N/10)/(N/1000)==111){
	  cout << "Yes" << endl;
    }
      
    else if((N%1000)/(N%10)==111){
      cout << "Yes" << endl;
    }
      
    else{
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n, y = map(int, input().split())
a = -1
b = -1
c = -1
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = n - i - j
        if 10000 * i + 5000 * j + 1000 * k == y:
            a = i
            b = j
            c = k

print(a, b, c)

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

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

  bool check[26] = {false};
  string Ans = "None";

  rep(i, 0, S.size()) {
    check[(int)(S[i])-97] = true;
  }

  rep(j, 0, 26) {
    if (check[j] == false) {
      Ans = (char)(97+j);
      break;
    }
  }

  cout << Ans << endl;
}


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

max_dif = 0
dif = 0

for i in range(0, N):
    for j in range(i+1, N):
        dif = abs(A[i]-A[j])
        if max_dif < dif:
            max_dif = dif

print("{}".format(max_dif))

Measured memory_bytes: 9128