akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] sl = sc.next().toCharArray();
        List<Integer> rl = new ArrayList<>();
        List<Integer> gl = new ArrayList<>();
        int bcnt = 0;
        long ans = 0;
        int i = 0;
        for(char c :sl){
            if(c == 'R'){
                rl.add(i);
            }else if(sl[i] == 'G'){
                gl.add(i);
            }else{
                bcnt++;
            }
            i++;
        }
        for(int r : rl){
            for(int g : gl){
                int big = Math.max(r,g);
                int small = Math.min(r,g);
                int dif = big-small;
                int tmp = bcnt;
                if(big + dif < n && sl[big+dif] == 'B') tmp--;
                if(small - dif >= 0 && sl[small-dif] == 'B') tmp--;
                if((big + small) % 2 == 0 && sl[(big+small)/2] == 'B') tmp--;
                if(tmp > 0) ans += tmp;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 37428
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();
    int K = sc.nextInt();

    sc.close();

    int C = A;

    if (A < B) {
      C = B;
    }

    Deque<Integer> deque = new ArrayDeque<>();

    for (int i = 1; i <= C; i++) {
      if ((A % i == 0) && (B % i == 0)) {
        deque.push(i);
      }
    }

    int s = 0;

    for (int i = 0; i < K; i++) {
      s = deque.pollFirst();
    }

    System.out.println(s);

  }

}

Measured memory_bytes: 22740
N = gets.to_i
s = gets.chomp
w = [0]*(N+1)
c = 0
N.times do |i|
  w[i+1] = w[i]
  w[i+1] += 1 if s[i]=="."
end
ans = N
(N+1).times do |i|
  t = (i-w[i]) + w[N]-w[i]
  ans = t if t < ans
end
p ans


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

typedef vector<double> vec;
typedef vector<vec> mat;
const double EPS=1E-9;

vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];
  for(int i=0;i<n;i++)B[i][n]=b[i];
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);
    if(abs(B[i][i])<EPS)return vec();
    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];
    for(int j=0;j<n;j++)if(i!=j)for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
  }
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

int main(){
  int n,s,t,q[100],a[100][100],d[100][100];
  while(cin>>n>>s>>t,n){
    vector<int> v[2][100];
    s--,t--;
    for(int i=0;i<n;i++)cin>>q[i];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	cin>>a[i][j];
	if(!a[i][j])a[i][j]=d[i][j]=1e9;
	else v[0][i].push_back(j),d[i][j]=a[i][j];
      }
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	for(int k=0;k<n;k++)
	  d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
    if(d[s][t]==1e9){cout<<"impossible"<<endl;return 0;}
    mat A(n,vec(n));
    vec b(n);
    for(int i=0;i<n;i++){
      if(d[i][t]==a[i][t])v[1][i].push_back(t);
      for(int j=0;j<n;j++)
	if(d[i][t]==a[i][j]+d[j][t])v[1][i].push_back(j);
      }
    for(int i=0;i<n;i++){
      int sz=v[q[i]][i].size();
      if(i==t){A[i][i]=1;continue;}
      double cnt=0;
      for(int j=0;j<sz;j++){
	int p=v[q[i]][i][j];
	A[i][p]=1.0/sz;
	cnt+=a[i][p];
      }
      A[i][i]-=1;
      b[i]-=cnt/sz;
    }
    vec res=gauss_jordan(A,b);
    printf("%.9lf\n",res[s]);
  }
  return 0;
}


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

using namespace std ; 

const int N = 1e5 + 7 ; 

int main(){
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0) ; 
   // freopen("in.in" , "r" ,stdin) ; 
    string s , t ; 
    cin>>s>> t; 
    if(s == t.substr(0 , t.size() -1)) cout<<"Yes" ; 
    else cout<<"No" ; 


    return 0 ; 
}

Measured memory_bytes: 3648
s = int(input())

a = []
f={}
a.append(s)

cnt =0
n=0

while True:
    cnt += 1
    
    if a[cnt-1]%2==0:
        n =  int(a[cnt-1]/2)
    else:
        n =  int(3*a[cnt-1]+1)
    
    if n in a:
        print(len(a)+1)
        break
    else:
        a.append(n)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    char a[H][W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < W+2; i++) cout << "#";
    cout << endl;

    for(int i = 0; i < H; i++){
        cout << "#";
        for(int j = 0; j < W; j++){
            cout << a[i][j];
        }
        cout << "#" << endl;
    }

    for(int i = 0; i < W+2; i++) cout << "#";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#define MP make_pair
#define F first
#define S second
using namespace std;
typedef long long ll;
ll m;
ll c[2000020], d[2000020];

ll fans = 0;

void dfs (ll num, ll sum) {
	if (num <= 1)
		return ;
	fans += num - 1;
	ll num1 = 0, sum1 = 0;
	while (sum) {
		num1 ++;
		sum1 += sum % 10;
		sum /= 10;
	}
	dfs (num1, sum1);
}


