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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,m,t,x1,yy1,x2,y2,dist[1000010],vis[1000010][4],dx[]={1,-1,0,0},dy[]={0,0,1,-1};
string s[1000010];
queue <pii> q;

bool out(int x,int y)
{
	return x<0||x>=n||y<0||y>=m;
}

int main()
{
	cin>>n>>m>>t>>x1>>yy1>>x2>>y2;
	x1--;
	yy1--;
	x2--;
	y2--;
	rep(i,n) cin>>s[i];
	rep(i,1000010) dist[i]=1e18;
	dist[x1*m+yy1]=0;
	rep(i,4)
	{
		q.push(mpr(x1*m+yy1,i));
		//vis[x1*m+yy1][i]=1;
	}
	while(!q.empty())
	{
		pii p=q.front();
		q.pop();
		if(vis[p.fi][p.se]==1) continue;
		vis[p.fi][p.se]=1;
		int y=p.fi%m,x=p.fi/m;
		rep(i,t)
		{
			x+=dx[p.se];
			y+=dy[p.se];
			if(out(x,y)||s[x][y]=='@'||vis[x*m+y][p.se]==1||dist[x*m+y]<dist[p.fi]+1) break;
			dist[x*m+y]=dist[p.fi]+1;
			//cout<<x<<' '<<y<<' '<<dist[x*m+y]<<endl;
			rep(j,4)
			{
				if(vis[x*m+y][j]==1) continue;
				q.push(mpr(x*m+y,j));
			}
		}
	}
	if(dist[x2*m+y2]==1e18) puts("-1");
	else cout<<dist[x2*m+y2]<<endl;/*
	rep(i,n)
	{
		rep(j,m) cout<<dist[i*m+j]<<'\t';cout<<endl;
	}*/
	return 0;
}

Measured memory_bytes: 76500
package main

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

var N, M int
var visited = map[int]bool{}
var nodes []node

var sc = bufio.NewScanner(os.Stdin)

const bufferSize = 1000000

func init() {
	sc.Buffer(make([]byte, 0), bufferSize)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	N = nextInt()
	M = nextInt()
	nodes = make([]node, N+1)
	for i := 0; i < M; i++ {
		a := nextInt()
		b := nextInt()
		nodes[a].next = append(nodes[a].next, b)
		nodes[b].next = append(nodes[b].next, a)
	}
	// 1から順に幅優先探索
	visited[1] = true
	q := make([]int, 100000)
	q[0] = 1
	round(0, q)
	fmt.Println("Yes")
	for i, v := range nodes {
		if i <= 1 {
			continue
		}
		fmt.Println(v.mark)
	}
}

func round(cur int, q []int) {
	if cur == len(q) {
		return
	}
	nid := q[cur]

	for _, next := range nodes[nid].next {
		if visited[next] {
			continue
		}
		nodes[next].mark = nid
		q = append(q, next)
		visited[next] = true
	}
	round(cur+1, q)
}

type node struct {
	next []int
	mark int
}


Measured memory_bytes: 80852
n,d = map(int,input().split())

x = [ [] for x in range(n) ]

count = 0

for i in range(n):
  x[i] = list(map(int,input().split()))

for i in range(n):
  for j in range(n)[i+1:]:
    s = 0
    for k in range(d):
      s += (x[i][k] - x[j][k])**2
    r=int(s**0.5)
    if s == r**2 :
      count += 1
print(count)

