akhauriyash/Code-Regression huggingface dataset:
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/* He can go k, k-2, k-4,...moves */
void solve() {
    cini(x);
    cini(k);
    cini(d);

    x=abs(x);
    d=abs(d);
    int steps=x/d;
    if((steps&1)!=(k&1))
        steps--;

    steps=min(steps, k);

    int p1=x-(d*steps);
    int p2=x-(d*(min(k, steps+2)));
    int ans=min(abs(p1), abs(p2));
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3648
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;

void solve(long long N, long long T, std::vector<long long> A){
    vll RightMax(N, A.back());
    for(ll i=N-2; i>= 0; i--){
        RightMax[i] = max(RightMax[i+1], A[i]);
    }
    map<ll, ll> rec;
    REP(i, N){
        rec[RightMax[i]-A[i]]++;
    }
    cout<<rec.rbegin()->second<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long T;
    scanf("%lld",&T);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, T, std::move(A));
    return 0;
}


Measured memory_bytes: 8064
sx, sy, tx, ty = [int(x) for x in input().split()]
fw = tx - sx
fh = ty - sy
print("R"*fw + "U"*fh + "L"*fw + "D"*fh + "D" + "R"*(fw+1) + "U"*(fh+1) + "LU" + "L"*(fw+1) + "D"*(fh+1) + "R")

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

int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  int ret = 0;
  int sum = 0;
  for (int i = 0; i < n; ++i)
  {
    cin >> d[i];
    sum += d[i];
  }
  for (int i = 0; i < n; ++i)
  {
    sum -= d[i];
    ret += d[i] * sum;
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
from   itertools import   permutations

N,M = map(int, input().split())
L = [list(map(int,input().split())) for _ in range(M)]
graph = [[False] * (N + 1) for _ in range(N + 1)]
#%%

for i in L:
    graph[i[0]][i[1]] = True
    graph[i[1]][i[0]] = True

graph[0][1] = True
graph[1][0] = True
#%%
ans = 0
for i in permutations(range(1, N + 1)):
    if i[0] != 1:
        continue
    for j in range(1, N):
        if not graph[i[j - 1]][i[j]]:
            break
    else:
       ans += 1 

print(ans)


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

int main()
{
  i64 n;
  string s;
  cin >> n >> s;
  i64 ans = 0;
  for (i64 i = 0; i < n - 2; i++)
    if (s.substr(i, 3) == "ABC")
      ans++;
  cout << ans << endl;
  return 0;
}


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

int n,k,l;
int la[200200],lb[200200];
int gru_ans[200200];
int use_gru[200200];
bool visit[200200];

int fia(int idx)
{
    if(la[idx]==idx)return idx;
    return la[idx]=fia(la[idx]);
}

int fib(int idx)
{
    if(lb[idx]==idx)return idx;
    return lb[idx]=fib(lb[idx]);
}

void unia(int l1,int l2)
{
    la[l1]=l2;
}

void unib(int l1,int l2)
{
    lb[l1]=l2;
}

map<pair<int,int>,int> mp;

main()
{
    scanf("%d %d %d",&n,&k,&l);
    for(int i=1;i<=n;i++)
    {
        la[i]=lb[i]=i;
    }
    for(int i=0;i<k;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        if(fia(a)!=fia(b))
            unia(fia(a),fia(b));
    }
    for(int i=0;i<l;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        if(fib(a)!=fib(b))
            unib(fib(a),fib(b));
    }
    for(int i=1;i<=n;i++)
        mp[make_pair(fia(i),fib(i))]++;
    for(int i=1;i<=n;i++)
    {
        printf("%d ",mp[make_pair(fia(i),fib(i))]);
    }
}


Measured memory_bytes: 13568
N, L = map(int, input().split())
ans = 0

if L>0:
    for i in range(N-1):
        ans += L+i+1
    print(ans)
    exit()

if L<=0 and N+L-1 <= 0:
    for i in range(N-1):
        ans += L+i
    print(ans)
    exit()

for i in range(N):
    ans += L+i
print(ans)




Measured memory_bytes: 61812
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int M,N;

int num[1100][1100];
int ans[1100][1100];
int ma[1100][1100];

const int MAX_N=1e6;

bool isprime[MAX_N+1];

void prime(){
    for(int i=1;i<=MAX_N;i++) isprime[i]=true;
    isprime[1]=false;
    for(int i=2;i<=MAX_N;i++){
        if(isprime[i]){
            for(int j=2;i*j<=MAX_N;j++){
                isprime[i*j]=false;
            }
        }
    }
}

void init(){
    int cnt=1;
    int x=550,y=550;
    num[x][y]=cnt;
    cnt++;
    int len=1;
    bool changeLen=false;
    char dir='R';
    while(cnt<MAX_N){
        int dx=0,dy=0;
        char ndir;
        if(dir=='R'){
            dy++;
            ndir='U';
        }else if(dir=='L'){
            dy--;
            ndir='D';
        }else if(dir=='U'){
            dx++;
            ndir='L';
        }else if(dir=='D'){
            dx--;
            ndir='R';
        }

        int nx=x,ny=y;
        for(int k=0;k<len;k++){
            if(cnt>MAX_N) break;
            nx+=dx;
            ny+=dy;
            num[nx][ny]=cnt;
            cnt++;
        }
        dir=ndir;
        x=nx;
        y=ny;
        if(changeLen){
            len++;
            changeLen=false;
        }else{
            changeLen=true;
        }
    }
}

void solve(){
    for(int i=0;i<1100;i++){
        for(int j=0;j<1100;j++){
            ans[i][j]=-1;
            ma[i][j]=0;
        }
    }

    int resa=0,resb=0,resma=0;
    for(int i=1090;i>=0;i--){
        for(int j=0;j<=1090;j++){
            if(num[i][j]==0) continue;
            if(num[i][j]>M) continue;
            int nxma=0,nxans=0;
            bool path=false;
            for(int k=-1;k<=1;k++){
                if(ans[i+1][j+k]==-1) continue;

                path=true;
                if(nxans<ans[i+1][j+k]){
                    nxans=ans[i+1][j+k];
                    nxma=ma[i+1][j+k];
                }else if(nxans==ans[i+1][j+k]){
                    nxma=max(nxma,ma[i+1][j+k]);
                }
            }

            if(!path&&num[i][j]!=N) continue;

            if(isprime[num[i][j]]){
                nxans++;
                nxma=num[i][j];
            }
            ans[i][j]=nxans;
            ma[i][j]=nxma;

            if(resa<nxans){
                resa=nxans;
                resma=nxma;
                resb=num[i][j];
            }else if(resa==nxans){
                if(resma<nxma){
                    resma=nxma;
                    resb=num[i][j];
                }
            }
        }
    }

    cout<<resa<<" "<<resb<<endl;
}

int main(){
  init();
  prime();
  while(1){
      cin>>M>>N;
      if(M==0&&N==0) break;
      solve();
  }

  return 0;
}



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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int ret=0;
	for (char ch : s)
		if(ch=='1')
			ret++;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int j,k;
	char *s;
	
	fscanf(stdin, "%d %d", &j,&k);
	
	if (j == k)       s = "==";
	else if (j < k)   s = "<";
	else              s = ">";
	
	fprintf(stdout, "a %s b", s);
	fputc('\n', stdout);
	
	return 0;
}

