akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        int Q = scan.nextInt();
        boolean order = true;
        Deque<Character> prefix = new LinkedList<>();
        Deque<Character> postfix = new LinkedList<>();
        for (int i = 0; i < Q; i++) {
            int type = scan.nextInt();
            if (type == 1) {
                order = !order;
                continue;
            }
            int F = scan.nextInt();
            char c = scan.next().toCharArray()[0];
            if (order) {
                if (F == 1) {
                    prefix.addLast(c);
                } else {
                    postfix.addLast(c);
                }
            } else {
                if (F == 1) {
                    postfix.addLast(c);
                } else {
                    prefix.addLast(c);
                }
            }
        }
        StringBuilder t = new StringBuilder();
        t.append(S);
        StringBuilder ans = new StringBuilder();
        if (order) {
            while(!prefix.isEmpty()) {
                ans.append(prefix.pollLast());
            }
            ans.append(t.toString());
            while(!postfix.isEmpty()) {
                ans.append(postfix.pollFirst());
            }
        } else {
            while(!postfix.isEmpty()) {
                ans.append(postfix.pollLast());
            }
            ans.append(t.reverse().toString());
            while(!prefix.isEmpty()) {
                ans.append(prefix.pollFirst());
            }
        }
        System.out.println(ans.toString());
    }
}


Measured memory_bytes: 158180
n, t = map(int, input().split())
clst = []
tlst = []
for i in range(n):
    cc, tt = map(int, input().split())
    if tt <= t:
        clst += [cc]
        tlst += [tt]
if len(clst) > 0:
    print(min(clst))
else:
    print('TLE')

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=0;i<=n;++i)
#define INF 10000000000
#define ll long long

using namespace std;

typedef pair<int, ll int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct edge{
    int to;
    ll int cost;
};

int N, M;
int L, R, D;
ll int x[100001];
bool res;

vector<edge> G[100001];

void bfs(int k){
    queue<P> que;
    que.push(P(k, 0));
    x[k] = 0;
    
    while(!que.empty()){
        P p = que.front(); que.pop();
        int v = p.first;

        REP(i, G[v].size()){
            edge e = G[v][i];
            if(x[e.to] == INF){
                x[e.to] = x[v] + e.cost;
                que.push(P(e.to, x[e.to]));
            } else if (x[e.to] != x[v] + e.cost){
                res = false;
            }
        }
    }
}

int main(){
    scanf("%d%d", &N, &M);
    REP(i, M){
        scanf("%d%d%d", &L, &R, &D);
        G[L].push_back(edge{R, D});
        G[R].push_back(edge{L, -D});
    }

    rep(i, N) x[i] = INF;
    res = true;

    rep(i, N){
        if(x[i] == INF && G[i].size() != 0) bfs(i);
    }

    if(res){
        printf("Yes\n");
    } else {
        printf("No\n");
    }

	return 0;
}


Measured memory_bytes: 14448
#include<stdio.h>

int main()
{
	int a[4],b[4],hit,brow;

	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF)
	{
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		hit=0;
		brow=0;

		if(a[0]>9||a[1]>9||a[2]>9||a[3]>9||b[0]>9||b[1]>9||b[2]>9||b[3]>9)
		{
		}
		else if(a[0]<0||a[1]<0||a[2]<0||a[3]<0||b[0]<0||b[1]<0||b[2]<0||b[3]<0)
		{
		}
		else
		{
			for(int x=0;x<4;x++)
			{
				for(int y=0;y<4;y++)
				{
					if(a[x]==b[y])
					{
						if(x==y)
						{
							hit++;
						}
						else
						{
							brow++;
						}
					}
				}
			}
			printf("%d %d\n",hit,brow);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**9)

N,M = map(int,input().split())
E = [[] for _ in range(N)]
for i in range(M):
  x,y = map(int,input().split())
  x -= 1
  y -= 1
  E[x].append(y)
#print(E)

# dp[i]:頂点iを始点とする最長パスの長さ
dp = [-1 for _ in range(N)]

def rec(v):
  if dp[v] != -1:
    return dp[v]
  res = 0
  for u in E[v]:
    res = max(res, rec(u)+1)
  dp[v] = res
  return dp[v]

for i in range(N):
  rec(i)
print(max(dp))

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n, m;
PI a[100100];

int main() {
    cin >> n >> m;
    rep(i, m) {
        cin >> a[i].F >> a[i].S;
    }
    sort(a, a + m);
    li res = 1;
    li prev_max = a[0].S;
    repp(i, 1, m) {
        li nowf = a[i].F;
        if (nowf >= prev_max) {
            ++res;
            prev_max = a[i].S;
        } else {
            prev_max = min(prev_max, a[i].S);
        }
    }

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

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
 int A,B,C,X;
  cin>>A>>B>>C>>X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; 
        if (total == X) ++res; 
      }
    }
  }
  cout << res << endl;
    
    
}