Measured memory_bytes: 3064
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
int main()
{
fast;
ll n;
cin>>n;
vector<ll>v;
priority_queue<double,vector<double> ,greater<double> >pq;
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    pq.push(a);
}
double ans=0.0;
while(pq.size()!=1)
{
    double x=pq.top();
    pq.pop();
    double y=pq.top();
    pq.pop();
    ans=(x+y)/2.0;
    pq.push(ans);
}
cout<<pq.top()<<endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int m[210],x,y,ans;
int main(){
	m[1]=300000;
	m[2]=200000;
	m[3]=100000;
	scanf("%d%d",&x,&y);
	if(x==1&&y==1)
	   ans=m[x]+m[y]+400000;
	else
	    ans=m[x]+m[y];
	printf("%d\n",ans);



	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
#include <cctype>
#include <set>
#include "iostream"
using namespace std;
const int INF = 2147483640;
typedef unsigned long long ll;
const int MAXN = 600500;
const int MOD = 998244353;
struct edge
{
	int t,w;
};
std::vector<edge> e[MAXN];
int in[MAXN];
bool vis[MAXN];
void init()
{
	memset(in,0,sizeof in);
	memset(vis,0,sizeof vis);
	for (int i = 0; i < MAXN; ++i)
	{
		e[i].clear();
	}
}
int n,s;
ll top()
{
	ll ans=1;
	queue<int> que;
	for(int i=n+1;i<=2*n;++i) if(in[i]==1) que.push(i),vis[i]=1;
	while(!que.empty())
	{
		int cur=que.front(); que.pop();
		int si=e[cur].size();
		for(int i=0;i<si;++i)
		{
			int v=e[cur][i].t,w=e[cur][i].w;
			if(vis[v]) continue;
			in[v]--;
			if(in[v]==1)
				que.push(v),vis[v]=1;
			if(cur>n) ans=(ans*1LL*w)%MOD;
		}
	}
	return ans;
}
ll ans[2];
void dfs(int u,int ty,int fa)
{
	vis[u]=1;
	int si=e[u].size();
	for(int i=0;i<si;++i)
	{
		int v=e[u][i].t,w=e[u][i].w;
		if(v==s && v!=fa) ans[ty]=(ans[ty]*1LL*w)%MOD;
		if(vis[v]) continue;
		ans[ty]=(ans[ty]*1LL*w)%MOD;
		dfs(v,ty^1,u);
	}
}
int main()
{

	int n;
	while(cin>>n)
	{
		if(n%10==n/100)
			printf("Yes\n");
		else printf("No\n");
	}
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<char, ll> mp;
    rep(i, n) {
        string s;
        cin >> s;
        ++mp[s[0]];
    }
    ll ans = 0;
    ans += mp['M'] * mp['A'] * mp['R'];
    ans += mp['M'] * mp['A'] * mp['C'];
    ans += mp['M'] * mp['A'] * mp['H'];
    ans += mp['M'] * mp['R'] * mp['C'];
    ans += mp['M'] * mp['R'] * mp['H'];
    ans += mp['M'] * mp['C'] * mp['H'];
    ans += mp['A'] * mp['R'] * mp['C'];
    ans += mp['A'] * mp['R'] * mp['H'];
    ans += mp['A'] * mp['C'] * mp['H'];
    ans += mp['R'] * mp['C'] * mp['H'];
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
#define debug(x) cout << #x << "=" << x << endl;
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); cout << (i>0 ? " ":"") << v[i++]); cout << "\n"; return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,n;
    cin >> a >> b >> n;
    ll x;
    x = min(n,b-1);
    ll ans = (a*x)/b - a*(x/b);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>

ll N, A;

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

    if(N % 500 <= A)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
vector<int> vec;
vector<int> ans;
bool isPrime(int x){
    if(x <= 6) return false;
    for(int i=0; i*i<vec.size(); i++){
        if(x % vec[i] == 0) return false;
    }
    return true;
}
int main(){
    int n;
    vec.push_back(6);
    for(int i=7; i<=300000; i+=7){
        if(isPrime(i-1)) vec.push_back(i-1);
        if(isPrime(i+1)) vec.push_back(i+1);
    }
    while(cin >> n){
        if(n == 1) break;
        //if(isPrime(n)) vec.push_back(n);
        sort(vec.begin(),vec.end());
        rep(i,vec.size()){
            if(vec[i] > n) break;
            if(n % vec[i] == 0) ans.push_back(vec[i]);
        }
        //sort(ans.begin(),ans.end());
        //ans.erase(unique(ans.begin(),ans.end()),ans.end());
        cout << n << ':';
        rep(i,ans.size()){
            cout << " " << ans[i]; 
        }
        cout << endl;
        ans.resize(0);
    }
    return 0;
}


Measured memory_bytes: 3164
#include <cstdio>
#include <cstring>

int main(){
    int n;
    scanf("%d",&n);
    char s[n][11];
    for(int i = 0; i < n; i++){
        scanf("%s",s[i]);
    }
    int m;
    scanf("%d",&m);
    char t[m][11];
    for(int i = 0; i < m; i++){
        scanf("%s",t[i]);
    }

    char a[11];
    int count;
    int max = 0;
    for(int i = 0; i < n; i++){
        strcpy(a,s[i]);
        count = 0;
        for(int j = 0; j < n; j++){
            if(strcmp(a,s[j]) == 0){
                count++;
            }
        }
        for(int j = 0; j < m; j++){
            if(strcmp(a,t[j]) == 0){
                count--;
            }
        }
        if(count > max){
            max = count;
        }
    }

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

    return 0;
}

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

