akhauriyash/Code-Regression huggingface dataset:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int, readline().split())

MAX = max(A, B)

i = 2
setA = set()
setB = set()
while i ** 2 <= A:
    if A % i == 0:
        while A % i == 0:
            A //= i
        setA.add(i)
    i += 1
if A > 1:
    setA.add(A)
i = 2
while i ** 2 <= B:
    if B % i == 0:
        while B % i == 0:
            B //= i
        setB.add(i)
    i += 1
if B > 1:
    setB.add(B)

print(len(setA & setB) + 1)



Measured memory_bytes: 3312
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc = new Scanner (System.in);
		
		long k = sc.nextInt();
		long seven = 7;
		
		for(int i=1;i<=k;i++) {
			if(seven%k==0) {
				System.out.println(i);
				return;
			}
			//sevenの桁数が大きくなりすぎるので、割ったあまりを入れておく
			seven=(seven*10+7)%k;
		}

		System.out.println(-1);

 
	}
 
}

Measured memory_bytes: 35800
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

struct Edge {
  int to;
  bool even_cost;
  Edge(int a, int b) {
    to = a;
    even_cost = (b % 2 == 0);
  }
};

vector<vector<Edge>> G;
vector<int> colors;

void dfs(int v, int c) {
  colors[v] = c;
  for (const auto& e : G[v]) {
    if (e.even_cost) {  // Need same color
      if (colors[e.to] == 0) dfs(e.to, c);
    } else {  // Need different color
      if (colors[e.to] == 0) dfs(e.to, -c);
    }
  }
}

int main() {
  int N; cin >> N;
  G.resize(N + 1);
  colors.resize(N + 1, 0);

  for (int i = 0; i < N; ++i) {
    int u, v, w; cin >> u >> v >> w;
    G[u].push_back(Edge(v, w));
    G[v].push_back(Edge(u, w));
  }

  for (int i = 1; i <= N; ++i) {
    if (colors[i] == 0) {
      dfs(i, 1);
    }
  }

  for (int i = 1; i <= N; ++i) {
    cout << (colors[i] > 0) << endl;
  }
}


Measured memory_bytes: 8192
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let s = scan!();

    let mut blacks = vec![0];
    let mut num: i64 = 0;
    for c in s.chars() {
        if c == '#' {
            num += 1;
        }
        blacks.push(num)
    }
    let mut whites = vec![0];
    let mut num: i64 = 0;
    for c in s.chars().rev() {
        if c == '.' {
            num += 1;
        }
        whites.push(num)
    }

    let mut ans: i64 = 1 << 60;
    for (b, w) in blacks.iter().zip(whites.iter().rev()) {
        ans = min(ans, b + w);
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

int main() {
    long long int N, b = 0, a[100000 * 2] = {}, ans = 0, sum[100000 * 2 + 1] = {}, dif = 0, mini = 1000000000 * 2 + 1;
    std::cin >> N;
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    for (int i = 0; i < N - 1; i++) {
        b = (sum[N] - sum[i + 1]) - sum[i + 1];
        dif = std::abs(b);
        mini = std::min(dif, mini);
    }
    std::cout << mini << std::endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;

int main(){
  int n,q;
  cin >> n >> q;
  vector<tuple<int, int, int>> eve;
  REP(i,n){
    int s,t,x;
    cin >> s >> t >> x;
    eve.emplace_back(s-x, 1, x);
    eve.emplace_back(t-x, -1, x);
  }
  sort(ALL(eve));
  set<int> st;
  int t, id=0;
  REP(i,q){
    cin >> t;
    for(; id<eve.size() && get<0>(eve[id])<=t; id++){
      if(get<1>(eve[id])==1){
        st.insert(get<2>(eve[id]));
      }else{
        st.erase(get<2>(eve[id]));
      }
    }
    if(st.empty()) cout << -1 << '\n';
    else cout << *st.begin() << '\n';
  }
  return 0;
}


Measured memory_bytes: 15852
#include <iostream>
#include <string>
int main() {
	int x = 0;
	std::string S;
	std::cin >> S;
	for (int i = 0; i < S.size(); i++)
		if (x == 1) {
			if (S[i] == 'F') {
				std::cout << "Yes" << std::endl;
				return 0;
			}
		}
		else if (S[i] == 'C')
			x = 1;
	std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int main()
{
	ll A = 0;
	double B = 0.0;
	scanf("%lld %lf", &A, &B);

	//double a = (double)A * B;
	//printf("%lld\n", (ll)a);

	B = B * 100.000000001;
	ll b = (ll)B;
	//printf("%lld\n", b);
	ll ans = (A * b)/100;
	//printf("%lld\n", A * b);
	printf("%lld\n", ans);
	//yesno(ans);
	//okng(ans);
	return 0;
}


Measured memory_bytes: 1744
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  cin >> S;

  if(S[0] != 'A'){
    cout << "WA\n";
    return 0;
  }
  
  int count=0;
  int flag = 0;
  for(int i=2; i<S.size()-1; ++i){
    if(S[i] == 'C'){
      flag = i;
      count++;
    }
  }

  if(count != 1){
    cout << "WA\n";
    return 0;
  }

  for(int i=1; i<S.size(); ++i){
    if(i==flag) continue;
    if(S[i]-'a' > 'z'-'a'){
      cout << "WA\n";
      return 0;
    }
    if(S[i]-'a' < 0){
      cout << "WA\n";
      return 0;
    }
  }

  cout << "AC\n";
  return 0;
}


Measured memory_bytes: 256
/*
    Written by Kabir Kanha Arora
    @kabirkanha
 */

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        StringBuilder ans = new StringBuilder();
        ans.append(s);
        if (s.charAt(s.length() - 1) == 's') {
            ans.append("es");
        } else {
            ans.append("s");
        }
        System.out.println(ans.toString());
    }

}