Measured memory_bytes: 600
#include <vector>
#include <string>
#include <stack>
#include <numeric>
#include <stdio.h>
using namespace std;
void Caloc();

vector<string> strs = {"~:25*-!#@_,~25*-!#@_" };


int main() {
	Caloc();
}


int x = 0;
int y = 0;
int dirX = 1;
int dirY = 0;

stack<int> memory;

int GetWidth() {
	auto max = 0;
	for (size_t i = 0; i < strs.size(); ++i) {
		if (max < strs[i].size())
			max = strs[i].size();
	}
	return max;
}
char GetChar(int x, int y) {
	if (x >= strs[y].size())
		return ' ';
	else
		return strs[y][x];
}
void MoveNext() {

	if (dirX < 0) {
		x--;
		if (x < 0) x = GetWidth()-1;
	}
	else if (dirX > 0) {
		x++;
		if (x >= GetWidth()) x = 0;
	}
	if (dirY < 0) {
		y--;
		if (y < 0) y = strs.size() - 1;
	}
	else if (dirY > 0) {
		y++;
		if (y >= strs.size()) y = 0;
	}

}
void Push(int val) {
	memory.push(val);
}
int Pop() {
	int ret = memory.top();
	memory.pop();
	return ret;
}
void Do() {
	char letter = ' ';
	while (true)
	{
		letter = GetChar(x, y);
		char c;
		int a;
		switch (letter)
		{
		case '@': return;
		case '_': dirY = 0, dirX = ((Pop() == 0) ? 1 : -1); break;
		case ':': Push(memory.top()); break;
		case '+': Push(Pop() + Pop()); break;
		case '-': Push(-Pop() + Pop()); break;
		case '*': Push(Pop() * Pop()); break;
		case '/': a = Pop(); Push(Pop() / a); break;
		case '%': a = Pop(); Push(Pop() % a); break;
		case '!': Push((Pop() == 0) ? 1 : 0); break;
		case '#' :MoveNext(); break;
		case '~': c = getchar(); Push(c); break;
		case ',': c = Pop(); putchar(c); break;
		}
		if ('0' <= letter && letter <= '9')
			Push(letter - '0');
		MoveNext();
	}
}
void Caloc() {
	Do();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long aa;bool bb;char ch;
long long scan()
{
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	ch=='-'?(bb=1,aa=0):(bb=0,aa=ch-48);
	while(ch=getchar(),(ch>='0'&&ch<='9'))
		aa=aa*10+ch-48;
	return (bb?(-aa):(aa));
}
int i,j,k,x,y,z,p,q,n,m;
int lim;
int ans,tmp,flag;
int a[21][21];
int main()
{
	while(scanf("%d%d",&n,&m)&&n)
	{
		memset(a,0,sizeof(a));
		ans=0;
		for(i=1;i<=n;++i)
			for(j=1;j<=m;++j)
				a[i][j]=scan();
		for(lim=1;lim<=9;++lim)
		{
			for(i=1;i<n;++i)
			for(j=1;j<m;++j)//左上
			{
				if(a[i][j]<lim||a[i+1][j]<lim||a[i][j+1]<lim)
					continue;
				for(x=i+1;x<=n;++x)
				{
					if(a[x][j+1]>=lim)
						break;
					if(a[x+1][j]<lim)
						break;
				}
				if(a[x][j+1]<lim)
					continue;
				for(y=j+1;y<=m;++y)
				{
					if(a[i+1][y]>=lim)
						break;
					if(a[i][y+1]<lim)
						break;
				}
				if(a[i+1][y]<lim)
					continue;
				flag=0;
				for(z=i;z<=x;++z)
					if(a[z][y]<lim)
					{
						flag=1;
						break;
					}
				for(z=j;z<=y;++z)
					if(a[x][z]<lim)
					{
						flag=1;
						break;
					}
				if(flag==1)
					continue;
				tmp=0;
				for(p=i+1;p<x&&flag==0;++p)
					for(q=j+1;q<y;++q)
					{
						if(a[p][q]>=lim)
						{
							flag=1;
							break;
						}
						tmp+=lim-a[p][q];
					}
				if(flag==0)
				{
					if(tmp>ans)
						ans=tmp;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 3212
import java.util.*;

class Main{
    static int n;
    static double[] x,y,z,r;
    static double min;
    static double[][] cost;

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

	n = sc.nextInt();

	while(n!=0){
	    x = new double[n];
	    y = new double[n]; 
	    z = new double[n];
	    r = new double[n];
	    for(int i=0; i<n; i++){
		x[i] = sc.nextDouble();
		y[i] = sc.nextDouble();
		z[i] = sc.nextDouble();
		r[i] = sc.nextDouble();
	    }

	    min = Double.MAX_VALUE;
	    solve();
	    if(min==Double.MAX_VALUE){min=0.000;}
	    System.out.printf("%1.3f",min);
	    System.out.println();

	    n = sc.nextInt();
	}
    }

    public static void solve(){
	cost = new double[n][n];
	for(int i=0; i<n; i++){
	    for(int j=0; j<n; j++){
		cost[i][j] = getDistance(i,j);
		if(cost[i][j]<0)cost[i][j]=0.0;
	    }
	}

	min = getMin();
    }

    public static double getDistance(int i, int j){
	return Math.sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]))-r[i]-r[j];
    }

    public static double getMin(){
	double[] mincost = new double[n];
	boolean[] used = new boolean[n];
	for(int i=0; i<n; i++){
	    mincost[i] = 1000000000;
	    used[i] = false;
	}
	mincost[0] = 0;
	double res = 0;

	while(true){
	    int v = -1;
	    for(int i=0; i<n; i++){
		if(!used[i] && (v==-1 || (mincost[i]<mincost[v]))){v = i;}
	    }

	    if(v==-1)break;
	    used[v] = true;
	    res += mincost[v];

	    for(int i=0; i<n; i++){
		mincost[i] = mincost[i];
		if(mincost[i]>cost[v][i]){mincost[i]=cost[v][i];}
	    }
	}
	return res;
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const bool debug = 0;

int N;
bool dp1[1000][1001]; // [l,r)???1???????????¨???????????¨?????§??????
int dp2[1001]; // i????????§???????????????????°??????°
int c[1000], w[1000];
int sum[1001];

int main() {
	cin >> N;
	REP(i, N) scanf("%d %d", c + i, w + i);
	
	REP(i, N) sum[i + 1] = sum[i] + w[i];
	
	REP(i, N) dp1[i][i + 1] = true;
	FOR(w, 2, N + 1) {
		REP(i, N) {	// [i, i + w)
			if (i + w > N) break;
			
			if (dp1[i + 1][i + w] && sum[i + w] - sum[i + 1] <= c[i])
				dp1[i][i + w] = true;
			if (dp1[i][i + w - 1] && sum[i + w - 1] - sum[i] <= c[i + w - 1])
				dp1[i][i + w] = true;
		}
	}
	
	fill(dp2, dp2 + N + 1, INF);
	
	dp2[0] = 1;
	REP(i, N) {
		FOR(j, i + 1, N + 1) {
			if (dp1[i][j]) {
				if (i == 0) dp2[j] = 1;
				else chmin(dp2[j], dp2[i] + 1);
			}
		}
	}
	
	cout << dp2[N] << endl;
	
	return 0;
}

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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int ba=0, a=0, b=0, c=0;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        bool bb = false;
        bool aa = false;
        for(int j = 0; j < (int)s.size(); j++){
            if(j == 0 && s[j] == 'B')bb=true;
            else if(j != 0 && (s[j-1]=='A'&&s[j]=='B'))c++;
            else if(j == (int)s.size()-1 && s[j] == 'A')aa = true;
        }
        if(aa&&bb)ba++;
        else if(aa)a++;
        else if(bb)b++;
    }
    int ans = c+min(a, b)+ba;
    if(!a && !b && ba)ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    h, w = map(int,input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i == 0 or i == h-1 :
            print("#"*w)
        else:
            print("#"+"."*(w-2)+"#")
        
    print()



Measured memory_bytes: 5608
# DFS
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = 10 ** 9 + 100
ans = INF
def dfs(i, S, cost, C_list, A_list, N, M, X):
    global ans
    if i == N:
        ok = True
        for j in range(M):
            if S[j] < X:
                ok = False
                break
        if ok:ans = min(ans, cost)
        return
    dfs(i+1, S, cost, C_list, A_list, N, M, X)
    for j in range(M):
        S[j] += A_list[i][j]
    cost += C_list[i]
    dfs(i+1, S, cost, C_list, A_list, N, M, X)
    for j in range(M):
        S[j] -= A_list[i][j]
    cost -= C_list[i]
def main():
    global INF, ans
    N, M, X = map(int, input().split())
    C_list = []
    A_list = []
    for _ in range(N):
        C_A = list(map(int, input().split()))
        C_list.append(C_A[0])
        A_list.append(C_A[1:])
    S = [0 for _ in range(M)]
    cost = 0
    dfs(0, S, cost, C_list, A_list, N, M, X)
    if ans == INF:ans = -1
    print(ans)
if __name__ == "__main__":
    main()

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

int main(void){
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 650
int map[N][N],n;
void work(int D) {
	int p=0;
	while(D%4==0) D/=4,p++;
	int i,j;
	if(D&1) {
		for(i=0;i<2*n;i++) {
			for(j=0;j<2*n;j++) {
				if(((i>>p)+(j>>p))&1) map[i][j]=1;
			}
		}
	}else {
		for(i=0;i<2*n;i++) {
			for(j=0;j<2*n;j++) {
				if((i>>p)&1) map[i][j]=1;
			}
		}
	}
}
int main() {
	int d1,d2;
	scanf("%d%d%d",&n,&d1,&d2);
	work(d1); work(d2);
	int i,j,sum=0;
	for(i=0;i<2*n;i++) {
		for(j=0;j<2*n;j++) {
			if(!map[i][j]) {
				printf("%d %d\n",i,j); sum++;
				if(sum==n*n) return 0;
			}
		}
	}
}

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

// #define int long long
int dx[2] = {1, -1}, dy[2] = {1, -1};

struct P {
  int x, y;  
};

int N, D1, D2;
vector<P> G1[601][601];
bool color1[601][601];
bool used1[601][601];
vector<P> G2[601][601];
bool color2[601][601];
bool used2[601][601];

void dfs1(int x, int y) {
  if ( used1[y][x] ) return;
  used1[y][x] = true;  
  for ( P p : G1[y][x] ) {
    int nx = p.x, ny = p.y;
    if ( used1[ny][nx] ) continue;    
    color1[ny][nx] = !color1[y][x];
    dfs1(nx, ny);    
  }
}

void dfs2(int x, int y) {
  if ( used2[y][x] ) return;
  used2[y][x] = true;  
  for ( P p : G2[y][x] ) {
    int nx = p.x, ny = p.y;
    if ( used2[ny][nx] ) continue;    
    color2[ny][nx] = !color2[y][x];
    dfs2(nx, ny);    
  }
}

int SQRT[300000];
signed main() {
  for ( int i = 0; i < 300000; i++ ) SQRT[i] = sqrt(i);  
  cin >> N >> D1 >> D2;

  for ( int i = 0; i < 2*N; i++ ) {
    for ( int j = 0; j < 2*N; j++ ) {
      for ( int x = 0; x <= SQRT[D1]; x++ ) {	
	int y = SQRT[D1-x*x];	
	if ( x*x + y*y != D1 ) continue;
	for ( int a = 0; a < 2; a++ ) {
	  for ( int b = 0; b < 2; b++ ) {
	    int nx = j+dx[a]*x, ny = i+dy[b]*y;
	    if ( nx < 0 || ny < 0 || nx >= 2*N || ny >= 2*N ) continue;	    
	    G1[i][j].emplace_back(P{nx, ny});
	  }
	}
      }
    }
  }

  for ( int i = 0; i < 2*N; i++ ) {
    for ( int j = 0; j < 2*N; j++ ) {
      for ( int x = 0; x <= SQRT[D2]; x++ ) {
	int y = SQRT[D2-x*x];	
	if ( x*x + y*y != D2 ) continue;
	for ( int a = 0; a < 2; a++ ) {
	  for ( int b = 0; b < 2; b++ ) {
	    int nx = j+dx[a]*x, ny = i+dy[b]*y;
	    if ( nx < 0 || ny < 0 || nx >= 2*N || ny >= 2*N ) continue;	    
	    G2[i][j].emplace_back(P{nx, ny});
	  }
	}
      }
    }
  }

  for ( int i = 0; i < 2*N; i++ ) {
    for ( int j = 0; j < 2*N; j++ ) {
      if ( !used1[i][j] ) dfs1(j, i);
      if ( !used2[i][j] ) dfs2(j, i);      
    }
  }

  /* for ( int i = 0; i < 2*N; i++ ) {
    for ( int j = 0; j < 2*N; j++ ) {
      cout << color2[i][j] << " ";
    }
    cout << endl;
    } */

  vector<P> ans[4];
  for ( int i = 0; i < 2*N; i++ ) {
    for ( int j = 0; j < 2*N; j++ ) {
      if ( color1[i][j] && color2[i][j] )   ans[0].emplace_back(P{j, i});
      if ( color1[i][j] && !color2[i][j] )  ans[1].emplace_back(P{j, i});
      if ( !color1[i][j] && color2[i][j] )  ans[2].emplace_back(P{j, i});
      if ( !color1[i][j] && !color2[i][j] ) ans[3].emplace_back(P{j, i});
    }
  }

  for ( int i = 0; i < 4; i++ ) {
    if ( ans[i].size() < N*N ) continue;
    for ( int j = 0; j < N*N; j++ )
      cout << ans[i][j].x << " " << ans[i][j].y << endl;
    break;    
  }

  return 0;
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<int> cc(N, 0);

  rep(i,M){
    int a = 0, b = 0;
    cin >> a >> b;
    cc.at(a-1)++;
    cc.at(b-1)++;
  }

  rep(i,cc.size()){
    cout << cc.at(i) << endl;
  }
}

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

bool flag[100001];
int n;
int ans;

int main()
{
	scanf("%d",&n);
	for(register int i(1);i<=n;++i)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		for(register int j(a);j<=b;++j)
			flag[j]=true;
	}
	for(register int i(1);i<=100000;++i)
		if(flag[i]) ++ans;
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#define W 0
#define E 1

using namespace std;

int main(){
	int n;
	string str;

	cin>>n;
	cin>>str;

	int *data;
	data = new int[2];

	int minNum = 10000000;
	int ans = 0;

	int after=0;
	int before=0;
	for(int i=1;i<n;i++){
		if(str.at(i) == 'E'){
			after++;
		}
	}

	minNum = after;
	ans = after;

	for(int i=1;i<n;i++){
		if(str.at(i) == 'E'){
			after--;
		}
		if(str.at(i-1) == 'W'){
			after++;
		}
		if(ans >= after){
			ans = after;
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 900
X = int(input())
flag = True
a = 0
b = 0
for i in range(-500, 500):
    if flag == False:
        break
    for j in range(-500, 500):
        if i**5 - j**5 == X:
            a = i
            b = j
            flag = False
            break


print(str(a), str(b))


Measured memory_bytes: 9180
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    string S;
    cin>>S;
    if(S=="zyxwvutsrqponmlkjihgfedcba")
        printf("-1\n");
    else if(S.size() < 26){
        char c = 'a';
        for(c='a';c<='z';c++){
            int ok = true;
            for(char d:S)
                if(d==c)
                    ok = false;
            if(ok)
                break;
        }
        cout<<S+c<<endl;
    }else{
        string T = S;
        next_permutation(ALL(T));
        int i;
        for(i=0;i<S.size();i++)
            if(S[i]!=T[i])
                break;
        cout<<T.substr(0,i+1)<<endl;
    }
    return 0;
}

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

#define int long long int

main()
{
    int n, weight;
    std::cin >> n >> weight;

    int dp[105][100010] = { 0 };

    for (int i = 0; i <= 100; ++i)
    {
        for (int j = 1; j <= 100000; ++j)
        {
            dp[i][j] = 1e15;
        }
    }

    int w, v;
    for (int i = 1; i <= n; ++i)
    {
        std::cin >> w >> v;

        for (int j = 1; j <= 100000; ++j)
        {
            dp[i][j] = dp[i - 1][j];

            if (j >= v && dp[i - 1][j - v] + w <= weight)
                dp[i][j] = std::min(dp[i][j], dp[i - 1][j - v] + w);
        }
    }

    for (int j = 100000; j >= 1; --j)
    {
        for (int i = 1; i <= n; ++i)
            if (dp[i][j] != 1e15)
            {
                std::cout << j;
                return 0;
            }
    }
}


Measured memory_bytes: 82304
import sys
from collections import deque
si = sys.stdin.readline


def main():
    n = int(si())
    l = [int(e) for e in si().split()]
    cnt = 0
    for i in range(len(l)):
        if i % 2 == 0 and l[i] % 2 != 0:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9388
#include <iostream>
using namespace std;
typedef long long ll;
ll n, p[21000], a;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> a;
        p[a] = i;
    }
    for (ll i = 1; i <= n; i++) {
        cout << i * n + p[i] << ' ';
    }
    cout << endl;
    for (ll i = n; i > 0; i--) {
        cout << i * n  << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 768
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
b.sort()
c.sort()

ans = 0

for middle in b:
    tmp1 = bisect.bisect_left(a, middle)
    tmp2 = bisect.bisect_right(c, middle)
    ans += tmp1 * (n - tmp2)

print(ans)

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<s.size();++i){
    if(s[i]=='+') ++cnt;
    else --cnt;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Code4
    {
        static void Main(string[] args)
        {
            string s1 = Console.ReadLine();

            Console.WriteLine(funcMain(s1));
#if DEBUG
            Console.ReadKey();
#endif
        }

        static private string funcMain(string arg1)
        {
            string[] s = arg1.Split();
            byte i1, i2;
            string ret;

            i1 = System.Text.Encoding.ASCII.GetBytes(s[0])[0];
            i2 = System.Text.Encoding.ASCII.GetBytes(s[1])[0];

            if (i1 == i2) ret = "=";
            else if (i1 > i2) ret = ">";
            else ret = "<";

            return ret.ToString();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

const long MOD = 1e9 + 7;

int main(){
  long N,M;
  long ans = 1;
  cin >> N >> M;
  if(abs(N-M)<=1){
    for(int i=1;i<=N;++i){
      ans = ans * i;
      ans = ans % MOD;
    }
    for(int i=1;i<=M;++i){
      ans = ans * i;
      ans = ans % MOD;
    }
    if(N==M){
      ans = ans * 2;
      ans = ans % MOD;
    }
  }else{
    ans = 0;
  }
  cout << ans << endl;
}


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

int main(){
  int n,t,c,a[100];
  cin >> n;

  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  
  for(int i = 0;i < n;i++){
    for(int k = n-1;k > i;k--){
      if(a[k] < a[k-1]){
        swap(a[k],a[k-1]);
        c++;
      }
    }
  }
  
  for(int i = 0;i < n;i++){
    cout << a[i];
    if(i != n-1)
      cout << " ";
  }cout << endl << c << endl;
  
  return 0;
}

Measured memory_bytes: 3104
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n , k , a[N];
int fp(int x , int y) {
    if(!y)
        return 1;
    int res = fp(x , y >> 1);
    res = (1ll * res * res) % mod;
    if(y & 1)
        res = (1ll * res * x) % mod;
    return res;
}
int main() {
    abdelrahman010
    cin >> n >> k;
    int ans = 0;
    for(int i = k;i >= 1;i--) {
        int cnt = fp(k / i , n);
        for(int j = i;j <= k;j += i)
            cnt = (cnt - a[j] + mod) % mod;
        a[i] = cnt;
        ans = (ans + (1ll * a[i] * i) % mod) % mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3940
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,list[100][100];
int D[2][100];
vector<int> Z[100];
void dfs(int now, bool isUsed, int cost);
int main(){
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        int a,b,c;
        fill(D[0],D[0]+n,1000000);
        fill(D[1],D[1]+n,1000000);

        for(int i=0;i<n;i++)Z[i].clear();

        for(int i=0;i<m;i++){

            cin>>a>>b>>c;
            a--,b--;
            list[a][b]=c;
            list[b][a]=c;
            Z[a].push_back(b);
            Z[b].push_back(a);
        }

        dfs(0,false,0);
        int ans = min(D[0][n-1],D[1][n-1]);
        cout<<ans<<endl;
        /*for(int i=0;i<n;i++){
            cout<<D[0][i]<<" "<<D[1][i]<<endl;
        }*/
    }

    return 0;
}
void dfs(int now, bool isUsed, int cost){

    if(D[isUsed][now]<=cost)return;
    //cout<<"**"<<endl;

    D[isUsed][now]=cost ;

    for(int i=0;i<Z[now].size();i++){
        dfs(Z[now][i],isUsed,list[now][Z[now][i]] + D[isUsed][now]);

        if(!isUsed){
            for(int j=0;j<Z[Z[now][i]].size();j++){
            dfs(Z[Z[now][i]][j],true,D[isUsed][now]);
            }
        }
    }
}

Measured memory_bytes: 1268
// 提出時に消す


import java.math.BigDecimal;
import java.util.Scanner;

// 提出時にMainに変更する
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        BigDecimal ans = BigDecimal.ONE;
        BigDecimal[] a = new BigDecimal[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextBigDecimal();
            if (BigDecimal.ZERO.compareTo(a[i]) == 0) {
                System.out.println(0);
                System.exit(0);
            }
        }

        for (int i = 0; i < n; i++) {
            ans = ans.multiply(a[i]);
            if (ans.compareTo(BigDecimal.ONE.scaleByPowerOfTen(18)) > 0) {
                System.out.println(-1);
              System.exit(0);
            }
        }

        if (ans.compareTo(BigDecimal.ONE.scaleByPowerOfTen(18)) <= 0) {
            System.out.println(ans);
        } else {
            System.out.println(-1);
        }

        sc.close();
    }
}

Measured memory_bytes: 67808
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 300005 , inf = ~0U>>1;
int W , H , n , x[N] , y[N];
int mx[N<<2] , add[N<<2];
#define lson c<<1,l,m
#define rson c<<1|1,m+1,r
#define pos int c,int l,int r
inline void Update(int c,int x){add[c]+=x,mx[c]+=x;}
inline void Down(int c){
    if(add[c]) Update(c<<1,add[c]) , Update(c<<1|1,add[c]) , add[c] = 0;
}
int Max(pos,int L,int R){
    if(L > R) return -inf;
    if(L <= l && r <= R) return mx[c];
    else {
        Down(c);int m=(l+r)>>1 , ret = -inf;
        if(L <= m) ret = max(ret , Max(lson,L,R));
        if(R > m) ret = max(ret , Max(rson,L,R));
        return ret;
    }
}
void Add(pos,int L,int R,int x){
    if(L > R) return;
    if(L <= l && r <= R) Update(c , x);
    else {
        Down(c);int m=(l+r)>>1;
        if(L <= m) Add(lson,L,R,x);
        if(R > m) Add(rson,L,R,x);
        mx[c] = max(mx[c<<1] , mx[c<<1|1]);
    }
}
int solve(){
#define rk(x) lower_bound(all(Y) , x) - Y.begin()
#define root 1,0,sz(Y)-1
    vector<pii> pts;
    stack<pii> lft,  rgt;
    vi Y;
    rep(i,0,n) pts.pb(mp(y[i] , x[i])) , Y.pb(y[i]);
    pts.pb(mp(H , 0));
    Y.pb(H);Y.pb(0);
    sort(all(pts));
    sort(all(Y));Y.erase(unique(all(Y)) , Y.end());
    memset(add , 0 , sizeof(add));
    memset(mx , 0 , sizeof(mx));
    lft.push(mp(0 , W/2)); rgt.push(mp(0 , W/2));
    rep(i,0,sz(Y)) Add(root,i,i,-Y[i] + W);
    int ans = -inf;
    for(auto e : pts){
        int y = e.fi , x = e.se;
        ans = max(ans , Max(root , 0 , rk(y)-1) + y);
        //cout << x << " " << y << " " << Max(root , 0 , rk(y) - 1) << endl;
        if(x <= W / 2){
            pii A = mp(y , 0);
            while(x > lft.top().se){
                Add(root , rk(lft.top().fi) , rk(A.fi) - 1 , A.se - x);
                A = lft.top(); lft.pop();
            }
            Add(root , rk(lft.top().fi) , rk(A.fi) - 1 , A.se - x);
            lft.push(e);
        } else {
            pii A = mp(y , W);
            while(x < rgt.top().se){
                Add(root , rk(rgt.top().fi) , rk(A.fi) - 1 , x - A.se);
                A = rgt.top(); rgt.pop();
            }
            Add(root , rk(rgt.top().fi) , rk(A.fi) - 1 , x - A.se);
            rgt.push(e);
        }
    }
    return ans;
}

int main(){
    scanf("%d%d%d",&W,&H,&n);
    H *= 2 , W *= 2;
    rep(i,0,n) scanf("%d%d",x + i,y + i) , x[i] *= 2, y[i] *= 2;
    int ans = solve();
    swap(W , H);
    rep(i,0,n) swap(x[i] , y[i]);
    ans = max(ans , solve());
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 18476
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
// typedef vector<int,vector<int>> vvec;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define here  cout<<"Here"<<endl;


//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,K;cin>>N>>K;
  vector<int> A(N);
  REP(i,0,N){cin>>A[i];}
  int lb=min(N,K),ans=A[0];
  REP(a,0,lb+1){
    REP(b,0,lb-a+1){
      priority_queue<int,vector<int>, greater<>> que;
      int tmp_ans=0;
      int can_discard=K-a-b;
      REP(i,0,a){que.push(A[i]);}
      REP(j,0,b){que.push(A[N-1-j]);}
      if(!que.size())continue;
      while(can_discard>0&&que.size()>0){
        int e=que.top();
        // debug(e);
        if(e<0){
          can_discard--;
        }
        if(e>0)break;
        que.pop();
      }
      while(que.size()){
        //debug(que.top());
        tmp_ans +=que.top();que.pop();
      }
      //debug(tmp_ans);

      // debug(tmp_ans);
      ans=max({ans,tmp_ans,(ll)0});
      // debug(ans);
    }
  }
  print(ans)

}


Measured memory_bytes: 256
h,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(h)]
ans=[]
cnt=0
for i in range(h):
    for j in range(w-1):
        if l[i][j]%2==1:
            l[i][j]-=1
            l[i][j+1]+=1
            cnt+=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if l[i][w-1]%2==1:
        l[i][w-1]-=1
        l[i+1][w-1]+=1
        cnt+=1
        ans.append([i+1,w,i+2,w])
print(cnt)
for i in ans:
    print(*i)

Measured memory_bytes: 30264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

bool solve(string s, string t) {
    sort(ALL(s));
    sort(ALL(t), greater<char>());
    if (s < t) return true;
    else return false;
}

int main() {
    string s, t;
    cin >> s >> t;
    if (solve(s, t)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3536
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] len_list = new int[3];
		int[] triangles = new int[3];
		while (true) {
			for (int i = 0; i < 3; i++){
				int len = sc.nextInt();
				len_list[i] = len;
			}
			Arrays.sort(len_list);
			// 3辺の長さ
			int l1 = len_list[0];
			int l2 = len_list[1];
			int l3 = len_list[2];
			// 存在しない場合出力
			if (l1 + l2 <= l3) {
				int t1 = triangles[0];
				int t2 = triangles[1];
				int t3 = triangles[2];
				System.out.println(t1+t2+t3+" "+t2+" "+t1+" "+t3);
				break;
			}
			int s1 = l1 * l1 + l2 * l2;
			int s2 = l3 * l3;
			if (s1 > s2) {
				triangles[0]++;
			} else {
				if (s1 == s2) {
					triangles[1]++;
				} else {
					triangles[2]++;
				}
			}

		}
	}
}



Measured memory_bytes: 26384
a=gets.to_i
b=gets.to_i
c=gets.to_i
d=gets.to_i
e=gets.to_i
k=gets.to_i
p=[]
p<<a
p<<b
p<<c
p<<d
p<<e
p.sort!
puts (p[4]-p[0]<=k) ? :Yay! : ':('

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int num=0;
	while(n){
		n/=k;
		num++;
	}
	cout<<num<<endl;
	return 0;
}


Measured memory_bytes: 256
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int n , b[N] , d[N] , p[N] , ans = 1 , g = 0;
int gcd(int x,int y){
    if(x>y) swap(x,y);
    if(x==0) return y;
    return gcd(y%x , x);
}
int main(){
fcin;
  cin >> n;
  vector<int> a(n);
  for(int i = 0 ; i < n ; i++){
    cin >> a[i];
    g=gcd(a[i],g);
    b[a[i]]++;
  }
  bool pairwise = true;
  for (int i = 2; i < N; i++) {
    int cnt = 0;
    for (int j = i; j < N; j += i) {
      cnt += b[j];
    }
    if (cnt > 1) pairwise = false;
  }
    if(pairwise) {
        cout << "pairwise coprime";
        return 0;
    }
    else if(g==1) {
        cout << "setwise coprime";
        return 0;
    }
    cout << "not coprime";


}

Measured memory_bytes: 11080
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int N, ni=1;
	string S;
	cin>>N;
	
	if(!N)S += '0';
	
	while(N){
		if(N%(ni*2)){
			S += '1';
			N-=ni;
		}else{
			S += '0';
		}
		ni *= -2;
	}
	
	for(int i = S.size()-1; i >= 0; i--){
		cout<<S[i];
	}cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fastt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pll pair<ll,ll>
const ll INF=1e9;
const ll MOD=1e9+7;
//--------------------------------------------------//
double prob[3000];
double dp[3000][3000];
ll n;
double fun(ll cnth,ll cnt)
{
	if(cnt==n)
	{
		if(cnth<=cnt-cnth)//h<=t	
			return 0.0;
		else 
			return 1.0;
	}

	if(dp[cnth][cnt]!=-1.0)
		return dp[cnth][cnt];

	double ans=0.0;	
	ans=prob[cnt+1]*fun(cnth+1,cnt+1)+(1.0-prob[cnt+1])*fun(cnth,cnt+1);
	return dp[cnth][cnt]=ans;
}
int main()
{
	ll i,j;
	cin>>n;
	for(i=1;i<=n;i++)
		scanf("%lf",&prob[i]);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			dp[i][j]=-1;

	printf("%.12lf\n",fun(0,0));
}

Measured memory_bytes: 70656
from itertools import permutations
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, C = map(int, input().split())

D = []
for _ in range(C):
    D.append(list(map(int, input().split())))


# それぞれのグループで、color_iが何個あるかをカウント
mod_0 = [0]*C
mod_1 = [0]*C
mod_2 = [0]*C

for i in range(N):
    l = list(map(int, input().split()))
    for j in range(N):
        m = i+j
        color = l[j]-1
        if m % 3 == 0:
            mod_0[color] += 1
        elif m % 3 == 1:
            mod_1[color] += 1
        else:
            mod_2[color] += 1


# 書き換え方を全通ためして、min
def solve():
    ans = float('inf')
    per = permutations(range(C), 3)

    for c1, c2, c3 in per:
        cost = 0
        for i in range(C):
            cost += D[i][c1]*mod_0[i]
        for i in range(C):
            cost += D[i][c2]*mod_1[i]
        for i in range(C):
            cost += D[i][c3]*mod_2[i]
        ans = min(ans, cost)

    return ans


print(solve())


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

#define Max(a,b) max({a,b})
#define Min(a,b) min({a,b})
#define rep(i,m,n) for(int (i)=(m);(i)<(int)(n);(i)++)
#define len(n) n.size()
#define print(n); cout << n << endl;

// s.substr(i,n)

typedef long long ll;

using namespace std;

//char a = 65;

int n,m,a,b,c,cou,co;
double d,k;
const ll LINF = 1e18;
char num = 65;
string s,t;

int main(){
    
    cin >> n >> s;
    int ans = 0;
    cou = 0;
    map<char,ll> mp;
    for(int i = 0;i < n-1;i++){
        mp[s[i]]++;
        map<char,ll> mpp;
        
        for(int j = i+1;j < n;j++){
            mpp[s[j]]++;
        }
        for(char c='a';c<='z';c++){
            if(mp[c] >= 1 && mpp[c] >= 1){
                cou++;
            }
        }
        ans = max(ans,cou);
        cou = 0;
    }
    print(ans)

    return 0;
}

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

int main() {
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  int count=1;
  for(int i=0;i<N;i++){
    if(i!=0){
      if(A.at(i)<A.at(i-1))
        count++;
    }
  }
  
  cout<<count<<endl;
}
  
  


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

typedef long long ll;

vector<int> solve(int n) {
  vector<int> a(n);
  for(int i=2; i<n; i++) a[i]=i-1;
  a[1]=2;  
  for(int i=2; i*2<n; i++) {
    for(int j=i*2; j<n; j+=i) a[j]-=a[i];
  }
  return a;
}

int main() {
  vector<int> a=solve(1000001);
  vector<ll> ans(1000001);
  ans[1]=a[1];
  for(int i=2; i<1000001; i++) ans[i]=ans[i-1]+a[i];
  int t;
  cin >> t;

  while(t--) {
    int x;
    cin >> x;
    cout << ans[x] << endl;
  }
  return 0;
}

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

const double PI = 3.14159265358979323846;

int main()
{
    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double langle = (H * 60 + M) * 0.5; //0.5度
    double sangle = M * 360 / 60;
    double angle = (langle < sangle) ? sangle - langle : langle - sangle;
    double ans = sqrt(A * A + B * B - 2 * A * B * cos(angle * (PI / 180)));
    cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 4220
import java.util.*;
import java.io.PrintWriter;

public class Main{
	static int[] c=new int[26];
	static int[] lastD=new int[26];
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int d=sc.nextInt();
		for(int i=0; i<26; i++){
			c[i]=sc.nextInt();
		}
		int[][] s=new int[d][26];
		for(int i=0; i<d; i++){
			for(int j=0; j<26; j++){
				s[i][j]=sc.nextInt();
			}
		}
		int maxSati=-1000000;
		int maxInd=-1;
		//j:何日目
		for(int j=0; j<d; j++){
			//i:どの大会をやるか
			for(int i=1; i<=26; i++){
				int sati=0;
				sati+=s[j][i-1];
				sati-=subSati(j+1,i-1);
				if(maxSati<sati){
					maxSati=sati;
					maxInd=i;
				}
			}
			System.out.println(maxInd);
			lastD[maxInd-1]=j+1;
			maxSati=-1000000;
			maxInd=-1;
		}
	}
	static int subSati(int d,int ii){
		int ret=0;
		for(int i=0; i<26; i++){
			if(i==ii) continue;
			ret+=c[i]*(d-lastD[i]);
		}
		return ret;
	}
}


Measured memory_bytes: 46496
#include<stdio.h>


int main(){
	int a,b,n,I[10]={0};
	
	while(scanf("%d",&n)!=EOF){
		if(n==0) break;
		
		for(a=0;a<n;a++){
			scanf("%d",&b);
			I[b]++;
		}
		for(a=0;a<10;a++){
			if(I[a]==0) printf("-");
			else{for(b=0;b<I[a];b++){printf("*");}}
			printf("\n");
		}
		for(a=0;a<10;a++){
			I[a]=0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 568
N, M = gets.split(" ").map(&:to_i)

Max_div = 10000000000000000

studant = Array.new(N)
N.times do |i|
  a, b = gets.split(" ").map(&:to_i)
  studant[i] = [a, b]
end

checkPoint = Array.new(M)
M.times do |i|
  a, b = gets.split(" ").map(&:to_i)
  checkPoint[i] = [a, b]
end

minPoint = Array.new(N, 0)
N.times do |i|
  min = Max_div
  div = 0
  M.times do |j|
    div = (studant[i][0] - checkPoint[j][0]).abs + (studant[i][1] - checkPoint[j][1]).abs
    if div < min then
      min = div
      minPoint[i] = j
    end
  end
end

N.times do |i|
  puts minPoint[i] + 1
end

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

int main()
{
	string s,t;
	cin >> s  >> t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	if(s<t)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    ll k;
    cin>>k;
    ll val=0;
    for(int i=0;i<=k;i++)
    {
        val=(val*10+7)%k;
        if(val==0)
        {
            cout<<i+1<<endl;
            goto end;
        }
    }
    cout<<-1<<endl;
    end:;
}


Measured memory_bytes: 3600