akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

void printVector(vector<string> &vec){
    // cout << "size = " << vec.size() << endl;
    for(int i = 0; i < vec.size(); ++i){
        if(vec[i] != ""){
            cout << vec[i] << endl;
        }
        
    }
    // cout << endl << endl;
}

int main(){
    int n;
    cin >> n;
    unordered_map<string, int> s;
    rep(i, n){
        string ss;
        cin >> ss;
        s[ss]++;
    }
    set<string> st;
    int max_val = 0;
    for (auto itr = s.begin(); itr != s.end(); ++itr) {
        // cout << itr->first << endl;
        if(itr->second >= max_val){
            max_val = itr->second;
        }
    }
    for (auto itr = s.begin(); itr != s.end(); ++itr) {
        if(itr->second == max_val){
            // max_val = itr->second;
            st.insert(itr->first);
        }
    }

    vector<string> vec(st.begin(), st.end());
    // rep(i, vec.size()){
    //     cout << vec[i] << endl;
    // }
    sort(vec.begin(), vec.end());
    // vec.erase(st.size(),vec.end());

    printVector(vec);

    // cout << n << endl;
}

Measured memory_bytes: 35500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>

using namespace std;

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= 13) {
        cout << b << endl;
    } else if (a >= 6) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <map>

using namespace std;
using lli = long long int;
using ll = long long;

lli N;

void dfs(string s, char mx) {
    if (s.length() == N) {
        printf("%s\n", s.c_str());
    } else {
        for (char c = 'a'; c <= mx; c++) {
            dfs(s + c, ((c == mx) ? (char) (mx + 1) : mx));
        }
    }
}

int main() {
    cin >> N;
    dfs("", 'a');
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char code[5],flag=0;
    scanf("%s",&code);
    for(int i=0;i<strlen(code);i++)
    {
        if(code[i]==code[i+1])
        {
            printf("Bad");
            return 0;
        }
        else
        {
            flag=1;
        }
    }
    if(flag==1)
    {
        printf("Good");
    }
    return 0;
}

Measured memory_bytes: 256
pub 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()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn f(u: usize, p: usize, d: u32, edges: &Vec<Vec<usize>>, dist: &mut Vec<(u32, u32)>) {
    dist[u].0 = d;
    for v in &edges[u] {
        if *v == p {
            continue;
        }
        f(*v, u, d + 1, edges, dist);
    }
}

fn s(u: usize, p: usize, d: u32, edges: &Vec<Vec<usize>>, dist: &mut Vec<(u32, u32)>) {
    dist[u].1 = d;
    for v in &edges[u] {
        if *v == p {
            continue;
        }
        s(*v, u, d + 1, edges, dist);
    }
}

fn main() {
    let n: usize = read();
    let mut edges: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..n - 1 {
        let ab: Vec<usize> = read_vec();
        let a = ab[0] - 1;
        let b = ab[1] - 1;
        edges[a].push(b);
        edges[b].push(a);
    }

    let mut dist: Vec<(u32, u32)> = vec![(0, 0); n];
    f(0, 1000000, 0, &edges, &mut dist);
    s(n - 1, 1000000, 0, &edges, &mut dist);

    let mut c1 = 0;
    let mut c2 = 0;
    for (d1, d2) in dist {
        if d1 <= d2 {
            c1 += 1;
        } else {
            c2 += 1;
        }
    }
    if c1 > c2 {
        println!("Fennec");
    } else {
        println!("Snuke");
    }
}


Measured memory_bytes: 18684
#include <bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
 
deque<int> next_good(deque<int> s) {
    int p = sz(s) - 1;
    while (p >= 0 && s[p] == 9) {
        s[p] = 0;
        p--;
    }
    if (p == -1) {
        s.push_front(1);
    } else {
        s[p]++;
    }
    while (true) {
        int b = -1;
        rep(i, 0, sz(s) - 1) {
            if (abs(s[i] - s[i + 1]) > 1) {
                b = i;
                break;
            }
        }
        if (b == -1) {
            break;
        }
        if (s[b + 1] > s[b]) {
            s[b]++;
        }
        int lll = max(s[b] - 1, 0);
        rep(i, b + 1, sz(s)) {
            s[i] = lll;
            lll = max(lll - 1, 0);
        }
    }
    return s;
}
 
int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;

    int k;
    cin >> k;
    deque<int> ans;
    rep(i, 0, k) {
        ans = next_good(ans);
    }
    for (int i : ans) {
        cout << i;
    }
    cout << "\n";
    return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100000][3];
int main()
{
	int f=1,i,j,n;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		if((a[i][2]+a[i][1]>a[i][0])||a[i][0]%2!=(a[i][1]+a[i][2])%2)	f=0;
	}
	if(f==1) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int cmpItem(const char* a, const char* b) {
	int id1 = isdigit((unsigned char)*a), id2 = isdigit((unsigned char)*b);
	if (*a == '\0' && *b != '\0') return -1;
	if (*a != '\0' && *b == '\0') return 1;
	if (id1 && !id2) return -1;
	if (!id1 && id2) return 1;
	if (id1) {
		int aa = atoi(a), bb = atoi(b);
		return aa < bb ? -1 : aa > bb;
	} else {
		return (unsigned char)*a - (unsigned char)*b;
	}
}

