akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<queue>
using namespace std;
typedef pair<int,int> P;

int bfs();
char mas[1111][1111];
int d[1111][1111];
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int sx,sy;
int ans=0;
char life='0';
int h,w,n;
int INF=10000000;

int main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> mas[i][j];
      if(mas[i][j] == 'S'){
	sx = i,sy = j;
      }
    }
  }
  for(int i=1;i<=n;i++){
    life++;
    ans += bfs();
  }
  cout << ans << endl;
}

int bfs(){
  queue <P> que;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      d[i][j] = INF;
    }
  }
  que.push(P(sx,sy));
  d[sx][sy] = 0;
  while(que.size()){
    P p = que.front();
    que.pop();
    if(mas[p.first][p.second] == life){
      sx = p.first,sy=p.second;
      break;
    }
    for(int i=0;i<4;i++){
      int nx=p.first + dx[i];
      int ny=p.second + dy[i];
      if(nx >= 0 && nx < h && ny >= 0 && ny < w && mas[nx][ny] != 'X' && d[nx][ny] == INF){
	que.push(P(nx,ny));
	d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[sx][sy];
}

Measured memory_bytes: 6644
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int a;
  rep(i,m)
  {
    cin >> a;
    if (x < a) {
      cout << min(i, m - i);
      return 0;
    }
  }
  cout << 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

const long long mod=1e9+7;

int main(){
	int n,m;cin>>n>>m;
	vector<bool> conc(n+1,true);
    for(int i=1;i<=m;i++)
    {
        int temp; cin>>temp;
        conc[temp]=false;
    }
    vector<int> dynamic(n+1);
    fill(dynamic.begin(),dynamic.end(),0);
    dynamic[0]=1;
    for(int i=0;i<=n;i++)
    {
        for(int j=i+1;j<=min(n,i+2);j++)
        {
            if(conc[j])
                dynamic[j]+=dynamic[i];
            dynamic[j]%=mod;
        }
    }
    cout<<dynamic[n];
	return 0;
}


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

long long n;
vector<long long> a;
map<long long, long long> mp;

long long solve();

int main() {
  cin >> n;
  for(long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a.push_back(x);
    ++mp[x];
  }
  sort(a.begin(), a.end(), greater<long long>());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i < n; ++i) {
    if(mp[a[i]] > 0)
      for(long long j = 32; j >= 0; --j) {
        long long now = (1LL << j);
        if(now <= a[i]) break;
        if(mp[now - a[i]] > 0) {
          if(a[i] == now - a[i] && mp[a[i]] == 1) continue;
          ++ans;
          --mp[a[i]];
          --mp[now - a[i]];
          break;
        }
      }
  }
  return ans;
}


Measured memory_bytes: 65264
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    rep(i,3){
        if(i+1==a||i+1==b) continue;
        else{
            cout << i+1;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    ll a,b,x;
    cin>>a>>b>>x;
    ll ans=(b/x)-(a/x);
    if(a%x==0)ans++;
    cout<<ans;
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(abs(c-b-1)%2==0)
		printf("Borys");
	else
		printf("Alice");
	return 0;
 } 

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

int main() {
    int g;
    int x, y;

    cin >> x >> y;
    for (int i = 1; i <= 1000; i++) {
        if (x % i == 0 && y % i == 0) {
            g = i;
        }
    }

    cout << x + y - g + 1 << endl;
}



Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  int q;
  int ans;
  if(h<=w){
	q = n / w;
    if(n == q * w){
	  ans = q;
    }else{
	  ans = q + 1;
    }
  }else{
	q = n / h;
    if(n == q * h){
	  ans = q;
    }else{
	  ans = q + 1;
    }
  }
  cout  << ans;
  return 0;
}

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

int main(){
  string n;
  cin >> n;
  int s = n.size();
  if(n.at(s-1) == '3'){ 
    std::cout << "bon" << '\n';
  }
  else if(n.at(s-1) == '0' || n.at(s-1) == '1' || n.at(s-1) == '6' || n.at(s-1) == '8'){
     std::cout << "pon" << '\n';
  }
  else {
    std::cout << "hon" << '\n';
  }
  return 0;
}

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

signed main(){
	int n,m;
	cin>>n>>m;
	bool bou[m+5];
	for(int i=0;i<m+3;i++){
	    bou[i]=true;
	}
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		int a[k+5];
		a[0]=0;
		a[k+1]=m+1;
		for(int j=1;j<=k;j++){
			cin>>a[j];
		}
		sort(a,a+k+2);
		for(int j=0;j<=k+1;j++){
		    if(j!=0){
				for(int z=a[j-1]+1;z<a[j];z++){
					bou[z]=false;
					//cout<<z<<endl;
				}
			}
		}
	}
	for(int i=1;i<=m;i++){
		if(bou[i]){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 5e5 + 5;
ll l[N], r[N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen("VLJUM.INP", "r")){
                freopen("VLJUM.INP", "r", stdin);
                freopen("VLJUM.OUT", "w", stdout);
        }
        ll n, k, c;
        cin >> n >> k >> c;
        string s;
        cin >> s;
        s = " " + s;
        set<ll> sr;
        set<ll, greater<ll>> sl;
        for (int i = 1; i <= n; i++){
                if (s[i] == 'o') {
                        sl.insert(i);
                        sr.insert(i);
                }
        }
        sl.insert(-1e18);
        sr.insert(1e18);
        unordered_map<ll,ll> dp;
        dp[-1e18] = 0;
        for (int i = 1; i <= n; i++){
                if (s[i] == 'o'){
                        dp[i] = dp[*(sl.lower_bound(i - c - 1))] + 1;
                        if (l[dp[i]] == 0) {
                                l[dp[i]] = i;
                        }
                        if (dp[i] > k) return 0;
                }
        }
        dp.clear();
        dp[1e18] = k + 1;
        for (int i = n; i >= 1; i--){
                if (s[i] == 'o'){
                        dp[i] = dp[*(sr.lower_bound(i + c + 1))] - 1;
                        if (r[dp[i]] == 0){
                                r[dp[i]] = i;
                        }
                }
        }
        for (int i = 1; i <= k; i++){
                if (l[i] == r[i]) cout << l[i] << endl;
        }
}
/*
*/


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

int main() {
    int n,k;
    cin>>n>>k;
    double rate_sum=0;
    for(int i=1;i<=n;i++){
        int count=0;
        int x=i;
        while(x<k){

            x*=2;
            count++;
        }

        rate_sum+=(1.0/n)*pow((1.0/2),count);
    }

    cout << setprecision(12) << rate_sum<<endl;
}

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a, b, c;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a.push_back(x);
    b.push_back(y);
    c.push_back(z);
  }

  vector<vector<int> > dp(n+2, vector<int>(3));
  for (int i = 0; i < n; i++) {
    dp[i+1][0] = a[i] + max(dp[i][1], dp[i][2]);
    dp[i+1][1] = b[i] + max(dp[i][0], dp[i][2]);
    dp[i+1][2] = c[i] + max(dp[i][0], dp[i][1]);
  }

  cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
  return 0;
}