Measured memory_bytes: 256
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)

n = int(input())
T = [int(input()) for i in range(n)]

ans = T[0]

for i in range(n):
    ans = ans*T[i]//gcd(ans,T[i])

print(ans)

Measured memory_bytes: 3060
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define ll long long
#define db double
#define ld long double
#define pp printf
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define pb push_back
#define sz size()
using namespace std;

vector<int> a[18][18];


int z[1 << 18];
int us[20], to[20];

void zh(int x, int y, int n) {
	ff(i, 0, n) us[i] = 0;
	ff(i, 0, n) {
		ff(j, 0, n) if((x >> i & 1) == (y >> j & 1) && !us[j])
			{ us[j] = 1; to[i] = j; break;}
	}
	ff(i, 0, 1 << n) {
		int s = 0;
		ff(j, 0, n) s += (i >> j & 1) * (1 << to[j]);
		z[i] = s;
	}
}

int n, x, y, c;

void pr(int x, int n) {
	fd(i, n - 1, 0) pp("%d", x >> i & 1); pp(" ");
}

int main() {
	n = 17;
	a[1][1].pb(0); a[1][1].pb(1);
	fo(i, 2, n) {
		int mx = 1 << (i - 1);
		ff(k, 0, a[i - 1][1].sz)
			a[i][1].pb(a[i - 1][1][k]);
		fd(k, a[i - 1][1].sz - 1, 0)
			a[i][1].pb(a[i - 1][1][k] + mx);
			
		for(int j = 3; j <= i; j += 2) {
			ff(k, 0, a[i - 1][j - 2].sz)
				a[i][j].pb(a[i - 1][j - 2][k]);
			int h = a[i - 1][j - 2][a[i - 1][j - 2].sz - 1];
			zh(1 << (i - 2), 1 << (i - j), i - 1);
			ff(k, 0, a[i - 1][1].sz)
				a[i][j].pb((z[a[i - 1][1][k]] ^ h) + (1 << (i - 1)));
		}
	}
	scanf("%d %d %d", &n, &x, &y);
	ff(i, 0, n) c += (x ^ y) >> i & 1;
	if(c % 2 == 0) {
		pp("NO\n"); return 0;
	}
	pp("YES\n");
//	ff(k, 0, a[4][3].sz) pr( a[4][3][k], 4), pp("\n");
	zh(a[n][c][a[n][c].sz - 1], x ^ y, n);
//	ff(k, 0, a[n][c].sz) pr( z[a[n][c][k]] ^ x, n); pp("\n");
	ff(k, 0, a[n][c].sz) pp("%d ", z[a[n][c][k]] ^ x);
	
}

Measured memory_bytes: 10744
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;

  int cnt[26];
  for (int i = 0; i < 26; i++) {
    cnt[i] = 0;
  }
  for (int i = 0; i < s.length(); i++) {
    cnt[s[i] - 'a']++;
  }
  bool dif = true;
  for (int i = 0; i < 26; i++) {
    if (!(cnt[i] == 0 || cnt[i] == 1)) {
      dif = false;
    }
  }

  if (dif) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
x = A[0]
y = sum(A[1:])
ans = abs(x - y)
for i in range(1, N - 1):
    a = A[i]
    x += a
    y -= a
    dif = abs(x - y)
    if dif < ans:
        ans = dif
print(ans)

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

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

