akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(long long int i=a; i<n; i++)
#define rloop(i,a,n) for(long long int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcount(a)
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define stkll stack<ll>
#define qll queue<ll>
#define pqll priority_queue<ll>
#define mod 1000000007
#define M 998244353
#define PI 3.141592653589793
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
int main()
{
    FAST
    FO
    FI
    int n;
    IN n;
    vector<string> a(n);
    map<string,int> mp;
    int maxi=0;
    loop(i,0,n)
    {
        IN a[i];
        mp[a[i]]++;
        maxi= max(maxi,mp[a[i]]);
    }
    set<string> s;
    for(auto x:mp)
    {
        if(x.second==maxi)
        {
            s.insert(x.first);
        }
    }
    for(auto x:s)
    {
        OUT x<<endl
    }
    return 0;
}


Measured memory_bytes: 34816
#include <iostream>

#define FOR(i , num) for(i = 0; i < num; i++)

using namespace std;

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

    if(s.length() <= k)
    {
        cout << s << endl;
    }
    else
    {
        string res;
        int i;
        FOR(i, k)
        {
            char a[2];
            a[0] = s[i];
            a[1] = '\0';
            res.append(a);
        }
        res.append("...");

        cout << res << endl;
    }
    
    return 0;   
}

Measured memory_bytes: 3628
// kyopro.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<string>
using namespace std;
#define ll long long int
#define rep(N) for(ll i=0;i<N;i++)
#define For(i,N) for(ll i=0;i<N;i++)
ll MOD = 1e9 + 7;
int main()
{
	ll H, W;
	cin >> H >> W;
	vector<string>S(H+2);
	rep(H) {
		cin >> S[i+1];
	}
	rep(H) {
		S[i+1].insert(W, "#");
		S[i+1].insert(0, "#");
	}
	rep(W+2) {
		S[0].push_back('#');
		S[H+1].push_back('#');
	}
	//from
	vector<vector<ll>>NDP(H+2);
	vector<vector<ll>>EDP(H + 2);
	vector<vector<ll>>SDP(H + 2);
	vector<vector<ll>>WDP(H + 2);
	rep(H + 2) {
		NDP[i].resize(W + 2);
		EDP[i].resize(W + 2);
		WDP[i].resize(W + 2);
		SDP[i].resize(W + 2);
	}

	ll ans = 0;

	rep(H+2) {
		For(j, W+2) {
			int flag = 1;
			int flag2 = 1;
			int flag3 = 1;
			if (S[i][j] == '#') {
				NDP[i][j] = -1;
				WDP[i][j] = -1;
				flag = 0;
			}
			if (S[i][W + 1 - j] == '#') {
				EDP[i][W + 1 - j] = -1;
				flag2 = 0;
			}
			if(S[H+1-i][j]=='#'){
				SDP[H+1-i][j] = -1;
				flag3 = 0;
			}
			if(flag!=0) {
				if (i != 0) {
					NDP[i][j] = NDP[i - 1][j]+1;
				}
				else
					NDP[i][j] = 0;
				if (j != 0) {
					WDP[i][j] = WDP[i][j-1]+1;
				}
				else
					WDP[i][j] = 0;

			}
			if (flag3 == 1) {
				if (i != H + 2) {
					SDP[H + 1 - i][j] = SDP[H + 1 - i + 1][j] + 1;
				}
				else
					SDP[H + 1 - i][j] = 0;
			}
			if (flag2 == 1) {
				if (j != W + 1) {
					EDP[i][W + 1 - j] = EDP[i][W + 1 - j + 1] + 1;
				}
				else
					EDP[i][W + 1 - j] = 0;
			}

		}
	}








	rep(H + 2) {
		For(j, W + 2) {
			ans = max(ans, NDP[i][j] + SDP[i][j] + EDP[i][j] + WDP[i][j]+1);
		
		}
	}

	cout << ans<<endl;


}


Measured memory_bytes: 129920
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)
#define pd(x) printf("%lf\n", x)
#define ps(x) printf("%s\n", x)
 
#define INF 1000000000000000000
#define MOD 1000000007

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

int compare_long(const void *a, const void *b) {
	return *(long*)b - *(long*)a;
}

