akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<algorithm>

using namespace std;

const int maxn = 1010;
const int inf = 0x3f3f3f3f;

int dis[maxn][maxn];
int n,m,L;

struct node
{
    int s,t;
    node(int _s ,int _t):s(_s),t(_t) {}
    node() {};
    bool operator <(const node& o)const
    {
        return t < o.t;
    }
} q[maxn];

int nn;
bool e[maxn][maxn];
void build()
{
    memset(e,0,sizeof(e));
    nn = L;
    for (int i=1; i<=nn; i++)
        for (int j=i+1; j<=nn; j++)
        {
            int d1 = q[j].t - q[i].t;
            int d2 = dis[q[j].s][q[i].s];
            if (d2 <= d1)
            {
                e[i][j] = 1;
                //printf("%d %d\n",i,j);
            }
        }
    for (int k=1;k<=nn;k++)
        for (int i=1;i<k;i++)
            for (int j=k+1;j<=nn;j++)
                e[i][j] = (e[i][j] | (e[i][k] & e[k][j]));
    return ;
}

int vis[maxn];
int cx[maxn];
int cy[maxn];
int find(int u)
{
    for (int v = u; v<=nn; v++)
    {
        if (e[u][v] && !vis[v])
        {
            vis[v] = 1;
            if (cy[v]==-1 || find(cy[v]))
            {
                cx[u] = v;
                cy[v] = u;
                return true;
            }
        }
    }
    return false;
}
int solve()
{
    memset(vis,0,sizeof(vis));
    memset(cx,-1,sizeof(cx));
    memset(cy,-1,sizeof(cy));
    int res = 0;
    for (int i=1; i<=nn; i++)
    {
        if (cx[i]==-1)
        {
            memset(vis,0,sizeof(vis));
            if (find(i))
                res++;
        }
    }
    return res;
}
int main()
{
    while (scanf("%d%d%d",&n,&m,&L)==3)
    {
        if (n==0 &&m==0 && L==0)
            break;
        memset(dis,inf,sizeof(dis));
        for (int i=1; i<=m; i++)
        {
            int u,v,d;
            scanf("%d%d%d",&u,&v,&d);
            u++;
            v++;
            if (d < dis[u][v])
            {
                dis[u][v] = d;
                dis[v][u] = d;
            }
        }

        for (int k=1; k<=n; k++)
            for (int i=1; i<=n; i++)
                for (int j=1; j<=n; j++)
                    dis[i][j] = min(dis[i][j],dis[i][k] + dis[k][j]);
        for (int i=1;i<=n;i++)
            dis[i][i] = 0;


        for (int i=1; i<=L; i++)
        {
            int s,t;
            scanf("%d%d",&s,&t);
            s++;
            q[i] = node(s,t);
        }
        sort(q+1,q+1+L);
        build();
        int res = solve();
        int ans = L - res;

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

    }
    return 0;
}

Measured memory_bytes: 6064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
int main(){
    ll k;
    VL a(5);
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>k;
    sort(a.begin(),a.end());
    if((a[4]-a[0])>k)cout<<":(";
    else cout<<"Yay!";
}

Measured memory_bytes: 256
K,N=map(int,input().split())
A=list(map(int,input().split()))
B=0
for i in range(N-1):
    b=A[i+1]-A[i]
    if b>B:
        B=b
        n=i
b=K-A[N-1]+A[0]
if b>B:
    B=b
print(K-B)

