akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int row[8], col[8], dpos[15], dneg[15], ans[8][8] = { 0 };

void print() {
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            if (ans[i][j] == 1) {
                if (row[i] != j) {
                    return;
                }
            }
        }
    }
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            if (row[i] == j) {
                cout << 'Q';
            }
            else {
                cout << '.';
            }
        }
        cout << endl;
    }
}

void recursive(int i) {
    if (i == 8) {
        print();
        return;
    }
    for (int j = 0; j < 8; j++) {
        if (col[j] == 1 || dpos[i + j] == 1 || dneg[i - j + 7] == 1) {
            continue;
        }
        row[i] = j;
        col[j] = dpos[i + j] = dneg[i - j + 7] = 1;
        recursive(i + 1);
        row[i] = col[j] = dpos[i + j] = dneg[i - j + 7] = -1;
    }
}

int main() {
    int k, r, c;

    for (int i = 0; i < 8; i++) {
        row[i] = col[i] = -1;
    }
    for (int i = 0; i < 15; i++) {
        dpos[i] = dneg[i] = -1;
    }

    cin >> k;
    for (int i = 0; i < k; i++) {
        cin >> r >> c;
        ans[r][c] = 1;
    }

    recursive(0);
    
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int a,b,c; cin >> a >> b >> c;
    int ans = c-a+b;
    cout << max(0,ans) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[5000],n;
signed main(){
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>a[i];
        int ma=LLONG_MIN;
        for(int i=0;i<n;i++){
            int cur=0;
            for(int j=i;j<n;j++){
                cur+=a[j];
                ma=max(ma,cur);
            }
        }
        cout<<ma<<endl;
    }

    return 0;
}

Measured memory_bytes: 1180
from functools import lru_cache

(K,) = [int(x) for x in input().split()]


def solve(K):
    def getNext(x):
        if x == 0:
            return [0, 1]
        if x == 9:
            return [8, 9]
        return [x - 1, x, x + 1]

    @lru_cache(maxsize=None)
    def getNum(begin, digits):
        if digits == 0:
            assert False
            return 0
        if digits == 1:
            return 1
        ans = 0
        for x in getNext(begin):
            ans += getNum(x, digits - 1)
        return ans

    ans = []
    count = 0
    for digits in range(1, 30):
        for i in range(1, 10):
            delta = getNum(i, digits)
            if count < K <= count + delta:
                ans.append(i)
                while digits > 1:
                    for x in getNext(ans[-1]):
                        delta = getNum(x, digits - 1)
                        if count < K <= count + delta:
                            ans.append(x)
                            digits -= 1
                            break
                        count += delta
                return "".join(map(str, ans))

            count += delta


print(solve(K))


Measured memory_bytes: 67924
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sum_A=sum(A)
for i in range(N):
    if(B[i]>(A[i]+A[i+1])):
        A[i] -= A[i]
        B[i] -= A[i]
        A[i+1] -= A[i+1]
    elif(B[i]<=A[i]):
        A[i] -= B[i]
        B[i] -= B[i]
    elif(B[i]>=A[i]):
        B[i] -= A[i]
        A[i] -= A[i]
        A[i+1] -= B[i]
        B[i] -= B[i]
sum_end_A = sum(A)
print(sum_A-sum_end_A)