int main() {
	long N;
  long i, j;
  long a, b;
	long ans = 0;
	
  sl(a); sl(b);
	
  //for(i=1;i<=N;i++) {
   // 
  //}
  if(a <= 5) pl(0);
  else if(a <= 12) pl(b/2);
  else pl(b);
	
	return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    let mut ans = 0;
    for i in 0..s.len() / 2 {
        if s[i] != s[s.len() - i - 1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2120
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    int N, K;
    double sum = 0.0f;
    int win_score = 1;
    
    cin >> N >> K;
    
    for (int i = 1; i <= N; i++) {
        win_score = i;
        int count = 0;
        while (win_score < K) {
            win_score *= 2;
            count++;
        }
        
        double a = (1.0 / (double)N) * pow(1.0 / 2.0, count);
        sum += a;
    }
    
    cout << fixed << setprecision(10);
    cout << sum << endl;
    
    return 0;
}

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 mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
void solve(){
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
}
 
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000;
const int maxn = 110; 
int h[maxn];
int n;
bool check(){
	for(int i=1;i<=n;i++){
		if(h[i]!=0){
			return true;
		}
	}
	return false;
} 

int main(){
	cin>>n;
	h[0]=0;
	h[n+1]=0;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	int pc = 0;
	int ans = 0;
	while(check()){
		if(pc==n+1) pc = 0;
		if(h[pc]==0){
			int j = pc+1;
			int miv = inf;
			while(h[j]!=0){
				miv = min(miv,h[j]);
				j++;
			}
			if(miv<inf){
				for(int i=pc+1;i<j;i++){
					h[i]-=miv;
				}
				ans+=miv;
			}
			pc=j;
		}
	}
	cout<<ans;
} 

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static int N;
        static long mod = 1000000007;
        static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray();
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            long K = long.Parse(Console.ReadLine());
            var num = new long[S.Length];

            for (int i = 0; i < S.Length; i++)
            {
                var tmp = S[i];
                num[i] = (tmp-97);
            }

            for (int i = 0; i < S.Length; i++)
            {
                
                if(num[i]+K >= 26)
                {
                    if (i != S.Length - 1 && num[i] == 0)
                    {
                        continue;
                    }
                    var tmp2 = 26 - num[i];
                    K -= tmp2;
                    num[i] = 0;
                }
                if(S.Length-1 == i)
                {
                    num[i] += (K%26);
                    //num[i] %= 26;
                }
            }

            var ans = new List<char>();
            for (int i = 0; i < S.Length; i++)
            {
                ans.Add((char)(97+num[i]));
            }

            //for (int i = 0; i < 26; i++)
            //{
            //    Console.WriteLine((char)(97 + i));
            //}

            Console.WriteLine(String.Join("",ans));
            }

    }
}


Measured memory_bytes: 32352
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while (true) {
			int H = scanner.nextInt();
			int W = scanner.nextInt();
			
			if (H == 0 && W == 0)
				break;
			
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++){
					if (i * j == 0 || i == H - 1 || j == W - 1) {
						System.out.print('#');
					} else {
						System.out.print('.');
					}
				}
					
				System.out.println();
			}
			System.out.println();
		}

	}

}



Measured memory_bytes: 36096
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main()
{
  ll n;
  cin>>n;
  cout<<n*(n-1)/2<<endl;
  return 0;
}


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

int constexpr N = 100009, MOD = 1000000007;
int n, m, f[N];
vector<int> d;
unordered_map<int, int> dp[40];

using ll = long long;
ll mod(ll x) {
    return x < 0 ? x % MOD + MOD : x % MOD;
}

ll mpow(ll base, ll exp) {
    base = mod(base);
    ll res = 1;
    while(exp > 0) {
        if(exp & 1) res = mod(res * base);
        base = mod(base * base);
        exp >>= 1;
    }
    return res;
}

int C(int c) {
    return (((f[n] * mpow(f[c], MOD - 2)) % MOD) * mpow(f[n - c], MOD - 2)) % MOD;
}

int go(int x, int c) {
    if(x == 1 && c <= n) {
        return C(c);
    }
  	if(c > n) return 0;
    if(dp[c].find(x) != dp[c].end()) return dp[c][x];
    int& ans = dp[c][x];
    for(int i : d) {
        if(i == 1) continue;
        if(x % i == 0) {
            ans += go(x / i, c + 1);
            if(ans >= MOD) ans -= MOD;
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i * i <= m; ++i) {
        if(m % i) continue;
        d.push_back(i);
        int j = m / i;
        if(j != i) d.push_back(j);
    }
    f[0] = 1;
    for(int i = 1; i < N; ++i) f[i] = (1LL* i * f[i - 1]) % MOD;
    cout << go(m, 0) << endl;
}

Measured memory_bytes: 896
//コメント有りver
#include <bits/stdc++.h>
using namespace std;
using  P=pair<int,int>;
int main(){
  int N,T,dp[3020][6020],maxvalue=0,a,b;
  cin>>N>>T;
  vector<P> vec(0);
  for(int i=0;i<N;i++){
    cin>>a>>b;
    vec.push_back(make_pair(a,b));//a(first)は所要時間,b(second)は価値
  }
  //所要時間順にソート
  sort(vec.begin(),vec.end());
  //(1+(rock^価値)*x^(所要時間))の累積の考えて指数について制限をかけて考える
  //係数についてはrockの指数部分について見る。
  //形式的冪級数展開を行う(T+max(所要時間)まで考える)
  //計算量はO(N*(T+max(所要時間)))<=O(1.8*10^7)なので間に合う！
  for(int h=0;h<N;h++){
    //先に0乗の係数は1にしておく
    dp[h][0]=1;
  }
  for(int i=1;i<=N;i++){
    for(int j=0;j<T;j++){
      if(dp[i-1][j]!=0){//多項式をかける前のj乗の係数が0で無いなら
        //多項式のうちxの指数乗の方について、係数をまずは計算
        dp[i][j+vec.at(i-1).first]+=dp[i-1][j]+vec.at(i-1).second;
        //(jが0の時だけ処理(j=0の係数の1が加算されてしまうため))
        if(j==0){dp[i][j+vec.at(i-1).first]--;}
        //(j+vec.at(i-1).first)乗の係数はかける前の係数とかけて計算して出てきた二つのうち大きい方を採用
        dp[i][j+vec.at(i-1).first]=max(dp[i][j+vec.at(i-1).first],dp[i-1][j+vec.at(i-1).first]);
        //j乗の係数も二つのうち大きい方を採用
        dp[i][j]=max(dp[i][j],dp[i-1][j]);
      }
      //最大価値を更新
      maxvalue=max(maxvalue,dp[i][j]);
      maxvalue=max(maxvalue,dp[i][j+vec.at(i-1).first]);
    }
  }
  cout<<maxvalue<<endl;
}

Measured memory_bytes: 64684
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<60)
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// ある数字xを先頭に持ってきた場合、その数より小さい数字を全て先頭に持ってくる必要がある。
// 逆にある数字xを末尾に持ってきた場合、その数より大きい数字を全て末尾に持ってくる必要がある。