char* getNextItem(char* out, char* in) {
	if (isdigit((unsigned char)*in)) {
		while (isdigit((unsigned char)*in)) {
			*(out++) = *(in++);
		}
		*out = '\0';
		return in;
	} else {
		out[0] = *in;
		out[1] = '\0';
		return in + 1;
	}
}

int main(void) {
	int n;
	int i;
	char s0[16];
	char s[16];
	if (scanf("%d", &n) != 1) return 1;
	if (scanf("%15s", s0) != 1) return 1;
	for (i = 0; i < n; i++) {
		char* s0ptr, *sptr;
		if (scanf("%15s", s) != 1) return 1;
		s0ptr = s0;
		sptr = s;
		for (;;) {
			char item1[16], item2[16];
			int cres;
			s0ptr = getNextItem(item1, s0ptr);
			sptr = getNextItem(item2, sptr);
			cres = cmpItem(item1, item2);
			if (cres != 0) {
				printf("%c\n", cres > 0 ? '-' : '+');
				break;
			} else if (*item1 == '\0' && *item2 == '\0') {
				puts("+");
				break;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 2112
import java.util.*;

public class Main {
	static int MOD = 1_000_000_007;
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        long res = (((modPow(2, n) - comb(n, a) - comb(n, b) - 1) ) % MOD + MOD) % MOD;
        System.out.println( res );
    }

    private static long modPow(long a, long b) {
    	if(b == 0)
    		return 1;
    	if(a == 0)
    		return 0;
    	if(b == 1)
    		return a;
    	long res = modPow(a, b / 2) % MOD;
    	if(b % 2 == 1)
    		return ((res * res) % MOD) * a % MOD;
    	return (res * res) % MOD;
    }

    private static long factorial(long n, long start) {
    	long res = 1L;
    	for(long i = start; i <= n; i++)
    		res = (res % MOD)* (i % MOD) % MOD;
    	return res;
    }

    private static long comb(long a, long b) {
    	long factA = factorial(a, a - b + 1) % MOD;
    	long factB = factorial(b, 1) % MOD;
    	long inv = modPow(factB, MOD - 2) % MOD;
    	return factA * inv % MOD;
    }
}


Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,a,num[100000]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		num[a-1]++;
		num[a]++;
		num[a+1]++;
	}
	sort(num,num+100000);
	cout<<num[99999]<<endl;
	return 0;
}

Measured memory_bytes: 640
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ


int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	double ret=mod;
	int at=0;
	for(int i=0;i<a;i++){
		int h;scanf("%d",&h);
		double t=b-0.006*h;
		if(ABS(t-c)<ret){
			ret=ABS(t-c);at=i;
		}
	}
	printf("%d\n",at+1);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
int N,V,C;

scanf("%d", &N);
int vx[N];
int vy[N];
int i;

for(i=0; i<N; i++) 
scanf("%d ", &vx[i]);

for(i=0; i<N; i++)
scanf("%d ", &vy[i]);

int sum=0;
for (i=0; i<N; i++) {
if (vx[i]>vy[i])
sum+=vx[i]-vy[i];
}

printf("%d\n", sum);

return 0;
}

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

using namespace std;
const int MAX = 100003;

int dp[MAX], h[MAX];

int main() {

    fill_n(dp, MAX, 1000000000);
    fill_n(h, MAX, 1000000000);

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n, i;
    
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> h[i];
        
    dp[n] = 0;

    for(i = n - 1; i > 0; --i)
        dp[i] = min(dp[i + 1] + abs(h[i] - h[i + 1]), dp[i + 2] + abs(h[i] - h[i + 2]));

    cout << dp[1] << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;
 
int main () {
  int n;
  cin >> n;
  int a [n];
  int i, j, k, temp, count, minj;
  REP (k, n) {
    cin >> a [k];
  }
  count = 0;
  REP (i, n) {
    minj = i;
    for (j = i; j < n; j++) {
      if (a [j] < a [minj]) {
        minj = j;
      }
    }
    if (i != minj) {
      temp = a [i];
      a [i] = a [minj];
      a [minj] = temp;
      count++;
    }
  }

  cout << a [0];
  REP1 (k, n) {
    cout << " " << a [k];
  }
  cout << endl << count << endl;
 
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>

using namespace std;

int c[2][100002], n, a, b;

main(){
  cin >> n;
  fill(c[0], c[2], 0);
  for(int i=0;i<n;i++){
    cin >> a >> b;
    c[0][a]++;
    c[1][b]++;
  }
  a = 0;
  b = 1;
  for(int i=1;i<n+3;i++){
    b += c[0][i];
    b -= c[1][i-1];
    if(b >= i) a = i - 1;
  }
  cout << a << endl;
}

Measured memory_bytes: 1944
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int x=0;
    vector<int> vec(10100,0);
    for (int i = 1; i < 100; i++)
    {
        for (int j = 1; j <100; j++)
        {
            for (int k = 1; k < 100; k++)
            {
                x = i*i+j*j+k*k+i*j+j*k+k*i;
               
                if (x<=10000)
                {
                    vec.at(x)+=1;
                }
                

            }
            
        }
        
    }
    for (int i = 1; i <= n; i++)
    {
        cout<<vec.at(i)<<endl;
    }
    
    
    


    return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>

int main() {
  int n, a;
  int min = 1000001, max = -1000001;
  long long sum = 0;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &a);
    if (a < min) min = a;
    if (a > max) max = a;
    sum += a;
  }
  printf("%d %d %lld\n", min, max, sum);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int d[200005][80];

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) --a[i];
    rep(i,n) d[i][0] = a[i];

    for(int i=1;i<=79;i++){
        rep(j,n){
            d[j][i] = d[d[j][i-1]][i-1];
        }
    }

    int ans = 0;
    int c = 0;
    while(k > 0){
        if(k & 1){
            ans = d[ans][c];
        }
        k >>= 1;
        ++c;
    }

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

