akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

signed main() {
  vector<string> v(3);
  for(int i = 0; i < v.size(); i++) cin >> v.at(i);

  // A=0 / B=1 / C=2
  int now = 0;
  while(true) {
    if(v.at(now) == "") {
      cout << (char)('A' + now) << endl;
      return 0;
    }
    char c = v.at(now).at(0);
    v.at(now).erase(v.at(now).begin());
    now = (int)(c - 'a');
  }
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	static int MOD = 1000000007;
	public static void main(String[] $){
		//入力
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		//処理
		long ans = 1;
		for(int i = 1; i<= n; i++){
			ans *= i;
			ans %= MOD;
		}

		//出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
typedef vector<pair<int, char> > P;

int main() {
    int n,m;
    cin >> n >> m;
    int cnt=1;
    for(int i=0;i<m;i++) cnt *= 2;
    cout << (100*n+1800*m)*cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    if(s=="SSS")
    ans=0;
    else if(s=="RRR")
    ans=3;
    else if(s=="SRR"||s=="RRS")
    ans=2;
    else
    ans=1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        long K = sc.nextLong();

        Map<Integer, Long> map = new HashMap<>();

        for(int i = 0; i < N; i++) {
            int a = sc.nextInt();
            long b = sc.nextLong();
            map.put(a, map.getOrDefault(a, 0L) + b);
        }

        List<Integer> keys = new ArrayList(map.keySet());
        Collections.sort(keys);

        long count = 0;

        int ans = 0;
        for(int key: keys) {
            long newCount = count + map.get(key);
            if(count <= K && K <= newCount) {
                ans = key;
                break;
            }
            count = newCount;
        }

        System.out.println(ans);
    }
}

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

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a==b){
    cout<<"Draw"<<endl;
    return 0;
  }

  if(a==1)a+=13;
  if(b==1)b+=13;
  if(a<b)cout<<"Bob"<<endl;
  else cout<<"Alice"<<endl;
  return 0;
}

Measured memory_bytes: 256
n,a,b = map(int, input().split())

def ruizyou(x,r,mod):
    sisuu=r
    kotae=1
    kake=x
    while sisuu:
        if sisuu&1==True:
            kotae*=kake
        sisuu>>=1
        kake**=2
        kake%=mod
        kotae%=mod
    return kotae

def conbi(n,r,mod):
    ue=1
    for i in range(n-r+1,n+1):
        ue*=i
        ue%=mod

    sita=1

    for i in range(1,r+1):
        sita*=i
        sita%=mod

    sita=ruizyou(sita,mod-2,mod)

    return (ue*sita)%mod

mod=10**9+7

ans=ruizyou(2,n,mod)-conbi(n,a,mod)-conbi(n,b,mod)-1
ans%=mod
print(ans)

Measured memory_bytes: 63608
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); }
vector< vector<ll> > matpow(vector<vector<ll> >&r1,vector< vector<ll> >&r2,int n){
	vector< vector<ll> >ans(n, vector<ll>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				ll res=( r1[i][k]%MOD*r2[k][j]%MOD)%MOD;
				ans[i][j]=(ans[i][j]%MOD+res%MOD)%MOD;
			}
		}
	}
	return ans;
} 
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n,k;
		cin>>n>>k;
		vector< vector< ll > >in(n,vector<ll>(n));
		vector< vector<ll> >res(n, vector<ll>(n));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>in[i][j];
				res[i][j]=(i==j);
				// cout<<res[i][j]<<" ";
			}
			// cout<<endl;
		}
		while(k){
			if(k&1) res=matpow(res,in,n);
			in=matpow(in,in,n);
			k/=2;
		}
		ll res1=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				res1=(res1%MOD+res[i][j]%MOD)%MOD;
				// res1=res1%MOD;
			}
		}
		cout<<res1%MOD<<endl;
	}
}

Measured memory_bytes: 384
N = int(input())
S = input()
ans_lis = []

alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

for i in range(len(S)):
    for j in range(26):
        if S[i] == alphabets[j]:
            t = j
            if t + N <= 25:
                ans_lis.append(alphabets[t + N])
            else:
                ans_lis.append(alphabets[t + N - 26])

ans = ''.join(ans_lis)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
using namespace std;

int p[100010],N,Q,n;

int find(int x)
{
	return p[x]==x?x:find(p[x]);
}

int main()
{
	while(~scanf("%d %d",&N,&Q)&&N&&Q)
	{
		for(int i=2;i<=N;i++)
		{
			scanf("%d",&p[i]);
		}
		p[1]=1;
		long long sum=0;
		char ch[5];
		while(Q--)
		{
			scanf("%s %d",ch,&n);
			if(ch[0]=='Q')
				sum+=find(n);
			else if(ch[0]=='M')
				p[n]=n;
		}
		cout<<sum<<endl;
	}
} 


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

using namespace std;

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

    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c =='u'){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int S, h, m;
    
    scanf("%d", &S);
    
    h = S / 3600;
    S -= h * 3600;
    m = S / 60;
    S -= m * 60;

    printf("%d:%d:%d\n", h, m, S);
    
    return 0;
}