int main () {
	ios::sync_with_stdio(false);
	cin >> m;
	ll sum = 0, num = 0;
	for (int i = 1; i <= m; i ++) {
		cin >> d[i] >> c[i];
		sum += d[i] * c[i];
		num += c[i];
	}
	cout << num - 1 + (sum - 1) / 9 << endl; 
	return 0;
}

Measured memory_bytes: 5888
def sosu(n):
    s = [1] * (n+1)
    s[0] = s[1] = 0
    
    end = int(n ** 0.5) + 1
    for i in range(2,end+1):
        if s[i] == 0:continue
        j = i+i
        while j <= n:
            s[j] = 0
            j += i

    return s

S = sosu(1000000)

while 1:
    a, d, n = list(map(int,input().split()))
    if not a:break

    while 1:
        if S[a] == 1:
            n -= 1
            if n == 0:
                break
        a += d

    print(a)

Measured memory_bytes: 14436
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<string>


using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
const int maxn = 3e5;
const int inf = 0x3f3f3f3f;

int a[10], b[10], c[10];
int main() {
	int n;
	while (~scanf("%d", &n)) {
		for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
		for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
		for (int i = 1; i <= n; ++i) c[i - 1] = i;

		ll A = 0, B = 0, res = 0;
		do {
			++res;
			int i = 0; while (i < n && a[i] == c[i]) ++i;
			if (i == n) A = res;
			i = 0; while (i < n && b[i] == c[i]) ++i;
			if (i == n) B = res;			
		} while (next_permutation(c, c + n));
		printf("%lld\n", abs(A - B));
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
def main():
	b = defaultdict(int)
	w = input()
	for c in w:
		b[c] += 1

	beauty = True
	for num in b.values():
		if num%2 == 1:
			beauty = False
			break
	if beauty:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define itn int
#define REP(i,n) for(int i=0;i<n;i++)
#define IREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=k;i<n;i++)
#define REPEACH(itr,k) for(auto itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL<<60;
typedef pair<double,int> P;


int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> v(n+1,vector<int>());
  vector<int> p(m+1);
  REP(i,m){
    int k;
    cin >> k;
    REP(j,k){
      int a;
      cin >> a;
      v[a].push_back(i+1);
    }
  }
  REP(i,m){
    cin >> p[i+1];
  }
  int ans=0;
  for(int bit=0;bit<(1<<n);++bit){
    vector<int> p1(m+1);
    for(int i=0;i<n;i++){
      if(((1<<i)&bit)!=0){
        REP(j,v[i+1].size()){
          p1[v[i+1][j]]++;
        }
      }
    }
    bool flag=false;
    REP(i,m){
      if(p1[i+1]%2!=p[i+1]){
        flag=true;
      }
    }
    ans++;
    if(flag){
      ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!

void solve(){

    ll n,m,c;
    cin>>n>>m>>c;
    
    vll B(m);
    ll ans=0;
    for(int i=0;i<m;++i){cin>>B[i];}
    
    for(int i=0;i<n;i++){
        ll sum=c;
        for(int j=0;j<m;j++){
            ll aj;
            cin>>aj;
            sum+=(B[j]*aj);
        }
        // cout<<sum<<" ";
        if(sum>0)
          ans++;
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 3640
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    int n, k;
    cin >> n >> k;
    vector<int>p(n);
    rep(i, n)cin >> p[i];
    //最初からk番目までを足してそこから足し引きして動かす
    int s = 0;
    rep(i, k)s += p[i];
    int sm = s;
    rep(i, n - k) {
        s -= p[i];
        s += p[i + k];
        sm = max(s, sm);
    }
    double ans = sm + k;
    ans = ans / 2.0;
    
    
    printf("%.16f", ans);

    return 0;
}

Measured memory_bytes: 3568
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        StringBuilder bf = new StringBuilder();
        for (int i=0; i<str.length(); i++) {
            if (i%2 == 0) {
                bf.append(str.charAt(i));
            }
        }
        System.out.println(bf.toString());
    }
}


Measured memory_bytes: 26196
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

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


ull gcd(ull a, ull b) {
    while (a % b != 0) {
        ull tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

ull lcm(ull a, ull b) {
    if (a == b) return b;
    ull g = gcd(a, b);
    return (a / g) * b;
}


ll n, k;
int main() {
    cin >> n >> k;
    if (n == k) {
        cout << 0 << endl;
        return 0;
    }
    if (n > k) {
        n -= k * (n / k);
    }
    chmin(n, k - n);
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
long long int knapSack(int W, int wt[], long long int val[], int n) 
{ 
   int i, w; 
   long long int  K[n+1][W+1]; 
  
   // Build table K[][] in bottom up manner 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
int main()
{
    int n,w;cin>>n>>w;int a[n];long long int b[n];
    for (int i=0;i<n;i++)cin>>a[i]>>b[i];
   cout<<knapSack(w,a,b,n);
    
}

Measured memory_bytes: 79104
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);   
    // 持ち金
    int X = sc.nextInt();
    //100で割った商（買える個数）
    int count = X/100;
    //100で割ったあまり
    int A = X%100;
    //端数は買い物回数以内で合わせられるか
    for(int i=0;i<count;i++){
        if(A>=5){
          A=A-5;
        }else if(A>=4){
          A=A-4;
        }else if(A>=3){
          A=A-3;
        }else if(A>=2){
          A=A-2;
        }else if(A>=1){
          A=A-1;
        }
    }
      if(A==0){
        System.out.println(1);
      }else{
        System.out.println(0);
      }
  }
}

Measured memory_bytes: 35880
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;

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


int main(){
  int N,M;
  cin >> N >> M;
  map<int, int> mp_0,mp_N;
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    if(a == 0){
      mp_0[b]++;
    }
    if(b == 0){
      mp_0[a]++;
    }
    if(a == N-1){
      mp_N[b]++;
    }
    if(b == N-1){
      mp_N[a]++;
    }
  }
  bool can=false;
  for(auto m: mp_0){
    if(mp_N.find(m.first) != mp_N.end()){
      can = true;
    }
  }
  if(can){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 9600
using DataStructures
const lines=readlines()
function main()
	N,M,S=map(x->parse(Int,x),split(popfirst!(lines)))
	LIM=50*(N-1)+1
	S=min(S+1,LIM)
	G=[Tuple{Int,Int,Int}[] for _=1:N]
	for _=1:M
		u,v,a,b=map(x->parse(Int,x),split(popfirst!(lines)))
		push!(G[u],(v,a,b))
		push!(G[v],(u,a,b))
	end
	C=Int[]
	D=Int[]
	for _=1:N
		c,d=map(x->parse(Int,x),split(popfirst!(lines)))
		push!(C,c)
		push!(D,d)
	end
	dist=ones(Int,N,LIM)*1145141919810931893
	dist[1,S]=0
	Q=PriorityQueue{Pair{Int,Int},Int}()
	Q[1=>S]=0
	while !isempty(Q)
		u,g=dequeue!(Q)
		cost=dist[u,g]
		nr=min(g+C[u],LIM)
		if dist[u,nr]>cost+D[u]
			Q[u=>nr]=dist[u,nr]=cost+D[u]
		end
		for (v,a,b)=G[u]
			if g>a
				nxt=cost+b
				nr=g-a
				if dist[v,nr]>nxt
					Q[v=>nr]=dist[v,nr]=nxt
				end
			end
		end
	end
	for i=2:N
		println(minimum(dist[i,:]))
	end
end
main()


Measured memory_bytes: 240816
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		char[] str = sc.next().toCharArray();

		for(int i = 0; i < str.length; i++){
			if(str[i] == '1'){
				str[i] = '9';
			}
			else if(str[i] == '9'){
				str[i] = '1';
			}
		}

		System.out.println(str);
	}

}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

int n;

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	return true;
}

void solve() {
	printf("%d\n", 360 / __gcd(n, 360));
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 3864
n,m = map(int,input().split())
req = [list(map(int,input().split())) for i in range(m)]

for i in range(10000):
  st = str(i)
  if len(st) != n:
    continue
  ok = True
  for s,c in req:
    if int(st[s-1]) != int(c):
      ok = False
  if ok:
    print(st)
    exit()
    
print(-1)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){

	int n,a[3]={0},tmp;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>tmp;
		if(tmp%4==0) a[2]++;
		else if(tmp%2==0) a[1]++;
		else a[0]++;
	}
	
	if(n==1 && a[2]!=1) cout<<"No"<<endl;
	else if(a[0]-a[2]==1 && a[1]==0) cout<<"Yes"<<endl;
	else if(a[0]<=a[2]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
	
}


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


int main(){
    int n, a, b; cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
}
   

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

void propagate(int pivot
				, vector<vector<int>>& counter
                , vector<int>& score, int except);

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> counter(N);
  rep(i,N-1) {
    int a, b;
    cin >> a >> b;
    counter.at(a-1).push_back(b);
    counter.at(b-1).push_back(a);
  }
  vector<int> score(N, 0);
  rep(j,Q) {
    int p, x;
    cin >> p >> x;
    score.at(p-1) += x;
  }
  
  propagate(1, counter, score, -1);
  
  cout << score.at(0);
  for(int i = 1; i < N; i++) {
    cout << ' ' << score.at(i);
  }
  cout << endl;
}

void propagate(int pivot, vector<vector<int>>& counter, vector<int>& score,
              int except) {
  vector<int> carray = counter.at(pivot-1);
  int n = carray.size();
  int pivot_score = score.at(pivot-1);
  rep(i,n) {
    int c = carray.at(i);
    if ( c == except ) {
      continue;
    }
    score.at(c-1) += pivot_score;
    propagate(c, counter, score, pivot);
  }
  return;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

bool can1[16001][16001], can2[16001][16001];
int x[8001], y[8001];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string s;
	int X, Y;
	cin>>s>>X>>Y;
	int n=s.size(), cnt=0, xsz=0, ysz=0;
	bool xflag=true;
	REP(i, n){
		if(s[i]=='T'){
			if(xflag){
				x[xsz++]=cnt;
			}
			else{
				y[ysz++]=cnt;
			}
			xflag=!xflag;
			cnt=0;
		}
		else{
			++cnt;
		}
	}
	if(xflag){
		x[xsz++]=cnt;
	}
	else{
		y[ysz++]=cnt;
	}
	can1[0][x[0]+8000]=true;
	REP(i, xsz-1){
		FOR(j, -n+8000, n+8001){
			if(can1[i][j]){
				can1[i+1][j-x[i+1]]=can1[i+1][j+x[i+1]]=true;
			}
		}
	}
	can2[0][8000]=true;
	REP(i, ysz){
		FOR(j, -n+8000, n+8001){
			if(can2[i][j]){
				can2[i+1][j-y[i]]=can2[i+1][j+y[i]]=true;
			}
		}
	}
	cout<<(can1[xsz-1][X+8000] && can2[ysz][Y+8000] ? "Yes" : "No")<<'\n';
	return 0;
}


Measured memory_bytes: 125696
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

class Main {
  public static int cnt = 0;
  
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
  	int n = sc.nextInt();
  	int[] a = new int[n];
  	for(int i = 0; i < n; ++i) {
  		a[i] = sc.nextInt();
  	}

  	//insertionSort(a, 1);
  	shellSort(a);
  	System.out.println(cnt);
  	for(int i = 0; i < n; ++i) {
  		System.out.println(a[i]);
  	}
  }
  
  public static void insertionSort(int[] a, int g){
  	for(int i = g; i < a.length; ++i) {
  		int v = a[i];
  		int j = i - g;
  		while(j >= 0 && a[j] > v) {
  			a[j + g] = a[j];
  			j = j - g;
  			cnt += 1;
  		}
  		a[j + g] = v;
  	}
  }
  
  public static void shellSort(int[] a) {
  	List<Integer> g = new ArrayList<Integer>();
  	for(int t = 1; t < a.length; t = 4*t + 1){
  		g.add(0, t);
  	}
  	
	if(g.size() == 0){
		g.add(0, 1);
	}
  	
  	int m = g.size();
  	System.out.println(m);
	
	for(int i = 0; i < m; ++i) {
		System.out.print(i == 0 ? "" : " ");
		System.out.print(g.get(i));
	}
  	System.out.println();
  	
  	for(int i = 0; i < m; ++i) {
  		insertionSort(a, g.get(i));
  	}
  }
}