int main() {
    ll h,w;cin>>h>>w;
    ll x;x=1000000007;
    string a[h];
    for(ll i=0;i<h;i++){
        cin>>a[i];
    }
    ll dp[h][w];
    bool b;b=true;
    for(ll i=0;i<w;i++){
        if(b){
            if(a[0][i]=='.'){
                dp[0][i]=1;
            }else{
                dp[0][i]=0;
                b=false;
            }
        }else{
            dp[0][i]=0;
        }
    }
    b=true;
    for(ll i=0;i<h;i++){
        if(b){
            if(a[i][0]=='.'){
                dp[i][0]=1;
            }else{
                dp[i][0]=0;
                b=false;
            }
        }else{
            dp[i][0]=0;
        }
    }
    for(ll i=1;i<h;i++){
        for(ll j=1;j<w;j++){
            if(a[i][j]=='.'){
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%x;
            }else{
                dp[i][j]=0;
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
    return 0;
}


Measured memory_bytes: 9088
//A
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
	reg ll s = 0, t = 0; reg char ch = getchar();
	while (!isdigit(ch)) t |= ch == '-', ch = getchar();
	while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return t ? -s : s;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
	return 0;	
}

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

typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int MID = 1e5 + 3;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int main(){
    speed;
    int n, t;
    cin >> n >> t;
    ll s = t;
    ll l = t;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        if(x > l){
            s += t;
        }
        else{
            s += x + t - l;
        }
        l = x + t;
    }
    cout << s;
}

Measured memory_bytes: 3648
import java.util.*; 
public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        while(true){
            int n; 
            n = sc.nextInt();
            if(n==0){
                System.exit(0);
            }
            int[] s;
            int i=0;
            s=new int[n];
            while(i<n){
                s[i]=sc.nextInt();
                i++;
            }
            Arrays.sort(s);
            i=1;
            int sum=0;
            while(i<n-1){
                sum+=s[i];
                i++;
            }
            System.out.println(sum/(n-2));
        }
    }
}


Measured memory_bytes: 29500
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a[3 * n];
    for(int i = 0; i < 3 * n; i++){
        cin >> a[i];
    }
    sort(a,a+3 * n);
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += a[3 * n - 2 * i];
    }
    cout << ans << endl;
}



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

int main() {
    int N;
    cin >> N;
    vector<int> score;
    int s,sum=0;
    for(int i=0;i<N;i++){
        cin >> s;
        sum+=s;
        score.push_back(s);
    }
    sort(score.begin(),score.end());
    int num=0;
    if(sum%10==0){
        for(int i=0;i<N;i++){
            if(score[i]%10!=0) {
                num=score[i];
                break;
            }
            else if(i==N-1) num=sum;
        }
    }
    cout << sum-num << endl;
}

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

