akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for(int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    for(int i = 0; i < N; ++i) {
        cin >> C[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    ll ret = 0;
    for(int i = 0; i < N; ++i) {
        auto iterA = lower_bound(A.begin(), A.end(), B[i]);
        auto iterC = upper_bound(C.begin(), C.end(), B[i]);
        ret += ll(iterA - A.begin()) * ll(C.end() - iterC);
    }
    // vector<int> AB(N);
    // for(int i = 0; i < N; ++i) {
    //     auto iter = lower_bound(A.begin(), A.end(), B[i]);
    //     AB[i] = int(iter - A.begin());
    // }
    // for(int i = 1; i < N; ++i) {
    //     AB[i] += AB[i-1];
    // }
    // int ret = 0;
    // for(int i = 0; i < N; ++i) {
    //     auto iter = lower_bound(B.begin(), B.end(), C[i]);
    //     ret += AB[iter - B.begin()-1];
    // }
    cout << ret << endl;
    return 0;
}

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

typedef long long LL;

LL n;
LL x;

int main(){
	scanf("%lld%lld",&n,&x);
	LL ans = n;
	LL at = x;
	LL kan = n-x;
	while(x!=0){
		LL tmp = kan/x;
		ans+=tmp*2LL*x;
		kan%=x;
		if(kan == 0) ans-=x;
		x = kan;
		
		if(x==0) break;
		
		tmp  = at/x;
		ans+= tmp*2LL*x;
		at%=x;
		if(at == 0) ans-=x;
		x = at;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long

const int size = 10e5;
int arr[size], t;
int dp[size];
int solve(int i){
	if (i==t-1) return 0;
	if (i>=t) return INT_MAX;

	if (dp[i] != -1) return dp[i];

	int l = abs(arr[i] - arr[i+1]) + solve(i+1);
	int r = INT_MAX;
	if (i+2<t){
		r = abs(arr[i] - arr[i+2]) + solve(i+2);
	}
	return dp[i] = min(l,r);
}

int main()
{
	load;
	//int t;
	cin >> t;
	memset(dp, -1, sizeof(dp));
	for (int i=0; i<t; i++){
		cin >> arr[i];
	}
	cout << solve(0);
	return 0;
}


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

using namespace std;

const int N = 100000 + 7;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<ll,ll> pll;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[N], x[N], y[N], z[N];
  memset(a, 0, sizeof a);
  map<int, vector<int>> list; list.clear();
  for(int i = 0; i < m; ++i) {
    scanf("%d %d %d", &x[i], &y[i], &z[i]);
    list[x[i]].push_back(y[i]);
    list[y[i]].push_back(x[i]);
  }
  /*
  cout << "why" << list[5].size() << endl;
  cout << list[5][0] << list[5][1] << endl;
  cout << "why" << list[6].size() << endl;
  cout << list[6][0] << endl;
  */
  int ans = 0;
  for(int i = 1; i <= n; ++i) {
    if(a[i] == 0) {
      ++ans;
      //cout << i << endl;
      a[i] = i;
      queue<int> q;
      while(!q.empty()) q.pop();
      q.push(i);
      while(!q.empty()) {
        int qf = q.front(); q.pop();

        for(int j = 0; j < list[qf].size(); ++j) {
          int y = list[qf][j];
          //cout << y << a[y] << endl;
          if(a[y] == 0) {
            a[y] = i;
            q.push(y);
            //cout << "yes" << endl;
            //cout << qf << list[qf][j] << endl;
          }
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

typedef long long ll;
typedef long long ll;
typedef vector <int> vi;
typedef vector < pair < int, int > > vpi;

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

#define pi pair< int , int >
#define pii pair< pi , int >
#define PI acos(-1)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define R(a) for(int i=0;i<a;i++)
#define PrtArr(a,n) for (int i=0;i<n;i++){cout << a[i] << " ";}cout << endl
#define IN(x,a,b) x >= a && x <= b
#define INO(x,a,b) x > a && x < b
#define fr first
#define sc second
#define pb push_back

#define SET(x,y)    x|=(1<<y)
#define CLEAR(x,y)  x&= ~(1<<y)
#define TOGGLE(x,y) x^=(1<<y)
#define READ(x,y)   ((bool)((ll)(x&(1<<y)) != 0))

#define I(x) scanf("%d",&x)
#define I2(x,y) scanf("%d%d",&x,&y)
#define I3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define I4(x,y,z,r) scanf("%d%d%d%d",&x,&y,&z,&r)
#define L(x) scanf("%I64d",&x)
#define L2(x,y) scanf("%I64d%I64d",&x,&y)
#define L3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define L4(x,y,z,r) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&r);

#define SPEED_UP ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sz(x) ((int)(sizeof(x)))
#define all(t) t.begin(),t.end()
#define frei freopen("out.out","r",stdin)
#define freo freopen("out.out","w",stdout)
#define left(x) (x << 1)
#define right(x) ( ( x << 1 ) + 1)
#define eps 1e-6
#define OO   INT_MAX
#define OOLL LLONG_MAX
#define M 1000000007
#define MAX (int)2e5+100
#define lim (int)46340

void f(int a , char x, char y)
{
    for(int i = 0 ; i < 21 ; i ++ )
    {
        if(i%2)
        {
            FOR(j,0,100)
            {
                if(j%2==0 && a)
                {
                    printf("%c",x);
                    a--;
                }
                else
                    printf("%c",y);
            }
        }
        else
            FOR(j,0,100)printf("%c",y);
        printf("\n");
    }
}
int main()
{
    int a,  b;
    I2(a,b);
    a--,b--;
    printf("42 100\n");
    f(a,'.','#');
    f(b,'#','.');
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B,L;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD = (1e+9) + 7;
const ll MAX_N = 100010;
typedef pair<ll,ll> P;

int main() {
    cin>>N>>K;
    vec a(N);
    ll sum = 0;
    rep(i,N){
        cin>>a[i];
        sum += a[i];
    }
    set<ll> d;
    reps(i,1,sum+1){
        if(sum%i == 0){
            d.insert(sum/i);
            d.insert(i);
        }
        if(i*i > sum) break;
    }
    vec mod(N,0);
    ll ans = 0;
    for(ll di : d){
        rep(i,N) mod[i] = a[i]%di;
        sort(mod.begin(),mod.end());
        ll lb = 0, ub = N-1;
        ll temp = 0;//足した数
        ll judge = 0;
        while(ub -lb >= 0){
            if(temp > 0) {
                temp -= mod[lb];
                ++lb;
            }else{
                temp += (di - mod[ub]);
                judge += (di - mod[ub]);
                --ub;
            }
        }
        if(judge <= K) ans = max(ans, di);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,C,X,Y = MI()
    C*=2
    ans = A*X+B*Y
    if(X>Y):
        ans = min(ans,min(X,Y)*C + (X-Y)*A)
    else:
        ans = min(ans,min(X,Y)*C + (Y-X)*B)
    ans = min(ans,max(X,Y)*C)
    print(ans)
if __name__ == '__main__':
    main()

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


 int main (){
	 int n;
	 int card[4][13]={{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0}};
	 cin >> n;
     //start import
	 for(int i=0;i<n;i++){
		char x;
		int y;
		cin >>x >> y;
		switch(x){
		case 'S':
			card[0][y-1] = 1;
			break;
		case 'H':
			card[1][y-1] = 1;
			break;
		case 'C':
			card[2][y-1] = 1;
			break;
		case 'D':
			card[3][y-1] = 1;
			break;
		}	 
	 }
     //end import
     //start output
	 for(int j=0;j<4;j++){
		 for(int k=0;k<13;k++){
			 if(card[j][k] == 0){
			  switch(j){
			  case 0:
				  cout <<"S"<<" "<<k+1<<"\n";
				  break;
			  case 1:
				  cout <<"H"<<" "<<k+1<<"\n";
				  break;
			  case 2:
			      cout <<"C"<<" "<<k+1<<"\n";
				  break;
			  case 3:
			      cout <<"D"<<" "<<k+1<<"\n";
			      break;


			 }
			 }
		 }
	 }
	//end output
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define F first
#define S second
using namespace std;

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

int main()
{
    ll t,i,j,k,ans,n,m;

    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n>>m;

        ll lc = 1;
        vector<ll> v(n);
        rep(p,0,n){cin>>v[p];lc = lcm(lc,v[p]);}

        ll val = ((v[0] ^ (v[0]-1))+1)/2;
        bool flag=true;

        rep(p,1,n)
        {
            if(val != ((v[p] ^ (v[p]-1))+1)/2){flag=false;break;}
        }
        if(flag)
        {
            lc/=2;
            ans = (m/lc) - (m/(2*lc));
            cout<<ans;
        }else cout<<"0";
    }
    return 0;
}



Measured memory_bytes: 4016
#include<iostream>
using namespace std;
int main() {
    int h, w;
    while (1) {
        cin >> h >> w;
        if (h == 0 & w == 0)
            break;
        for (int i = 0; i < h; i++) {
            for (int k = 0; k < w; k++) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 1; i <= a; i++) {
            if (a % i == 0 && b % i == 0) {
                list.add(i);
            }
        }
        Collections.sort(list);
        int num = list.size();
        System.out.println(list.get(num - k));
    }
}

Measured memory_bytes: 21844
from collections import defaultdict
N, M = map(int, input().split())

G = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

V = [0] * N
V[0] = 1
def dfs(n, V):
    if all([v == 1 for v in V]):
        return 1

    ans = 0
    for e in G[n]:
        if V[e] == 1:
            continue
        V[e] = 1
        ans += dfs(e, V)
        V[e] = 0
    
    return ans

print(dfs(0, V))

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

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

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

	    int a,b,c;
	    in>>a;
	    string s,t;
	    in>>s>>t;

	    for(int i =0;i<s.size();i++)
        {
	        out<<s[i]<<t[i];
        }

	}
};


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


Measured memory_bytes: 256
(A,B,C,X,Y)=[int(i) for i in input().split()]

C*=2
if X>Y:
    print(min([A*X+B*Y,(X-Y)*A+Y*C,C*max([X,Y])]))
else:
    print(min([A*X+B*Y,(Y-X)*B+X*C,C*max([X,Y])]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
void program(); int main() {cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); program();}
#define endl "\n"
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>

#define N 100007
int a[N],dp[N];

void program(){
    int n; cin>>n;
    for(int i=0;i<n;i++) cin>>a[i], dp[i] = 999999999;
    dp[0] = 0;
    for(int i=1;i<n;i++)
        for(int k=1;k<=2;k++) if (i-k >= 0)
            dp[i] = min(dp[i], dp[i-k] + abs(a[i]-a[i-k]));
    cout << dp[n-1] << endl;
}

/*
WA:
-bounds on loops
-truncating
-intialization
-0 vs 1 indexing

TLE:
-might need unordered_set/map
-infinite while loop

Stuck:
-different perspective?
-bruteforce?
-greedy?
-reduce dimensionality with problem contraints?
*/


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  long long  int c;
    scanf("%lld",&c);

   long long int A=c/500;
    long long int ModA=c%500;
    long long int B=ModA/5;

    long long int C=(A*1000)+(B*5);

    printf("%lld\n",C);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  ll a; double b;
  cin >> a >> b;
  ll bb = b * 100 + 0.5;
  ull ans = a * bb;
  ans /= 100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3744
class Node:
    def __init__(self):
        self.parent = -1
        self.depth = 0
        self.children = []
    def setDepth(self, depth):
        global t
        self.depth = depth
        for no in self.children:
            t[no].setDepth(depth + 1)

n = int(input())
t = [Node() for i in range(n)]
for i in range(n):
    id, k, *lst = map(int, input().split())
    t[id].children = lst
    for j in lst:
        t[j].parent = id
for i in range(n):
    if t[i].parent == -1:
        t[i].setDepth(0)

for i in range(n):
    print('node {0}: parent = {1}, depth = {2}, '.\
        format(i, t[i].parent, t[i].depth), end='')
    if t[i].parent < 0:
        print('root', end='')
    elif len(t[i].children) == 0:
        print('leaf', end='')
    else:
        print('internal node', end='')
    print(', [', end='')
    print(', '.join(map(str, t[i].children)), end='')
    print(']')



Measured memory_bytes: 43328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    ll n,k,s;cin>>n>>k>>s;
    vector<ll> a(n);
    rep(i,k) a[i]=s;
    for(int i=k;i<n;i++){
        if(s!=1e+9)a[i]=s+1;
        else a[i]=a[i]=s-1;
    }
    rep(i,n)cout<<a[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 2048
#include <stdio.h>
 
int main() {
 
    int n, h;
    int cnt = 1;
 
    scanf("%d", &n);
    scanf("%d", &h);
    int hmax = h;
 
    for (int i = 1; i < n; i++) {
        scanf("%d", &h);
        if (hmax <= h) {
            cnt += 1;
            hmax = h;
        }
 
    }
 
    printf("%d", cnt);
 
 
    return 0;
}

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

using namespace std;

const int M = 1046527;
const int NIL = -1;
const int L = 14;

char H[M][L]{};

int getChar(char ch) {
    if(ch == 'A')
        return 1;
    else if(ch == 'C')
        return 2;
    else if(ch == 'G')
        return 3;
    else if(ch == 'T')
        return 4;
    else
        return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1;
    for(int i = 0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key) {
    return key % M;
}

int h2(int key) {
    return 1 + (key % (M - 1));
}

bool find(char str[]) {
    long long key, h;
    key = getKey(str);
    for(int i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M; 
        if(strcmp(H[h], str) == 0)  //如果比对结果相等，即找到了 
            return true;
        else if(strlen(H[h]) == 0)  //如果不相等，而且该位置字符串长度为零 
            return false;
    }
    return false;
}

bool insert(char str[]) {
    long long key, h;
    key = getKey(str);
    for(int i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0)  //如果比对结果相等，即散列表中已经有了相同的元素，无须重复插入 
            return true;
        else if(strlen(H[h]) == 0) {  //如果找到空位，便插入 
            strcpy(H[h], str);
            return false;
        }
    }
    return false;
}

int main() {
    int n;
    char str[L], com[9];
    
    for(int i = 0; i < M; i++) {
        H[i][0] = '\0';
    }
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> com >> str;
        
        if(com[0] == 'i') {
            insert(str);
        } else {
            if(find(str)) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 17412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	ll n = s.size();
	
	bool ans = true;
	zep(i, 0, n){
		if(s[i] != s[n-1-i]){
			ans = false;
		}
	}
	
	zep(i, 0, (n-1)/2){
		if(s[i] != s[(n-1)/2-1-i]){
			ans = false;
		}
		
		if(s[i+(n-1)/2+1] != s[(n-1)/2-1+(n-1)/2+1-i]){
			ans = false;
		}
	}
	
	print((ans)? "Yes" : "No")
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;

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

    int ans = N-K+1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
li = []
for i in range(n):
    a,b = map(str,input().split())
    li.append([a,int(b),i+1])

li = sorted(li, reverse=True, key=lambda x:x[1])
li = sorted(li, key=lambda x:x[0])

for i in range(n):
    print(li[i][-1])


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, T;
int ch[30], pat[30];
int dp[2][1<<16];
int input() {
  int s = 0;
  rep(i, 16) {
    int a;
    cin >> a;
    if (a) s |= 1<<i;
  }
  return s;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N >> T) {
    if (N == 0 && T == 0) break;
    rep(i, N) ch[i] = input();
    rep(i, T) pat[i] = input();
    rep(i, 1<<16) dp[0][i] = dp[1][i] = -INF;
    dp[0][0] = 0;
    rep(i, N) {
      rep(s, 1<<16) dp[1][s] = -INF;
      rep(s, 1<<16) dp[1][s|ch[i]] = max(dp[1][s|ch[i]], dp[0][s]);
      swap(dp[0], dp[1]);
      rep(s, 1<<16) dp[1][s] = -INF;
      rep(s, 1<<16) {
        rep(j, T) {
          int ns = s & (~pat[j]);
          dp[1][ns] = max(dp[1][ns], dp[0][s] + __builtin_popcount(s & pat[j]));
        }
      }
      swap(dp[0], dp[1]);
    }
    int m = 0;
    rep(s, 1<<16) m = max(m, dp[0][s]);
    cout << m << "\n";
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){
  vector<int> A(9);
  int N;

  string ans = "No";
/*  cin>>A.at(0)>>A.at(1)>>A.at(2);
  cin>>A.at(3)>>A.at(4)>>A.at(5);
  cin>>A.at(6)>>A.at(7)>>A.at(8);
  */
  rep(j,9){
    cin>>A.at(j);
  }
  cin>>N;
  vec B(N);
  rep(i,N){
  cin>>B.at(i);
  rep(j,9){

    if(B.at(i)==A.at(j)){
      A.at(j)=-1;
    }
  }
  }

  if(A.at(0)+A.at(1)+A.at(2)==-3)ans = "Yes";
  if(A.at(3)+A.at(4)+A.at(5)==-3)ans = "Yes";
  if(A.at(6)+A.at(7)+A.at(8)==-3)ans = "Yes";
  if(A.at(0)+A.at(3)+A.at(6)==-3)ans = "Yes";
  if(A.at(1)+A.at(4)+A.at(7)==-3)ans = "Yes";
  if(A.at(2)+A.at(5)+A.at(8)==-3)ans = "Yes";
  if(A.at(0)+A.at(4)+A.at(8)==-3)ans = "Yes";
  if(A.at(2)+A.at(4)+A.at(6)==-3)ans = "Yes";
  cout<<ans<<endl;
}


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

int main(int argc, char const *argv[]) {
  int N;
  int *E, *W;
  int cost, minCost;

  scanf("%d\n", &N);
  E = (int *)malloc((N + 2) * sizeof(int));
  W = (int *)malloc((N + 2) * sizeof(int));
  E[0] = 0;
  W[0] = 0;
  for (int i = 1; i <= N; i++) {
    E[i] = E[i - 1];
    W[i] = W[i - 1];
    if (getchar() == 'E')
      E[i]++;
    else
      W[i]++;
    // printf("E[%d] = %d, W[%d] = %d\n", i, E[i], i, W[i]);
  }
  E[N + 1] = E[N];
  W[N + 1] = W[N];
  for (int i = 1; i <= N; i++) {
    cost = W[i - 1] + E[N + 1] - E[i];
    // printf("debug W=%d,E=%d,E[N+1]=%d\n", W[i - 1], E[i], E[N + 1]);
    if (i == 1) {
      minCost = cost;
    } else if (cost < minCost) {
      minCost = cost;
    }
  }
  free(E);
  free(W);
  printf("%d", minCost);
}

Measured memory_bytes: 2560
#include<stdio.h>
#define SENTINEL 2000000000
#define N 500000

int  L[N/2+2],R[N/2+2];
int count=0;

void Merge(int A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i=0;i<n1;i++){
    L[i] = A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid+i];
  }

  L[n1]=R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    count++;
    if(L[i]<=R[j]){
      A[k] = L[i++];
    }else{
      A[k]=R[j++];
    }
  }
}

void MergeSort(int A[],int n,int left,int right){
    if(left+1 < right){
      int mid=(left+right)/2;
      MergeSort(A,n,left,mid);
      MergeSort(A,n,mid,right);
      Merge(A,n,left,mid,right);
    }
}

int main(){
  int i,n,A[N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }  
  MergeSort(A,n,0,n);
  
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
}

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


int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  ll cnt=0;
  rep(i,0,n-1){
    if(s[i]==s[i+1]) cnt+=1;
  }
  ll ans;
  if(cnt+2*k<n) ans=cnt+2*k;
  else ans=n-1;
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

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


void solve()
{
	
	int n,k;
	cin>>n>>k;
	vector<ll>lower(n+1),upper(n+1);
	ll lsum=0,usm=0;
	rep(i,n+1){
		lsum+=i;
		lower[i]=lsum;
		usm+=n-i;
		upper[i]=usm;
	}
	ll ans=0;
	FOR(i,k-1,n+1){
		ans+=upper[i]-lower[i]+1;
		ans%=M;
	}
	cout<<ans<<endl;

}

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


Measured memory_bytes: 6368
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
str s;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>s;
    for(int i=0;i<s.size();i++) cout<<"x";
    cout<<newl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=15+9;
pii x;
vector<pii> v[sz];
int val[sz];
int n,a;
int ans;

bool ok(int mask){
	memset(val,-1,sizeof(val));
	for(int j=0;j<n;j++){
		int i=j+1;
		if((mask>>j)&1){
			for(auto u:v[i]){
				if(val[u.f]==-1) val[u.f]=u.s;
				else if(val[u.f]!=u.s) return 0;
				int m=mask>>(u.f-1);
				if(u.s==0&&(m&1)) return 0;
				if(u.s==1&&(m&1)==0) return 0;
			}
		}
	}
	return 1;
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a;
    	while(a--){
    		cin>>x.f>>x.s;
    		v[i].pb(x);
    	}
    }
    for(int mask=0;mask<=(1<<n)-1;mask++){
    	if(ok(mask)) ans=max(ans,__builtin_popcount(mask));
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

class Prime {
public:
    Prime(ll n) {
        mPrimeTbl.clear();
        vector<bool> u(n, false);
        for (ll i = 2; i <= n; ++i) {
            if (u[i])
                continue;
            mPrimeTbl.push_back(i);
            for (ll p = i; p <= n; p += i)
                u[p] = true;
        }
    }

    ~Prime() {}

    ll num() {
        return static_cast<ll>(mPrimeTbl.size());
    }

    ll get(ll index) {
        return mPrimeTbl[index];
    }

private:
    vector<ll> mPrimeTbl;
};

ll S[100005];
bool P[100005];

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

    memset(S, 0, sizeof(S));
    memset(P, 0, sizeof(P));
    Prime prime(100005);
    REP(i, prime.num()) {
        P[prime.get(i)] = true;
    }

    REP(i, 100004) {
        if (P[i] && P[(i + 1) / 2])
            S[i]++;
        S[i + 1] += S[i];
    }
    ll Q;
    cin >> Q;
    REP(_, Q) {
        ll l, r;
        cin >> l >> r;
        cout << S[r] - S[l - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1780
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rep0(i,n) for(int i=0;i<n;i++)
#define per0(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
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; }
 

void solve() {
    string S, T; cin >> S >> T;
    cout << T + S;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 256
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define PI acos(-1)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

int main()
{

	ll n,a[2],m,v1,v2;

	cin>>n>>a[0]>>a[1];

	sort(a,a+2);

	if((a[1]-a[0])%2==0)
	{
		m=(a[1]-a[0])/2;
	}
	else
	{
		v1=a[0]-1;
		v2=a[1]-v1;
		--v2;
		m = (v2-1)/2 + 1 + v1;

		v2=n-a[1];
		v1=a[0]+v2;
		++v1;
		m = min(m,(n-v1)/2 + 1 + v2);

	}

	cout<<m<<"\n";


	return 0;
}

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

using namespace std;


int main() {
	int k, n, sum = 0;
	cin >> n >> k;
	vector<int> p(n);
	for (int i = 0; i < n; ++i)
		cin >> p[i];
	sort(p.begin(), p.end());
	for (int i = 0; i < k; ++i)
		sum += p[i];
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3600
import math
data = []
tmp = []
output = []
for x in range(0,10000):
    num = int(input())
    if num == 0:
        break
    else:
        tmp = input().split()
        data.append([float(tmp[i]) for i in range(num)])
        avg = sum(data[0])/num
        output.append(math.sqrt(sum(pow( data[0][i] - avg  ,2) for i in range(num))/num ))
        data.clear()
for x in range(len(output)):
    print(output[x])


Measured memory_bytes: 7908
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <stack>

using namespace std;

const int NMAX = 100000 + 5;
typedef long long int lint;

int N;
int v[NMAX];
lint sPart[NMAX];

int st[NMAX];
int dr[NMAX];

bool win[NMAX];

bool vis[NMAX];
void solve(int node) {
    if (vis[node])
        return ;
    vis[node] = true;

    if (st[node] == 0 && dr[node] == N + 1)
        win[node] = true;
    else {
        lint sum = sPart[dr[node] - 1] - sPart[st[node]];
        if (v[st[node]] <= 2 * sum) {
            solve(st[node]);
            win[node] |= win[st[node]];
        }
        if (v[dr[node]] <= 2 * sum) {
            solve(dr[node]);
            win[node] |= win[dr[node]];
        }
    }
}

int main()
{
    //freopen("data.in", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    for (int i = 1; i <= N; ++ i)
        cin >> v[i];
    v[0] = v[N + 1] = 2E9 + 5;

    sort(v + 1, v + N + 1);
    for (int i = 1; i <= N; ++ i)
        sPart[i] = sPart[i - 1] + v[i];

    stack <int> stk;
    stk.push(0);

    for (int i = 1; i <= N; ++ i) {
        while (v[stk.top()] <= v[i])
            stk.pop();
        st[i] = stk.top();
        stk.push(i);
    }

    while (!stk.empty())
        stk.pop();
    stk.push(N + 1);

    for (int i = N; i; -- i) {
        while (v[stk.top()] <= v[i])
            stk.pop();
        dr[i] = stk.top();
        stk.push(i);
    }

    int ans = 0;
    for (int i = 1; i <= N; ++ i) {
        solve(i);
        ans += win[i];
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision;
// #define int cpp_int
using namespace std;

#define fastio 			ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int 			long long
#define ll 				long long
#define ld 				long double
#define vi 				vector<int>
#define pii 			pair<int,int>
#define vpii 			vector< pair<int,int> >
#define uset			unordered_set
#define umap 			unordered_map
#define maxpq 			priority_queue<int>
#define minpq			priority_queue<int,vi,greater<int>()>

#define all(v) 			v.begin(),v.end()
#define part(v,s,e)		v.begin()+s,v.begin()+e
#define rev(v)			reverse(v.begin(),v.end())
#define sz(x)			(int)x.size()
#define def(v)			memset(v,-1,sizeof(v));
#define def0(v)			memset(v,0,sizeof(v));
#define minv(a)			*min_element(all(a))
#define maxv(a)			*max_element(all(a))
#define sumv(a)			accumulate(all(a),0)

#define	lb				lower_bound
#define	ub				upper_bound
#define	desc			greater<int>()
#define	pb				emplace_back
#define	mp				make_pair
#define	F				first
#define	S				second

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a/(__gcd(a,b)))*b

#define setbits(x) 		__builtin_popcountll(x)
#define zerobits(x)		__builtin_ctzll(x)

#define ip(v)	 		for(auto& i:v)	cin>>i;
#define op(v) 			for(auto i:v)	cout<<i<<" ";cout<<endl;
#define deb(x) 			cout <<"Value of " #x << " : " << x << endl;



void solve()
{	

	int x,n;
	cin>>x>>n;

	if(n==0)
	{
		cout<<x<<endl;
		rr;
	}

	set<int>s;

	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		s.insert(a[i]);
	}

	sort(a,a+n);

	int diff=INT_MAX,ans;
	for(int i=a[0]-1;i<=a[n-1]+1;i++)
	{
		if(s.find(i)==s.end())
		{
			if(abs(i-x)<diff)
			{
				diff=abs(i-x);
				ans=i;
			}
		}
	}

	cout<<ans<<endl;

}	

int32_t main()
{

	fastio
	cout<<setprecision(15)<<fixed;


	int t=1;
	// cin>>t;
	
	for(int i=1;i<=t;i++)
	{
		// cout<<"Case "<<i<<" : "<<endl;
		solve();
	}
	
	#ifndef ONLINE_JUDGE	
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	#endif

	return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
    N, C = map(int, raw_input().split())
    if N == 0:
        break
    S = []
    for loop in range(N):
        lst = map(int, raw_input().split())
        S.append(lst)
    used = {}
    def func(x, y, c):
        if x < 0 or x > y or y >= N:
            return []
        if (x, y) in used:
            return []
        used[(x, y)] = 1
        if S[y][x] == 0:
            return [(x, y)]
        if S[y][x] != c:
            return []
        lst = []
        pos = [[x - 1, y], [x + 1, y], [x - 1, y - 1], [x, y - 1], [x, y + 1], [x + 1, y + 1]]
        for p in pos:
            p += [c]
            ret = func(*p)
            if ret:
                lst += ret
        return lst
    ans = -10000
    for y in range(N):
        for x in range(y + 1):
            if S[y][x] == 0:
                dum = S[y][x]
                S[y][x] = C
                ret = []
                for i in range(N):
                    for j in range(i + 1):
                        if S[i][j] != 0:
                            used = {}
                            if len(func(j, i, S[i][j])) == 0:
                                ret.append(S[i][j])
                S[y][x] = dum
                score = 0
                for num in ret:
                    if num == C:
                        score -= 1
                    else:
                        score += 1
                ans = max(ans, score)
    print ans


Measured memory_bytes: 4996
#coding:utf-8

a = int(input())

def chk_prime(n):
    i = 2
    is_prime = True
    while i <= n ** (1/2):
        if n % i == 0:
            is_prime = False
            break
        i += 1
    return is_prime
        
        
while chk_prime(a) == False:
    a += 1
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
#define INF 1<<21
using pii = std::pair<int,int>;
#define SORT(v) std::sort(v.begin(), v.end())
const int nmax = 50;
bool graph[nmax][nmax];
int a[nmax], b[nmax];
bool visited[nmax];
void dfs(int v,int N) {
    visited[v] = true;
    for (int i = 0; i < N; i++) {
        if (graph[v][i] == false) continue;
        if (visited[i] == true) continue;
        dfs(i, N);
    }
}
int main() {
    int N, M;
    std::cin >> N >> M;

    for (int i = 0; i < M; i++) {
        std::cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;

    for (int i = 0; i < M; i++) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        for (int j = 0; j < N; j++) {
            visited[j] = false;
        }

        dfs(0,N);
        bool bridge = false;
        for (int j = 0; j < N; j++) {
            if (visited[j] == false) {
                bridge = true;
            }
        }
        if (bridge) {
            ans+=1;
        }
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    
    std::cout << ans << std::endl;
    return 0;

}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    printf("%.10f\n", sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));

    return 0;
}


Measured memory_bytes: 3200
import sys
input = sys.stdin.readline
import math
import time
import numpy as np

k = int(input())

if k %2 ==0 or k%5==0:
    print(-1)
else:
    if k %7 == 0:
        l = k*9//7
    else:
        l = k*9
    q = 10%l
    for i in range(1,1000000):
        if q ==1:
            print(i)
            break
        else:
            q = (q*10)%l
            pass


Measured memory_bytes: 27048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

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

    if(S<=W)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mex=1e5+1;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define sclli(x) scanf("%lld",&x);
#define pii pair<int,int>
#define plli pair<long long int ,lont long int>
#define foit(it,x) for(auto it=x.begin();it!=x.end();it++)
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr);
#define sz(x) x.size()

int main()
{
    
    fast
    int n,k;
    cin>>n>>k;
    int arr[n],dp[n];
    fo(i,0,n)
    cin>>arr[i];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    fo(i,2,n)
    {
        dp[i]=1e9;
        fo(j,max(i-k,0),i)
        dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include <cassert>
#include<stack>
#include<deque>
#include<list>
#include<sstream>
#include<unordered_map>
#include<time.h>
#pragma comment(linker, "/STACK:880999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const ll settled = 400007;

int main()
{
	ios_base::sync_with_stdio(false); cout.tie(NULL);
#ifndef overlord
	//freopen("qual.in", "r", stdin);
	//freopen("qual.out", "w", stdout);
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n, 0), b(m, 0);
	ll coa = 0, cob = 0;
	vector<pll> xy(n*m + 1, { -1, -1 }); // first - row; second - column

	forn(row, 0, n)
	{
		ll i;
		cin >> i;
		if (xy[i].first > -1)
		{
			cout << 0;
			exit(0);
		}
		xy[i].first = row;
	}
	forn(col, 0, m)
	{
		ll i;
		cin >> i;
		if (xy[i].second > -1)
		{
			cout << 0;
			exit(0);
		}
		xy[i].second = col;
	}
	ll ans = 1;
	for (ll i = m * n; i > 0; i--)
	{
		pll ab = xy[i];
		if (ab.first > -1 && ab.second > -1)
		{
			if (a[ab.first] == 1 || b[ab.second] == 1)
			{
				cout << 0;
				exit(0);
			}
			coa++; cob++;
			a[ab.first] = 1;
			b[ab.second] = 1;
			continue;
		}
		if (ab.first > -1)
		{
			if (a[ab.first] == 1)
			{
				cout << 0;
				exit(0);
			}
			coa++;
			a[ab.first] = 1;
			ans *= cob;
			ans %= mod;
			continue;
		}
		if (ab.second > -1)
		{
			if (b[ab.second] == 1)
			{
				cout << 0;
				exit(0);
			}
			cob++;
			b[ab.second] = 1;
			ans *= coa;
			ans %= mod;
			continue;
		}
		ans *= (cob * coa - (m * n - i));
		ans %= mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 15872
k, a, b = map(int, input().split())
biscuits = 1
if a - 1 <= k:
    biscuits += a - 1
    k -= a - 1
if b - a > 3:
    biscuits += k // 2 * (b - a) + k % 2
else:
    biscuits += k
print(biscuits)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m,d;
  cin>>m>>d;
   int cnt = 0;
  if(m<4 || d<22)
  {
    cout<<cnt<<endl;
    return 0;
  }
 
  int i=22;
   int prod =1;
  while(i<=d)
  {
  if(i%10 < 2)
  	i++;
  else
  {
    prod = (i%10)*(i/10);
    if(prod>=4 && prod <=m)
      cnt++;
    i++;
  }
  }

cout<<cnt<<endl;
return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

def odd_detector(a_list):
    is_odd = 0
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

n_division = 0
while odd_detector(a_list) == 0:
    a_list = [a / 2 for a in a_list]
    n_division += 1

print(n_division)


Measured memory_bytes: 2940