akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

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

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

#define MAX_V 2000
struct edge{int to,cap,rev;};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f){
  int i;
  if(v==t)return f;
  used[v]=true;
  rep(i,G[v].size()){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(void) {
  int i,j;
  int m,n;
  while(1){
    memset(G,0,sizeof(G));

    cin>>m>>n;
    if(n+m==0)break;
    vi b(m),r(n);
    rep(i,m){
      cin>>b[i];
      add_edge(0,1+i,1);
      //cout<<0<<" "<<1+i<<endl;
    }
    rep(i,n){
      cin>>r[i];
      add_edge(1+m+i,1+m+n,1);
      //      cout<<1+m+i<<" "<<1+m+n<<endl;
    }
    rep(i,m) rep(j,n) if(__gcd(b[i],r[j])>1) add_edge(1+i,1+m+j,1);
    
    cout<<max_flow(0,1+m+n)<<endl;
  }
}

Measured memory_bytes: 63152
#include<stdio.h>
int main()
{
    int n,i,x;
    scanf("%d %d",&n,&i);
    if(n>0 && n<=100 && i>0 && i<=n)
    {
        x=(n-i)+1;
        printf("%d\n",x);
    }

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
using namespace std;
int w,h;
char m[21][21];

int dfs(int y,int x){
  if(x < 0 || x >= w)return 0;
  if(y < 0 || y >= h)return 0;
  if(m[y][x] == '#') return 0;
  int ret = 1;
  m[y][x] = '#';
  ret += dfs(y+1,x);
  ret += dfs(y-1,x);
  ret += dfs(y,x+1);
  ret += dfs(y,x-1);
  return ret;
}

int main(){
  int sx,sy;
  while(true){
  scanf("%d %d",&w,&h);
  if(w == 0 && h == 0)break;
  for(int i = 0;i < h;i++){
    scanf("%s",m[i]);
    for(int j = 0;j < w;j++){
      if(m[i][j] == '@'){
        sx=j;sy=i;
      }
    }
  }
  printf("%d\n",dfs(sy,sx));
  }
}

Measured memory_bytes: 1044
def e_max_min_sums(MOD=10**9 + 7):
    N, K = [int(i) for i in input().split()]
    A = sorted([int(i) for i in input().split()])

    class Combination(object):
        """参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb"""
        __slots__ = ['mod', 'factorial', 'inverse']

        def __init__(self, max_val_arg: int = 10**6, mod: int = 10**9 + 7):
            fac, inv = [1], []
            fac_append, inv_append = fac.append, inv.append

            for i in range(1, max_val_arg + 1):
                fac_append(fac[-1] * i % mod)

            inv_append(pow(fac[-1], mod - 2, mod))

            for i in range(max_val_arg, 0, -1):
                inv_append((inv[-1] * i) % mod)

            self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

        def combination(self, n, r):
            if n < 0 or r < 0 or n < r:
                return 0
            return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod

    comb = Combination(N + 1).combination
    ans = 0
    for time in range(2):  # time == 1 のときは min を計算している
        for i in range(N):
            current = comb(i, K - 1)
            if time == 1:
                current = -current
            ans += A[i] * current
        A.reverse()
    return ans % MOD

print(e_max_min_sums())

Measured memory_bytes: 15704
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
 
 
class Program {
    static List<long> rep;
    static int[][] d;
    static int N;
    static void Main(string[] args){
       
        var HW = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
         var H = HW[0];
         var W = HW[1];
         N = 10;
         var ans = 0;
         d = new int[10][];
         
         for(int i = 0;i < N ;i++){
             d[i] = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
         }
         warshall_floyd();
         for(int i = 0;i < H ;i++){
             var tmp = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
             for(int j = 0;j < W ;j++){
                 if(tmp[j] != -1){
                     
                     ans += d[tmp[j]][1];
                 }
             }
         }
         
         Console.WriteLine(ans);
       　
    }
    
    static void warshall_floyd(){
        for(int k = 0;k < N;k++){
            for(int i = 0;i < N;i++){
                for(int j = 0;j < N;j++){
                    d[i][j] = Math.Min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
    }
    
    
}


Measured memory_bytes: 15444
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 100005;
const int inf = 0x3f3f3f3f;

int jo[maxn];

int n, k;

struct Edge
{
	int to, nxt;
} e[maxn << 1];

int first[maxn];

inline void add_edge(int from, int to)
{
	static int cnt = 0;
	e[++cnt].nxt = first[from];
	first[from] = cnt;
	e[cnt].to = to;
	e[++cnt].nxt = first[to];
	first[to] = cnt;
	e[cnt].to = from;
}

int ll[maxn], rr[maxn];
int fa[maxn];

inline void dfs(int now)
{
//	cout << "now = " << now << ' ' << ll[now] << ' ' << rr[now] << endl;
	for(int i = first[now]; i; i = e[i].nxt)
	{
		int to = e[i].to;
		if(to != fa[now])
		{
			if(~jo[to] && (jo[to] ^ (!jo[now])))
			{
				puts("No");
				exit(0);
			}
			jo[to] = !jo[now];
			fa[to] = now;
			ll[to] = max(ll[now] - 1, ll[to]);
			rr[to] = min(rr[now] + 1, rr[to]);
			dfs(to);
		}
	}
    ll[fa[now]] = max(ll[now] - 1, ll[fa[now]]);
    rr[fa[now]] = min(rr[now] + 1, rr[fa[now]]);
}

int anss[maxn];

inline void dfs2(int now)
{
//	cout << "dfs2 " << now << ' ' << ll[now] << ' ' << rr[now] << endl;
	ll[now] = max(anss[fa[now]] - 1, ll[now]);
	if(jo[now] ^ (ll[now] & 1))
	{
		ll[now]++;
		if(ll[now] > rr[now])
		{
			puts("No");
			exit(0);
		}
	}
	rr[now] = min(anss[fa[now]] + 1, rr[now]);
	anss[now] = ll[now];
	for(int i = first[now]; i; i = e[i].nxt)
	{
		int to = e[i].to;
//		cout << "to = " << to << ' ' << fa[now] << endl;
		if(to != fa[now])
			dfs2(to);
	}
}

int main()
{
	memset(rr, 0x3f, sizeof(rr));
	memset(jo, 0xff, sizeof(jo));
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		ll[i] = -inf;
	for(int i = 1, a, b; i < n; ++i)
	{
		scanf("%d%d", &a, &b);
		add_edge(a, b);
	}
	scanf("%d", &k);
	int tmp = 0;
	for(int i = 1, v, p; i <= k; ++i)
	{
		scanf("%d%d", &v, &p);
		ll[v] = max(p, ll[v]);
		rr[v] = min(p, rr[v]);
		jo[v] = p & 1;
		tmp = v;
	}
	if(!tmp)
	{
		jo[1] = 0;
		tmp = 1;
		dfs(1);
	}
	else
		dfs(tmp);
//	cout << endl;
//	for(int i = 1; i <= n; ++i)
//		cout << ll[i] << ' ' << rr[i] << ' ' << jo[i] << endl;
//	cout << endl;
	for(int i = 1; i <= n; ++i)
	{
		if(ll[i] > rr[i])
		{
			puts("No");
			return 0;
		}
	}
	dfs2(tmp);
	puts("Yes");
	for(int i = 1; i <= n; ++i)
		printf("%d\n", anss[i]);
	return 0;
}

Measured memory_bytes: 7296
import math
q=int(input())
cnt=0
Issame=True
remainder=1e10
sum=0
for j in range(q):
  a,b=[int(i) for i in input().split()]
  Issame=Issame if a==b else False 
  if a>b:
    remainder=min(remainder,b)
  sum+=a
if Issame:
  print(0)
else:
  print(sum-remainder)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int dp[10000000],cost[2000],weight[2000];
int main()
{
	int h,n;
	cin>>h>>n;
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	int MIN=INF,mx=0;
	for(int i=0;i<n;i++)
	{
		cin>>cost[i]>>weight[i];
		mx=max(mx,weight[i]);
	}
	for(int i=0;i<n;i++)
		for(int v=cost[i];v<=max(h+h+h+h,mx);v++)
	{
		dp[v]=min(dp[v],dp[v-cost[i]]+weight[i]);
		if(v>=h) 
		{
			MIN=min(dp[v],MIN);
		}
	}
	cout<<MIN<<endl;
}

Measured memory_bytes: 39296
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

bool mark[maxN];
ll ans = 0;
int par[maxN];
pair <ll, pii> E[maxN];

int getpar(int v){
	if (par[v] == v) return v;
	return par[v] = getpar(par[v]);
}

void join(int u, int v, ll w){
	v = getpar(v);
	u = getpar(u);
	if (u == v){
		if (mark[u]) return;
		mark[u] = true;
		ans += w;
		return;
	}
	if (mark[u] && mark[v]) return;
	par[u] = v;
	ans += w;
	mark[v] |= mark[u];
	return;	
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for (int i = 0; i < maxN; i++){
		par[i] = i;
	}
	int n; cin >> n;
	int h, w; cin >> h >> w;
	for (int i = 0; i < n; i++){
		ll r, c, w;
		cin >> r >> c >> w;
		c += h;
		E[i] = {w, {r, c}};
	}
	sort(E, E + n);
	reverse(E, E + n);
	for (int i = 0; i < n; i++){
		join(E[i].second.first, E[i].second.second, E[i].first);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4352
// यथा चतुर्भिः कनकं परीक्ष्यते निघर्षणच्छेदनतापताडनैः।
// तथा चतुर्भिः पुरुषः परीक्ष्यते त्यागेन शीलेन गुणेन कर्मणा॥
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv std::vector<int>
#define mapii std::map<int,int>
#define mpaci std::map<char,int>
#define umapii std::unordered_map<int,int>
#define umapci std::unordered_map<char,int>
#define seti std::set<int>
#define useti std::unordered_set<int>
#define qi std::queue<int>
#define qc std::queue<char>
#define sti std::stack<int>
#define stc std::stack<char>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end() 
#define printv(v) for(auto x: v){ cout<< x << " ";}
#define pi 3.14159265358979323846
#define setprc(x) setprecision(x)
void file(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
bool sortdesk(const pair<int,int> &a, const pair<int,int> &b){return a.ff>b.ff;}
bool sortdesv(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;}
bool sortascv(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasck(const pair<int,int> &a, const pair<int,int> &b){return a.ff<b.ff;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
int gcd(int a, int b){if (b == 0){return a;} return gcd(b, a % b);}
int cntdiv(int n){int cnt=0;for(int i=1;i<=sqrt(n);++i){if(n%i==0){if(n/i==i)++cnt;else{cnt = cnt + 2;}}}return cnt;}
lld posnegmod(lld a,lld b){//return (x%mod+mod)%mod;
long long int r = a % b;
    return r < 0 ? r + b : r;
}
// cout<<fixed<<setprecision(20)
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
// const int maxi = 1e6+10;
// vector<int> v[maxi];
// vector<long long> a(maxi,0);
// void dfs(int x){
//     if(a[x]){return;}
//     a[x]=1;
//     for(int i=0;i<v[x].size();++i){
//         dfs(v[x][i]);
//     }
// }

void test_case(){
    int n,k;
    cin>>n>>k;
    map<int,int> mp;
    for(int i=1;i<=n;++i){
        mp[i]=0;
    }
    for(int i=0;i<k;++i){
        int x;
        cin>>x;
        for(int j=0;j<x;++j){
            int y;
            cin>>y;
            mp[y]++;
        }
    }
    int cnt=0;
    for(auto x:mp){
        if(x.ss==0){
            ++cnt;
        }
    }
    cout<<cnt;
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
        test_case();
    }
}


Measured memory_bytes: 3580
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#include <math.h> 

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

int main()
{
	//あらかじめ計算
	int List[100000+1];
	List[1] = 0;
	for (int i = 3; i <= 100000; i+=2)
	{
		if (IsPrime(i) && IsPrime((i+1)/2))
		{
			List[i] = List[i-2]+1;
		}
		else
		{
			List[i] = List[i-2];
		}
	}

	int Q;
	cin >> Q;
	for (int n = 0; n < Q; n++)
	{
		int cnt = 0;
		int l, r;
		cin >> l >> r;
		if (l >= 3)
		{
			cnt = List[r] - List[l - 2];
		}
		else
		{
			cnt = List[r];
		}
		cout << cnt << endl;
	}
	return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	int n;
	int debt = 100000;
	int debtcpy;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		debt *= 1.05;
		
		debtcpy = debt;
		
		if (debtcpy % 1000 > 0) {
			debtcpy = debtcpy % 1000;
			
			debt = debt - debtcpy + 1000;
		}
	}
	
	printf("%d\n", debt);
	
	return (0);
}

Measured memory_bytes: 592
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Zero is
   X : Integer;
begin
   for I in 1 .. 5 loop
      Get (X);
      if X = 0 then
         Put_Line (Integer'Image (I));
      end if;
   end loop;
end Zero;

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
map<int, int>mp;
int ara[200005];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)scanf("%d", &ara[i]);
    long long res= 0;
    for(int i=n-1; i>=0; i--)
    {
        int x= i+1+ara[i];
        res+= mp[x];
        mp[(i+1-ara[i])]++;
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 21600
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>n;
    vl<pair<ll,ll>> v(n);
    for(i=0;i<n;i++) cin>>v[i].ff>>v[i].ss;
    for(i=0;i<n-3+1;i++)
    {
        if(v[i].ff==v[i].ss && v[i+1].ff==v[i+1].ss && v[i+2].ff==v[i+2].ss)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (x-r<0 || x+r>W || y-r<0 || y+r>H){
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3112
import sys

input = sys.stdin.readline
import math


def solve():
    a, b, x = (int(i) for i in input().split())
    L = a * a * b
    if L <= x:
        print(0)
    else:
        mi = 0
        ma = 89.999999999
        while ma - mi >= 10 ** (-9):
            next = (mi + ma) / 2
            bairitu = math.tan(math.radians(next))
            if x >= L / 2:
                lim = L - (a ** 3 / 2) * round(bairitu, 10)
            else:
                lim = (0.5) * a * b * b * math.tan(math.radians(90 - next))
            if x > lim:
                ma = next
            else:
                mi = next
        print(ma)


solve()


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
##################################
# University of Wisconsin-Madison
# Author: Yaqi Zhang
##################################

# standard library
import sys
from functools import lru_cache

sys.setrecursionlimit(10**9)

Input = lambda: sys.stdin.readline().rstrip()
IntRead = lambda: int(Input())
LineRead = lambda: list(map(int, Input().split()))


INF = 10**18

def main():
    t_h, t_a, a_h, a_a = LineRead()
    idx = 0
    while True:
        if idx % 2 == 0:
            a_h -= t_a
            if a_h <= 0:
                print("Yes")
                break
        else:
            t_h -= a_a
            if t_h <= 0:
                print("No")
                break
        idx += 1


if __name__ == "__main__":
    main()



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

#define ll long long
#define ull unsigned long long

using namespace std;

const int INF = 100100100;
using ituple = tuple<int,int,int>;

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

	int CH, CW, DH, DW;
	cin >> CH >> CW >> DH >> DW;
	CH--, CW--, DH--, DW--;

	vector <string> s(H, "");
	for (int ii = 0; ii < H; ++ii){
		cin >> s[ii];
	}

	priority_queue <ituple,vector<ituple>,greater<ituple>> q;	//値が小さい順に出てくる
	q.push(make_tuple(0, CH, CW));

	vector<vector<bool>> fix(H, vector <bool> (W, false));
	vector<vector<int>> weight(H, vector <int> (W, INF));

	int nx[4] = {1, -1, 0, 0};
	int ny[4] = {0, 0, 1, -1};
	while (!q.empty()) {
		int tw = get<0>(q.top());
		int ty = get<1>(q.top());
		int tx = get<2>(q.top());
		q.pop();

		if (fix[ty][tx]) continue;
		fix[ty][tx] = true;
		weight[ty][tx] = tw;

		//隣接マスへ移動
		for (int ii = 0; ii < 4; ++ii){
			int x = tx + nx[ii];
			int y = ty + ny[ii];
			if (x<0 || x>= W || y<0 || y>= H ){continue;}
			if (s[y][x] == '#'){continue;}
			if (weight[ty][tx] < weight[y][x]){
				q.push(make_tuple(weight[ty][tx], y, x));
			}
		}

		//ワープ
		for (int ii = -2; ii < 3; ++ii){
			for (int jj = -2; jj < 3; ++jj){
				if (ii==0 && jj==0){continue;}
				if (ii==0 && (jj==1 || jj==-1) ){continue;}
				if (jj==0 && (ii==1 || ii==-1) ){continue;}
				int x = tx + ii;
				int y = ty + jj;
				if (x<0 || x>= W || y<0 || y>= H ){continue;}
				if (s[y][x] == '#'){continue;}
				if (weight[ty][tx] + 1 < weight[y][x]){
					q.push(make_tuple(weight[ty][tx]+1, y, x));
				}
			}
		}
	}

	if (weight[DH][DW] == INF){
		cout << -1 << "\n";
	} else {
		cout << weight[DH][DW] << "\n";
	}

	return 0;
}


Measured memory_bytes: 10224
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

constexpr int inf = 1e9;
template<class T> struct edge { int to; T cap; int rev; edge(int t, T c, int r) : to(t), cap(c), rev(r) {} };

void add_edge(int from, int to, auto cap, auto& g) {
  g[from].emplace_back(to, cap, g[to].size());
  g[to].emplace_back(from, 0, g[from].size() - 1);
}

template<class T> T dinic(int s, int t, VV< edge<T> > g) {
  int n = g.size();
  V<> dist, i;

  auto bfs = [&]() {
    dist.assign(n, -1);
    queue<int> q;
    dist[s] = 0; q.push(s);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for (auto&& e : g[v]) if (dist[e.to] == -1 and e.cap > 0) {
        dist[e.to] = dist[v] + 1; q.push(e.to);
      }
    }
  };

  function<T(int, T)> dfs = [&](int v, T f) {
    if (v == s) return f;
    for (; i[v] < g[v].size(); i[v]++) {
      edge<T>& e = g[v][i[v]];
      if (dist[e.to] < dist[v] and g[e.to][e.rev].cap > 0) {
        T d = dfs(e.to, min(f, g[e.to][e.rev].cap));
        if (d > 0) {
          g[e.to][e.rev].cap -= d;
          e.cap += d;
          return d;
        }
      }
    }
    return (T) 0;
  };

  T res = 0;
  while (true) {
    bfs();
    if (dist[t] == -1) return res;
    i.assign(n, 0);
    while (true) {
      T f = dfs(t, inf);
      if (f == 0) break;
      res += f; 
    }
  }
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  V<string> a(h); for (int i = 0; i < h; i++) cin >> a[i];
  int s, t;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    if (a[i][j] == 'S') s = 2 * (i * w + j) + 1;
    if (a[i][j] == 'T') t = 2 * (i * w + j);
  }
  VV< edge<int> > g(2 * h * w);
  for (int i = 0; i < h; i++) {
    for (int jl = 0; jl < w; jl++) for (int jr = 0; jr < w; jr++) {
      if (jl != jr and a[i][jl] != '.' and a[i][jr] != '.') add_edge(2 * (i * w + jl) + 1, 2 * (i * w + jr), inf, g);
    }
  }
  for (int j = 0; j < w; j++) {
    for (int il = 0; il < h; il++) for (int ir = 0; ir < h; ir++) {
      if (il != ir and a[il][j] != '.' and a[ir][j] != '.') add_edge(2 * (il * w + j) + 1, 2 * (ir * w + j), inf, g);
    }
  }
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) add_edge(2 * (i * w + j), 2 * (i * w + j) + 1, 1, g);
  int res = dinic<int>(s, t, g);
  cout << (res >= inf ? -1 : res) << '\n';
}

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

int main()
{
    int a,b,c;
    map<int,int> m;
    m[5]=0;
    m[7]=0;
    cin>>a>>b>>c;
    m[a]++;
    m[b]++;
    m[c]++;
    
    if(m[5]==2 && m[7]==1)
        cout<<"YES";
    else
        cout<<"NO";
    
    
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import combinations


def solve(N: int, K: int):
    if K > (N-2) * (N - 1) // 2:
        print(-1)
        return
    print(N * (N-1) // 2 - K)
    count = 0
    for u, v in combinations(range(1, N+1), 2):
        if u == 1:
            print(u, v)
            continue
        if count < K:
            count += 1
            continue
        print(u, v)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 44400
import sys

sys.setrecursionlimit(10**9)

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

def dfs(num):
    visited[num]=1
    for item in way[num]:
        if visited[item]==0:
            dfs(item)
    return 

mem=[-1]*M
way=[[] for i in range(N)]
visited=[0]*N
for n in range(N):
    temp=list(map(int,input().split()))
    
    for i in range(temp[0]):
        if mem[temp[i+1]-1]==-1:
            mem[temp[i+1]-1]=n
        else:
            way[mem[temp[i+1]-1]].append(n)
            way[n].append(mem[temp[i+1]-1])

for i in range(N):
    way[i]=list(set(way[i]))

dfs(0)

if visited.count(0)==0:
    print("YES")
else:
    print("NO")




    

Measured memory_bytes: 32760
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn dfs(
    cur: usize,
    parent: usize,
    a: &Vec<i64>,
    graph: &Vec<Vec<usize>>,
    dp: &mut Vec<i64>,
    answers: &mut Vec<usize>,
) {
    let pointer = dp.lower_bound(&a[cur]);
    let prev = dp[pointer];
    dp[pointer] = a[cur];
    answers[cur] = dp.lower_bound(&std::i64::MAX);
    for &to in graph[cur].iter() {
        if to == parent {
            continue;
        }
        dfs(to, cur, a, graph, dp, answers);
    }
    dp[pointer] = prev;
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let mut graph = vec![vec![]; n];
    for i in 0..n - 1 {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut dp = vec![std::i64::MAX; n + 1];
    let mut answers = vec![std::usize::MAX; n];
    dfs(0, 0, &a, &graph, &mut dp, &mut answers);
    for ans in answers {
        println!("{}", ans);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}


Measured memory_bytes: 34724
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,f[105][15]={},p[105][15]={},cnt,ans=-inf,m;
  cin >> n;
  for(int i=0; i<n; i++) {
    for(int j=0; j<10; j++) {
      cin >> f[i][j];
    }
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<11; j++) {
      cin >> p[i][j];
    }
  }
  for(int i=1; i<(1<<10); i++) {
    m=0;
    for(int j=0; j<n; j++) {
      cnt=0;
      for(int k=0; k<10; k++) {
        if(f[j][k]&&i&(1<<k)) {
          cnt++;
        }
      }
      m+=p[j][cnt];
    }
    ans=max(ans,m);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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


int main() {
	
	string S;
	ll w;
	cin >> S >> w;

	for (ll i = 0; i < S.size(); i += w) {
		cout << S[i];
	}


	system("PAUSE");
}


Measured memory_bytes: 504
<?php

    $s = trim(fgets(STDIN));
    $d['N'] = -1;
    $d['S'] = -1;
    $d['W'] = -1;
    $d['E'] = -1;
    $c = 0;
    while($c<strlen($s)){
        $d[$s[$c]] = 1;
        $c++;
    }
    if($d['N']*$d['S'] == 1){
        if($d['W']*$d['E'] == 1) echo "Yes";
        else echo "No";
    } else echo "No";

?>


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

bool ispal(int x)
{
    string s;
    while (x > 0)
    {
        int y = x % 10;
        s.push_back((char)(y + '0'));
        x /= 10;
    }
    string t = s;
    reverse(all(t));
    return s == t;
}

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

#define MAX 100000
    int cnt[MAX] = {};
    Rep(i, 1, MAX)
    {
        cnt[i] = cnt[i - 1];
        if (ispal(i))
            cnt[i]++;
    }
    int a, b;
    cin >> a >> b;
    cout << cnt[b] - cnt[a - 1] << endl;
}

Measured memory_bytes: 1024
// Copyright 2015 KanatoNagayama
#include <iostream>
using std :: cout;
using std :: cin;
using std :: endl;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a < b && b < c) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() { // 4 2 0 1 3  5 3 1 0 2 4
  int n;
  cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  vi b;
  int cnt=n-1;
  if(cnt%2==0){
    while(cnt>=0){
      b.pb(a[cnt]);
      cnt-=2;
    }
    cnt=1;
    while(cnt<=n-2){
      b.pb(a[cnt]);
      cnt+=2;
    }
  }else{
    while(cnt>=0){
      b.pb(a[cnt]);
      cnt-=2;
    }
    cnt=0;
    while(cnt<=n-2){
      b.pb(a[cnt]);
      cnt+=2;
    }
  }
  rep(i,n){
    cout<<b[i]<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 5012
#include <iostream>                                                             
#include <string>                                                               
                                                                                
using namespace std;                                                            
                                                                                
int main(void) {                                                                
  typedef long long ll;                                                         
  ll n, n2;                                                                     
  int s(0);                                                                     
  cin >> n;                                                                     
  n2 = n;                                                                       
  while(n > 0){                                                                 
    s += n % 10;                                                                
    n /= 10;                                                                    
  }                                                                             
  if(n2 % s == 0)cout << "Yes";                                                 
  else cout << "No";                                                            
                                                                                
  return 0;                                                                     
}    

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    bool flag = true;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < n-1; i++){
        if(a[i] == a[i+1]) flag = false;
    }
    if(flag == true) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
using namespace std;

const ll MAX = 2010010;
const ll mod = 1000000007;
vector<ll> fac(MAX), finv(MAX), inv(MAX);
bool init_called = false;
//=============modinv============================
void COMinit() {
  init_called = true;
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (ll i = 2; i < MAX; i++){
    fac.at(i) = fac.at(i - 1) * i % mod;
    inv.at(i) = mod - inv.at(mod % i) * (mod / i) % mod;
    finv.at(i) = finv.at(i - 1) * inv.at(i) % mod;
  }
}

ll COM(ll n, ll k){
  if (!init_called) {
    COMinit();
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n - k) % mod) % mod;
}
//=================================================


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  if ((r1 == r2) && (c1 == c2)) {
    cout << COM(r1 + c1, r1) << "\n";
    return 0;
  }
  ll ans = (COM(r1 + c1, r1) + COM(r2 + c2, r2)) % mod;
  if ((r1 != r2) && (c1 != c2)) {
    ans = (ans + COM(r2 + c2, r2)) % mod;
  }
  for (ll i = r1 + 1; i < r2; ++i) {
    ans = (ans + COM(i + c2, c2)) % mod;
  }
  for (ll i = c1 + 1; i < c2; ++i) {
    ans = (ans + COM(r2 + i, r2)) % mod;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 50328
#include <iostream>
#include <cstdlib>
using namespace std;
const static int SEQ_LEN_MAX = 100;

int main() {
  while( 1 ) {
    int n, seq[ SEQ_LEN_MAX ];
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }
    for( int i = 0; i < n; i++ ) {
      cin >> seq[ i ];
    }
    int counter = 0;
    for( int i = 0; i < n; i++ ) {
      for( int j = 0; j < n - i - 1; j++ ) {
        if( seq[ j ] > seq[ j + 1 ] ) {
          int k = seq[ j + 1 ];
          seq[ j + 1 ] = seq[ j ];
          seq[ j ] = k;
          counter++;
        }
      }
    }
    cout << counter << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

llint gcd(llint m, llint n)
{
    if (n == 0) return m;
    return gcd(n, m%n);
}

llint lcm( llint m, llint n )
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}


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

    int N;
    cin >> N;
    llint t;
    cin >> t;
    REP(i, N-1){
        llint x;
        cin >> x;
        t = lcm(t, x);
    }

    cout << t << "\n";
    return 0;
}


Measured memory_bytes: 256
S = input()
mod = 10**9 + 7
N = len(S)
cA = 0
cAB = 0
cABC = 0
all = 1
for i in range(N):
    if S[i] == 'A':
        cA += all
    elif S[i] == 'B':
        cAB += cA
    elif S[i] == 'C':
        cABC += cAB
    else:
        cABC *= 3
        cABC += cAB
        cAB *= 3
        cAB += cA
        cA *= 3
        cA += all
        all *= 3
    cABC %= mod
    cAB %= mod
    cA %= mod
    all %= mod
print(cABC)


Measured memory_bytes: 3188
n=int(input())
li=list(map(int,input().split()))
le=int(n*(n-1)/2)
a=0
b=[]
c=[]
def three(n):
  return n*li[i]
for i in range(le):
  a=li[i+1:]
  c=list(map(three,a))
  b.append(c)
    
print(sum(sum(b,[])))

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

int main() {
  int A,B,ans=-1,a1=0,a2=0,b1=0,b2=0;
  cin >> A >> B;
  
  a1 = ceil(A/0.08);
  a2 = (A+1)/0.08;
  b1 = ceil(B/0.1);
  b2 = (B+1)/0.1;
  if(a1<b1 && a2>b1) ans = b1;
  else if(a1>=b1 && a1<b2) ans = a1;
  //cout << a1 << a2 << b1 << b2 << endl;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int res=0;
	for(int i=0;i<n;i++){
		int val;
		cin>>val;
		while(val%2==0){
			val/=2;
			res++;
		}
	}
	cout<<res;
}

Measured memory_bytes: 256
import bisect

N, Q = [int(x) for x in input().split()]
S = input()
lr = []
for i in range(Q):
    lr.append([int(x)-1 for x in input().split()])

aclist = []
target = "AC"
index = -1
while True:
    index = S.find(target, index + 1)
    if index == -1:
        break
    aclist.append(index)

for [l, r] in lr:
    min_ac = bisect.bisect_left(aclist, l)
    max_ac = bisect.bisect_right(aclist, r-1)
    print(max_ac - min_ac)


Measured memory_bytes: 24032
package main

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

func main() {
	N := readInt()
	K := readInt()

	c := make([][]int, 2000+1)
	for i := 0; i < 2000+1; i++ {
		c[i] = make([]int, 2000+1)
	}
	c[0][0] = 1
	for i := 0; i < 2000+1; i++ {
		c[i][0] = 1
		for j := 1; j < i+1; j++ {
			c[i][j] = (c[i-1][j-1] + c[i-1][j]) % 1000000007
		}
	}

	f := func(n, k int) int {
		return c[n+k-1][k-1]
	}

	for i := 1; i <= K; i++ {
		fmt.Println(f(K-i, i) * f(N-K-(i-1), i+1) % 1000000007)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N; cin >> N;
	vector<pair<ll, ll>> xy;
	REP(i, N)
	{
		ll a, b; cin >> a >> b;
		xy.push_back(P{a, b});
	}

	// z = x + y;
	// w = x - y;
	ll zma, zmi, wma, wmi; 
	zma = wma = -INF;
	zmi = wmi = INF;
	
	REP(i, N)
	{
		zma = max(zma, xy[i].first + xy[i].second);
		zmi = min(zmi, xy[i].first + xy[i].second);

		wma = max(wma, xy[i].first - xy[i].second);
		wmi = min(wmi, xy[i].first - xy[i].second);
	}

	std::cout << max(zma - zmi, wma - wmi) << std::endl;
}


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

int main(){
  double r; cin >> r;
  double area = r * r * 3.14159265359;
  double length = 2 * r * 3.14159265359;
  cout << fixed << setprecision(6) << area << " " << length << endl;

  return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<queue>
#define INF 0x3f3f3f3f
#define MOD 1000000000+7
#define N 550
#define PI 3.1415927
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        long long fact=1;
        for(int i=1;i<=n;i++)
        {
            fact=fact*i;
            fact%=MOD;
        }
        fact%=MOD;
        cout<<fact<<endl;
    }
    return 0;
}


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

typedef long long ll;

int solve(ll k,ll arr[],ll n,vector<vector<int> > &dp,int mark){
	if(k<0)
		return 1;
	if(k==0)
		return 0;
	if(dp[k][mark]!=-1)
		return dp[k][mark];
	//cout<<k<<" "<<mark<<" "<<dp[k][mark]<<endl;
	for(ll i=0;i<n;i++){

		if(k-arr[i]>=0 && solve(k-arr[i],arr,n,dp,1-mark)==0){
			dp[k][mark]=1;
			return dp[k][mark];
		}
		
		
	}
	dp[k][mark]=0;
	return dp[k][mark];
}

int main(){
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	vector<vector<int> > dp(k+1,vector<int> (2,-1));
	
	if(solve(k,arr,n,dp,1)==1){
		cout<<"First"<<endl;
	}
	else{
		cout<<"Second"<<endl;
	}
	
}

Measured memory_bytes: 17980
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N=3e5+10;
 
 
int main(){
    //freopen("a.txt", "r", stdin);
    //freopen("answers.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++)
                ans+=(i*500+j*100+k*50==x);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
int par(int x){
    if(x%2) return -1;
    else return 1;
}
ll dp[3001][3001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    ll a[N];
    rep(i,0,N) cin>>a[i];
    int s;
    s=par(N);
    rep(k,1,N+1){
        rep(i,0,N-k+1){
            if(s*par(k)==1){
                dp[i][i+k]=max(a[i]+dp[i+1][i+k],a[i+k-1]+dp[i][i+k-1]);
            }
            else{
                dp[i][i+k]=min(-a[i]+dp[i+1][i+k],-a[i+k-1]+dp[i][i+k-1]);
            }
        }
    }
    cout <<dp[0][N]<<"\n";
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    double N,K;
    cin>>N>>K;
    vi A(N);
    rep(i,N) cin>>A[i];
    if(N<K) {
        cout<<1<<endl;
        return 0;
    }
    cout<<ceil((N-1)/(K-1))<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	int n;
	cin >> n;
	vector<int> a(n+2, 0), a_max(n+2, 0);
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	
	for(int i=1; i<=n; i++){
		if(a[i]!=0) continue;
		for(int d=-1; d<2; d+=2){
			int shut=inf;
			int dist=0;
			for(int j=i+d; a[j]!=0; j+=d){
				dist++;
				if(a[j]<0 && -a[j]<=shut-dist){
					shut = -a[j];
					dist = 0;
				}
				if(a[j]>0){
					a_max[j] = max(a_max[j], min(a[j], shut-dist));
				}
			}
		}
	}
	int ans = 0;
	for(int i=1; i<=n; i++){
		ans += a_max[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


const ll limit = 100010;
struct edge{
    ll to;
    ll cost;
};

vector<edge> tree[limit];
ll depth[limit];


void dfs(ll v,ll p,ll d){
    depth[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p) continue;
        dfs(e.to,v,d+e.cost);
    }
}


int main(){
    FIN;
    ll n; cin >> n;
    //vector<vector<ll>> c(n,vector<ll>(n,0));
    //Graph G(n);
    for(ll i=0;i<n-1;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }

    ll q,k;
    cin >> q >> k;
    k--;

    dfs(k,-1,0);

    for(ll i=0;i<q;i++){
        ll x,y;
        cin >> x >> y;
        x--; y--;
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 16040
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin>>N;
  vpll C;
  ll a,b;
  REP(i,N){
    cin>>a>>b;
    C.push_back(make_pair(b,a));
  }
  sort(ALL(C));
  bool ans = true;
  ll time=0;
  REP(i,N){
    time+=C[i].second;
    if(time>C[i].first)ans=false;
  }
  if(ans)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

int main()
{
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  queue<char> path;
  for(int i=0; i < ty-sy; i++)
    path.push('U');
  for(int i=0; i < tx-sx; i++)
    path.push('R');
  for(int i=0; i < ty-sy; i++)
    path.push('D');
  for(int i=0; i < tx-sx; i++)
    path.push('L');
  path.push('L');
  for(int i=0; i < ty-sy+1; i++)
    path.push('U');
  for(int i=0; i < tx-sx+1; i++)
    path.push('R');
  path.push('D');
  path.push('R');
  for(int i=0; i < ty-sy+1; i++)
    path.push('D');
  for(int i=0; i < tx-sx+1; i++)
    path.push('L');
  path.push('U');
  while(path.size() > 0){
    cout << path.front();
    path.pop();
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
    IOS;
    string s;
    cin >> s;
    if(s[2] == s[3] && s[5] == s[4])
    cout <<"Yes";
    else
    cout << "No";   
    return 0;
}

Measured memory_bytes: 256
import sys

w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
    lines = sys.stdin.readline().rstrip()
    if not lines:
		break	
    words = lines.split( " " )
    for i in range( len( words ) ):
    	if w == words[i].lower():
			cnt = cnt + 1	

print( cnt )

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

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

void doit(){	
	ll n;
	cin >> n;
	cout << ((n + 1) / 2) * (n/2) << nl;	
}

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


Measured memory_bytes: 3596