akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;

#define all(A) (A).begin(), (A).end()
#define II(A) int (A); scanf("%d",&(A));
#define DBG if(1)
#define NDBG if(0)

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

const int MN = 100000 + 1;

int N, M;
bool red[MN];
int cnt[MN];

int main(){
	scanf("%d%d",&N,&M);
	red[0] = true;
	for(int i=0;i<N;i++) cnt[i]=1;
	for(int q=0;q<M;q++){
		II(a)II(b); a--,b--;
		cnt[a]--;
		cnt[b]++;
		red[b] |= red[a];
		if(cnt[a]==0) red[a] = false;
	}
	int ans = 0;
	for(int i=0;i<N;i++)if(red[i])ans++;
	printf("%d\n",ans);
	return 0;
} 


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

ma = max(a)
for ai in a:
    if ai < ma - 1:
        print("No")
        exit()

flag = 0
for ai in a:
    if ai == ma - 1:
        flag = 1

# 数字が異なるものが存在
if flag:
    count = 0
    for ai in a:
        if ai == ma - 1:
            count += 1
    if (n - count) == 1:
        print("No")
        exit()
    count_min = count + 1
    count_max = count + (n - count) // 2
    if (count_min <= ma) and (ma <= count_max):
        print("Yes")
        exit()
    else:
        print("No")
        exit()

# 数字が全て同じ
if ma == n-1:
    print("Yes")
    exit()
if (1 <= ma) and (ma <= n // 2):
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 14092
// AOJ 1316: The Sorcerer's Donut
// 2017.12.4 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 500009
typedef struct { unsigned x; int w; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;			// Hash table
char ans[500]; int len;

void lookup(unsigned x, char *s, int w)
{
	int i = (int)(x % HASHSIZ);
	HASH *tp = hash + i;

	while (tp->x) {
		if (w == tp->w && x == tp->x) {
			if (w > len || (w == len && memcmp(s, ans, w) < 0))
				memcpy(ans, s, w), len = w;
			return;
		}
		if (++tp == hashend) tp = hash;
	}
	tp->x = x, tp->w = w;
}

#define M 4294967291
int h, w;
char m[10][22];
int mv[8][2] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
char buf[1000];

void rec(int sr, int sc, int r, int c, int dir, char *s,
		 unsigned x, int len)
{
	int r2, c2, cc;

	s[len++] = m[r][c];
	cc = m[r][c] - ('A'-1);
	x = (((long long)x << 5) | cc) % M;
	lookup(x, s, len);

	r2 = r + mv[dir][0]; if (r2 < 0) r2 = h-1; else if (r2 >= h) r2 = 0;
	c2 = c + mv[dir][1]; if (c2 < 0) c2 = w-1; else if (c2 >= w) c2 = 0;

	if (r2 == sr && c2 == sc) return;
	rec(sr, sc, r2, c2, dir, s, x, len);
}

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

	while (scanf("%d%d", &h, &w) && h > 0) {
		memset(hash, 0, sizeof(hash));
		for (r = 0; r < h; r++) scanf("%s", m[r]);

		len = 0, ans[0] = 0;
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) for (d = 0; d < 8; d++) {
			rec(r, c, r, c, d, buf, 0, 0);
		}

		if (len < 2) puts("0");
		else {
			ans[len] = 0;
			puts(ans);
		}
	}
	return 0;
}

Measured memory_bytes: 5604
#include<stdio.h>

int gcd(int ,int);
void swap(int *,int *);

int main(){
  int a=0,b=0;
  
  scanf("%d%d",&a,&b);
  
  printf("%d\n",gcd(a,b));

  return 0;

}

int gcd(int x, int y){
  int n;
  
  if(x < y){
    n = x;
    x = y;
    y = n;
  }
  
  while(y>0){
    n = x%y;
    x = y;
    y = n;
  }
  return x;
}


 

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {

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

		//入力の準備
		Scanner scan = new Scanner(System.in);

		//入力値を受け取る
		String str = scan.next();
		//受け取った文字を数値に変換
		int x = Integer.parseInt(str);

		//xを３乗する
		int anser = 0;
		double y = (double)x;

		double z = Math.pow(y,3.0);
		anser = (int)z;
		


		System.out.println( anser );

		//scan.close();
	}
}



Measured memory_bytes: 26096
N = int(input())
H = list(map(int, input().split()))
c = 0
L = []
for i in range(N-1):
    if H[i+1] <= H[i]:
        c = c+1
    else:
        L.append(c)
        c = 0