Measured memory_bytes: 66584
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

const int inf = 1 << 30;

int main(void){
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i,n) cin >> h[i];

	vector<int> dp(n, inf);
	dp[0] = 0;
	rep(i,n)rep(j,1,3){
		if(i + j < n){
			chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	cout << dp[n-1] << endl;

	return 0;
}

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

int main() {
    long long int A,B,C,D, K, N;
    long long int new_A, new_B, new_C, new_K;
    long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, s, w;
    vector<long long int> a_v;
    string str;
    cin >> str;

    while(1) {
       str.pop_back();       str.pop_back();
       if (str.substr(0, str.length()/2) == str.substr(str.length()/2, str.length()/2)) {
            break;
       }
    }
    cout << str.length() << endl;
    // cout << str << endl;
    // long long int board[str.length()+1];
    // for (int i = 1; i <= str.length(); i++) {
    //     if (str[i] == '<') {
    //         board[i] = 1;
    //     } else {
    //         board[i] = 0;
    //     }
    // }
    // long long int sum = 0, cny = 0;
    // for (int i = 0; i < str.length(); i++) {
    //     if (board[i] == 1) {
    //         sum += i-cny;
    //         cny++;
    //     }
    // }
    // cout << sum << endl;
    // for (int i = 0; i < N; i++) {
    //     long long int a;
    //     cin >> a;
    //     a_v.push_back(a);
    // }

    // int now = 1;
    // bool flag = false;
    // for (i = 0; i < N; i++) { 
    //     now = a_v[now-1];
    //     // cout << now << endl;
    //     if (now == 2) {
    //         flag = true;
    //         break;
    //     }
    // }

    // if (flag) {
    //     cout << i+1 << endl;
    // }
    // else {
    //     cout << "-1" << endl;
    // }

    // cin >> A;
    // cin >> B;
    // cin >> C;
    // cin >> D;

    // while(1) {
    //     C = C-B;
    //     if (C <= 0) {break;} 
    //     A = A - D;    
    //     if (A <= 0) {break;} 
    // }
    // if (A <= 0) {
    //     cout << "No" << endl;
    // }
    // else {
    //     cout << "Yes" << endl;
    // }
    // long long int tmp, cnt = 0;
    // tmp = b;
    // for (;;) {
    //     tmp = tmp/10;
    //     cnt ++;
    //     if (tmp > 0) {
    //     }
    //     else {
    //         break;
    //     }
    // } 
    // long long int time = 1;
    // for (int i = 0; i < cnt; i++) {
    //     time *= 10;
    // }
    // b += a*time;
    // // cout << b<< endl;
    // bool flag = false;
    // for (long long int i = 0; i < sqrt(b)+1; i++) {
    //     if (i*i == b) {
    //         flag = true;
    //     }
    // }
    // if (flag) {
    //     cout << "Yes" << endl;
    // }
    // else {
    //     cout << "No" << endl;
    // }

    return 0;
}

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

int main(){
  int a[5];
  int ave = 0;

  for(int i=0;i<5;++i){
    cin >> a[i];
    if(a[i] < 40) a[i] = 40;

    ave += a[i];
  }

  cout << ave / 5 << endl;
  
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
#define bit(mask,i) ((mask)>>(i)&1)
using namespace std;
using ll = long long;


const int MD=int(1e9)+7;

inline int madd(int x,int y) {
	if (x+y<MD) return x+y; else return x+y-MD;
}
inline int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+MD;
}
inline int mmul(int x,int y) {
	return int(ll(x)*y % MD);
}

int const MAXN=16;
int N,M;
int a[MAXN];
int f[1<<MAXN];

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N>>M;
	rep(i,0,M) {
		int x,y;
		cin>>x>>y;
		x--,y--;
		a[x]|=1<<y;
	}
	
	rep(mask,1,1<<N) if (bit(mask,0)==bit(mask,1)) {
		f[mask]=1;
		for (int S=mask&(mask-1); S>0; S=mask&(S-1)) {
			if (bit(S,0)!=bit(S,1)) continue;
			int T=mask^S;
			int add=f[S];
			assert(T!=0);
			rep(v,0,N) {
				if (bit(S,v)) {
					int k=__builtin_popcount(a[v]&T);
					add=mmul(add,(1<<k)-1);
				} else if (bit(T,v)) {
					int k=__builtin_popcount(a[v]&S);
					add=mmul(add,1<<k);
				}
			}
			f[mask]=madd(f[mask],add);
		}
	}
	
	int res=1;
	rep(i,0,M) res=madd(res,res);
	res=msub(res,f[(1<<N)-1]);
	cout<<res<<"\n";
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll dp[n][n][2];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) {
        dp[i][i][0] = v[i];
        dp[i][i][1] = -v[i];
    }
    for (int w = 2; w <= n; w++) {
        for (int i = 0; i < n - w + 1; i++) {
            int j = i + w - 1;
            dp[i][j][0] = max(v[i] + dp[i+1][j][1], dp[i][j-1][1] + v[j]);
            dp[i][j][1] = min(-v[i] + dp[i+1][j][0], dp[i][j-1][0] - v[j]);
        }
    }
    cout << dp[0][n-1][0];
    return 0;
}