int n;
vector<int> a;

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    if (i % 2 == 0 && a[i] % 2 == 1) ++cnt;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int n, m;
  cin >> n >>m;
  vecint a(m,0), b(m,0);
  REP(i,m)cin >> a[i] >> b[i];
  vecint ans(n,0);
  REP(i,m){
    ans[a[i] - 1]++;
    ans[b[i] - 1]++;
  }
  REP(i,n){
    cout << ans[i] << endl;
  }
} 


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 100000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
typedef string::const_iterator State;
int expression(State& begin);
int term(State& begin);
int number(State& begin);
int factor(State& begin);
int factor(State& begin) {
	if (*begin == '(') {
		begin++;
		int ret = expression(begin);
		begin++;
	}
	else {
		return number(begin);
	}
}
int expression(State& begin) {
	int ret = term(begin);
	for (;;) {
		if (*begin == '+') {
			begin++;
			ret += term(begin);
		}
		else if (*begin == '-') {
			begin++;
			ret -= term(begin);
		}
		else break;
	}
	return ret;
}
int term(State& begin) {
	int ret = factor(begin);
	for (;;) {
		if (*begin == '*') {
			begin++;
			ret *= factor(begin);
		}
		else if (*begin == '/') {
			begin++;
			ret /= factor(begin);
		}
		else {
			break;
		}
	}
	return ret;
}
int number(State& begin) {
	int ret = 0;
	while (isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	return ret;
}
int main() {
	long long n;
	cin >> n;
	REP(imt, n) {
		string s;
		cin >> s;
		State begin = s.begin();
		cout << expression(begin) << endl;
	}
	return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll inf2 = 1000000000000000000;
const ll mod = 1000000007;


int main() {
   int n;
   cin >> n;
   vector<ll>a(n);
   vector<ll>b(n);
   rep(i, 0, n){
       cin >> a[n-1-i] >> b[n-1-i];
   }
   ll ans = 0;
   rep(i, 0, n){
       if((a[i]+ans)%b[i]==0)continue;
       ans += (b[i]-(a[i]+ans)%b[i]);
       //cout << ans << endl;
   }
   cout << ans << endl;
}

Measured memory_bytes: 1792
import math

arr = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる

if arr[1] < 10:
    num = arr[0]*10 + arr[1]
elif arr[1] < 100:
    num = arr[0]*100 + arr[1]
else:
    num = arr[0]*1000 + arr[1]

num_h = int(math.sqrt(num))

if num == num_h*num_h:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
mod = 10**9+7

lower = [0]*n
tento = [0]*n
for i in range(n):
    t = a[i]
    for j in range(n):
        if t > a[j]:
            lower[i] += 1
            if j > i:
                tento[i] += 1
for i in range(n):
    ans += k*tento[i] % mod
    ans += (k-1)*k*lower[i]//2 % mod
print(ans%mod)


Measured memory_bytes: 9220
n,m,l=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for i in range(m)]

M=[]
for i in range(n):
    line=[]
    for j in range(l):
        sum=0
        for k in range(m):
            sum+=A[i][k]*B[k][j]
        line.append(sum)
    M.append(line)
for a in range(n):
    print(*M[a])
    
    
        
            
            


Measured memory_bytes: 7056
def f(n):
    str_n = str(n)
    tmp = 0
    for i in range(len(str_n)):
        tmp += int(str_n[i])
    if tmp%9==0:
        return True
    else:
        return False
        
n = int(input())
if f(n):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9364
#include <stdio.h>

int doubleup(int num,int goal);

int main()
{
	int n,m,i;
	int l,r,maxl=0,minr=200000;
	//int l[100010],r[100010];
	int ans;
	scanf("%d %d",&n,&m);
	
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&l,&r);
		if(maxl<l)maxl=l;
		if(minr>r)minr=r;
	}
	
	if((ans=minr-maxl)>=0)printf("%d",ans+1);
	else printf("0");
	return 0;
}


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

// Definitions
#define MAXN
#define elif else if
typedef long long int64;
typedef long double num128;
typedef unsigned long long uint64;

// Variables
int64 n, d;
int64 ans;

// Improve the speed of read-in.
inline bool IsNum(char x) { return ('0' <= x) && (x <= '9'); }
inline int64 ReadNum() {
  int64 sign = 1, val = 0; char tmp = getchar();
  while (!IsNum(tmp)) { if (tmp == '-') {sign = -sign;} tmp = getchar(); }
  while (IsNum(tmp)) { val = val * 10 + tmp - 48; tmp = getchar(); }
  return val * sign;
}

// Functions
inline void ReadIn() {
  n = ReadNum();
  d = ReadNum();
  d *= d;
  int64 x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &x, &y);
    ans += ((x * x + y * y) <= d);
  }
}
inline void PrintAns() {
  printf("%lld\n", ans);
}

int main() {
  ReadIn();
  PrintAns();
  return 0;
}
/*

*/


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define int long long

struct Droite
{
	int origine , pente;
};

deque<Droite> droites;

void enlever(int x)
{
	while (droites.size() > 1 && droites[0].origine + x * droites[0].pente >= droites[1].origine + x * droites[1].pente)
	{
		droites.pop_front();
	}
}