L.append(c)
print(max(L))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  while(1){
    Int n, m;
    cin>>n>>m;
    if(n == 0 && m == 0) break;
    vector<Int> S(n);
    cin>>S;

    auto simulate = [&](Int X){
      Int level = 1;    
      auto getNextMonster = [&](){
	Int i = lower_bound(S.begin(), S.end(), level) - S.begin();
	Int j = i - 1;
	Int res = -1;
	if(0 <= i && i < (Int)S.size() && level + X > S[i]) res = i;
	if(0 <= j && j < (Int)S.size() && level + X > S[j] &&
	   (res == -1 || abs(level - S[i]) > abs(level - S[j]))) res = j;
	return res;
      };
      
      Int cnt = 0;
      while(1){
	cnt++;
	Int nextMonster = getNextMonster();
	if(level + X > S[n-1]) return cnt;
	if(nextMonster == -1) return INF;
	level += max(1LL, X - abs(level - S[nextMonster]) );
      }
      return cnt;
    };


    Int L = 1, R = 1e6 + 100;
    while(L + 1 < R){
      Int M = (L + R) / 2;
      Int cnt = simulate(M);
      (cnt < m)? (R = M):(L = M);
    }
    
    Int ans = L;
    Int cnt = simulate(ans);
    if(cnt < m || cnt == INF) ans = -1;
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 200010;

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

    int n;
    cin >> n;
    vector< P > v;
    for( int i = 0; i < n; ++i ) {
        int a;
        cin >> a;
        v.pb( MP( a, i + 1 ) );

    }
    sort( v.begin(), v.end() );

    int center = n / 2;
    vector< P > res;

    for( int i = 0; i < v.size(); ++i ) {
        if( i == center ) {
            --center;

        }
        res.pb( MP( v[i].S, v[center].F ) );

    }
    sort( res.begin(), res.end() );
    for( int i = 0; i < res.size(); ++i ) {
        cout << res[i].S << endl;

    }

    return 0;
}



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




int main(){

  ll mod=1e9+7;
  ll n,m,t,ans=0;
  string st;
  cin>>st;
  
  n=st.size();
  if(st[n-1]=='s'){
      cout<<st<<"es";
  }else{
      cout<<st<<"s";
  }
  
      

}

Measured memory_bytes: 3620
n, k = map(int, raw_input().split())
n -= 2
if n < 0:
    print 0
    quit()
p, q = divmod(n, 11)
c = e = 0
for i in xrange(11):
    s = 7 * i + 1
    a = 0
    for j in xrange(5):
        t = ((s + j) * 9 + 9 + 21 + 42) % 11
        a += t == k
    if i < q:
        e += a
    c += a
print e + c * p


Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,A,B; cin>>N>>A>>B;
    ll ans=0;
    ans=(N/(A+B))*A+min(A,(N%(A+B)));
    cout<< ans <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int  main(){
  int H,W;
  cin>>H>>W;
  std::vector<string> v(H);
  for(int i=0;i<H;i++)cin>>v[i];
  std::vector<int> h(H,0),w(W,0);
  for(int i=0;i<H;i++){
    int a=0;
    for(int j=0;j<W;j++){
      if(v[i][j]=='#')a++;
    }
    if(a==0)h[i]++;
  }
  for(int j=0;j<W;j++){
    int a=0;
    for(int i=0;i<H;i++){
      if(v[i][j]=='#')a++;
    }
    if(a==0)w[j]++;
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(h[i]==0&&w[j]==0)cout<<v[i][j];
    }
    if(h[i]==0)cout<<endl;
  }
}


Measured memory_bytes: 256
from sys import stdin
read = stdin.read
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

MAX_A = 300005

class SegmentTree:
    def __init__(self, n:int, p:list, ide_ele, func):
        self.num = 1 << ((n-1).bit_length())
        self.tree = [ide_ele]*(2*self.num)
        for i in range(n):
            self.tree[i+self.num] = p[i]
        for i in range(self.num-1, 0, -1):
            self.tree[i] = func(self.tree[i << 1], self.tree[(i << 1)+1])
        self.f = func
        self.ide_ele = ide_ele

    def update(self, i, x):
        i += self.num
        self.tree[i] = x
        while i:
            i >>= 1
            self.tree[i] = self.f(self.tree[i << 1], self.tree[(i << 1)+1])

    def query(self, l, r):
        ansl = ansr = self.ide_ele
        l += self.num
        r += self.num-1
        if l == r:
            return self.tree[l]
        while l < r:
            if l & 1:
                ansl = self.f(ansl, self.tree[l])
                l += 1
            if ~r & 1:
                ansr = self.f(self.tree[r], ansr)
                r -= 1
            l >>= 1
            r >>= 1
        if l == r:
            ansl = self.f(ansl, self.tree[l])
        return self.f(ansl, ansr)

def main():
    N, K = i_map()
    A = list(map(int, read().strip().splitlines()))
    s = SegmentTree(MAX_A, [0]*MAX_A, 0, lambda x, y : max(x,y))
    ans = 0
    for a in A:
        l, r = max(a - K, 0), min(a + K + 1, MAX_A)
        now = s.query(l, r) + 1
        s.update(a, now)
        ans = max(ans, now)
    print(ans)