Measured memory_bytes: 298508
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<char> h(3);
  for(int i=0;i<3;++i)
  {
  cin >> h.at(i);
  if(h.at(i)=='1') h.at(i)='9';
  else if(h.at(i)=='9') h.at(i)='1';
  cout << h.at(i);
  }
}

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

int main(){
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;
	
	if(s==u){
		a--;
	}else{
		b--;
	}
	
	cout<<a<<' '<<b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}

/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*最大公約数*/
unsigned long long GCD(long long L,long long R){
    if(L>R){
        long long temp=R;
        R = L;
        L = temp;
    }
    unsigned long long pp=0,ppt=0;
    unsigned long long ans=0;
    if(R%L==0){
        ans = L;
    }else{
        while(true){
            ppt = pp;
            pp=R%L;
            if(pp == 0){
                ans = ppt;
                break;
            }
            R = L;
            L = pp;
        }
    }    
    return ans;    
}

/*最小公倍数*/
unsigned long long LCM(long long L,long long R){
    unsigned long long ans;
    unsigned long long gcd = GCD(L,R);
    ans = (L/gcd)*R;
    return ans;
}

/*Combination set*/
#define mod 1000000007
#define maxcomb 3000/*大きいものを求めるときはここを変える*/
vector<long long> fc(maxcomb+1);
vector<long long> ifc(maxcomb+1);
long long modpow(long long x,long long n){
    long long ans = 1;
    while(n > 0){
        if(n & 1) {
            ans = ans*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}
void Conb(){
    fc[0]= 1;
    ifc[0]=1;
    for(long long i=0;i<maxcomb;i++){
        fc[i+1] = fc[i]*(i+1)%mod;//n!(mod)
        ifc[i+1] = ifc[i]*modpow(i+1,mod-2)%mod;//k!^{M-2} (mod)
    }
}
unsigned long long Combination(long long L,long long R){
    unsigned long long up=1,ans;
    Conb();
    if(L==0&&R==0){
        return 1;
    }else if(L<R||L<0){
        return 0;
    }else{
        long long t = ifc[L-R]*ifc[R]%mod;
        ans = t*fc[L]%mod;
    }
    return ans;
}
/*Combination set ここまで*/

/*ここから*/
int main() {
    int N;
    cin >> N;
    long sum = 0;
    vector<long> A(N);
    vector<long> A1(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
        A1[i] = A[i]*2;
    }
    long tempb;
    tempb = sum;
    vector<long> B(N,0);
    for(int i=1;i<N-1;i+=2){
        tempb -= A1[i];
    }
    B[0]=tempb;
    cout << B[0];
    cout << " ";
    for(int i=1;i<N;i++){
        B[i] = A1[i-1]-B[i-1];
        cout << B[i];
        if(i!=N-1){
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}

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

long long t, n, m, a, b;

int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b;
    cout << floor_sum(n, m, a, b) << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int N,ANS=0;
	cin >> N;
	for(int i=0;i<N;i++){
		int a,b;
		cin >> a >> b;
		ANS=ANS+b-a+1;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
def isMM(s):
    if s in ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']:
        return True
    return False

S = input()

front = S[0:2:]
back = S[2::]

if isMM(front) and isMM(back):
    print('AMBIGUOUS')
elif not isMM(front) and isMM(back):
    print('YYMM')
elif isMM(front) and not isMM(back):
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import itertools
n = int(input())
xy = []
for i in range(n):
    xy.append([int(i) for i in input().split()])

ans = 0
tmp = list(itertools.permutations(range(n)))
for i in range(len(tmp)):
    for j in range(len(tmp[i]) - 1):
        tmp2 = tmp[i][j + 1]
        tmp3 = tmp[i][j]
        ans += pow((pow(xy[tmp2][0] - xy[tmp3][0], 2) + pow(xy[tmp2][1] - xy[tmp3][1], 2)), 0.5)
ans /= len(tmp)
print(ans)


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    n -= 2;
    string t = to_string(n);
    string ans = s[0] + t + s[s.size() - 1];
    cout << ans << endl;
    return 0;
}

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

int main()
{
	ll N, T[1000], A[1000], rT[1000], rA[1000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> T[i] >> A[i];
		rT[i] = T[i];
		rA[i] = A[i];
	}
	for (int i = 1; i < N; i++) {
		if (rT[i - 1] > rT[i]) {
			rT[i] = (rT[i - 1] + T[i] - 1) / T[i] * T[i];
			rA[i] = (rT[i - 1] + T[i] - 1) / T[i] * A[i];
		}
		if (rA[i - 1] > rA[i]) {
			rT[i] = (rA[i - 1] + A[i] - 1) / A[i] * T[i];
			rA[i] = (rA[i - 1] + A[i] - 1) / A[i] * A[i];
		}
	}
	cout << rT[N - 1] + rA[N - 1] << endl;
	return 0;
}


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

signed main(void)
{
	long long n, a, b, ans;
	vector<long long> x;

	cin >> n >> a >> b;
	x.resize(n);
	rep(i, n) cin >> x[i];
	ans = 0;
	rep(i, n - 1)
	{
		ans += min((x[i + 1] - x[i]) * a, b);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N, K, C; string S; cin >> N >> K >> C >> S;
  bool f[N], l[N]; for (int i = 0; i < N; i++) f[i] = l[i] = false;
  int d = 0, m = 0;
  while (d < N) {
    if (S[d] == 'x') { d++; continue; }
    f[d] = true; m++; d += C + 1;
  }
  if (m > K) cout << endl;
  else {
    d = N - 1;
    while (d >= 0) {
      if (S[d] == 'x') { d--; continue; }
      l[d] = true; d -= C + 1;
    }
    for (int i = 0; i < N; i++)
      if (f[i] && l[i])
        cout << i + 1 << endl;
  }
}


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

int main(){
  int n, c, t;
  scanf("%d", &n);
  t=n;
  while(t>0){
    c+=t%10;
    t/=10;
  }
  if(n%c==0) puts("Yes");
  else puts("No");
}
  

Measured memory_bytes: 128
#include <iostream>
#include<math.h>
using namespace std;

int main()
{
    int a,b;
    a=b=0;
    cin >> a;
    cin >> b;
    if(a < b){
        cout << "a < b" << endl;
    }
    else if (a == b){
        cout << "a == b" << endl;
    }
    else{
        cout << "a > b" << endl;
    }
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int P[N];
    int M[N];
    cin >> P[0];
    int min = P[0];
    M[0] = P[0];

    for(int i = 1; i < N; i++){
        cin >> P[i];
        if(P[i] <= min){
            min = P[i];
        }
        M[i] = min;
    }

    int n = 0;
    for(int i = 0; i < N; i++){
        if(P[i] == M[i]){
            n++;
        }
    }

    cout << n << endl;

    // int N;
    // cin >> N;
    // int P[N];
    // for(int i = 0; i < N; i++){
    //     cin >> P[i];
    // }

    // int n = 0;
    // for(int i = 0; i < N; i++){
    //     bool check = true;
    //     for(int j = 0; j < i; j++){
    //         if(P[j] < P[i]) check = false;
    //     }
    //     // cout << check << endl;
    //     if(check) n++;
    // }
    // cout << n << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	int k,n,d,a[10]={};
	cin >> n >> k;
	for (int i=0;i<k;i++) {
		cin >> d;
		a[d]=1;
	}
	for (int i=n;i<100000;i++) {
        string b = to_string(i);
		int count=0;
        for (int j=0;j<b.length();j++) if (a[b[j]-'0']!=1) count++;
      	if (count==b.length()) {
          		cout << i;
          		break;
        }
		
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

int main(){
	
	char abc[27]="abcdefghijklmnopqrstuvwxyz";
	int num[27]={};
	
	char cha;

	
	int i=0;
	while (scanf("%c", &cha) !=EOF){

		for (int k=0; k<26; k++){
			if (cha==65+k || cha==97+k) num[k]++;			
		}
		i++;
	}
	
	for (int k=0; k<26; k++){
		printf("%c : %d\n", abc[k], num[k]);
	}

	
	return 0;
}

Measured memory_bytes: 968
#include<bits/stdc++.h>
using namespace std;
int n,k,a,l,r,val1,val2,mn=1e9,pos,some1,some2;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a==1)
		{
			pos=i;
		}
	}
	for(int i=1;i<=n-k+1;i++)
	{
		l=i;
		r=i+k-1;
		if(l<=pos&&pos<=r)
		{
			some1=l-1;
			some2=n-r;
			if(some1%(k-1)==0)
			{
				val1=some1/(k-1);
			}else
			{
				val1=some1/(k-1)+1;
			}
			if(some2%(k-1)==0)
			{
				val2=some2/(k-1);
			}else
			{
				val2=some2/(k-1)+1;
			}
			mn=min(mn,val1+val2+1);	
		}
	}
	printf("%d\n",mn);
}

Measured memory_bytes: 3772
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;

const ll N = 3e5 + 10;

int deg[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		deg[v]++, deg[u]++;
	}
	for (int i = 1; i <= n; i++) {
		if(deg[i] % 2 == 1) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>

using namespace std;


int main()
{
	string s;
	cin >> s;
	istringstream ss;
	ss = istringstream(s);

	int a = atoi(s.c_str());

	ss >> a;

	if ((1 <= a / 100) && (a / 100 <= 12)) {
		if ((1 <= a % 100) && (a % 100 <= 12)) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if ((1 <= a % 100) && (a % 100 <= 12)) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

    return 0;
}

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

using namespace std;

int main(){
  
  int n, k, h[100000], mi = 1e9;
  
  cin >> n >> k;
  for(int i = 0;i < n;i++) cin >> h[i];
  
  sort(h, h + n);
  
  for(int i = 0;i + k - 1 < n;i++) mi = min(mi, h[i + k - 1] - h[i]);
  
  cout << mi << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
#define CO(a, b, c) ((a)?(b):(c))

using namespace std;

int func(int a, int b){
	return (powl(a, 5) - powl(b, 5));
}

int main(void)
{
	
	int x, tmp;
	cin >> x;

	for(int b = -119; b < 119; b++)
	{
		for (int a = b + 1; a < 120; a++)
		{
			tmp = func(a, b);
			if(tmp==x)
			{
				cout << a << ' ' << b << endl;
				return 0;
			}
		}
	}

	return 0;
	
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	map<int,int> NP;
	vector<int> A(n),B(n);
	int nmin = (1 << 28);
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		B[i] = A[i];
		nmin = min(A[i],nmin);
		NP[A[i]] = i;
	}
	sort(B.begin(),B.end());
	map<int,int> TP;
	for (int i = 0; i < n; ++i) {
		TP[B[i]] = i;
	}

	int ind = 0;
	vector<int> WPN(n,0);
	for (int i = 0; i < n; ++i) {
		if (A[i] != B[i]) {
			WPN[ind] = -A[i];
			++ind;
		}
	}
	sort(WPN.begin(),WPN.end());

	int res = 0;
	for (int i = 0; WPN[i] < 0; ++i) {
		WPN[i] = -WPN[i];
		if (TP[WPN[i]] != NP[WPN[i]]) {
			int next = A[TP[WPN[i]]];
			if (TP[next] == NP[WPN[i]]) {
				res += next+WPN[i];
				NP[WPN[i]] = TP[WPN[i]];
				NP[next] = TP[next];
			}
			else {
				int nos = 0;
				int cost = WPN[i];
				int mc = (1 << 28);
				NP[WPN[i]] = TP[WPN[i]];
				while (next != WPN[i]) {
					mc = min(next,mc);
					cost += next;
					NP[next] = TP[next];
					next = A[TP[next]];
					++nos;
				}
				res += cost + min(mc*(nos-1),(nmin*nos)+(2*nmin)+mc);
			}
		}
	}
	cout << res << endl;

	return 0;
}



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

int main()
{
  int N, A, debug;
  cin >> N;
  cin >> A;
  if(N >= 500){
    debug = N / 500;
    N = N - 500 * (N / 500);
  }
  if(N <= A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(void)
{
	char s[200001];
	int len,plen;
	int start, end;
	int i;

	scanf("%s", s);
	len = strlen(s);

	for (i = 0; i < len; i++) {
		start = i + 1;
		if (s[i] == 'A')break;
	}
	for (i = len - 1; i >= 0; i--) {
		end = i + 1;
		if (s[i] == 'Z')break;
	}
	plen = end - start + 1;
	printf("%d",plen);

	return 0;

}

Measured memory_bytes: 384
n = int(input())
field = [list(map(int, input().split())) for i in range(2)]
for i in range(n - 1):
	field[0][i + 1] += field[0][i]
field[1][0] += field[0][0]
for i in range(n - 1):
	field[1][i + 1] += max(field[0][i + 1], field[1][i])
print(field[1][n - 1])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define N 100
using namespace std;

int t,n,y,x,d,f;
char c[N][N];
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};

bool check(int a,int b){
  return (a>=0&&b>=0&&a<n&&b<n);
}

int main(){
  cin>>t;
  while(t--){
    cin>>n;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)c[i][j]=' ';
    y=x=d=0;
    c[y][x]='#';
    while(1){
      int ny=y+dy[d];
      int nx=x+dx[d];
      f=0;
      if(ny<0||nx<0||n<=ny||n<=nx)f=1;
      int a=ny+dy[d],b=nx+dx[d];
      if(check(a,b)&&c[a][b]=='#')f=1;
      if(f)d=(d+1)%4;
      ny=y+dy[d];
      nx=x+dx[d];
      a=ny+dy[d],b=nx+dx[d];
      if(check(a,b)&&c[a][b]=='#')break;
      a=ny+dy[(d+1)%4],b=nx+dx[(d+1)%4];
      if(check(a,b)&&c[a][b]=='#')break;
      y+=dy[d];
      x+=dx[d];
      c[y][x]='#';
    }
    for(int i=n-1;i>=0;i--){
      for(int j=0;j<n;j++)cout<<c[i][j];
      cout<<endl;
    }
    if(t)cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
from math import gcd
from bisect import insort

N = int(input())
A = list(map(int, input().split()))
mA = max(A)
primenum = [2]
sgn = [-1 for _ in range(int(mA**0.5)+1)]
k = 3
while k**2 <= mA:
  if sgn[k] == -1:
    primenum.append(k)
    add = k*k
    ok = k
    while ok**2 <= mA:
      sgn[ok] = 1
      ok += add
  k += 2
#prime_num が用意されているとき

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    #return None
    return False

primecounter = [0 for _ in range(len(primenum))]
biggerprime = []
def factorization(n):
  M = n
  for k in range(len(primenum)):
    p = primenum[k]
    if p**2 > M:
      break
    else:
      if M%p == 0:
        if primecounter[k] == 0:
          primecounter[k] = 1
        else:
          return False
        while M%p == 0:
          M //= p

  if M > 1:
    if binary_search(biggerprime, M):
      return False
    else:
      insort(biggerprime, M)
  return True



g = A[0]
flag = True
for k in range(N):
  a = A[k]
  g = gcd(g, a)
  if flag:
    flag = factorization(a)
  if flag == False:
    if g == 1:
      break


if flag:
  print('pairwise coprime')
  exit()
if g == 1:
  print('setwise coprime')
else:
  print('not coprime')


Measured memory_bytes: 180600
#!/usr/bin/env python3
import sys
from itertools import chain


def solve(A: int, B: int):
    answer = 6 - A - B
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    answer = solve(A, B)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9012
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n; n %= 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon";
    else if (n == 3) cout << "bon";
    else cout << "pon";
}


Measured memory_bytes: 3544
using static System.Console;
using static System.Convert;
class Program
{
    static void Main(string[] args)
    {
        var odd = ReadLine();
        var even = ReadLine();
        var isNotEven = odd.Length > even.Length ?true:false;
        for(var i = 0; i < odd.Length; i++)
        {
            Write(odd.Substring(i, 1));
            if (!(i == odd.Length - 1 && isNotEven)) Write(even.Substring(i, 1));
        }
        WriteLine();
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   string s,t;cin >>s>>t;
   s+=s;
   ll n=t.size();
   bool flg=false;
    for (int i = 0; i < n; ++i) {
        if(s.substr(i,n)==t)flg=true;
    }
    if(flg)puts("Yes");
    else puts("No");
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll int
#define ld double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll binpow(ll a,ll b,ll m=mod)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res;
}
main()
{
    IO
    string s;
    cin>>s;
    ll e=0;
    for(int x=0;x<s.length();x++)
    {
        e=(e+(s[x]-'0'))%9;
    }
    if(e==0)cout<<"Yes";
    else cout<<"No";
}


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

using namespace std;

void f(string &s)
{
    for (char &c : s) {
        if ('a' <= c && c <= 'z') c = (c - 'a' + 25) % 26 + 'a';
    }
}

int main()
{
    string s;

    while (getline(cin, s)) {
        if (s.empty()) break;
        while (s.find("the") == string::npos && s.find("this") == string::npos && s.find("that") == string::npos) f(s);
        cout << s << endl;
    }
}

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

int main() {
	ios_base::sync_with_stdio(false);
	long long a[3], sol, b, x;
	cin >> a[0] >> sol >> b >> a[1] >> a[2];
	for (int i = 0; i < 3; i++)
		if (a[i] > 1) {
			sol += a[i] - a[i]%2 - 2;
			a[i] = a[i]%2 + 2;
		}
	sort(a, a + 3);
	x = a[0]*100 + a[1]*10 + a[2];
	if (a[0] == 0)
		sol += a[0]-a[0]%2 + a[1]-a[1]%2 + a[2]-a[2]%2;
	else if (x == 111 || x == 112)
		sol += 3;
	else if (x == 122)
		sol += 4;
	else if (x == 113 || x == 123)
		sol += 5;
	else if (x == 222 || x == 223)
		sol += 6;
	else if (x == 133 || x == 233)
		sol += 7;
	else
		sol += 9;
	cout << sol;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = 0
if N == 0:
    if A[0] >= 2:
        ans = -1
    else:
        ans = 1

if N >= 1 and A[0] >= 1:
    ans = -1

if N >= 1:
    node_num = {N: A[N]}
    max_parent_num = {0: 1}
    for i in range(1, N+1):
        max_parent_num[i] = max_parent_num[i-1] * 2 - A[i]

    for i in range(N, 0, -1):
        if node_num[i] > A[i] + max_parent_num[i]:
            ans = -1
            break
        #i-1 no parent wo tukuru
        if node_num[i] <= max_parent_num[i-1]:
            i_1_parent_num = node_num[i]
        else:
            i_1_parent_num = max_parent_num[i-1]
        node_num[i-1] = i_1_parent_num + A[i-1]
        if i == 1:
            if node_num[i-1] != 1:
                ans = -1
                break

if ans == -1 or ans == 1:
    print(ans)
else:
    ans = sum(node_num.values())
    print(ans)

Measured memory_bytes: 718132
def make_divisors(n):
    ans = float("inf")
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div1 = i
            div2 = n // i
            res = max(len(str(div1)), len(str(div2)))
        ans = min(ans, res)
    return ans

if __name__ == '__main__':
    n = int(input())
    print(make_divisors(n))

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

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

	string ans = "Yes";
	if (s.at(0) == s.at(1) && s.at(1) == s.at(2) && s.at(2) == s.at(0)) ans = "No";
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>

using namespace std;

int main()
{
	int n, q, time, k, elaps = 0;
	queue<pair<string, int>> Q;
	string name; 
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		cin >> name >> time;
		Q.push(make_pair(name, time));
	}
	pair <string, int> u;
	while (!Q.empty())
	{
		u = Q.front();
		Q.pop();
		k = min(u.second, q);
		elaps += k;
		u.second -= k;
		if (u.second)
			Q.push(u);
		else
			cout << u.first << " " << elaps << endl;
	}
}



Measured memory_bytes: 6276
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
int min_count(std::vector<int> blocks) {
	const auto sum = std::accumulate(blocks.begin(), blocks.end(), 0);
	const auto sqrt = static_cast<int>(std::sqrt(sum * 2));
	if (sqrt * (sqrt + 1) / 2 != sum) return -1;
	for (auto times = 0; times <= 10000; ++times) {
		if (blocks.size() == sqrt) {
			bool is_triangle = true;
			for (auto i = 0; i < blocks.size(); ++i) {
				if (blocks[i] != i + 1) {
					is_triangle = false;
					break;
				}
			}
			if (is_triangle) return times;
		}
		const auto size = blocks.size();
		for (auto& b : blocks) --b;
		blocks.erase(std::remove(blocks.begin(), blocks.end(), 0), blocks.end());
		blocks.push_back(size);
	}
	return -1;
}
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::vector<int> blocks(n); for (auto& b : blocks) std::cin >> b;
		std::cout << min_count(blocks) << '\n';
	}
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int exp = 1;
  int tmp = b;
  while (tmp > 0) {
    exp *= 10;
    tmp /= 10;
  }
  
  int num = a * exp + b;
  int i = 1;
  while (i * i <= num) {
    i++;
  }
  i--;
  if (i * i == num) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

vector<long long> v(3005,0);
long long dp[3003][3003];

long solve(int i, int j, int chance)
{
  if (dp[i][j] != 0)
    return dp[i][j];
  if (i == j && chance == 0)
  {
    return dp[i][j] = v[i];
  }
  else if (i == j && chance == 1)
    return dp[i][j] = -(v[i]);
  else if (chance == 0)
  {
    return dp[i][j] = max(v[i]+solve(i+1,j,1),v[j]+solve(i,j-1,1));
  }
  else if (chance == 1)
  {
    return dp[i][j] = min(-v[i]+solve(i+1,j,0),-v[j]+solve(i,j-1,0));
  }
  return 1;
}

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

  for (int i = 0 ; i < n;++i)
    cin >> v[i];

  cout << solve(0,n-1,0);
  // for (int i = 0 ; i<6;++i){
  //   for (int j = 0 ; j<6;++j){
  //     cout << dp[i][j] << " ";}
  //   cout << endl;}
  return 0;
}


Measured memory_bytes: 70272