void ajouter(Droite nouvelle)
{
	while (droites.size() > 1 && (droites[droites.size() - 2].origine - droites[droites.size() - 1].origine) * (nouvelle.pente - droites[droites.size() - 2].pente) >= (droites[droites.size() - 2].origine - nouvelle.origine) * (droites[droites.size() - 1].pente - droites[droites.size() - 2].pente))
	{
		/*int inter1 = (droites[droites.size() - 2].origine - droites[droites.size() - 1].origine) / (droites[droites.size() - 1].pente - droites[droites.size() - 2].pente);
		int inter2 = (droites[droites.size() - 2].origine - nouvelle.origine) / (nouvelle.pente - droites[droites.size() - 2].pente);
		if (inter2 >= inter1)
		{
			break;
		}*/
		droites.pop_back();
	}
	droites.push_back(nouvelle);
}
int32_t main()
{
	int N , C;
	cin >> N >> C;
	int hauteur[N];
	for (int i = 0 ; i < N ; i++)
	{
		cin >> hauteur[i];
	}
	droites.push_back({C + hauteur[0] * hauteur[0], -2*hauteur[0]});
	int dp[N];
	for (int i = 1 ; i < N ; i++)
	{
		enlever(hauteur[i]);
		dp[i] = droites[0].origine + droites[0].pente * hauteur[i] + hauteur[i] * hauteur[i];
		Droite nouvelle;
		nouvelle.origine = dp[i] + C + hauteur[i] * hauteur[i];
		nouvelle.pente = -2 * hauteur[i];
		ajouter(nouvelle);
	}
	cout<<dp[N - 1]<<endl;
}	

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