Measured memory_bytes: 140928
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int n,m;
    ll ans=0;
    cin>>n>>m;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    vector<int> a(m),b(m);
    vector<bool> f(n,true);
    rep(i,m) {
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
        if (h[a[i]]>h[b[i]]) f[b[i]]=false;
        else if(h[a[i]]==h[b[i]]) {
            f[a[i]]=false;
            f[b[i]]=false;
        }
        else f[a[i]]=false;
    }
    rep(i,n) {
        if (f[i]) {
            ans++;
        }
    }
    cout<<ans<<endl;
}   


Measured memory_bytes: 4580
n,m,k = map(int, input().split( ))
A = list(map(int, input().split( )))
B = list(map(int, input().split( )))
acc1 = [0]
for i in range(n):
  acc1.append(acc1[-1] + A[i])
acc2 = [0]
for i in range(m):
  acc2.append(acc2[-1] + B[i])

ans = 0
j = m
for i in range(n+1):
  if acc1[i] > k:
    break
  while acc2[j] > k - acc1[i] and j > 0:
    j -= 1
  ans = max(ans,i+j)
print(ans)

Measured memory_bytes: 47496
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;

int main(){
    string s;
    cin>>s;
    int n=s.length();
    if(s[n-1]=='s'){
        s+="es";
    }else{
        s+='s';
    }
    cout<<s<<endl;
    
}

Measured memory_bytes: 3132
#include <stdio.h>

typedef struct {
	int point, rank;
} s_team;

int main() {
	int N, A, B, C, D;
	s_team team[100];
	
	scanf("%d", &N);
	
	int n;
	for(n = 0; n < N; n ++) {
		team[n].point = 0;
		team[n].rank = 0;
	}
	
	for(n = 0; n < N*(N-1)/2; n ++) {
		scanf("%d %d %d %d", &A, &B, &C, &D);
		if(C < D) {
			team[B - 1].point += 3;
		}
		else if(C == D) {
			team[A - 1].point ++;
			team[B - 1].point ++;
		}
		else if(C > D) {
			team[A - 1].point += 3;
		}
	}
	
	int i = 0, j, k = 0, max;
	
	int flag[100];
	for(i = 0; i < 100; i ++) {
		flag[i] = 0;
	}
	
	i = 0;
	while(i < N) {
		max = 0;
		k = 0;
		for(j = 0; j < N; j ++) {
			if(flag[j] == 0 && max < team[j].point) {
				max = team[j].point;
			}
		}
		for(j = 0; j < N; j ++) {
			if(team[j].point == max) {
				team[j].rank = i + 1;
				flag[j] = 1;
				k ++;
			}
		}
		i += k;
	}
	
	for(n = 0; n < N; n ++) {
		printf("%d\n", team[n].rank);
	}
	
	return 0;
}

Measured memory_bytes: 0
S = input()
ans = 0

def f(shiki, index):
	global ans
	l = len(shiki)
	if index < l - 1:
		f(shiki, index + 1)
		f(shiki[: index + 1] + '+' + shiki[index + 1:], index + 2)
		
	else:
		ans += sum(list(map(lambda x: int(x), shiki.split('+'))))

f(S, 0)
print(ans)

Measured memory_bytes: 3060
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
ans = 1000-N%1000
if ans == 1000:
    print(0)
else:
    print(ans)

Measured memory_bytes: 77340
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,l = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n-1):
    if a[i]+a[i+1]>=l:
        ans = ["Possible"]
        ans += [j for j in range(1,i+1)]
        ans += [j for j in range(n-1, i+1, -1)]
        ans.append(i+1)
        break
else:
    ans = ["Impossible"]
write("\n".join(map(str, ans)))

Measured memory_bytes: 73760
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> PI;

namespace io
{
	const int maxb = 1<< 15;
	char b[maxb], *s = b, *t = b;
	bool Getchar(char &ch)
	{
		return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++;

	}
}