// 移動しない数字の相対的な順序は変わらない。

int main(){
    Init();
    ll n; cin >> n;
    vi p(n);
    rep(i, n) cin >> p[i];

    vi dp(n+1, 0);
    ll maxval = 0;
    rep(i, n){
        if(dp[p[i]-1] == 0) dp[p[i]] = 1;
        else dp[p[i]] = dp[p[i]-1] + 1;
        chmax(maxval, dp[p[i]]);
    }
    cout << n-maxval << endl;
    return 0;
}


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

void chmin(int& a, int b){
    a = min(a, b);
}

const int Tmax = 10000;
int N, M;
int Dst[Tmax];

int dist[400][400], E[400][400], Nxt[400][400];

void initialize(){
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        E[a][b] = E[b][a] = c;
    }
    int _; cin >> _;
    for(int i=0; i<Tmax; i++){
        int n; cin >> n;
        if(n) cin >> _ >> Dst[i];
        Dst[i]--;
    }

    for(int i=0; i<N; i++) for(int j=0; j<N; j++) if(i != j) dist[i][j] = (E[i][j] ? E[i][j] : 1e9);
    for(int k=0; k<N; k++) for(int i=0; i<N; i++) for(int j=0; j<N; j++) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        for(int k=0; k<N; k++) if(i != k && E[i][k] && E[i][k] + dist[k][j] == dist[i][j]){
            Nxt[i][j] = k;
            break;
        }
    }
}

vector<int> ans;
int stock[400], have[400], havesum;
int pos, now;
int scorenum = 0;

void addtime(){
    now++;
    if(now < Tmax && Dst[now] >= 0) stock[Dst[now]]++;
}
void visit(int v){
    cerr << "Visit " << v << " on " << now << endl;
    if(v == 0) for(int i=0; i<N; i++){
        have[i] += stock[i];
        havesum += stock[i];
        stock[i] = 0;
    }
    scorenum += have[v];
    havesum -= have[v];
    have[v] = 0;
}

void moveto(int v){
    if(pos == v){
        addtime();
        ans.push_back(-1);
        visit(pos);
        return;
    }
    while(pos != v){
        int nxt = Nxt[pos][v];
        int d = E[pos][nxt];
        while(d--){
            addtime();
            ans.push_back(nxt);
        }
        pos = nxt;
        visit(nxt);
    }
}

int main(){
    initialize();
    int len = 0;
    while(ans.size() < Tmax){
        if(havesum > 0 && len < 80){
            int nxt = -1;
            for(int i=0; i<N; i++) if(have[i]) if(nxt == -1 || dist[pos][nxt] > dist[pos][i]) nxt = i;
            moveto(nxt);
            len++;
        }else{
            moveto(0);
            len = 0;
        }
    }
    ans.resize(Tmax);
    for(int a : ans) cout << (a == -1 ? -1 : a+1) << endl;
    cerr << "scorenum: " << scorenum << endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1*1e5+5;

int dp[MAXN][3];

vector<int> g[MAXN];

void dfs(int u, int p) {
    
    int grau = 0;
    
    dp[u][0] = 1;
    dp[u][1] = 1;
    for(auto i : g[u]) 
        if(i != p) {
            dfs(i, u);
            grau++;
            
            dp[u][1] = (dp[u][1]*dp[i][0])%mod;
            dp[u][0] = (dp[u][0]*(dp[i][0] + dp[i][1])%mod) %mod;
            
        }
    
}

int32_t main() {

    int n;
    cin >> n;
    
    for(int i = 0 ; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
        
    }
    
    dfs(0, 0);
    cout << (dp[0][0] + dp[0][1])%mod << endl;        
}


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

int main() {
	int n;
	cin >> n;
  	int ans = 0;
  	int arr[2*n];
  	for(int i=0; i<2*n; i++)
      	cin >> arr[i];
  	sort(arr, arr+2*n);
  	for(int i=0; i<2*n; i++) {
      	if(i % 2 == 0)
        	ans += arr[i];
    }
  	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int D, T, S;
    cin >> D >> T >> S;
    if(D % S == 0){
        if(D / S <= T)  cout << "Yes\n";
        else    cout << "No";
    }
    else{
        if((D + S - 1) / S <= T)    cout << "Yes\n";
        else    cout << "No\n";
    }
}

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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int n; cin >> n;
    double a[n];
    forn(i,n) cin >> a[i];
    vector<vector<double>> dp(n);
    forn(i,n) dp[i] = vector<double>(n+1);
    dforn(i,n){
        dp[i][0] = (1-a[i]) * (i+1 < n ? dp[i+1][0] : 1);
        forsn(j,1,n-i+1){
            double head = a[i] * (i+1 < n ? dp[i+1][j-1] : 1);
            double tail = (1-a[i]) * (i+1 < n ? dp[i+1][j] : 0);
            dp[i][j] = head + tail;
        }
    }
    double r = 0;
    forsn(i,n/2+1,n+1) r += dp[0][i];
    cout << fixed << setprecision(10) << r << endl;
    return 0;
}