Measured memory_bytes: 6892
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll MOD=1e9+7 ;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string s; cin >> s;
    ll k; cin >> k;

    int n = s.length();
    bool flag = (s[0]==s[n-1]);
    ll samechar = 0;
    int start_renzoku = 1;
    int end_renzoku = 1;
    char start_char = s[0];
    char end_char = s[n-1];
    rep(i,n-1)
    {
        if (s[i] == s[i+1])
        {
            start_renzoku++;
        }
        else
        {
            break;
        }
    }
    for (int i=n-1;i>0;i--)
    {
        if (s[i] == s[i-1])
        {
            end_renzoku++;
        }
        else
        {
            break;
        }
    }
    if (start_renzoku==n)
    {
        cout << k * n / 2 << endl;
    }
    else
    {
        // mannnakawo kazoeru;
        for (int i=start_renzoku;i<n-end_renzoku;i++)
        {
            if (s[i] == s[i+1])
            {
                samechar++;
                s[i+1] = '0';
            }
        }
        if (flag)
        {
            // cout << "koko" << start_renzoku<<" " << end_renzoku<<" " << samechar <<endl;
            cout << samechar * k + start_renzoku / 2 + end_renzoku / 2 + (start_renzoku + end_renzoku) / 2 * (k-1) << endl;
        }
        else
        {
            cout << (samechar+(start_renzoku)/2+end_renzoku/2) * k << endl;
        }
        
    }
    

}


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

