akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}


int n, m;
vi a;

int main() {
  scanf("%d", &n);
  m = (1 << n);
  a.assign(m+1, 0);
  rep(i, m) {
    scanf("%d", &a[i]);
  }
  a[m] = 0;

  vvi bt(m, vi(2, m));
  rep (i, m) {
    bt[i][0] = i;
  }
  FOR (i, 1, m) {
    vi tmp;
    tmp.insert(tmp.end(), all(bt[i]));
    rep (j, n) {
      int tt = (1 << j);
      if ((i & tt) == 0) { continue; }
      tmp.insert(tmp.end(), all(bt[i-tt]));
    }
    sort(all(tmp), [](auto x, auto y) {
        return a[x] > a[y];
        });
    unique(all(tmp));
    bt[i][0] = tmp[0];
    bt[i][1] = tmp[1];
  }
  vi ans(m, 0);
  FOR (i, 1, m) {
    ans[i] = a[bt[i][0]] + a[bt[i][1]];
    ans[i] = max(ans[i], ans[i-1]);
    printf("%d\n", ans[i]);
  }

  return 0;
}


Measured memory_bytes: 19456
path_list = [0, 0, 0, 0]
count = 0
for _ in range(3):
    a, b = map(int, input().split())
    path_list[a-1] += 1
    path_list[b-1] += 1

for path in path_list:
    if path >= 3:
        count += 1
if count == 1:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   string s;
   cin >> s;
   int ans = 0;
   for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') ans++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<sstream>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

long long dp[110][100010];
int main() {
	int n, W;
	cin >> n >> W;
	long long *w = new ll[n];
	long long *v = new ll[n];
	for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
	for (int i = 0; i < n + 1; i++) {
		for (int j = 0; j < 100010; j++) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 100010; j++) {
			if (j - v[i] <= 0) {
				chmin(dp[i + 1][j], dp[i][0] + w[i]);
			}
			else {
				chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
			}
			chmin(dp[i + 1][j], dp[i][j]);		
		}
	}
	int max = 0;
	for (int i = 100009; i >=0; i--) {
		if (dp[n][i] <= W) {
			max = i;
			break;
		}
	}
	cout << max;
	return 0;
}


Measured memory_bytes: 80128
#include <iostream>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n,ans = 0; cin>>n;
	ans += (n/500)*1000;	
	n = n%500;
	ans += (n/5)*5;
	cout<<ans;
}

Measured memory_bytes: 256
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))