Measured memory_bytes: 70656
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        int[] vars = { 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 };

        var k = System.Console.ReadLine().Split(' ').Select(int.Parse).ToArray()[0];


        System.Console.WriteLine(vars[k-1]);

    }
}



Measured memory_bytes: 13396
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


typedef long long ll;

using namespace std;

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

	int nums[m];
	for (int i = 0; i < m; i++) cin >> nums[i];


	int sum = 0;
	for (int i = 0; i < m; i++) sum += nums[i];

	if (sum > n){
		cout << -1 << endl;
	} else {
		cout << n - sum << endl;
	}


	return 0; 
} 


Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	int a[210][5];
	int s[210]={0};
	int f[210][5]={0};
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	    for(int j=0;j<3;j++){
            scanf("%d",&a[i][j]);

	    }
	}
	for(int j=0;j<3;j++){
        for(int i=0;i<n;i++){
            f[a[i][j]][j]++;
        }
	}

    for(int j=0;j<3;j++){
        for(int i=0;i<n;i++){
            if(f[a[i][j]][j]==1)s[i]+=a[i][j];
        }
	}
	for(int i=0;i<n;i++){
        printf("%d\n",s[i]);
	}
	return 0;
}

Measured memory_bytes: 1232
def A():
    p = s[2:]
    count = 0
    index = 0
    for i, c in enumerate(p):
        if c == '=':
            count += 1
        elif c == '#':
            index = i
            break
        else:
            print 'NA'
            return
    else:
        if not index:
            print 'NA'
            return
    p = p[index+1:-1]
    for c in p:
        if c == '=':
            count -= 1
        else:
            print 'NA'
            return
    if count == 0 and s[-1] == '~':
        print 'A'
    else:
        print 'NA'
         
def B():
    p = s[2:-2]
    for i in range(0, len(p), 2):
        if not (p[i]+p[i+1] == 'Q='):
            print 'NA'
            return
    if s[-2:] == '~~':
        print 'B'
    else:
        print 'NA'

for i in range(input()):
    s = raw_input()
    if s[:3] == ">'=":
        A()
    elif s[:4] == ">^Q=":
        B()
    else:
        print 'NA'

Measured memory_bytes: 4284
package main

import (
	"fmt"
)

func MinInts(nums ...int) int {
	var minVal int
	for i, e := range nums {
		if i == 0 || e < minVal {
			minVal = e
		}
	}
	return minVal
}

func main() {
	var str string
	fmt.Scan(&str)

	cnts := make([]int, 2)
	for _, c := range str {
		cnts[c-'0']++
	}
	fmt.Println(MinInts(cnts...) * 2)
}

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

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

    long long n, m, d;
    cin >> n >> m >> d;
    if (d == 0) {
        cout << setprecision(7) << (double) (m - 1)/ n << '\n';
    } else {
        cout << setprecision(7) << (double) 2 * (n - d) * (m - 1)/ (n * n) << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> b,tri,ans;
int main(){
	for(int i=0;i<1000;i++){
		tri.push_back(i*(i+1)/2);
	}
	while(true){
		b.clear();
		ans.clear();
		int n,k=0;
		cin >> n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			int h;
			cin >> h;
			k+=h;
			b.push_back(h);
		}
		if(find(tri.begin(),tri.end(),k)==tri.end()){
			cout << -1 << endl;
			continue;
		}
		int p=find(tri.begin(),tri.end(),k)-tri.begin();
		for(int i=0;i<p;i++) ans.push_back(i+1);
		for(int i=0;i<=10000;i++){
			if(b==ans){
				cout << i << endl;
				break;
			}
			for(int j=0;j<b.size();j++) b[j]--;
			b.push_back(b.size());
			for(int j=0;j<b.size();j++){
				if(b[j]==0){
					b.erase(b.begin()+j);
					j--;
				}
			}
		}
		if(b!=ans) cout << -1 << endl;
	}
	return 0;
}

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

