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

public final class Main {
    
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int m = in.nextInt();
        final int x = in.nextInt();
        in.nextLine();
        int[][] books = new int[n][m + 1];
        int[] max = new int[m];
        for (int i = 0; i < n; i++) {
            int[] book = new int[m + 1];
            for (int z = 0; z < m + 1; z++) {
                book[z] = in.nextInt();
                if (z > 0) {
                    max[z - 1] += book[z];
                }
            }
            in.nextLine();
            books[i] = book;
        }
        if (Arrays.stream(max).anyMatch(skill -> skill < x)) {
            System.out.println(-1);
            return;
        }
        int [] res = { (int) 1e9 };
        knapsack(books, new int[m], x, 0, 0, new boolean[n], res);
        System.out.println(res[0]);
    }

    private static void knapsack(int[][] books, int[] pick, int x, int i, int cost, boolean[] taken, int[] res) {
        if (Arrays.stream(pick).noneMatch(tt -> tt < x)) {
            res[0] = Math.min(res[0], cost);
        }
        for (int t = i; t < books.length; t++) {
            if (!taken[t]) {
                taken[t] = true;
                for (int z = 1; z < books[t].length; z++) {
                    pick[z - 1] += books[t][z];
                }
                knapsack(books, pick, x, t, cost + books[t][0], taken, res);
                taken[t] = false;
                for (int z = 1; z < books[t].length; z++) {
                    pick[z - 1] -= books[t][z];
                }
            }
        }
    }
}


