akhauriyash/Code-Regression huggingface dataset:
N, Q = map(int, input().split())

if N == 1:
    for i in range(Q):
        V, W = map(int, input().split())
        print(min(V, W))
else:
    p = []
    p.append(1)
    for i in range(40):
        p.append(p[-1] * N)

    for i in range(Q):
        V, W = map(int, input().split())

        v = []
        w = []
        dv = 0
        dw = 0

        while V > (p[dv + 1] - 1) // (N - 1): dv = dv + 1
        while W > (p[dw + 1] - 1) // (N - 1): dw = dw + 1

        v.append(V)
        e = V
        for j in range(dv, 0, -1):
            e = (e - (p[j] - 1) // (N - 1) - 1) // N + (p[j - 1] - 1) // (N - 1) + 1;
            v.append(e)
        v.reverse()

        w.append(W)
        e = W
        for j in range(dw, 0, -1):
            e = (e - (p[j] - 1) // (N - 1) - 1) // N + (p[j - 1] - 1) // (N - 1) + 1;
            w.append(e)
        w.reverse()

        ans = 1
        j = 0
        while j < len(v) and j < len(w) and v[j] == w[j]:
            ans = v[j]
            j = j + 1
        print(ans)


Measured memory_bytes: 58072
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
int h,w;
char s[105][105];
scanf("%d %d",&h,&w);
for(int i=0;i<h;i++){
    scanf("%s",s[i]);
}

for(int i=0;i<h;i++){
    printf("%s\n",s[i]);
    printf("%s\n",s[i]);
}
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int gint(){
	char c; int f=1;
	while(c=getchar(),c<48||c>57)
		if(c=='-')f=-1;
	int x=0;
	for(;c>47&&c<58;c=getchar()){
		x=x*10+c-48;
	}
	return x*f;
}

int a,b,c,S,M;

int main(){
	a=gint(),b=gint(),c=gint();
	S=a+b+c;
	M=max(a,max(b,c));
	printf("%d\n",S-M);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

bool isNotEnough(const vector<int>& a, int rain0){
  bool ret = false;
  int now = rain0;
  for(int i=0; i<a.size(); i++){
    now = a[i] - now;
  }
  if (rain0 <= now) ret = true;
  return ret;
}

int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }

  int leq, more, mid;
  leq = -1;
  more = min(a[0], a[N-1]) + 1;
  while(abs(more-leq) > 1){
    mid = (leq+more)/2;
    if(isNotEnough(a, mid)) leq = mid;
    else more = mid;
  }
  int tmp = leq;
  cout << 2 * tmp << " ";
  for(int i=0; i<N-1; i++){
    tmp = a[i]-tmp;
    cout << 2 * tmp << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
void solve() {
    int n, w;
    cin >> n >> w;
    pair<int, int> items[n];
    for (int i = 0; i < n; i++) {
    	int wt, val;
    	cin >> wt >> val;
    	items[i] = {wt, val};
    }
    int dp[n][w+1];
    memset(dp, 0, sizeof(dp));
    for (int j = items[0].ff; j <= w; j++)
    	dp[0][j] = items[0].ss;
    for (int i = 1; i < n; i++) {
    	for (int j = 1; j <= w; j++) {
    		dp[i][j] = dp[i-1][j];
    		if (j >= items[i].ff)
    			dp[i][j] = max(dp[i][j], dp[i-1][j-items[i].ff] + items[i].ss);
    	}
    }
    cout << dp[n-1][w];
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
  
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
  
	return 0;
}

Measured memory_bytes: 81772
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        
        for(int i=1; ; i++){
            int H = scanner.nextInt();
            int W = scanner.nextInt();

            if(H == 0 && W == 0){
                break;
            }else{

                for(int j=0; j<H;j++){
                 for(int k=0; k<W; k++){
                    System.out.print("#");
                }
                    System.out.print("\n");
            }
        }
        System.out.print("\n");
    }
}
}


Measured memory_bytes: 37240
#include <stdio.h>
#include <iostream>
#include <string>

int main(void) {
	int a = 0;
	int b = 0;
	std::cin >> a >> b;

	char* str = "";
	if (a > b) {
		str = ">";
	}
	else if (a < b) {
		str = "<";
	}
	else {
		str = "==";
	}

	printf("a %s b\n", str);
	return 0;
}


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

using namespace std;

int main() {
    int h, w, n, r, c;
    string s, t;
    cin >> h >> w >> n >> r >> c >> s >> t;
    int l1 = 0, r1 = 0, u1 = 0, d1 = 0;
    bool yes = true;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'L') ++l1;
        if (s[i] == 'R') ++r1;
        if (s[i] == 'U') ++u1;
        if (s[i] == 'D') ++d1;
        if ((l1 >= c)    ||
            (r1 > w - c) ||
            (u1 >= r)    ||
            (d1 > h - r)) {
            yes = false;
            break;
        }
        if (t[i] == 'L' && c + r1 > 1) --r1;
        if (t[i] == 'R' && c - l1 < w) --l1;
        if (t[i] == 'U' && r + d1 > 1) --d1;
        if (t[i] == 'D' && r - u1 < h) --u1;
    }
    cout << (yes ? "YES" : "NO") << endl;
}


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

