akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.regex.*;

import static java.lang.Math.*;
import static java.lang.System.out;

// AOJ
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().AOJ0139();
	}
	void AOJ0145(){
		int n=sc.nextInt();
		
	}
	
	void AOJ0141(){
		int N=sc.nextInt();
		for(int I=1; I<=N; I++){
			int n=sc.nextInt();
			char[][] c=new char[n+4][n+4];
			int[] vx={0, 1, 0, -1};
			int[] vy={-1, 0, 1, 0};
			c=solve141(2, n+1, n, c, vx, vy);
			for(int j=2; j<=n+1; j++){
				for(int i=2; i<=n+1; i++)	out.print(c[i][j]);
				out.println();
			}
			out.println();
		}
	}
	char[][] solve141(int x, int y, int n, char[][] c, int[] vx, int[] vy){
		//範囲を超えていないか
		if(x<2&&x>n+1 && y<2&&y>n+1)	return c;
		//周りが#
		//return c;
		
		c[x][y]='#';
		
		// 1周目
		if(x==2){
			if(y!=2)	solve141(x, y-1, n, c, vx, vy);
			else	solve141(x+1, y, n, c, vx, vy);
		}
		if(y==2){
			if(x!=n+1)	solve141(x+1, y, n, c, vx, vy);
			else	solve141(x, y+1, n, c, vx, vy);
		}
		if(x==n+1){
			if(y!=2)	solve141(x, y+1,n,c,vx,vy);
			else	solve141(x-1, y,n,c,vx,vy);
		}
		if(y==n+1){
			if(x!=3)	solve141(x-1,y,n,c,vx,vy);
			else	solve141(x,y-1,n,c,vx,vy);
		}
		
		// それ以降
		for(int i=0; i<4; i++){
			if(c[x+vx[i]][y+vy[i]]!='#'){
				solve141(x+vx[i], y+vy[i],n,c,vx,vy);
			}
		}

		return c;
	}
	
	
	void AOJ0139(){
		int N=sc.nextInt();
		for(int i=1; i<=N; i++){
			String s=sc.next();
			Matcher m=Pattern.compile("^>'(=+)#(=+)~$").matcher(s);
			if(m.matches()){
				if(m.group(1).length()==m.group(2).length()){
					out.println("A");
					continue;
				}
			}else if(Pattern.compile("^>\\^(Q=)+~~$").matcher(s).matches()){
				out.println("B");
				continue;
			}
			out.println("NA");
		}
	}
	
	void AOJ0137(){
		int N=sc.nextInt();
		for(int i=1; i<=N; i++){
			long s=sc.nextLong();
			out.println("Case "+i+":");
			for(int j=0; j<10; j++){
				s*=s;	s/=100;	s%=10000;
				out.println(s);
			}
		}
	}
	
	ArrayList<Integer> Sieve2(int N){
	    ArrayList<Integer> prime = new ArrayList<Integer>();
	    boolean[] list = new boolean[N+1];
	    Arrays.fill(list, true);
	    list[1]=false;
	    for (int i=2; i<=N; i++) {
	        if(list[i]) {
	            prime.add(i);
	            for (int j=i+i; j<=N; j+=i)    list[j] = false;
	        }
	    }
	    return prime;
	}

	boolean[] Sieve(int N){
	    boolean[] list = new boolean[N+1];
	    Arrays.fill(list, true);
	    list[1]=false;
	    for(int i=2; i<=N; i++) {
	        if(list[i]) {
	            for (int j=i+i; j<=N; j+=i)     list[j] = false;
	        }
	    }
	    return list;
	}
	
	//素数判定
	boolean isPrime(int n){
	    for(int i=2; i*i<=n; i++){
	        if(n%i==0)     return false;
	    }
	    return true;
	}
	
	int gcd(int x, int y){
		if(y==0)	return x;
		else	return gcd(y, x%y);
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cmath>
#include <vector>
#define ll long long

using namespace std;

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    
    for (ll i = 0; i < n; i++) {
        cin >> a[i];        
    }
    
    for (ll i = 0; i < m; i++) {
        cin >> b[i];
    }

    vector<ll> A;
    vector<ll> B;
    A.push_back(0);
    B.push_back(0);
    for (ll i = 1; i <= n; i++) {
        A.push_back(A[i - 1] + a[i - 1]);
    }
    
    for (ll i = 1; i <= m; i++) {
        B.push_back(B[i - 1] + b[i - 1]);        
    }
    
    ll total = 0;
    ll j = m;
    for (ll i = 0; i <= n; i++) {
        if (A[i] > k) {
            break;
        }
        while (B[j] > k - A[i]) {
            j--;
        }
        total = max(total, i + j);
    }

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

Measured memory_bytes: 11044
// Give me My Shotgun

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

#define int ll

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

#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()

#define debug(x) cerr << #x << " = " << x << endl

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

const int MAX_N = -1 ;
const int inf = 2e9 + 19 ;

int a , b , k ;

int32_t main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        cin >> a >> b >> k ;
        int kk = k ;
        int aa = a ;
        int bb = b ;
        k -= aa ;
        a -= kk ;
        if (a <= 0)
                a = 0 ;
        if (k <= 0)
                k = 0 ;
        kk = k ;
        k -= b ;
        b -= kk ;
        if (b <= 0)
                b = 0 ;
        cout << a << ' ' << b ;
        return (0) ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

ll n;
ll ans = 0;

void dfs(ll x, int a, int b, int c) {
	if (x > n)return;
	if (a && b && c)ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<int>q;
	rep(i, n) {
		int a;
		cin >> a;
		q.push(a);
	}
	rep(i, m) {
		int a = q.top();
		q.pop();
		q.push(a / 2);
	}
	ll ans = 0;
	rep(i, n) {
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 892
import collections
S = list(input())
S_g = [S[i] for i in range(len(S)) if i%2 == 0]
S_k = [S[i] for i in range(len(S)) if i%2 != 0]

S_g_count = collections.Counter(S_g)
S_k_count = collections.Counter(S_k)

S_g_count = sorted(S_g_count.items(),key = lambda x:x[1],reverse=True)
S_k_count = sorted(S_k_count.items(),key = lambda x:x[1],reverse=True)

count = 0
if len(S_g_count) == 0 or len(S_k_count) == 0:
  print(0)
  exit()
if len(S_g_count) == 2 and len(S_k_count) == 2:
  if S_g_count[0][0] != S_k_count[0][0]:
    count = len(S_g)-S_g_count[0][1] + len(S_k)-S_k_count[0][1]
  else:
    if S_k_count[0][1] >= S_g_count[0][1]:
      count = len(S_k)-S_k_count[0][1] + len(S_g)-S_g_count[1][1]
    else:
      count = len(S_g)-S_g_count[0][1] + len(S_k)-S_k_count[1][1]
elif len(S_g_count) == 1 and len(S_k_count) == 1:
  if S_g_count[0][0] == S_k_count[0][0]:
    count = min(S_g_count[0][1],S_k_count[0][1])
  else:
    count = 0
else:
  if len(S_g_count) == 1:
    if S_g_count[0][0] == S_k_count[0][0]:
      count = len(S_k) - S_k_count[1][1]
    else:
      count = len(S_k) - S_k_count[0][1]
  else:
    if S_k_count[0][0] == S_g_count[0][0]:
      count = len(S_g) - S_g_count[1][1]
    else:
      count = len(S_g) - S_g_count[0][1]
print(count)

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

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

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

  int e=0, o=0;
  rep(i,n){
    int a;
    cin >> a;
    if(a%2==0) e++;
    else o++;
  }

  ll ans=0;
  ll e_a=0, o_a=0;
  e_a = pow(2,e);

  ll k=o*p + abs(p-1);
  o_a += k;
  for(int i=p+2; i<=n; i+=2){
    k = k*(o+2-i)*(o-i+1);
    k = k/((i)*(i-1));
    o_a += k;
    //cout << k << endl;
  }

  ans = e_a * o_a;
  cout << ans;
}

Measured memory_bytes: 4064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

int main(void){
	int n=in(),i;
	long long t,ans=1;
	rep(i,n){
		t=llin();
		ans=lcm(ans,t);
	}
	llprint(ans);
	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

void ssolve(std::istream& in, std::ostream& out){
    int n;
    s(n);
    int ac = 0, wa = 0, tle = 0, re = 0;
    string reading;
    f(i, 0, n){
       s(reading);
       if (reading == "AC") {
           ac++;
       }
        if (reading == "WA") {
            wa++;
        }
        if (reading == "TLE") {
            tle++;
        }
        if (reading == "RE") {
            re++;
        }
    }
    out << "AC x " << ac << endl;
    out << "WA x " << wa << endl;
    out << "TLE x " << tle << endl;
    out << "RE x " << re << endl;
    return;
}

class BJudgeStatusSummary {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    BJudgeStatusSummary solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 3660
#include<stdio.h>

int main(void) {
	int i, a=1, b=1;

	for (i = 0;; i++) {

		scanf("%d %d", &a, &b);

		if (a == 0 && b == 0)
			break;

		else if(a <= b)
			printf("%d %d\n", a, b);

		else 
			printf("%d %d\n", b, a);
	}
	
	return 0;
}

Measured memory_bytes: 600
// Be name khoda
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1e5 + 5;
int n;
int Arr[MAX_N];

int main() {
 	ios::sync_with_stdio(false), cin.tie(0);
  	cin >> n;
  	for (int i = 0; i < n; i++)
      	cin >> Arr[i];
  
  	sort(Arr, Arr + n);
  	int ans = 0;
  	for (int i = 0; i < n; i++)
      	ans += Arr[i];
  	ans -= Arr[n - 1] / 2;
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int K, X;
  cin >> K >> X;;
  cout << (X <= 500 * K ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

struct edge {
    int to, cost, num;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<edge>> graph(N);
    vector<vector<ll>> dist(N, vector<ll>(N, 1e18));
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back(edge({b, c, i}));
        graph[b].push_back(edge({a, c, i}));
        dist[a][b] = c;
        dist[b][a] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    set<int> used;
    for (int i = 0; i < N; i++) {
        for (auto e : graph[i]) {
            int j = e.to;
            if (dist[i][j] == e.cost) {
                used.insert(e.num);
            }
        }
    }

    cout << M - (int)used.size() << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 1; i < (n); i++) 
#define out(n) cout << n << endl;

int main() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k <= a){
        out(k);
    }else if(k <= a+b){
        out(a);
    }else{
        out(a-(k-a-b));
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    scanf("%d", &x);
    vector<bool> isbeki(x + 1);
    isbeki[1] = true;
    for (int i = 2; i <= x; i++)
    {
        int v = i * i; //2乗
        while (v <= x)
        {
            isbeki[v] = true;
            v *= i; //3乗～増やしてく
        }
    }
    for (int i = x; i >= 1; i--)
    {
        if (isbeki[i])
        {
            printf("%d\n", i);
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		new ABC127().c();
	}
}

class ABC127{
	void c(){
		int N, M;
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		M = in.nextInt();
		int[] s = new int[N+2];
		for(int i=0; i<M; ++i){
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		}
		int ans = 0;
		for(int i=1; i<N+2; ++i){
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	}
}


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

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

	string s;
	int a;

	cin >> a >> s;
	
	if(a>=3200) cout << s << "\n";
	else cout << "red" << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns          #-}

import           Control.Monad.Primitive
import           Data.List (unfoldr)
import           Control.Monad.ST
import           Control.Monad.State.Strict
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM

find_ :: PrimMonad m => UM.MVector (PrimState m) Int -> Int -> m Int
find_ arr x = go x return
    where
        go !x k = do {
            px <- UM.unsafeRead arr x;
            if px < 0
                then 
                    k x
                else
                    go px $ \ppx -> do{
                        UM.unsafeWrite arr x ppx;
                        k ppx;
                    }
        }

main :: IO ()
main = do
    [n, m] <- unfoldr (C.readInt . C.dropWhile isSpace) <$> C.getLine
    es <- U.unfoldrN m parseInt3 <$> C.getContents
    print $ U.foldl' (\s v -> if (-1) == v then 1 + s else s) 0 $ runST $ do {
        arr <- UM.replicate n (-1::Int);
        U.forM_ es (\(x, y, z) -> do { 
            x_ <- find_ arr (x-1);
            y_ <- find_ arr (y-1);
            if x_ == y_ 
                then return ()
                else
                    UM.unsafeWrite arr x_ y_; 
        });
        U.freeze arr;
    }

parseInt3 :: C.ByteString -> Maybe ((Int, Int, Int), C.ByteString)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)


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

S = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

ans = 0
temp = [0]*N
for i in range(2**N):
    # bit全探索のつもり
    for j in range(N):
        if((i >> j) & 1):
            temp[j] = 1
    # print("temp = ", temp)

    for k in range(M):
        count = 0
        for l in range(1, len(S[k])):
            if temp[S[k][l] - 1] == 1:
                count += 1
        if count % 2 != p[k]:
            break
    else:
        ans += 1
    temp = [0]*N

print(ans)


Measured memory_bytes: 3188
#include <stdio.h>  
int main()
{
    int r, c, i, j; 
    int hyou[101][101] = {0};
     
    scanf("%d %d", &r, &c);
     
    for(i=0; i<r; i++)
    {
        for(j=0; j<c; j++) 
        {
            scanf("%d",&hyou[i][j]);
        }
    } 
     
    for (i=0; i<r; i++)
    {
        for (j=0; j<c; j++)
        {
            hyou[i][c] += hyou[i][j]; 
        }
    }
     
    for (j=0; j<c+1; j++)
    {
        for (i=0; i<r; i++)
        {
            hyou[r][j] += hyou[i][j];
        }
    }
     
    for (i=0; i<r+1; i++)
    {
        for (j=0; j<c; j++) 
        {
            printf("%d ",hyou[i][j]);
        }
         
        printf("%d\n",hyou[i][c]); 
    }
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl dp(n+1, INF);
    dp[0] = 0;
    rep(i, n) {
        ll pow6 = 1;
        while(i + pow6 <= n) {
            chmin(dp[i+pow6], dp[i] + 1);
            pow6 *= 6;
        }
        ll pow9 = 1;
        while(i + pow9 <= n) {
            chmin(dp[i+pow9], dp[i] + 1);
            pow9 *= 9;
        }
    }
    
    out(dp[n]);
    re0;
}

Measured memory_bytes: 1024
H,W = map(int,input().split())
a = [list(map(int,input().split())) for i in range(H)]
ans = []
for i in range(H-1):
    if i%2 == 0:
        for j in range(W-1):
            if a[i][j]%2 == 1:
                ans.append([i+1,j+1,i+1,j+2])
                a[i][j] -= 1
                a[i][j+1] += 1
        if a[i][W-1]%2 == 1:
            ans.append([i+1,W,i+2,W])
            a[i][W-1] -= 1
            a[i+1][W-1] += 1
    else:
        for j in range(W-1,0,-1):
            if a[i][j]%2 == 1:
                ans.append([i+1,j+1,i+1,j])
                a[i][j] -= 1
                a[i][j-1] += 1
        if a[i][0]%2 == 1:
            ans.append([i+1,1,i+2,1])
            a[i][0] -= 1
            a[i+1][0] += 1
if (H-1)%2 == 0:
    for j in range(W-1):
        if a[H-1][j]%2 == 1:
            ans.append([H,j+1,H,j+2])
            a[H-1][j] -= 1
            a[H-1][j+1] += 1
else:
    for j in range(W-1,0,-1):
        if a[H-1][j]%2 == 1:
            ans.append([H,j+1,H,j])
            a[H-1][j] -= 1
            a[H-1][j-1] += 1

print(len(ans))
for an in ans:
    print(*an)


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

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

Measured memory_bytes: 256
class Node:
    def __init__(self, no):
        self.no = no
        self.parent = -1
        self.left = self.right = -1
    def preorder(self):
        global t
        L = [self.no]
        if self.left >= 0: L += t[self.left].preorder()
        if self.right >= 0: L += t[self.right].preorder()
        return L
    def inorder(self):
        global t
        L = []
        if self.left >= 0: L += t[self.left].inorder()
        L.append(self.no)
        if self.right >= 0: L += t[self.right].inorder()
        return L
    def postorder(self):
        global t
        L = []
        if self.left >= 0: L += t[self.left].postorder()
        if self.right >= 0: L += t[self.right].postorder()
        L.append(self.no)
        return L

n = int(input())
t = [ Node(i) for i in range(n) ]
for _ in range(n):
    no, left, right = map(int, input().split())
    t[no].left = left
    t[no].right = right
    if left >= 0:
        t[left].parent = no
    if right >= 0:
        t[right].parent = no

for i in range(n):
    if t[i].parent == -1:
        rootno = i
        break

print('Preorder')
print('',*t[rootno].preorder())
print('Inorder')
print('',*t[rootno].inorder())
print('Postorder')
print('',*t[rootno].postorder())



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    int A,B;
    cin >> A >> B;
    string S;
    cin >> S;
    int count = 0;
    rep(i,A) {
        if (S[i] < '0' || S[i] > '9') {
            count++;
        }
    }
    if (S[A] != '-') {
        count++;
    }
    rep2(j,A + 1, A + B + 1) {
        if (S[j] < '0' || S[j] > '9') {
            count++;
        }
    }
    if (count == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



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

using namespace std;

bool exist[2021];

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        exist[x[i]] = true;
    }
    exist[2020] = true;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int a;
        cin >> a;
        --a;
        if (!exist[x[a] + 1]) {
            exist[x[a]] = false;
            ++x[a];
            exist[x[a]] = true;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << x[i] << '\n';
    }
}


Measured memory_bytes: 3100
#include<stdio.h>
long long int a[100005];
int par[100005], min[100005];
int root(int n)
{
	if (par[n] != n)
		par[n] = root(par[n]);
	return par[n];
}
void uni(int x, int y)
{
	x = root(x);
	y = root(y);
	par[x] = y;
	if (a[min[x]] < a[min[y]])
		min[y] = min[x];
	return;
}
int h[100005], l;
int comp_h(int x, int y)
{
	if (a[h[x]] > a[h[y]])
		return 1;
	else
		return -1;
}
void swap_h(int x, int y)
{
	int f = h[x];
	h[x] = h[y];
	h[y] = f;
	return;
}
void push(int ne)
{
	h[l] = ne;
	int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	int x[100005], y[100005];
	for (i = 0; i < m; i++)
		scanf("%d %d", &x[i], &y[i]);
	for (i = 0; i < n; i++)
	{
		par[i] = i;
		min[i] = i;
	}
	for (i = 0; i < m; i++)
		uni(x[i], y[i]);
	int k = 0;
	int use[100005];
	for (i = 0; i < n; i++)
		use[i] = 0;
	long long int ans = 0;
	for (i = 0; i < n; i++)
	{
		if (root(i) == i)
		{
			k++;
			ans += a[min[i]];
			use[min[i]] = 1;
		}
	}
	if (n < 2 * k - 2)
	{
		printf("Impossible\n");
		return 0;
	}
	if (k == 1)
	{
		printf("0\n");
		return 0;
	}
	l = 0;
	for (i = 0; i < n; i++)
		push(i);
	int cnt = k;
	for (; cnt < 2 * k - 2; cnt++)
	{
		i = pop();
		while (use[i] > 0)
			i = pop();
		use[i] = 1;
		ans += a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4820
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100010];
int main()
{
	int n;
	scanf("%d", &n);
	int cnt = 0;
	int cnt1 = 0;
	int cnt2 = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 4==0)cnt++;
		else if (a[i] % 2 == 0)cnt1++;
		else cnt2++;
	}
	if (cnt >= cnt2) {
		puts("Yes");
		return 0;
	}
	if (cnt+1 == cnt2 && !cnt1) {
		puts("Yes");
		return 0;
	}
	puts("No");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
  int n, m;
  long long k;
  cin >> n >> m>> k;
  vector<long long > A(n);
  vector<long long > B(m);
  vector<long long > a(n+1,0);
  vector<long long > b(m+1,0);
  
  for(int i=0;i < n;i++){
    cin >> A.at(i);
  }
  for(int i=0;i < m;i++){
    cin >> B.at(i);
  }
  
  for(int i=1;i < n+1;i++){
    a.at(i) = a.at(i-1) + A.at(i-1);
  }
   for(int i=1;i < m+1;i++){
    b.at(i) = b.at(i-1) + B.at(i-1);
     // cout << b.at(i)<< endl;
  }
 
  
  long long ans = 0;
  int j = m;
  for(int i=0;i < n+1;i++){
    if(a.at(i) > k){
      break;
    }
    //cout << endl;
    while(a.at(i) + b.at(j) > k){
      j--;
    }
    chmax(ans,(long long)(i+j));
  }
  
  
  cout << ans << endl;
      
}



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

#define READ_NUMBER(i) scanf("%d",i)

int main(){
    int N;
    cin >> N;
    int a[N];
    int Maximum = 0;
    int SUM = 0;
    int Maxnum = 0;
    for(int i = 0;i < N;i++){
        cin >> a[i];
    }
    for(int i = 0;i < N;i++){
        if(a[i] > Maximum){
            Maximum = a[i];
            Maxnum = i;
        }
    }
    //cout << Maxnum << Maximum << endl;
    for(int i = 0;i < N;i++){
        SUM += a[i];
    }
    SUM -= a[Maxnum];
  //cout << SUM << endl;

    if(SUM > Maximum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i < n; i++) d[i] = INFTY;
  d[s] = 0;
  int u;
  while( !q.empty() ) {
    u = q.front(); q.pop();
    for (int v = 0; v < n; v++) {
      if(M[u][v] == 0) continue;
      if(d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i]) << endl;
  }
}

int main() {
  int u, k, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) M[i][j] = 0;
  }

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>

int main(void)
{
    int i, color[3];
    for (i = 0; i < 3; i++) scanf("%d", &color[i]);
    if (color[0] == color[1] && color[0] == color[2]) printf("1\n");
    else if (color[0] == color[1] || color[0] == color[2] || color[1] == color[2]) printf("2\n");
    else if (color[0] != color[1] && color[0] != color[2] && color[1] != color[2]) printf("3\n");
    return (0);
}


Measured memory_bytes: 128
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
min_nk=min(n,k)
for i in range(min_nk+1):#左
    for j in range(n-min_nk+i,n+1):#右
        count=a[0:i]+a[j:n]
        count.sort()
       # print(count)
        ans=max(ans,sum(count))
        for x in range(1,k-len(count)+1):#消せれば消す
           # print(sum(count[x:]))
            ans=max(ans,sum(count[x:]))
print(ans)




Measured memory_bytes: 43752
n,k = map(int, input().split())

if k>n:
    if k%2==0 and 2*n>=k:
        print(1)
    else:
        print(0)
elif k%2==1:
    k2 = n//k
    print(k2**3)
else:
    n2 = n-k//2
    k3 = n2//k
    k2 = n//k
    print((k3+1)**3+k2**3)

Measured memory_bytes: 3060
from math import gcd, sqrt, cos, radians, pi
from collections import defaultdict as d
from itertools import combinations as c

n = int(input())
#a, b = map(float, input().split())
#x, y, z = map(int, input().split())
#a, b, h, m = map(int, input().split())
#arr = list(map(int, input().split()))

div = []
tmp = n
if n % 2 == 0:
	div.append(2)
	while n % 2 == 0:
		n //= 2
for i in range(3, int(n**.5)+2, 2):
	if n % i == 0:
		div.append(i)
		while n % i == 0:
			n //= i

if n > 1:
	div.append(n)

s = 0
exp = 1
n = tmp
while n > 1:
	f = 0
	for v in div:
		if n > 1:
			if n % (v**exp) == 0:
				s += 1
				f = 1
				n //= (v**exp)
	exp += 1
	if not f:
		break
	
print(s)

Measured memory_bytes: 9744
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
	int K;
	string str;

	cin >> str >> K;

	int rem = K, cnt = 0;
	rep(i, str.size()){
		if( str[i] != 'a' && 26 - (str[i]-'a') <= rem ){
			rem -= 26 - (str[i]-'a');
			str[i] = 'a';
		}
	}
	str[str.size()-1] += rem%26;

	cout << str << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int x;
    int y;
    for (int i = 1; i < 3001; i++) {
      x = scan.nextInt();
      y = scan.nextInt();
      if (x == 0 && y == 0) {
        break;
      }
      if (x == y) {
        System.out.println(x + " " + y);
      } else if (x < y) {
        System.out.println(x + " " + y);
      } else if (x > y) {
        System.out.println(y + " " + x);
      }
    }
  }
}