LL Getint()
{
	using namespace io;
	char ch;
	while (Getchar(ch) && (ch < '0' || ch > '9'));
	LL s = ch - '0';
	while (Getchar(ch) && ch >= '0' && ch <= '9')
		s = s * 10 + ch - '0';
	return s;
}

const LL INF = 1e18;
const int maxn = 100;
const int Mod = 1e9 + 7;

void Chkadd(int &x, const int &y) { if ((x += y) >= Mod) x -= Mod; }

int n;
LL fib[maxn];
vector<PI> exc[maxn];

#define fir first
#define sec second

void Prepare()
{
	fib[0] = fib[1] = 1;
	for (n = 1; fib[n] <= INF; ++ n)
		fib[n + 1] = fib[n] + fib[n - 1];
	n -= 2;
	exc[1].push_back(PI(1, 2));
	exc[1].push_back(PI(1, 3));
	for (int i = 2; i <= n; ++ i)
	{
		vector<PI> &lst = exc[i - 1], &cur = exc[i];
		int size = lst.size();
		for (int j = 0; j < size; ++ j)
		{
			LL x = lst[j].fir, y = lst[j].sec;
			for (LL z = x + y; z <= fib[i + 2]; z += y)
				cur.push_back(PI(y, z));
		}
	}
}

void Doit()
{
	LL X = Getint(), Y = Getint();
	if (X > Y) swap(X, Y);
	int k;
	for (k = 1; fib[k] <= X && fib[k + 1] <= Y; ++ k);
	-- k;
	if (k <= 1)
	{
		printf("1 ");
		if (X == 1) printf("%lld\n", Y % Mod); else puts("4");
		return;
	}
	printf("%d ", k);
	vector<PI> &cur = exc[k - 1];
	int size = cur.size(), ans = 0;
	for (int i = 0; i < size; ++ i)
	{
		LL x = cur[i].fir, y = cur[i].sec;
		if (X < y || Y < x + y) continue;
		Chkadd(ans, (Y - x) / y % Mod);
		if (X < x + y) continue;
		Chkadd(ans, (X - x) / y % Mod);
	}
	printf("%d\n", ans);
	return;
}

int main()
{
	Prepare();
	int Q = Getint();
	while (Q --) Doit();
	return 0;
}


Measured memory_bytes: 4096
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef int ll;

const ll maxn = 310;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define pb push_back
#define Mp make_pair
#define pll pair<ll, ll>
#define F first
#define S second

ll n, m, dp[3][2][maxn][maxn], l, r, c, ans, mp[3][2] = {{1, 2}, {2, 0}, {0, 1}};
vector<pll> g[maxn];

int main(){
	fast_io;
	
	cin >> n >> m;
	for(ll i = 0; i < m; i++){
		cin >> l >> r >> c;
		g[r].pb(Mp(l, c));
	}
	dp[0][1][0][0] = 1;
	dp[1][1][0][0] = 1;
	dp[2][1][0][0] = 1;
	for(ll i = 1; i <= n; i++){
		for(ll j = 0; j < 3; j++){
			for(ll k = 0; k < i; k++){
				for(ll o = 0; o < i; o++){
					dp[j][i + 1 & 1][k][o] = 0;
				}
			}
		}
		for(ll j = 0; j < 3; j++){
			for(ll k = 0; k < i; k++){
				for(ll o = 0; o < i; o++){
					for(ll p = 0; p < g[i].size(); p++){
						l = g[i][p].F;
						c = g[i][p].S;
						if(ll(k >= l) + ll(o >= l) + 1 != c) dp[j][i & 1][k][o] = 0;
					}
					dp[j][i + 1 & 1][k][o] += dp[j][i & 1][k][o];
					if(dp[j][i + 1 & 1][k][o] >= mod) dp[j][i + 1 & 1][k][o] -= mod;
					dp[mp[j][0]][i + 1 & 1][o][i] += dp[j][i & 1][k][o];
					if(dp[mp[j][0]][i + 1 & 1][o][i] >= mod) dp[mp[j][0]][i + 1 & 1][o][i] -= mod;
					dp[mp[j][1]][i + 1 & 1][i][k] += dp[j][i & 1][k][o];
					if(dp[mp[j][1]][i + 1 & 1][i][k] >= mod) dp[mp[j][1]][i + 1 & 1][i][k] -= mod;
				}
			}
		}
	}
	for(ll i = 0; i < n; i++){
		for(ll j = 0; j < n; j++){
			for(ll k = 0; k < 3; k++){
				ans += dp[k][n & 1][i][j];
				if(ans >= mod) ans -= mod;
			}
		}
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 2432
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  int h, w, hh, ww;
  cin>>h>>w>>hh>>ww;
  std::cout << (h*w)-(hh*w+ww*h-(ww*hh)) << std::endl;
  return 0;
}



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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]);
			b[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		long ans = 0;
		for (int i = 29; i > 0; i--) {
			int ki = k >> i & 1;
			if (ki == 0) {
				continue;
			}
			long val = 0;
			label:
			for (int j = 0; j < n; j++) {
				for (int j2 = 29; j2 > i; j2--) {
					int kj2 = k >> j2 & 1;
					int aj2 = a[j] >> j2 & 1;
					if (aj2 > kj2) {
						continue label;
					}
				}
				int kj2 = k >> i & 1;
				int aj2 = a[j] >> i & 1;
				if (aj2 < kj2) {
					val += b[j];
				}
			}
			ans = Math.max(ans, val);
		}
		long val = 0;
		label:
		for (int j = 0; j < n; j++) {
			for (int j2 = 29; j2 > 0; j2--) {
				int kj2 = k >> j2 & 1;
				int aj2 = a[j] >> j2 & 1;
				if (aj2 > kj2) {
					continue label;
				}
			}
			int kj2 = k & 1;
			int aj2 = a[j] & 1;
			if (aj2 <= kj2) {
				val += b[j];
			}
		}
		ans = Math.max(ans, val);
		System.out.println(ans);
	}
}