string s;
int n;
int a[30];
int ma;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> s;
	n = s.size();
	for(int i=0; i<n; ++i)
		++a[s[i]-'a'];
	for(int i=0; i<26; ++i)
		ma = max(ma, a[i]);
	cout << (ma <= (n+2)/3 ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 512
from collections import deque

k = int(input())

d = deque()
for i in range(1,10):
  d.append(i)
for j in range(k):
  a = d.popleft()
  b = a%10
  if b != 0:
    d.append(10*a+b-1)
  d.append(10*a+b)
  if b != 9:
    d.append(10*a+b+1)
print(a)

Measured memory_bytes: 18768
#include <stdlib.h>
#include <stdio.h>
typedef struct{
    int x;
    int y;
}pos;
int main()
{   int h,w,d;
    scanf("%d%d%d",&h,&w,&d);
    pos a[h*w+1];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int tmp;
            scanf("%d",&tmp);
            a[tmp].x=j;
            a[tmp].y=i;
        }
    }
    int arr[90001]={0};
    for(int i=d+1;i<=h*w;i++){
        arr[i]=arr[i-d]+abs(a[i-d].x-a[i].x)+abs(a[i-d].y-a[i].y);
    }
    int q;
    scanf("%d",&q);
    int l[q],r[q];
    for(int i=0;i<q;i++){
        scanf("%d%d",&l[i],&r[i]);
        printf("%d\n",arr[r[i]]-arr[l[i]]);
    }

    return 0;
}


Measured memory_bytes: 2816
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

def gcd(a, b):
    if a == 0:
        return b
    elif b == 0:
        return a
    else:
        return gcd(b, a%b)

h = a[0]
gcda = a[0]

for i in range(1, n):
    if a[i] > h:
        h = a[i]

    gcda = gcd(gcda, a[i])

if k%gcda == 0 and k <= h:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 19936
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main(void)
{
	int i, j, n;

	scanf("%d", &n);

	for (i = 1; i <= n; i++){
		if (i % 3 == 0){
			printf(" %d", i);
		}

		else{
			j = i;
			while (j > 0){
				if (j % 10 == 3){
					printf(" %d", i);
					break;
				}
					j /= 10;
			}
		}
	}
	putchar('\n');

	return 0;
}

Measured memory_bytes: 1028
import sys
from collections import deque
from collections import defaultdict

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10**17