Measured memory_bytes: 24024
#include<bits/stdc++.h>
#define MAX 300000
using namespace std;
vector<int> l[MAX+10];
int c[MAX+10];
set<pair<int,int>,greater<pair<int,int>>> st;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,k;
	cin>>n>>m>>k;
	while(k--)
	{
		int x,y;
		cin>>x>>y;
		l[x].push_back(y);
		c[y]++;
	}
	for(int i=0;i<=m;++i)
		if(c[i])
			st.insert({c[i],i});
	int ans = 1;
	for(int i=0;i<=n;++i)	
	{
		for(int y:l[i])
		{
			st.erase({c[y],y});
			st.insert({c[y]-1,y});
		}
		ans = max(ans,st.begin()->first+(int)l[i].size());
		for(int y:l[i])
		{
			st.erase({c[y]-1,y});
			st.insert({c[y],y});
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 35296
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll a[200010];
map<ll,ll>m;
vector<ll>v;
string s,q;

int main()
{
    ll t,n,i,j,k,l,r,mn=0, mx=0;
    sl2(t,n);
    for(int i=0; i<n; i++)
    {
        sl(k); m[k]=1;
    }
    for(int i=0; i<=105; i++)
    {
        if(m[t+i]==0)
        {
            r=t+i;
            break;
        }
    }
    for(int i=0; i<=105; i++)
    {
        if(m[t-i]==0)
        {
            l=t-i;
            break;
        }
    }

    if(abs(l-t)<= abs(r-t))
        cout<<l<<endl;
    else
        cout<<r<<endl;
}




Measured memory_bytes: 3812
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    l = sorted(LI())
    r = 0
    for i in range(n):
        k = i + 1
        li = l[i]
        for j in range(i+1,n):
            ij = li + l[j]
            while k < n-1 and l[k+1] < ij:
                k += 1
            r += k - j

    return r


print(main())



Measured memory_bytes: 5592
import java.util.*;

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

	int MAX = 100000;

	int[] p = new int[MAX];
	for(int i=2; i<p.length; i++){p[i] = 1;}
	for(int i=2; i<Math.sqrt(MAX)+1; i++){
	    for(int j=i*2; j<MAX; j+=i){
		p[j] = 0;
	    }
	}

	while(sc.hasNext()){
	    int n = sc.nextInt();
	    int max = n;
	    int min = n;
	    
	    for(int i=n-1; i>=0; i--){
		if(p[i]==1){max = i; break;}
	    }
	    for(int i=n+1; i<MAX; i++){
		if(p[i]==1){min = i; break;}
	    }
	    
	    System.out.println(max+" "+min);
	}
    }
}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main(){
    
    for(ll D, E; cin >> D >> E; ){
        if(D == 0)break;
        double ans = 19191919;
        for(ll x = 0; x <= D; x++){
            for(ll y = 0; y <= D; y++){
                if(x + y == D){
                    ans = min(ans, abs(hypot(x, y) - E));
                }
            }
        }
        printf("%.9f\n", ans);
    }
    
    return 0;    
}


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

int p[100005];
int r[100005];
set<int> ans;
void init(int n) {
  for(int i = 0; i < n; i++) {
    p[i] = i;
  }
  return;
}

int Find(int x) {
  return p[x] == x ? x : p[x] = Find(p[x]);
}

void Union(int x, int y) {
  int a = Find(x);
  int b = Find(y);
  if(a == b) return;

  if(r[a] > r[b]) {
    p[b] = a;
  }
  else {
    p[a] = b;
    if(r[a] == r[b]) r[a]++;
  }
}
  

int main() {
  int n,m;
  cin >> n >> m;
  init(n);
  for(int i = 0; i < m; i++) {
    int x,y,z;
    cin >> x >> y >> z;
    x--; y--;
    Union(x,y);
  }

  
  for(int i = 0; i < n; i++) {
    ans.insert(Find(p[i]));
  
  }

  cout << ans.size() << endl;
}

  
  


Measured memory_bytes: 5632
import java.util.*;

public class Main
{
	public static void main(String ards[])
    {
    	Scanner sc=new Scanner(System.in);
      	int[] x=new int[5];
      	int res=0;
      	for(int i=0;i<5;i++)
        {
        	x[i]=sc.nextInt();
          	if(x[i]==0)
            	res=i+1;
        }
      	System.out.println(res);
    }
}

Measured memory_bytes: 35596
#include<stdio.h>

int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	int x = (a+b)/2;    	
	if((a+b)%2 != 0)
		printf("%d\n",x+1);
	else
		printf("%d\n",x);
	return 0;
} 