Measured memory_bytes: 147216
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define fr(i,x,n) for(int i=x;i<=n;i++)
#define rf(i,n,x) for(int i=n;i>=x;i--)
#define mst(x,i) memset(x,i,sizeof(x))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define PB push_back
#define X first
#define Y second
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=1E5+5;
const int maxm=1E5+5;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const LL mod=1E9+7;
const double eps=1E-6;
const double PI=acos(-1.0);
LL dp[maxn][5],h[5][maxn];
void solve(){
    int n;
    cin>>n;
    rep1(i,n){
        rep(j,3) cin>>h[j][i];
    }
    rep1(i,n){
        rep(j,3){
            rep(k,3) if(j!=k) dp[i][j]=max(dp[i][j],dp[i-1][k]+h[j][i]);
        }
    }
    LL ans=0;
    rep(i,3) ans=max(ans,dp[n][i]);
    cout<<ans<<"\n";
}
int main(){
    IOS;
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 9856
n,a,b=map(int,input().split())
if a==0:
  print(0)
elif b==0:
  print(n)
else:
  q=n//(a+b)
  r=n%(a+b)
  if r<=a:
    print(int(q*a+r))
  else:
    print(int((q+1)*a))
  

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int calc_d0(int n) {
    return n/10000;
}
int calc_d1(int n) {
    return (n/1000)%10;
}
int calc_d3(int n) {
    return (n/10)%10;
}
int calc_d4(int n) {
    return n%10;
}
int check_palindrome(int n) {
    if((calc_d0(n)==calc_d4(n))&&(calc_d1(n)==calc_d3(n))) return 1;
    else return 0;
}


int main() {
    int A, B;
    cin >> A >> B;

    int i, ans=0;
    for(i=A; i<=B; i++) {
        if(check_palindrome(i)) ans+=1;
    }

    cout << ans << endl;


    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n;
ll b[100];
char a[100];
void dg(ll j){
	ll i;
	if(j==n){
		for(i=0;i<n;i++)
			cout<<a[i];
		cout<<endl;
		return;
	}
	for(i=0;i<=j;i++){
		a[j]='a'+i;
		if(j)
			b[j]=b[j-1];
		if(b[j]<i)
			b[j]=i;
		if(j)
			if(a[j]-'a'-b[j-1]>1)
				continue;
		dg(j+1);
	}
}
int main(){
	cin>>n;
	ll i,j;
	for(i=0;i<n;i++){
		a[i]='a';
		b[i]=0;
	}
	dg(0);
}



Measured memory_bytes: 1536
/*

  ______      _                _____ 
  |  ____/\   | |        /\    / ____|
  | |__ /  \  | |       /  \  | (___  
  |  __/ /\ \ | |      / /\ \  \___ \
  | | / ____ \| |____ / ____ \ ____) |
  |_|/_/    \_\______/_/    \_\_____/ 
                                            
                                            

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

#define ll long long
#define INF 1000000
#define MOD 1000000007

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;

#define F first
#define S second

#define mp make_pair
#define endl '\n'
#define priority_queue pq

int a[33];
int main(){
    string s;
    cin>>s;
    for(int i=0;i<4;i++) a[s[i]-'A']++;
    for(int i=0;i<26;i++){
        for(int j=0;j<26;j++){
            if(i==j) continue;
            if(a[i]==2 && a[j]==2){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";

}



Measured memory_bytes: 256
#include <cstdio>

int main(void) {
    int n, u, k, v, i, j;
    scanf("%d", &n);
    int m[n+1][n+1];

    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
            m[i][j] = 0;

    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            m[u][v] = 1;
        }
    }

    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
            if (j-1) printf(" ");
            printf("%d", m[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[5];
  for(int i=0;i<5;i++)
  {
    cin >> a[i];
  }
  for(int i=0;i<5;i++)
  {
    if(a[i]==0)
    {
      cout<< i+1<< endl;
    }
  }
  return 0;
}
  

Measured memory_bytes: 3536
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  numA = scanner.nextInt();//要素数
		int arrayA[] = new int[numA];
		
		for(int i = 0; i < numA; i ++ ){
			arrayA[i] = scanner.nextInt();
		}
		
		int  numM = scanner.nextInt();//要素数
		int arrayM[] = new int[numM];
		
		for(int i = 0; i < numM; i ++ ){
			arrayM[i] = scanner.nextInt();
		}
		
		Recursive(numA, arrayA, numM, arrayM);
		
		scanner.close();
	}
	
	public static void Recursive(int numA, int[] arrayA, int numM, int[] arrayM){ 
		
		for(int cou = 0; cou < numM; cou ++ ){
			if ( Recursive(numA, arrayA, 0, arrayM[cou]) ){
				System.out.println("yes");
			}else{
				System.out.println("no");
			}
		}
		
	}
	
	public static boolean Recursive(int numA, int[] arrayA, int i, int m){ 
		if( m == 0){
			return true;
		}
		
		if (i >= numA){
			return false;
		}
		
		return ( Recursive(numA,arrayA, i + 1, m)|| 
				Recursive(numA,arrayA,i + 1, m - arrayA[i]) );		//再帰
	
	}
}


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

int main()
{
    string s;
    cin >> s;
    s.at(5) = ' ';
    s.at(13) = ' ';
    cout << s << endl;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int A, B;
  cin >> A >> B;
  cout << A * B - A - B + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int a, b, r, tmp;
int gcd(int a,int b){
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
int main(){
    int n,A[200000];
    cin>>n;
    rep(i,n) cin>>A[i];
    int a=A[0];
    rep(i,n) a=gcd(A[i],a);
    cout<<a;
}

Measured memory_bytes: 640
while True:
  h,w = map(int,input().split())
  if (h,w) == (0,0):
    break
  l = []
  for i in range(h):
    l.append(input())
  x,y = 0,0
  l1 = []
  while True:
    if (x,y) in l1:
      print('LOOP')
      break
    l1.append((x,y))
    pos = l[y][x]
    if pos == '.':
      print(x,y)
      break
    elif pos == '<':
      x -= 1
    elif pos == '>':
      x += 1
    elif pos == '^':
      y -= 1
    elif pos == 'v':
      y += 1

Measured memory_bytes: 7696
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{int from,to,cost;};
vector<edge> es(100); //辺の集合
vector<int> d(100,INFi);//最短距離
int V,E;//頂点数、辺数

int main(){
    int n;cin>>n;
    int s=0;
  int d=n;
    while(d>0){
        s+=d%10;
        d/=10;
    }
    if(n%s==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = input()
a = []
for i in range(n):
	a.append(raw_input())
for i in range(1, n):
	if a[i - 1][-1] != a[i][0]:
		print 'No'
		exit()
if len(set(a)) != n:
	print 'No'
	exit()
print 'Yes'

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

int main() {
  
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  
  sort(A.begin(),A.end());
  
  int ans;
  if(A[0]==A[2]) ans = 1;
  else if(A[0]==A[1] || A[1]==A[2]) ans = 2;
  else ans = 3;
  
  cout << ans << endl;
}
  
  
  

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long,long long>> vec;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    vec.emplace_back(a, b);
  }
  sort(vec.begin(), vec.end());
  long long sum = 0;
  int remain = m;
  for (int i = 0; i < n; i++) {
    auto p = vec.at(i);
    if (p.second >= remain) {
      sum += remain * p.first;
      cout << sum << endl;
      return 0;
    }
    remain -= p.second;
    sum += p.second * p.first;
  }
}


Measured memory_bytes: 2420
fn main() {
    let x: i32 = read();
    println!("{}", solve(x));
}

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

fn solve(x: i32) -> String {
    String::from(if x < 30 { "No" } else { "Yes" })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_solve_1() {
        assert_eq!("No", solve(25))
    }

    #[test]
    fn test_solve_2() {
        assert_eq!("Yes", solve(30))
    }
}


Measured memory_bytes: 2160
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	string a, b;
	while(cin >> a >> b)
	{
		int lena = a.size();
		int lenb = b.size();
		if(lena < lenb)
			cout<<"LESS"<<endl;
		if(lena > lenb)
			cout<<"GREATER"<<endl;
		if(lena == lenb)
		{
			if(a > b)
			{
				cout<<"GREATER"<<endl;
			}
			if(a < b)
			{
				cout<<"LESS"<<endl;
			}
			if(a == b)
			{
				cout<<"EQUAL"<<endl;
			}			
		}
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = list(str(input()))

s = s[::-1]
n = len(s)
#print(s)

ans = "YES"
i = 0
while i < n:
    #print(s[i:i+6])
    if i + 7 <= n and s[i:i+7] ==  ['r', 'e', 'm', 'a', 'e', 'r', 'd']:
        i += 7
    elif i + 6 <= n and s[i:i+6] == ['r', 'e', 's', 'a', 'r', 'e']:
        i += 6
    elif i + 5 <= n and s[i:i+5] == ['m', 'a', 'e', 'r', 'd']:
        i += 5
    elif i + 5 <= n and s[i:i+5] == ['e', 's', 'a', 'r', 'e']:
        i += 5
    else:
        ans = "NO"
        #print('c', i)
        break
print(ans)


Measured memory_bytes: 4652
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  ll n;
  cin>>n;
  vstr s(n);
  vvll t(n,vll(26));
  rep(i,n){
    cin>>s[i];
    sort(all(s[i]));
    rep(j,s[i].size()){
      t[i][s[i][j]-'a']++;
    }
  }
  vll a(26,100);
  rep(i,n){
    rep(j,26){
      a[j]=min(t[i][j],a[j]);
    }
  }
  vector<char> g(0);
  rep(i,26){
    ll h=a[i];
    rep(j,h){
      g.pb((char)('a'+i));
    }
  }
  rep(i,g.size()){
    cout<<g[i];
  }
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {
  def evaluate(x:Double,y:Double) = {
                if(x<35.5 && y < 71.0) "AAA"
    else if(x<37.5 && y<77.0) "AA"
    else if(x<40.0 && y<83.0) "A"
    else if(x<43.0 && y<89.0) "B"
    else if(x<50.0 && y<105.0) "C"
    else if(x<55.0 && y<116.0) "D"
    else if(x<70.0 && y<148.0) "E"
    else "NA"
  }

  Iterator.continually(readLine).takeWhile(_!=null).map( _.split(" ").map(_.toDouble) ).foreach { n =>
        println(evaluate(n(0),n(1)))
  }
}

Measured memory_bytes: 43684
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

const int MAXN = 200000 + 10;

int N, M;
int A[MAXN];
int Fa[MAXN];
multiset <int> Set[MAXN];
multiset < pair < pair <int, int>, int> > GS;

int GetRoot(int i)
{
	return (Fa[i] == i) ? i : (Fa[i] = GetRoot(Fa[i]));
}

void Work()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i ++)
	{
		scanf("%d", &A[i]);
		Fa[i] = i;
	}
	for (int i = 0; i < M; i ++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		if (GetRoot(a) != GetRoot(b))
			Fa[GetRoot(a)] = GetRoot(b);
	}
	for (int i = 0; i < N; i ++)
	{
		Fa[i] = GetRoot(i);
		Set[Fa[i]].insert(A[i]);
	}
	for (int i = 0; i < N; i ++)
		if (! Set[i].empty())
			GS.insert(make_pair(make_pair(-Set[i].size(), *Set[i].begin()), i));

	long long Cost = 0;
	while (GS.size() >= 2)
	{
		int a, b;
		vector <int> V;
		for (auto it: GS) { V.push_back(it.second); if (V.size() == 2) break; }
		a = V[0];
		b = V[1];
		a = GetRoot(a);
		b = GetRoot(b);
		GS.erase(make_pair(make_pair(-Set[a].size(), *Set[a].begin()), a));
		GS.erase(make_pair(make_pair(-Set[b].size(), *Set[b].begin()), b));
		if (Set[a].size() > Set[b].size())
			swap(a, b);
		Cost += (long long) (*Set[a].begin() + *Set[b].begin());
		Set[a].erase(Set[a].begin());
		Set[b].erase(Set[b].begin());
		for (auto it: Set[a]) Set[b].insert(it);
		Set[a].clear();
		if (Set[b].size() > 0) GS.insert(make_pair(make_pair(-Set[b].size(), *Set[b].begin()), b));
		Fa[a] = b;
	}

	int FF = GetRoot(0);
	for (int i = 0; i < N; i ++)
		if (GetRoot(i) != FF)
		{
			printf("Impossible\n");
			return;
		}
	printf("%lld\n", Cost);
}

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

Measured memory_bytes: 21760
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a=1;
    for(int i=0;i<n;i++){
		if(a<k){
			a*=2;
		}
		else{
			a+=k;
		}
	}
	cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
//char a[55][55];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};
ll a[100];
int main()
{
	dhoom;
	int n , k;
	cin >> n >> k;
	set< int > st;
	map< int , int > mp;
	for(int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		st.insert(x);
		mp[x]++;
	}
	int sz = st.size();
	if(sz <= k)
		cout << 0 << endl;
	else{
		vector< int > v;
		for(auto it : mp){
			v.push_back(it.second);
		}
		sort(v.begin() , v.end());
		int need = sz - k;
		int ans = 0;
		for(int i = 0 ; i < need ; i++)
			ans += v[i];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 20216
import sys
import bisect

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
alphabet = [chr(i) for i in range(97, 97 + 26)]


def resolve():
    S = input()
    T = input()

    n = len(S)
    m = len(T)

    idx = [[] for _ in range(26)]
    for i in range(n):
        idx[alphabet.index(S[i])].append(i)

    for i in range(n):
        idx[alphabet.index(S[i])].append(i + n)

    res = 0
    pos = 0
    for i in range(m):
        c = alphabet.index(T[i])
        if len(idx[c]) == 0:
            print(-1)
            break
        pos = idx[c][bisect.bisect_left(idx[c], pos)] + 1
        if pos >= n:
            pos -= n
            res += n
    else:
        res += pos
        print(res)


if __name__ == '__main__':
    resolve()


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

using namespace std;

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



int main(){

  int a,b,f;
  cin >> a >> b;
  if(a>8 || b>8) cout << ":(" << endl;
  else cout << "Yay!" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <sstream>
#include <stdio.h>
#include<math.h>
using namespace std;

int main(){

    int a,b;

    cin >> a >> b;

    if(a * b % 2 == 0 ){
        cout << "Even" << endl;
    }
    else{
        cout << "Odd" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j,k,l;
		Scanner sc = new Scanner(in);
		long h = parseLong(sc.next());
		sc.close();
		long ans = (long)pow(2,(long)floor(log(h)/log(2))+1)-1;
		out.println(ans);
	}
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
#include<stdio.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF 1000000000000000
#define MAXN (int)(1e6)+1
#define MOD 1000000007
 
using namespace std;
 
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pwi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector< vector<pair<int,lli > > > wGraph;
typedef vector<vector<int> > graph;
//typedef vector<vector<int> > matrix;

int n;
int dp[MAXN];
vi ar;

int knap(int ind){
    
    if(ind>=n){
        return 0;
    }
    
    if(dp[ind]!=-1) return dp[ind];
    
    int takeIt = INT_MAX,leaveIt = INT_MAX;
    if(ind+2 < n){
        takeIt = abs(ar[ind]-ar[ind+2]);
    }
    if(ind+1<n)
        leaveIt = abs(ar[ind]-ar[ind+1]);
    
    if(ind+1>=n) return dp[ind] = 0;
    else{
        return dp[ind] = min(takeIt+knap(ind+2),leaveIt+knap(ind+1));
    }
    
}


int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(4);
    
    for(int i = 0;i<MAXN;++i){
        dp[i] = -1;
    }
    
    cin>>n;
    for(int i = 0;i<n;++i){
        int v;
        cin>>v;
        ar.pb(v);
    }   
    
    cout<<knap(0)<<endl;
    
    return 0;
 
}

Measured memory_bytes: 9336
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	int n;
	cin >> n;
	printf("ABC%d\n", n);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x;
		cin>>x;
		n-=x;
	}
	if(n<0)cout<<-1<<endl;
	else cout<<n<<endl;
} 

Measured memory_bytes: 3644
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")
}

type Weight = usize;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

fn dfs(g: &Graph, from: usize, parent: usize, d: usize, dists: &mut Vec<usize>) {
    dists[from] = d;
    for edge in g[from].iter() {
        if edge.dest == parent {
            continue;
        }
        dfs(g, edge.dest, from, d + edge.weight, dists);
    }
}

fn main() {
    let n = read::<usize>();
    let mut g = graph_new(n);
    let mut e = 0;
    for _ in 0..n - 1 {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        let c = read::<usize>();
        add_bi_edge(&mut g, &mut e, a, b, c);
    }
    let q = read::<usize>();
    let k = read::<usize>() - 1;
    let mut dists = vec![0; n];
    dfs(&g, k, k, 0, &mut dists);
    for _ in 0..q {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        println!("{}", dists[a] + dists[b]);
    }
}


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

constexpr int64_t MAX_N = 100;
constexpr int64_t MAX_V = 1000;
constexpr int64_t MAX_SUM_V = MAX_N * MAX_V;
int64_t dp[MAX_N + 1][MAX_SUM_V + 1];

int64_t solve(const int64_t N, const int64_t W, const vector<int64_t>& w, const vector<int64_t>& v) {
  // Initialize dp table
  dp[0][0] = 0;
  for (auto i = 1; i <= N * MAX_V; ++i) {
    dp[0][i] = W + 1;
  }

  // dp
  for (auto i = 1; i <= N; ++i) {
    for (auto j = 0; j <= N * MAX_V; ++j) {
      if (j - v[i - 1] >= 0) {
        dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }

  // Find max_value
  int64_t max_value = 0;
  for (auto i = 1; i <= N * MAX_V; ++i) {
    if (dp[N][i] <= W) {
      max_value = i;
    }
  }

  return max_value;
}

int main() {
  // Input
  int64_t N, W;

  cin >> N >> W;

  vector<int64_t> w(N), v(N);
  for (auto i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
  }

  // Solve
  auto ans = solve(N, W, w, v);

  // Answer
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 79104
#include <stdio.h>

int main(){

    int a, b;
    int soma, diferenca, produto;

    scanf("%d %d", &a, &b);

    soma = a + b;
    diferenca = a - b;
    produto = a * b;

    if(soma >= diferenca && soma >= produto) {
        printf("%d\n", soma);
    } else if(diferenca > soma && diferenca > produto) {
        printf("%d\n", diferenca);
    } else {
        printf("%d\n", produto);
    }

    return 0;
}

Measured memory_bytes: 384
class Dice:
  def make_dice(self, value):
    self.face = value
  def move(self, direc):
    if direc == "N":
      self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
      return self.face
    elif direc == "E":
      self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
      return self.face
    elif direc == "S":
      self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
      return self.face
    elif direc == "W":
      self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
      return self.face
  def check_face(self, face1):
    for i in range(4):
      if face1 == self.face:
        return self.face
      else:
        self.face[1],self.face[2],self.face[4],self.face[3] = self.face[2],self.face[4],self.face[3],self.face[1]

def comp_dices(dice1,dice2,num):
  for i in range(6):
    dice2.make_dice(num)
    if i == 0:
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 1:
      dice2.move("N")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 2:
      dice2.move("E")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 3:
      dice2.move("S")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 4:
      dice2.move("W")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 5:
      dice2.move("N")
      dice2.move("N")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
      else:
        return False

n = int(input())
num = []
dice = []
for i in range(n):
  num.append(list(map(int, input().split())))
  dice.append(Dice())
  dice[i].make_dice(num[i])

for i in range(n):
  for j in range(i+1,n):
    flag = comp_dices(dice[i],dice[j],num[j])
    if flag:
      break
  if flag:
    break

if flag:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int sum = 0;

	vector<int>vec(N);
	rep(i, N) {
		cin >> vec[i];
	}

	vector<int>abs1(N);

	for (int i = 0; i < N; i++) {
		sum = sum + vec[i];
	}

	for (int i = 0; i < N; i++) {
		int r = 0;
		int l = 0;

		for (int j = 0; j < i; j++) {
			l = l + vec[j];
		}
		for (int k = i; k < N; k++) {
			r = r + vec[k];
		}
		abs1[i] = abs(l - r);
	}

	sort(abs1.begin(), abs1.end());
	cout << abs1[0] << endl;
}

Measured memory_bytes: 256
k,n=map(int,input('').split())
a=input('')
a=a.split(' ')
for b in range(n):
    a[b]=int(a[b])
a.sort()

m=0
for b in range(n-1):
    if m<=a[b+1]-a[b]:
        m=a[b+1]-a[b]

if m<=k-a[n-1]+a[0]:
    m=k-a[n-1]+a[0]

print(k-m)

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

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; ++i) cin >> a[i];
    
    int num[200010] = {0};  // バケット
    for (int i = 0; i < N; ++i) {
        num[a[i]]++;  // d[i] が 1 個増える
    }
    int ans = 1;
    for (int i = 0; i < 150000-1; ++i){
        int sum = num[i] + num[i+1] + num[i+2];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,k,n,q,x,y,l,r,m,c,z;
    string s;
	cin>>n>>x>>y;
	if(x == 0) cout<<0;
	else{
		cout<< x * (n/(x+y)) + min(x,(n)%(x+y));
	}
}

Measured memory_bytes: 256
word_count = Hash.new(0)

words =	gets.chomp.split
words.each do |word|
  word_count[word] += 1
end
sorted = word_count.sort{|a,b| b[1] <=> a[1]}
max_size = word_count.sort{|a,b| b[0].size <=> a[0].size}
puts "#{sorted[0][0]} #{max_size[0][0]}"



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


void solve(long long N, std::vector<std::string> S){
    vector<char> heads = {'M','A','R','C','H'};
    vector<long long> cnts(5, 0l);
    for(auto s: S){
        for(int i=0; i<5; i++)
            if(s[0]==heads[i])cnts[i]++;
    }
    long long ans=0;
    for(int i=0; i<3; i++){
        for(int j=i+1; j<4; j++){
            for(int k=j+1; k<5; k++){
                ans += cnts[i]*cnts[j]*cnts[k];
            }
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 6144
def g(x):
    if x % 4 == 0 or x % 4 == 3:
        l = [0]
    else:
        l = [1]
    r = x % 2
    x //= 2
    while x > 0:
        if x % 2 == 0:
            l.append(0)
        else:
            l.append(1 - r)
        x //= 2
    return l + [0] * (40 - len(l))

def f(x, y):
    ans = 0
    a = g(x - 1)
    b = g(y)
    for i in range(40):
        ans *= 2
        ans += a[-1 - i] ^ b[-1 - i]
    return ans

A, B = map(int, input().split())
print(f(A, B))


Measured memory_bytes: 38256
#include <stdio.h>
int main(void)
{
  int n,s=0;
  scanf("%d",&n);
  if((n%10)==7)
    s=1;
  n/=10;
  if((n%10)==7)
    s=1;
  n/=10;
  if(n==7)
    s=1;
  if(s==1)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] nums = new int[11];
		for (int i = 0; i < 3; i++) {
			int num = sc.nextInt();
			nums[num]++;
		}
		
		if (nums[5] == 2 && nums[7] == 1) System.out.println("YES");
		else System.out.println("NO");
		
		sc.close();
	}
}



Measured memory_bytes: 27028
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(){
    int N,count=0;
    cin >>N;
    int A[N],B[N],C[N];
    for( int i=0;i<N;i++){
        cin >>A[i];
    }
       for( int i=0;i<N;i++){
        cin >>B[i];
        count+=B[i];
    }
       for( int i=0;i<N-1;i++){
        cin >>C[i];
    }
      for( int i=0;i<N-1;i++){
          if(A[i]==A[i+1]-1){
          count+=C[A[i]-1];
          }
    }
    cout << count;

}



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

int main(){
    int n, m;
    cin >> n >> m;
    int a[n];
    int total = 0;
    for (int i = 0; i < n; ++i){
        cin >> a[i];
        total+=a[i];
    }

    int count = 0;
    int basis;
    if (total%(4*m)==0){
        basis = total / (4*m);
    }else{
        basis = (total - total%(4*m)) / (4*m) + 1;
    }

    for (int i = 0; i < n; ++i){
        if (a[i] >= basis){
            count+=1;
        }
    }

    if (count>=m){
        cout << "Yes"  << endl;
    }else{
        cout << "No"  << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,i,k,x;
    cin >> n;
    k=0;x=n;
    for(i=0;i<n;i++)
    {
        cin >> a;
    if(a<=x)
    {
        k++;
        x=a;
    }
    }

    cout << k << endl;

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int rn = uniform_int_distribution<int>(0, MAXN)(rng);

    int n,x,y;
    char s;
    cin>>n;
    pii a[2*n];
    int b[2][n+1][n+1] , z[2][n+1];
    MEM(b,0); MEM(z,0);

    REP(i,2*n) {
        cin>>s>>y;
        if(s == 'W') x = 0;
        else x = 1;
        a[i] = MP(x,y);
    }

    REP(i,2*n) {
        REP(j,i) {
            if(a[j].x == a[i].x && a[j].y > a[i].y) z[a[i].x][a[i].y] += 1;
            else if(a[j].x != a[i].x) {
                b[a[i].x][a[i].y][a[j].y] += 1;
            }
        }
        REP(j,n+1) if(j) b[a[i].x][a[i].y][j] += b[a[i].x][a[i].y][j-1];
    }

    int dp[n+1][n+1];
    dp[0][0] = 0;
    FOR(i,1,n) dp[i][0] = dp[i-1][0] + z[0][i] + b[0][i][n];
    FOR(j,1,n) dp[0][j] = dp[0][j-1] + z[1][j] + b[1][j][n];
    
    FOR(i,1,n) {
        FOR(j,1,n) {
            int p = dp[i-1][j] + z[0][i] + b[0][i][n] - b[0][i][j];
            int q = dp[i][j-1] + z[1][j] + b[1][j][n] - b[1][j][i];
            dp[i][j] = min(p, q);
        }
    }
    
    cout<<dp[n][n];
    return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;
	cin>> n;

	cout<< n*n<<endl;
	return 0;
}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

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

int nmax=200000; // 2*(10^5)
vvec g(nmax);


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

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
  
  double r;
    cin>>r;
    cout<<2*r*3.141592653589793<<endl;

}


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

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

#define INF 1000000000
#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define foreach(v,c) for(typeof((c).begin()) v=(c).begin();v!=(c).end();++v)
#define all(a) a.begin(),a.end()
#define in(a,b) ((b).find(a)!=(b).end())
#define fill(a,v) memset(a,v,sizeof a)
#define sz(a) ((int)(a.size()))
#define mp make_pair
#define pb push_back

int cnt[1000010];
int main(){
	int n;
	fastIO
	cin>>n;
	for(int i = 1; i <= 100; i++) {
		for(int j = 1; j <= 100; j++) {
			for(int k = 1; k <= 100; k++) {
				cnt[i * i + j * j + k * k + i * j + i * k + j * k]++;
			}
		}
	}
	for(int i = 1; i <= n; i++) cout<<cnt[i]<<endl;
}

Measured memory_bytes: 3844
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << '\n';
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    string s; cin >> s;
    int x, y; cin >> x >> y;
    
    vector<int> move_x, move_y;
    int dis = 0;
    bool direction = true; // x:true y:false
    for (int i = 0; i < s.size(); i++) {
        if ((s[i] == 'T') || i == s.size() - 1){
            if (s[i] == 'F') dis++;
            if (direction) move_x.emplace_back(dis);
            else move_y.emplace_back(dis);

            direction = !direction;
            dis = 0;
        }
        else dis++;
    }

    set<int> reach_x, reach_y;
    reach_x.insert(0);
    reach_y.insert(0);

    reach_x.insert(move_x[0]);
    move_x.erase(move_x.begin());

    bool flag = false;
    for (int d : move_x) {
        set<int> new_reach; 
        for (int pos : reach_x) {
            new_reach.insert(pos + d);
            new_reach.insert(pos - d);
        }
        reach_x = new_reach;
    }
    for (int d : move_y) {
        set<int> new_reach; 
        for (int pos : reach_y) {
            new_reach.insert(pos + d);
            new_reach.insert(pos - d);
        }
        reach_y = new_reach;
    }

    bool flag_x = false, flag_y = false;
    for (int goal : reach_x) {
        if (goal == x) flag_x = true;
    }
    for (int goal : reach_y) {
        if (goal == y) flag_y = true;
    }

    if (flag_x && flag_y) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

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

    solve();

    return 0;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 M = 1000000007;
// vector<i64> fact(2010);

// i64 comb(i64 n, i64 r) {
//   return fact[n] * inv(fact[r], M) % M * inv(fact[n - r], M) % M;
// }

signed main() {
  // fact[0] = 1;
  // REP(i, 2005) {
  //   fact[i + 1] = (i + 1) * fact[i] % M;
  // }
  i64 n, k;
  cin >> n >> k;
  i64 a = 1;
  i64 b = n - k + 1;
  REP(i, k) {
    cout << (a * b % M) << "\n";
    a = a * (k - 1 - i) % M * inv(i + 1, M) % M;
    b = b * (n - k - i) % M * inv(i + 2, M) % M;
    // cout << comb(k - 1, i) * comb(n - k + 1, i + 1) % M << endl;
  }
}


Measured memory_bytes: 256
/*
      author  : nishi5451
      created : 14.08.2020 16:56:40
*/

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


int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(i*500+j*100+k*50 == x) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620