def main():

    N, M = in_nn()
    LRD = in_nl2(M)

    edge = [[] for _ in range(N)]

    for i in range(M):
        l, r, d = LRD[i]
        l, r = l - 1, r - 1
        edge[l].append((r, d))
        edge[r].append((l, -d))

    v_set = []
    search = [False] * N

    def bfs(N, v0, edge):

        search[v0] = True
        q = deque()
        q.append(v0)

        while q:
            v = q.popleft()
            for nv, _ in edge[v]:
                if not search[nv]:
                    q.append(nv)
                    search[nv] = True

    for i in range(N):
        if not search[i]:
            bfs(N, i, edge)
            v_set.append(i)

    def judge(v0):

        search = defaultdict(lambda: False)
        search[v0] = True

        q = deque()
        q.append(v0)

        pos = defaultdict(lambda: INF)
        pos[v0] = 0

        vs = [v0]

        while q:
            v = q.popleft()
            now_pos = pos[v]
            for nv, dis in edge[v]:
                if pos[nv] == INF:
                    pos[nv] = now_pos + dis
                elif pos[nv] - now_pos != dis:
                    return False
                if not search[nv]:
                    q.append(nv)
                    search[nv] = True
                    vs.append(nv)

        max_pos = -INF
        min_pos = INF
        for tv in vs:
            tp = pos[tv]
            max_pos = max(max_pos, tp)
            min_pos = min(min_pos, tp)

        return max_pos - min_pos <= 10**9 + 1

    ans = 'Yes'
    for v in v_set:
        if not judge(v):
            ans = 'No'

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 167672
N = int(input())
A = [int(_) for _ in input().split()]

xs = sorted(A, reverse=True)

cs = {}

for x in xs:
    cs[x] = cs.get(x, 0) + 1

result = 0

for x in xs:
    if cs[x]:
        for i in range(31, 0, - 1):
            m = 2**i
            y = m - x
            if y > x or y < 1:
                continue
            if y in cs:
                if x == y:
                    if cs[y] >= 2:
                        cs[y] -= 2
                        result += 1
                        break
                else:
                    if cs[y] >= 1:
                        cs[x] -= 1
                        cs[y] -= 1
                        result += 1
                        break

#print(cs)
print(result)