Measured memory_bytes: 48220
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr
void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p=LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------
int h,w,dp[1010][1010];
vector<string> a(1010);


int fill(int i,int j){
    if(i<=0 || j<=0) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    if(a[i][j]=='#'){
        dp[i][j]=0;
        return 0;
    }

    int ans=0;
    if(a[i-1][j]=='.') ans=(ans+fill(i-1,j))%mod;
    if (a[i][j-1] == '.')
        ans = (ans + fill(i, j-1)) % mod;
    dp[i][j]=ans;
    return ans;
}

int main()
{   
    cin>>h>>w;
    memset(dp,-1,sizeof(dp));
    string x;
    fori(w) x+='#';
    a[0]=x;
    dp[1][1]=1;
    fori(h){
        cin>>x;
        a[i+1]='#'+x;

    }
    cout<<fill(h,w)<<endl;

    
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int n,i,j,x,ans=1e9;
int main () {
	for(scanf("%d",&n),i=1;i<n;++i){
		for(x=0,j=i;j;j/=10)x+=j%10;
		for(j=n-i;j;j/=10)x+=j%10;
		ans=min(ans,x);
	}
	printf("%d\n",ans);
}

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

typedef double db;
const int maxn = 3000;
const db pi = acos(-1);
int n, k, a[maxn + 3];

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	db x = 0, y = 0;
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			x += cos(pi * (a[i] + a[j]) / k) * (i - 1 + n - j) + cos(pi * (a[i] + a[j]) / k + pi) * (j - i - 1);
			y += sin(pi * (a[i] + a[j]) / k) * (i - 1 + n - j) + sin(pi * (a[i] + a[j]) / k + pi) * (j - i - 1);
		}
	}
	db t = 6. / n / (n - 1) / (n - 2);
	x *= t, y *= t;
	printf("%.15lf %.15lf\n", x, y);
	return 0;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef double ld;

class t {
public:
	void solve(std::istream& in, std::ostream& out) {

	    ll a,b,c;
	    in>>a>>b;

	    ll l = a*b;
	    ll g = __gcd(a,b);
	    out<<l/g<<endl;

	}
};


int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(nullptr);
	t solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
using System;

class Program
{
    static void Main()
    {
        string[] alpha = Console.ReadLine().Split(' ');
        int n = int.Parse(alpha[0]);
        int m = int.Parse(alpha[1]);
        int l = int.Parse(alpha[2]);

        long[,] A = new long[n, m];
        long[,] B = new long[m, l];
        long[,] C = new long[n, l];

        for (int i = 0; i < n; i++)
        {
            string[] beta = Console.ReadLine().Split(' ');

            for (int j = 0; j < m; j++)
            {
                A[i, j] = int.Parse(beta[j]);
            }
        }
        for (int i = 0; i < m; i++)
        {
            string[] gamma = Console.ReadLine().Split(' ');

            for (int j = 0; j < l; j++)
            {
                B[i, j] = int.Parse(gamma[j]);
            }

        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < l; j++)
            {
                for (int k = 0; k < m; k++)
                {
                    C[i, j] += A[i, k] * B[k, j];
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < l - 1; j++)
            {
                Console.Write(C[i, j] + " ");
            }
            Console.WriteLine(C[i, l - 1]);
        }
    }
}


Measured memory_bytes: 17956
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ara[100000];
int main()
{
    ll i,j=0,k=0;
    ll n;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>ara[i];
    }
    sort(ara,ara+n);
    for(i=n-1;i>=0;i--){
        if(ara[i]==ara[i-1]){
            j=ara[i];
            i=i-2;
            break;
        }
    }
    for(;i>=0;i--){
        if(ara[i]==ara[i-1]){
            k=ara[i];
            break;
        }
    }
    cout<<j*k<<endl;
}


Measured memory_bytes: 1024
n,k=list(map(int,input().split(" ")))
x=list(map(int,input().split(" ")))
x_=[]
for i in range(n-k+1):
    if x[i+k-1]<=0:
        x_.append(-x[i])
    elif x[i+k-1]>=0 and x[i]<=0:
        x_.append(2*min(abs(x[i+k-1]),abs(x[i]))+max(abs(x[i+k-1]),abs(x[i])))
    else:
        x_.append(x[i+k-1])
print(min(x_))

Measured memory_bytes: 14252
import java.util.*;