int main(){
  long x, y, a, b, c, tmp, ans=0;
  priority_queue<long> pqa, pqb, pqc, res;
  cin >> x >> y >> a >> b >> c;
  rep(i, a){
    cin >> tmp;
    pqa.push(tmp);
  }
  rep(i, b){
    cin >> tmp;
    pqb.push(tmp);
  }
  rep(i, c){
    cin >> tmp;
    res.push(tmp);
  }
  rep(i, x){
    res.push(pqa.top());
    pqa.pop();
  }
  rep(i, y){
    res.push(pqb.top());
    pqb.pop();
  }
  for(long i = 0; i< x+y; i++){
    ans += res.top();
    res.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 7920
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, m;
  cin>>n>>m;
  int x[m];
  REP(i, m) cin >> x[i];
  sort(x, x+m);

  if(m==1){
    cout<<0<<endl;
    return 0;
  }
  priority_queue<int> q;
  REP(i, m-1) q.push(-x[i+1] + x[i]);
  int ans=0;
  REP(i, m-n){
    ans -= q.top();
    q.pop();
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
long long h,w,n;
long long ans[11];
map<long long, map<long long, long long> > core;
set<pair<long long, long long> > oup;
long long check(long long posy, long long posx){
	if(posy>=2&&posx>=2&&posy<=h-1&&posx<=w-1){
		return 1;
	}
	return 0;
}
signed main(){
	memset(ans,0,sizeof(ans));
	long long x[9] = {1,1,1,0,-1,-1,-1,0,0};
	long long y[9] = {-1,0,1,1,1,0,-1,-1,0}; 
	cin >> h >> w >> n;
	while(n--){
		long long a,b;
		cin >> a >> b;
		for(int i=0;i<9;i++){
			if(check(a+y[i],b+x[i])==1){
				core[a+y[i]][b+x[i]]++;
				oup.insert({a+y[i],b+x[i]});
			}
		}
	}
	for(auto t:oup){
		long long val = core[t.fi][t.se];
		if(val>=1&&val<=9){
			ans[val]++;
		}
		else if(val>9){
			ans[10]++;
		}
	}
	long long num = (h-2)*(w-2);
	for(int i=1;i<=10;i++){
		num = num - ans[i];
	}
	cout << num<<endl;
	for(int i=1;i<=9;i++){
		cout << ans[i] << endl;
	}
}

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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	
	int d[k];
	for(int i = 0; i < k; i++)
	{
		cin >> d[i];
	}
	
	int tmp = n;
	vector<int> x;
	while(tmp != 0)
	{
		x.insert(x.begin(), tmp % 10);
		tmp /= 10;
	}
	
	while(1)
	{
		bool flag = true;
		for(int i = 0; i < k; i++)
		{
			for(int j = 0; j < x.size(); j++)
			{
				if(d[i] == x[j])
				{
					flag = false;
					break;
				}
			}
		}
		
		if(flag == true)
		{
			break;
		}
		
		x[x.size() - 1]++;
		
		for(int i = x.size() - 1; i >= 0; i--)
		{
			if(x[i] == 10)
			{
				x[i] = 0;
				if(i != 0)
				{
					x[i - 1]++;
				}
				else
				{
					x.insert(x.begin(), 1);
				}
			}
		}
		
	}
	
	for(int i = 0; i < x.size(); i++)
	{
		cout << x[i];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int num[200001];
int main(void){
    // Your code here!
    int n, k, a;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a;
        num[a]++;
    }
    sort(num, num + 200001, greater<int>());
    int res = 0;
    for (int i = 0; i < k; i++) res += num[i];
    cout << n - res << endl;//超えるわけがない
}


Measured memory_bytes: 1152
#include <stdio.h>

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

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

int w,h;
int field[20][20];
int ans,sx,sy;

void dfs(int x, int y, int cnt){
  int tx,ty,i,j,k;
  int *p;
  if( cnt>=ans ) return;
  
#if DEB
  printf("(%d,%d)  cnt:%d\n",x,y,cnt);
  rep(i,h){
    rep(j,w){
      printf("%d ",field[i][j]);
    }
    puts("");
  }
#endif

  rep(k,4){
    tx = x;
    ty = y;
    if( tx<0 || ty<0 || tx>=w || ty>=h ||
	field[ty+dy[k]][tx+dx[k]]==1 )continue;
    for(;;){
      tx += dx[k];
      ty += dy[k];
      if( tx<0 || ty<0 || tx>=w || ty>=h ) break;
      p = &field[ty][tx];
      if( *p==1 ){
	*p = 0;
	dfs(tx-dx[k], ty-dy[k], cnt+1);
	*p = 1;
	break;
      }else if( *p==3 ){
	ans = cnt+1;
	return;
      }
    }
  }
}

int main(){
  int i,j;
  while(scanf("%d%d",&w,&h),w|h){
    ans = 11;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}
      }
    }
    dfs(sx,sy,0);
    printf("%d\n",ans==11?-1:ans);
  }
  return 0;
}

Measured memory_bytes: 412
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
  int n, y, b, r, t;
  int ans_num;
  double ans_value;
  double v;
  while(1)
  {
    ans_value = ans_num = -1;

    cin >> n;
    if(!n)
      break;
    cin >> y;
    for(int i = 0; i < n; i++)
    {
      cin >> b >> r >> t;
      if(t == 1)
        v = 1.0 * (1.0 + y * (r / 100.0));
      else
        v = 1.0 * pow(1.0 + r / 100.0, y);
      if(v > ans_value)
      {
        ans_value = v;
        ans_num = b;
      }
    }
    cout << ans_num << endl;
  }
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> height(n);
    for(int i = 0; i < n; i++)
        cin >> height[i];
    vector<int> dp(n + 1, INT_MAX);
    dp[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        if(i == 2)
            dp[i] = abs(height[i - 2] - height[i - 1]) + dp[i - 1];
        else
            dp[i] = min(abs(height[i - 2] - height[i - 1]) + dp[i - 1], abs(height[i - 3] - height[i - 1]) + dp[i - 2]);
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int g=0,b=0,gr=0,c=0,bl=0,y=0,o=0,r=0,n,x=0;
	cin >> n;
	vec(a,n);
	REP(i,n){
		cin >> a[i];
		if(a[i] < 400){
			g=1;
		}
		else if(a[i] < 800){
			b=1;
		}
		else if(a[i] < 1200){
			gr=1;
		}
		else if(a[i] < 1600){
			c=1;
		}
		else if(a[i] < 2000){
			bl=1;
		}
		else if(a[i] < 2400){
			y=1;
		}
		else if(a[i] < 2800){
			o=1;
		}
		else if(a[i] < 3200){
			r=1;
		}
		else{
			x++;
		}
	}
	int ans= g+b+gr+c+bl+y+o+r;
	(ans ==0)? cout << 1 << " " << x << endl : cout << ans << " " << ans+x << endl;

    return 0;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
)
 