int main(){
  long long n ,a, b;
  cin >> n >> a >> b;
  
  if ((b - a) % 2 == 0){
    cout << (b - a) / 2<< endl;
  }
  else{
    cout << min(n - b, a - 1) + (b - a + 1) / 2 << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int mult(int a,int b){
    int res = (a%MOD * b%MOD)%MOD;
    return res;
}
void _run(){
  int n;
  cin>>n;
  int ans =1;
  for(int i=1;i<=n;i++){
      ans= mult(ans,i);
  }
  cout<<ans<<endl;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int t=1;
    // scanf("%d",&t);
    while(t--)_run();
    
    return 0;
}

Measured memory_bytes: 3512
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n = int(input().strip())
    a = list(map(int, input().strip().split()))
    ans=sys.maxsize
    for i in range(n):
        ans = min(abs(sum(a[0:i]) - sum(a[i:n])),ans)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 6480
#include <iostream>
using namespace std;
 
int
main(int argc, char *argv[])
{
        int a,b;
        float t;
        cin >> a;
        cin >> b;
        cin >> t;
        int sum=0;
        for(int i=1;i<t+0.5;i++){
            if(i%a==0){
                sum = sum + b;
            }
        }
        cout << sum << endl;
        return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
map<pair<int,int > ,int> mp;
map<pair<int,int > ,int> it;
int n;
int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

cin>>n;
for(int i=1;i<=n;i++)
{

		int y=i%10;
		int z,u;
		u=i;
		while(u)
		{
			z=u%10;
			u/=10;
}
mp[{y,z}]++;
//cout<<mp[{y,z}]<<endl;

	
}
int ans=0;
for(int y=0;y<10;y++)
for(int z=0;z<10;z++)
ans+=mp[{y,z}]*mp[{z,y}];



cout<<ans;


}

Measured memory_bytes: 256
Scanf.scanf "%s" (fun s ->
    let rec loop i acc =
        if i = 16 then acc else
            let acc = if s.[i] <> "CODEFESTIVAL2016".[i] then acc + 1 else acc in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
int a[]={0 ,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
	int n;
	cin>>n;
	cout<<a[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
using pii = pair <int, int>;
#define int ll
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = false;

vector <pair<string, int>> v[10];
int32_t main()
{
    usecppio
    v[1] = {{"a",0}};
    for (int i = 2; i<=10; i++)
    {
        for (auto it:v[i-1])
        {
            for (int j = 0; j<=it.second+1; j++)
            {
                string u = it.first;
                u.push_back('a'+j);
                v[i].push_back({u, max(it.second, j)});
            }
        }
        sort(all(v[i]));
        v[i].erase(unique(all(v[i])),v[i].end());
    }
    int n; cin >> n;
    for (auto it:v[n])
        cout << it.first << '\n';
}


Measured memory_bytes: 10736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N;
  int K;
  cin >> N >> K;
  int sum = 1;
  int x = K;
  int y = 0;
  
  while (x > 1) {
    y++;
    x /= 2;
  }
  y++;
  
  int n = N-y;
  
  if (N <= y) {
    for (int i = 0; i < N; i++) {
      sum *= 2;
	}
    cout << sum << endl;
  }
  else {
    for (int i = 0; i < y; i++) {
      sum *= 2;
	}
    for (int i = 0; i < n; i++) {
      sum += K;
	}
    cout << sum << endl;
  }
 
}

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

using namespace std;

int main(){
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int c,a,n; cin >> c >> a >> n;
        int sincho = min({c,a,n});
        c -= sincho;
        a -= sincho;
        n -= sincho;
//        cerr << c << " " << a << " " << n << endl;
        int gangan = min({c/2, a});
        c -= gangan*2;
        a -= gangan;
 //       cerr << c << " " << a << " " << n << endl;
        int ante = c/3;
  //      cerr << ante << " " << gangan << " " << sincho << endl;
        cout << ante+gangan+sincho << endl;
    }
    return 0;
}



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

std::vector<std::vector<int>> g;
std::vector<int> dp;

template<class T> inline void chmax(T& a, T b){
	if(a < b){
		a = b;
		return;
	}
	return;
}

int rec(int v){
	if(dp[v] != -1){ //探索済み
		return dp[v];
	}

	int res = 0;
	for(auto u : g[v]){
		chmax(res, rec(u) + 1);
	}
	return dp[v] = res;
}

int main(){
	int n, m;
	std::cin >> n >> m;
	g.resize(n);
	dp.assign(n, -1);
	for(int i=0; i<m; i++){
		int x, y;
		std::cin >> x >> y;
		--x; --y;
		g[x].emplace_back(y); 
	}

	int res = 0;
	for(int i=0; i<n; i++){
		chmax(res, rec(i));
	}

	std::cout << res << std::endl;
	return 0;

}

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

typedef struct {
  int a;
  string op;
  int b;
} calc_t;

int main()
{
  string line;
  calc_t c;
  vector<calc_t> v;
  while (1)
  {
    getline (cin,line);
    stringstream(line) >> c.a >> c.op >> c.b;
    if ( c.op=="?" ) { break; }
    v.push_back(c);
  }
  for ( auto c: v )
  {
    if      ( c.op=="+" ) { cout << c.a+c.b << '\n'; }
    else if ( c.op=="-" ) { cout << c.a-c.b << '\n'; }
    else if ( c.op=="*" ) { cout << c.a*c.b << '\n'; }
    else if ( c.op=="/" ) { cout << c.a/c.b << '\n'; }
    else { break; }
  }
  return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long int I,O,T,J,L,S,Z;
	cin>>I>>O>>T>>J>>L>>S>>Z;
	if(I==0||J==0||L==0)
		cout<<O+I/2*2+J/2*2+L/2*2<<endl;
	else{
		if((I%2==0&&J%2==0&&L%2==0)||(I%2==1&&J%2==1&&L%2==1))
			cout<<O+I+J+L<<endl;
		else
			cout<<O+I+J+L-1<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=b;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double,double>>
#define vpp vector<pair<int, pair<int,int>>>
#define pp pair<int,int>

stack<int> s;
int n,m,visited[100005];

// void topo_sort(vector<int> adj[], int src)
// {
// 	visited[src]=1;
// 	ffor(i,0,adj[src].size())
// 	{
// 		if(!visited[adj[src][i]])
// 			topo_sort(adj,adj[src][i]);
// 	}
// 	s.push(src);
// }

void dfs(int src, vector<int> adj[], int dp[])
{
   visited[src]=1;
   ffor(i,0,adj[src].size())
   {
   	 if(!visited[adj[src][i]])
   	 	dfs(adj[src][i],adj,dp);
   	 dp[src] = max(dp[src],1 + dp[adj[src][i]]);
   }
}

int main()
{
   cin>>n>>m;
   vector<int> adj[n];
   ffor(i,0,m)
   {
   	 int a,b;
   	 cin>>a>>b;
   	 a--,b--;
   	 adj[a].pb(b);
   }
   memset(visited,0,sizeof(visited));
   int dp[n];
   ffor(i,0,n) dp[i]=0;
   ffor(i,0,n)
   {
   	 if(!visited[i])
   	 	dfs(i,adj,dp);
   }
   int maxt=INT_MIN;
   ffor(i,0,n)
    maxt = max(maxt, dp[i]);
   cout<<maxt<<endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int h, w, n;
  cin >> h >> w >> n;
  int ans = INF;
  for(int i = 0; i <= h; ++i) {
    for(int j = 0; j <= w; ++j) {
      if(h*w - (h-i)*(w-j) >= n) chmin(ans, i+j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
N = int(input())
ans = 1
mod = 10**9 + 7
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
Sieve = [0]*(N+1)

for i in range(2,N+1):
    temp = i
    for p in prime:
        if p > temp:
            break
        while temp%p == 0:
            Sieve[p] += 1
            temp /= p

for s in Sieve:
    if s > 0:
        ans *= s+1
        ans %= mod

print(ans)

Measured memory_bytes: 3188
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <time.h>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#define LEN 100005
#define M 1046527
using namespace std;

string H[M];

int getChar(char ch)
{
    if (ch == 'A')
        return 1;
    else if (ch == 'C')
        return 2;
    else if (ch == 'G')
        return 3;
    else if (ch == 'T')
        return 4;
    else
        return 0;
}

long long getKey(string str)
{
    long long sum = 0, p = 1;
    for (int i = 0; i < str.size(); i++)
    {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(string str)
{
    long long key, h;
    key = getKey(str);
    for (int i = 0;; i++)
    {
        h = (h1(key) + i * h2(key)) % M;
        if (str.compare(H[h]) == 0)
            return 1;
        else if (H[h].size() == 0)
            return 0;
    }
}

int insert(string str)
{
    long long key, h;
    key = getKey(str);
    for (int i = 0;; i++)
    {
        h = (h1(key) + i * h2(key)) % M;
        if (str.compare(H[h]) == 0)
            return 1;
        else if (H[h].size() == 0)
        {
            H[h] = str;
            return 0;
        }
    }
    return 0;
}

int main()
{
    int n;
    cin >> n;
    string order;
    string key;
    for (int i = 0; i < n; i++)
    {
        cin >> order;
        cin >> key;
        if (order == "insert")
        {
            insert(key);
        }
        else if (order == "find")
        {
            if (find(key))
            {
                cout << "yes" << endl;
            }
            else
            {
                cout << "no" << endl;
            };
        }
    }
    return 0;
}



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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

int v[] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200};

void solve() {
	int n; scanf("%d", &n);
	int h[9] = {};
	for (int i = 0; i < n; ++i) {
		int t; scanf("%d", &t);
		++h[lower_bound(v, v+8, t+1)-v];
		debug(lower_bound(v, v+8, t+1)-v);
	}
	int ans = 0;
	for (int i = 0; i < 8; ++i) ans += !!h[i];
	printf("%d %d", max(ans, (int)!!h[8]), ans+h[8]);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
from functools import reduce

def gcd(a, b):
	while b != 0:
		a, b = b, a % b
	return a

def lcm(a, b):
	return (a * b) // gcd(a, b)

N = int(input())
T = [int(input()) for _ in range(N)]

print(reduce(lcm, T))

Measured memory_bytes: 3572
let () =
  let minkowski_dist x y p =
    if p = infinity 
    then List.fold_left2 (fun acc x y -> max acc (abs_float (x-.y))) 0. x y 
    else List.fold_left2 (fun acc x y -> acc +. (abs_float (x-.y) ** p))
        0. x y ** (1./.p)
  in
  let parse str = str
                  |> Str.split (Str.regexp " ")
                  |> List.map float_of_string in
  let _ = read_line () in
  let x = read_line () |> parse in
  let y = read_line () |> parse in
  List.iter
    (fun p -> minkowski_dist x y p |> Printf.printf "%f\n")
    [1.;2.;3.;infinity]

Measured memory_bytes: 2452
import re
s = input()
s_ = s.replace("BC", "D")
group = re.findall(r"[AD]+", s_)
ans = 0
for grp in group:
    a = 0
    for g in grp:
        if g=="A":
            a += 1
        if g=="D":
            ans += a
print(ans)

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

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;

constexpr long double INF = 1e20;
constexpr int MAX_N = 2000;

vector<long double> d(MAX_N, INF);
priority_queue<pair<long double, ll>, vector<pair<long double, ll>>, greater<pair<long double, ll>>> que;
vector<vector<pair<ll, long double>>> edges(MAX_N);

struct Point {
    Pll pos;
    long double r;
    Point(ll x=0, ll y=0, long double r=0.0): r(r) {
        pos = {x, y};
    }
    Point operator - (const Point &p) const { return Point(pos.first-p.pos.first, pos.second-p.pos.second); }
    long double abs() const { return sqrt(norm()); }
    long double norm() const { return pos.first*pos.first + pos.second*pos.second; }
    long double dot(Point &p) const { return pos.first*p.pos.first + pos.second*p.pos.second; }
};

void dijkstra(ll start){
    d[start] = 0;
    que.push({0, start});

    while(!que.empty()){
        auto v = que.top(); que.pop();
        if(d[v.second] < v.first) continue;
        for(auto e: edges[v.second]){
            if(d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push({d[e.first], e.first});
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    Point s, t;
    cin >> s.pos.first >> s.pos.second >> t.pos.first >> t.pos.second;
    int n;
    cin >> n;
    vector<Point> points(n);
    for(int i=0;i<n;++i){
        cin >> points[i].pos.first >> points[i].pos.second >> points[i].r;
    }

    for(int i=0;i<n;++i) {
        for(int j=i+1;j<n;++j) {
            long double dist = max(0.0L, (points[i]-points[j]).abs() - points[i].r - points[j].r);
            edges[i].emplace_back(j, dist);
            edges[j].emplace_back(i, dist);
        }
        edges[n].emplace_back(i, max(0.0L, (points[i]-s).abs() - points[i].r));
        edges[i].emplace_back(n+1, max(0.0L, (points[i]-t).abs() - points[i].r));
    }
    edges[n].emplace_back(n+1, max(0.0L, (t-s).abs()));

    dijkstra(n);

    cout << fixed << setprecision(15) << d[n+1] << endl;
}


Measured memory_bytes: 42544
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let k: isize = iterator.next().unwrap().parse().unwrap();
    let a: isize = iterator.next().unwrap().parse().unwrap();
    let b: isize = iterator.next().unwrap().parse().unwrap();

    if a >= b || (b - a) < 2 {
        return (k + 1).to_string();
    }

    if a >= k {
        return (k + 1).to_string();
    }

    let ans = a + (k - a + 1) / 2 * (b - a) + (k - a + 1) % 2;

    return ans.to_string();
}


Measured memory_bytes: 4352
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  rep(_, n) {
    int a = 0;
    vi x(3);
    int c = 0;
    while (a < 3) {
      string s;
      cin >> s;
      if (s == "OUT") {
        a++;
      }
      if (s == "HOMERUN") {
        c += count(all(x), 1) + 1;
        fill(all(x), 0);
      }
      if (s == "HIT") {
        c += x[2];
        rotate(x.begin(), x.begin() + 2, x.end());
        x[0] = 1;
      }
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

typedef struct _Node Node;
struct _Node {
        int val;
        Node *prev;
        Node *next;
};

Node *dummy;

Node *newNode(int _val, Node *_prev,  Node *_next) {
        Node *m = (Node*)malloc(sizeof(Node));
        m->val = _val;
        m->prev = _prev;
        m->next = _next;
        return m;
}

void init() {
        dummy = newNode(-1, NULL, NULL);
        dummy->prev = dummy;
        dummy->next = dummy;
}

Node* list_first() {
        return dummy->next;
}

Node* list_last() {
        return dummy->prev;
}

Node* list_end() {
        return dummy;
}

Node* insertAfter(Node *n, int val) {
        Node *m = newNode(val, n, n->next);
        n->next->prev = m;
        n->next = m;
        return m;
}

Node* InsertFirst(int val) {
        return insertAfter(dummy, val);
}

void Erase(Node *n) {
        if (n == dummy) {
                return;
        }
        n->prev->next = n->next;
        n->next->prev = n->prev;
        free(n);
        return ;
}

void Delete(int val) {
        Node *n = list_first();
        for (; n != list_end(); n = n->next) {
                if (n->val == val) {
                        return Erase(n);
                }
        }
}

void DeleteFirst() { Erase(list_first()); }

void DeleteLast() { Erase(list_last()); }

void Show() {
        Node *n = list_first();
        for (; n != list_end(); n = n->next) {
                printf(" %d", n->val);
        }
        printf("\n");
}

void PrintList() {
        bool ifs = false;
        Node *n;
        for (n = list_first(); n != list_end(); n = n->next) {
                if (ifs == true) {
                        printf(" ");
                }
                printf("%d", n->val);
                ifs = true;
        }
        printf("\n");
}

int main() {
        int loopmax, val, i;
        char cmd[64] = {};

        init();
        scanf("%d", &loopmax);
        for (i = 0; i < loopmax; i++) {
                memset(cmd, '\0', 64);
                scanf("%s %d", cmd, &val);
                if (cmd[0] == 'i') {
                        InsertFirst(val);
                } else {
                        if (cmd[6] == 'F') {
                                DeleteFirst();
                        }
                        else if (cmd[6] == 'L') {
                                DeleteLast();
                        }
                        else {
                                Delete(val);
                        }
                }
        }
        PrintList();

        return 0;
}

Measured memory_bytes: 31788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(int i = (m); i <= (n); i++)
#define zep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll r; cin >> r;
	cout << fixed << setprecision(20) << 2*r*3.141592653 << endl;
	return 0;
}

Measured memory_bytes: 3804
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var a = input[1].split(" ").map(i => parseInt(i));
  var dp = new Array(N+1);
  var mod=Math.pow(10,9)+7;
  for(var i=0;i<N+1;i++){
    var tmp=new Array(K+1).fill(0);
    dp[i]=tmp;
  }
  dp[0][0]=1;
  for(var i=0;i<N;i++){
    var sum=0;
    for(var j=0;j<K+1;j++){
      sum+=dp[i][j];
      sum%=mod;
      if(j>a[i]){
        sum+=mod-dp[i][j-a[i]-1];
        sum%=mod;
      }
      dp[i+1][j]=sum;
    }
  }
  var ans=dp[N][K];
  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 115504
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println(Math.abs(x - a) > Math.abs(x - b) ? "B" : "A");
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

ll choose2(ll n) {
    return n * (n - 1) / 2;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    vector<int> cnt(n);
    rep(i, n) cnt[a[i]]++;
    ll tot = 0;
    rep(i, n) {
        tot += choose2(cnt[i]);
    }
    rep(i, n) {
        ll ans = tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]] - 1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
int a[45],b[45],c[45];
int main()
{
	int n;
	long long ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n;i++)
		cin>>c[i];
	for(int i=0;i<n;i++)
	{
		ans+=b[i];
		if(a[i]-1==a[i-1])ans+=c[a[i-1]-1];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
ans,ans_2,ans_3,ans_4=float("inf"),float("inf"),float("inf"),float("inf")
for i in range(1,w):
    a=h*i
    res=w-i
    if res%2==0:
        b=h*(res//2)
        c=h*(res//2)
    else:
        b=h*(res//2)
        c=h*(res//2+1)
    cut=max(a,b,c)-min(a,b,c)
    ans=min(ans,cut)
for i in range(1,h):
    a_2=i*w
    res_2=h-i
    if res_2%2==0:
        b_2=w*(res_2//2)
        c_2=w*(res_2//2)
    else:
        b_2=w*(res_2//2)
        c_2=w*(res_2//2+1)
    cut_2=max(a_2,b_2,c_2)-min(a_2,b_2,c_2)
    ans_2=min(ans_2,cut_2)
for i in range(1,w):
    a_3=i*h
    res_3=w-i
    if h%2==0:
        b_3=res_3*(h//2)
        c_3=res_3*(h//2)
    else:
        b_3=res_3*(h//2)
        c_3=res_3*(h//2+1)
    cut_3=max(a_3,b_3,c_3)-min(a_3,b_3,c_3)
    ans_3=min(ans_3,cut_3)
for i in range(1,h):
    a_4=w*i
    res_4=h-i
    if w%2==0:
        b_4=res_4*(w//2)
        c_4=res_4*(w//2)
    else:
        b_4=res_4*(w//2)
        c_4=res_4*(w//2+1)
    cut_4=max(a_4,b_4,c_4)-min(a_4,b_4,c_4)
    ans_4=min(ans_4,cut_4)
print(min(ans,ans_2,ans_3,ans_4))


Measured memory_bytes: 3188
SS = list(input())
T = list(input())
nt = len(T)
un = 'UNRESTORABLE'
flag = False
for i in reversed(range(len(SS))):
    if i < nt-1:
        break
    flag2 = True
    for j in range(nt):
        if (SS[i-j] == T[nt-1-j] or SS[i-j] == '?') and flag2:
            continue
        else:
            flag2 = False
            break
    if flag2:
        for k in range(nt):
            SS[i+1-nt+k] = T[k]
        flag = True
        break
if flag:
    for s in range(len(SS)):
        if SS[s] == '?':
            SS[s] = 'a'
    print(''.join(SS))
else:
    print(un)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

int main() {
    vector<li> deg(4);
    for (int i = 0; i < 6; ++i) {
        li v;
        cin >> v;
        v--;
        deg[v] += 1;
    }
    bool ok = true;
    for (int i = 0; i < 4; ++i) {
        ok &= deg[i] <= 2;
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}


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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> s(n, 0);
  vector<int> e(n, 0);
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    if (a == 1)
    {
      s.at(b) = 1;
    }
    if (b == n)
    {
      e.at(a) = 1;
    }
  }

  for (int i = 2; i < n; i++)
  {
    if (s.at(i) && e.at(i))
    {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    map<ll, int, greater<ll>> mp;
    REP(i, n){
        ll a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0, rem = n;

    FORR(i, 1, 40){
        ll x = 1LL << i;
        while(rem > 1){
            auto itr = mp.begin();
            if(itr->first < (x >> 1)) break;
            itr->second--;
            rem--;
            ll y = x - itr->first;
            if(mp[y] > 0){
                mp[y]--;
                ans++;
                rem--;
            }
            if(itr->second == 0) mp.erase(itr->first);
            if(mp[y] == 0) mp.erase(y);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12800
#include<stdio.h>

int n,A[50];

int solve(int i,int m) {
  if(m==0)return 1;
  if(i>=n)return 0;
  int a = solve(i + 1,m)||solve(i+1,m-A[i]);
  return a;
}

int main(){
  int q,M,i;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }
}



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


int main()
{
	int n, a[100], i;

	cin >> n;

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

	for (i = 0; i < n; i++)
	{
		cout << a[n-1 - i];
		if (i == n-1)
		{
			break;
		}
		cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long A = cin.nextInt();
        long B = cin.nextInt();
        int[] X = cin.ArrayInt(N);
        long ans = 0;
        for (int i = 0; i < N - 1; i++)
        {
            ans += Math.Min(B, A * (X[i + 1] - X[i]));
        }
        Console.WriteLine(ans);
    }
    
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 20448
S = list(input())

count1 = 0
count2 = 0

for i in range(200000):
    if S[i] == "A":
        count1 = i
        break

for i in range(1, 200000 + 1):
    if S[-i] == "Z":
        count2 = i
        break

ans = len(S) - (count1 + count2) + 1
print(ans)

Measured memory_bytes: 10656