Measured memory_bytes: 128
#include<stdio.h>
main(){
  int m[102]={0};
  int ans[101]={0};
  int i,j,t,temp,ansp=0;
  while(scanf("%d",&temp)!=EOF){
    if(temp!=0){
      m[temp]++;
      temp=0;
    }
    scanf("%d",&t);
    m[t]++;
  }
  for(i=1;i<=100;i++){
    if(m[i]>m[ans[0]]){
      ans[0]=i;
      ansp=0;
    }
    else if(m[i]==m[ans[0]]){
      ansp++;
      ans[ansp]=i;
    }
  }

  for(i=ansp-1;i>0;i--){
    for(j=0;j<i;j++){
      if(ans[j]>ans[j+1]){
	temp=ans[j];
	ans[j]=ans[j+1];
	ans[j+1]=temp;
      }
    }
  }

  for(i=0;i<=ansp;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}

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

using namespace std;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

string S="()01+-*=";

bool flag=false;

#define NONE -1
int n;
string s;
int F(int &id);
int E(int &id,int sgn);

int getnum(int &id){
    int cnt=0,num=0;
    bool firstzero=s[id]=='0';
    while(id<n&&(s[id]=='0'||s[id]=='1')){
        num*=2;
        num+=(s[id]-'0');
        id++;
        cnt++;
    }
    if(firstzero&&cnt>1){
        flag=false;
    }
    return num;
}

int F(int &id){
    if(id<n){
        if(s[id]=='0'||s[id]=='1')return getnum(id);
        else if(s[id]=='('){
                id++;
                int num=E(id,1);
                if(id<n&&s[id]==')'){
                    id++;
                    return num;
                }
        }
        else if(s[id]=='-'){
            id++;
            return -F(id);
        }
    }
    flag=false;
    return 0;
}
int T(int &id){
    int sum=1;
    if(s[id]=='('||s[id]=='-'||s[id]=='0'||s[id]=='1')sum*=F(id);
    else{
        flag=false;
        return 0;
    }
    if(!flag)return false;
    if(id==n||s[id]==')'||s[id]=='='||s[id]=='+'||s[id]=='-'){
        return sum;
    }
    if(s[id]=='*'){
        id++;
        return sum*T(id);
    }
    else{
        flag=false;
        return 0;
    }    

}
int E(int &id,int sgn){
    int sum=0;
    if(s[id]=='('||s[id]=='-'||s[id]=='0'||s[id]=='1')sum=sgn*T(id);
    else{
        flag=false;
        return 0;
    }
    if(!flag)return false;
    if(id==n||s[id]==')'||s[id]=='='){
        return sum;
    }
    if(s[id]=='+'){
        id++;
        return sum+E(id,1);
    }
    else if(s[id]=='-'){
        id++;
        return sum+E(id,-1);
    }
    else{
        flag=false;
        return 0;
    }    
}

bool Q(){
    int L,R;flag=true;
    int eq=NONE,id;
    REP(i,n){
        if(s[i]=='='){
            if(eq==NONE)
                eq=i;
            else
                return false;
        }
    }
    if(eq==NONE)return false;
    L=E(id=0,1);
    if(!flag||id!=eq)return false;
    R=E(id=eq+1,1);
    if(!flag||id!=n)return false;
    return L==R;
}
int main(){
    flag=true;
    map<char,int> m;
    string input;
    cin>>input;
    n=input.size();
    s=input;
    REP(i,n){
        bool exist=false;
        REP(j,8)if(s[i]==S[j])exist=true;
        if(!exist)m[s[i]]=0;
    }
    int cnt=0;
    for(auto &it:m)it.second=cnt++;
    if(cnt>8){
        cout<<0<<endl;
        return 0;
    }
    set<string> all;
    vector<int> ord(8);
    iota(ord.begin(),ord.end(),0);
    do{
        REP(i,n){
            if(m.count(input[i]))
                s[i]=S[ord[m[input[i]]]];   
        }
        all.insert(s);
    }while(next_permutation(ord.begin(),ord.end()));
    
    int res=0;
    for(auto &it:all){
        s=it;
        if(Q())res++;
    
    }
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 7584
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e6,mod=998244353;
int n,m;
int fac[maxn+5],ifac[maxn+5];
int C(int n,int m){return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
int main(){
	fac[0]=1;rep(i,1,maxn)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[maxn]=power(fac[maxn],mod-2,mod);per(i,maxn-1,0)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	read(n);read(m);
	if(n<m)swap(n,m);
	int ans=0;
	rep(i,1,m)ans=(ans+1ll*C(2*i,i)*C(n+m-2*i,n-i))%mod;
	ans=1ll*ans*power(2,mod-2,mod)%mod*power(C(n+m,n),mod-2,mod)%mod;
	cout<<(ans+n)%mod<<endl;
	return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;
class Main {
  public static void main(String[] args){

    Scanner scanner = new Scanner(System.in);

    double r = scanner.nextDouble();
    double ans1 = Math.PI * r * r;
    double ans2 = Math.PI * 2 * r;

    System.out.printf("%f %f", ans1, ans2);
  }
}


Measured memory_bytes: 28148
H,W = map(int,input().split())
Min = float('inf')
if H >= 3:
    if H%3 == 0:
        Min = 0
    Min = min(Min, W)
if W>=3:
    if W%3 == 0:
        Min = 0
    Min = min(Min, H)

for h in range(1,H):
    cake1 = h*W
    cake2 = (H-h)*(W//2)
    cake3 = (H-h)*(-(-W//2))
    big = max(cake1,cake2,cake3)
    small = min(cake1,cake2,cake3)
    Min = min(Min,big-small)


for w in range(1,W):
    cake1 = w*H
    cake2 = (W-w)*(H//2)
    cake3 = (W-w)*(-(-H//2))
    big = max(cake1,cake2,cake3)
    small = min(cake1,cake2,cake3)
    Min = min(Min,big-small)

print(Min)

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

int main(void){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    } else {
        cout << "Yes " << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
A, B, M = map(int, input().split())  #数字
a = list(map(int, input().split()))
b = list(map(int, input().split()))

pr = []
for i in range(M):
    X = list(map(int, input().split()))  #リスト

    pr.append(a[X[0]-1] + b[X[1]-1] - X[2])

print(min(min(a)+min(b),min(pr)))

Measured memory_bytes: 18736
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
    std::ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<string> map(n);
    for (int i = 0; i < n; i++) {
    	cin >> map[i];
    }
    for (int i = 0; i < n; i++) {
    	for (int j = 0; j < m; j++) {
    		if (map[i][j] == '.') {
    			map[i][j] = '0';
    			for (int ii = i - 1; ii <= i + 1; ii++) {
    				for (int jj = j - 1; jj <= j + 1; jj++) {
    					if (ii >= 0 && ii < n && jj >= 0 && jj < m && map[ii][jj] == '#') {
    						map[i][j]++;
    					}
    				}
    			}
    		}
    	}
    }
    for (int i = 0; i < n; i++) {
    	cout << map[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int i,cnt[100],cace,j, k[100], m,max,temp, l, n, a[100];
	scanf("%d %d", &n, &m);
	for (i = 0; i<n; i++) {
		scanf("%d", &a[i]);
	}
	for (j = 1; j <= m; j++) {
		for (i = 0; i < n-1; i++) {
			temp = a[i] % j;
			max = a[i + 1] % j;
			if (temp > max) {
				cace = a[i + 1];
				a[i + 1] = a[i];
				a[i] = cace;
			}
		}
	}
	for (i = 0; i < n; i++) {
		printf("%d\n", a[i]);
	}
}

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

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			List<Integer> p = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				p.add(sc.nextInt());
			}
			Collections.sort(p);
			int result = 0;
			for (int i = 0; i < k; i++) {
				result += p.get(i);
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 38704
import java.util.Scanner;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		char s[] = sc.next().toCharArray();
		int cnt=0;
		for(int i=0; i<s.length/2; i++) {
			if(s[i] != s[s.length-1-i]) {
				cnt++;
			}
		}
		System.out.println(cnt);
		sc.close();
	}
}


Measured memory_bytes: 22996
import sys
 
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
 
n, y = inm()

discov_flg = False

for a in range(0, n + 1):
    for b in range(0, n + 1 - a):
        c = n - a - b
        total = 10000 * a + 5000 * b + 1000 * c
        if y == total:
            print(f"{a} {b} {c}")
            discov_flg = True
            break
    if discov_flg:
        break
        
if not(discov_flg):
    print("-1 -1 -1")

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

constexpr int MX_V = 1000000;
int cp[MX_V + 1];
int ns[MX_V + 1];

void solve() {
    for (ll i = 2; i <= MX_V; i++) {
        if (cp[i] == 0) {
            cp[i] = i;
        }
        for (ll j = i + i; j <= MX_V; j += i) {
            if (cp[j] != 0) continue;
            cp[j] = i;
        }
    }

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

    set<int> st;
    int mx = 0;
    for (ll i = 0; i < N; i++) {
        st.clear();
        int t = A[i];
        while (t > 1) {
            int q = cp[t];
            if (q > 1) {
                st.emplace(q);
                t /= q;
            }
        }
        for (auto x : st) {
            chmax(mx, ++ns[x]);
        }
    }

    if (mx <= 1) {
        prints()("pairwise coprime");
    }
    else if (mx < N) {
        prints()("setwise coprime");
    }
    else {
        prints()("not coprime");
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 14804
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  get(N);
  vector<vector<int>> G(N);
  FOR(i, N - 1) {
    int a, b;
    get(a, b);
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  vector<int> visited(N);
  queue<Pi> q;
  q.push(Pi(1, 0));
  q.push(Pi(2, N - 1));
  visited[0]=1;
  visited[N-1]=2;
  int a = 0, b = 0;
  while (!q.empty()) {
    Pi p = q.front();
    q.pop();
    int c = p.first, v = p.second;
    for (int x : G[v]) {
      if (visited[x] == 0) {
        q.push(Pi(c, x));
        visited[x] = c;
        if (c == 1) {
          a++;
        } else {
          b++;
        }
      }
    }
  }
  if (a > b) {
    print("Fennec");
  } else {
    print("Snuke");
  }
  return 0;
}

Measured memory_bytes: 6272
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

is_war = False
for Z in range(X + 1, Y + 1):
    if max(x) < Z and min(y) >= Z:
        is_war = True
        break
print('No War') if is_war else print('War')


Measured memory_bytes: 2940
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  int X[N], Y[N];
  for(int i=0; i<N; ++i){
    cin >> X[i];
    Y[i] = X[i];
  }
  sort(Y, Y+N);
  int m1 = Y[N/2-1], m2 = Y[N/2];
  // cout << m1 << " " << m2 << endl;

  for(int i=0; i<N; ++i){
    if(X[i] <= m1){
      cout << m2 << endl;
    } else{
      cout << m1 << endl;
    }
  }

}


Measured memory_bytes: 3712
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = MAP()

# 各レベルでの層とパティの総数を前計算
A = [0] * (N+1)
P = [0] * (N+1)
A[0] = P[0] = 1
for i in range(1, N+1):
    A[i] = A[i-1] * 2 + 3
    P[i] = P[i-1] * 2 + 1

def rec(n, x):
    if n == 0:
        # 最後の1つは食べる残数がまだ残ってれば食べる
        if x >= 1:
            return 1
        else:
            return 0
    else:
        # 食べる残数が真ん中のパティより手前
        if x <= A[n] // 2:
            # 左半分しか考えなくていい(xから左端バンズ分は引く)
            return rec(n-1, x-1)
        # 真ん中のパティ以降まで食べる
        else:
            # 左半分の総取り + 真ん中パティ + 右からいくつか(xから左半分と真ん中パティ分は引く)
            return P[n-1] + 1 + rec(n-1, x - (A[n] // 2 + 1))
print(rec(N, X))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

void input(string &S) {
  char c;
  cin >> c;
  S+=c;
  return;
}

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

  ll n;
  cin >> n;
  string p, q;
  char c;
  rep(i, n) input(p);
  rep(i, n) input(q);
  if(p>q) swap(p, q);
  vl P(n), Q(n);
  rep(i, n) P[i] = p[i]-'0';
  rep(i, n) Q[i] = q[i]-'0';
  ll ans=0;
  do {
    if(P==Q) break;
    ans++;
  } while (next_permutation(all(P)));
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
class UnionFind
{
public:
    vector<T> par;
    UnionFind(T n) : par(n, -1) {}
    void init(T n)
    {
        par.resize(n, -1);
    }

    ll root(T x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool same(T x, T y)
    {
        return root(x) == root(y);
    }

    bool unite(T x, T y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    ll size(T x)
    {
        return -par[root(x)];
    }
};
int main()
{
    ll n, m;
    cin >> n >> m;
    UnionFind<ll> uf(n);
    uf.init(n);
    vector<pair<ll, ll>> bridge(m);
    for (int i = 0; i < m; i++)
    {
        cin >> bridge[i].first >> bridge[i].second;
        bridge[i].first--;
        bridge[i].second--;
    }
    vector<ll> res;
    ll all = n * (n - 1) / 2;
    for (int i = 0; i < m; i++)
    {
        res.emplace_back(all);
        ll a = bridge[m - i - 1].first, b = bridge[m - i - 1].second;
        if (uf.same(a, b))
            continue;

        ll sa = uf.size(a), sb = uf.size(b);
        all -= sa * sb;
        uf.unite(a, b);
    }
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); i++)
        cout << res[i] << endl;
}

Measured memory_bytes: 4596
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

dp = [float('inf')] * N
dp[0] = 0

Func = min
for i, hi in enumerate(h):
    if i == 0:
        continue
    x = (0 if i-K < 0 else i-K)
    dp[i] = min([dpj + abs(hi - hj) for dpj, hj in zip(dp[x:i], h[x:i])])

print(dp[-1])

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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;


int32_t main()
{
    int h = in(), a = in();
    cout << (h+a-1)/a << nl;
    return 0;
}


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

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define y0 yORZDXM
#define y1 yORZDXM
#define y2 yORZDXM
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 2005;

/*
define A'ik as the ith element in the kth copy (1 <= k <= K),
then the contribution of A'ik = (number of elements less than Ai in A) * (K - k) + (number of elements less than Ai and after Ai in A)
for one i, the sum of the contribution among all k is
(number of elements less than Ai in A) * (K * K - (1 + 2 + ... + K)) + (number of elements less than Ai and after Ai in A) * K
summing the second terms in all i, we get (the number of invesions in A) * K
summing the first terms we can use some algo to compute it.
*/

int n, k;
int a[maxn], cnt[maxn];
ll ans = 0;

int main(){
	scanf("%d%d", &n, &k);
	FOR(i, 0, n) scanf("%d", a + i);
	FOR(i, 0, n) FOR(j, i + 1, n) if(a[i] > a[j]) ++ans;
	(ans *= k) %= INF;
	FOR(i, 0, n) ++cnt[a[i]];
	FOR(i, 1, 2000) cnt[i] += cnt[i - 1];
	FOR(i, 0, n)
		(ans += 1ll * (cnt[a[i] - 1] * ((1ll * k * k - 1ll * (k + 1) * k / 2) % INF)) % INF) %= INF;
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 256
def calc(x1, y1, x2, y2):
    return 2 * (x2 - x1), 2 * (y2 - y1), x2 ** 2 + y2 ** 2 - x1 ** 2 - y1 ** 2


n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    cx1, cy1, z1 = calc(x1, y1, x2, y2)
    cx2, cy2, z2 = calc(x1, y1, x3, y3)
    dcy, dz = cx2 * cy1 - cx1 * cy2, cx2 * z1 - cx1 * z2
    y = dz / dcy
    x = (z1 - cy1 * y) / cx1 if cx1 else (z2 - cy2 * y) / cx2
    r = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
    print('{:.3f} {:.3f} {:.3f}'.format(x, y, r))

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

int main() {
  int A, B;
  cin >> A >> B;
  string s1;
  cin >> s1;
  
  string ans = "Yes";
  
  for(int i = 0; i<A; i++){
    if(s1.at(i) != '0' && s1.at(i) != '1' && s1.at(i) != '2' && s1.at(i) != '3' && s1.at(i) != '4' && s1.at(i) != '5' && s1.at(i) != '6' && s1.at(i) != '7' && s1.at(i) != '8' && s1.at(i) != '9'){
      ans = "No";
      break;
    }
  }
  if(s1.at(A) != '-'){
    ans = "No";
  }
  for(int j = A+1; j<A+B+1; j++){
   if(s1.at(j) != '0' && s1.at(j) != '1' && s1.at(j) != '2' && s1.at(j) != '3' && s1.at(j) != '4' && s1.at(j) != '5' && s1.at(j) != '6' && s1.at(j) != '7' && s1.at(j) != '8' && s1.at(j) != '9'){
    ans = "No";
      break;
   }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
  cin>>n;
    if(n%10==9||n/10==9){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c,d,e;
  cin>>a;
  if(a=="Sunny") cout<<"Cloudy";
  if(a=="Cloudy") cout<<"Rainy";
  if(a=="Rainy") cout<<"Sunny";
  cout<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int n, d;
	cin >> n >> d;

	vector<vector<int>> D(n, vector<int>(d));
	rep(i, n) rep(j, d) cin >> D[i][j];

	int ans = 0;
	rep(i, n) {
		rep2(j, i + 1, n) {
			int dist = 0;
			rep(xi, d) {
				dist += pow(D[i][xi] - D[j][xi], 2);
			}
			int dist2 = sqrt(dist);
			if (dist2 * dist2 == dist)
				ans++;
		}
	}
	cout << ans << endl;
}

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

	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL X, Y, Z;
	cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n;
	int a[200000];
	int ans[200000]={0};
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < 32; i++) {
		int c0 = 0, c1 = 0;
		for (int j = 0; j < n; j++) {
			if ((a[j] >> i) & 1) {
				c1++;
			} else {
				c0++;
			}
		}
		if (c1 % 2 == 0) {
			// bit1
			for (int j = 0; j < n; j++) {
				if ((a[j] >> i) & 1) {
					ans[j] += (1 << i);
				}
			}
		} else {
			for (int j = 0; j < n; j++) {
				if (!((a[j] >> i) & 1)) {
					ans[j] += (1 << i);
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d", ans[i]);
		printf(i == n - 1 ? "\n" : " ");
	}
	return 0;
}

Measured memory_bytes: 4060
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int i = 1;
	do {
		int x = i;
		if (x % 3 == 0 || x % 10 == 3)
			cout << " " << i;
		else
		{
			
			while (x /= 10)
			{
				if (x % 10 == 3)
				{
					cout << " " << i;
					break;
				}
			}
		}
	} while (++i <= n);
	cout << endl;
}


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

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

int main() {
    string s;
    cin >> s;
    int num = 0;
    rep(i, 4){
        if(s[i] == '+') num++;
        else num--;
    }
    cout << num;
}


Measured memory_bytes: 256
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    StdIn.readLine()
    val list = StdIn.readLine().split(" ").map(_.toLong)
    println("%d %d %d".format(list.min,list.max,list.sum))
  }
}

Measured memory_bytes: 49632
A, B, C, D, E, F = map(int, input().split())

density = -1
s_water = -1
sugar = -1
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F or w + s < 100*A:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = w + s
                        sugar = s
print(s_water, sugar)

Measured memory_bytes: 73900
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	S := sc.nextRuneSlice()
	D := []int{}
	now := 1
	cnt := 0
	for i := 0; i < N; i++ {
		if rune('0'+now) == S[i] {
			cnt++
		} else {
			D = append(D, cnt)
			now ^= 1
			cnt = 1
		}
	}
	D = append(D, cnt)
	ans, sum := 0, 0
	l, r := 0, 0
	for i := 0; i < len(D); i += 2 {
		nextLeft := i
		nextRight := min(len(D), i+2*K+1)
		for l < nextLeft {
			sum -= D[l]
			l++
		}
		for r < nextRight {
			sum += D[r]
			r++
		}
		if ans < sum {
			ans = sum
		}
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 6144
#include<iostream>
using namespace std;
int main(){
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	if(A+B>C+D){
		cout<<"Left";
	}
	if(A+B==C+D){
		cout<<"Balanced";
	}
	if(A+B<C+D){
		cout<<"Right";
	}
	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 one=0;
		for(int i = 0; i<n; i++){
			long a = sc.nextLong();
			if(a%2==1){
				one++;
			}
		}
		if(one%2==0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 48116
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
  int n;
  int h;
  vector<int> a;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    {
      cin>>h;
      a.push_back(h);
    }
  sort(a.begin(),a.end(), greater<int>());
  int ans=0;
  for(int i=0;i<n;i+=2)
    {
      ans+=a[i];
    }
 for(int i=1;i<n;i+=2)
    {
      ans-=a[i];
    }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 302, MAXM = 45004, Mod = 998244353 , MAXLog = 20;


bool cmp(const pair<string, pair<int, int>> p1, const pair<string, pair<int, int>> p2) {
    if (p1.first == p2.first) {
        return p2.second.first < p1.second.first;
    }
    return p1.first < p2.first;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n, m;
    cin >> n >> m;
    vector<vector<int>> bulbs(m);
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int swit;
            cin >> swit;
            bulbs[i].push_back(swit);
        }
    }
    vector<int> p(m);
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }

    int ans = 0;
    for (int combination = 0; combination < (1 << n); ++combination) {
        bool plus = 1;
        for (int i = 0; i < m; ++i) {
            int on = 0;
            for (int j = 0; j < bulbs[i].size(); ++j) {
                on += ((combination & (1 << (bulbs[i][j] - 1))) != 0);
            }
            plus &= ((on & 1) == p[i]);
        }
        ans += plus;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
count = 0
while any(h):
    l = -1
    r = -1
    for i in range(N):
        if l == -1 and h[i] != 0:
            l = i
        if r == -1 and h[i] == 0:
            r = i-1
        if r == -1 and i == len(h)-1:
            r = i
        if r < l:
            r = -1
        if l == len(h) - 1:
            r = l
    if l != -1 and r != - 1:
        for j in range(l, r+1):
            if h[j] != 0:
                h[j] -= 1
    count += 1
print(count)


Measured memory_bytes: 3064
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def S(): return input().rstrip()

def main():
    N, A, B = MI()
    ans = N//(A+B)*A
    rem = N%(A+B)
    print(ans+min(rem, A))
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
x,y = map(int, input().split())
group_a = [1,3,5,7,8,10,12]
group_b = [4,6,9,11]
group_c = [2]

if x in group_a and y in group_a:
    print('Yes')
elif x in group_b and y in group_b:
    print('Yes')
elif x in group_c and y in group_c:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    let mut l = 0;
    let mut r = n - 1;
    let mut sum_l = a[l];
    let mut sum_r = a[r];
    while r - l > 1 {
        if sum_l < sum_r {
            l += 1;
            sum_l += a[l];
        } else {
            r -= 1;
            sum_r += a[r];
        }
    }
    let ans = (sum_r - sum_l).abs();
    println!("{}", ans);
}


Measured memory_bytes: 5528
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<int> a(N);
  rep(i, N) {
    cin >> a[i];
    a[i]--;
  }

  int result = 0;
  rep(i, N) {
    if (i == a[a[i]]) {
      result++;
    }
  }
  cout << result / 2 << endl;
  return 0;
}

Measured memory_bytes: 640
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
X=[0]*26
for i in range(D):
  SC+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SC-=sum(X)
YY=[]
Y=[]
for i in range(D):
  for k in range(25):
    SC2=SC
    YY=XX[:]
    Y=X[:]
    SC2-=S[i][P[i][0]]
    SC2+=S[i][P[i][k+1]]
    for j in range(26):
      Y[j]=0
    YY[P[i][0]],YY[P[i][k+1]]=0,0
    for j in range(D):
      if j==i:
        Z=P[j][k+1]
      else:
        Z=P[j][0]
      Y[P[i][0]]+=C[P[i][0]]
      Y[P[i][k+1]]+=C[P[i][k+1]]
      Y[Z]=0
      YY[P[i][0]]+=Y[P[i][0]]
      YY[P[i][k+1]]+=Y[P[i][k+1]]
    if SC2-sum(YY)>SC-sum(XX):
      P[i].insert(0,P[i][k+1])
      del P[i][k+2]
      XX=YY[:]
      SC=SC2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 85088