Measured memory_bytes: 112980
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	int N;
	cin >> N;

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

	int sum_up = 0;
	int sum_down = A[1].back();
	for (int i=0; i<A[0].size();i++) sum_up += A[0][i];

	int max = sum_up + sum_down;
	// cout << sum_up << "+" << sum_down << "=" << sum_down+sum_up << endl;
	for(int i=A[0].size()-1;i>=1;i--){
		sum_up -= A[0][i];
		sum_down += A[1][i-1];
		// cout << sum_up << "+" << sum_down << "=" << sum_down+sum_up << endl;
		if (max < sum_up + sum_down){
			max = sum_up + sum_down;
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String[] c1 = sc.nextLine().split(" ");
		String[] c2 = sc.nextLine().split(" ");
		String[] c3 = sc.nextLine().split(" ");
		int[][] grid = new int[][] { { Integer.valueOf(c1[0]), Integer.valueOf(c2[0]), Integer.valueOf(c3[0]) },
				{ Integer.valueOf(c1[1]), Integer.valueOf(c2[1]), Integer.valueOf(c3[1]) },
				{ Integer.valueOf(c1[2]), Integer.valueOf(c2[2]), Integer.valueOf(c3[2]) } };
		int[] x = new int[3];
		int[] y = new int[3];
		x[0] = 0;
		for (int i = 0; i < 3; i++)
			y[i] = grid[0][i] - x[0];
		for (int i = 0; i < 3; i++)
			x[i] = grid[i][0] - y[0];
		String ans = "Yes";
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (x[i] + y[j] != grid[i][j])
					ans = "No";
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<stdio.h> 

int a[10];

void insertion();

void insertion()
{
    int i,j,t;
    for(j=1;j<10;j++)
    {
        t=a[j];
        i=j-1;
        while(i>=0 && a[i]>t)
        {
            a[i+1]=a[i];
            i=i-1;
        }
        a[i+1]=t;
    }
}

int main() 
{
	int i=0;
   for(i=0;i<10;i++)
   {
	   scanf("%d",&a[i]);
   }
   insertion();
   printf("%d\n%d\n%d\n",a[9],a[8],a[7]);
   return 0;
} 

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int a[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			for(int k=j+1;k<=n;k++){
				if(a[i]==a[j]||a[i]==a[k]||a[j]==a[k]) continue;
				if(a[i]+a[j]>a[k]) ans++;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3848
//??????????????????
#include<iostream>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep3(i,k,n) for(int i = k; i < n; i++)
#define INFTY 2000000000
using namespace std;

int L[250002],R[250002],cnt;

//???????????????????£????????????§????????????
void merge(int A[],int n,int left,int mid,int right){
    int n1 = mid-left;
    int n2 = right - mid;
    rep(i,n1){
        L[i]=A[left+i];
    }
    rep(i,n2){
        R[i]=A[mid+i];
    }
    L[n1]=INFTY;
    R[n2]=INFTY;
    int i=0,j=0,k;
    rep3(k,left,right){
        cnt++;
        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(void){
    int A[500000],n,i;
    cnt=0;

    cin >> n;
    rep(i,n) cin >> A[i];
    MergeSort(A,n,0,n);
    
    rep(i,n){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 6952
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n; cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  vector<ll> b;
  b.push_back(inf);
  b.push_back(a[0]);
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i-1]) {
      b.push_back(a[i]);
    }
  }
  b.push_back(-inf);

  ll stocks = 0;
  ll money = 1000;
  for (int i = 1; i < b.size()-1; i++) {
    if (b[i-1] > b[i] && b[i] < b[i+1]) {
      stocks += money / b[i];
      money %= b[i];
    } else if (b[i-1] < b[i] && b[i] > b[i+1]) {
      money += b[i] * stocks;
      stocks = 0;
    }
  }

  cout << money << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional> 

using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int (i)=0;(i)<(n);++(i))
#define rep(i,st,ed) for(register int (i)=(st);(i)<=(ed);++(i))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<typename T> inline T qmin(const T a,const T b) {return a<b?a:b;}
template<typename T> inline T qmax(const T a,const T b) {return a>b?a:b;}
template<typename T> inline void getmin(T &a,const T b) {if(a>b) a=b;}
template<typename T> inline void getmax(T &a,const T b) {if(a<b) a=b;}

inline void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=1e9+7;
const ll linf=1e17+7;

const int N=5e5+7,S=26,logN=21;

char s[N];
int succ[N][S],nxt[N][logN];
int n,q;

int main(){
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=0;i<S;++i) succ[n+2][i]=succ[n+1][i]=n+2;
	nxt[n+2][0]=nxt[n+1][0]=n+2;
	for(int i=n;i>=1;--i){
		int cur=s[i]-'a';
		succ[i][cur]=i+1;
		for(int c=cur+1;c<S;++c) succ[i][c]=succ[succ[i][c-1]][c-1];
		nxt[i][0]=succ[succ[i][S-1]][S-1];
		int pos=nxt[i][0];
		for(int c=0;c<cur;++c) succ[i][c]=succ[pos][c];
	}
	for(int i=1;i<=n+2;++i) eprintf("%d ",nxt[i][0]);eprintf("\n");
	for(int i=1;i<logN;++i){
		for(int j=1;j<=n+2;++j){
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
		//	if(i<=2) cerr<<"pos="<<j<<" level="<<i<<" val="<<nxt[j][i]<<endl; 
		}
	}
	scanf("%d",&q);
	while(q--){
		int l,r;
		scanf("%d%d",&l,&r),++r;
		int pos=l;
		for(int i=logN-1;~i;--i){
		//	cerr<<pos<<"->";
			if(nxt[pos][i]<=r) pos=nxt[pos][i];
		//	cerr<<pos<<endl;
		}
	//	cerr<<pos<<endl;
		puts(pos==r?"Yes":"No");
	}
	return 0;
} 

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


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int H, A;
    cin >> H >> A;
    cout << (H + A - 1) / A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



// check
// 問題文を復唱する


int main() {
  ll n, h, w, m;
  cin >> n >> m;
  // string s;
  // cin >> s;
  vector<ll> k(m, 0);
  vector<ll> p(m, 0);

  vector<vector<ll>> s(m, vector<ll>());

  // cin >> a;

  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      ll o;
      cin >> o;
      o--;
      s[i].push_back(o);
    }
  }

  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }


  ll ans = 0;





  for (int bit = 0; bit < (1 << n); ++bit) { //2^10  10^3

    bool tf = true;
    for (int j = 0; j < m; j++) {//mは10
      ll count = 0;
      for (int l = 0; l < k[j]; l++) {
        if (bit & (1 << s[j][l]))count++;
      }
      if (count%2 != p[j]){
        tf =false;
        break;
      }
    }

    if (tf)ans++;

  }





  cout << ans << endl;


  // cout << (true? "Yes":"No");


}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  long double a;
  long double b;
  cin >> a;
  cin >> b;
  cout << (ll)(a*b) << endl;

  return 0;
}