Measured memory_bytes: 35640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 1 << 28;

// original:
// https://qiita.com/drken/items/cce6fc5c579051e64fab
// the potentioal must form Abel group on the operation of interest
template <class Abel>
class PotentialUnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

  public:
    PotentialUnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n + 1);
        rank.resize(n + 1);
        diff_weight.resize(n + 1);
        for (int i = 0; i < n + 1; ++i)
            par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool isSame(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y, Abel w) {
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y), w = -w;
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};
int main() {
    int N, M;
    cin >> N >> M;
    vi l(M), r(M), d(M);
    for (int i = 0; i < M; ++i) {
        cin >> l[i] >> r[i] >> d[i];
    }
    PotentialUnionFind<int> uf(N);
    bool ret = true;
    for (int i = 0; i < M; ++i) {
        if (!uf.isSame(l[i], r[i])) {
            uf.unite(l[i], r[i], d[i]);
        } else {
            if (d[i] != uf.diff(l[i], r[i])) {
                ret = false;
                break;
            }
        }
    }
    if (ret)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int gcd(int x,int y){
    return y==0?x:gcd(y,x%y);
}
const int N=100000+10;
int n,a[N],pre[N],suf[N];
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)pre[i]=gcd(pre[i-1],a[i]);
    for(int i=n;i>=1;i--)suf[i]=gcd(suf[i+1],a[i]);
    int ans=0;  
    for(int i=1;i<=n;i++)ans=max(ans,gcd(pre[i-1],suf[i+1]));
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
N = int(input())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))

items = sorted(items, key=lambda x: x[1])


now = 0
for k, v in items:
    if now + k <= v:
        now += k
        continue
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 33468
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC144D
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputArr = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //var inputInt = int.Parse(Console.ReadLine());

            int a = inputArr[0];
            int b = inputArr[1];
            int x = inputArr[2];

            double ans = 0;
            //string ans = "";

            if (x >= a * a * b / 2.0)
            {
                ans = Math.Atan(2.0 * b / a - 2.0 * x / (a * a * a)) / Math.PI * 180;
            }
            else
            {
                ans = 90 - Math.Atan(2.0 * x / (a * b * b)) / Math.PI * 180;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n+1,0);
    rep(i,n+1)cin >> a[i];
    vector<ll> b(n,0);
    rep(i,n)cin >> b[i];
    ll ans = 0;
    rep(i, n) {
		int kill = 0;
		if (a[i] <= b[i]) {
			kill += a[i];
			b[i] -= a[i];
			if (b[i] >= a[i+1]) {
				kill += a[i+1];
				a[i + 1] = 0;
			}
			else {
				kill += b[i];
				a[i+1] -= b[i];
			}
		}
		else {
			kill += b[i];
		}
		ans += kill;
	}
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 1792
n=int(input())
arr=list(map(int,input().split()))
total=sum(arr)
acum=[arr[0]]
for i in range(1,n):
  acum.append(arr[i]+acum[-1])