int main(){
    for(int j=0; j<105; j++){
        int s1, s2;
        cin >> s1 >> s2;
        if(s1 == 0 && s2 == 0){
            break;
        }
        int ans = s1+s2;
        char mozi;
        mozi = 65;
        for(int i=1; i<5; i++){
            int a, b;
            cin >> a >> b;
        int temp;
        temp = a+b;
        if(ans <= temp){
            ans = temp;
            mozi = 65+i;
        }
        }
        cout << mozi << " " << ans << endl;
    }
    return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	if(a!=1&&b!=1) cout << 1;
	if(a!=2&&b!=2) cout << 2;
	if(a!=3&&b!=3) cout << 3;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef string ST;
 
 
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 

 
LL modpow(LL a, LL n, LL mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

LL modinv(LL a, LL m) {
  LL b = m, u = 1, v = 0;
  while (b) {
    LL t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0){
     u += m;
  }
  return u;
}

bool isPrime(LL N)
{
  if (N < 2) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else if (N % 2 == 0) {
    return false;
  }

  LD sqrtNum = sqrt(N);
  for (LL i = 3; i <= sqrtNum; i += 2)
  {
    if (N % i == 0)
    {
      return false;
    }
  }
  return true;
}



void func() {
  string S1;
  string S2;
  cin >>S1;
  cin >>S2;
  LL N1 = S1.length();
  LL N2 = S2.length();
  //printf("N1=%lld,N2=%lld\n",N1,N2);
      
  vector<vector<LL>> dp(N1+1,vector<LL>(N2+1,0));  
  REP(i1 , N1){
    //PRINTSP(dp[i1]);
    REP(i2 , N2){
      //printf("i1=%lld,i2=%lld\n",i1,i2);
      if(S1[i1]==S2[i2]){
        dp[i1+1][i2+1] = dp[i1][i2]+1;
      }
      cmax(dp[i1+1][i2+1],dp[i1+1][i2  ]);
      cmax(dp[i1+1][i2+1],dp[i1  ][i2+1]);
    }
  }
  REP(i1 , N1+1){
    //PRINTSP(dp[i1]);
  }

  LL num = 0;
  string s="";
  LL i1 = S1.length();
  LL i2 = S2.length();
  while(i1>0 && i2>0){
    if(dp[i1][i2]== dp[i1][i2-1]){
      i2--;
    }
    else if(dp[i1][i2]== dp[i1-1][i2]){
      i1--;
    }
    else {
      s = S1[i1-1]+s;
      i1--;
      i2--;
    }
  }
 

  //cerr << s.length();
  cout <<s;

  return;
}



int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[101][100001];
ll knapsack(ll wt[], ll val[], ll n, ll W){
	//base condition
	if(n==0 || W==0) return 0;
	//choice diagram
	if(dp[n][W]!=-1) return dp[n][W];
	if(wt[n-1]<=W)
		dp[n][W] = max((ll)val[n-1]+knapsack(wt,val,n-1,W-wt[n-1]), knapsack(wt,val,n-1,W));
	else 
		dp[n][W] = knapsack(wt,val,n-1,W);
	return dp[n][W];
	
}

int main(){
	memset(dp,-1,sizeof(dp));
	ll n, W; cin>>n>>W;
	ll wt[n];
	ll val[n];
	for(ll i=0;i<n;i++) cin>>wt[i]>>val[i];
	ll ans = knapsack(wt,val,n,W);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 79104
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int64;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())

const int inf = (int) 1e9;
const int N = 301;
char s[N];
int n, k, ans[N][N][N];

int main() {
	scanf("%s%d", s, &k), n = strlen(s);
	for (int l = n - 1; l >= 0; --l) {
		for (int r = l; r < n; ++r) {
			for (int t = 0; t <= k; ++t) {
				ans[l][r][t] = -inf;
				if (l == r) {
					ans[l][r][t] = 1;
				} else if (s[l] == s[r]) {
					ans[l][r][t] = 2 + ans[l + 1][r - 1][t];
				} else {
					ans[l][r][t] = max(ans[l + 1][r][t], ans[l][r - 1][t]);
					if (t > 0) {
						ans[l][r][t] = max(ans[l][r][t], ans[l + 1][r - 1][t - 1] + 2);
					}
				}
			}
		}
	}
	printf("%d\n", ans[0][n - 1][k]);
	return 0;
}

Measured memory_bytes: 106624
// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
#include <bits/stdc++.h>
using namespace std;
// ¯\_(ツ)_/¯
#define f first
#define s second
#define p push
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005
#define MOD 1000000007LL
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18
// ¯\_(ツ)_/¯
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vll vector<long long>
#define vvll vector<vll>
//vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;



int main()
{
    fast_io();
#ifndef ONLINE_JUDGE
    //freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
#endif

    cin>>n>>m;
    vvll arr(n, vll(m, 0));
    rep(i, 0, n) {
        string str;
        cin>>str;
        rep(j, 0, m) {
            if(str[j] == '.') arr[i][j] = 1;
            else arr[i][j] = 0;
        }
    }
    vvll dp(n, vll(m, 0));
    dp[0][0] = 1;
    rep(i, 0, n)
    rep(j, 0, m) {
        if(arr[i][j]) {
            if(i-1 >= 0) {
                dp[i][j] += dp[i-1][j];
                dp[i][j] %= INFI + 7;
            }

            if(j-1 >= 0) {
                dp[i][j] += dp[i][j-1];
                dp[i][j] %= INFI + 7;
            }
        }
    }

    cout<<dp[n-1][m-1];

    return 0;
}

/*
2
4
0 1 0 1
5
0 0 1 0 0
*/

Measured memory_bytes: 16000
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0

a,b = map(int,input().split())
s = input()
for x in range(len(s)):
    if s[x] == '-':
        neko = x
        nya+=1
if nya != 1:
    pn()
elif (a == neko)and(b == len(s)-1-neko):
    py()
else:
    pn()

Measured memory_bytes: 9192
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = list(np.array(A) - 1)
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum_ = 0
diff = list(np.array(A[1:]) - np.array(A[:-1]))
diff.insert(0, -1)
for i in range(N):
  sum_ += B[A[i]]
  
  if diff[i] == 1:
    sum_ += C[A[i-1]]
  
print(sum_)

Measured memory_bytes: 21428
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1e+9;

int main(){
	int n,m,dist[21][21];
	
	for(int i=0 ; i < 21 ; i++ )
		for(int j=0 ; j < 21 ; j++ )
			dist[i][j] = INF;

	scanf("%d %d", &n, &m);
	for(int i=0 ; i < m ; i++ ){
		int a,b,c,d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		dist[a][b] = c;
		dist[b][a] = d;
	}
	for(int k=1 ; k <= n ; k++ ){
		for(int i=1 ; i <= n ; i++ ){
			for(int j=1 ; j <= n ; j++ ){
				dist[i][j] = min( dist[i][j] , dist[i][k]+dist[k][j] );
			}
		}
	}
	int x1,x2,y1,y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
	int ans = y1 - (y2 + dist[x1][x2] + dist[x2][x1]);
	printf("%d\n", ans );
}

Measured memory_bytes: 2644
<?php

    list($h, $w) = in_ints();

    $odd_line = (int)ceil($w / 2);
    $even_line = (int)floor($w / 2);

    $odd_line_cnt = (int)ceil($h / 2);
    $even_line_cnt = (int)floor($h / 2);

    $cnt = 1;
    if ($h > 1 && $w > 1) {
        $cnt = ($odd_line * $odd_line_cnt) + ($even_line * $even_line_cnt);
    }

    out($cnt);
    
    /**
    * お手伝い関数さんたち
    */
    function in() {
        return trim(fgets(STDIN));
    }
    function in_int() {
        return (int)in();
    }
    function in_vals() {
        return explode(' ', in());
    }
    function in_ints() {
        return array_map('intval', in_vals());
    }
    function out($s) {
        echo $s . PHP_EOL;
    }
    function yes() {
        out('Yes');
    }
    function no() {
        out('No');
    }



Measured memory_bytes: 4856
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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


i64 x,y;

//コンビネーション
//けんちょんさんありがとう
const int MAX = 1010101, MOD = INF;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long C(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
////

int main(){
	cin >> x >> y;
	
	if((x+y) % 3){
		cout << 0 << endl;
		return 0;
	}
	COMinit();
	cout << C((x+y)/3, (2*y-x)/3) << endl;
	
	return 0;
}

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

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

  int cnt = 0;
  rep(i,3){
    if(s[i]=='1') {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vd p(2*n);
    rep(i,2*n){
        cin >> p[i];
    }
    sort(all(p),greater<ll>());
    double ans = 0;
    srep(i,1,2*n+1){
        ans += p[i-1]*(2*n-i)/(2*n-1);
    }
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=100010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int fa[maxn];
int n,m;
ll num[maxn];
void init()
{
	repd(i,0,n)
	{
		fa[i]=i;
		num[i]=1;
	}
}
struct node
{
	int f;
	int t;
}b[maxn];
ll cnt[maxn];
int findpar(int x)
{
	if(x==fa[x])
	{
		return x;
	}else
	{
		fa[x]=findpar(fa[x]);
		return fa[x];
	}
}
void Merg(int x,int y)
{
	x=findpar(x);
	y=findpar(y);
	if(x!=y)
	{
		fa[x]=y;
		num[y]+=num[x];
	}
}
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n>>m;
	init();
	repd(i,1,m)
	{
		cin>>b[i].f>>b[i].t;
	}
	ll v;
	for(int i=m;i>=1;i--)
	{
        b[i].t=findpar(b[i].t);
        b[i].f=findpar(b[i].f);
		if(b[i].t!=(b[i].f))
		{
		    v=num[b[i].t]*num[b[i].f];
		    Merg(b[i].t,b[i].f);
			cnt[i]=v;
		}
	}
	ll ans=0;
	repd(i,1,m)
	{
		ans+=cnt[i];
		cout<<ans<<endl;
	}
    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    priority_queue<ll> que;
    rep(i,n){
        ll a; cin>>a;
        que.push(a);
    }
    rep(i,m){
        ll x = que.top(); que.pop();
        que.push(x/2);
    }
    ll ans=0;
    rep(i,n){
        ans += que.top(); que.pop();
    }
    cout<<ans<<"\n";
    return 0;
}


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

int main() {
	int a, b,c;
	cin >> a >> b;
	if (b == 100) b++; 
		if (a == 0) c = b;
		if (a == 1) c = 100 * b;
		if (a == 2) c = 10000 * b;
		cout << c << endl;
	
	return 0;
}

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

using namespace std;

int main(){
	
	int a,b,c,d;
	
	cin >> a >> b >> c >> d;
	
	if( std::abs(a-c) <= d) cout << "Yes" << endl;
	
	else if( std::abs(a-b) <= d && std::abs(c-b) <= d) cout << "Yes" << endl;
	
	else cout << "No" << endl;
}


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

int main()
{
	int x;
	cin >>x;
	if (x>=30) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  vector< pair<double,int> > v1(8),v2(8),v3(8);

  rep(i,8)cin>>v1[i].second>>v1[i].first;
  rep(i,8)cin>>v2[i].second>>v2[i].first;
  rep(i,8)cin>>v3[i].second>>v3[i].first;

  sort(all(v1));
  sort(all(v2));
  sort(all(v3));

  cout<<shosu(2)<<v1[0].second<<" "<<v1[0].first<<endl;
  cout<<shosu(2)<<v1[1].second<<" "<<v1[1].first<<endl;
  cout<<shosu(2)<<v2[0].second<<" "<<v2[0].first<<endl;
  cout<<shosu(2)<<v2[1].second<<" "<<v2[1].first<<endl;
  cout<<shosu(2)<<v3[0].second<<" "<<v3[0].first<<endl;
  cout<<shosu(2)<<v3[1].second<<" "<<v3[1].first<<endl;

  vector< pair<double,int> > p(18);
  rep(i,6)p[i]=v1[i+2];
  rep(i,6)p[6+i]=v2[i+2];
  rep(i,6)p[12+i]=v3[i+2];
  sort(all(p));

  cout<<shosu(2)<<p[0].second<<" "<<p[0].first<<endl;
  cout<<shosu(2)<<p[1].second<<" "<<p[1].first<<endl;

}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(int argc, char const *argv[])
{
	string s; cin >> s;
	int year = stoi(s.substr(0, 4));
	int month = stoi(s.substr(5, 2));
	int day = stoi(s.substr(8, 2));
	if (year < 2019 || (year == 2019 && month < 4) ||
		(year == 2019 && month == 4 && day <= 30)) printf("Heisei\n");
	else printf("TBD\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())

dp = [[[[0 for _ in range(5)] for _ in range(5)] for _ in range(5)] for _ in range(N+1)]

dp[0][0][0][0] = 1

# Aを1、Gを2、Cを3、Tを4とする
# j は３つ前、kは２つ前、lは１つ前の情報
for i in range(N):
    for j in range(5):
        for k in range(5):
            for l in range(5):
                # tは今の情報
                for t in range(1, 5):
                    if k == 1 and l == 2 and t == 3:
                        continue
                    if k == 2 and l == 1 and t == 3:
                        continue
                    if k == 1 and l == 3 and t == 2:
                        continue
                    if j == 1 and l == 2 and t == 3:
                        continue
                    if j == 1 and k == 2 and t == 3:
                        continue
                    dp[i+1][t][l][k] += dp[i][l][k][j]

sums = 0
for j in range(1, 5):
    for k in range(1, 5):
        for l in range(1, 5):
            sums += dp[N][l][k][j]

print(sums % (10**9 + 7))


Measured memory_bytes: 3700
var
	now,L,R,N,i,ans,T,j:Longint;
	w:array[1..100]of Longint;
begin
	read(N);
	for i:=1 to N do read(w[i]);
	ans:=1000000000;
	L:=0;
	R:=0;
	for i:=1 to N do inc(R,w[i]);
	for i:=1 to N-1 do begin
		inc(L,w[i]);
		dec(R,w[i]);
		now:=R-L;
		if now<0 then now:=-now;
		if ans>now then ans:=now;
	end;
	writeln(ans);
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int INFTY = 2000000000;

long long cnt = 0;

void merge(vector<int> &A, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int> L(n1+1), R(n2+1);
  for (int i = 0; i <= n1; i++) {
    L[i] = A[left + i];
  }
  for (int j = 0; j <= n2; j++) {
    R[j] = A[mid + j];
  }
  L[n1] = R[n2] = INFTY;
  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    }
    else {
      A[k] = R[j];
      j++;
    }
  }
}

void mergeSort(vector<int> &A, int left, int right) {
  if (right - left > 1) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  mergeSort(A, 0, n);
  
  for (int i = 0; i < n; i++) {
    if (i) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;
  cout << cnt << endl;
}


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

int main(void){
  int N;
  cin>>N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  set<string> dict;
  for(int i=0;i<N;i++){
    dict.insert(S[i]);
  }
  cout<<dict.size()<<endl;
  return 0;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
    int n,m;
    while (cin >> n >> m) {
        VI ac(n+1), wa(n+1);
        FOR(_,0,m) {
            int i; string s; cin >> i >> s;
            if (s == "AC")
                ac[i] = 1;
            else if (!ac[i])
                wa[i]++;
        }
        int x = 0, y = 0;
        FOR(i,1,n+1) if (ac[i])
            x++, y += wa[i];
        cout << x << " " << y << endl;        
    }
    return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

vector<pair<int, int> > g[200000];

pair<int, int> tddfs(int v, int par = -1) {
  pair<int, int> ret = {0, v};
  for (auto &x : g[v]) {
    int w, cost;
    tie(w, cost) = x;
    if (w == par)
      continue;
    auto r = tddfs(w, v);
    ret = max(ret,  {cost+r.first, r.second});
  }
  return ret;
}

int treeDiameter() {
  auto v = tddfs(0);
  auto w = tddfs(v.second);
  return w.first;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //1 -> o, 2 -> x, 3 -> o, 4 -> o, 5 -> x, 6 -> o, 7 -> o, 
    int N; cin >> N;
    vector<bool> win(N+1);
    win[1] = true; win[2] = false;
    for(int i = 3; i <= N; i++){
        if(i % 3 == 2) win[i] = false;
        else win[i] = true;
    }

    rep(i, N-1){
        int a, b; cin >> a >> b;
        g[a-1].push_back({b-1,1});
        g[b-1].push_back({a-1,1});
    }
    int ret = treeDiameter();
    //cout << ret << endl;
    if(win[ret+1]) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
class union_find {
private:
	int par[200001], ran[200001];
public:
	void init(int n) {
		rep(i, n + 1) {
			par[i] = i;
			ran[i] = 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 (ran[x] < ran[y])par[x] = y;
		else {
			par[y] = x;
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};
int n, k, l, p, q;
map<pair<int, int>, int>mp;
signed main() {
	cin >> n >> k >> l;
	union_find a, b;
	a.init(n); b.init(n);
	while (k--) {
		cin >> p >> q;
		a.unite(p, q);
	}
	while (l--) {
		cin >> p >> q;
		b.unite(p, q);
	}
	for (int i = 1; i <= n; i++)mp[{a.find(i), b.find(i)}]++;
	for (int i = 1; i < n; i++)cout << mp[{a.find(i), b.find(i)}] << " ";
	cout << mp[{a.find(n), b.find(n)}] << endl;
	return 0;
}



Measured memory_bytes: 15104
macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = get_tuple!(u32, u32);
    let ans = if n == m {"Yes"} else {"No"};
    println!("{}", ans);
}


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

bool _solve() {
    long a, b, c, d; cin >> a >> b >> c >> d;
    if(d < b) return false;
    if(a - b < 0) return false;
    if(c + 1 >= b) return true;
    d %= b;
    if(d == 0) {
        if((a % b) > c) return false;
        return true;
    }
    d %= b,  a %= b;
    long l = c+1, r = b-1;
    if(r - l + 1 >= d) return false;
    if(__gcd(d, b) == 1) return false;
    a %= d, l %= d, r %= d;
    if(l <= r && l <= a) return false;
    if(r > l && (a >= l || a <= r)) return false;
    return true;
}

bool solve() {
    long a, b, c, d; cin >> a >> b >> c >> d;
    long z = max(1ll, (a-c+b-1)/b);
    a -= z *b;
    if(a < 0) return false;
    if(d < b) return false;
    if(b <= c) return true;
    long g = __gcd(b, d);
    long x = (b - a -1) / g;
    a += x * g;
    if(a > c) return false;
    return true;
}

int main() {
    int T; scanf("%d", &T);
    while(T--) puts(solve() ? "Yes" : "No");
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define INF 100000000

int main()
{
	LL N, M;
	cin >> N >> M;
	vector<LL> A(N);
	for (int n = 0; n < N; n++)
		cin >> A[n];

	unordered_map<LL, LL> um;
	um[A[0] % M]++;
	for (int n = 1; n < N; n++)
	{
		A[n] += A[n-1];
		um[A[n] % M]++;	
	}
	LL count = 0;
	for (auto i = um.begin(); i != um.end(); i++)
	{
		LL a = i->first, b = i->second;
		count += (b)*(b-1)/2;
	}
	count += um[0];
	cout << count << endl;
}



Measured memory_bytes: 7304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    string S,T,U;
    ll A,B;
    cin >>S>>T>>A>>B>>U;
    if(S==U){
        A--;
    }else{
        B--;
    }
    
    cout << A<<" " <<B<< endl;


    return 0;
    

}

Measured memory_bytes: 3608
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std;
vector<vector<vector<double>>>dp;
int N; 
double compute(int ct3, int ct2,int ct1){ 
	if(dp[ct3][ct2][ct1]!=-1){ 
		return dp[ct3][ct2][ct1]; 
	}
	int s1=ct1+ct2+ct3;
	int ct0=N-(s1); 
	if(ct0==N){ 
		return 0;
	}
	double val=1./(1.-double(ct0)/N);
	if(ct3>0){ 
		val+=double(ct3)/s1*compute(ct3-1,ct2+1,ct1);
	}
	if(ct2>0){
		val+=double(ct2)/s1*compute(ct3,ct2-1,ct1+1);
	} 
	if(ct1>0){ 
		val+=double(ct1)/s1*compute(ct3,ct2,ct1-1); 
	} 
	dp[ct3][ct2][ct1]=val;
	return val; 

}
	


int main(){ 
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	cin>>N;
	dp.resize(N+1);
	for(int i=0;i<N+1;i++){ 
		dp[i].assign(N+1,vector<double>(N+1,-1)); 
	}
	int ct1=0,ct2=0,ct3=0;
	int a;
	for(int i=0;i<N;i++){ 
		cin>>a;
		switch(a){ 
			case 1:
				ct1++;
				break;
			case 2:
				ct2++;
				break; 
			case 3:
				ct3++; 
		} 
	} 
	cout<<setprecision(15)<<compute(ct3,ct2,ct1); 
				
		




	return 0;
}



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

using namespace std;

const int MaxN = 2e5 + 15;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

int n, a[MaxN];

int main()
{
//    freopen("output.txt", "r", stdin);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

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

    if(a[1])
        return cout << "-1\n", 0;

    int cur = 0;

    long long ans = 0;

    for(int i = n; i; --i)
    {
        --cur;
        if(a[i] < cur)
            return cout << "-1\n", 0;
        if(a[i] == cur)
            continue;
        ans += a[i];
        cur = a[i];
    }

    cout << ans << '\n';

    return 0;
}


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

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

  int max3=fmax(a,fmax(b,c));
  int min3=fmin(a,fmin(b,c));
  int mid3=a+b+c-max3-min3;

  int dmid=max3-mid3;
  int num=dmid;

  if((max3-(min3+dmid)) %2 == 0){
    num=num+((max3-(min3+dmid))/2);
  }
  else{
    num=num+((max3-(min3+dmid))/2)+2;
  }
  printf("%d\n",num);
  return 0;
}


Measured memory_bytes: 128
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
A = [abs(753 - int(x+y+z)) for x, y, z in zip(S[:], S[1:], S[2:])]
answer = min(A)
print(answer)


Measured memory_bytes: 3060