Measured memory_bytes: 26004
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 0;
		int idx = 0;
		for (int i = 1; i <= n; i++) {
			sum += i;
			if (sum >= n) {
				idx = i;
				break;
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = idx; i > 0; i--) {
			if (sum - n != i) {
				sb.append(i).append("\n");
			}
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a) 
int main(){
  string n;
  cin>>n;
  if(n.at(0)!=n.at(1)||n.at(1)!=n.at(2))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

int main()
{
 	int n;
  cin>>n;
  int mat[n][3];
  for(int i=0; i<n; i++)
  {
   	cin>>mat[i][0]>>mat[i][1]>>mat[i][2]; 
  }
  int dp[n][3];
  memset(dp,0,sizeof(dp));
  dp[0][0]=mat[0][0];
  dp[0][1]=mat[0][1];
  dp[0][2]=mat[0][2];
  
  for(int i=1; i<n; i++)
  {
   	dp[i][0]=max(dp[i-1][1]+mat[i][0],dp[i-1][2]+mat[i][0]);
    dp[i][1]=max(dp[i-1][0]+mat[i][1],dp[i-1][2]+mat[i][1]);
    dp[i][2]=max(dp[i-1][0]+mat[i][2],dp[i-1][1]+mat[i][2]);
    
  }
  int res=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>

char input[51];

int main(int argc, char const* argv[]) {
	using namespace std;

	int n;
	cin >> n;
	cin >> input;

	long long int count = 0;

	for (int i = 0; i < n; i++) {
		if (input[i] == 'A' && input[i + 1] == 'B' &&
		    input[i + 2] == 'C')
			count++;
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int[] Ti = new int[N];
    int ans = 0;
    for(int i = 0; i < N; i++)
      Ti[i] = sc.nextInt();
      
    for(int i = 0; i < N-1; i++){
      if(Ti[i+1] - Ti[i] <= T){
        ans += Ti[i+1] - Ti[i];
      }else if(Ti[i+1] - Ti[i] > T){
        ans += T;
      }else{
        System.out.println(Ti[i+1] + " " + Ti[i] + "例外発生");
      }
    }
    System.out.println(ans+T);
    
	}
}

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

int main(void)
{
    int total, poyo;
    while(1) {
        cin >> total;
        if(total==0) break;
        for(int i=0; i<9; i++) {
            cin >> poyo;
            total -= poyo;
        }
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

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

    int req = n/1000;
    req*=1000;
    if (req<n)
        req+=1000;
    cout<<req-n<<endl;   
}

Measured memory_bytes: 3644
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  long double a,b;cin>>a>>b;
  if(a>b)cout<<"GREATER";
  else if(a<b)cout<<"LESS";
  else cout<<"EQUAL";
}


Measured memory_bytes: 27124
import sys
sys.setrecursionlimit(10 ** 7)

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

N = int(input())
A = list(map(int, input().split()))

al = sum(A)

x = al - sum(A[1::2]) * 2

ans = []
ans.append(x)

for i in range(N-1):
    x = A[i] * 2 - x
    ans.append(x)

print(' '.join(map(str, ans)))


Measured memory_bytes: 19144
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define MAX_T 50
#define WIDTH 7100
pair<int, vector<vector<int>>> E[MAX_T][WIDTH], D[WIDTH*4];
vector<vector<int>>X;
int hantei(vector<vector<int>>a) {
	int sum = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			int Num = (a[i][j] + 15) % 16; if (a[i][j] == 0)continue;
			sum += abs(i - (Num / 4)) + abs(j - (Num % 4));
		}
	}
	return sum;
}
int main() {
	for (int i = 0; i < 4; i++) {
		vector<int>FF; for (int j = 0; j < 4; j++) { int p; cin >> p; FF.push_back(p); }
		X.push_back(FF);
	}
	E[0][0] = make_pair(hantei(X), X);
	for (int i = 0; i < MAX_T; i++) {
		int CNT = 0;
		if (E[i][0].first == 0) { cout << i << endl; break; }
		for (int j = 0; j < WIDTH; j++) {
			if (E[i][j].second.size() == 0)break;
			int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
			vector<vector<int>>H = E[i][j].second; int I = E[i][j].first;
			int C = 0;
			for (int k = 0; k < 16; k++) {
				if (H[k / 4][k % 4] == 0) {
					C = k;
				}
			}
			for (int k = 0; k < 4; k++) {
				vector<vector<int>>J = H;
				int Ex = (C / 4) + dx[k], Ey = (C % 4) + dy[k];
				if (Ex < 0 || Ex > 3 || Ey < 0 || Ey > 3)continue;
				swap(J[C / 4][C % 4], J[Ex][Ey]);
				D[CNT] = make_pair(hantei(J), J); CNT++;
			}
		}
		sort(D, D + CNT); E[i + 1][0] = D[0]; int cnt2 = 1;
		for (int k = 1; k < CNT; k++) {
			if (D[k - 1] == D[k])continue;
			E[i + 1][cnt2] = D[k]; cnt2++;
		}
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define vec(a) vector<int > a;

typedef pair<int ,int > pii;
typedef long long LL;
const long long oo = 1e9 + 7;

int h,w;
char a[123][123];

int main() {
 //   freopen("test.txt","r",stdin);
    cin >> h >> w;
    for (int i = 1 ; i <= h ; i++) {
        for (int j =1 ; j <= w ; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0 ; i <= h +1 ; i++) {
        for (int j = 0 ; j <= w +1 ; j++) {
            if ( i == 0 || i == h+1 || j == 0 || j == w + 1) {
                cout << '#';
            } else cout << a[i][j];
        }
        cout << endl;
    }

}


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

vector<int> cnt, arr;
vector<vector<int > > grid;
int main () {
    int H, W, N;
    cin >> H >> W;
    cin >> N;
    cnt= vector<int> (N+1, 0);
    for(int i=1;i<=N;i++) {
        cin >> cnt[i];
        for(int j=1;j<=cnt[i];j++) {
            arr.push_back(i);
        }
    }
    
    grid = vector<vector<int> > (H+1, vector<int> (W+1, 0));
    for(int i=1;i<=H;i++) {
        if(i%2) {
            for(int j=1;j<=W;j++) {
                grid[i][j] = arr.back();
                arr.pop_back();
            }
        } else {
            for(int j=W;j>=1;j--) {
                grid[i][j] = arr.back();
                arr.pop_back();
            }
        }
    }
    
    for(int i=1;i<=H;i++) {
        for(int j=1;j<=W;j++) {
            cout << grid[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long ans=0;
            int v =(int)Math.sqrt(n);
            for (int i = v ; i>=1 ; i--) {
                if ((n%i)==0) {ans=(i-1)+(n/i-1);break;}
            }
            out.println(ans);
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public Long nextLong() { return Long.parseLong(next()); }


    }

}

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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> b(n - 1);
    rep(i, n - 1) {
        scanf("%d", &b[i]);
    }
    vector<int> a(n);
    if (n == 2) {
        printf("%d", b[0] * 2);
        return 0;
    }
    rep(i, n) {
        if (i == 0) {
            a[i] = b[i];
        } else if (i == n - 1) {
            a[i] = b[i - 1];
        } else {
            a[i] = min(b[i - 1], b[i]);
        }
    }
    printf("%d", accumulate(a.begin(), a.end(), 0));
    return 0;
}

Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll gcd(ll m, ll n)
{
  return (n==0) ? m : gcd(n, m%n);
}

int main()
{
  ll A, B;
  cin >> A >> B;
  
  ll C = gcd(A, B);
  ll ans = 1;
  
  if(C%2==0){
    ans++;
    while(C%2==0) C/=2;
  }
  for(ll i = 3; i*i <= C; i+=2){
    if(C%i==0){
      ans++;
      while(C%i==0) C/=i;
  	}
  }
  if(C>1) ans++;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long int a[330][330];
long long int s=0;
long long int ss=0;
for(int i=1;i<=n;i++)
{
    for(int j=1;j<=n;j++)
    {
         cin>>a[i][j];
        s+=a[i][j];
    }

}
s/=2;
bool flag=0;
for(int i=1;i<=n;i++)
{
    for(int j=i+1;j<=n;j++)
    {
        bool pp=0;
        for(int w=1;w<=n;w++)
        {
            if(w==i||w==j)
            {
                continue;
            }
            else
            {
                if(a[i][w]+a[w][j]<a[i][j])
                {
                    flag=1;
                }
                else if(a[i][w]+a[w][j]==a[i][j])
                {
                    pp=1;
                }
            }
        }
        if(pp==1)
        {
            ss+=a[i][j];
        }
    }
}
//printf("%lld %lld\n",s,ss);
if(flag==1)
{
    printf("-1\n");
}
else
{
    printf("%lld\n",s-ss);
}

    return 0;
}


Measured memory_bytes: 1024
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=int(input())
# x=(10**9-s%(10**9))%(10**9)
# y=(s+x)//(10**9)
y=math.ceil(s/(10**9))
x=(10**9)*y-s
print(0, 0, 10**9,1,x,y)
# print(10**9,1)
# print(10**9-s%(10**9),s//(10**9))

Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
int a,b,c,d;
string S;
vi va, vb;

void input() {
  cin>>a>>b>>c>>d;
  while(a || c){
    c -= b;
    if (c <= 0){
      cout<<"Yes"<<endl;return;
    }
    a -= d;
    if (a <= 0){
      cout<<"No"<<endl;return;
    }

  }
  ;
  ;
}
void solve() {
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 3640
def sortex(X):
  b=sorted(X)
  b.append("null")
  a=[]
  for i in range(len(X)):
    if b[i]!=b[i+1]:a.append(b[i])
  return a
n,s=int(input()),input().split();s=sortex(s);print("Four"if len(s)==4else"Three")

Measured memory_bytes: 3060
n=int(input())
A=list(map(int,input().split()))
B=sorted([A[i]-(i+1) for i in range(n)])
if n%2==1:
    b=B[n//2]
else:
    b=(B[n//2-1]+B[n//2])//2
r=0
for i in range(n):
    r+=abs(B[i]-b)
print(r)

Measured memory_bytes: 25196
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define mod 1000000007
#define mod1 1000000009
#define mod2 1000000021
#define INF 500001
#define MAX 1000000001
using namespace std;

/* 🐣🐥 */
int arr[100001][3];
int dp[100001][3];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			scanf("%d", &arr[i][j]);
		}
	}
	dp[0][0] = arr[0][0], dp[0][1] = arr[0][1], dp[0][2] = arr[0][2];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			dp[i][j] = max(dp[i-1][(j+1)%3], dp[i - 1][(j + 2) % 3]) + arr[i][j];
		}
	}
	printf("%d", max({ dp[n - 1][0],dp[n - 1][1] ,dp[n - 1][2] }));

	return 0;
}

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

vector<int> adj[100100];
bool dp[2][100100];

void dfs(int i, int v) {
    dp[i][v] = true;
    const int j = 1 - i;
    for (int u : adj[v]) {
        if (dp[j][u]) continue;
        dfs(j, u);
    }
}

int main() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v; u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0, 0);
    long long c1 = 0, c2 = 0, c12 = 0;
    for (int i = 0; i < n; i++) {
        c12 += (dp[0][i] && dp[1][i]);
        c1 += dp[1][i];
        c2 += dp[0][i];
    }
    cout << c1 * c2 - c12 * (c12 + 1) / 2 - m << endl;
}


Measured memory_bytes: 7808
#include<stdio.h>

main(){

int i,j,H,W;

while(1){
scanf("%d %d",&H,&W);
if (H==0&&W==0) break;

for(j=0;j<H;j++){
for(i=0;i<W;i++){
if(i!=0&&i!=W-1&&j!=0&&j!=H-1) printf(".");
else printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
N, M = list(map(int, input().split()))

s = list()

for m in range(M):
    ks = list(map(int, input().split()))
    zz = [0] * 10
    for u in range(1, len(ks)):
        zz[ks[u] - 1] = 1
    s.append(zz)

p = list(map(int, input().split()))

ans = 0
for z in range(2 ** N):
    y = [0] * 10
    for x in range(10):
        y[x] = z >> x & 1
    b = True
    for m in range(M):
        w = 0
        for q in range(10):
            w = w + (s[m][q] & y[q])
        b = b & ((w % 2) == p[m])
    if b == True:
        ans = ans + 1

print(ans)


Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, k = LI()
    s = S()
    conb = []
    for i in range(n-1):
        conb.append(s[i] == s[i+1])
    print(min(sum(conb) + k * 2, n-1))




if __name__ == '__main__':
    main()

Measured memory_bytes: 4668
/**
 * The Last One is the Best
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		int n = parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			line = br.readLine();
			int k = parseInt(line.substring(0, line.indexOf(' ')));
			int p = parseInt(line.substring(line.indexOf(' ') + 1));
			System.out.println((k %= p) != 0 ? k : p);
		}
	}
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{   
    gearup;
    int n,u,v; cin >> n >> u >> v;
    vvl g(n);
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vvl dists(n,vl(2,0));
    function<void(int,int,int,int)> dfs = [&](int node,int pre_node,int dist,int type) -> void{
        dists[node][type] = dist;
        for(auto nv:g[node]){
            if(nv == pre_node)continue; //逆流を防ぐ
            dfs(nv,node,dist+1,type);
        }
        return;
    };
    dfs(u-1,-1,0,0);
    dfs(v-1,-1,0,1);
    ll res = 0;
    rep(i,n)if(dists[i][0] < dists[i][1])res = max(res,dists[i][1]-1);
    out(res);
}

Measured memory_bytes: 23092
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> x(n); REP(i, n) cin >> x[i];
  int ans = INF;
  FOR(i, 1, 101) {
    int tmp = 0;
    REP(j, n) tmp += (x[j] - i) * (x[j] - i);
    chmin(ans, tmp);
  }
  cout << ans << '\n';
  return 0;
}


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

int main() {
string s;
cin >> s;
if(s[2] == s[3] && s[4] == s[5]){
  cout << "Yes" << endl;
}
else{
  cout << "No" << endl;
}

}

Measured memory_bytes: 256
//package src.com.jetman.atcoder;

import java.util.*;

/**
 * @description:
 * @author: Jetman
 * @create: 2020-08-29 14:39
 **/
public class Main {

    Scanner sc = new Scanner(System.in);

    long MOD = 1000000000 + 7;

    long dp[][];

    private void slove() {

        int n = sc.nextInt();

        Map<Integer,List<Integer>> edge = new HashMap<>();
        long ans = 0;
        for (int i = 1; i <= n ; i++) {
            ans += ((long)i*(n-i+1L));
        }
        for (int i = 1; i < n; i++) {
            long l = sc.nextInt();
            long r = sc.nextInt();
            if (l > r) {
                long tmp = l;
                l = r;
                r = tmp;
            }
            ans -= l*(n-r+1L);
        }


        System.out.println(ans);



    }

    private void build(Map<Integer, List<Integer>> edge, int l, int r) {
        List<Integer> list = edge.getOrDefault(l, new ArrayList<>());
        list.add(r);
        edge.put(l,list);
    }


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


Measured memory_bytes: 59596
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
   long long int n,i=100;
   int count=0;
   scanf("%lld",&n);
   while(i<(double)n)
   {
       i=i*(1.01);
       count++;
   }
   printf("%d\n",count);
}


Measured memory_bytes: 1728
#include <iostream>
#include <vector>

using namespace std;

int can[40][40];
int inside[40][40];

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

string answer;

vector<int> v;
int dfs(int x,int y,int hand){
	if(x == 1 && y == 2 ) return 0;
	//cout << x << " " << y << endl;
	
	if( !can[y+dy[hand]][x+dx[hand]] ){
		//v.push_back(hand);
		y += dy[hand];
		x += dx[hand];
		hand = (hand+1)%4;
		
	}
	if( can[y+dy[(hand+3)%4]][x+dx[(hand+3)%4]] ){
		do{
			hand = (hand+1)%4;
		}while(!can[y+dy[hand]][x+dx[hand]]);
		v.push_back(hand);
	}
	v.push_back(hand);
	dfs(x+dx[(hand+3)%4],y+dy[(hand+3)%4],hand);
	
}
int main(){

	for(int i = 0 ; i < 9 ; i++){
		if( i % 2 ){
			for(int j = 0 ; j < 5 ; j++){
				char c;
				cin >> c;
				if( c == '1' ){
					can[1+i/2*3][1+3*j] = 1;
					can[1+i/2*3+1][1+3*j] = 1;
					can[1+i/2*3+2][1+3*j] = 1;
					can[1+i/2*3+3][1+3*j] = 1;
				}
			}
		}else{
			for(int j = 0 ; j < 4 ; j++){
				char c;
				cin >> c;
				if( c == '1' ){
					can[i/2*3+1][1+j*3+0] = 1; 
					can[i/2*3+1][1+j*3+1] = 1;
					can[i/2*3+1][1+j*3+2] = 1;  
					can[i/2*3+1][1+j*3+3] = 1; 
				}
			}
		}
	}
	dfs(1,0,0);
	v.push_back(-1);
	int idx = 0;
	for(int i = 1 ; i < v.size() ; i++){
		if( v[i] != v[i-1] ){
			int len = (i - idx);
			//cout << len << endl;
			cout << string((len+1)/3,"RDLU"[v[idx]]);
			idx = i;
		}
	}
	cout << endl;
	
}

Measured memory_bytes: 1208
object Main extends App {
	import scala.math._

	val N = scala.io.StdIn.readInt

	val F = new Array[Int](N)
	val P = Array.ofDim[Int](N,11)

	for(i<-0 until N){
		val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		for(j<-0 until 10){
			if(temp(j) == 1) F(i) = F(i) | 0x1 << j
		}
	}

	for(i<-0 until N){
		P(i) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	}

	var ans = Int.MinValue
	var sum = 0
	for(i<-1 until (0x1 << 10)){
		sum = 0
		for(j<-0 until N){
			sum = sum + P(j)(ele(i & F(j)))
		}
		ans = max(ans,sum)
//		println(sum)
	}

	println(ans)


	def ele(x: Int): Int = {
		var n = x
		n = (0x55555555 & n) + (0x55555555 & (n >> 1));
		n = (0x33333333 & n) + (0x33333333 & (n >> 2));
		n = (0x0f0f0f0f & n) + (0x0f0f0f0f & (n >> 4));
		n = (0x00ff00ff & n) + (0x00ff00ff & (n >> 8));
		n = (0x0000ffff & n) + (0x0000ffff & (n >> 16));
		n;
	}


	
}

Measured memory_bytes: 29660
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
typedef struct {
    int d0;
    int d1;
    int d2;
    int d3;
    int d4;
    int d5;
}DICE;
 
int DiceRoll(DICE[], int);
void Dice(char p, DICE[], int);
int Count(DICE[], int);
 
int main() {
    DICE d[100];
    int i = 0, flg = 0, n;
    char str[2][4] = { "Yes" ,"No" };
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d%d%d%d%d%d", &d[i].d0, &d[i].d1, &d[i].d2, &d[i].d3, &d[i].d4, &d[i].d5);
    for (i = 1; flg == 0&&i < n; i++) flg = DiceRoll(d, i);
    if (flg) { printf("No\n"); return 0; }
    printf("Yes\n");
    return 0;
}
 
int DiceRoll(DICE d[], int i)
{
    int j, l, iSum, jSum;
     
        for (j = 0; j < i; j++) {
            iSum = d[i].d0 + d[i].d1 + d[i].d2 + d[i].d3 + d[i].d4 + d[i].d5;
            jSum = d[j].d0 + d[j].d1 + d[j].d2 + d[j].d3 + d[j].d4 + d[j].d5;
            if (jSum == iSum) {
            if (d[j].d5 == d[i].d0) Dice('N', d, j), Dice('N', d, j);
            else if (d[j].d1 == d[i].d0) Dice('N', d, j);
            else if (d[j].d4 == d[i].d0) Dice('S', d, j);
            else if (d[j].d2 == d[i].d0) Dice('W', d, j);
            else if (d[j].d3 == d[i].d0) Dice('E', d, j);
            if (d[j].d0 == d[i].d0) {
                for (l = 0; l < 4; l++) {
                    if (d[j].d1 == d[i].d1)if (d[i].d2 == d[j].d2&&d[i].d3 == d[j].d3&&d[i].d4&&d[j].d4&&d[i].d5 == d[j].d5)  return 1;
                    Dice('L', d, j);
                }
            }
            if (Count(d, i) >= 10 && Count(d, j) >= 10) return 1;
        }
    }
    return 0;
}
 
void Dice(char p, DICE d[], int n) {
    int tmp;
    if (p == 'S') { tmp = d[n].d0; d[n].d0 = d[n].d4; d[n].d4 = d[n].d5; d[n].d5 = d[n].d1; d[n].d1 = tmp; }
    if (p == 'W') { tmp = d[n].d0; d[n].d0 = d[n].d2; d[n].d2 = d[n].d5; d[n].d5 = d[n].d3; d[n].d3 = tmp; }
    if (p == 'E') { tmp = d[n].d0; d[n].d0 = d[n].d3; d[n].d3 = d[n].d5; d[n].d5 = d[n].d2; d[n].d2 = tmp; }
    if (p == 'N') { tmp = d[n].d0; d[n].d0 = d[n].d1; d[n].d1 = d[n].d5; d[n].d5 = d[n].d4; d[n].d4 = tmp; }
    if (p == 'L') { tmp = d[n].d1; d[n].d1 = d[n].d3; d[n].d3 = d[n].d4; d[n].d4 = d[n].d2; d[n].d2 = tmp; }
}
 
int Count(DICE d[], int n) {
    int cnt = 0;
    if (d[n].d0 == d[n].d1)++cnt;
    if (d[n].d0 == d[n].d2)++cnt;
    if (d[n].d0 == d[n].d3)++cnt;
    if (d[n].d0 == d[n].d4)++cnt;
    if (d[n].d0 == d[n].d5)++cnt;
    if (d[n].d1 == d[n].d2)++cnt;
    if (d[n].d1 == d[n].d3)++cnt;
    if (d[n].d1 == d[n].d4)++cnt;
    if (d[n].d1 == d[n].d5)++cnt;
    if (d[n].d2 == d[n].d3)++cnt;
    if (d[n].d2 == d[n].d4)++cnt;
    if (d[n].d2 == d[n].d5)++cnt;
    if (d[n].d3 == d[n].d4)++cnt;
    if (d[n].d3 == d[n].d5)++cnt;
    if (d[n].d4 == d[n].d5)++cnt;
    return cnt;
}


Measured memory_bytes: 2112
class SegmentTree:
    def __init__(self, initial_values, f=max, zero=0):
        self.__size = len(initial_values)
        self.__n = 1 << ((self.__size - 1).bit_length())
        self.__f = f
        self.__z = zero
        self.__dat = [zero] * (2 * self.__n)
        self.__get_leaf = lambda i: self.__n + i - 1
        self.__get_parent = lambda i: (i-1)//2
        self.__get_children = lambda i: (self.__dat[2*i+1], self.__dat[2*i+2])
        self.__is_left = lambda i: i&1 == 1
        self.__is_right = lambda i: i&1 == 0
        zi = self.__get_leaf(0)
        dat, get_children = self.__dat, self.__get_children
        for i, v in enumerate(initial_values):
            dat[zi + i] = v
        for i in range(zi-1, -1, -1):
            dat[i] = f(*get_children(i))
    
    def update(self, index, value):
        f, dat, get_leaf, get_parent, get_children = self.__f, self.__dat, self.__get_leaf, self.__get_parent, self.__get_children
        i = get_leaf(index)
        if dat[i] == value: return
        dat[i] = value
        while i > 0:
            i = get_parent(i)
            dat[i] = f(*get_children(i))
    
    def query(self, from_inclusive, to_exclusive):
        f, z, dat, get_leaf, get_parent, is_left, is_right = self.__f, self.__z, self.__dat, self.__get_leaf, self.__get_parent, self.__is_left, self.__is_right
        if to_exclusive <= from_inclusive: return z
        a, b = get_leaf(from_inclusive), get_leaf(to_exclusive) - 1
        ans = z
        while b - a > 1:
            if is_right(a): ans = f(ans, dat[a])
            if is_left(b): ans, b = f(ans, dat[b]), b-1
            a, b = a//2, get_parent(b)
        ans = f(ans, dat[a])
        if a != b: ans = f(ans, dat[b])
        return ans

N = int(input())
S = input()
g = lambda c: 1 << (ord(c)-ord('a'))
tree = SegmentTree([g(c) for c in S], lambda x,y:x|y)
Q = int(input())
for _ in range(Q):
    t, a, b = input().split()
    if t == '1': tree.update(int(a)-1, g(b))
    else: print(bin(tree.query(int(a)-1, int(b))).count('1'))

Measured memory_bytes: 89112
#include <iostream>

using namespace std;

int main()
{
	unsigned int n;
	unsigned int s[5][4][11];
	for (int i = 1; i < 5; ++i) {
		for (int j = 1; j < 4; ++j) {
			for (int k = 1; k < 11; ++k) {
				s[i][j][k] = 0;
			}
		}
	}

	cin >> n;
	for (int i = 0; i < n; ++i) {
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		s[b][f][r] += v;
	}

	for (int i = 1; i < 5; ++i) {
		for (int j = 1; j < 4; ++j) {
			for (int k = 1; k < 11; ++k) {
				cout << " " << s[i][j][k];
			}
			cout << endl;
		}
		if (i < 4)
			cout << "####################" << endl;
	}
	return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  double a,b,c,d,e,f;
  while(cin>>a>>b>>c>>d>>e>>f){
    double x,y;
    x=(e*c-b*f)/(a*e-b*d);
    y=(a*f-c*d)/(a*e-b*d);
    if(x == 0){x = 0;}
    if(y == 0){y = 0;}
  
    printf("%.3lf %.3lf\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 3080
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 998244353
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif

int add(int a, int b) {int res = a + b;if (res >= MOD)return res - MOD;return res;}
int mul(int a, int b) {long long res = a;res *= b;if (res >= MOD)return res % MOD;return res;}
int sub(int a, int b) {int res = a - b;if(res < 0)return res + MOD;return res;}
int modpow(ll a, ll b) {a %= MOD; int res = 1; while (b) {if (b & 1)res = mul(res, a); a = mul(a, a); b >>= 1;} return res;}
ll bpow(ll a, ll b) {ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
int modinv(ll a) {return modpow(a, MOD - 2);}

const int minv2 = modinv(2);
void solve() {
    int n, s;
    cin >> n >> s;
    vi arr(n);
    forn(i, n) cin >> arr[i];
    vi cnt(s + 1, 0), temp(s + 1);
    int ans = 0;
    cnt[0] = 1;
    for(int i = 0; i < n; i++){
        temp = cnt;
        cnt = vi(s + 1, 0);
        for(int j = 0; j < s; j++){
            if(j + arr[i] > s){
                continue;
            }
            cnt[j + arr[i]] = add(mul(temp[j], minv2), cnt[j + arr[i]]);
        }
        forn(j, sz(cnt)){
            cnt[j] = add(cnt[j], temp[j]);
        }
    }
    ans = cnt[s];
    ans = mul(ans, modpow(2, n));
    cout << ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3696
N, M = map(int, input().split())
AL = [int(input()) for _ in range(M)]
dp = [0] * (N+1)
dp[0] = 1
amidx = 0
for i in range(1, N+1):
    if amidx < len(AL) and i == AL[amidx]:
        dp[i] = 0
        amidx += 1
    else:
        if i == 1:
            dp[i] = 1
        else:
            dp[i] = dp[i-1] + dp[i-2]
res = dp[-1] % (10**9+7)
print(res)

Measured memory_bytes: 460020
import java.util.*;
import java.lang.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++)
      a[i]=sc.nextInt();
    Arrays.sort(a);
    int sum=0;
    for(int i=0;i<k;i++)
      sum+=a[i];
    System.out.println(sum);
   }
}


Measured memory_bytes: 39032
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}

int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){


 // }
int n;
cin >> n;
vi v(n);
fo(i,0,n)cin >> v[i];

vi ith(n);
fo(i,0,n)ith[i] = i+1+v[i];
vi jth(n);
fo(i,0,n)jth[i] = i+1-v[i];
sort(all(jth));
sort(all(ith));
// fo(i,0,n)cout << ith[i] << ' ';
// cout << endl;
// fo(j,0,n)cout << jth[j] << ' ';
// cout << endl;
int count = 0;
fo(i,0,n){
	auto it1 = upper_bound(all(jth),ith[i]);
	auto it2 = lower_bound(all(jth),ith[i]);
	count += it1-it2;
}
cout << count << endl;



return 0;
	
	}




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

int main() {
  
  int k,n,c;
  bool f = false;
  cin >> k >> n;
  if(n == 0){
    cout << k;
  }else{
    vector<int> a(n);
    for(int i = 0;i<n;i++){
      cin >> a.at(i);
    }
    sort(a.begin(), a.end());
        for(int j = 0;j<=n;j++){
          c = (((j-1) % 2) * 2 - 1) * int((j+1)/2);
          for(int l = 0;l<n;l++){
          	if(k + c == a.at(l)){
              break;
            }else if(l == n - 1){
              cout << k + c << endl;
              f = true;
            }
          }
          if(f == true){
            break;
          }
        }
  }
        
        
}


Measured memory_bytes: 3628
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<fstream>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;

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


int main(){

  int a,b;
  while(cin >> a >> b){
    int c = a+b;
    stringstream ss;
    ss << c;
    string ret;
    ss >> ret;   
    cout << ret.size() << endl;
  }

  for(int j=0;j<=1000;j++){
    string name = "out";
    stringstream ss;
    ss << j;
    string index;
    ss >> index;
    name += index+".txt";
    ofstream ofs(name.c_str());
      ofs << string(100000,'?') << endl;
    
  }

return 0;
}

Measured memory_bytes: 1376
#include <deque>
#include <iostream>

using namespace std;

int main()
{
    int q, ope, tmp, decision;
    deque<int> p = {};

    cin >> q;

    for (int i = 0; i < q; i++){
        cin >> ope;
        if (ope == 0){
            cin>>decision;
            cin>>tmp;
            if(decision==0){
                p.push_front(tmp);
            }else{
                p.push_back(tmp);
            }
        }else if (ope == 1){
            cin>>tmp;
            cout << p[tmp]<<"\n";
        }else{
            cin>>decision;
            if(decision==0){
                p.pop_front();
            }else{
                p.pop_back();
            }
        }
        
        /*
        cout<<"[";
        for(int j=0;j<p.size();j++){
            cout<<p[j]<<" ";
        }
        cout<<"]";
        */
    }
    return 0;
}


Measured memory_bytes: 4564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;cin>>n;
    int a[n+5];
    for(int i=0;i<n;i++) cin>>a[i];
    int temp = -1;
    for(int i=0;i<n;i++)
    {
        for(int k=i+1;k<n;k++)
        {
              temp = max(temp,abs(a[i]-a[k]));
        }
    }
    cout<<temp<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# IMPORT ###############################################################################################################
import sys                                                      # システム
sys.setrecursionlimit(10**6)                                    # 再帰処理の上限変更
from collections import deque, Counter                          # キュー・個数カウント
from itertools   import accumulate, permutations, combinations  # 累積和・順列・組み合わせ
from operator    import itemgetter                              # ソート補助
from bisect      import bisect_left, bisect_right, bisect       # 二分探索
from heapq       import heappop, heappush                       # プライオリティキュー
from fractions   import gcd                                     # 最大公約数
from math        import ceil, floor, sqrt, cos, sin, tan, pi    # 数学処理
from copy        import deepcopy                                # オブジェクトコピー
import numpy         as np                                      # 数値計算

# MAIN #################################################################################################################
def main():
    # Init #############################################################################################################
    im = InputManager()
    # Input ############################################################################################################
    n, k = im.inputMultiple()
    # Logic ############################################################################################################
    ans = 0
    powers = [(2 ** i) for i in range(18)]
    possibilities = [(0.5 ** i) for i in range(18)]
    for i in range(n):
        score = i + 1
        for power, possibility in zip(powers, possibilities):
            if ((score * power) >= k):
                ans = ans + possibility
                break
    ans = ans / n
    # Output ###########################################################################################################
    print("{:.10f}".format(ans))
    # Return ###########################################################################################################
    return

# INPUT MANAGER ########################################################################################################
class InputManager(object):
    def __init__(self):
        pass

    @staticmethod
    def inputSingle(dtype=int):
        return dtype(input())
    
    @staticmethod
    def inputMultiple(dtype=int, aslist=False):
        if aslist:
            return list(map(dtype, input().split()))
        else:
            return map(dtype, input().split())

    @staticmethod
    def input2D(h, dtype=int):
        return [list(map(dtype, input().split())) for i in range(h)]

# CALL MAIN ############################################################################################################
main()

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

using namespace std;

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

    int a = stoi(S.substr(0, 2));
    int b = stoi(S.substr(2, 2));
    if(a>0 && a<=12 && b>0 && b<=12){
        cout<<"AMBIGUOUS"<<endl;
        return 0;
    }
    if(a>0 && a<=12){
        cout<<"MMYY"<<endl;
        return 0;
    }
    if(b>0 && b<=12){
        cout<<"YYMM"<<endl;
        return 0;
    }
    cout<<"NA"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
s
t

2*10^5

Yes No
 */
string s,t;
vector<int> ps['z'-'a'+1];
vector<int> pt['z'-'a'+1];

int main(){
  cin>>s>>t;

  int l = s.size();
  REP(i,l){
    ps[s[i]-'a'].push_back(i);
    pt[t[i]-'a'].push_back(i);
  }

  sort(ps,ps+'z'-'a'+1);
  sort(pt,pt+'z'-'a'+1);

  REP(i,'z'-'a'+1){
    // cerr<<"i="<<i<<endl;
    // for(auto j : ps[i]) cerr<<j<<" ";
    // cerr<<endl;
    // for(auto j : pt[i]) cerr<<j<<" ";
    // cerr<<endl;
    
    if(!equal(ps[i].begin(),ps[i].end(), pt[i].begin(), pt[i].end())){
      cout<<"No\n";
      return 0;
    }
  }

  cout<<"Yes\n";

  return 0;
}


Measured memory_bytes: 3080
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
  auto k = readln.chomp.to!int;
  a[k-1].writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

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

	int q;
	cin >> q;
	int m[q];
	for(int i = 0; i < q; i++) cin >> m[i];

	
	vector<int> num;
	for(int bit = 0; bit < (1<<n); bit++) {
		vector<int> s(n, 0);
		for(int i = 0; i < n; i++) {
			if(bit & (1<<i)) {
				s[i] = 1;
			}	
		}		
		
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(s[i] == 0) {
				//pass
			}
			else {
				ans += array[i];
			}
		}
		num.push_back(ans);

	}

	for(int i = 0; i < q; i++) {
		int flag = 0;
		for(int j = 0; j < num.size(); j++) {
			if(num[j] == m[i]) {
				cout << "yes" << endl;
				flag = 1;
				break;
			}
		}
		if(flag == 0) {
			cout << "no" << endl;
		}
	}


	return 0;
}



Measured memory_bytes: 7080
def main():
    import sys
    input = sys.stdin.readline
    
    H,W = map(int,input().split())
    N = int(input())
    A = list(map(int,input().split()))

    map_list = [[-1]*W for i in range(H)]

    pre = A.pop(0)
    idx = 1
    for i in range(H):
        if i%2==0:
            start = 0
            end = W
            step = 1
        else:
            start = W-1
            end = -1
            step = -1

        for j in range(start,end,step):
            if pre==0:
                pre = A.pop(0)
                idx += 1
        
            pre-=1
            map_list[i][j]= idx

    for i in range(H):
        print(' '.join(map(str,map_list[i])))

        

if __name__=='__main__':
    main()

Measured memory_bytes: 9356