// 日本でよく使われる紙幣は、
// 10000円札、
// 5000円札、
// 1000円札です。以下、「お札」とはこれらのみを指します。

// 青橋くんが言うには、彼が祖父から受け取ったお年玉袋にはお札が N枚入っていて、合計で Y円だったそうですが、嘘かもしれません。このような状況がありうるか判定し、
// ありうる場合はお年玉袋の中身の候補を一つ見つけてください。なお、彼の祖父は十分裕福であり、お年玉袋は十分大きかったものとします。

public class Main{
    public static void main (String[]args){
        
        Scanner sc = new Scanner(System.in);
        
        // お札の枚数
        int N = sc.nextInt();
        
        // 合計金額
        int Y = sc.nextInt();

        sc.close();

        // 枚数のパターンを洗い出す → 合計金額を算出する → 合計金額が一致するならばそのパターンを出力　パターンを洗い出してなければ-1を出力
        // 10000円札
        boolean breakFlg = false;
        for (int i = 0; i<=N; i++){
            
        	// 5000円札
            for (int j = 0 ; j <= N-i; j++){
             
            	// 1000円札
             int k = N - (i + j);

             int trueMoney = (i * 10000) + (j * 5000) + (k * 1000);

             if (Y == trueMoney ){
                System.out.println(i+"\t"+j+"\t"+k);

                breakFlg = true;

                break;
             }   
                
            }
            
            if (breakFlg){
            
            	break;
            }
            
        }

        if (!breakFlg){
        	System.out.println(-1+"\t"+-1+"\t"+-1);
        }

        
    }
}

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

void solve()
{
    int h, n;
    cin>>h>>n; int sum=0;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        sum +=x;
    }
    if(sum>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
   int K, X;
   cin >> K >> X;
   if (500 * K >= X) {
       cout << "Yes" << '\n';
   }else{
       cout << "No" << '\n';
   }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pub push_back
#define pob push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r;
ll l,ans,num;
ll x[1000005],y[500005],z[500005];
bool dame,flag;
char s[500005],t[500005];
bool used[500005];

int main(){
    cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
		if(x[i]%2==1)a++;
	}
	if(a){
		p("first");
	}else{
		p("second");
	}
	

    return 0;
}

Measured memory_bytes: 26496
// review

#include <iostream>

using namespace std;

int a, b;

bool shouldDrawWhite(int x, int y) {
  if (y < 50) {
    if (a == 0) {
      return false;
    }
    if (y % 2 == 0 && x % 2 == 0) {
      a--;
      return true;
    }
    return false;
  }
  if (b == 0) {
    return true;
  }
  if (y % 2 == 1 && x % 2 == 0) {
    b--;
    return false;
  }
  return true;
}

void solve() {
  a--;b--;
  cout << 100 << " " << 100 << endl;
  for (int y=0;y<100;y++) {
    for (int x=0;x<100;x++) {
      if (shouldDrawWhite(x, y)) {
        cout << '.';
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }
}

int main() {
  cin >> a >> b;
  solve();
}


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

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    string s; cin >> s;
    int N = s.size();
    int cntP = 0, cntG = 0;
    int ans = 0;
    rep(i, N) {
        if(s[i] == 'g')  {
            if(cntP < cntG) cntP++, ans++;
            else cntG++;
        } else {
            if(cntP < cntG) cntP++;
            else cntG++, ans--; 
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main(void) {
  int H,W;
  cin >> H >> W;
  
  string board[50];
  
  for (int i = 0; i < H; ++i) 
    cin >> board[i];
  
  const int dx[8]={0,0,1,1,1,-1,-1,-1};
  const int dy[8]={1,-1,0,1,-1,0,1,-1};
  
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      
      if (board[i][j] == '#') continue;
      
      int num = 0;
      for (int k = 0; k < 8; ++k) {
        const int ni = i + dx[k];
        const int nj = j + dy[k];
        
        if (ni < 0 || H <= ni) continue; 
        if (nj < 0 || W <= nj) continue; 
        if (board[ni][nj] == '#') num++;
      }
      board[i][j] = char(num + '0');
    }
  }
  for (int i = 0; i < H; ++i)
    cout << board[i] << endl;
  
  return 0;
}

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

ll dp[3001][3001];
ll sum[3001][3001];


void prepocess(vector<int>& v,int n){
    
    for(int i=1;i<=n;i++){
       for(int j=i;j<=n;j++){
          sum[i][j]=v[j]+((j==i)? 0 : sum[i][j-1]);
       }
    }
}



ll solve(vector<int>& v,int i,int j){

   if(i==j){
      return 0;
   }
   if(dp[i][j]!=-1){
      return dp[i][j];
   }
   ll min_cost=(1LL<<60);
   for(int k=i;k<j;k++){
       min_cost=min(min_cost,sum[i][j]+solve(v,i,k)+solve(v,k+1,j));
   }
  return dp[i][j]=min_cost;

}



int main() {
  
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
  int n;
  cin>>n;
  memset(dp,-1,sizeof dp);
  vector<int> v(n+1);
  for(int i=1;i<=n;i++){
      cin>>v[i];
  }
  prepocess(v,n);
  cout<<solve(v,1,n)<<endl;
  return 0;

}    

Measured memory_bytes: 76192
import bisect

N,M,K = map(int,input().split())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))