Measured memory_bytes: 40548
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  int n, y,k;
  cin >> n >> y;
  for (int i = 0; i < n+1; i++)
  {
    for (int j = 0; j < n+1-i; j++)
    {
      k = n - i - j;
      if(10000*i+5000*j+1000*k==y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


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

int main() {
    int H, W;

    while(1) {
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(int i = 1; i <= H; i++) {
            for(int j = 1; j <= W; j++) {
                if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1) ) {
                    cout << "#" << flush;
                } else {
                    cout << "." << flush;
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
//long long mo = 1e9 + 7;
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}

int main(){
    long long X,r,p;
    cin >> X;
    bool flag = false;
    for(long long i=X; true;i++){
        if(is_prime(i)){
            p = i;
            break;
        }
    }

    cout << p << endl;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
 
 
public class Main{
     
	public static class Walk{
		int pos, time;

		public Walk(int pos, int time) {
			super();
			this.pos = pos;
			this.time = time;
		}
	}
	
    public static void main(String[] args){
    	final Scanner sc = new Scanner(System.in);
    	
    	final int N = sc.nextInt();
    	
    	int[] array = new int[N];
    	for(int i = 0; i < N; i++){
    		array[i] = sc.nextInt();
    	}
    	
    	int[] times = new int[N];
    	Arrays.fill(times, Integer.MAX_VALUE);
    	
    	LinkedList<Walk> queue = new LinkedList<Walk>();
    	queue.add(new Walk(0, 0));
    	
    	while(!queue.isEmpty()){
    		Walk walk = queue.poll();
    		
    		//System.out.println(walk.pos + " " + walk.time);
    		
    		if(times[Math.min(N - 1, walk.pos)] <= walk.time){
    			continue;
    		}
    		times[Math.min(N - 1, walk.pos)] = walk.time;
    		
    		int next = walk.pos + array[Math.min(N - 1, walk.pos)];
    		if(next != walk.pos){
    			queue.addFirst(new Walk(next, walk.time));
    		}else{
    			
    			if(walk.pos >= N - 1){
    				System.out.println(walk.time);
    				return;
    			}
    			
    			for(int i = 6; i >= 1; i--){
    				queue.addLast(new Walk(walk.pos + i, walk.time + 1));
    			}
    		}
    	}
    	
    }
     
}

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

int main(){
  string S;
  cin >> S;
  while(!S.empty()){
    if(S.substr(0,2)=="hi"){
      S.erase(0,2);
    }else{
      break;
    }
  }
  if(S.empty()){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k = map(int,input().split())
data = [0] * n
for i in range(k):
  d = int(input())
  A = list(map(int,input().split()))
  for ai in A:
    ai-=1
    data[ai] += 1
for di in data:
  if di == 0:
    ans += 1
print(ans)

Measured memory_bytes: 68188
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int pow(int n)
{
    int ans=1;
    while(n--)
        ans*=10;
    return ans;
}
int main()
{
    LL a,b=0;
    char ch[10];
    cin>>a>>ch;
    int k=0;
    for(int i=0;ch[i];i++)
    {
        if(ch[i]=='.')
            k=i;
        else b=b*10+(LL)(ch[i]-'0');
    }
    LL ans=a*b;
    if(k)
    {
        ans/=pow(strlen(ch)-k-1);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

int gcd(int a, int b){
    if(a % b == 0) return b;
    else return (gcd(b, a%b));
}



int main(){
    int a, b;
    cin >> a >> b;
    string str;
    cin >> str;
    rep(i, str.length()){
        if(i == a){
            if(str[i] != '-'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(str[i] == '-'){
                cout << "No" << endl;
                return 0;
            }
     
        }
    }
    cout << "Yes" << endl;
} 

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

int n,m;
int a;

priority_queue<int> pq;

int main(){

	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){scanf("%d",&a);pq.push(a);}

	for(int i=0;i<m;i++){
		int t=pq.top();pq.pop();
		pq.push(t/2);
	}

	long long ans = 0;
	for(int i=0;i<n;i++){
		ans += pq.top();pq.pop();
	}

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

Measured memory_bytes: 892
n, k, c = map(int, input().split())
s = input()

l = [0 for i in range(k+1)]
r = [0 for i in range(k+1)]

cnt = 0
kaime = 1
for i in range(n):
    if kaime > k: break
    if cnt > 0:
        cnt -= 1
    else:
        if s[i] == 'o':
            l[kaime] = i
            kaime += 1
            cnt = c

cnt = 0
kaime = k
for j in range(n):
    i = n-1 - j
    if kaime < 1: break
    if cnt > 0:
        cnt -= 1
    else:
        if s[i] == 'o':
            r[kaime] = i
            kaime -= 1
            cnt = c

for i in range(1, k+1):
    if l[i] == r[i]:
        print(l[i]+1)

Measured memory_bytes: 20640
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	const int mod=100000;
	int M,N,ans=1;
	vector<string> field;
	vector<int> crt,next;
	cin >> M >> N;
	crt.resize(1<<(N+1));
	next.resize(1<<(N+1));
	REP(i,0,M){
		string str;
		cin >> str;
		field.push_back(str);
	}
	crt[0]=1;
	REP(y,0,M) REP(x,0,N){
		if(field[y][x]=='?'){
			ans*=3;
			ans%=mod;
		}
		REP(mask,0,1<<(N+1)){
			//maskの後ろのほうのbitが新しい.一番最初のbitは直前にJを置いたかどうかのフラグ
			const unsigned int nmask=(mask>>2)<<1;
			switch(field[y][x]){
				case '?':
				//J
				if(x+1<N){ //右端でないならば
					next[nmask|1]+=crt[mask]; //Jを置いたのでフラグが立っている
					next[nmask|1]%=mod;
				}else{ //右端ならJを置いてもその後に影響しない
					next[nmask]+=crt[mask];
					next[nmask]%=mod;
				}
				//O
				if(mask&1){ //もし直前にJをおいていたら
					next[nmask|(1<<N)]+=crt[mask]; //JOの並びができているので最新のbitが立っている
					next[nmask|(1<<N)]%=mod;
				}else{
					next[nmask]+=crt[mask]; //直前にJを置いていないので最新のbitは立っていない
					next[nmask]%=mod;
				}
				//I
				if(((mask>>2)&1)!=1){ //いま見ているマスの上でJOの並びができていなかったらIが置ける
					next[nmask]+=crt[mask];
					next[nmask]%=mod;
				}
				break;
				case 'J':
				if(x+1<N){ //右端でないならば
					next[nmask|1]+=crt[mask]; //Jを置いたのでフラグが立っている
					next[nmask|1]%=mod;
				}else{ //右端ならJを置いてもその後に影響しない
					next[nmask]+=crt[mask];
					next[nmask]%=mod;
				}
				break;
				case 'O':
				if(mask&1){ //もし直前にJを置いていたら
					next[nmask|(1<<N)]+=crt[mask]; //JOの並びができているので最新のbitが立つ
					next[nmask|(1<<N)]%=mod;
				}else{
					next[nmask]+=crt[mask];
					next[nmask]%=mod;
				}
				break;
				case 'I':
				if(((mask>>2)&1)!=1){ //いま見ているマスの上でJOの並びができていなかったらIが置ける
					next[nmask]+=crt[mask];
					next[nmask]%=mod;
				}
				break;
				default:
				break;
			}
		}
		swap(next,crt);
		fill(begin(next),end(next),0);
	}
	const int invalid=accumulate(begin(crt),end(crt),0,[](int a,int b){return (a+b)%mod;});
	ans=(ans-invalid+mod)%mod;
	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 17484
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		//int answer=0;
		String answer="NO";
		//List<Integer> h=new ArrayList<Integer>();
		//int af=Integer.MAX_VALUE;
		int N=0;
		int K=0;
		int max=0;
		int min=0;
		int sum=0;
		//int sub=0;
		//int a=0;
		//int t[]=new int[(int)Math.pow(10,5)];
		
		//入力
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();
		K=sc.nextInt();
		//X=sc.nextDouble();
		//for(int i=0;i<M;i++)
		//{
		//	X[i]=sc.nextInt();
		//}
		//String S=sc.next();
		
		//処理
		if(N%2==0)
		{
			if(N/2>=K)
			{
				answer="YES";
			}
		}else
		{
			if(N/2+1>=K)
			{
				answer="YES";
			}
		}
		
		// 出力
		//System.out.println(Arrays.toString(X))
		//System.out.println(Arrays.deepToString(td));
		System.out.println(answer);
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1001001001001001;

int n;
ll r[111], c[111];
ll dp[111][111]; // dp[le][ri] = [le, ri) の最小回数

ll rec(int le, int ri) {
    if (dp[le][ri] != INF) return dp[le][ri];
    if (ri - le - 2 == 0) {
        return dp[le][ri] = min(dp[le][ri], r[le] * c[le] * c[ri - 1]);
    }
    if (le + 1 < ri - 1) dp[le][ri] = min(dp[le][ri], rec(le + 1, ri) + r[le] * c[le] * c[ri - 1]);
    if (le < ri - 2) dp[le][ri] = min(dp[le][ri], rec(le, ri - 1) + r[le] * c[ri - 2] * c[ri - 1]);
    for (int md = le + 1; md < ri - 1; md++) {
        dp[le][ri] = min(dp[le][ri], rec(le, md) + rec(md, ri) + r[le] * c[md - 1] * c[ri - 1]);
    }
    return dp[le][ri];
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> r[i] >> c[i];
    for (int i = 0; i < 111; i++) {
        for (int j = 0; j < 111; j++) {
            dp[i][j] = INF;
        }
    }
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    rec(0, n);
    cout << dp[0][n] << endl;
}


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

int main() {
    string str;
    cin >> str;

    if (str == "AAA") {
        cout << "No" << endl;
    }
    else if (str == "BBB") {
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007
#define println(x) cout << "[" << #x << ":" << x << "]\n"; 
#define print(x) cout << "[" << #x << ":" << x << "] "; 

int main(){
	ios::sync_with_stdio(0); 
    cin.tie(0); 
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++)
		cin >> a[i];
	int dp[n+1] = {0};
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i=2; i<n; i++){
		dp[i] = min((dp[i-1] + abs(a[i]-a[i-1])), (dp[i-2] + abs(a[i] - a[i-2])));
	}
	cout << dp[n-1] << "\n";
	return 0;
}

Measured memory_bytes: 4340
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;

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

    int n,l; cin >> n >> l;

    int ans = 0;

    int x = 1000;

    rep(i,n){
        ans+=l+i;
        if(abs(l+i) < abs(x)) x = l+i;
    }

    cout << ans-x << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    n, q = map(int, input().split())
    s = input()

    tmp = [0] * (n + 1)

    for i in range(1,n):
        tmp[i] = tmp[i-1] + ( 1 if s[i-1] ==  'A' and s[i] ==  'C' else 0 )
    
    for _ in range(q):
        l, r = map(int, input().split())
        print(tmp[r-1] - tmp[l-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 50904
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0){
        cout<<0;
    }else{
        ll ans=1e18;
        for(int i=1;i<a;i++){
            ll S0=1LL*i*b;
            int t=a-i;
            int k=b/2;
            ll S1=1LL*k*t,S2=1LL*(b-k)*t;
            ll Max=max(max(S1,S0),S2);
            ll Min=min(min(S1,S0),S2);
            if(Max&&Min) ans=min(ans,Max-Min);
            if(t==1) continue;
            k=t/2;
            S1=1LL*k*b,S2=1LL*(t-k)*b;
            Max=max(max(S1,S0),S2);
            Min=min(min(S1,S0),S2);
            if(Max&&Min) ans=min(ans,Max-Min);
        }
        for(int i=1;i<b;i++){
            ll S0=1LL*i*a;
            int t=b-i;
            int k=a/2;
            ll S1=1LL*k*t,S2=1LL*(a-k)*t;
            ll Max=max(max(S1,S0),S2);
            ll Min=min(min(S1,S0),S2);
            if(Max&&Min) ans=min(ans,Max-Min);
            if(t==1) continue;
            k=t/2;
            S1=1LL*k*a,S2=1LL*(t-k)*a;
            Max=max(max(S1,S0),S2);
            Min=min(min(S1,S0),S2);
            if(Max&&Min) ans=min(ans,Max-Min);
        }
        cout<<ans;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}



int main() {
    int L;cin>>L;
    int d = 0;
    
    
    while(pow(2,d+1) <= L ){
        d++;
    }
    
    int cnt = 0;
    int n = d+1;
    vector<vector<pii>> path(n+1);
    int pow2 = 1;
    repsg(i,1,n){
        path[i].emplace_back(i+1,pow2);
        path[i].emplace_back(i+1,0);
        cnt+=2;
        pow2*=2;
    }

///    path[d+1]がgoal. ここまでで0... 2^d -1まではすべて作れている。
///
    
    for(auto t = n-1; t>=1; t--){
        int rest = L - pow(2,t-1);
        
        if(rest >= pow(2,n-1)){
            path[t].emplace_back(n,rest);
            L -= pow(2,t-1);
            cnt++;
        }
    }
    
    
    
    cout<<d+1<<" " << cnt<<endl;
    repsg(i,1,n){
        for(auto p:path[i]){
            cout<<i<<" " << p.first << " " <<p.second<<endl;
        }
        
    }
    
    
    
    return 0;
}








Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define rep_r(i,n) for(i=n-1;i>=0;i--)
#define debug_i(x) printf("x:%d\n",x)
#define debug_s(str) printf("str:%s\n",str)
#define debug_c(c) printf("c:%c\n",c)
#define s_i1(x) scanf("%d",&x)
#define s_i2(x,y) scanf("%d %d",&x,&y)
#define s_i3(x,y,z) scanf("%d %d %d",&x,&y,&z)
////////////////////////////////////////////////////
////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
///////////////////////

int main()
{
	int i,j,k;
	int n,q;
	int x,y,sd_num=0;
	double max=0,num=0,sd_max=0;
	int a[100000]={},v[100000]={};

	s_i1(n);
	rep(i,n)
	{
		scanf("%d %d",&x,&y);
		if(i==0)
		{
			max=y;
			num=x;
		}
		else 
		{
			num=(max<y)? x : num;
			max=fmax(y,max);
		}
		if(max==y)num=fmin(num,x);
	}
	printf("%d %d\n",(int)num,(int)max);
	return 0;
}

Measured memory_bytes: 1032
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			int s = scanner.nextInt();
			int g1 = scanner.nextInt();
			int g2 = scanner.nextInt();
			if ((n | m | s | g1 | g2) == 0)
				break;
			s--;
			g1--;
			g2--;
			int[][] g = new int[n][n];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					g[i][j] = i == j ? 0 : INF;

			while (m-- > 0) {
				int b1 = scanner.nextInt() - 1;
				int b2 = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				g[b1][b2] = c;
			}

			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					for (int k = 0; k < n; k++)
						g[j][k] = Math.min(g[j][k], g[j][i] + g[i][k]);

			int ans = INF;
			for (int i = 0; i < n; i++)
				ans = Math.min(ans, g[s][i] + g[i][g1] + g[i][g2]);
			System.out.println(ans);
		}
	}

	int INF = 1 << 29;
}

Measured memory_bytes: 62900
using System;

namespace ABC085
{
    class B
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var d = new int[N];
            for (int i = 0; i < d.Length; i++)
                d[i] = int.Parse(Console.ReadLine());

            Array.Sort(d);
            var res = 0;
            var d_pre = int.MinValue;
            for (int i = 0; i < d.Length; i++)
            {
                if (d_pre < d[i]) res++;
                d_pre = d[i];
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 11348
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
A = LI()

ans = 0

for a in A :
    ans += (1.0 / a)

print(1.0 / ans)

Measured memory_bytes: 39152
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

SS = list(input())
W = N = S = E = 0
for s in SS:
	if s == 'W':
		W += 1
	elif s == 'N':
		N += 1
	elif s == 'S':
		S += 1
	elif s == 'E':
		E += 1

if (W == 0 and E != 0) or (W != 0 and E == 0):
	print('No')
elif (N == 0 and S != 0) or (N != 0 and S == 0):
	print('No')
else:
	print('Yes')


Measured memory_bytes: 4584
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n

for i in range(1, n):
    start = max(0, i - k)
    dp[i] = min([cost + abs(h[i] - hh) for cost, hh in zip(dp[start:i], h[start:i])])

print(dp[n - 1])


Measured memory_bytes: 13980
def resolve_c():
    n, m = map(int, input().split())
    ac_list = [0] * n
    wa_list = [0] * n
    wa_tmp_list = [0] * n
    for i in range(m):
        p, s = input().split()
        if ac_list[int(p)-1] == 0:
            if s == "AC":
                ac_list[int(p)-1] = 1
                wa_list[int(p)-1] = wa_tmp_list[int(p)-1]
            elif s == "WA":
                wa_tmp_list[int(p)-1] += 1
    print(str(sum(ac_list)) + " " + str(sum(wa_list)))
resolve_c()

Measured memory_bytes: 5364
#include <iostream>
using namespace std;
int main(){
	int a,b,c,i;
	char op;
	
	for(i=0;i<=10000000000;i++){
		cin>>a>>op>>b;
	if(op=='+'){
	c=a+b;
	}
	else if(op=='-'){
	c=a-b;
	}
	else if(op=='*'){
	c=a*b;
	}
	else if(op=='/'){
	c=a/b;
	}
	else break;
	cout<<c<<endl;}
	
return 0;
}


Measured memory_bytes: 3080
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
bool isprime[1000000];
vector<lnt> primes;

int main()
{
	fill(isprime,isprime+1000000,1);
	isprime[0]=isprime[1]=0;
	for(lnt i=2;i<1000000;i++){
		if(!isprime[i]) continue;
		primes.push_back(i);
		for(lnt j=2*i;j<1000000;j+=i) isprime[j]=0;
	}
	lnt n;
	while(scanf("%lld",&n)!=EOF){
		cout<<upper_bound(primes.begin(),primes.end(),n)-primes.begin()<<endl;
	}
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int n, k;
	cin >> n >> k;
	int res = 1;
	REP(i, n) res = min(res * 2, res + k);
	cout << res << endl;
	return 0;
}
 

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()
    G = collections.defaultdict(list)
    for _ in range(M):
        X, Y, _ = LI_()
        G[X].append(Y)
        G[Y].append(X)

    # A_XtoA_Yは片方が決まればもう片方も決まる よって連結成分数が答え
    visited = [False] * N
    def dfs(c):
        visited[c] = True
        for n in G[c]:
            if not visited[n]:
                dfs(n)

    ans = [0]
    for i in range(N):
        if not visited[i]:
            dfs(i)
            ans[0] += 1

    print(ans[0])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 139928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int x=nxt();
    if(x==0){
        printf("1");
    } else{
        printf("0");
    }
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int n = N, sum = 0;
    while(n){
        sum += n%10; n /= 10;
    }
    if(N%sum == 0) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}




Measured memory_bytes: 384
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

#include <complex>
typedef complex<double> P;

struct L {
	P a, b;
	L(const P &a, const P &b) : a(a), b(b) { }
};

struct C {
	P p; double r;
	C(const P p, double r) : p(p), r(r) { }
};

double dot(P a, P b) {
	return real(conj(a)*b);
}

double cross(P a, P b) {
	return imag(conj(a)*b);
}

bool LLcross(L l1, L l2) {
	return abs(cross(l1.b-l1.a, l2.b-l2.a)) > EPS/* || abs(cross(l1.b-l1.a, l2.b-l1.a)) < EPS*/;
}

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

	REP(i, n) {
		double x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		L l1(P(x1, y1), P(x2, y2));

		
		cin >> x1 >> y1 >> x2 >> y2;
		L l2(P(x1, y1), P(x2, y2));

		cout << (LLcross(l1, l2) ? "NO" : "YES") << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

ll dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
ll dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    ll n; cin >> n;
    ll arr[n];
    for(ll &i: arr) cin >> i;
    ll mx = arr[0];
    ll ans = 0;
    for(ll i = 1; i < n; i++){
        if(arr[i] < mx) ans += mx - arr[i];
        mx = max(arr[i], mx);
    }
    cout << ans << endl;
}



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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#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)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    string s;
    cin >> n >> s;
    for (char &c: s) --c;
    ford(k, 30) {
        if ((1 << k) >= (int)s.size()) continue;
        string t;
        forn(i, s.size() - (1 << k)) t += (char)('0' + abs(s[i] - s[i + (1 << k)]));
        if (count(all(t), '1')) s = t;
        else continue;
    }

    if (s.size() == 1) cout << s << '\n';
    else {
        string t;
        forn(i, s.size() - 1) t += (char)('0' + abs(s[i] - s[i + 1]));
        s = t;

        int n = s.size();
        int res = 0;
        forn(i, n) if ((i & (n - 1)) == i) res ^= (s[i] - '0');
        cout << res << '\n';
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3308
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int H, W;
    
    while (in.hasNext()) {
      StringBuilder s = new StringBuilder();
      String crlf = System.getProperty("line.separator");
      H = in.nextInt();
      W = in.nextInt();
      if(H == 0 && W == 0) break;
      
      for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
          s.append("#");
        }
        s.append(crlf);
      }
      System.out.println(s.toString());
    }
  }
}

Measured memory_bytes: 20992
task_num = gets.chomp.to_i
tasks = Array.new
task_num.times do
  tasks << gets.chomp.split(' ').map(&:to_i)
end

def abort
  puts 'No'
  exit
end

sorted_tasks = tasks.sort_by{|task| task[1]}
current_time  = 0
sorted_tasks.each do |difficulty, limit|
  abort if current_time + difficulty > limit
  current_time += difficulty
end
puts 'Yes'


Measured memory_bytes: 22392
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll mygcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll mylcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ; cin >> s ;
	yorn(s.at(0)=='7'||s.at(1)=='7'||s.at(2)=='7') ;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 100000
int n,a[MAXN+5],minn;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	minn=1000000007;
	for(int i=n;i>=1;i--)
	{
		minn=min(a[i],minn);
		if(a[i]-minn>1){printf("No\n");return 0;}
	}
	printf("Yes\n");
}

Measured memory_bytes: 640
n=int(input())
s=input()
w=s.count("W")
e=s.count("E")
t=0
ans=n
for i in range(n):
    if s[i]=="E":
        e-=1
    tmp=e+t
    if tmp<ans:
        ans=tmp
    if s[i]=="W":
        t+=1
print(ans)

Measured memory_bytes: 68444
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main()
{
 //clock_t start=clock();
    long A,B,C,K;
    std::cin >> A>> B >> C >> K;
    if(A>=K){
        std::cout << K << std::endl;
    }else if(A+B>=K){
        std::cout << A << std::endl;
    }else{
        std::cout << A-(K-(A+B)) << std::endl;
    }
    //clock_t end=clock();
//std::cout << static_cast<double>(end-start)/CLOCKS_PER_SEC * 1000.0 << std::endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  string s;
  cin >> n >> s >> k;
  REP(i,n){
    if(s[i]!=s[k-1]) s[i]='*';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(a);
        int count = 0;
        for(int i = 0; i < N; i++){
            if(x >= a[i] && i != N-1){
                count++;
                x -= a[i];
            }
            if(i == N-1){
                if(x == a[i])
                    count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 23380
#include<iostream>
#include<vector>
#include<algorithm>
#include <numeric>
using namespace std;
const long long int INF = 10000000;
int main()
{
	long long int n, x, max = -INF, min = INF, sum = 0;
	vector<int> v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		v.push_back(x);
		if (max < x)max = x;
		if (min > x)min = x;
		sum += x;
	}
	cout << min << " " << max << " " << sum << endl;
	//cout << *min_element(v.begin(), v.end()) << " " << *max_element(v.begin(), v.end()) << " " << accumulate(v.begin(), v.end(), 0) << endl;
    return 0;
}

Measured memory_bytes: 1320
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll mod =1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> T maxt(T x,T y) {if (x>y) return x;else return y;}
template<class T> T mint(T x,T y) {if (x>y) return y;else return x;}
//sort(v.begin(), v.end(), [](auto& x, auto& y){return x[1] < y[1];});


//小数出力
// double print_double(double d){printf("%.6f", d);}

//約数列挙
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}



// ll combination_mod(int n, int k) {
//   k = mint(k,n-k);
//   ll ans = 1;
//   if (n==0 || k ==0) return ans;
//   rep(i,k) {
//     ans = ans*(n-i)%mod;
//     ans = ans*modinv(i+1)%mod;
//   }
//   return ans;
// }

struct edge {
  int from; //出発点
  int to;   //到達点
  ll cost; //移動コスト
};

//ベルマンフォード法
vector<ll> bellman_ford (vector<edge> edges, int V, int E, int r, ll INF = 100000000000) {  
  vector<ll> cost_to(V,INF);
  cost_to[r] = 0;
  rep(i,V) {
    rep(j,E) {
      edge e = edges[j];
      if (cost_to[e.from]==INF) continue;
      if (cost_to[e.to] > cost_to[e.from] + e.cost) {
        cost_to[e.to] = cost_to[e.from] + e.cost;
        if (i==V-1) {
          printf("NEGATIVE CYCLE\n");
          return {};
        }
      }

    }
  }
  return cost_to;
}

// combination
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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


// 木上の探索
vector<int> cnt;
void dfs(const vector<vector<int>> &G, int v, int p) {
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v);
    }

    // 帰りがけ時に、部分木サイズを求める
    cnt[v] = 1; // 自分自身
    for (auto c : G[v]) {
        if (c == p) continue;
        cnt[v] += cnt[c]; // 子のサイズを加える
    }
}

int main() {
  ll N,K;
  cin >> N >> K;
  ll ans = 0;
  for (ll i=K;i<N+2;i++) {
    ans += (N-i+1+N)*i/2%mod - (i-1)*i/2%mod + 1;
    ans%=mod;
    // cout << ans << endl;
  }
  // cout << ans/mod << endl;
  if (ans/mod<=0) {
    ans = (ans + mod - ans/mod*mod)%mod;
  }
  cout << ans << endl;
}


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

int main() {
	int power[] = {12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
	int A, B;
	cin >> A >> B;
	if (power[A - 1] > power[B - 1]) cout << "Alice";
	else if (power[A - 1] < power[B - 1]) cout << "Bob";
	else cout << "Draw";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

1の時だけ強さがひっくり返るのを実装するのは面倒なので、先に強さ順の値に変えてしまうと分かりやすいね
*/

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int N; std::cin >> N;
    //info[i][j]: i人目が正直の時 j人目は (-1:不明 1:正直 0:不親切)
    std::vector<std::vector<int>> info(N, std::vector<int>(N, -1));
    {
        int A, x, y;
        for(int i(0); i < N; ++i){
            std::cin >> A;
            info[i][i] = 1;
            for(int j(0); j < A; ++j){
                std::cin >> x >> y;
                --x;
                info[i][x] = y;
            }
        }
    }
    int ans(0);
    for(int i(0), i_len(1 << N); i < i_len; ++i){
        std::vector<int> fact(N); 
        int honest(0);
        for(int j(0); j < N; ++j){
            fact[j] = ((i >> j) & 1);
            if(fact[j]) ++honest;
        }

        bool okay(true);
        for(int j(0); j < N; ++j){
            if(!fact[j]) continue;
            for(int k(0); k < N; ++k){
                if(info[j][k] == -1) continue;

                if(info[j][k] != fact[k]){
                    okay = false; break;
                }
            }
            if(!okay) break;
        }
        if(okay) chmax(ans, honest);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
const int maxn = 200005;
int nex[30][30], vis[30], l[maxn][30], r[maxn][30];
string s, t;
int main() {
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    cin >> s >> t;
    string s0 = s + s;
    memset(vis, -1, sizeof(vis));
    for (int i = s0.size() - 1; i >=0; i--) {
        for (int j = 0; j < 26; j++) {
            r[i][j] = vis[j] % s.size();
        }
        vis[s0[i]-'a'] = i;
    }
    for (int i = 0; i < t.size(); i++) {
        if (vis[t[i]-'a'] == -1) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll ed  = vis[t[0] - 'a'], k = ed;
    int len = s.size();
    int cnt = 0;
    while (++cnt < t.size()) {
        int pos = r[k][t[cnt]-'a'];
        if (pos > k) 
            ed += (pos - k);
        else
            ed += (pos + len - k);
        k = pos;
    }
    cout << ed + 1<< endl;
}

Measured memory_bytes: 25344
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

 class Main {


    private static int min(int a, int b)
    {
        return (a < b) ? a : b;
    }


        static long binomialCoeff(int n, int k)
        {
            long C[][] = new long[n+1][k+1];
            int i, j;

            for (i = 0; i <= n; i++)
            {
                for (j = 0; j <= min(i, k); j++)
                {
                    if (j == 0 || j == i)
                        C[i][j] = 1;

                    else
                        C[i][j] = C[i-1][j-1] + C[i-1][j];
                }
            }

            return C[n][k];
        }


        public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();

        String[] strings=new String[n];
        for(int i=0;i<n;i++){
            char[] s=in.next().toCharArray();
            Arrays.sort(s);
            strings[i]=new String(s);
        }
        Arrays.sort(strings);
        long count=0;
        for(int i=1;i<n;){
            long c=0;
            boolean flag=false;
            while(i<n && strings[i].equals(strings[i-1])) {
                flag=true;
                c++;
                i++;
            }
            if(c>0) {
               // c++;
                //count += binomialCoeff(c, 2);
                count+= (c*(c+1))/2;
            }
            if(!flag)
                i++;

        }
            System.out.println(count);


    }
}


Measured memory_bytes: 51792
from itertools import product
S = input()

for string in product(["+","-"],repeat = 3):
    string = list(string)
    string.append("")
    sum_ = [a + b for a,b in zip(S,string)]
    if eval("".join(sum_)) == 7:
        print("".join(sum_)+"=7")
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, s, e) for(int i = s; i < e; i++)
#define rrep(i, s, e) for(int i = s; i > (s)-(e); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  int a, b;
  cin >> a >> b;

  if (a == 1) a = 14;
  if (b == 1) b = 14;
  if (a > b) pr("Alice");
  else if (b > a) pr("Bob");
  else pr("Draw");


  return 0;
}


Measured memory_bytes: 256
#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_V = 100000;

vector<int> G[MAX_V];


int main(){
	int V,E;
	cin >> V >> E;
	REP(i,E){
		int s,t;
		cin >> s >> t;
		s--; t--;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	REP(i,V) cout << G[i].size() << endl;
 }

Measured memory_bytes: 2560