if __name__ == "__main__":
    main()


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

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

int main(){
    int n;
    cin >> n;
    int amari=n%10;
    if(amari==3){
        cout << "bon" << endl;
        return 0;
    }else if(amari==0||amari==1||amari==6||amari==8){
        cout << "pon" << endl;
        return 0;
    }else{
        cout <<"hon" <<endl;
        return 0;
    }

    return 0;
}











Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<string> v;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	for(int j=i;j<s.size()&&j<i+6;j++){
		v.push_back(s.substr(i,j-i+1));
	}
	sort(v.begin(),v.end());
	int k;
	cin>>k;
	k--;
	v.erase(unique(v.begin(),v.end()),v.end());
	printf("%s\n",v[k].c_str());
	return 0;
}

Measured memory_bytes: 1916
#include<iostream>
using namespace std; //or std::cin et al.

int main() {
	int w,h;
	
	while (1) {
	    cin >> h >> w;
		if ( w == 0 && h == 0 ) {
			break;
		}
		for ( int i = 0; i < h; i++ ) {
	        for ( int j = 0; j < w; j++ ) {
	        	if ( (i + j) % 2 == 0) {
	        		cout << "#";
	        	} else {
	    	        cout << ".";
	        	}
	        }
	        cout << "\n";
        }
        cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				break;
			ans = new int[n + 1];
			ans[0] = n;
			rec(1, n);
		}
	}

	private void rec(int pos, int cnt) {
		if (cnt == 0) {
			for (int i = 1; i < pos - 1; i++)
				System.out.print(ans[i] + " ");
			System.out.println(ans[pos - 1]);
			return;

		}
		for (int i = ans[pos - 1]; i > 0; i--) {
			if (i > cnt)
				continue;
			ans[pos] = i;
			rec(pos + 1, cnt - i);
		}
	}

	int n;
	int[] ans;
}

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