Measured memory_bytes: 3796
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

// const abcd = "abcdefghijklnmopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}
var inf int = 1e9

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	n := next.Int()
	a := next.Int()
	fmt.Println(n*n - a)

}

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

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[32] = {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};
int main(){
    int n;
    cin>>n;
    cout<<a[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj278().doIt();
	}
	class aoj278{
		void doIt() {
			int n = sc.nextInt();
			for(int i = 0;i < n;i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				int b = sc.nextInt();
				int p = sc.nextInt();
				int ans = 0;
				if(b >=5 && p >= 2)ans = (int)((x*b + y*p)*0.8);
				else {
					ans = x*b + y*p;
					int ans2 = x*b + y*p;
					if(b < 5)ans2 = ans2 + x*(5 - b);
					if(p < 2)ans2 = ans2 + y*(2 - p);
					ans2 = (int)(ans2*0.8);
					if(ans > ans2)ans = ans2; 
				}
				System.out.println(ans);
			}
		}
	}
}

Measured memory_bytes: 23268
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, M;
	cin >> N >> M;
	if (N == M)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a <= 2 * b) {
        cout << 0 << endl;
    }
    else {
        cout << a - 2 * b << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N;
	long count =0;
	scanf("%d", &N);
	for(int i=1; i<=N; i++){
		if(i%3==0 && i%5==0){	
		}
		else if(i%3==0){
		}
		else if(i%5==0){
		}
		else{
			count+=i;
		}		
	}
	if(count>1000000){
		printf("%ld", count);
		//printf("Watch out for overflow.");
	}
	else{
		printf("%ld", count);	
	}
	
	return 0;
}

Measured memory_bytes: 2156
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()

print(len([i for i in range(1, n + 1) if i % 2]) / n)



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

# M個の対戦場は、それぞれ違う距離の対戦相手と対戦するようにする
# そのために、1~Nのうち前半を奇数差、後半を偶数差で構成する
a = 1
if M%2 == 1:
    # M~1までの奇数を順に
    for i in range(M,0,-2):
        print(str(a) + ' ' + str(a+i))
        a+=1
    a = N
    # M-1~2までの偶数を順に
    for i in range(M-1, 1, -2):
        print(str(a) + ' ' + str(a - i))
        a-=1
elif M%2 == 0:
    # M-1~1までの奇数を順に
    for i in range(M-1,0,-2):
        print(str(a) + ' ' + str(a+i))
        a+=1
    a = N
    # M~2までの偶数を順に
    for i in range(M, 1, -2):
        print(str(a) + ' ' + str(a - i))
        a-=1