ans=10**18
for i in range(n):
  tmp=abs(acum[i]-(total-acum[i]))
  ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 26764
// 
// Fifteen Puzzle (Recursive Best First Search)
//
// ?????????????????????????????£???????°??????????????????????
//

#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <unordered_set>

using namespace std;

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())
#define TEST(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }

int B[4][4], x, y;
int manhattan_distance = 0;
int md(int i, int j) {
  int a = B[i][j] - 1;
  return abs(a%4 - j) + abs(a/4 - i);
}
int move(int d) {
  int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1};
  int X = x + dx[d], Y = y + dy[d];
  if (X < 0 || X >= 4 || Y < 0 || Y >= 4) return false;
  manhattan_distance -= md(X,Y);
  swap(B[x][y], B[X][Y]);
  manhattan_distance += md(x,y);
  x = X; y = Y;
  return true;
}

const int INF = 9999999;
int rbfs() {
  typedef pair<int, bool> result;
  function<result(int,int,int,int)> rec = [&](int depth, int prev, int lower, int bound) {
    if (lower > bound) return result(lower, false);
    if (manhattan_distance == 0) return result(depth, true);
    int score = manhattan_distance + depth;

    int F[4] = {INF+1, INF+1, INF+1, INF+1};
    for (int d = 0; d < 4; ++d) {
      if (abs(prev - d) == 2) continue;
      if (move(d)) {
        F[d] = depth + manhattan_distance + 1;
        if (score < lower) F[d] = min(F[d], lower);
        move((d + 2) % 4);
      }
    }

    while (1) {
      int d = 0, th = INF;
      for (int j = 0; j < 4; ++j) 
        if      (F[j] < F[d]) { th = F[d]; d = j; }
        else if (F[j] < th) { th = F[j]; }
      if (F[d] > bound) return result(F[d], false);
      move(d);
      result z = rec(depth + 1, d, F[d], min(bound, th));
      if (z.snd) return z;
      F[d] = z.fst;
      move((d + 2) % 4);
    }
  };
  printf("%d\n", rec(0, 100, 0, INF).fst);
  return 0;
}

int main() {
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      scanf("%d", &B[i][j]);
      if (B[i][j] == 0) { x = i, y = j; }
      else { manhattan_distance += md(i, j); }
    }
  }
  rbfs();
}