int main(){
    string s;
    int k;
    cin >> s;
    cin >> k;
    map<char, int> d{{'z',1},{'y',2},{'x',3},{'w',4},{'v',5},{'u',6},{'t',7},{'s',8},{'r',9},{'q',10},{'p',11},{'o',12},{'n',13},{'m',14},{'l',15},{'k',16},{'j',17},{'i',18},{'h',19},{'g',20},{'f',21},{'e',22},{'d',23},{'c',24},{'b',25},{'a',0}};
    for(int i=0; i<s.length(); i++){
        if(d[s[i]] <= k){
            k = k - d[s[i]];
            s[i] = 'a';
        }
    }
    for(int i=0; i<k%26; i++){
        if(s[-1]=='z'){
            s[-1] = 'a';
        }else{
            s[s.length()-1] = s[s.length()-1] + 1;
        }
    }
    cout << s;
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        if ((sc.nextInt() * sc.nextInt()) % 2 == 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
long long int dp[3000][3000];
char ans[3000][3000];
pair<int, int> nxt[3000][3000];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  string a, b;
  cin >> a >> b;
  int na = a.size();
  int nb = b.size();
  if (a[0] == b[0]) {
    dp[0][0] = 1;
    ans[0][0] = a[0];
  }
  else {
    dp[0][0] = 0;
    ans[0][0] = 0;
  }
  nxt[0][0] = { -1, -1};
  for (int j = 1; j < nb; j++) {
    if (a[0] == b[j]) {
      dp[0][j] = 1;
      ans[0][j] = a[0];
      nxt[0][j] = { -1, -1};
    }
    else {
      dp[0][j] = dp[0][j - 1];
      nxt[0][j] = {0, j - 1};
    }
  }
  for (int i = 1; i < na; i++) {
    if (a[i] == b[0]) {
      dp[i][0] = 1;
      ans[i][0] = b[0];
      nxt[i][0] = { -1, -1};
    }
    else {
      dp[i][0] = dp[i - 1][0];
      nxt[i][0] = { i - 1, 0};
    }
  }
  for (int i = 1; i < na; i++) {
    for (int j = 1; j < nb; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
        ans[i][j] = a[i];
        nxt[i][j] = {i - 1, j - 1};
      }
      else {
        if (dp[i - 1][j] > dp[i][j - 1]) {
          nxt[i][j] = {i - 1, j};
        }
        else {
          nxt[i][j] = {i, j - 1};
        }
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  int i = na - 1, j = nb - 1, ilast, jlast;
  string res = "";
  while (i != -1) {
    if (ans[i][j]) {
      res += ans[i][j];
    }
    ilast = i, jlast = j;
    i = nxt[ilast][jlast].first;
    j = nxt[ilast][jlast].second;
  }
  reverse(res.begin(), res.end());
  cout << res;
  return 0;
}

Measured memory_bytes: 152968
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
        String [] str = new String [H];
        int [][] ans = new int [H][W];
        int ans1,ans2;
        for(int i=0;i<H;i++){str[i] = sc.next();                             
                            }
		if(str[0].charAt(0)=='#'){ans[0][0]=1;}
        for(int i=1;i<W;i++){if(str[0].substring(i-1,i+1).equals(".#"))
                            {ans[0][i]=ans[0][i-1]+1;}
                             else{ans[0][i]=ans[0][i-1];}
                            }
        for(int i=1;i<H;i++){if(str[i-1].charAt(0)=='.'&&str[i].charAt(0)=='#')
                            {ans[i][0]=ans[i-1][0]+1;}
                             else{ans[i][0]=ans[i-1][0];}
                            }
        for(int i=1;i<H;i++){for(int j=1;j<W;j++){
                             if(str[i].substring(j-1,j+1).equals(".#"))
                            {ans1=ans[i][j-1]+1;}
                             else{ans1=ans[i][j-1];}
                            if(str[i-1].charAt(j)=='.'&&str[i].charAt(j)=='#')
                            {ans2=ans[i-1][j]+1;}
                             else{ans2=ans[i-1][j];}
                             ans[i][j]=Math.min(ans1,ans2);
                            }
                            }        
		System.out.println(ans[H-1][W-1]);
	}
}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -fsanitize=signed-integer-overflow -fno-sanitize-recover=all -o template template.cpp


signed main()
{
	int n;
	cin >> n;
	vector<long long > a(n);
	for (int i = 0, i_len = n; i < i_len; ++i)
	{
		cin >> a.at(i);
	}

	long long  cnt{}, cnt2{}, sum{};

	for (int i = 0, i_len = n; i < i_len; ++i)
	{
		sum += a.at(i);
		if (i % 2 != 0)
		{
			if (sum <= 0)
			{
				cnt += abs(1 - sum);
				sum = 1;
			}
		}
		else
		{
			if (sum >= 0)
			{
				cnt += abs(sum + 1);
				sum = -1;
			}
		}
	}
	sum = 0;

	for(auto i = 0; i != n; ++i){
		sum += a.at(i);
		if(i%2 == 0){
			if(sum <= 0){
				cnt2 += abs(1-sum);
				sum = 1;
			}
		}
		else{
			if(sum >= 0){
				cnt2 += abs(sum+1);
				sum = -1;
			}
		}
	}

	cout << min(cnt, cnt2);
	return 0;
}

Measured memory_bytes: 1024
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll R=1e6+69, INF=2e9+6969;

ll k,licz,w;
bitset <R> v;
bool ok = 1;

int main()
{
	scanf("%lld", &k);
	licz = 1;
	w = 7%k;
	v[w] = 1;
	if(w == 0)
	{
		puts("1");
		return 0;
	}
	while(true)
	{
		w = (10*w+7)%k;
		++licz;
		if(w == 0) break;
		if(v[w] == 1)
		{
			ok = 0;
			break;
		}
		v[w] = 1;
	}
	printf("%lld\n", (ok ? licz : -1));
	return 0;
}


Measured memory_bytes: 3852
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	auto high = (long long)1e9;
	auto low = 0ll;
	while (high >= low)
	{
		auto mid = (high + low) / 2;
		auto next = mid;
		for (auto i = 0; i < N; ++i)
		{
			next = A[i] - next;
		}
		if (next <= mid)
		{
			high = mid - 1;
		}
		else
		{
			low = mid + 1;
		}
	}

	auto result = low;
	for (auto i = 0; i < N; ++i)
	{
		cout << result * 2;
		if (i < N - 1)
		{
			cout << " ";
		}
		result = A[i] - result;
	}

	cout << endl;

	return 0;
}

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

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

	if ((a == 7 && b == 5 && c == 5) ||(a == 5 && b == 7 && c == 5) || (a == 5 && b == 5 && c == 7)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, A;
double dp[310][310][310];
lint cnt[3];
double dfs(lint c1, lint c2, lint c3) {
	if (c1 == 0 && c2 == 0 && c3 == 0) return 0;
	if (dp[c1][c2][c3] > 0) return dp[c1][c2][c3];

	double res = N;
	if (c1 >= 1) res += dfs(c1 - 1, c2, c3) * c1;
	if (c2 >= 1) res += dfs(c1 + 1, c2 - 1, c3) * c2;
	if (c3 >= 1) res += dfs(c1, c2 + 1, c3 - 1) * c3;
	res /= c1 + c2 + c3;
	return dp[c1][c2][c3] = res;
}

int main() {
	cin >> N;
	REP(i, N) {
		cin >> A;
		cnt[A - 1]++;
	}
	cout << setprecision(14) << dfs(cnt[0], cnt[1], cnt[2]) << endl;
}


Measured memory_bytes: 114232
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>

using namespace std;

int n, x, y;
static const int INF = 1e9 + 7;
vector<vector<int>> edge;
vector<int> ans;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x >> y;
	edge.resize(n);
	ans.resize(n);
	for (int i = 0; i < n - 1; i++) {
		edge[i].push_back(i + 1);
		edge[i + 1].push_back(i);
	}
	edge[x - 1].push_back(y - 1);
	edge[y - 1].push_back(x - 1);

	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	set<int> s;
	for (int i = 0; i < n; i++) {
		s.clear();
		for (auto&& j : edge[i]) {
			pq.push(make_pair(1, j));
		}
		s.insert(i);
		while (pq.size()) {
			auto info = pq.top();
			pq.pop();
			if (s.count(info.second)) {
				continue;
			}
			ans[info.first]++;
			s.insert(info.second);
			for (auto&& j : edge[info.second]) {
				if (s.count(j)) {
					continue;
				}
				pq.push(make_pair(info.first + 1, j));
			}
		}
	}
	for (int i = 1; i < n; i++) {
		cout << ans[i] / 2 << "\n";
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pb push_back
#define mp make_pair
typedef pair<int,int> ii;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int s,w;
	cin>>s>>w;
	if(w>=s)
	cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
}

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

#include <iostream>
#include <map>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  map<int64_t, int64_t> A;
  int64_t total = 0;
  for (int64_t i = 0; i < n; ++i) {
    int64_t ai;
    cin >> ai;
    A[ai]++;
    total += ai;
    // cout << ai << " " << A[ai] << endl;
  }

  int64_t q;
  cin >> q;

  for (int64_t i = 0; i < q; ++i) {
    int64_t b, c;
    cin >> b >> c;
    total += A[b] * (c - b);
    cout << total << endl;

    A[c] += A[b];
    A[b] = 0;
  }
  return 0;
}


