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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define DI(v,i) distance((v).begin(),(auto(i)))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------
int V, E ;
vector<int> seen ;
vector<vector<int>> graph ;
queue<int> que ;
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V >> E ;

    vector<int> zero(V,0) ;
    vint ans(V,0) ;
    seen = zero ;

    for(int i=0;i<V;i++){
        graph.push_back(vector<int>()) ;
    }


    for(int i=0;i<E;i++){
        int a, b ;
        cin >> a >> b ;
        graph[a-1].push_back(b-1) ;
        graph[b-1].push_back(a-1) ;
    }
    
    
    que.push(0) ;
    seen[0] = 1 ;

    while(!que.empty()){
        int k = que.front() ;
        que.pop() ;
        for(int i=0;i<graph[k].size();i++){
            if(seen[graph[k][i]]==0){
                que.push(graph[k][i]) ;
                seen[graph[k][i]] = 1 ;
                ans[graph[k][i]] = k + 1 ;
            }
        }
    }

    REP(i,V){
        if(seen[i]==0){
            no() ;
            return 0 ;
        }
    }
    yes() ;
    FOR(i,1,V){
        cout << ans[i] <<endl ;
    }
    

    return 0;
}



Measured memory_bytes: 10944
#include<bits/stdc++.h>
using namespace std;
#define int 		  long long
#define	pb 			  push_back
#define all(a)		  (a).begin(),(a).end()
#define sz(x)		  (int)x.size()
#define endl	 	  "\n"
#define MOD 		  1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
//int dp[1000001] = {0};
void solve(){
	int n, res=0;
	cin>>n;
	int arr[n];
	FOR(i, 0, n) cin>>arr[i];
	for(int b = 0; b <= 60; b++){
        int x[2] = {0};
        for(int i = 0; i < n;i++){
            x[(arr[i]>>b)&1]++;
        }
        res += (x[0]*x[1])%MOD*((1LL<<b)%MOD)%MOD;
        res %= MOD;
    }
    cout<<res;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
	//	cout<<"Case #"<<i<<":"<<endl;
		solve();
	}
	return 0;
 
}


Measured memory_bytes: 2560
n, a, b, c, d =[int(i) for i in input().split()]
s = input()

if c < d:
    s1 = s[a-1:d]
    if s1.count("##") == 0:
        print("Yes")

    else:
        print("No")

else:
    s1 = s[a-1:c]
    s2 = s[b-2:d+1]
    if s1.count("##") == 0 and s2.count("...") != 0:
        print("Yes")

    else:
        print("No")

Measured memory_bytes: 3572
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int z[100005];
		int ans=0;
		for(int i=1;i<=n;i++)
		scanf("%d",&z[i]);
		sort(z,z+n+1);
		ans=(z[n/2+1]-z[n/2]);
		printf("%d\n",ans);
	}
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int m[] = {1, 5, 10, 50, 100, 500};
  int sum = 0;
  rep(i, 0, 6) {
    int c;
    cin >> c;
    sum += c * m[i];
  }
  cout << (sum >= 1000) << endl;
}



Measured memory_bytes: 3120
t_hp,t_atk,a_hp,a_atk = gets.split(" ").map(&:to_i)

loop do
  a_hp -= t_atk
  if a_hp <= 0
    puts "Yes"
    exit
  end
  t_hp -= a_atk
  if t_hp <= 0
    puts "No"
    exit
  end
end

Measured memory_bytes: 14296
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <cassert>
#include <string>
using namespace std;

#define N1 4
#define N2 16  
#define LIMITMAX 100
//#define false 0
//#define true 1

struct PUZZLE{
  int f[N2], kuuhaku ,MD;/*マンハッタン距離*/
  //int cost;
};

static const int dx_123[4] = {0, -1, 0, 1};//４方向
static const int dy_123[4] = {1, 0, -1, 0};//４方向
static const char houkou[4] ={'r', 'u', 'l', 'd'};//右:right,　上:up,　左:left,　下:down

int ManhattanDistance[N2][N2];
PUZZLE jyoutai;
int limit;//深さのlimit
int miti[LIMITMAX];

int GetallManhattanDistance(PUZZLE);
bool dfs(int, int);
//int max(int, int);
//int min(int, int);
string  iterative_deepning(PUZZLE); //反復深化


int main(){

  int i,j,k;
  PUZZLE in;
  
  for(i=0;i<N2;i++){
    for(j=0;j<N2;j++){
      ManhattanDistance[i][j] = abs( i/N1 - j/N1 ) + abs(i%N1 -j%N1); 
    }
  }

   
  for(i=0;i<N2;i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] =  N2;
      in.kuuhaku = i;
    }
  }

  string kotae = iterative_deepning(in);

  cout << kotae.size();
  cout << endl;
 
  return 0;
}