Measured memory_bytes: 34856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int n; cin >> n;
  cout << n*n << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n, i;
    cin>>n;
    int h[n+5];
    FOR0(i, n) cin>>h[i];
    int ans = 0;
    FOR0(i, n)
    {
        int j = i+1;
        int cur = 0;
        while(j < n && h[j] <= h[j-1])
        {
            cur++;
            j++;
        }
        ans = MAX2(ans, cur);
        i = j-1;
    }
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <iomanip>
#include <math.h>
#include <mutex>
#include <algorithm>

//#include "SandBox/StopRangeAccess/StopRangeAccess.h"

//#include "Data.h"


using namespace std;

typedef unsigned long ulong;
typedef unsigned long long ulolong;
typedef long long lolong;

#define CHECKED (0)


void CheckBingo(int bingo_card[3][3], int check_num)
{
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (check_num == bingo_card[i][j])
			{
				bingo_card[i][j] = CHECKED;
				return;
			}
		}
	}
}


bool IsBingo(int bingo_card[3][3])
{
	for (int i = 0; i < 3; i++)
	{
		if (CHECKED == bingo_card[i][0]
			&& CHECKED == bingo_card[i][1]
			&& CHECKED == bingo_card[i][2])
		{
			return true;
		}
	}

	for (int j = 0; j < 3; j++)
	{
		if (CHECKED == bingo_card[0][j]
			&& CHECKED == bingo_card[1][j]
			&& CHECKED == bingo_card[2][j])
		{
			return true;
		}
	}

	if (CHECKED == bingo_card[0][0]
		&& CHECKED == bingo_card[1][1]
		&& CHECKED == bingo_card[2][2])
	{
		return true;
	}

	if (CHECKED == bingo_card[0][2]
		&& CHECKED == bingo_card[1][1]
		&& CHECKED == bingo_card[2][0])
	{
		return true;
	}

	return false;
}