Measured memory_bytes: 2732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;

int divcnt(int n, int d){
    int cnt = 0;
    while(n % d == 0){
        n /= d;
        cnt++;
    }
    return cnt;
}

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int ans = 0;
    if(A == B && B == C) {
        if(A % 2 == 0) ans = -1;
        else ans = 0;
    }
    else{
        int divA = divcnt(A,2), divB = divcnt(B,2), divC = divcnt(C,2);
        if(divA == divB && divB == divC) ans = divA + 1;
        else ans = min({divA,divB,divC});
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
C = 3.times.map{
  gets.split.map(&:to_i)
}

if C[0][0] - C[0][1] == C[1][0] - C[1][1] &&
                        C[1][0] - C[1][1] == C[2][0] - C[2][1] &&
   C[0][2] - C[0][1] == C[1][2] - C[1][1] &&
                        C[1][2] - C[1][1] == C[2][2] - C[2][1]
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include <iostream>
#include <cassert>
#include <queue>
#include <string>
#include <cstring>
#include <cstdio>

#define MAX 10000000
#define INF 922337203685477580
typedef long long ll;

using namespace std;

char table[MAX][14];

int char2ord(char c) {
  if (c == 'A') {
    return 2;
  } else if (c == 'T') {
    return 3;
  } else if (c == 'C') {
    return 5;
  } else if (c == 'G') {
    return 7;
  } else {
    assert(0);
  }
}
ll genHash(string s) {
  ll hash = 11;
  for ( string::iterator it=s.begin(); it!=s.end(); ++it) {
    hash *= *it * 13;
    hash = hash % MAX;
    // cout << hash << endl;
  }
  // cout << "hash for <" << s << ">: " << hash << endl;
  return hash;
}
void insert(string s) {
  ll hash = genHash(s);
  while(strlen(table[hash]) != 0) { // if not empty
    hash += 1;
  }
  strcpy(table[hash], s.c_str());
}
int find(string s) {
  ll hash = genHash(s);

  while (strlen(table[hash]) != 0) {
    if (strcmp(table[hash], s.c_str()) == 0) {
      return 1; //found
    }
    hash++;
  }
  return 0;
}

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

  for (int i = 0; i < n; i++) {
    char cmd[12];
    // cin >> cmd;
    scanf("%s", cmd);

    if (cmd[0] == 'i') { // insert
      string dna;
      cin >> dna;
      insert(dna);
    } else if (cmd[0] == 'f') { // find
      string dna;
      cin >> dna;
      if (find(dna)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

  return 0;
}

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

using namespace std;

int main() {
	unsigned int next = 0, prev = 0, n;
	cin >> n;


	unsigned int* p1 = new unsigned int[n];

	for (unsigned int i = 0; i < n; i++) cin >> p1[i];

	for (unsigned int i =1; i < n; i++)
	{
		if (p1[i - 1] == p1[i]) continue;
		else if(p1[i-1] < p1[i])
		{
			p1[i]--;
		}
		else {
			cout << "No";
			delete[] p1;

			return 0;
			
		}


	}

	cout << "Yes";

	delete[] p1;

	return 0;






}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];
    }
    int ans=100;
    int minp=100;
    for(int i=101;i>=0;i--){
        int cnt=0;
        rep(j,n){
            if(p[j]!=i){
                cnt++;
            }
        }
        if(cnt==n){
            if(minp>=abs(x-i)&&ans){
                ans=i;
            }
            minp=min(abs(x-i),minp);
        }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 3624
k,n=map(int,input().split())
arr=list(map(int,input().split()))


min_=99999999999

for i in range(n):
	if i==0:
		x=arr[-1]-arr[0]
	else:
		x=k-(arr[i]-arr[i-1])
	if x<min_:
		min_=x


print(min_)

Measured memory_bytes: 32292
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Feb  2 15:14:37 2020
//
package main

import "fmt"

const MOD = 1e9 + 7

var H int

func main() {
	fmt.Scan(&H)

	n := 1
	ans := 0
	for i := 1; !(H < i && i <= 2*H); i *= 2 {
		ans += n
		n *= 2
	}
	fmt.Println(ans)
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  
  if(a==b&&b==c&&c==a){
    cout << "No" << endl;
  }
  else if(a!=b&&b!=c&&c!=a){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
#define MOD 1000000007
using namespace std;
const int MAXK = 1e5 + 5;
ll f[MAXK], n, k;

ll pow(ll a, ll n)
{
    ll ans = 1;
    while (n)
    {
        if (n & 1) ans = (ans * a) % MOD;
        n >>= 1;
        a = a * a % MOD;
    }
    return ans;
}

int main()
{
    cin >> n >> k;
    
    ll ans = 0;
    for (int i = k; i >= 1; i--)
    {
        f[i] = pow(k / i, n);
        for (int j = 2 * i; j <= k; j += i)
            f[i] = (f[i] - f[j] + MOD) % MOD;
    }

    for (int i = 1; i <= k; i++) ans = (ans + i * f[i]) % MOD;
    cout << ans << endl;
}

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

int main ()
{
	int S,h,m,s;
	cin >> S;
	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 3600 % 60;
	cout << h << ":" << m << ":" << s << endl;

	return 0;
}

Measured memory_bytes: 1168
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String a[] = new String[n];
        String b[] = new String[m];
        for(int i = 0; i < n; i++){
        	a[i] = sc.next();
        }
        for(int i = 0; i < m; i++){
        	b[i] = sc.next();
        }
        for(int i = 0; i < n - m + 1; i++){
        	for(int j = 0; j < n - m + 1; j++){
                int count = 0;
            	for(int k = 0; k < m; k++){
                	if(a[k + i].substring(j, (j + m)).equals(b[k])){
                    	count++;
                    }else{
                    	break;
                    }
                }
                if(count == m){
                	System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
	}
}

Measured memory_bytes: 35692
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
	int i;
	string s;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		cout<<"x";
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

const int N = 101;

int n, a, b;
vector<int> G[N];
bool vis[N];

int dfs(int p){
  vis[p] = true;
  int res = 1;
  for(int i=0;i<G[p].size();i++) if(!vis[G[p][i]]) res = max(res, dfs(G[p][i]) + 1);
  vis[p] = false;
  return res;
}

main(){
  while(cin >> n && n){
    for(int i=0;i<N;i++) G[i].clear();
    for(int i=0;i<n;i++){
      cin >> a >> b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    int ans = 0;
    for(int i=1;i<N;i++){
      fill(vis, vis+N, false);
      ans = max(ans, dfs(i));
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
double dp[3002][3002];
double p[3002];
int main() {
	int n;
	cin>>n;
	int i, j;
	for(i=1;i<=n;i++)
	    cin>>p[i];
	    
	dp[1][1] = p[1];
	dp[1][0] = 1  - p[1];
	
	for(i=2;i<=n;i++) {
	    for(j=0;j<=n;j++)  {
	        
	        dp[i][j] = dp[i-1][j]*(1-p[i]);
	        if(j>=1)
	            dp[i][j]+=dp[i-1][j-1]*(p[i]);
	        
	    }
	}
	
	double ans=0;
	for(i=0;i<=n;i++){
	    int heads = i;
	    int tails = n-i;
	    if(heads>tails)  
	        ans+=dp[n][i];
	}
	cout<<setprecision(12);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 70528
A=int(input())
B=int(input())
C=int(input())
X=int(input())


count=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i + 100*j + 50*k == X:
        count+=1

print(count)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int X = sc.nextInt();
            int Y = sc.nextInt();
            int Z = sc.nextInt();

            int swap = X;
            X = Y;
            Y = swap;
            swap = X;
            X = Z;
            Z = swap;

            System.out.println(X + " " + Y + " " + Z);
        }
    }
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if((C-A)*(C-B) < 0){
      printf("Yes\n");
  }
  else{
      printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 256
n = int(input())
list = []
for i in range(n):
    s, t = input().split()
    list.append([s, int(t)])
x = input()

time = 0
is_sleep = False
for i in range(n):
    if is_sleep:
        time += list[i][1]
    if list[i][0] == x:
        is_sleep = True

print(time)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl			    "\n"
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)



int32_t main()
{
	FIO;

	int h, w;
	cin >> h >> w;
	char a[h][w];
	fr(i, h) {fr(j, w) cin >> a[i][j];}
	int dp[h][w];

	fr(i, h) {fr(j, w) dp[i][j] = 0;}
	fr(i, w) {
		
			if (a[0][i] == '.') {dp[0][i] = 1;}
			else break;
		
	}
	fr(i, h) {
			if (a[i][0] == '.') {dp[i][0] = 1;}
			else break;
		}
	for (int i = 1; i < h; ++i) {
		for (int j = 1; j < w ; ++j)
		{
			if (a[i][j] != '#'){
			
				int op1 = dp[i - 1][j];
				int op2 = dp[i][j - 1];

				if (op1 > 0 and op2 > 0) dp[i][j] = (op1 + op2) % mod;
				else if (op1 > 0 and op2 <= 0) dp[i][j] = (op1) % mod;
				else if (op2 > 0 and op1 <= 0) dp[i][j] = (op2) % mod;
			}
		}
	}
	//fr(i, h) {{fr(j, w) cout << dp[i][j] << " " ;} cout << nl;}
	cout << dp[h - 1][w - 1];







}


Measured memory_bytes: 9088
<?php
fscanf(STDIN, "%d", $n);
$h = explode(" ", fgets(STDIN));

$h = array_reverse($h);

$err = 0;
foreach($h as $val){
	if($val !== $h[0]){
      	if(($val - $tmp) > 1){
          $err = 1;
          break;
        }
    	if(($val - $tmp) === 1){
          	$val--;
        }
    }	
  	$tmp = $val;	
}
if($err === 0){
	echo "Yes\n";
}else{
	echo "No\n";
}
?>

Measured memory_bytes: 30908
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    vector<pair<int, int> > v;
    for(int y=1; y<n; y+=2)
        v.push_back(make_pair(0, y));
    for(int x=2-n%2; x<n; x+=2)
        v.push_back(make_pair(x, n-1));
    for(int y=1; y<n-1; y+=3){
        for(int x=1+y%2; x<n; x+=2){
            v.push_back(make_pair(x, y));
        }
    }

    cout << v.size() << endl;
    for(const auto& p : v)
        cout << p.first << ' ' << p.second << endl;

    return 0;
}


Measured memory_bytes: 2928
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int a,b,c,k,ans;

int main(){
	cin>>k;
	
	for(a=1;a<=k;a++)
	for(b=1;b<=k;b++)
	for(c=1;c<=k;c++)
	ans+=__gcd(__gcd(a,b),c);
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)
#include <queue>
#include <set>
#include <vector>
using namespace std;
using i64 = long long;

struct Graph {
  struct edge {
    int to;
    i64 cap;
    i64 cost;
    int rev;
  };

  int n;
  vector<vector<edge>> edges;

  Graph(int N) {
    n = N;
    edges.resize(n, vector<edge>());
  }

  int size() const { return n; }

  vector<edge> &operator[](int v) { return edges[v]; }
};

struct Primal_Dual {
  Graph g;
  const int n;
  Primal_Dual(int n_) : g(n_), n(n_) {}

  void add_edge(int from,int to , i64 cost,i64 cap,i64 revcap){
    g[from].push_back({to, cap, cost , (int)g[to].size()});
    g[to].push_back({from, revcap, -cost, (int)g[from].size() - 1});
  }

  i64 minimumCostFlow(int s, int t, i64 f) {
    using Pi = pair<i64, i64>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    vector<int> prevv(n, -1);
    vector<int> preve(n, -1);
    vector<i64> potential(n, 0);
    i64 res = 0;
    while (f > 0) {
      vector<i64> dist(n, 1e9);
      que.push({0, s});
      dist[s] = 0;
      while (!que.empty()) {
        Pi p = que.top();
        que.pop();
        if (dist[p.second] < p.first)
          continue;
        for (int i = 0; i < (int)g[p.second].size(); i++) {
          auto &e = g[p.second][i];
          i64 next =
              dist[p.second] + e.cost + potential[p.second] - potential[e.to];
          if (e.cap > 0 && dist[e.to] > next) {
            dist[e.to] = next;
            prevv[e.to] = p.second;
            preve[e.to] = i;
            que.push({dist[e.to], e.to});
          }
        }
      }
      if (dist[t] == 1e9)
        return -1;
      for (int v = 0; v < n; v++) {
        potential[v] += dist[v];
      }
      i64 d = f;
      for (int v = t; v != s; v = prevv[v]) {
        d = min(d, g[prevv[v]][preve[v]].cap);
      }
      f -= d;
      res += d * potential[t];

      for (int v = t; v != s; v = prevv[v]) {
        auto &e = g[prevv[v]][preve[v]];
        e.cap -= d;
        g[v][e.rev].cap += d;
      }
    }
    return res;
  }
};
int n;
i64 a[1010],b[1010];

int main(){
	cin >> n;
	map<i64,int> mp;
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i];
		mp.emplace(a[i],(int)mp.size());
		mp.emplace(b[i],(int)mp.size());
	}
	int s = mp.size() + n;
	int t = mp.size() + n + 1;

	Primal_Dual pd(t + 1);

	for(auto ite = mp.begin();ite != mp.end();++ite){
		pd.add_edge(s, ite->second, 0, 1, 0);
	}
	for(int i = 0;i < n;i++){
		pd.add_edge(mp[a[i]],mp.size() + i, -b[i], 1, 0);
		pd.add_edge(mp[b[i]],mp.size() + i, -a[i], 1, 0);
		pd.add_edge(mp.size() + i, t, 0 , 1, 0);
	}

	pd.add_edge(s , t, 0, n, 0);

	cout << -pd.minimumCostFlow(s , t, n) << endl;;
}



Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
int n,sfx[102],pfx[102],a[102],b[102];
int main()
{
    cin >>n;
    for (int i=0;i<n;i++)
        cin>>a[i];
    for (int i=0;i<n;i++)
        cin >>b[i];
    pfx[0]=a[0];
    for (int i=1;i<n;i++)
    {
        pfx[i]=pfx[i-1]+a[i];
    }
    for (int i=n-1;i>=0;i--)
        sfx[i]=sfx[i+1]+b[i];
    int maxx=0;
    for (int i=0;i<n;i++)
        maxx=max(maxx,pfx[i]+sfx[i]);
    cout <<maxx;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        long d = sc.nextInt();
        long t = sc.nextInt();
        long s = sc.nextInt();

        boolean b = s * t >= d;
        System.out.println(b ? "Yes": "No");
    }

}

Measured memory_bytes: 35640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5005, M = 205, LG = 15;

int n, m, a[N], b[M][N], st[N][LG];
ll f[N][N];

void calc(int j, int l, int r) {
  int k = log2(r - l + 1);
  int p = st[l][k];
  if (b[j][p] < b[j][st[r - (1 << k) + 1][k]])
    p = st[r - (1 << k) + 1][k];
  // add b[j][p] to rectangle (l, p) -> (p, r)
  f[l][p] += b[j][p];
  f[p + 1][p] -= b[j][p];
  f[l][r + 1] -= b[j][p];
  f[p + 1][r + 1] += b[j][p];
  if (l <= p - 1) calc(j, l, p - 1);
  if (r >= p + 1) calc(j, p + 1, r);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> b[j][i];
    }
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i)
        st[i][0] = i;
    for (int k = 1; (1 << k) <= n; ++k) {
      for (int i = 1; i + (1 << k) - 1 <= n; ++i){
        if (b[j][st[i][k - 1]] > b[j][st[i + (1 << (k - 1))][k - 1]])
          st[i][k] = st[i][k - 1];
        else
          st[i][k] = st[i + (1 << (k - 1))][k - 1];
      }
    }
    calc(j, 1, n);
  }

  for (int l = 1; l <= n; ++l) {
    for (int r = 1; r <= n; ++r) {
      f[l][r] += f[l - 1][r] + f[l][r - 1] - f[l - 1][r - 1];
    }
  }

  ll ans = LLONG_MIN;
  for (int l = 1; l <= n; ++l) {
    ll dist = 0;
    for (int r = l; r <= n; ++r) {
      ans = max(ans, f[l][r] - dist);
      dist += a[r];
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 200192
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;
const int Mod=1e9+7;

lint ans=0;
lint n,k;

int main(void)
{

	//freopen("testdata.in","r",stdin);
	//freopen("testdata.out","w",stdout);

	scanf("%lld%lld",&n,&k);

	for(lint i=k;i<=n+1;i++)
	{
		ans+=(n+n-i+1)*i/2-(i-1)*i/2+1;
		ans%=Mod;
		// printf("%lld\n",ans);
	}

	printf("%lld\n",ans);

	return 0;

}

Measured memory_bytes: 3836
import math
def Sosu(N) :
    for i in range(2, int(math.sqrt(N))+1) :
        if N % i == 0 :
            return False
    return True
    
def main(a) :
    count = 0
    for i in range(2, a) :
        if Sosu(i) :
            other = a - i
            if other >= i and Sosu(other) :
                count += 1
    return count

while True :
    n = int(input())
    if n == 0 :
        break
    
    print(main(n))


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	int N, A;
	cin >> N >> A;
	vector<int> x(N);
	for (int i = 0; i < N; ++i)cin >> x[i];

	ll dp[55][3000][55]; 
	//3次元のdpを作る。dp[ i ][ s ][ k ] := N 個の整数のうちの最初の i 個から、k 個選ぶ場合について、総和を s にするものが何個あるか
	memset(dp, 0, sizeof(dp)); //0で初期化
	
	dp[0][0][0] = 1; //最初を1にする？？？「何も選ばない」を除くため？？

	for (int i = 0; i < N; ++i) //「最初のi個から」をカード分繰り返す
	{
		for (int s = 0; s <= N * A; ++s) //「総和s」を0から（カードの枚数 * 平均）まで繰り返す。 S / K(<=N) = A 変換するとsの最大値が分かる
		{
			for (int k = 0; k <= N; ++k) //「k個選ぶ」をカードの枚数分繰り返す
			{
				if (dp[i][s][k] == 0) continue; 
				dp[i + 1][s][k] += dp[i][s][k]; //x(i)を選ばない場合、iを次に移動するだけ
				dp[i + 1][s + x[i]][k + 1] += dp[i][s][k]; //x(i)を選んだ場合、iを次に移動して、総和sにx[i]を加算して、選んだ個数kを加算する
			}
		}
	}

	// ここまでで準備ができたのであとは答えを出力

	ll res = 0;
	for (int k = 1; k <= N; ++k) res += dp[N][A * k][k]; //「k個選ぶ」をカードの枚数分繰り返す。N枚のカードからk個選んで総和がA*kになるものを加算する。
	cout << res << endl;
}

Measured memory_bytes: 74552
n = int(input())
x = [None]*n
y = [None]*n

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


#y=x+k1 <=> x-y=-k1
k1 = [0]*n
#y=-x+k2 <=> x+y=k2
k2 = [0]*n
for i in range(n):
    k1[i] = -(x[i]-y[i])
    k2[i] = x[i]+y[i]

print(max(max(k1)-min(k1),max(k2)-min(k2)))

Measured memory_bytes: 82540
#include<bits/stdc++.h>
using namespace std;
int a[110];
int b[10100];
int main(){
    int n;
    scanf("%d",&n);

    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    memset(b,0,sizeof(b));
    b[0]=1;
    for(int i=0;i<n;i++){
        for(int j=10010;j>=a[i];j--)
            b[j]=max(b[j-a[i]],b[j]);
    }
    int ans=0;
    for(int j=10000;j>=0;j--)
    if(b[j]&&(j%10!=0)){ans=j;        break;}
        printf("%d\n",ans);
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n-1; i++){
        if(a[i] == a[i+1]){
            cnt++;
            a[i+1] = 0;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

int A,B;
int x[111];
ll coudp[111][111][5555];
string divide[4] = { "dream","dreamer","erase","eraser" };
int main()
{
	int r;
	cin >> r;
	cout << r * r << endl;

}

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

int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
    cout<<"Bad"<<endl;
  }else{
    cout<<"Good"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
created by sanyam singhal
*/

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

#define pb push_back
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define w(t) int t;	cin>>t while(t--)
#define triplet pair<int,pair<int,int>>
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
#define loop(i, k, n) for(ll i=k; i<n; i+=1)
#define loop2(i, k, n) for(ll i=k; i>=n; i--)

const ll inf = 1e18;
ll dp[3001][3001];


void take_fileIO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  return;
}

ll bottomUp(vector<ll> &candies, int i, int j, int p) {
  if(i>j){
    return 0;
  }
  else if(dp[i][j]!=-1)
    return dp[i][j];
  else{
    // if(p==1 || p==0){
      ll op1 = candies[i] - bottomUp(candies, i+1, j, 1-p);
      ll op2 = candies[j] - bottomUp(candies, i, j-1, 1-p);
      return dp[i][j] = max(op1, op2);
    // }
    // else{
    //   ll op1 = candies[i] - bottomUp(candies, i+1, j, 1-p);
    //   ll op2 = candies[j] - bottomUp(candies, i, j-1, 1-p);
    //   return max(op1, op2);
    // }
  }
}

void solve(){
  memset(dp, -1, sizeof(dp));
  ll n; cin>>n;
  vector<ll>candies(n);
  loop(i, 0, n)
    cin>>candies[i];

  cout<<bottomUp(candies, 0, n-1, 1);
}

int main(){

  fastIO;
  //take_fileIO();
  solve();
  return 0;
}

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

#define int int64_t
#define rep(i,a,n) for(int i=(a); i<(n); ++i)
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define re(s) reverse((s).begin(),(s).end())
#define ll long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3fLL;
const int mod = 1000000007;
using namespace std;

int x[510][510];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m,q;
    cin>>n>>m>>q;
    int l,r,cnt;

    rep(i,0,m){
        cin>>l>>r;
        ++x[l][r];
    }

    for(int i=1; i<=n; ++i){
        for(int j=1; j<=n; ++j){
            x[i][j] += (x[i-1][j] + x[i][j-1] - x[i-1][j-1]);
        }
    }

    rep(i,0,q){
        cin>>l>>r;
        cnt = (x[r][r] - x[r][l-1] - x[l-1][r] + x[l-1][l-1]);
        cout<<cnt<<'\n';
    }
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> xs(n);
  for(int i=0;i<n;i++) cin>>xs[i];
  sort(xs.begin(),xs.end());
  cout<<(xs.back()-xs.front()+1)/2<<endl;
  return 0;
}



Measured memory_bytes: 3148
from itertools import product
N,K=map(int, input().split())

num = [0 for k in range(K)]

# Nの範囲の中で、Kで割った時のあまりがxになる数がどれくらいあるのかをカウントする
for n in range(1, N+1):
  num[n%K] += 1

ans = 0

for a in range(len(num)):
  b = (K-a) % K
  c = (K-a) % K
  if (b + c) % K == 0:
    ans += num[a] * num[b] * num[c]

print(ans)

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

string s;
int ans;

int main() {
	cin >> s;
	ans = s.length() / 2 + s.length() % 2;

	for (int i = 0; i < s.length() / 2; i++) {
		if (!(s[s.length() / 2 - i - 1] == s[s.length() / 2 - i] 
			&& s[s.length() / 2 + i + s.length() % 2] == s[s.length() / 2 + i + s.length() % 2 - 1] 
			&& s[s.length() / 2 - i - 1] == s[s.length() / 2 + i + s.length() % 2])) {
			break;
		}
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;

 long long LCM(long long a,long long b){
	 long long r,x;
	 if(a<b) swap(a,b);
	 r=a%b;
	 x=a*b;
	 while(r!=0){
		 a=b;
		 b=r;
		 r=a%b;
	 }
	return x/b;
}

int MOD=1000000007;
int main() {
	long long A,B,C,D,Cwa,Dwa,dabu,wari,ans=0;
	cin >> A >> B >> C >> D;
	Cwa=B/C; Dwa=B/D; dabu=B/LCM(C,D);
	wari=Cwa+Dwa-dabu;
	ans=B-wari;
	Cwa=(A-1)/C; Dwa=(A-1)/D; dabu=(A-1)/LCM(C,D);
	wari=Cwa+Dwa-dabu;
	ans-=(A-1)-wari;
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = set()

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid.add((h-1,w-1))

    max_row = max(row)
    max_column = max(column)

    idx_row = [i for i,x in enumerate(row) if x == max_row]
    idx_column = [i for i,x in enumerate(column) if x == max_column]

    ans = max_row+max_column
    flag = False

    for h in idx_row:
        for w in idx_column:
            if not (h,w) in grid:
                flag = True
                break

    if flag:
        print(ans)
    else:
        print(ans-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83616
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
typedef long double ld;
//////////////////////////////////////////////////////////////////////

int main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  
  int n;ll ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    ll lx,rx;cin>>lx>>rx;
    ans += rx-lx+1;
  }
  cout<<ans<<nl;
  
  return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    double a, b, x;
    cin >> a >> b >> x;
    double v = a * a * b, ans;
    if (x * 2 > v) {
      double y = x / a / a * 2 - b;
      ans = atan2(b - y, a);
    } else {
      double y = x / a * 2 / b;
      ans = atan2(b, y);
    }
    printf("%.10f\n", ans / acos(-1) * 180);
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class MyScanner {
    BufferedReader br;

    MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public int intLine() throws IOException {
        return Integer.parseInt(br.readLine());
    }

    public String line() throws IOException {
        return br.readLine();
    }

    public int[] intArray() throws IOException {
        String[] in = br.readLine().split(" ");
        int n = in.length;
        int[] res = new int[n];
        for(int i = 0; i < n; i++) {
            res[i] = Integer.parseInt(in[i]);
        }
        return res;
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        MyScanner sc = new MyScanner();

        int[] in = sc.intArray();
        int n = in[0];
        int a = in[1];
        int b = in[2];

        System.out.println(Math.min(a * n, b));
        sc.br.close();
    }
}

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

int main() {
  int64_t n,a,b,x,y;
  cin >> n >> a >> b;
  int64_t asum=0;
  
  x = n/(a+b);
  y = n%(a+b);
  if(y>a){
    asum = a*x + a;
  }
  else{
    asum = a*x + y;
  }
  cout << asum << endl;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> high(N,0);
  vector<int> compare(N,0);
  for (int i=0; i<N; i++)
  {
    cin >> high.at(i);
  }
  for (int i=0; i<M; i++)
  {
    int A,B;
    cin >> A >> B;
    if(high.at(A-1) > high.at(B-1))
    {
      compare.at(B-1) = -1;
    }
    else if(high.at(A-1) < high.at(B-1))
    {
      compare.at(A-1) = -1;
    }else
    {
      compare.at(A-1) = -1;
      compare.at(B-1) = -1;
    }
  }
  
  int count = 0;
  for (int i=0; i<N; i++)
  {
    if(compare.at(i) == 0)
    {
      count++;
    }
  }
  
  cout << count << endl;

  

}


Measured memory_bytes: 4044
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;

int n;
int A[100001];

int main(){

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    sort(A,A+n);
    reverse(A,A+n);

    int x = 0, y = 0, cnt = 1;

    for(int i = 1; i <= n; i++){
        if(i == n || A[i] != A[i-1]){
            if(cnt >= 4){
                if(!x) x = y = A[i-1];
                else y = A[i-1];
                break;
            }
            else if(cnt >= 2){
                if(!x) x = A[i-1];
                else{ y = A[i-1]; break; }
            }
            cnt = 1;
        }else{
            cnt++;
        }
    }

    cout << (long long)x*y << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int v1, v2;
    double d, time;
    int l[10];
    char comma;

    while (cin >> l[0] >> comma) {
        int tmp;
        d = l[0];

        for (int i = 1; i < 10; i++) {
            cin >> tmp >> comma;
            d += tmp;
            l[i] = l[i - 1] + tmp;
        }

        cin >> v1 >> comma >> v2;

        time = v1 * d / (v1 + v2);

        for (int i = 0; i < 9; i++)
            if (l[i] < time && time <= l[i + 1]) {
                cout << i + 2 << endl;
                break;
            }
    }

    return 0;
}

Measured memory_bytes: 1160
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 1e9
long double PI =3.14159265358979323846;
 
const ll M=1e12;
const ll inf=1e18;
const ll ms=10000000;
fast;
ll ans,n,m;
void solve()
{
    cin>>n>>m;
    m=2*m+1;
    cout<<ceil(1.0*n/m)<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <functional>
#include <queue>
#include <random>
#include <string>
#include <stack>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

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

  std::string s;
  int x, y;

  static bool dp[4010][32010]; // dp[i][d] := i回目の移動でdに到達できるか
  std::vector<int> xd, yd(1, 0); // ydだけ調整

  cin >> s;
  cin >> x >> y;

  int cnt_f = 0;
  bool ans = true;

  for (int i = 0; i < int(s.size()); ++i) {
    if (s[i] == 'F') {
      cnt_f++;

      if (i == int(s.size() - 1)) {
        if (xd.size() < yd.size()) {
          xd.push_back(cnt_f);
        }
        else {
          yd.push_back(cnt_f);
        }
      }
    }
    else {
      if (xd.size() < yd.size()) {
        xd.push_back(cnt_f);
      }
      else {
        yd.push_back(cnt_f);
      }
      cnt_f = 0;
    }
  }

  // + 16000 がア もっとスマートに書く
  dp[0][xd[0] + 16000] = true;

  // 最後の命令の後に x にいることができるか
  for (int i = 1; i < int(xd.size()); ++i) {
    for (int x_ = -8000; x_ <= 8000; ++x_) {
      dp[i][x_ + 16000] |= (dp[i - 1][x_ - xd[i] + 16000] | dp[i - 1][x_ + xd[i] + 16000]);
    }
  }

  if (!dp[int(xd.size()) - 1][x + 16000]) {
    ans = false;
  }

  // dp を使い回す
  std::memset(dp, false, sizeof dp);

  dp[0][yd[0] + 16000] = true;

  // 最後の... y にいることができるか
  for (int i = 1; i < int(yd.size()); ++i) {
    for (int y_ = -8000; y_ <= 8000; ++y_) {
      dp[i][y_ + 16000] |= (dp[i - 1][y_ - yd[i] + 16000] | dp[i - 1][y_ + yd[i] + 16000]);
    }
  }

  if (!dp[int(yd.size()) - 1][y + 16000]) {
    ans = false;
  }

  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 125696
#include <iostream>

using namespace std;

int main() {
	int n, m, i, j, sum, c;
	int mat[100][100];
	int vec[100];
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			cin >> mat[i][j];
		}
	}
	for (i = 0; i < m; i++) {
		cin >> vec[i];
	}
	
	for (i = 0; i < n; i++) {
		sum = 0;
		for (j = 0; j < m; j++) {
			c = mat[i][j] * vec[j];
			sum += c;
		}
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3136
from collections import Counter

def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
C=Counter(A)
ans=0
for i in C.values():
    ans+=Comb(i,2)
for i in A:
    print(ans-C[i]+1)

Measured memory_bytes: 26780
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



N,M = map(int,input().split())
uf = UnionFind(N)

for _ in range(M):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)

ans = 1
for i in range(N):
    ans = max(ans,uf.size(i))

print(ans)

Measured memory_bytes: 75284
#include <bits/stdc++.h>
#define DUMBER using
#define EVERY namespace
#define DAY std
DUMBER EVERY DAY;
#define el '\n'
typedef long long ll;
ll a[55], p[55];
ll serc(int n, ll x) {
  if (x == 0) return x;
  if (n == 0) {
    if (x <= 0) return 0;
    return 1;
  }
  if (x <= 1+a[n-1]) return serc(n-1, x-1);
  //  bun [burger] pat [burger] bun 
  //  xxxxxxxxxxxxxxxxxxxxx
  //  xxxxxxxxxxxxxxxxx
  return 1 + p[n-1] + serc(n-1, x-2-a[n-1]);
}
int main() {
  int n;
  ll x;
  cin >> n >> x;
  a[0] = p[0] = 1;
  for (int i = 1; i <= n; i++) {
    a[i] = 2*a[i-1]+3;
    p[i] = 2*p[i-1]+1;
  }
  cout << serc(n, x) << el;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define REP(i,n) for(int i = 0; i < n ; ++i)
#define LL long long 
using namespace std;

int n;

int main()
{
	cin >> n;
	REP(i, n){
		LL ans = 0;
		LL y, m, d;
		cin >> y >> m >> d;
		for (int i = y+1; i < 1000; i++)
		{
			if (!(i % 3)){
				ans += 5 * 40;
			}
			else{
				ans += 5 * 39;
			}
		}
		for (int i = m + 1; i < 11; i++)
		{
			if (!(i % 2)){
				ans += 19 + (!(y%3));
			}
			else{
				ans += 20;
			}
		}
		ans += 19 + (!(y % 3) || (m % 2)) - d;

		cout << ans + 1 << endl;
	}
}

Measured memory_bytes: 1164
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: # j番目は正直と仮定
            for x,y in testimony[j]:
                if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
                    flag = 1
                    break
    if flag == 0:  
    # 矛盾がある場合はflag == 1になる
        honest = max(honest, bin(i)[2:].count('1'))  # 1の数をカウントし最大となるものを選択
print(honest)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>

using namespace std;
long long MOD = 1e9 + 7;

const long double PI = 3.1415926535;

int main() {
	long double a, b, x;
	cin >> a >> b >> x;
	long double t = 2 * (b*a*a - x ) / (a*a*a);
	if (a * a * b / 2 <= x)cout << setprecision(12) << atan2l(2 * (b * a * a - x), a * a * a) / acos(-1) * 180 << endl;
	else cout << setprecision(12) << atan2l(a * b * b, 2 * x) / acos(-1) * 180 << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<ll> a(26);
	vector<ll> b(26);

	for (int i = 0; i < s.length(); i++)
	{
		int a0 = s.at(i) - 'a';
		a.at(a0)++;
		int b0 = t.at(i) - 'a';
		b.at(b0)++;
	}

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

	bool ok = true;
	for (int i = 0; i < 26; i++)
	{
		if (a.at(i) != b.at(i))
		{
			ok = false;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
}

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

int main(){
	int n;
	cin>>n;
	for(;n--;){
		int x,y,b,p;
		cin>>x>>y>>b>>p;
		cout<<min((x*max(5,b)+y*max(2,p))*8/10, x*b+y*p)<<endl;
	}
}

Measured memory_bytes: 3096
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code)]

use std::cmp::*;
use std::collections::*;

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Pythonからの移行組としては苦しすぎるのでライブラリ濫造
fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {return a};
    return gcd(b, a % b);
}

// エントリーポイント
fn main() {
    input! {
        N : usize,
        D : usize
    }
    let d = D * 2 + 1;
    println!("{}", N / d + if N % d == 0 {0} else {1});
}


Measured memory_bytes: 4352