Measured memory_bytes: 69724
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scanf("%d %d %d", &a, &b, &k)
	if a > k {
		fmt.Printf("%d %d", a-k, b)
	} else if a+b > k {
		fmt.Printf("%d %d", 0, a+b-k)
	} else {
		fmt.Printf("%d %d", 0, 0)
	}
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, Q;
int S, T, X;
size_t pos = 0;

int main() {
    scanf("%d %d\n", &N, &Q);
    set<int> C;
    vector<int> D(Q);
    vector<pair<int, int>> E(2 * N);
    REP(i, N) {
        scanf("%d %d %d\n", &S, &T, &X);
        E[i*2] = make_pair(S - X, X);
        E[i*2+1] = make_pair(T - X, -X);
    }
    REP(i, Q) scanf("%d", &D[i]);
    sort(ALL(E));
    REP(i, Q) {
        while(pos < 2 * N && E[pos].first <= D[i]) {
            if(E[pos].second > 0) C.insert(E[pos].second);
            else C.erase(C.find(-E[pos].second));
            pos++;
        }
        printf("%d\n", C.empty() ? -1 : *C.begin());
    }
 	return 0;
}

Measured memory_bytes: 14592
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        String[] input=new String[h];
        boolean[][] inp=new boolean[h][w];
        Queue<Integer>y=new ArrayDeque<>();
        Queue<Integer>x=new ArrayDeque<>();
        for(int i=0;i<h;i++){
            input[i]=sc.next();
            for(int j=0;j<w;j++){
                inp[i][j]=input[i].charAt(j)=='#';
                if(inp[i][j]){
                    y.add(i);
                    x.add(j);
                }
            }
        }
        int[][] far=new int[h][w];
        int visited=x.size();
        int ans=0;
        int[] numsx={1,0,-1,0};
        int[] numsy={0,1,0,-1};
        int sizetmp;
        while(true){
            if(visited==h*w){
                System.out.println(ans);
                return;
            }
            ans++;
            sizetmp=x.size();
            for(int i=0;i<sizetmp;i++){
                for(int j=0;j<4;j++){
                    try{
                        if(!inp[y.peek()+numsy[j]][x.peek()+numsx[j]]){
                            far[y.peek()+numsy[j]][x.peek()+numsx[j]]=ans;
                            inp[y.peek()+numsy[j]][x.peek()+numsx[j]]=true;
                            visited++;
                            y.add(y.peek()+numsy[j]);
                            x.add(x.peek()+numsx[j]);
                        }
                    }catch(Exception e){
                        continue;
                    }
                }
                x.remove();
                y.remove();
            }
        }
        
        
    }

}

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

#define M 1000000007
typedef long long LL;

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(void)
{
    LL s;
    cin >> s;
    vector<LL> dp(s+2);
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = 0;
    if(s==0 || s==1 || s==2)
    {
        cout << dp[s] << "\n";
        return;
    }

    for(LL i=3; i<=s; i++)
    {
        dp[i] = 1;
        for(LL j=3; j<=i-3; j++)
            dp[i] = (dp[i]+dp[j])%M; 
    }

    cout << dp[s] << "\n";
}

int main()
{
    fastIO_test();

    LL t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

int main(){
  int H, W;
  cin >> H >> W;
  char s[H+2][W+2];
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++) cin >> s[i][j];
  }
  int cnt=0;
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++){
      if(s[i][j]=='#'){
        if(s[i-1][j]=='#' || s[i][j-1]=='#' || s[i+1][j]=='#' || s[i][j+1]=='#')  cnt=cnt;
        else cnt++;
      }
    }
  }
  if(cnt>0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

int main(){
	long long a;scanf("%lld",&a);
	long long ret=a-1;
	for(int i=2;(long long)i*i<=a;i++){
		if(a%i==0)ret=min(ret,i+a/i-2);
	}
	printf("%lld\n",ret);
}

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n, m;
    cin >> n >> m;
    map<int, int> f;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ++f[x];
    }

    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        f[y] += x;
    }

    int rem = n;
    auto it = prev(end(f));
    ll ans = 0LL;
    while (rem > 0) {
        int take = min(it->second, rem);
        /*
        cout << "val: " << it->first << '\n';
        cout << "freq: " << it->second << '\n';
        cout << "take: " << take << '\n';
        */

        ans += 1LL * it->first * take;
        rem -= take;
        if (it != begin(f))
            it = prev(it);
    }

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


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