AList.append(10**10)
BList.append(10**10)

ASList = [AList[0]]
for i in range(1,N+1):
  a = ASList[-1] + AList[i]
  if a > 10 **10:
    a = 10 **10
  ASList.append(a)

BSList = [0,BList[0]]
for i in range(1,M+1):
  a = BSList[-1] + BList[i]
  if a > 10 **10:
    a = 10 **10
  BSList.append(a)  
  
ans = 0
for i in range(M+2):
  b = BSList[i]
  c = int( K-b )
  if c > 0:
    d = bisect.bisect_left(ASList,c)
    if ASList[d] == c:
      d +=1 
    ans = max(ans,i+d)
  elif c == 0:
    ans = max(ans,i)
  else:
    d = bisect.bisect_left(ASList,K)
    ans = max(ans,d)
  
print(int(ans))

Measured memory_bytes: 41528
let cnt = ref 0

let selection_sort a n =
  let swap i j = let t = a.(i) in a.(i) <- a.(j); a.(j) <- t in
  for i = 0 to n - 1 do
    let mini = ref i in
    for j = i to n - 1 do
      if a.(j) < a.(!mini) then mini := j;
    done;
    if !mini <> i then begin
      swap i !mini;
      incr cnt;
    end;
  done

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let a = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in
  selection_sort a n;
  Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) a;
  print_newline ();
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 2292
#include <bits/stdc++.h>
#define int long long
const int magic = 1e9;
using namespace std;
int a1, b1, a2, b2, a3, b3;
int S;
signed main()
{
	cin >> S;
	if(S <= magic)
		return cout << 1 << ' ' << 1 << ' ' << S << ' ' << 0 << ' ' << 0 << ' ' << 0, 0;
	
	int tmp = magic - (S % magic);
	if(S % magic == 0)
		tmp = 0;
	
	a2 = (S + tmp)/magic;
	b1 = magic;
	a1 = tmp;
	b2 = 1;

	cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << ' ' << 0 << ' ' << 0;

	
}

Measured memory_bytes: 256
n=input()
L=[int(x) for x in input().split()]

t=0
for i in range(len(L)-2):
  for j in range(i+1,len(L)-1):
    for k in range(j+1,len(L)):
      if L[i]==L[j] or L[j]==L[k] or L[k]==L[i]:
        continue
      if L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[i]+L[j]:
        t+=1

print(t)


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

struct tes{
int i,j,k,r;
};
int data[500];

int main(){
	
	
	int a,b,c,N,n;
while(cin>>a>>b>>c &&a &&b&&c){
vector<tes> in;
for(int i=0;i<500;i++)data[i]=2;
	cin>>N;
	n=a+b+c;
	
	for(int i=0;i<N;i++){
		tes tmp;
		cin>>tmp.i>>tmp.j>>tmp.k>>tmp.r;
		in.push_back(tmp);
	}
	
	bool up_date=true;;
	while(up_date){
		up_date=false;
		for(int i=0;i<N;i++){
			tes tmp=in[i];
			if(tmp.r==1 &&(data[tmp.i]!=1 || data[tmp.j]!=1 || data[tmp.k]!=1)){
				data[tmp.i]=1;
				data[tmp.j]=1;
				data[tmp.k]=1;
				up_date=true;
			}
			else{
					if(data[tmp.i]==1 && data[tmp.j]==1 &&data[tmp.k]==2){
						data[tmp.k]=0;
						up_date=true;
					}
					else if(data[tmp.j]==1 && data[tmp.k]==1 && data[tmp.i]==2){data[tmp.i]=0;up_date=true;}
					else if(data[tmp.i]==1 && data[tmp.k]==1 && data[tmp.j]==2){up_date=true;data[tmp.j]=0;}
					
				
			}
		}
	}
	
	for(int i=1;i<=n;i++)cout<<data[i]<<endl;
	
	}
}

Measured memory_bytes: 1248
n, m = gets.chop.split.map(&:to_i)

# aを小さいものから書き換えていくため、ソート
# 合計N回までしか操作しないので、O(N)
a = gets.chop.split.map(&:to_i).sort

bc = []

m.times do |i|
  bc << gets.chop.split.map(&:to_i)
end

bc.sort_by!{|x| x[1]}.reverse!

# aを見るインデックス
idx = 0

bc.each do |b, c|
  break if a[idx] >= c
  b.times do |i|
    if a[idx] < c
      a[idx] = c
    end
    idx +=1
    break if idx == n
  end
  break if idx == n
end

p a.inject(:+)



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

signed main()
{
  string a, b, c;
  cin >> a >> b >> c;

  if (a[a.size() - 1] == b[0]) {
    if (b[b.size() - 1] == c[0]) {
      cout << "YES" << endl;
    }
    else {
      cout << "NO" << endl;
    }
  }
  else {
    cout << "NO" << endl;
  }

  return (0);
}

Measured memory_bytes: 256