func main() {
  var x int
  fmt.Scanf("%d", &x)

  ans := "NO"
  if x == 7 {
    ans = "YES"
  }
  if x == 5 {
    ans = "YES"
  }
  if x == 3 {
    ans = "YES"
  }
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1832
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
    char a[101],b[101],c[202];
    scanf("%s %s", a,b);
    int i;
    int x=strlen(a);
    int y=strlen(b);
    for(i=0;i<y;i++)
    {
        c[i]=b[i];
    }
    int k=0;
    for(i=y;i<x+y;i++)
    {
        c[i]=a[k++];
    }
    c[i]='\0';
    printf("%s\n", c);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 998244353

int main(){
    int N;
    cin >> N;
    vector<int> D(N+1);
    vector<int> count(N);
    ll ans = 1;
    int m = -1;
    for(int i=1;i<=N;i++){
        cin >> D[i];
        count[D[i]]++;
        if(m<D[i])m=D[i];
    }
    if(D[1]!=0 || count[0]!=1){
        cout << 0 << endl;
        return 0;
    }

    sort(D.begin(),D.end());
    for(int i=1;i<=N;i++){
        if(D[i-1]-D[i] < -1){
            cout << 0 << endl;
            return 0;
        }
    }

    for(int i=2;i<=N;i++){
        if(D[i]==1) continue;
        ans*=count[D[i]-1];
        ans%=MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import numpy as np
N = int(input())
Hs = [int(i) for i in input().split()]

DP_list = [np.inf for _ in range(N)]
DP_list[0] = 0

for i in range(1, N):
  for j in range(i-2, i):
    if j >= 0:
      this_time_score = DP_list[j] + np.abs(Hs[j] - Hs[i])
      if DP_list[i] > this_time_score:
        DP_list[i] = this_time_score 

print(DP_list[-1])

Measured memory_bytes: 23080
def main():
    import itertools as it
    N,A,B,C = map(int,input().split())
    pre = [int(input()) for _ in range(N)]
    ss = max(pre)*N <= min(A,B,C)
    if N == 3:print(A-pre[0]+B-pre[1]+C-pre[2])
    else:
        m = [0,1,2,3,4,5,6,7]
        cpm = it.permutations(pre,N)
        ccb = list(it.combinations(m[:N], 3))
        minc = 99999999999999999
        for l in cpm:
            for d in ccb:
                cmp = (d[2] - 2) * 10
                if ss:
                    asum = (cmp+A+B+C-sum(l[:d[2]+1]))
                    minc = min(minc,asum)
                else:
                    asum = abs(A - sum(l[:d[0]+1]))
                    if cmp+asum >= minc: continue
                    bsum = abs(B - sum(l[d[0]+1:d[1]+1]))
                    if cmp+asum+bsum >= minc: continue
                    csum = abs(C - sum(l[d[1]+1:d[2]+1]))
                    tc = cmp+asum+bsum+csum
                    minc = min(minc,tc)
        print(minc)
main()

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

int main(){
  int N,M,sum=0,p,x;
  cin >> N;
  vector<int> T(N,0);
  for(int i=0;i<N;i++){
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  for(int i=0;i<M;i++){
    cin >> p >> x;
    cout << sum - T[p-1] + x << endl;
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> data(H, vector<char>(W));
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> data.at(i).at(j);
    }
  }
  
  vector<int> row;
  vector<int> col;
  
  for (int i = 0; i < H; i++) {
    bool flag = true;
    for (int j = 0; j < W; j++)
    {
      if( data.at(i).at(j) == '#' )
      {
        flag = false;
      }
    }
    if (flag == true)
    {
      row.push_back(i);
    }
  }  

  for (int i = 0; i < W; i++) {
    bool flag = true;
    for (int j = 0; j < H; j++)
    {
      if( data.at(j).at(i) == '#' )
      {
        flag = false;
      }
    }
    if (flag == true)
    {
      col.push_back(i);
    }
  }  
  
  for (int i = 0; i < H; i++)
  {
    bool flag = false;  
    for (int x: row)
    {
      if(x == i)
      {
        flag = true;
        break;
      }
    }
    if (flag == true)
    {
      continue;
    }
    
    for (int j = 0; j < W; j++)
    {
      flag = false;
      for (int x: col)
      {
        if(x == j)
        {
          flag = true;
          break;
        }
      }
      if(flag == false)
      {
      	cout << data.at(i).at(j);
      }
    }
    cout << endl;
  }
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

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

    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    ll ans=0;
    rep(i,n){
        cin>>h[i];
        if(h[i]>=k){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int y=0;
  double i;
  cin>>N;
  for(i=0;i<50000;i++){
    if((int)(i*(1.08))==N){
      y=1;
      break;
    }
  }
  if(i==50000 && y==0){
    cout<<":("<<endl;
  }else{
    cout<<i<<endl;
  }
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PA;
typedef priority_queue<int, vector<int>, greater<int> > GQint;
typedef priority_queue<int> PQint;
typedef priority_queue<PA, vector<PA>, greater<PA> > GQpair;
typedef priority_queue<PA> PQpair;
typedef	set<int> Sint;
typedef	set<PA> SPA;
typedef map<int, int> MAP;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 100000001
#define MOD 100000
#define MAXN 100005
#define MAXM 30001

ll n,a[MAXN],c[MAXN];

int main()
{
    cin >> n;
    REP(i, 1, n + 1){
        cin >> a[i];
    }
    REP(i, 1, n + 2){
        c[i] = abs(a[i - 1] - a[i]) + c[i - 1];
    }
    REP(i, 1, n + 1){
        cout << c[n + 1] - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
    }


    return 0;
}
/*O(10 ^ 9)(2s)
    REP(i,a){
        REP(j,b){
4 4
1 2 100
2 3 250
2 4 200
3 4 100

        }
    }
*/



Measured memory_bytes: 2816
N = int(input())
S = sorted([input() for x in range(N)])
word = [S[0]]+[""]*(N-1)    #単語のリスト
kaisuu = [0]*N              #単語の出た回数のリスト
k = 0                       #今wordリストのどこを使っているか

for p in range(N):  #wordとkaisuuのリスト作成

    if word[k] != S[p]:
        k += 1
        word[k] = S[p]
        kaisuu[k] += 1
    
    else:
        kaisuu[k] += 1

m = max(kaisuu)     #m:出た回数が最大のもの
ansnum = []         #出た回数が最大のもののwordリストでの位置
for q in range(N):      
    if kaisuu[q] == m:
        ansnum += [q]

for r in range(len(ansnum)):
    print(word[ansnum[r]])

Measured memory_bytes: 35672
#include <bits/stdc++.h>
#define ssize 8
#define fi first
#define se second
using namespace std;
using P = pair<int, int>;

string s[ssize];
char cookie[2] = {'x', 'o'};
P dummy = {-1, -1};

void solve();
P search(bool turn);
void setc(P now, bool turn);
int calc(P now, bool turn, P nowd);
bool ch(P now);

int main() {
  for(int i = 0; i < ssize; ++i) cin >> s[i];
  solve();
  for(int i = 0; i < ssize; ++i) cout << s[i] << endl;
  return 0;
}

void solve() {
  int fin = 0;
  bool turn = 1;
  while(fin != 2) {
    P now = search(turn);
    if(now == dummy)
      ++fin;
    else {
      fin = 0;
      setc(now, turn);
    }
    turn = !turn;
  }
}

P search(bool turn) {
  P ans = dummy;
  int cnt = 0;
  for(int i = 0; i < ssize; ++i)
    for(int j = 0; j < ssize; ++j)
      if(s[i][j] == '.') {
        int now = 0;
        for(int k = -1; k <= 1; ++k)
          for(int l = -1; l <= 1; ++l)
            if(k != 0 || l != 0) {
              now += calc({i, j}, turn, {k, l});
            }
        if(turn && now > cnt) {
          cnt = now;
          ans = {i, j};
        }
        if(!turn && now >= cnt && now != 0) {
          cnt = now;
          ans = {i, j};
        }
      }
  return ans;
}

void setc(P now, bool turn) {
  s[now.fi][now.se] = cookie[turn];
  for(int i = -1; i <= 1; ++i)
    for(int j = -1; j <= 1; ++j)
      if(i != 0 || j != 0) {
        P nowp = now;
        int cnt = calc(now, turn, {i, j});
        for(int k = 0; k < cnt; ++k) {
          nowp.fi += i;
          nowp.se += j;
          s[nowp.fi][nowp.se] = cookie[turn];
        }
      }
}

int calc(P now, bool turn, P nowd) {
  int cnt = 0;
  while(ch({now.fi + nowd.fi, now.se + nowd.se})) {
    now.fi += nowd.fi;
    now.se += nowd.se;
    if(s[now.fi][now.se] == cookie[turn])
      return cnt;
    else if(s[now.fi][now.se] == cookie[!turn])
      ++cnt;
    else
      break;
  }
  return 0;
}

bool ch(P now) {
  return now.fi >= 0 && now.fi < ssize && now.se >= 0 &&
         now.se <= ssize;
}


Measured memory_bytes: 3200
class Node:
  def __init__(self, id):
    self.id = id
    self.parent = None
    self.left = None
    self.right = None

def preParse(node):
  if node == None:
    return
  print(" {}".format(node.id), end="")
  preParse(node.left)
  preParse(node.right)

def inParse(node):
  if node == None:
    return
  inParse(node.left)
  print(" {}".format(node.id), end="")
  inParse(node.right)

def postParse(node):
  if node == None:
    return
  postParse(node.left)
  postParse(node.right)
  print(" {}".format(node.id), end="")

num = int(input())
nodes = [None] * num
for i in range(num):
  id, left, right = map(int, input().split())
  node = nodes[id] if nodes[id] else Node(id)
  nodes[id] = node

  if left != -1:
    if nodes[left]:
      nodes[left].parent = node
      node.left = nodes[left]
    else:
      l = Node(left)
      l.parent = node
      node.left = l
      nodes[left] = l

  if right != -1:
    if nodes[right]:
      nodes[right].parent = node
      node.right = nodes[right]
    else:
      r = Node(right)
      r.parent = node
      node.right = r
      nodes[right] = r

def getParent(node):
  if node.parent == None:
    return node
  return getParent(node.parent)

print("Preorder")
preParse(getParent(nodes[0]))
print()
print("Inorder")
inParse(getParent(nodes[0]))
print()
print("Postorder")
postParse(getParent(nodes[0]))
print()


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

struct CumulativeSum2D {
	int h;
	int w;
	std::vector<std::vector<ll>>& grid_;
	CumulativeSum2D(std::vector<std::vector<ll>>& grid) : grid_(grid) {
		h = grid_.size() - 1;
		w = grid_[0].size() - 1;
		for (int i = 0; i < h; ++i)
			for (int j = 0; j < w; ++j)
				grid_[i + 1][j + 1] += grid_[i][j + 1] + grid_[i + 1][j] - grid_[i][j];
	}

	ll get_from_size(int left, int top, int width, int height) {
		return grid_[top + height][left + width] - grid_[top][left + width] - grid_[top + height][left] + grid_[top][left];
	}

	ll get_from_ltrb(int left, int top, int right, int bottom) {
		return get_from_size(left, top, right - left + 1, bottom - top + 1);
	}
};

int main(void)
{
	ll n, k;
	cin >> n >> k;
	int k2 = 2 * k;
	vector<vector<ll>> black(k2 * 2+1, vector<ll>(k2 * 2+1, 0));
	vector<vector<ll>> white(k2 * 2+1, vector<ll>(k2 * 2+1, 0));
	rep(i, n) {
		ll x, y;
		char c;
		cin >> x >> y >> c;
		if (c == 'W') {
			white[x % k2 + 1] [y % k2 + 1]++;
			white[x % k2 + k2 + 1][y % k2 + 1]++;
			white[x % k2 + 1][y % k2 + k2 + 1]++;
			white[x % k2 + k2 + 1][y % k2 + k2 + 1]++;
		}
		else {
			black[x % k2 + 1][y % k2 + 1]++;
			black[x % k2 + k2 + 1][y % k2 + 1]++;
			black[x % k2 + 1][y % k2 + k2 + 1]++;
			black[x % k2 + k2 + 1][y % k2 + k2 + 1]++;
		}
	}
	CumulativeSum2D b(black);
	CumulativeSum2D w(white);

	ll ans = 0;
	for (int y = 0; y < k2; y++) {
		for (int x = 0; x < k2; x++) {
			ll r = 0;
			r += w.get_from_size(x, y, k, k);
			r += w.get_from_size(x + k, y + k, k, k);
			r += b.get_from_size(x + k, y, k, k);
			r += b.get_from_size(x, y + k, k, k);
			ans = max(ans, r);
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef double dd;

void solve(ll test_num) {
  (void) test_num;
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  const ll dx = abs(A - C), dy = abs(B - D);
  const ll gcd = __gcd(dx, dy);
  ll res = 0;
  if (dx > 0 && dy > 0) {
    res = gcd * ((dx / gcd - 1) + (dy / gcd - 1) + 1);
  }
  cout << res << endl;
}

void init() {

}

int main() {
#ifdef AZN
  const auto start_time = chrono::system_clock::now();
  freopen("/home/azneye/Documents/Stuff/input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  init();
  ll tests = 1;
  //cin >> tests;
  for (ll test = 1; test <= tests; ++test) {
    solve(test);
  }
#ifdef AZN
  cerr << "Took: " << ((chrono::system_clock::now() - start_time).count() / 1e9) << " s" << endl;
#endif
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
    long N,A,B;
    long num = 0;
    scanf("%ld %ld %ld\n",&N,&A,&B);
    num = (N/(A+B))*A;
    if(N%(A+B) < A){
        num+=N%(A+B);
    }else{
        num+=A;
    }

    printf("%ld",num);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int S;
    int W;
    cin >> S >> W;
    if(S <= W){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector <string> a(n);
    for (auto &i : a) cin >> i;
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < (1 << m); j++) {
            auto b = a;
            for (int i1 = 0; i1 < n; i1++) {
                if (i & (1 << i1)) {
                    for (int j1 = 0; j1 < m; j1++) {
                        b[i1][j1] = '-';
                    }
                }
            }
            for (int j1 = 0; j1 < m; j1++) {
                if (j & (1 << j1)) {
                    for (int i1 = 0; i1 < n; i1++) {
                        b[i1][j1] = '-';
                    }
                }
            }
            int cnt = 0;
            for (int i1 = 0; i1 < n; i1++) {
                for (int j1 = 0; j1 < m; j1++) {
                    if (b[i1][j1] == '#') ++cnt;
                }
            }
            if (cnt == k) ++ans;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3616