int main()
{
	int bingo_card[3][3];
	int N, tmp_num;

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> bingo_card[i][j];
		}
	}

	cin >> N;

	for (int k = 0; k < N; k++)
	{
		cin >> tmp_num;
		CheckBingo(bingo_card, tmp_num);
	}

	if (IsBingo(bingo_card))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


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

int n,m,ans;
vector<bool> vis;
vector<vector<int>> tree;

void dfs(int x,int count){
  if(count==n){
    ans++;
    return;
  }
  vis[x]=true;
  for(int i=0;i<tree[x].size();i++){
    if(vis[tree[x][i]]) continue;
    dfs(tree[x][i],count+1);
  }
  vis[x]=false;
  return;
}

int main(){
  cin>>n>>m;
  tree.resize(n); vis.resize(n,false);
  for(int i=0;i<m;i++){
    int a,b; cin>>a>>b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  ans=0;
  dfs(0,1);
  cout<<ans<<endl;
}

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

using namespace std;

int ans[26];

int main(){
    int n;
    scanf("%d",&n);
    long long r1 = 0,r2 = 0;
    for (int i = 0; i < n;i++ ){
        int k;
        scanf("%d",&k);
        if(k%4==0){
            r1++;
        }
        else if(k%2==0){
            r2++;
        }
    }
    if (n > r1*2+1+r2 ){
        printf("No");
    }
    else if (n == r1*2 + r2+1&&r2!=0){
        printf("No");
    }
    else{
        printf("Yes");
    }
}


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


void solve(long long N, long long M){
    cout << N * (N- 1)/2 + M * (M - 1) / 2 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	s := next()
	already := map[byte]bool{}

	for i := 0; i < len(s); i++ {
		c := s[i]
		if already[c] {
			fmt.Println("no")
			return
		}
		already[c] = true
	}

	fmt.Println("yes")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ll i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();

    int n;
    cin>>n;
    vector<int>v(n),p(n),q(n),ans;
    loop(i,0,n)cin>>p[i];
    loop(i,0,n)cin>>q[i];
    loop(i,0,n)v[i] = i+1;
    int i = 0;
    do
    {
        i++;
        // ov(v);
        if(v==p)ans.pb(i);
        if(v==q)ans.pb(i);

    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(ans[0]-ans[1]);

    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

char S[111111], T[111111];
int preS[111111], preT[111111];

int main() {
  scanf("%s%s", S, T);
  int N = strlen(S), M = strlen(T);
  REP(i,N) preS[i+1] = preS[i] + (S[i] == 'A' ? 1 : 2);
  REP(i,M) preT[i+1] = preT[i] + (T[i] == 'A' ? 1 : 2);
  int Q;
  scanf("%d", &Q);
  REP(i,Q) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int tmp = preS[b] - preS[a-1] - (preT[d] - preT[c-1]);
    printf(tmp % 3 ? "NO\n" : "YES\n");
  }
}


Measured memory_bytes: 1536
n =gets.chomp.to_i
d = 0
c = []
while s = gets
  c.push(s.split.map(&:to_i))
end
c.sort!
i = 0
t = 0
cnt = 0
while i < n do
  j = 0
  while c[i+j]==c[i] do
  j += 1
  end
  cnt += j%2
  i +=j
end
puts cnt

Measured memory_bytes: 12424
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <complex>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second

void solve(void){
	int N;
	cin >> N;
	set<string> s;
	while (N--) {
		string ope, word;
		cin >> ope >> word;
		if (ope == "insert") s.insert(word);
		else cout << (s.count(word)?"yes":"no") << endl;
	}

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 32140
#include <iostream>
#include <bitset>
using namespace std;
int main(){
    int n,x;
    cin>>n;bitset<2001>c(1);
    while(n--){
        cin>>x;c|=(c<<x);
    }
    cin>>n;
    while(n--){
        cin>>x;
        //cout<<x<<" ";
        cout<<(c[x]?"yes\n":"no\n");
    }
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int N;
cin>>N;
string s1;
string s2;
cin>>s1;
cin>>s2;
long long ans=3;



bool straight=false;

int p=1;
    if(s1[0]==s2[0]){
        if(straight){
            ans=3;
        }
        straight=true;
    }
    else{
        straight=false;
        ans=6;
        p++;
    }

for(int i=p;i<N;i++){
    if(s1[i]==s2[i]){
        if(straight){
            ans*=2;
        }
        straight=true;
    }
    else{
        if(straight){
            ans*=2;
        }
        else{
        ans*=3;
        }
        straight=false;
        i++;
    }
    if(ans>mod){
        ans%=mod;
    }
}

cout<<ans<<endl;
 return 0;
}
/*

3
aab
ccb

6


1
Z
Z

3

52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

958681902
*/

Measured memory_bytes: 256
# 素因数分解
def factorization(t):
    arr = []
    temp = t
    for i in range(2, int(-(-t ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([t, 1])
    return arr

def solve():
    n = int(input())
    mp = {}
    MOD = 10**9+7
    # 素因数分解
    for i in range(2, n + 1):
        f_list = factorization(i)
        for a in f_list:
            if a[0] in mp:
                mp[a[0]] += a[1]
            else:
                mp[a[0]] = a[1]
    res = 1
    for v in mp.values():
        res = res * (v + 1) % MOD
    print(res)

solve()

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	string s;
	cin>>s;
	int n=s.size();
	ll sum=0;
	rep(i,1<<(n-1)){
		ll t=s[0]-'0';
		loop(j,1,n){
			if(i&1<<(j-1)){
				sum+=t;
				t=s[j]-'0';
			}else{
				t*=10;
				t+=s[j]-'0';
			}
		}
		sum+=t;
	}
	cout<<sum<<endl;
}






Measured memory_bytes: 256
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
--import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  ans <- sum. map (\ss -> ((length ss)*((length ss)-1)) `div` 2). group. sort <$> (replicateM n $ sort <$> getLine)
  print ans


Measured memory_bytes: 115068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
char s[N];
void ng(){
	printf("No\n");
	exit(0);
}
bool chk(int x, int y){
	for(int i = x; i+1<y; i++){
		if(s[i]=='#' && s[i+1]=='#') return false;
	}
	return true;
}

int main(){
	int n, a, b, c, d; scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s);
	a--; b--; c--; d--;
	if(!chk(a, c)) ng();
	if(!chk(b, d)) ng();
	if(d<c){
		bool ok = false;
		for(int i=b; i<=d; i++){
			int j=i-1, k=i+1;
			if(j<0 || k>=n) continue;
			if(s[j]=='.' && s[i]=='.' && s[k]=='.') ok = true;
		}
		if(!ok) ng();
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

// https://atcoder.jp/contests/abc160/tasks/abc1160_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		if((s.substring(2, 3).equals(s.substring(3, 4)))&&(s.substring(4, 5).equals(s.substring(5, 6)))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}


	}
}


Measured memory_bytes: 22740
# -*- coding: utf-8 -*-
N=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)
    return divisors

ans=make_divisors(N)

temp=ans[0]+ans[1]-2

for i in range(len(ans)):
    if i%2!=0:
        continue
    if temp>ans[i]+ans[i+1]-2:
        temp=ans[i]+ans[i+1]-2
print(temp)

Measured memory_bytes: 3264
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	K := getInt()
	A, B := getInt(), getInt()

	b := B / K
	a := (A - 1) / K

	if b-a != 0 {
		out("OK")
	} else {
		out("NG")
	}
}


Measured memory_bytes: 1756
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long 
using namespace std;
string s;
int main()
{
	cin >> s;
	if (s.length() == 2)
		cout << s;
	else
	{
		reverse(s.begin(), s.end());
		cout << s;
	}
	return 0;
}

Measured memory_bytes: 256
x= int(input())
cont=0
if x>= 400 and x<=599:
    cont=8
elif x>= 600 and x<=799:
    cont=7
elif x>= 800 and x<=999:
    cont=6
elif x>= 1000 and x<=1199:
    cont=5
elif x>= 1200 and x<=1399:
    cont=4
elif x>= 1400 and x<=1599:
    cont=3
elif x>= 1600 and x<=1799:
    cont=2
elif x>= 1800 and x<=1999:
    cont=1
print(cont)

Measured memory_bytes: 9192