using ll = long long int;

const int MAX_N = (int)(2000 + 5);
const ll INF = (ll)(1e10 + 5);

ll answer, a[MAX_N];
ll n, z, w;

ll memo[MAX_N][2][MAX_N];

ll ans(int il, int f, ll cx, ll cy) {
  ll opp = (f == 0) ? cy : cx;

  if (memo[il][f][opp] != -1) return memo[il][f][opp];

  if (il == n + 2) {
    return abs(a[cx] - a[cy]);
  }

  ll tmp;
  if (f == 1) {
    tmp = INF;
    for (int i = il; i < n + 2; ++i) {
      tmp = min(tmp, ans(i + 1, 0, cx, i));
    }
  }
  else {
    tmp = -1;
    for (int i = il; i < n + 2; ++i) {
      tmp = max(tmp, ans(i + 1, 1, i, cy));
    }
  }

  return memo[il][f][opp] = tmp;
}

int main(void){
    // Here your code !
    scanf("%d %lld %lld", &n, &z, &w);
    for (int i = 2; i < n + 2; ++i) {
      scanf("%lld", &(a[i]));
    }
    a[0] = z;
    a[1] = w;

    memset(memo, -1, sizeof(memo));

    answer = ans(2, 0, 0, 1);
    printf("%lld\n", answer);
    return 0;
}

Measured memory_bytes: 63232
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
tmodk = []
score = 0
for i in range(k):
  tmodk.append(t[i::k])
for i in range(k):
  for j in range(len(tmodk[i])):
    if j > 0 and beforeEnemyHand == tmodk[i][j]:
      beforeEnemyHand = ""
      continue
    if tmodk[i][j] == "r":
      score += p
    if tmodk[i][j] == "s":
      score += r
    if tmodk[i][j] == "p":
      score += s
    beforeEnemyHand = tmodk[i][j]
    
print(score)

Measured memory_bytes: 8828
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <stack>
#include <queue>

using namespace std;
#define mod 1e9+7
typedef long long ll;

string change_pm(string a){
  if(a=="+") return "-";
  else return "+";
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> v(4);
  
  for(int i=3; i>=0; i--){
    v[i] = N%10;
    N /= 10;
  }
  vector<string> s(3,"+");
  int temp1,temp2,temp3;
  for(int i1=0; i1<2; i1++){
    if(s[0]=="+") temp1 = v[0]+v[1];
    else temp1 = v[0]-v[1];

    for(int i2=0; i2<2; i2++){
      if(s[1]=="+") temp2 = temp1+v[2];
      else temp2 = temp1-v[2];

      for(int i3=0; i3<2; i3++){
        if(s[2]=="+") temp3 = temp2+v[3];
        else temp3 = temp2-v[3];
        if(temp3==7) break;
        s[2] = change_pm(s[2]);
      }
      if(temp3==7) break;
      s[1] = change_pm(s[1]);
    }
    if(temp3==7) break;
    s[0] = change_pm(s[0]);
  }
  cout<<v[0]<<s[0]<<v[1]<<s[1]<<v[2]<<s[2]<<v[3]<<"=7"<<endl;
  return 0;
}

Measured memory_bytes: 256
// B - たてなが
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> h >> w;
  vlli d(n);
  vs e;
  rep(i, 0, h)
  {
    cin >> s;
    e.pb(s);
    e.pb(s);
  }
  rep(i, 0, e.size())
  {
    cout << e[i] << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
    for(int i=0; i<3; i++){
      pq.add(sc.nextInt());

    }

    int a = pq.poll();
    int b = pq.poll();
    int c = pq.poll();

    System.out.println(10*a+b+c);
  }
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long