int main()
{
	int day[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	for (int i = 1; i < 12; i++) {
		day[i] += day[i - 1];
	}
	int mo, da;
	while (cin >> mo >> da, mo | da) {
		switch ((day[mo - 1] + da - 1) % 7)
		{
		case 0:
			cout << "Thursday" << endl;
			break;
		case 1:
			cout << "Friday" << endl;
			break;
		case 2:
			cout << "Saturday" << endl;
			break;
		case 3:
			cout << "Sunday" << endl;
			break;
		case 4:
			cout << "Monday" << endl;
			break;
		case 5:
			cout << "Tuesday" << endl;
			break;
		case 6:
			cout << "Wednesday" << endl;
			break;
		default:
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 2972
from collections import deque
h,w = map(int,input().split())
l = []
for i in range(h):
    s = list(input())
    l.append(s)
q = deque()
s = [[1,0],[0,1],[-1,0],[0,-1]]
def aaa(i,j,h,w):
    if i >= 0 and i <= h-1 and j >= 0 and j <= w-1:
        return True
    else:
        return False
ans = []
for i in range(h):
    for j in range(w):
        if l[i][j] == ".":
            rl = [[-1 for i in range(w)] for j in range(h)]
            rl[i][j] = 0
            q.append([i,j])
            while len(q) > 0:
                a,b = deque.popleft(q)
                for x in s:
                    if aaa(a+x[0],b+x[1],h,w):
                        if l[a+x[0]][b+x[1]] == ".":
                            if rl[a+x[0]][b+x[1]] >= 0:
                                rl[a+x[0]][b+x[1]] = min(rl[a+x[0]][b+x[1]],rl[a][b]+1)
                            else:
                                rl[a+x[0]][b+x[1]] = rl[a][b]+1
                                q.append([a+x[0],b+x[1]])
            for y in range(h):
                ans.append(max(rl[y]))
print(max(ans))

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

int main() {
    int n;
    cin >> n;
    if(n%2 == 0) cout << n << endl;
    else cout << n*2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int N;
int A[100];
int main(void){
    cin >> N ;
    REP(i,N) cin >> A[i];

    int count = 0;
    REP(i,N){
        if (A[i]%2==0){
            if (A[i] % 3 != 0 and A[i] % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  private static final Scanner in = new Scanner(System.in);

  public static void main(String[] args) {
    int n = in.nextInt();
    int k = in.nextInt();
    int[] arr = new int[k];
    for (int i = 0; i < k; i++) {
      arr[i] = in.nextInt();
    }
    solve(n, arr);
  }

  private static void solve(int n, int[] arr) {
    if (arr.length == 10){
      System.out.println(n);
      return;
    }
    for (int i = n; true; i++) {
      for (int j = 0; j < arr.length; j++) {
        if (String.valueOf(i).contains(String.valueOf(arr[j]))) {
          break;
        }
        if (j == arr.length - 1) {
          System.out.println(i);
          return;
        }
      }
    }
  }


}


Measured memory_bytes: 37408
N = int(input())
s = input().split()
s = [int(i) for i in s]
ans = []
for i in range(N):
    ans_sub = 0
    while s[i] / 2 == int(s[i] / 2) : 
        ans_sub += 1
        s[i] /= 2
    ans.append(ans_sub)
print(min(ans))


Measured memory_bytes: 2940
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

//#include <vector>
//#include <set>
//#include <map>
//#include <iostream>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

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

int main(void)
{
	//変数の宣言
	ll int a[10];
//
	//よく使う変数
	int i,j,k;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;


	//データの読み込み
//	scanf("%d %d %d",&n,&m,&q);
//	scanf_s("%d %d %d",&n,&m,&q);

	for(i=0;i<7;i++){
		scanf("%lld",&a[i]);
//		scanf_s("%lld",&a[i]);
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	if(a[0]%2+a[3]%2+a[4]%2<2||a[0]==0||a[3]==0||a[4]==0){
		ans=a[0]/2*2+a[3]/2*2+a[4]/2*2+a[1];
	}else{
		ans=3+(a[0]-1)/2*2+(a[3]-1)/2*2+(a[4]-1)/2*2+a[1];
	}


	//	printf("計算部分終了\n");

	//出力

	printf("%lld",ans);

	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 128
import java.io.*;
import java.util.*;
class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = br.readLine();
    String[] a = line.split(" ");
    List<Integer> list = new ArrayList<Integer>();
    for (String f : a) {
      list.add(Integer.parseInt(f));
    }
    Collections.sort(list);
    System.out.println
      (list.get(0) + " " + list.get(1) + " " + list.get(2));
  }
}

Measured memory_bytes: 24248
#include <iostream>
using namespace std;
int main(){
    int n,tree[1000000]={};
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>tree[i];
    }
    for(int i=1;i<=n;i++){
        cout<<"node "<<i<<": key = "<<tree[i]<<", ";
        if(tree[i/2]!=0){
            cout<<"parent key = "<<tree[i/2]<<", ";
        }
        if(tree[2*i]!=0){
            cout<<"left key = "<<tree[2*i]<<", ";
        }
        if(tree[(2*i)+1]!=0){
            cout<<"right key = "<<tree[(2*i)+1]<<", ";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 6992
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    char[] r1 = sc.next().toCharArray();
    char[] r2 = sc.next().toCharArray();
    sc.close();

    int i;
    long count;
    boolean prev;
    if (r1[0]==r2[0]) {
      i=1;
      count=3;
      prev=true;
    } else {
      i=2;
      count=6;
      prev=false;
    }
    for (; i<n; i++) {
      if (r1[i]==r2[i]) {
        if (prev)
          count = mulmod(count,2);
        prev=true;
      } else {
        if (prev)
          count = mulmod(count,2);
        else
          count = mulmod(count,3);
        prev=false;
        i++;
      }
    }
    System.out.println(count);
  }

  private static long mulmod(long a, long b) {
    final long MOD = 1000000007;
    return ((a%MOD) * (b%MOD)) % MOD;
  }
}

Measured memory_bytes: 23892
#include<stdio.h>
int main()
{
    int a , i;
    double b , c=0;
    scanf("%d",&a);
    for(i=0;i<a;i++)
    {
        scanf("%lf",&b);
        c = c+(1/b);
    }
    printf("%lf\n",1/c);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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

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

int main()
{
    long long n, m;
    cin >> n >> m;
    if (n * 2 <= m)
    {
        cout << n + (m - n * 2) / 4 << endl;
    }
    else
    {
        cout << m / 2 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  int N, C, K;
  cin >> N >> C >> K;
  int T[N];
  rep(i, 0, N) cin >> T[i];
  sort(T, T+N);

  int ans   = 1;
  int start = T[0];
  int count = 1;
  rep(i, 1, N) {
    if (start+K < T[i]  || C == count) {
      ans++;
      start = T[i];
      count = 1;
      continue;
    }
    count++;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 640
use proconio::{input, fastout};
use num::BigInt;
// use itertools::Itertools;

#[fastout]
fn main() {
  input!{
    n: usize,
    mut aa: [u64; n]
  };

  let mut ans = BigInt::from(1 as u64);
  let max = BigInt::from(1e18 as u64);
  aa.sort();
  if aa[0] == 0 {
    println!("0");
    return;
  }
  for a in aa {
    let a = BigInt::from(a);
    ans = ans * a;
    if ans > max {
      println!("-1");
      return;
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 5488
#include<iostream>
using namespace std;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int main()
{
  string str;
  cin >> str;
  long num = 0;
  for(int i = 0; i < (int)str.size(); i++){
    char ch = str.at(i);
    num = num + ctoi(ch);
  }
  if((num % 9) > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 1000000000
typedef long long int lli;
typedef pair<int,int> P;

int dp[152][1001][76];
int s[152][1001];
int abs(int x){
	if(x<0) return -1*x;
	else return x;
}

int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		for(int i=1; i<=n; ++i){
			for(int j=1; j<1001; ++j){
				s[i][j]=INF;
				for(int k=0; k<=m; ++k){
					dp[i][j][k]=INF;
				}
			}
		} 
		for(int i=1; i<=n; ++i){
			int k;
			cin >> k;
			for(int j=0; j<k; ++j){
				int t1,t2;
				cin >> t1 >> t2;
				s[i][t1]=t2;
			}
		}
		for(int i=1; i<1001; ++i){
			if(s[1][i]!=INF) dp[1][i][0]=0;
		}
		for(int i=1; i<1001; ++i){
			if(s[2][i]!=INF){
				for(int j=1; j<1001; ++j){
					if(s[1][j]!=INF){
						dp[2][i][0]=min(dp[2][i][0],(s[2][i]+s[1][j])*abs(i-j));
					}
				}
				dp[2][i][1]=0;
			}
		}
		for(int i=3; i<=n; ++i){
			for(int j=1; j<1001; ++j){
				if(s[i][j]!=INF){
					for(int k=0; k<=m; ++k){
						for(int l=1; l<1001; ++l){
							if(s[i-1][l]!=INF&&dp[i-1][l][k]!=INF){
								dp[i][j][k]=min(dp[i][j][k],(s[i-1][l]+s[i][j])*abs(j-l)+dp[i-1][l][k]);
							}
							if(s[i-2][l]!=INF&&k!=0&&dp[i-2][l][k-1]!=INF){
								dp[i][j][k]=min(dp[i][j][k],(s[i-2][l]+s[i][j])*abs(j-l)+dp[i-2][l][k-1]);
							}
						}
					}
				}
			}
		}
		int ans=INF;
		for(int i=1; i<1001; ++i){
			for(int j=0; j<=m; ++j){
				ans=min(ans,dp[n][i][m]);
				if(j<m) ans=min(ans,dp[n-1][i][j]);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 46332
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[51],b[51];
int dp[1<<18][51];
int INF=1<<25;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<=50;j++){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(int i=0;i<(1<<n);i++){
		int pos=__builtin_popcount(i);
		for(int j=0;j<=50;j++){
			if(dp[i][j]==INF)continue;
			int t_pos=0;
			//printf("%d %d %d %d\n",i,j,dp[i][j],pos);
			for(int k=0;k<n;k++){
				if((i>>k) & 1)continue;
				int flag=(k-pos+100)%2;
				//printf("k=%d flag=%d t_pos=%d\n",k,flag,t_pos);
				if(flag==0){
					if(j<=a[k]){
						dp[i+(1<<k)][a[k]]=min(dp[i+(1<<k)][a[k]],dp[i][j]+t_pos);
					}
				}else{
					if(j<=b[k]){
						dp[i+(1<<k)][b[k]]=min(dp[i+(1<<k)][b[k]],dp[i][j]+t_pos);
					}
				}
				t_pos++;
			}
		}
	}
	int ans=INF;
	for(int i=0;i<=50;i++){
		ans=min(ans,dp[(1<<n)-1][i]);
	}
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}


Measured memory_bytes: 52480
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();

		if((x+r<=W) && (x-r>=0) && (y+r<=H) && (y-r>=0)){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

int x,y,z;

signed main() {
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

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

int gcd(int a, int b);
int gcd(const std::vector<int>& arr);

int main() {

        int x, a;
        std::cin >> x >> a;
        if (x < a) {
                std::cout << 0 << std::endl;
        }
        else {
                std::cout << 10 << std::endl;
        }
        return 0;
}

int gcd(int a, int b) {
        if (a > b) {
                std::swap(a, b);
        }

        for (int r = b % a; r != 0; b = a, a = r, r = b % a)
                ;

        return a;
}

int gcd(const std::vector<int>& arr) {
        const int size = arr.size();
        if (size == 0) {
                return 0;
        }
        else if (size == 1) {
                return arr[0];
        }

        int ret = gcd(arr[0], arr[1]);

        for (std::size_t i = 2; i < size && ret != 1; ++i) {
                ret = gcd(arr[i], ret);
        }

        return ret;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    list<int> l;
    REP(i, N) {
        if (i & 1) {
            l.push_front(a[i]);
        } else {
            l.push_back(a[i]);
        }
    }
    if (N & 1)
        reverse(ALL(l));
    for (auto x : l) {
        cout << x << " ";
    }
}

Measured memory_bytes: 10344
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    ll N;
    cin >> N;
    ll ans = 0;
    for (ll i = 2; i*i <= N; i++) {
        if (N%i == 0) {
            ll cnt = 0;
            while (N%i == 0) {
                cnt++;
                N /= i;
            }
            ll tmp = 1;
            while (cnt >= tmp) {
                ans++;
                cnt -= tmp;
                tmp++;
            }

        }
    }

    if (N > 1) ans++;
    cout << ans << "\n";
}

Measured memory_bytes: 3648
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		 Scanner scn = new Scanner(System.in);
		    int a = scn.nextInt();
		    int b = scn.nextInt();
		    int c =scn.nextInt();
		if(a<b & b<c) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26376
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n;
int main(){
	cin>>n;
	ll sum=0;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ll k=n/i;
			k-=1;
			if(k>0 && n%k==n/k) sum+=k;
			if(i-1>0 && n/(i-1)==n%(i-1)) sum+=i-1;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,X=get_i
a=get_i
ans=0
(N-1).times do|i|
  if a[i]+a[i+1]>X
    val=X-a[i]
    if val<0
        ans+=a[i+1]
        a[i+1]=0
        ans-=val
        a[i]+=val
    else

    ans+=a[i+1]-val
    a[i+1]=val 
    end
  end
end
puts ans

Measured memory_bytes: 9612
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int A[100000],n;

int main(){
  int sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];

  int q, k;
  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> k;
    if(*lower_bound(A, A + n, k) == k) sum++;
  }

  cout << sum << endl;

  return 0;
}





Measured memory_bytes: 3384
using System;
using static System.Console;

class Program {
	static void Main() {
		var X = int.Parse(ReadLine());
		var ans = 1;

		for (var b = 2; b * b <= X; b++) {
			for (var p = 2; ; p++) {
				if (Math.Pow(b, p) > X) {
					break;
				}
				ans = Math.Max(ans, (int)Math.Pow(b, p));
			}
		}
		WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, M, L;
    cin >> N >> M >> L;
    struct Edge {
        Edge(ll t, ll c) : to(t), cost(c) {}
        ll to, cost;
    };
    vector<vector<Edge>> edges(N);
    for (ll i = 0; i < M; i++) {
        ll A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        edges[A].emplace_back(B, C);
        edges[B].emplace_back(A, C);
    }

    ll Q;
    cin >> Q;
    vector<ll> s(Q), t(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> s[i] >> t[i];
        s[i]--; t[i]--;
    }

    constexpr ll INF = LLONG_MAX / 10;
    struct Element {
        ll node, refueling_num, curr_l;
        bool operator<(const Element& rhs) const {
            return (refueling_num != rhs.refueling_num ? refueling_num < rhs.refueling_num : curr_l > rhs.curr_l);
        }
        bool operator>(const Element& rhs) const {
            return (refueling_num != rhs.refueling_num ? refueling_num > rhs.refueling_num : curr_l < rhs.curr_l);
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;

    vector<vector<ll>> ans(N, vector<ll>(N));

    for (ll i = 0; i < N; i++) {
        vector<pair<ll, ll>> cost(N, { INF, INF });
        cost[i] = { 0, L };
        pq.push({ i, cost[i].first, cost[i].second });
        while (!pq.empty()) {
            Element top = pq.top();
            pq.pop();
            if (top.refueling_num > cost[top.node].first
                || (top.refueling_num == cost[top.node].first && top.curr_l > cost[top.node].second)) {
                continue;
            }

            for (const Edge& e : edges[top.node]) {
                ll refueling_num = (top.curr_l >= e.cost ? top.refueling_num : top.refueling_num + 1);
                ll curr_l = (top.curr_l >= e.cost ? top.curr_l - e.cost : L - e.cost);
                if (curr_l < 0) {
                    continue;
                }

                pair<ll, ll> p = make_pair(refueling_num, curr_l);
                if (p.first < cost[e.to].first
                || (p.first == cost[e.to].first && p.second > cost[e.to].second)) {
                    cost[e.to] = p;
                    pq.push({ e.to, p.first, p.second });
                }
            }
        }

        for (ll j = 0; j < N; j++) {
            ans[i][j] = cost[j].first;
        }
    }

    for (ll i = 0; i < Q; i++) {
        cout << (ans[s[i]][t[i]] == INF ? -1 : ans[s[i]][t[i]]) << endl;
    }
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
while True:
    try:
        n = int(raw_input())
        case = 0
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a + b + c + d == n:
                            case += 1
        print(case)
    except EOFError:
        break

Measured memory_bytes: 5020
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=300010;
const int inf=2147483647;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*f;
}
LL n,a,b;
int main()
{
	n=read(),a=read(),b=read();
	if(a+b>n+1)return puts("-1"),0;
	if((b-1)*a<n-a)return puts("-1"),0;
	if(b==1)
	{
		if(a!=n)return puts("-1"),0;
		for(int i=1;i<=n;i++)printf("%d ",i);
		return 0;
	}
	int t=(n-a)/(b-1),r=(n-a)%(b-1),cur=n-a;
	for(int i=1;i<=a;i++)printf("%d ",n-a+i);
	for(int j=1;j<b;j++)
	{
		int len=((j<=r)?(t+1):t);
		for(int k=1;k<=len;k++)printf("%d ",cur-len+k);
		cur-=len;
	}
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;


int main() {
    ios_base::sync_with_stdio(false);
    int n, a, b, c, d;
    cin >> n;
    d = n%10;
    n/=10;
    c = n%10;
    n/=10;
    b = n%10;
    n/=10;
    a = n%10;
    n/=10;
    if (a+b+c+d == 7) {
        cout << a << '+' << b << '+' << c << '+' << d << "=7" <<  endl;
    } else if (a+b+c-d == 7) {
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
    } else if (a+b-c-d == 7) {
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
    } else if (a-b-c-d == 7) {
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
    } else if (a+b-c+d == 7) {
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
    } else if (a-b-c+d == 7) {
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
    } else if (a-b+c+d == 7) {
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
    } else if (a-b+c-d == 7) {
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 21;

int N;

ll dp[1 << MAX_N];
int A[MAX_N][MAX_N];

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

    cin >> N;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    dp[0] = 1;

    for (int j = 1; j < (1 << N); j++) {
        int S = 0;
        for (int k = 0; k < N; k++) {
            if ((j & (1 << k)))
                S++;
        }
        ll res = 0;
        for (int k = 0; k < N; k++) {
            if ((j & (1 << k)) && A[S - 1][k]) {
                res = (res + dp[j & ~(1 << k)]) % MOD;
            }
        }
        dp[j] = res;
    }

    cout << dp[(1 << N) - 1] << "\n";

    return 0;
}

Measured memory_bytes: 20020
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  string a;
  cin>>a;
  int b=0;
  rep(i,a.size()){
  if(a[i]=='o')
    b++;
  }
  YESNO(b+15-a.size()>=8);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll A[200010];

int main(){
   ll N,K;
   cin >> N >> K;
   rep(i,N) cin >> A[i];
   FOR(i,K,N){
      if(A[i-K] < A[i]) cout << "Yes" << endl;
      else cout << "No" << endl;
   }
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int a[]={111,222,333,444,555,666,777,888,999};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	int ptr = lower_bound(begin(a),end(a),n)-begin(a);
	cout << a[ptr] << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
N,W = map(int,input().split())
v1 = []
v2 = []
v3 = []
v4 = []
w1,v = map(int,input().split())
v1.append(v)
for i in range(N-1):
    w,v = map(int,input().split())
    if w == w1:
        v1.append(v)
    elif w == w1 + 1:
        v2.append(v)
    elif w == w1 + 2:
        v3.append(v)
    elif w == w1 + 3:
        v4.append(v)
v1.sort(reverse=True)
v2.sort(reverse=True)
v3.sort(reverse=True)
v4.sort(reverse=True)

l1 = len(v1)
l2 = len(v2)
l3 = len(v3)
l4 = len(v4)
ans = 0
for i in range(l1+1):
    for j in range(l2+1):
        for k in range(l3+1):
            for l in range(l4+1):

                if i*w1 + j*(w1+1) + k*(w1+2) + l*(w1+3) <= W:
                    temp = sum(v1[:i]) + sum(v2[:j]) + sum(v3[:k]) + sum(v4[:l])
                    ans = max(ans,temp)
print(ans)

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

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

const int MAX_N = 2505;
const int MAX_M = 5005;
const int INF = 1e9;
const int MOD = 1e9 + 7;

class edge{
    public:
        int from, to, cost;
};

int N, M, P;
vector<int> Gfrom1[MAX_N], GtoN[MAX_N];
edge edges[MAX_M];
bool ok1[MAX_N], okN[MAX_N];

ll ans;

void dfs(int n){
    ok1[n] = true;
    for(int i : Gfrom1[n]){
        if(!ok1[i]) dfs(i);
    }
}

void rdfs(int n){
    okN[n] = true;
    for(int i : GtoN[n]){
        if(!okN[i]) rdfs(i);
    }
}

int main(){
    cin >> N >> M >> P;
    rep(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        Gfrom1[a].push_back(b);
        GtoN[b].push_back(a);

        edge e;
        e.from = a;
        e.to = b;
        e.cost = c - P;
        e.cost = -e.cost;
        edges[i] = e;
    }

    dfs(0);
    rdfs(N-1);

    ll d[MAX_N];
    rep(i, N) d[i] = INF;
    d[0] = 0;
    bool flg = true;
    rep(i, N){
        flg = false;
        rep(j, M){
            edge e = edges[j];
            if(!ok1[e.from] or !okN[e.to]) continue;
            if(d[e.from] + e.cost < d[e.to]){
                flg = true;
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }

    if(flg){
        cout << -1 << endl;
        return 0;
    }

    ll ans = max((ll)0, -d[N-1]);

    cout << ans << endl;
}

Measured memory_bytes: 640
_,m,*A=`dd`.split.map &:to_i;D=[s=0]*l=3*m
A.each_cons(2){|a,b|b<a&&b+=m;s+=k=b-a;D[a+2]+=1;D[b+1]-=k;D[b+2]+=k-1}
(2*l).times{|i|D[i%l]+=D[~-i%l]};p s-A.map{|a|D[a]+D[a+m]}.max

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    string s;
    cin >> s;
    if (s[0] == 'S')
        cout << "Cloudy\n";
    else if (s[0] == 'C')
        cout << "Rainy\n";
    else if (s[0] == 'R')
        cout << "Sunny\n";
    return 0;
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:04:22 2018
ALDS1_3b_r リングバッファによる実装
@author: maezawa
"""

def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
    
def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data

fifo_size = 100000
fifo = [0 for _ in range(fifo_size)]
head = 0
tail = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    data = [s[0], int(s[1])]
    fifo_enque(data)
    
current_time = 0
finished = []
fin_time = []

while True:
    data = fifo_deque()
    if data[1] > q:
        current_time += q
        data[1] -= q
        fifo_enque(data)
    else:
        current_time += data[1]
        finished.append(data[0])
        fin_time.append(current_time)
    if head == tail:
        break

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))
        




Measured memory_bytes: 15668