Measured memory_bytes: 1176
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    max_val = 0
    A = [0] + A + [0]
    for i in range(len(A)):
        max_val += abs(A[i]-A[i-1])
    for i in range(1,len(A)-1):
        print(max_val + abs(A[i-1]-A[i+1]) - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 86884
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<math.h>
#include<queue>
#define inf 0x3f3f3f
#define M 200000
#define ll  long long
using namespace std;
string s;
int a[M];
int main()
{
    cin>>s;
    int len=s.size();
    int i,j;
    int count=0;
    for(i=0;i<len;i++)
    {
        if(s[i]!=s[i-1])
        {
            a[count++]=max(i,len-i);

        }
    }
 sort(a,a+count);
 cout<<a[0]<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,ans=1e9+7,l,r,d;cin>>n>>k;
  lvector x(n,0); rep(i,n) cin>>x[i];
  for(ll i=0;i+k-1<n;++i) {
    l=i,r=i+k-1;
    if(x[r]<=0) d=abs(x[l]);
    else if(x[l]<0&&x[r]>0) {
      ll d1=2*abs(x[l])+x[r], d2=abs(x[l])+2*x[r];
      d=min(d1,d2);
    }
    else if(x[l]>=0) d=x[r];
    ans=min(ans,d);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
h=0
w=0

while 1:
    w,h=map(int,input().split())
    if h==0 and w==0:
        break
    grid=[]
    sx=-1
    sy=-1
    ans=1
    used=[[0]*w for i in range(h)]
    def valid(i,j):
        return i>=0 and j>=0 and i<h and j<w and grid[i][j]=='.' and not used[i][j]
    for i in range(h):
        row=input()
        grid.append(row)
        for j in range(w):
            if row[j]=='@':
                sx=i
                sy=j
    stk=[(sx,sy)]
    while stk:
        x=stk[-1][0]
        y=stk[-1][1]
        stk.pop()
        for d in [(1,0),(0,1),(-1,0),(0,-1)]:
            xx=x+d[0]
            yy=y+d[1]
            if valid(xx,yy):
                stk.append((xx,yy))
                used[xx][yy]=1
                ans+=1
    print(ans)



Measured memory_bytes: 5624
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
#define M 1000000007

  
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    
    if(a>=k)
    cout<<k<<endl;
    else if(a+b>=k)
    cout<<a<<endl;
    else
    {
        cout<<a-(k-(a+b))<<endl;
    }
    
   
    
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "";
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == '0'){
                ans += "0";
            } else if (s.charAt(i) == '1'){
                ans += "1";
            } else {
                if(ans.length() > 0){
                    ans = ans.substring(0, ans.length() - 1);
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
n = int(input())
num_list = input().split()

def bubbleSort(num_list, n):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if int(num_list[j]) < int(num_list[j-1]):
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = 1
                count += 1

    result = ' '.join(num_list)
    print(result)
    print(count)

bubbleSort(num_list, n)

Measured memory_bytes: 7744
//stay in this moment
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void q1(){
	int ans=0;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<3;++i)
	if(s[i]==t[i])
	ans++;
	cout<<ans;
}
void q2(){
	int a,b;
	cin>>a>>b;
	int ans=(b+a-2)/(a-1);
	cout<<ans;
}
void q3(){
	int n;
	cin>>n;
	int arr[n],fre[n];
	for(int i=0;i<n;++i)
	{cin>>arr[n-i-1];fre[i]=1;}
	for(int i=1;i<n;++i)
	if(arr[i]>=arr[i-1])
	fre[i]+=fre[i-1];
	int mx=-1;
	for(int i=0;i<n;++i)
	mx=max(mx,fre[i]);
	cout<<mx;
}
void q4(){
	int n;
	cin>>n;
	n*=(n-1);
	cout<<n/2;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	q1();
	return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(int argc, const char * argv[]) {
    int a;int b;int temp;
    while(~scanf("%d%d",&a,&b)){
        temp=a+b;
        if(temp%2!=0)
    cout << "IMPOSSIBLE\n";
        else
            cout<<(int)temp/2<<endl;
    }
}

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

int main() {
  int x;
  cin >> x;
  if (x == 1) {
    cout << 1 << endl;
    return 0;
  }
  int res = 0;
  for (int i = 2; i * i <= x; i++) {
    int tmp = i;
    while (tmp <= x) tmp *= i;
    res = max(res, tmp/i);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 1e5 + 1;
const ll inf = 1e8;
typedef pair<ll,ll> LL;

template<typename T> inline void Read(T &x){
	register char c;
	bool neg=false;
	for(c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') neg=true;
	for(x=0;'0'<=c&&c<='9';c=getchar()) x=x*10+c-'0';
	if(neg) x=-x;
}

template<typename T,typename... Args> inline void Read(T &x,Args&... args){
	Read(x);
	Read(args...);
}

template<typename T> inline void Write(T x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) Write(x/10);
	putchar(x%10+'0');
}

template<typename T> inline void Write(T x, const char &c){
	if(x<0) putchar('-'),x=-x;
	Write(x);
	putchar(c);
}

template <typename T,typename... Args> inline void Write(const T &a, const char &c, Args... args){
    Write(a,c);
    Write(args...);
}


LL a[3*N];
ll u,v,n,q,i,dp[1024][N];
ll gen(ll x,ll y){
    if (x < 1024) return dp[x][y];
    ll ans = gen(x/2,y);
    if (a[x].sc <= y) ans = max(ans,a[x].fs + gen(x/2,y - a[x].sc));
    return ans;
}
int main(){
    //ios_base::sync_with_stdio(0);
    //cin.tie(0), cout.tie(0);
    Read(n);
    for (i = 1;i <= n;i++) Read(a[i].fs),Read(a[i].sc);
    for (i = 1;i < 1024;i++){
        for (ll j = 1;j < N;j++){
            dp[i][j] = dp[i/2][j];
            if (j >= a[i].sc) dp[i][j] = max(dp[i][j],a[i].fs + dp[i/2][j - a[i].sc]);
        }
    }
    cin>>q;
    while(q--){
        Read(u); Read(v);
        Write(gen(u,v)); cout<<"\n";
    }
}


Measured memory_bytes: 806940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}




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

int n;
cin >> n;
vector<string>v(n);
rep(i,n) cin >> v[i];

Sort(v);
v.erase(unique(v.begin(), v.end()), v.end());

cout << v.size() << endl;



//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 9536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
int main(){
    int n, m;
    cin >> n >> m;
    string a[100], b[100];
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    rep(i,n){
        rep(j,n){
            bool flag = true;
            rep2(y,i,i+m){
                rep2(x,j,j+m){
                    if(a[y][x]!=b[y-i][x-j])flag = false;
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int n;
int x[24],y[24],c[24],r[24];
bool memo[1<<24];
int hit(int i,int j){
	int L = r[i]*r[i] + r[j]*r[j] + 2 * r[i] * r[j];
	int X = (x[i]-x[j])*(x[i]-x[j]);
	int Y = (y[i]-y[j])*(y[i]-y[j]);
	return X + Y < L;
}
int nocover(int n,int bit){
	for(int i = 0 ; i < n ; i++){
		if( (bit>>i&1) && hit(i,n) ) return false;
	}
	return true;
}
int ans;
void dfs(int bit){
	ans = min(ans,__builtin_popcount(bit));
	if(memo[bit]) return;
	else memo[bit] = true;
	for(int i = 0 ; i < n ; i++){
		for(int j = i+1 ; j < n ; j++){
			if( (bit >> j & 1) && (bit >> i & 1) && c[i] == c[j] && nocover(i,bit) && nocover(j,bit) ){
				dfs( bit - (1<<j) - (1<<i) );
			}
		}
	}
	return;
}
int main(){
	while(cin >> n , n){
		for(int i = 0 ; i < n ; i++){
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		ans = n;
		memset(memo,0,sizeof(memo));
		dfs((1<<n)-1);
		cout << n-ans << endl;
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll whole = 0;
    rep(i,n){
        whole ^= a[i];
    }
    rep(i,n){
        cout << ll(whole ^ a[i]) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4832
N, K = map(int, input().split())
list_sunuke = [0]*N #list初期化

for i in range(K):
	d = int(input())
	list_k = list(map(int, input().split()))
    
	for j in range(len(list_k)):
		list_sunuke[list_k[j]-1]=list_sunuke[list_k[j]-1]+1
        
print(list_sunuke.count(0))


Measured memory_bytes: 9196
n = gets.chomp.split(" ").map(&:to_i)[0]
numbers = gets.chomp.split(" ").map(&:to_i)

min = 10 ** 6
numbers.each do |num|
    sum = 0
    while num % 2 == 0 do
        num = num / 2
        sum += 1
    end
    min = sum if sum < min
end

puts min


Measured memory_bytes: 1788
while n = gets.to_i
  break if n == 0
  hash = {}
  n.times{|i|
    e, p, q = gets.split.map(&:to_i)
    hash[e] ||= 0
    hash[e] += p * q
  }
  flag = true
  hash.keys.each{|key|
    if hash[key] >= 1000000
      flag = false
      puts "#{key}"
    end
  }
  if flag
    puts "NA"
  end
end

Measured memory_bytes: 8820
#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
using namespace std;
const LL N=2009,M=N*N,YL=1e9+7;
int f[N][N],fac[M],inv[M];
inline int fm(RG LL b){
	RG LL a=1;
	for(R k=YL-2;k;k>>=1,b=b*b%YL)
		if(k&1)a=a*b%YL;
	return a;
}
inline int C(R n,R m){
	if(n<0||m<0||n<m)return 0;
	return(LL)fac[n]*inv[m]%YL*inv[n-m]%YL;
}
int main(){
	R n,k,nk;
	scanf("%d%d",&n,&k);nk=n*k;
	if(k==1)return puts("1"),0;
	for(R i=fac[0]=1;i<=nk;++i)
		fac[i]=fac[i-1]*(LL)i%YL;
	inv[nk]=fm(fac[nk]);
	for(R i=nk;i;--i)
		inv[i-1]=inv[i]*(LL)i%YL;
	f[0][0]=1;
	for(R i=1;i<=n;++i)
		for(R j=f[i][0]=1;j<=i;++j)
			f[i][j]=(f[i-1][j]+(LL)f[i][j-1]*(n-j+1)%YL*C(n-i+(n-j+1)*(k-1)-1,k-2))%YL;
	printf("%d\n",f[n][n]);
	return 0;
}

Measured memory_bytes: 47488
n,s,*a=map(int,open(0).read().split())
mod=998244353
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=pow(2,n,mod)
for i in range(n):
  for j in range(s+1):
    dp[i+1][j]+=dp[i][j]
    dp[i+1][j]%=mod
    if j+a[i]<=s:
      dp[i+1][j+a[i]]+=dp[i][j]*(mod+1)//2
      dp[i+1][j+a[i]]%=mod
print(dp[n][s])

Measured memory_bytes: 139200
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vll a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    ll A = a[0], B = b[0];
    rep(i, 1, n){
        ll m = max(A / a[i] + (A % a[i] ? 1:0),
                   B / b[i] + (B % b[i] ? 1:0));
        A = m * a[i];
        B = m * b[i];
    }

    cout << A + B << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    int n; cin >> n;
    vector<int> s(n);
    int ans = 0;
    rep(i, n) {
        cin >> s[i];
        ans += s[i];
    }
    if(ans%10 != 0) {
        cout << ans << endl;
        return 0;
    } else {
        sort(s.begin(), s.end());
        rep(i, n) {
            if((ans-s[i])%10 != 0) {
                cout << ans-s[i] << endl;
                return 0;
            }
        }
    }

    cout << 0 << 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);
        String s = sc.next();
        String ans = "";
        for(int i = 0; i < s.length(); i++){
        	if(s.charAt(i) == '0'){
            	ans += "0";
            }else if(s.charAt(i) == '1'){
            	ans += "1";
            }else if(s.charAt(i) == 'B' && !(ans.isEmpty())){
            	ans = ans.substring(0, ans.length() - 1);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 38440
N=int(input())

ab=0
a=0
b=0
boa=0

for _ in range(N):
    s=input()
    ab+=s.count("AB")
    if s[0]=="B" and s[-1]=="A":
        boa+=1
    elif s[0]=="B":
        b+=1
    elif s[-1]=="A":
        a+=1
ans=ab

if boa>0:
    ans+=boa-1
    if b>0:
        ans+=1
        b-=1
    if a>0:
        ans+=1
        a-=1
ans+=min(a,b)
print(ans)

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

int max(int a, int b);
void findLCS(char *X, char *Y, int XLen, int YLen);

int max(int a, int b) {
  return (a > b)? a : b;
}

void findLCS(char *X, char *Y, int XLen, int YLen) {
  int L[XLen + 1][YLen + 1];
  int r, c, i;

  /*
   * find the length of the LCS
   */
  for(r = 0; r <= XLen; r++) {

    for(c = 0; c <= YLen; c++) {

      if(r == 0 || c == 0) {

        L[r][c] = 0;

      } else if(X[r - 1] == Y[c - 1]) {

        L[r][c] = L[r - 1][c - 1] + 1;

      } else {

        L[r][c] = max(L[r - 1][c], L[r][c - 1]);
      }
    }
  }

  /*
   * Print LCS
   */
  r = XLen;
  c = YLen;
  i = L[r][c];

  char LCS[i+1];

  /*
   * setting the NULL character at the end of LCS character array.
   * as we know in C programming language, NULL character is used
   * to denote the end of a string
   */
  LCS[i] = '\0';

  while(r > 0 && c > 0) {

    if(X[r - 1] == Y[c - 1]) {

      LCS[i - 1] = X[r - 1];

      i--;
      r--;
      c--;

    } else if(L[r - 1][c] > L[r][c - 1]) {

      r--;

    } else {

      c--;

    }

  }

  //print result
  // printf("Length of the LCS: %d\n", L[XLen][YLen]);
  printf("%s\n", LCS);
}

int main(void) {
  //the two sequences
  char X[3005];
  char Y[3005];

  scanf("%s",X);
  scanf("%s",Y);

  //length of the sequences
  int XLen = strlen(X);
  int YLen = strlen(Y);

  findLCS(X, Y, XLen, YLen);

  return 0;
}

Measured memory_bytes: 35328
#include <cstdio> 

int N;
int a[100010];
char s[10];

void solve()
{
	printf("%d\n", 0);
	fflush(stdout);
	scanf("%s", s);
	if(s[0]=='V')
		return ;
	else if(s[0]=='M')
		a[0] = a[N] = 1;
	else
		a[0] = a[N] = 2;
	int l=0, r=N;
	int i;
	while(1){
		//if(l+2==r){
		//}
		i = (l+r)/2;
		printf("%d\n", i);
		fflush(stdout);
		scanf("%s", s);
		if(s[0]=='V')
			return ;
		else if(s[0]=='M'){
			a[i] = 1;
			if(a[l]==1 && (i-l)%2==1 || a[l]==2 && (i-l)%2==0 )
				r = i;
			else
				l = i;
		}
		else{
			a[i] = 2;
			if(a[l]==2 && (i-l)%2==1 || a[l]==1 && (i-l)%2==0 )
				r = i;
			else
				l = i;
		}
	}
}

int main()
{
	scanf("%d", &N);
	solve();
	return 0;
}

Measured memory_bytes: 852
#include <iostream>

using namespace std;

int main()
{

    int K, A, B;
    cin >> K >> A >> B;

    bool flag = false;
    for (int i = A; i <= B; i++)
    {
        if (i % K == 0)
        {
            flag = true;
            break;
        }
    }

    if (flag)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128;
using cint = cpp_int;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define input(a) scanf("%lld", &a)
#define output(a) printf("%lld\n", a)
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
// run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll N, X, ANS;
vector<ll> A, B;
signed main() {
    input(N);
    rep(i, N) input(X), A.push_back(X);
    rep(i, N) input(X), B.push_back(X);
    rep(k, 29) {
        ll T = 1 << k, C = 0;
        vector<ll> MA, MB;
        rep(i, N) {
            MA.push_back(A[i] % (2 * T));
            MB.push_back(B[i] % (2 * T));
        }
        sort(all(MB));
        rep(i, N) {
            C += lower_bound(all(MB), 2 * T - MA[i]) -
                 lower_bound(all(MB), T - MA[i]);
            C += MB.end() - lower_bound(all(MB), 3 * T - MA[i]);
        }
        if (C & 1) ANS += T;
    }
    output(ANS);
}

// for compilation: g++ -O3 -o _ _.cpp -std=c++17


Measured memory_bytes: 8896
n=int(input())
s=str(input())
r=0
g=0
b=0
for x in range (n):
    if s[x]=='R':
        r+=1
    elif s[x]=='G':
        g+=1
    else:
        b+=1
rgb=r*g*b

for i in range (n):
    for j in range (i,n):
        k=j*2-i
        if k<n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                rgb=rgb-1
print(rgb)


Measured memory_bytes: 9148
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;
vi x;

signed main(){

    in(n);
    resz(n,x);
    in(x);
    sort(all(x));
    int h=0;
    rep(i,n-1){
        h+=x[i];
    }
    out(h>x[n-1]?"Yes":"No");

    return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;
public class Main{
	public void solve(){
		Scanner sc=new Scanner(System.in);
		int N,k;
		int ichi=0;
		int fuku=1;
		N=sc.nextInt();
		while(N!=0){
			for(int i=0;i<N;i++){
				k=sc.nextInt();
				if(k>=2){
					fuku++;
				}
				if(k==1){
					ichi++;
				}
			}
			if(fuku>=2){
				System.out.println(ichi+fuku);
			}else{
				System.out.println("NA");
			}
			fuku=1;
			ichi=0;
			N=sc.nextInt();
		}
	}
	public static void main(String[]args){
		Main obj =new Main();
		obj.solve();
	}
}

Measured memory_bytes: 158624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
int h,w;
int ch,cw;
int dh,dw;
char m[1010][1010];
int seen[1010][1010];
queue<P>que;
void dfs(int y,int x){
    rep(i,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
        if(seen[ny][nx])continue;
        if(m[ny][nx]=='#'){
            que.push(P(y,x));
            continue;
        }
        seen[ny][nx]=seen[y][x];
        dfs(ny,nx);
    }
}

void check(int y,int x){
    //if(seen[y][x])return;
    for(int ny=y-2;ny<=y+2;ny++)for(int nx=x-2;nx<=x+2;nx++){
        if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
        if(m[ny][nx]=='#')continue;
        if(seen[ny][nx])continue;
        seen[ny][nx]=seen[y][x]+1;
        dfs(ny,nx);
    }
}
int main(){
    cin>>h>>w;
    cin>>ch>>cw;
    ch--;cw--;
    cin>>dh>>dw;
    dh--;dw--;
    rep(i,h)rep(j,w){
        cin>>m[i][j];
    }
    memset(seen,0,sizeof(seen));
    seen[ch][cw]=1;
    dfs(ch,cw);
    while(que.size() && seen[dh][dw]==0){
        P next=que.front();
        que.pop();
        check(next.fi,next.se);
    }
    cout<<seen[dh][dw]-1<<endl;
}

Measured memory_bytes: 8820
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextLineValue() int {
  sc.Scan()
  return getInt(sc.Text())
}

func nextLineValues() []int {
  sc.Scan()
  return getIntArray(sc.Text())
}

func getInt(s string) int {
  v, _ := strconv.Atoi(s)
  return v
}

func getIntArray(s string) []int {
  var v []int
  valstr := strings.Split(s, " ")
  for _, c := range valstr {
    va, _ := strconv.Atoi(c)
    v = append(v, va)
  }
  return v
}

func digitTotal(v int) int {
  total := 0
  d := strings.Split(strconv.Itoa(v), "")
  for _, c := range d {
    dv, _ := strconv.Atoi(c)
    total += dv
  }
  return total
}

func sortDesc(v *[]int) {
  sort.Sort(sort.Reverse(sort.IntSlice(*v)))
}

func removeDupIntSlice(values *[]int) []int {
  m := make(map[int]bool)
  uniq := []int{}
  for _, v := range *values {
    if !m[v] {
      uniq = append(uniq, v)
      m[v] = true
    }
  }
  return uniq
}



func main() {
  l1 := nextLineValues()
  l2 := nextLineValues()
  l3 := nextLineValues()
  matrix := make([]int, 9)
  for i:=0; i<3; i++ {
    matrix[i] = l1[i]
  }
  for i:=0; i<3; i++ {
    matrix[3+i] = l2[i]
  }
  for i:=0; i<3; i++ {
    matrix[6+i] = l3[i]
  }

  n := nextLineValue()
  values := map[int]bool{}
  for i:=0; i<n; i++ {
    values[nextLineValue()] = true
  }

  for i:=0; i<3; i++ {
    if _, ok := values[matrix[i*3]]; ok {
      if _, ok := values[matrix[i*3+1]]; ok {
        if _, ok := values[matrix[i*3+2]]; ok {
          fmt.Print("Yes")
          return
        }
      }
    }
  }

  for i:=0; i<3; i++ {
    if _, ok := values[matrix[i]]; ok {
      if _, ok := values[matrix[i+3]]; ok {
        if _, ok := values[matrix[i+6]]; ok {
          fmt.Print("Yes")
          return
        }
      }
    }
  }

  if _, ok := values[matrix[0]]; ok {
    if _, ok := values[matrix[4]]; ok {
      if _, ok := values[matrix[8]]; ok {
        fmt.Print("Yes")
        return
      }
    }
  }

  if _, ok := values[matrix[2]]; ok {
    if _, ok := values[matrix[4]]; ok {
      if _, ok := values[matrix[6]]; ok {
        fmt.Print("Yes")
        return
      }
    }
  }

  fmt.Print("No")
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main() {
    long long n, money = 1000;
    cin >> n;
    vector<long long> A(n);
    for (int i = 0; i < n; i++) cin >> A.at(i);
    for (int i = 0; i < n - 1; i++) {
        long long stock = 0;
        if (A.at(i) < A.at(i + 1)) stock = money / A.at(i);
        money += (A.at(i + 1) - A.at(i)) * stock;
    }
    cout << money << endl;
 }

Measured memory_bytes: 3644
import std;

void main() {
    int n, m; scan(n, m);
    auto a = readints;
    int ans = n - a.sum;
    writeln(max(ans, -1));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 3872