Measured memory_bytes: 9544
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string.h>
using namespace std;

#define MAX_N (105)
#define MAX_W (10005)
int v[MAX_N];
int w[MAX_N];
int dp[2][MAX_W];

int main()
{
    int N, W;
    scanf("%d %d", &N, &W);
    memset( dp, 0, 2 * MAX_W );

    for ( int i = 0; i < N; i++ ) {
	scanf("%d %d", &v[i], &w[i]);
    }

    for ( int i = 0; i < N; i++ ) {
	for ( int j = 1; j <= W; j++ ) {
	    if ( j >= w[i] ) {
		dp[(i + 1)%2][j] = max( dp[i%2][j-w[i]] + v[i], max( dp[i%2][j], dp[(i+1)%2][j-1] ) );
	    }
	    else {
		dp[(i + 1)%2][j] = max( dp[i%2][j], dp[(i+1)%2][j-1] );
	    }
	}
    }
    
    printf("%d\n", dp[N%2][W]);
    return 0;
}

Measured memory_bytes: 1108
def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    dp = [[0] * (n + 1) for _ in range(n+1)]

    for len in range(1, n + 1):
        for i in range(0, n - len + 1):
            j = i + len
            if (n - len) % 2 == 0:
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1])
            else:
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1])
    print(dp[0][n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 112348
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a, b;
  cin >> a >> b;
  string s = a + b;
  int x = 0;
  FOR(i,0,s.length()) {
    x *= 10;
    x += s[i] - '0';
  }
  FOR(i,1,1000) {
    if(i * i == x) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

int n,a=INT_MIN,b=INT_MAX,c=a,d=b;

signed main(){
	read(n);
	while(n--){
		int x,y;
		read(x,y);
		a=max(a,x+y);
		b=min(b,x+y);
		c=max(c,x-y);
		d=min(d,x-y);
	}
	write(max(a-b,c-d));
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;  
int main()
{
	int a,b,k;
	cin>>k;
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long cot[105]= {0};
ll ans=0;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int t=i;
        for(int j=2;t!=1;j++)
            while(t%j==0)
            cot[j]++,t/=j;
    }
    int ans=0;
    for(int i=2;i<=n;i++)
    {
        if(cot[i]>=74)ans++;
        for(int j=2;j<=n;j++)
        {
            if(i==j)continue;
            if(cot[i]>=2&&cot[j]>=24)ans++;
            if(cot[i]>=4&&cot[j]>=14)ans++;
            for(int k=j+1;k<=100;k++)
            {
                if(k==i||k==j)continue;
                if(cot[i]>=2&&cot[j]>=4&&cot[k]>=4)ans++;
            }
        }
    }
    printf("%d\n",ans);

}



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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

int a,b;

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

	cin>>a>>b;
	cout<<2*b-a<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        HashMap<String, Integer> map = new HashMap<>();
        long ans = 0;

        for (int i = 0; i < n; i++) {
            String s = sc.next();
            s = str_sort(s);

            if (map.get(s) == null) {
                map.put(s, 1);
            } else {
                int val = map.get(s);
                ans += val;
                map.replace(s, val+1);
            }
        }

        System.out.println(ans);
    }

    static String str_sort(String a) {
        char[] re = a.toCharArray();

        for (int i = 0; i < re.length-1; i++) {
            for (int j = i+1; j < re.length; j++) {
                if (re[i] > re[j]) {
                    char tmp = re[j];
                    re[j] = re[i];
                    re[i] = tmp;
                }
            }
        }

        return new String(re);
    }
}

Measured memory_bytes: 50800
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1e4;
enum Color { WHITE = 0, GRAY, BLACK };
int n;
vector<pair<int, int>> adj[MAX];
inline void dijkstra() {
	priority_queue<pair<int, int>> pq;
	vi color(MAX, WHITE), d(MAX, INT_MAX);
	d[0] = 0;
	pq.emplace(mp(0, 0));
	color[0] = GRAY;
	int f, u, v, c;
	while(!pq.empty()) {
		tie(f, u) = pq.top(); pq.pop();
		color[u] = BLACK;
		if(d[u] < f * (-1)) continue;
		rep(j, 0, len(adj[u])) {
			tie(v, c) = adj[u][j];
			if(color[v] == BLACK) continue;
			if(d[v] > d[u] + c) {
				d[v] = d[u] + c;
				pq.emplace(mp(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}
	rep(i, 0, n) {
		cout << i << " " << (d[i] == INT_MAX ? -1 : d[i]) << endl;
	}
}
int main() {
	cin >> n;
	int u, k, v, c;
	rep(i, 0, n) {
		cin >> u >> k;
		rep(j, 0, k) {
			cin >> v >> c;
			adj[u].eb(mp(v, c));
		}
	}
	dijkstra();
	return 0;
}

Measured memory_bytes: 8164
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

int main(){
	int n,p[8][8],a=0;
	cin>>n;
	rep(i,n)rep(j,n)cin>>p[i][j];
	rep(i,n)a|=i<<3*i;
	set<int> v;
	priority_queue<pi> q;
	q.push(mp(0,a));
	int ans=0;
	while(!q.empty()){
		a=q.top().second;
		int c=q.top().first; q.pop();
		if(v.count(a))continue;
		ans=max(ans,-c);
		v.insert(a);
		rep(i,n)rep(j,i){
			a+=((a>>3*i&7)<<3*j)-((a>>3*j&7)<<3*j)+((a>>3*j&7)<<3*i)-((a>>3*i&7)<<3*i);
			if(!v.count(a))q.push(mp(c-p[i][j],a));
			a+=((a>>3*i&7)<<3*j)-((a>>3*j&7)<<3*j)+((a>>3*j&7)<<3*i)-((a>>3*i&7)<<3*i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;
using std::string;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std


int main()
{
	ll N;
	ll sum = 0;
	ll buf;

	IN >> N;

	LEP(a, N)
	{
		IN >> buf;
		sum += buf;
	}

	OUT << sum - N << endl;

	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

const int MOD = 1e9 + 7;
vector<P>g[110000];
int v[110000];
LL ijk_L[110000];
LL ijk_R[110000];

LL L[110000];
LL R[110000];
int main() {
	int n, m;
	cin >> n >> m;
	int s, t;
	cin >> s >> t;
	s--; t--;
	for (int i = 0; i < m; i++) {
		int p, q, r;
		cin >> p >> q >> r;
		p--; q--;
		g[p].emplace_back(mp(q, r));
		g[q].emplace_back(mp(p, r));
	}
	for (int i = 0; i < n; i++) {
		ijk_L[i] = LINF;
	}
	ijk_L[s] = 0;
	priority_queue<P> Q;
	Q.push(mp(0LL, s));
	L[s] = 1;
	while (Q.size()) {
		LL cost = -Q.top().first;
		int at = Q.top().second;
		Q.pop();
		if (v[at])continue;
		v[at] = 1;
		for (int i = 0; i < g[at].size(); i++) {
			int to = g[at][i].first;
			LL tmp = cost + g[at][i].second;
			if (!v[to] && ijk_L[to] >= tmp) {
				if (ijk_L[to] > tmp) {
					ijk_L[to] = tmp;
					L[to] = L[at];
					Q.push(mp(-ijk_L[to], to));
				}
				else {
					L[to] = (L[to] + L[at]) % MOD;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		ijk_R[i] = LINF;
		v[i] = 0;
	}
	ijk_R[t] = 0;
	R[t] = 1;
	Q.push(mp(0LL, t));
	while (Q.size()) {
		LL cost = -Q.top().first;
		int at = Q.top().second;
		Q.pop();
		if (v[at])continue;
		v[at] = 1;
		for (int i = 0; i < g[at].size(); i++) {
			int to = g[at][i].first;
			LL tmp = cost + g[at][i].second;
			if (!v[to] && ijk_R[to] >= tmp) {
				if (ijk_R[to] > tmp) {
					ijk_R[to] = tmp;
					R[to] = R[at];
					Q.push(mp(-ijk_R[to], to));
				}
				else {
					R[to] = (R[to] + R[at]) % MOD;
				}
			}
		}
	}
	LL D = ijk_L[t];
	LL ret = L[t] * R[s] % MOD;
	LL ng = 0;
	for (int i = 0; i < n; i++) {
		if (ijk_L[i] + ijk_R[i] > D)continue;
		if (ijk_L[i] == ijk_R[i]) {
			ng = (ng + L[i] * R[i] % MOD*L[i] % MOD*R[i]) % MOD;
		}
		for (int j = 0; j < g[i].size(); j++) {
			if (ijk_L[i] + g[i][j].second + ijk_R[g[i][j].first] == D) {
				if ((ijk_L[g[i][j].first] > ijk_R[g[i][j].first]) && (ijk_L[i] < ijk_R[i])) {
					ng = (ng + L[i] * R[g[i][j].first] % MOD*L[i] % MOD*R[g[i][j].first]) % MOD;
				}
			}
		}
	}
	ret = (ret + MOD - ng) % MOD;
	cout << ret << endl;
}

Measured memory_bytes: 17912
#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int a[10];
		fill(a, a + 10, 0);
		for (int i = 0; i < n; i++) {
			int b;
			cin >> b;
			a[b]++;
		}
		for (int i = 0; i < 10; i++) {
			if (a[i] == 0)
				cout << "-";
			else {
				for (int j = 0; j < a[i]; j++)
					cout << "*";
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3028
#include<bits/stdc++.h>
using namespace std;
int n,vis[8],a[3]={3,5,7},ans;

void dfs(long long x)
{
	if(x > n) return;
	if(vis[3] && vis[5] && vis[7]) ans++;
	for(int i = 0; i < 3; i++){
		vis[a[i]]++;
		dfs(x*10+a[i]);
		vis[a[i]]--;
	}
}

int main()
{
	cin >> n;
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    char[] s = scanner.next().toCharArray();

    int min = Integer.MAX_VALUE;
    for (int i = 0; i < s.length - 2; i++) {
      int d = Math.abs((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0') - 753);
      min = Math.min(d, min);
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 22996
import java.math.BigInteger;
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        int a_4 = 0;
        int b = 0;
        for(int i = 0; i < n; i++) {
            int m = sc.nextInt();
            if (m % 4 == 0) {
                a_4++;
            } else if (m % 2 != 0) {
                b++;
            }
        }
            if(n / 2 <= a_4 || a_4 >= b){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
    }
}

Measured memory_bytes: 49488
h, w = gets.chomp.split.map(&:to_i)
grid = h.times.map{ gets.chomp.split('') }
ans = grid.select{ |ar| ar.any?{ |c| c == '#' } }
ans.transpose.select{ |ar| ar.any?{ |c| c == '#' } }.transpose.each{ |ar| puts ar.join('') }


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair



void bfs(mat G, ll r, vec_b& f, vec& C)
{
    queue<ll> Q;
    Q.push(r);
    f[r] = true;
    while(!Q.empty()) {
        ll v = Q.front(); Q.pop();
        FORR(nv,G[v]) {
            if(!f[nv]) {
                C[nv] = v + 1;
                Q.push(nv);
                f[nv] = true;
            }
        }
    }
}


int main()
{
    ll N, M;
    cin >> N >> M;
    mat G(N);
    REP(i,0,M) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        G[a].pb(b);
        G[b].pb(a);
    }

    vec C(N, 0);
    vec_b F(N, false);
    bfs(G, 0, F, C);
    _PR("Yes");
    REP(i,1,N) _PR(C[i]);



    return 0;
}

/*



*/

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

using namespace std;

#define sz(a) int(a.size())



int main() {
	int m, k;
	cin >> m >> k;

	if (m == 1) {
		puts(!k ? "0 0 1 1" : "-1");
		return 0;
	}
	if (k >= (1<<m)) {
		puts("-1");
		return 0;
	}

	for (int i = 0; i < (1<<m); i++) {
		if (i == k) continue;
		cout << i << " ";
	}
	cout << k;
	for (int i = (1<<m)-1; i >= 0; i--) {
		if (i == k) continue;
		cout << " " << i;
	}

	cout << " " << k << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl


int main()
{
    string s;
    cin >> s;
    pr((s == "ABC" ? "ARC" : "ABC"));
    return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
struct node{
    double x,y;
}ver[10010];
struct Edge{
    int u,v;
    double l;
}e[1000000];
int n,m;
int pre[10010];
int Find(int x){
    if(x == pre[x])
        return x;
    else return pre[x] = Find(pre[x]);
}
int Union(int x,int y){
    int fx = Find(x),fy = Find(y);
    if(fx == fy)
        return 0;
    else{
        pre[fy] = fx;
        return 1;
    }
}
bool cmp(Edge a,Edge b){
    return a.l > b.l;
}
int main(){
    int i,j;
    cin >> n >> m;
    for(i = 0; i < 10010; i++)
        pre[i] = i;
    for(i = 1; i <= n; i++){
        cin >> ver[i].x >> ver[i].y;
    }
    double allsum = 0.0;
    for(i = 0; i < m; i++){
        int u,v;
        double len;
        cin >> u >> v;
        len = sqrt((ver[u].x-ver[v].x)*(ver[u].x-ver[v].x)+(ver[u].y-ver[v].y)*(ver[u].y-ver[v].y));
        e[i].u = u;
        e[i].v = v;
        e[i].l = len;
        allsum += len;
    }
    //cout << allsum << endl;
    sort(e,e+m,cmp);
    double sum = 0.0;
    int num = 0;
    for(i = 0; i < m; i++){
        if(Union(e[i].u,e[i].v)){
            sum += e[i].l;
            num++;
        }
        if(num == n-1)
            break;
    }
    //cout << sum << endl;
    printf("%.3f\n",allsum-sum);
    return 0;
}

Measured memory_bytes: 3964
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readStr() -> [String] {
  let str:String = readLine()!
  let arr:[String] = str.components(separatedBy: " ")
  return arr
}

let nb=readInts()
let n=nb[0]
let strs=readStr()
let S=strs[0]
let T=strs[1]

var ans:String=""

for i in 0..<n{
  let c1=S[S.index(S.startIndex,offsetBy:i)]
  let c2=T[T.index(T.startIndex,offsetBy:i)]
  ans+=String(c1)+String(c2)
}

print(ans)

Measured memory_bytes: 14316
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007

void inp()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
} 
ll min(ll a,ll b)
{
    if(a<b)
        return a;
    else
        return b;
}
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main() {
    //inp();
    fio;
    ll n;
    cin>>n;

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

    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
    	if(i-1>=0)
    	{
    		dp[i]=min(dp[i],dp[i-1]+abs(nums[i]-nums[i-1]));
    	}
    	if(i-2>=0)
    	{
    		dp[i]=min(dp[i],dp[i-2]+abs(nums[i]-nums[i-2]));
    	}
    }
    cout<<dp[n-1]<<endl;

    return 0;
}

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

int main()
{
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

	long long int n,r;
	cin>>n>>r;
	if(n<10){
		cout<<(100*(10-n))+r;
	}
	else
	{
		cout<<r;
	}
	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
import heapq    
    
n = int(input())
a = []
b = []
for i in range(n):
    x,y= map(int, input().split())
    a.append((x,y,i))
    b.append((y,x,i))
a.sort()
b.sort()
edgea = []
edgeb = []
for i in range(n-1):
    edgea.append((a[i+1][0]-a[i][0],a[i][2],a[i+1][2]))
    edgeb.append((b[i+1][0]-b[i][0],b[i][2],b[i+1][2]))
edge = edgea+edgeb
heapq.heapify(edge)

uf = UnionFind(n)
ans = 0
while len(edge):
    x,y,z = heapq.heappop(edge)
    if not uf.same(y,z):
        ans += x
        uf.union(y,z)
print(ans)

Measured memory_bytes: 56776
#include <bits/stdc++.h>
using namespace std;
int uni[100000],n,m;
int find(int a){
	if(a!=uni[a])a=find(uni[a]);
	return a;
}
bool same(int a,int b){
	return find(a)==find(b);
}
void unit(int a,int b){
	uni[find(a)]=find(b);
}
int main() {
	cin>>n>>m;
	for(int i=0;i<n;i++)uni[i]=i;
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>c>>a>>b;
		if(c)cout<<(same(a,b)?1:0)<<endl;
		else unit(a,b);
	}
}

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

int main() {
    double n, s[1001], sum, ans;
    while(cin >> n){
        if(n==0) break;
        sum=0;
        ans=0;
        for(int i=0; i<n; i++){
            cin >> s[i];
            sum += s[i];
        }
        sum /= n;
        for(int i=0; i<n; i++){
            ans += (s[i] - sum)*(s[i] - sum);
        }
        ans /= n;
        ans = sqrt(ans);
        printf("%f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1236
S = input()
Q = int(input())
flag = 0
H = ""
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag%2 == 0:
            if q[1] == "1":
                H = H+q[2]
            else:
                S = S+q[2]
        else:
            if q[1] == "1":
                S = S+q[2]
            else:
                H = H+q[2]
H = H[::-1]
H = H+S
if flag%2 == 0:
    print(H)
else:
    H = H[::-1]
    print(H)

Measured memory_bytes: 4316