typedef pair<int,int> pii;
const int N = 1e3+5;
const int H = 1e4+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int h, n;
int a[N], c[N];
int dp[N][H];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> h >> n;
	for(int i=1; i<=n; i++) cin >> a[i] >> c[i];
	for(int j=1; j<=h; j++) dp[0][j] = INF;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=h; j++){
			dp[i][j] = dp[i-1][j];
			if (j-a[i] >= 0) dp[i][j] = min(dp[i][j], dp[i][j-a[i]] + c[i]);
			else dp[i][j] = min(dp[i][j], c[i]);
		}
	}
	int ans = dp[n][h];
	cout << ans << endl;
	return 0;
}


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

int main(){
    ll n;
    cin >> n;
    ll m = sqrt(n);
    ll x;
    for(ll i=m;i>=1;--i){
        if(n%i==0) {
        x=n/i;
        cout << i+x-2;
        break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5+5;

int k , n;
int ar[N];
ll pfx[N];

int main(){
    cin >> k >> n;
    for(int i = 1; i <= n; i++){
        cin >> ar[i];
    }
    for(int i = n-1; i >= 1; i--){
        pfx[i] = pfx[i + 1] + (ar[i + 1] - ar[i]);
    }
    ll ans = 1e18 , sum = 0;
    for(int i = 1; i <= n; i++){
        ans = min(ans , pfx[i] + sum);
        if(i == 1){
            sum += (ar[1] + k) - ar[n];
        } else {
            sum += ar[i] - ar[i-1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
def main():
    from itertools import combinations
    from copy import deepcopy

    h, w, k = map(int, input().split())
    m = [list(input()) for _ in range(h)]
    c = (sum(m,[])).count('#')
    cnt = 0
    for i in range(w + 1):
        for w_ in combinations(list(range(w)), i):
            for j in range(h + 1):
                for h_ in combinations(list(range(h)), j):
                    m_ = deepcopy(m)
                    tmp = c
                    for x in w_:
                        for p in range(h):
                            if m_[p][x] == '#':
                                tmp -= 1
                    for y in h_:
                        for p in range(w):
                            if m_[y][p] == '#':
                                tmp -= 1
                    for x in w_:
                        for y in h_:
                            if m_[y][x] == '#':
                                tmp += 1

                    if tmp == k:
                        cnt += 1

    print(cnt)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9352
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

N, L = read_int()

apples = [L + i for i in range(N)]
tasteN = sum(apples)
INF = float('INF')
def solve():
    res = INF
    for a in apples:
        res = min(res, abs(a))
    return tasteN - res if res * tasteN > 0 else tasteN + res

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main() {
    char c;
    cin >> c;

    if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
typedef long long LL;

using namespace std;

int main()
{
	string s;
	char ss[105];
	int a,b;
	cin >> a;
	cin >> s;
	if(s.size() <= a)
	{
		cout << s;
	}
	else{
		for(int i = 0;i < s.size();i++)
		{
			ss[i] = s[i];
		}
		for(int i = 0;i < 3;i++)
		{
			ss[a+i] = '.';
		}
		ss[a+3] = '\0';
		cout << ss;
	}
	
	return 0;
} 

Measured memory_bytes: 3628
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  string s, t;
  cin >> s >> t;

  int ns = s.length(), nt = t.length();
  vector<int> as(ns + 1, 0), at(nt + 1, 0);
  rep(i, ns) as[i + 1] = as[i] + s[i] - 'A' + 1;
  rep(i, nt) at[i + 1] = at[i] + t[i] - 'A' + 1;

  int q;
  cin >> q;
  while (q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, c--;

    cout << ((as[b] - as[a]) % 3 == (at[d] - at[c]) % 3 ? "YES" : "NO") << '\n'; 
  }




  
  return 0;
}

Measured memory_bytes: 1744