/*
  void  swap(int *a , int *b){
  int *tmp;
  
  tmp = a;
  a = b ;
  b = tmp;
  
  }
*/
int GetallManhattanDistance(PUZZLE p){//全てのマンハッタン距離を取得する

  int goukei = 0;
  int i,j,k;

  for(i=0;i<N2;i++){
    if(p.f[i] == N2)continue;
    goukei += ManhattanDistance[i][p.f[i]-1];
  }

  return goukei;
}

bool dfs(int depth, int prev){

  int i,j,k;
  int r;
  int sx,sy;
  PUZZLE tmp;
  int tx,ty;
  
  if(jyoutai.MD == 0) return true ;
  //現在の深さにヒューリスティックを足して制限を超えたら枝を切る

  if( depth + jyoutai.MD > limit ) return false;

  sx = jyoutai.kuuhaku / N1;
  sy = jyoutai.kuuhaku % N1;

  for(r=0;r<4;r++){
    tx = sx + dx_123[r];
    ty = sy + dy_123[r];

    if(tx < 0 || tx >= N1 || ty < 0 || ty >= N1 ) continue;
    if(max(prev, r) - min(prev, r) == 2 ) continue;
    tmp = jyoutai;
    //マンハッタン距離の差分を計算しつつ、ピースをスワップ
    jyoutai.MD -= ManhattanDistance[tx * N1 + ty][jyoutai.f[tx * N1 + ty]-1];
    jyoutai.MD += ManhattanDistance[sx * N1 + sy][jyoutai.f[tx * N1 + ty]-1];
    swap(jyoutai.f[tx * N1 + ty], jyoutai.f[sx * N1 + sy]);
    jyoutai.kuuhaku = tx * N1 + ty;
    if( dfs(depth + 1, r) ){
      miti[depth] = r;
      return true;
    }
    jyoutai = tmp;
  }
  
  return false;
}
/*
  int max(int a, int b){
  if(a<b) return b;
  return a;
  }

  int min(int a, int b){
  if(a<b) return a;
  return b;
  }
*/




string  iterative_deepning(PUZZLE in){//反復深化

  int i,j,k;
  //string  kotae = "";
  //char kotae2[] = "unsolvable";
  
  in.MD = GetallManhattanDistance(in);//初期のマンハッタン距離

  for(limit = in.MD; limit <= LIMITMAX; limit++ ){
    jyoutai = in;
    if( dfs(0, -100) ){
      string kotae = "";
      for(i = 0; i < limit; i++) kotae += houkou[miti[i]];
      return kotae;
    } 
  }
  
  return "できませんでした";
  
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


ll C[1001][1001]; // C[n][k] -> nCk  O(n^2)
void Cinit(int N=1000){ //オーバーフローに注意
  rep(i,N+1){
    rep(j,i+1){
      if(j==0 or j==i){
        C[i][j]=1;
      }else{
        C[i][j]=(C[i-1][j-1]+C[i-1][j]);
      }
    }
  }
}

void Main(){


  int N,A,B;
  cin>>N>>A>>B;

  vector<ll> v(N);
  rep(i,N){
    cin>>v[i];
  }
  sort(ALL(v),greater<ll>());

  double ave=0;

  rep(i,A){
    ave+=v[i];
  }

  ave/=A;

  cout<< ave<<"\n";

  int ct=0;
  int ct2=0;

  rep(i,N){
    if(v[A-1]==v[i]) {
      ct++;
      if(i<A) ct2++;
    }
  }


  Cinit();
  // ct 個から、ct2 個以下を選ぶ。

  ll ans=0;

  if(v[0]==v[A-1]){
    rep(i,min(ct-ct2+1,B-A+1)){
      ans+=C[ct][ct2+i];
    }
  }
  else{
    ans+=C[ct][ct2];
  }


  cout<< ans<<"\n";

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


Measured memory_bytes: 7424
from collections import deque
import bisect
import sys
sys.setrecursionlimit(500000)

n = int(input())
a = list(map(int, input().split()))
to=[list() for _ in range(n)]

for i in range(n-1):
    u,v = map(int, input().split())
    u-=1
    v-=1
    to[u].append(v)
    to[v].append(u)

INF=1001001001
dp = [INF]*n
dp[0]=a[0]
ansls=[0]*n
ansls[0]=1
history=deque()
def dfs(u,p,rank):
    for v in to[u]:
        if v==p:
            continue
        idx=bisect.bisect_left(dp,a[v])
        prv=dp[idx]
        dp[idx]=a[v]       
        history.append((idx,prv))
        ansls[v]=bisect.bisect_left(dp,INF)
        dfs(v,u,rank+1)
        while len(history)>rank:
            idx,prv =history.pop()
            dp[idx] = prv

dfs(0,-1,0)

print(*ansls,sep='\n')

Measured memory_bytes: 387956
#include <bits/stdc++.h>
using namespace std;
int main(){
	int W, H, x, y;
	cin >> W >> H >> x >> y;
	long double area = double(W)/2.0*double(H);
	cout << area << endl;
	int flg = 0;
	if(2*y == H && 2*x == W)
		flg++;
	cout << flg << endl;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
D = {"AB": 2, "AC": 1, "BC": 0}
N, a, b, c = map(int, input().split())
X = [a, b, c]
S = [D[input()] for _ in range(N)]
ANS = []
if max(X) == 0:
    print("No")
    exit()

if sum(X) == 1:
    t = 0 if a else 1 if b else 2
    for s in S:
        if X[s]:
            print("No")
            exit()
        t ^= s ^ 3
        ANS.append(t)
        X[s-1] ^= 1
        X[s-2] ^= 1
    print("Yes")
    print("\n".join([chr(t+65) for t in ANS]))
    exit()

s = S[0]
if X[s-1] + X[s-2] == 0:
    print("No")
    exit()

for i, s in enumerate(S):
    if X[s-1] > X[s-2]:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    elif X[s-1] < X[s-2]:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1
    elif i == N - 1 or S[i+1] == (s-1) % 3:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    else:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1

print("Yes")
print("\n".join([chr(t+65) for t in ANS]))

Measured memory_bytes: 85980
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <stdio.h>

int main(void){
  int h1,m1,h2,m2,t,k;
  std::cin >>h1>>m1>>h2>>m2>>k;

  t=(h2-h1)*60+(m2-m1);
  
  if(t==k){
    std::cout << "0"; 
  }else{
    std::cout << t-k;
  }
  return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[] sum = new int[n];
        boolean a = s[0] == 'A';
        for (int i = 1; i < n; i++) {
            sum[i] = sum[i -1];
            if(s[i] == 'A'){
                a = true;
                continue;
            }
            if(s[i] == 'C' && a) sum[i]++;
            a = false;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt() -1;
            int r = sc.nextInt() -1;
            sb.append(sum[r] - sum[l]).append("\n");
        }
        System.out.println(sb.toString());
        sc.close();
    }

}


Measured memory_bytes: 67512
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];

    if a == b {
        println!("0");
    } else if (a + b) %2 == 0 {
        println!("{}", (a + b) / 2);
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
string s = "2019/04/30";
int main()
{
	string t;
	cin>>t;
	if(t<=s)
		cout<<"Heisei"<<endl;
	else
		cout<<"TBD"<<endl;
	return 0;
}

Measured memory_bytes: 256
import heapq
N, K = map(int, input().split())
d = [int(x) for x in map(int, input().split())]
e = d[::-1]

res = 0
num = min(N, K)
for i in range(num + 1):
    for j in range(num - i, -1, -1):
        s = d[:i] + e[:j]
        if not s:
            continue
        heapq.heapify(s)
        res = max(res, sum(s))
        l = min(i + j, K - (i + j))
        while l:
            heapq.heappop(s)
            res = max(res, sum(s))
            l -= 1
print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     int ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/











int n;
int t[100005],a[100005];
int main(){
     cin>>n;
     rep(i,n)cin>>t[i];rep(i,n)cin>>a[i];
     vector<pair<int,int>> res(n+1);
     res[0]={t[0],t[0]};
     for(int i=1;i<n;i++){
          if(t[i]>t[i-1]){res[i]={t[i],t[i]};}
          else {
               res[i]={1,t[i]};
          }
        //  cout<<i<<" "<<res[i].fi<<" "<<res[i].se<<"  "<<t[i-1]<<" "<<t[i]<<"\n";
     }
     for(int i=n-1;i>=0;i--){
          if(i==n-1){
               int l=a[n-1];
               if(res[n-1].fi<=l&&res[n-1].se>=l){
                    res[n-1]={l,l};
               }
               else {
                    cout<<0;return 0;
               }
          }
          else {
               if(a[i]>a[i+1]){
                    int l=a[i];
                    if(res[i].fi<=l&&res[i].se>=l){
                         res[i]={l,l};
                    }
                    else {
                         cout<<0;return 0;
                    }
               }
               else if(a[i]==a[i+1]){
                    int l=1,r=a[i];
                    int mx=max(res[i].fi,l);int mn=min(res[i].se,r);
                    if(mn<mx){cout<<0;return 0;}
                    else res[i]={mx,mn};
               }
          }
     }
     ll ans=1LL;
     for(int i=0;i<n;i++){
          int l=abs(res[i].se-res[i].fi+1);
          ans=(ans*l)%mod;
     }
     cout<<ans;
}












































Measured memory_bytes: 4780
#include<iostream>
using namespace std;
int main(){
    int i,a,b;
    string str1;
    while(1){
    cin >> str1 ;
    if(str1=="-")break;
    cin >> a;
    for(i=0;i<a;i++){
        cin >> b;
        str1=str1.substr(b)+str1.substr(0,b);
        }
        cout << str1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int a, b, flag=0;
	cin >> a >> b;
	string s;
	cin >> s;
	rep(i,a){
		if(!(s[i]>='0' && s[i]<='9')) flag++; 
	}
	if(s[a] != '-') flag++;
	loop(i, a+1, s.length()){
		if(!(s[i]>='0' && s[i]<='9')) flag++;
	}
	puts(flag==0? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
def main():
    kai, wo = 0, []
    kai = input()
    while(True):
        try:
            wo.append(raw_input())
        except EOFError:
            break
    R, S, O = 0, 0, 0
    for i in wo:
        if i == "HIT":
            if R < 3:
                R += 1
            else:
                S += 1

        elif i == "OUT":
            O += 1
            if O >= 3:
                print S
                R, S, O = 0, 0, 0
            else: pass
        elif i == "HOMERUN":
            R += 1
            S += R
            R = 0



if __name__=="__main__":
    main()

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    ll n,i,a,b,c,val;
    cin >> n;
    vector< ll >v(n + 5);
    rep(a,1,n){
        val = a*a;
        if(val > n)break;
        rep(b,1,n){
            val =  (a * a) + (b*b) + (a*b);
            if(val > n)break;
            rep(c,1,n){
                 ll val1 = val + (c*c) + (b*c) + (a*c);
                 if(val1 > n)break;
                 v[val1]++; 
            }
        }
    }
    rep(i,1,n+1)cout << v[i] << nl;
    
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >> N;
    char c[N];
    for(int i=0;i<N;i++)cin>>c[i];
    int count_W = 0,count_R = 0;
    for(int i=0;i<N;i++){
        if(c[i] == 'W')count_W++;
        else count_R++;
    }
    int change = 0;
    int l = 0,r = N-1;
    while(l < r){
        if(c[l] == 'W' && c[r] == 'R'){
            change++;
            l++;
            r--;
        }
        else{
            if(c[l] != 'W'){
                l++;
            }
            if(c[r] !='R'){
                r--;
            }
        }
    }
    int ans = min(change,min(count_R,count_W));
    cout << ans << endl;
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////

#define isIn(x,y) 0<=x&&x<H&&0<=y&&y<W

ll H,W;
ll Ch, Cw, Dh, Dw;
char S[1010][1010];
ll mk[1010][1010];

const ll gx[] = {1, 0, -1, 0};
const ll gy[] = {0, 1, 0, -1};
ll i, j, k;

int main(){
    scanf("%lld%lld", &H, &W);
    scanf("%lld%lld", &Ch, &Cw);
    scanf("%lld%lld", &Dh, &Dw);
    --Ch, --Cw, --Dh, --Dw;
    rep(i,0,H){
        scanf("%s", S[i]);
    }
    /*
    rep(i,0,H){
        rep(j,0,W){
            printf("%c", S[i][j]);
        }
        printf("\n");
    }*/

    mk[Ch][Cw] = 1e9;
    priority_queue<pair<ll,pll>> q;
    q.push({1e9, {Ch, Cw}});

    while(q.size()){
        auto qa = q.top();
        q.pop();
        ll c = qa.fi;
        ll bx = qa.se.fi;
        ll by = qa.se.se;
        if(mk[bx][by]!=c)
            continue;
        //printf("%lld,%lld:%lld\n", bx, by, c);

        rep(i,0,4){
            ll x = bx + gx[i];
            ll y = by + gy[i];
            
            if(isIn(x,y)&&S[x][y]=='.'&&mk[x][y]<c){
                q.push({c, {x, y}});
                mk[x][y] = c;
            }
        }

        rep(i,0,5){
            rep(j,0,5){
                ll x = bx + i - 2;
                ll y = by + j - 2;
                if(isIn(x,y)&&S[x][y]=='.'&&mk[x][y]<c-1){
                    q.push({c - 1, {x, y}});
                    mk[x][y] = c - 1;
                }
            }
        }
        
    }

    if(mk[Dh][Dw]==0){
        printf("-1\n");
    }else{
        printf("%lld\n", (ll)1e9 - mk[Dh][Dw]);
    }
    return 0;
}

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

#define NDEBUG
int N;
int a[50];
int abs(int a){return (a<0)?-a:a;}
int main(void){
    scanf("%d",&N);
    int max_a=-1000001;
    int max_index = -1;
    int min_a= 1000001;
    int min_index = -1;
    for(int i = 0; i < N; i++){
        scanf("%d",a+i);
        if(a[i] > max_a){
            max_a=a[i];
            max_index = i;
        }
        if(a[i] < min_a){
            min_a=a[i];
            min_index = i;
        }
    }
    int absmax= (abs(max_a) > abs(min_a))? max_a : min_a;
    int absindex = (abs(max_a) > abs(min_a))? max_index : min_index;
    if(absmax > 0){
        printf("%d\n", N+(N-1));
        for(int i = 0; i < N ; i++){
            printf("%d %d\n",absindex+1,i+1);
            #ifndef NDEBUG
            a[i] += a[absindex];
            for(int i = 0; i < N; i++){
                printf("%d,",a[i]);
            }puts("");
            #endif
        }
        for(int i = 1; i < N ; i++){
            printf("%d %d\n",i-1+1,i+1);
            #ifndef NDEBUG
            a[i] += a[i-1];
            for(int i = 0; i < N; i++){
                printf("%d,",a[i]);
            }puts("");
            #endif
        }
    }else /*absmax < 0*/{
        printf("%d\n", N+(N-1));
        for(int i = 0; i < N ; i++){
            printf("%d %d\n",absindex+1,i+1);
        }
        for(int i = N-1; i >= 1 ; i--){
            printf("%d %d\n",i+1,i-1+1);
        }
    }
}

Measured memory_bytes: 128
let ext_euclid a b =
  let rec doit a b x y =
    if b = 0 then (1, 0, a)
    else
      let (y, x, d) = doit b (a mod b) x y in
      (x, y - (a / b) * x, d) in
  doit a b 0 0 |> (fun (x, y, _) -> (x, y))

let () =
  let (a, b) = Scanf.scanf "%d %d\n" (fun a b -> (a, b)) in
  let (x, y) = ext_euclid a b in
  Printf.printf "%d %d\n" x y

Measured memory_bytes: 2424
#include <iostream>
#include <vector>

using namespace std;


int main() {
	int n;
	cin >> n;
	int* s = new int[n];
	for(int i = 0;i < n;i++) cin >> s[i];
	int q;
	cin >> q;
	int c = 0;
	for(int i = 0;i < q;i++) {
		int t;
		cin >> t;
		int v = 0;
		for(int j = 0;j < n;j++) {
			if(s[j] == t) v++;
		}
		if(v != 0) c++;
	}
	cout << c << endl;
}


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

int main(void)
{
	int N;
	scanf("%d", &N);
	int n = (int)sqrt((double)N);
	if ((n*n) == N) printf("%d", N);
	else{
		printf("%d", (n*n));
	}
	return 0;
}

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

int main() {
    ll X; cin >> X;
    map<ll, ll> p;

    for (ll i = 0; i <= 2000; i++) {
        p[i * i * i * i * i] = i;
        p[- i * i * i * i * i] = -i;
    }
    for (auto k : p) {
        ll ax, a; tie(ax, a) = k;
        if (p.count(X+ax) != 0) {
            cout << p[X+ax] << ' ' << a << endl;
            return 0;
        }
        if (p.count(X-ax) != 0) {
            cout << a << ' ' << p[X-ax] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3884
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

/// double で計算しても AC はとれる
int calc(int[] a) {
    double agv = 1.0 * a.sum / a.length;
    double best = int.max;
    int ans = 0;
    for (int i = 0; i < a.length; i++) {
        double d = abs(agv - a[i]);
        if (d < best) {
            best = d;
            ans = i;
        }
    }
    return ans;
}

/// 整数のみで答えを求める
int calc2(int[] a) {
    int sum = a.sum;
    int ans = 0;
    int best = int.max;
    int n = cast(int) a.length;
    for (int i = 0; i < a.length; i++) {
        int d = abs(sum - a[i] * n);
        if (d < best) {
            best = d;
            ans = i;
        }
    }
    return ans;
}

void main() {
    readint;
    auto a = readints;
    // writeln(calc(a));
    writeln(calc2(a));
}


Measured memory_bytes: 256
function main(input) {
    input = parseInt(input);
    var ans = 0;
    for (var i = 1; i < input+1; i++) {
        for (var j = 1; j < input+1; j++) {
            for (var k = 1; k < input+1; k++) {
                ans += gcd(k, gcd(i, j));
            }
        }
    }

    console.log(ans);
}

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

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

Measured memory_bytes: 31656
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
	string s;
	cin>>s;
	ll n=s.size();
	rp(i,0,n)cout<<'x';
	cout<<endl;
}


Measured memory_bytes: 384
def q1():
    n = int(input()[-1])
    if n in [2, 4, 5, 7, 9]:
        print("hon")
        return
    if n in [0, 1, 6, 8]:
        print("pon")
        return
    if n in [3]:
        print("bon")
        return


q1()


Measured memory_bytes: 9196
import java.util.*;

class Main {
   public static void main(String[] args)
   {
      Scanner scan = new Scanner(System.in);
      int     a    = scan.nextInt();
      int     b    = scan.nextInt();

      if(a % 2 == 1 && b % 2 == 1){
         System.out.println("Odd");
         }
      else{
          System.out.println("Even");
          }
   }
}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

struct ps{
    int l=0,r=0,d=0,u=0;
};

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(ps x) { cerr << "{"<<x.l <<"," << x.r <<","  << x.u <<"," << x.d <<"}" ;}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int h,w;
    scanf("%d%d",&h,&w);
    vector<string> g(h);
    for(int i=0;i<h;i++){
        cin>>g[i];
    }
    vector<vector<ps>> c(h,vector<ps>(w));
    for(int i=0;i<h;i++){
        if(g[i][0]=='#')c[i][0].l=1;
        for(int j=1;j<w;j++){
            if(g[i][j]=='#'){
                c[i][j].l=j+1;
            }
            else{
                c[i][j].l=c[i][j-1].l;
            }
        }
        if(g[i][w-1]=='#')c[i][w-1].r=w;
        else c[i][w-1].r=w+1;
        for(int j=w-2;j>=0;j--){
            if(g[i][j]=='#'){
                c[i][j].r=j+1;
            }
            else{
                c[i][j].r=c[i][j+1].r;
            }
        }
    }
    for(int i=0;i<w;i++){
        if(g[0][i]=='#')c[0][i].u=1;
        for(int j=1;j<h;j++){
            if(g[j][i]=='#'){
                c[j][i].u=j+1;
            }
            else{
                c[j][i].u=c[j-1][i].u;
            }
        }
        if(g[h-1][i]=='#')c[h-1][i].d=h;
        else c[h-1][i].d=h+1;
        for(int j=h-2;j>=0;j--){
            if(g[j][i]=='#'){
                c[j][i].d=j+1;
            }
            else{
                c[j][i].d=c[j+1][i].d;
            }
        }
    }
    debug(c[0]);
    debug(c[1]);
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(g[i][j]=='#'){
                continue;
            }
            else{
                int rl=c[i][j].r-c[i][j].l-1;
                int ud=c[i][j].d-c[i][j].u-1;
                debug(i,j,rl,ud);
                ans=max(ans,rl+ud-1);
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 73544
#include<stdio.h>
int main() {

	int a, b, c, k, i;

	scanf("%d%d%d%d", &a, &b, &c, &k);

	for (i = 1; i <= k; i++) {
		if (a >= b)
			b *= 2;
		else if (b >= c)
			c *= 2;
		else 
			break;
	}

	if (a < b && b < c)
		printf("Yes");
	else
		printf("No");

	return 0;
}

Measured memory_bytes: 2160
def l_in(type_): return list(map(type_, input().split()))
def i_in(): return int(input())
def m_in(type_): return map(type_, input().split())
def r_in(n, type_): return [type_(input()) for _ in range(n)]
ans = None

a, b, c, d = m_in(int)
ans = max(a*c, a*d, b*c, b*d)

print(ans)


Measured memory_bytes: 9216
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=305,inf=1e8;
#define pb push_back
struct lines{
	int to,flow,cap;
}l[maxn*maxn*5];
vector<int> g[maxn];
int cur[maxn],d[maxn],t=-1,S,T;
bool v[maxn];

inline void add(int from,int to,int cap){
	l[++t]=(lines){to,0,cap},g[from].pb(t);
	l[++t]=(lines){from,0,0},g[to].pb(t);
}

inline bool BFS(){
	memset(v,0,sizeof(v)),v[S]=1,d[S]=0;
	queue<int> q; q.push(S);
	int x; lines e;
	
	while(!q.empty()){
		x=q.front(),q.pop();
		for(int i=g[x].size()-1;i>=0;i--){
			e=l[g[x][i]];
			if(e.flow<e.cap&&!v[e.to]) v[e.to]=1,d[e.to]=d[x]+1,q.push(e.to);
		}
	}
	
	return v[T];
}

int dfs(int x,int A){
	if(x==T||!A) return A;
	int flow=0,f,sz=g[x].size();
	for(int &i=cur[x];i<sz;i++){
		lines &e=l[g[x][i]];
		if(d[x]+1==d[e.to]&&(f=dfs(e.to,min(e.cap-e.flow,A)))){
			A-=f,flow+=f;
			e.flow+=f,l[g[x][i]^1].flow-=f;
			if(!A) break;
		}
	}
	
	return flow;
}

inline int max_flow(){
	int an=0;
	while(BFS()){
		memset(cur,0,sizeof(cur));
		an+=dfs(S,inf);
	}
	return an;
}

int n,m;
char ch;

int main(){
	scanf("%d%d",&n,&m),S=0,T=n+m+1;
	for(int i=1;i<=n;i++)
	    for(int j=1;j<=m;j++){
	    	ch=getchar();
	    	while(ch!='.'&&ch!='o'&&ch!='S'&&ch!='T') ch=getchar();
	    	if(ch!='.') add(i,j+n,1),add(j+n,i,1);
	    	if(ch=='S') add(S,i,inf),add(S,j+n,inf);
	    	else if(ch=='T') add(i,T,inf),add(j+n,T,inf);
		}
	
	int ans=max_flow();
	if(ans>=inf) puts("-1");
	else printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 896
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int k, t; cin >> k >> t;
	vector<int> v(t); rep(i, t) cin >> v[i];

	sort(ALL(v), greater<int>());
	int a = 0;
	rep(i, t){
		a = abs(a - v[i]);
	}

	if(a >= 2){
		cout << a -1 << endl;
	}
	else{
		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
using namespace std;
typedef long long ll;

bool num(ll n){
    ll a[10]={};
    while(n!=0){
        a[n%10]++;
        n/=10;
    }
    if(a[3]>0&&a[5]>0&&a[7]>0) return true;
    return false;
}

ll dfs(ll n,ll a){
    if(n<a) return 0;
    if(num(a)) return dfs(n,a*10+3)+dfs(n,a*10+5)+dfs(n,a*10+7)+1;
    return dfs(n,a*10+3)+dfs(n,a*10+5)+dfs(n,a*10+7);
}
int main(void){
    ll n;
    cin>>n;
    cout<<dfs(n,0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,zx,xc,f[200009],pas[200009],inn[200009],de[200009];
vector <int> v[200009];
set <int> s;
set <int>::iterator tt,t;
void dfs(int q, int w){
    t=s.lower_bound(f[q]);
    if(t==s.end()){
        s.insert(f[q]);
        inn[q]=f[q];
    }else{
        if((*t)==f[q]){
            
        }else{
            inn[q]=f[q];
            de[q]=(*t);
            s.erase(t);
            s.insert(f[q]);
        }
    }
    pas[q]=s.size();
    for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
        if((*it)==w) continue;
        dfs((*it),q);
    }
    if(inn[q]!=0) s.erase(s.lower_bound(inn[q]));
    if(de[q]!=0) s.insert(de[q]);
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(i=1; i<=a; i++) cin>>f[i];
    for(i=1; i<a; i++){
        cin>>c>>d;
        v[c].push_back(d);
        v[d].push_back(c);
    }
    dfs(1,0);
    for(i=1; i<=a; i++) cout<<pas[i]<<endl;
    return 0;
}

Measured memory_bytes: 31952
const  MAXN = 100000;
var n,a,i,j,k,x: longint;
    dp:array[0..MAXN] of int64;

procedure Nhap;
begin
        readln(n,a);
end;

procedure Init;
begin
        dp[n*a]:= 1;
end;

procedure QHD;
begin
        for k:= 1 to n do
        begin
                read(x);
		for j:= 0 to 4999 do
                begin
			dp[5000 - i + j]:= dp[i + j];
			if (j - x + a >= 0) and (j - x + a < 5000) then
                        dp[5000 - i + j]:= dp[5000 - i + j] + dp[i + j -x + a];
		end;
		i:= 5000 - i;
	end;
end;

BEGIN
        Nhap;
        Init;
        QHD;
	writeln(dp[i + n*A] - 1);
END.

Measured memory_bytes: 128
n = int(input())
S = input()
l = len(S)

S += 'eeee'

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            # tmp = str(i)+str(j)+str(k)
            m = 0
            while S[m] != str(i):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(j):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(k):
                m += 1
                if m >= l:
                    break
            if m < l:
                cnt += 1

print(cnt)


Measured memory_bytes: 73908
#include<bits/stdc++.h>
using namespace std;
#include<math.h>
#define ll long long
#define ld long double
#define all(a) (a.begin(),a.end())
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1 ;
  //cin>>t ;
  while(t--)
  {
    ll k;
    cin>>k;
    string s ;
    cin>>s ;
    ll n = s.length() + k ;
    vector<ll> a(s.length()) ;
    a[0] = 1 ;
    for( ll i = 1 ; i<(s.length()) ; i++ )
    {
       a[i] = ((a[i-1])*((n-i+1)*(modexp(i,inf-2))%inf))%inf ;

    }
    for( ll i = 0 ; i<(s.length()) ; i++ )
    {
        a[i] = ((a[i])*(modexp(25ll,n-i)))%inf;
    }

    ll sum = 0 ;
    for( ll i = 0 ; i<s.length() ; i++ )
    {
        sum = (sum%inf + a[i]%inf)%inf;
    }
    ll tot = (modexp(26ll,n));
    cout<<((tot-sum)%inf+inf)%inf ;
   }
  return 0;

}


Measured memory_bytes: 12156
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  vector<string> s(3);
  rep(i, 3) cin >> s[i];
  rep(i, 3) cout << s[i][0];
  cout << endl;
}

Measured memory_bytes: 3636
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string a,b,c;
    cin >> a >> b >> c;
    cout << 'A' << b[0] << 'C' <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1E9 + 7;

long long dp[100001][13];

int main(){
    string S;
    cin >> S;
    dp[0][0] = 1;

    rep(i, S.size()){
        rep(j, 10){
            int D = S[i] - '0';
            if(S[i] == '?' || D == j){
                rep(k, 13){
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
                    dp[i + 1][(k * 10 + j) % 13] %= MOD;
                }
            }
        }
    }
    cout << dp[S.size()][5] << endl;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
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; }
const ll INF = 1e11;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    ll n,k;
    ll a[100005];
    ll dp[41][2] = {0};
    cin >> n >> k;
    rep(i,n){
        cin >> a[i];
    }
    ll c;
    ll ans = 0;
    ll l = 0,m = 0;
    bool on = true;
    for(ll i = 39;i >= 0;i--){
        c = 0;
        rep(j,n){
            if (a[j] & (1ll<<i)) c++;
        }
        if (on && (k & (1ll<<i))){
            dp[i][0] = l+(1ll<<i)*c;
            dp[i][1] = l+(1ll<<i)*(n-c);
            on = false;
        }
        else if (!on){
            dp[i][0] = dp[i+1][0]+(1ll<<i)*(max(c,n-c));
            if (k & (1ll<<i)){
                chmax(dp[i][0],dp[i+1][1]+(1ll<<i)*c);
                dp[i][1] = dp[i+1][1]+(1ll<<i)*(n-c);
            }
            else{
                dp[i][1] = dp[i+1][1]+(1ll<<i)*c;
            }
        }
        else{
            l += (1ll<<i)*c;
        }
    }
    PRINT(max({dp[0][0],dp[0][1],l}));
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<string> sv(n);
	for (auto& s : sv) {
		cin >> s;
	}

	int m;
	cin >> m;
	vector<string> tv(m);
	for (auto& t : tv) {
		cin >> t;
	}

	int max = 0;
	for (auto& s : sv) {
		int money = 0;

		for (auto& s2 : sv) {
			if (s == s2) {
				++money;
			}
		}

		for (auto& t : tv) {
			if (s == t) {
				--money;
			}
		}

		if (max < money) {
			max = money;
		}

	}
	
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

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

std::vector<bool> visited;  // visited.assign(n, false);
std::vector<bool> finished; // finished.assign(n, false);
std::stack<int> history;

int dfs(const Graph &g, const int v) {
  visited[v] = true;
  history.push(v);
  for (auto w : g[v]) {
    if (finished[w])
      continue;

    if (visited[w])
      return w;

    const int res = dfs(g, w);
    if (res != -1)
      return res;
  }
  history.pop();
  finished[v] = true;
  return -1;
}

std::vector<int> detect_cycle(const Graph &g) {
  for (int s = 0; s < (int)g.size(); ++s) {
    if (visited[s])
      continue;

    const int res = dfs(g, s);
    if (res != -1) {
      std::vector<int> cycle;
      while (not history.empty()) {
        int v = history.top();
        history.pop();
        cycle.push_back(v);
        if (v == res)
          break;
      }
      std::reverse(cycle.begin(), cycle.end());
      return cycle;
    }
  }
  return std::vector<int>();
}

int main() {
  int n, m;
  std::cin >> n >> m;

  Graph g(n);
  for (int i = 0; i < m; ++i) {
    int s, t;
    std::cin >> s >> t;
    g[s].push_back(t);
  }

  visited.assign(n, false);
  finished.assign(n, false);

  auto res = detect_cycle(g);

  if (res.size() >= 1)
    std::cout << 1 << std::endl;
  else
    std::cout << 0 << std::endl;

  return 0;
}



Measured memory_bytes: 3152
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main() {
	int64_t n, m; cin >> n >> m;
	vector<pair<int64_t, int64_t>> E(n);

	rep(i, n) {
		cin >> E[i].first >> E[i].second;
	}

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

	int64_t sum = 0;
	int64_t i = 0;

	while (m > 0) {
		if (E[i].second <= m) {
			m -= E[i].second;
			sum += E[i].first * E[i].second;
			i++;
		}
		else {
			sum += E[i].first * m;
			m = 0;
		}
	}

	cout << sum << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int n, i, j, flag, sum;
    while( scanf("%d", &n) != EOF)
    {
        flag = 1;
         for(i = 1; i <= 25; i++)
    {
        if(i*4 == n)
        {
            printf("Yes\n");
            flag = 0;
            break;
        }
        else if(i*7 == n)
        {
            printf("Yes\n");
            flag = 0;
            break;
        }
        else
        {
            for(j = 1; j <= 25; j++)
            {
                sum = 4*i + 7*j;
                if(sum == n )
                {
                    printf("Yes\n");
                    flag = 0;
                    break;
                }
            }
        }
        if(flag == 0)break;

    }
    if(flag == 1)
    {
        printf("No\n");
    }
    }


}


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

int main(){
  string a,b,c;
  cin >>a>>b>>c;
  if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)) cout << "YES"<<endl;
  else cout << "NO" <<endl;
}
 

Measured memory_bytes: 256
// C - Pyramid
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define manhattan(x1,y1,x2,y2) (abs((x1)-(x2))+abs((y1)-(y2)))
#define XMAX 100
#define YMAX 100

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

	VI X(N),Y(N),H(N);
	int IH = 0;
	rp(i, N){
		cin>>X[i]>>Y[i]>>H[i];
		if(H[i] > 0) IH = i;
	}

	rp(y0, YMAX+1){
		rp(x0, XMAX+1){

			int h0 = H[IH] + manhattan(x0,y0, X[IH],Y[IH]);

			int x,y,h;
			bool exist = true;
			rp(i, N){
				x = X[i], y = Y[i], h = H[i];
				if(h <= 0) continue;
				if(h0 != h + manhattan(x0,y0, x,y)){
					exist = false;
					break;
				}
			}
			if(!exist) continue;

			rp(i, N){
				x = X[i], y = Y[i], h = H[i];
				if(h > 0) continue;
				if(h0 - manhattan(x0,y0, x,y) > 0){
					exist = false;
					break;
				}
			}
			if(exist){
				cout<<x0<<" "<<y0<<" "<<h0<<"\n";
				return 0;
			}

		}
	}

}

Measured memory_bytes: 256