akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 x;
    cin >> x;
    cout << YN(1, 0, x == 0) << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= 10000; i++) {
    sum += i;
    if (sum >= n) {
      int k = sum - n;
      for (int j = i; j >= 1; j--) {
        if (j == k) {
          continue;
        }
        cout << j << endl;
      }
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

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

			int N = scan.nextInt();
			int M= scan.nextInt();
			int K= scan.nextInt();
			int[]A = new int[M];
			int[]B = new int[M];
			UnionFind uni = new UnionFind(N);
			Map<Integer,Integer>map = new TreeMap<Integer,Integer>();

			for(int i = 0;i<N;i++) {
				map.put(i+1, 0);
			}

			for(int i = 0;i<M;i++) {
				A[i] = scan.nextInt();
				B[i] = scan.nextInt();
				if(map.containsKey(A[i]))map.put(A[i], map.get(A[i])-1);
				//else map.put(A[i], -1);
				if(map.containsKey(B[i]))map.put(B[i], map.get(B[i])-1);
				//else map.put(B[i], -1);
				uni.connect(A[i]-1, B[i]-1);

			}
			int[]C = new int[K];
			int[]D = new int[K];
			for(int i = 0;i<K;i++) {
				C[i] = scan.nextInt();
				D[i] = scan.nextInt();
				if(uni.root(D[i]-1)==uni.root(C[i]-1)) {
					if(map.containsKey(C[i]))map.put(C[i], map.get(C[i])-1);
					//else map.put(C[i], -1);
				}
				if(uni.root(C[i]-1)==uni.root(D[i]-1)) {
					if(map.containsKey(D[i]))map.put(D[i], map.get(D[i])-1);
					//else map.put(D[i], -1);
				}



			}

			for(int i = 0;i<N;i++) {
				//System.out.println(uni.size(i));
			}


			for(int i = 0;i<N;i++) {
				int s = uni.size(i);
				int mi = map.get(i+1);
				System.out.print(s-1+mi+" ");
			}








		}


	}

private static class UnionFind {
		int Parent[];

		UnionFind(int n) {// Initialize by -1
			Parent = new int[n];
			Arrays.fill(Parent, -1);
		}

		int root(int A) {// In which tree is A?
			if (Parent[A] < 0)
				return A;
			return Parent[A] = root(Parent[A]);
		}

		int size(int A) {// size of tree which is include A
			return -Parent[root(A)];
		}

		boolean connect(int A, int B) {// Connect A and B
			A = root(A);
			B = root(B);
			if (A == B)
				return false;
			if (size(A) < size(B)) {
				int C = 0;
				C = B;
				B = A;
				A = C;
			} // SWAP
			Parent[A] += Parent[B];
			Parent[B] = A;
			return true;
		}
	}

}


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

public class Main {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(); //数列の長さ
    int[] a = new int[n];
    for (int i=0; i<n; i++) { //数列読み込み
        a[i] = sc.nextInt();
    }
    out(a,n);
    sort(a,n);
    }
    /**
     * ソート
     * @param a
     * @param n
     */
    public static void sort(int[] a, int n) {
        for (int i=1; i<n; i++) {
            int v = a[i];
            int j = i-1;
            while(j>=0 && a[j]>v) {
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = v;
            out(a,n);
        }
    }
    /**
     * 出力
     * @param a
     * @param n
     */
    public static void out(int[] a, int n) {
        for (int i=0; i<n; i++) {
            if(i==n-1) {
                System.out.print(a[i]);
                System.out.println();
            } else {
                System.out.print(a[i]+" ");
            }
        }
    }
}



Measured memory_bytes: 31764
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = __int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve(){
  int X, Y, Z, K;
  ll A[1000], B[1000], C[1000];
  vector<ll> v;

  cin >> X >> Y >> Z >> K;
  for(int i = 0; i < X; i++) cin >> A[i];
  for(int i = 0; i < Y; i++) cin >> B[i];
  for(int i = 0; i < Z; i++) cin >> C[i];

  sort(A, A+X, greater<ll>());
  sort(B, B+Y, greater<ll>());
  sort(C, C+Z, greater<ll>());

  for(int i = 0; i < X; i++){
    for(int j = 0; j < Y; j++){
      for(int k = 0; k < Z; k++){
        if((i+1)*(j+1)*(k+1) <= K) v.push_back(A[i]+B[j]+C[k]);
        else break;
      }
    }
  }

  sort(v.begin(), v.end(), greater<ll>());
  for(int i = 0; i < K; i++){
    cout << v[i] << endl;
  }
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    int n = s.length(), ans = n;
    for (int i = 1; i < n; i++)
        if (s[i - 1] != s[i]) ans = std::min(ans, std::max(i, n - i));
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<string> split(const string &s, char sep) {
  vector<string> res;
  int pos = 0, find_pos;
  while ((find_pos = s.find(sep, pos)) != string::npos) {
    res.emplace_back(s.substr(pos, find_pos - pos));
    pos = ++find_pos;
  }
  if (pos != s.size()) res.emplace_back(s.substr(pos, s.size() - pos));
  return res;
}

int dfs(int u, vector<vector<int>> &G, vector<bool> &visit) {
  visit[u] = true;
  if (G[u].size() == 0) return 1;
  int res = 0;
  for (auto &v : G[u]) if (!visit[v]) {
    res += dfs(v, G, visit);
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n;
  while (cin >> n, n) {
    vector<string> s(n);
    map<string, int> mp;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      s[i] = s[i].substr(0, s[i].size() - 1);
      auto a = split(s[i], ':');
      auto b = split(a[1], ',');
      mp[a[0]]++;
      for (auto &j : b) mp[j]++;
    }

    int id = 0;
    for (auto &i : mp) i.second = id++;

    int V = mp.size();
    vector<vector<int>> G(V);
    int group1 = -1;
    for (int i = 0; i < n; i++) {
      auto a = split(s[i], ':');
      auto b = split(a[1], ',');
      for (auto &j : b) {
        G[mp[a[0]]].emplace_back(mp[j]);
      }
      if (i == 0) group1 = mp[a[0]];
    }
    
    vector<bool> visit(V);
    cout << dfs(group1, G, visit) << endl;
  }

  return 0;
}


Measured memory_bytes: 3416
import math
n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if math.sqrt(sum(list(map(lambda c: (c[0] - c[1])**2, zip(x[i], x[j]))))).is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> ue;
    vector<int> shita;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        if (!i) ue.push_back(a);
        else {
            ue.push_back(ue[i-1]+a);
        }
    }

    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        if (!i) shita.push_back(ue[i] + a);
        else {
            shita.push_back(max(ue[i]+a, shita[i-1]+a));
        }
    }

    cout << shita[n-1] << endl;

    return 0;
}

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

int N;
vector<int> G[200];
int Gs[200];
int F[200];
vector<int> V;
int cnt;
void solve(int id,int h){
  F[id] = h;
  //  cout << "inid : " << id << " " << h <<  " " << V[cnt] << " F " << F[id] << endl;
  
  for(int i=1;i<=100;i++){
    int d = V[cnt];
    if( d > 0 ){
      if( !Gs[i] ) {
        G[id].push_back( i );
        G[i].push_back( id );
        Gs[i] = d; cnt++;
        solve(i,h+1);
        i = 0;
      }    
    } else {
      //cout << "nex " << d << " i " << i << " = "  << F[i]<<" - " << F[id] <<" = " << F[i]-F[id] << endl;
        if( F[i]!=-1 && F[i] - F[id] == d && Gs[i] > (int)G[i].size() ){
          G[id].push_back(i);
          G[i].push_back(id);
          cnt++;
          i = 0;
        }
    }
    if( (int)G[id].size() == Gs[id] ) {
      //  cout <<"id: " << id << " " <<  G[id].size() <<", " << Gs[id] << endl;
      break;
    }
    assert(i<100);
  }
}

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    memset(F,-1,sizeof(F));
    memset(Gs,0,sizeof(Gs));
    V.clear();
    for(int i=0;i<200;i++) G[i].clear();
    int t;
    while(cin>>t && t ) V.push_back(t);
    
    cnt = 0;
    Gs[1]=V[cnt++];
    solve(1,0);
    for(int i=1;i<=100;i++){
      if( G[i].empty() ) continue;
      //      cout << Gs[i] << " " << G[i].size() << endl;
      sort(G[i].begin(),G[i].end());
      cout << i;
      for(int j=0;j<(int)G[i].size();j++) cout << " " << G[i][j];
      cout << endl;
    }
  }
}

Measured memory_bytes: 1248
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   int[] t = new int[N];
   int sum = 0;
   for(int i=0;i<N;i++) 
   {
     t[i] = sc.nextInt();
     sum += t[i];
   }
   int M = sc.nextInt();
   
   int p;
   int x;
   int tmp = sum;
   for(int i=0;i<M;i++) 
   {
     p = sc.nextInt();
     x = sc.nextInt();
     tmp = sum;
     
     tmp += x-t[p-1];
     System.out.println(tmp);
   }
 }
}

Measured memory_bytes: 21716
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  int n, m;
  cin >> n >> m;
  ll ans = 1;
  if (n == m) {
    rep(i, n) { ans = ans * (i + 1) % MOD * (i + 1) % MOD; }
    ans = ans * 2 % MOD;
  } else if (n == m + 1 || n + 1 == m) {
    rep(i, n) { ans = ans * (i + 1) % MOD; }
    rep(i, m) { ans = ans * (i + 1) % MOD; }
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int N, D; cin >> N >> D;
	vector<vector<int> > X(N, vector<int>(D));

	for(int i = 0; i < N; ++i){
		for(int j = 0; j < D; ++j){
			cin >> X[i][j];
		}
	}

	int cnt = 0;
	for(int i = 0; i < N; ++i){
		for(int j = i; j < N; ++j){
			if(i == j) continue;
			double sum = 0;
			// cout << "i:" << i << ", j:" << j << endl;
			for(int k = 0; k < D; ++k){
				sum += abs(X[i][k]-X[j][k]) * abs(X[i][k]-X[j][k]);
			}
			// cout << (int)sqrt(sum)*(int)sqrt(sum) << " " << sum << endl;
			if((int)sqrt(sum)*(int)sqrt(sum) == sum) cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}



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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll n;
    string s;
    cin>>n>>s;

    ll l=0;
    rep(i,1,n) if(s[i]=='E') l++;

    ll ans = l;
    rep(i,1,n){
        if(s[i]=='E') l--;
        if(s[i-1]=='W') l++;
        ans=min(ans,l);
    }

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


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int MAXN = 110, MAXV = 110105;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int N, W;
int w[MAXN], v[MAXN];
void input() {
  cin >> N >> W;
  rep(i, 0, N - 1) { cin >> w[i] >> v[i]; }
}
int dp[MAXN + 3][MAXV + 3];
void solve() {
  rep(i, 0, MAXN - 1) rep(j, 0, MAXV - 1) { dp[i][j] = INF; }
  dp[0][0] = 0;

  rep(i, 0, N - 1) rep(j, 0, MAXV - 1) {
    if (j - v[i] >= 0) {
      chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
    }
    chmin(dp[i + 1][j], dp[i][j]);
  }

  int ans;
  rep(i, 0, MAXV - 1) {
    if (dp[N][i] <= W) {
      ans = i;
    }
  }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  char grid[100][100];
  
  for (int i = 0; i < 50; i++)
    for (int j = 0; j < 100; j++)
      grid[i][j] = '#';
  for (int i = 50; i < 100; i++)
    for (int j = 0; j < 100; j++)
      grid[i][j] = '.';
  
  for(int i = 0; i < a-1; i++)
    grid[i/50*2][i%50*2] = '.';
  for(int i = 0; i < b-1; i++)
    grid[i/50*2+51][i%50*2] = '#';
  
  cout << 100 << " " << 100 <<endl;
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < 100; j++){
      cout << grid[i][j];
    }
    cout << endl;
  }
}
    

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

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


using namespace std;

int w(int b, int a[]) {
	if (b == 4)return 0;
}


int main() {

	int a;
	int n = 3;
	int t = 1 << n;
	string p;
	cin >> p;
	int b[5] = {};
	for (int i = 0; i < p.size(); i++) {
		b[i] = p[i] - '0';
	}
	
	for (int i = 0; i < t; i++) {
		int r = b[0];
		vector<char>y;
		for (int j = 0; j < 3; j++) {
			if (i & 1 << j) {
				r += b[j + 1]; y.push_back('+');
			}
			else { r -= b[j + 1]; y.push_back('-'); }
		}
		if (r == 7) {
			cout << b[0];
			for (int j = 0; j < 3; j++) {
				cout << y[j] << b[j + 1];
			}
			cout <<"=7"<< endl;
			return 0;
		}
	}

	

	return 0;

}




Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n = input()
    if n == "A":
        print("T")
    elif n == "C":
        print("G")
    elif n == "G":
        print("C")
    else:
        print("A")
    return

#B
def B():
    s = S()
    ans = 0
    n = len(s)
    for i in range(n):
        for j in range(i,n):
            f = 1
            for k in range(i,j+1):
                if s[k] not in list("AGCT"):f = 0
            if f:
                ans = max(ans,j+1-i)
    print(ans)
#C
def C():
    n,q = LI()

    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 39152
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc158/submissions/10645244 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), p = scanner.nextInt();
			char[] s = scanner.next().toCharArray();
			// 文字列を数字に変換
			int[] s2 = new int[n];
			IntStream.range(0, n).forEach(i -> s2[i] = s[i] - '0');
			int[] m = new int[p];
			long answer = 0L;
			if ((2 == p) || (5 == p)) {
				answer = IntStream.range(0, n).mapToLong(i -> (0 == s2[i] % p) ? i + 1 : 0L).sum();
			} else {
				int now = 0;
				int digit = 1;
				m[0] = 1;
				for (int i = n - 1; i >= 0; i--) {
					now += s2[i] * digit;
					now %= p;
					answer += m[now];
					m[now]++;
					digit *= 10;
					digit %= p;
				}
			}
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 30016
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<ll> a(N);
	rep(i,N)cin >> a[i];
	int now = 1;
	int cnt = 0;
	for(int i=0;i<N;i++){
		if(a[i] == now){
			cnt ++;
			now ++;
		}
	}
	if(now == 1)cout << -1 << endl;
	else cout << N - cnt << endl;
}

Measured memory_bytes: 1792
/// Zhupengfei 2018
/// Hereby declare: this program is in public domain.

/// Solution for problem:

#include <bits/stdc++.h>

#ifdef LOCAL
#pragma GCC poison printf // To avoid fastio problems
#pragma GCC poison scanf
#endif

using namespace std;

int a[5001];
bool dp[5001];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n, K;
	cin>>n>>K;
	long long sum=0;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		sum+=a[i];
	}
	sort(a, a+n);
	memset(dp, false, sizeof(dp));
	dp[0]=true;
	int ans=0;
	for(int i=n-1;i>=0;i--) {
		bool flag=false;
		for(int j=0;j<K;j++){
			if(dp[j] && j+sum>=K) {
				flag=true;
				break;
			}
		}
		if(!flag) ans++;
		sum-=a[i];
		for(int j=K-1;j>=a[i];j--) dp[j]|=dp[j-a[i]];
	}
	cout<<ans<<endl;
	return 0;
}



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

int main(void){
  int N;
  scanf("%d",&N);
  int i,j;
  int sosu[500]={
    2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,
    103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,
    199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,
    313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,
    433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,
    563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,
    673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,
    811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,
    941,947,953,967,971,977,983,991,997
  };
  int rog;
  int box[169] = {0};
  for(i=2;i<=N;i++){
    rog = i;
    loop:
    for(j=0;j<168;j++){
      if(i%sosu[j] != 0){
        continue;
      }else if(i % sosu[j] == 0 && i / sosu[j] == 1){
        box[j]++;
        break;
      }else i = i / sosu[j]; box[j]++; goto loop;
    }
    i = rog;
  }
  long sum = 1;
  for(i=0;i<=168;i++){
    sum *= box[i] + 1;
    sum = sum % 1000000007;
  }

  printf("%ld\n",sum);
}


Measured memory_bytes: 128
#!/usr/bin/env python3

def main():
    n = int(input())
    s = input()
    x = 0
    xmin = 0
    for c in s:
        x += (1 if c == "(" else -1)
        xmin = min(xmin, x)
    l = max(-xmin, 0)
    r = x + l
    print("(" * l + s + ")" * r)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int m;
    cin >> m;
    cout << (48 - m) << endl;
    return 0;
}


Measured memory_bytes: 256
/// @file

#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

namespace {

bool run(std::istream& is, std::ostream& os);
}  // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception& e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

/// @brief 実行処理
bool run(std::istream& is, std::ostream& os)
{
  int n;
  int m;
  is >> n >> m;

  // 県番号、 誕生年
  std::vector<std::pair<int, int>> cityList(m);
  for (auto& v: cityList) is >> v.first >> v.second;

  // 県番号、 誕生年、 市番号
  std::map<int, std::map<int, int>> prefList;
  for (std::size_t idx = 0; idx < cityList.size(); ++idx) {
    const auto& city = cityList[idx];
    prefList[city.first][city.second] = idx;
  }

  // map によって並び替えられた順に市番号を振っていく
  std::vector<std::string> cityNumbers(m);
  for (const auto& pref: prefList) {
    int num(1);
    for (const auto& city: pref.second) {
      std::ostringstream ss;
      ss << std::setw(6) << std::setfill('0') << pref.first;
      const std::string PREF_STR(ss.str());

      ss.str("");
      ss.clear(std::stringstream::goodbit);

      ss << std::setw(6) << std::setfill('0') << num;
      const std::string CITY_STR(ss.str());

      cityNumbers[city.second] = PREF_STR + CITY_STR;

      ++num;
    }
  }

  // 出力
  for (const auto& v: cityNumbers) os << v << "\n";

  return true;
}
}  // unnamed namespace


Measured memory_bytes: 17152
from itertools import combinations

n, x, y = map(int, input().split())

cnt = [0] * n
for i, j in combinations(range(1, n + 1), 2):
    dist = min(abs(j - i), abs(i - x) + abs(j - y) + 1,
               abs(i - y) + abs(j - x) + 1)
    cnt[dist] += 1

for i in range(1, n):
    print(cnt[i])


Measured memory_bytes: 47836
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    ll n; cin >> n;
    ll a[n];
    map<ll, int> mp;
    vector<ll> v;
    ll cnt = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        if(mp[a[i]] == 0) v.push_back(a[i]);
        mp[a[i]]++;
    }
    ll m = v.size();
    for(ll i = 0; i < m; i++){
        if(mp[v[i]] < v[i]) cnt += mp[v[i]];
        else if(mp[v[i]] > v[i]) cnt += mp[v[i]] - v[i];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,a,b;
  long long ans=0;
  cin>>n>>a>>b;
   ans=(n/(a+b))*a;
  long long x=n%(a+b);
  if(x>=a)
    ans+=a;
  else
    ans+=x;
  cout<<ans;
}

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

int main()
{
    int N, K, Q;
    std::cin >> N >> K >> Q;

    std::vector<int> score;
    score.resize(N);
    std::fill(score.begin(), score.end(), 0);

    for (int i = 0; i < Q; ++i)
    {
        int A;
        std::cin >> A;
        ++score[A - 1];
    }

    for (int i = 0; i < N; ++i)
    {
        if (score[i] <= (Q - K))
        {
            std::cout << "No\n";
        }
        else {
            std::cout << "Yes\n";
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int K,A[100010];
	scanf("%d", &K);
	for (int i = 1; i <= K; i++)
	{
		scanf("%d", &A[i]);
	}
	long long left = 2, right = 2;
	for (int i = K; i > 0; i--)
	{
		left = ((left-1) / A[i] + 1)*A[i];
		right = (right / A[i] + 1)*A[i] - 1;
	}
	if (left > right)
		printf("-1\n");
	else
		printf("%lld %lld\n", left, right);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional> 
#include <vector>

using namespace std;

int main(){

    int x,y,z;
    cin >> x;
    cin >> y;
    cin >> z; 

    cout << (x-z)/(y+z);

    return 0;
}

Measured memory_bytes: 256
const fs = require('fs');

function main(input) {
  var a = input.split('\n')[1].split(' ');
  a = a.map((n) => parseInt(n, 10));
  
  var cnt = 0;
  while (a.every((n) => (n % 2) === 0)) {
    cnt++;
    a = a.map((n) => n / 2);
  }
  console.log(cnt);
}

input = fs.readFileSync('/dev/stdin', 'utf8');
main(input);

Measured memory_bytes: 7500
import sys
def input(): return sys.stdin.readline().strip()
INF = 10**18

def main():
    N, M = map(int, input().split())
    repn = [[] for _ in range(N)]
    edge = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        repn[a - 1].append((c, b - 1))
        repn[b - 1].append((c, a - 1))
        edge.append((a - 1, b - 1, c))

    # 全点間最短距離をワーシャルフロイドで求める
    dist = [[INF] * N for _ in range(N)]
    for i in range(N): dist[i][i] = 0
    for i in range(N):
        for cost, j in repn[i]: dist[i][j] = cost

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    # 辺を一つずつ見て余分かどうか判定する
    ans = 0
    for a, b, c in edge:
        no_need = True
        for i in range(N):
            for j in range(N):
                if dist[i][j] > dist[i][a] + (c - 1) + dist[b][j]:
                    no_need = False
                    break
        if no_need: ans += 1
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 74324
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b && b < c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3096
#include "bits/stdc++.h"

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int A,B;
	cin >> A>>B;
	if (A < 10 & B < 10) {
		print(A*B);
	}
	else {
		print(-1);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    ll N, M;
    cin>>N>>M;
    vector<ll> L(M), R(M), D(M);
    vector<vector<pair<ll, ll>>> Way(N);
    rep(i, M){
        cin>>L[i]>>R[i]>>D[i];
        L[i]--; R[i]--;
        Way[L[i]].push_back(make_pair(R[i], D[i]));
        Way[R[i]].push_back(make_pair(L[i], -1*D[i]));
    }

    vector<ll> Used(N, -1*INF);
    rep(i, N){
        if(Way[i].empty())continue;
        if(Used[i]!=-1*INF)continue;
        Used[i]=0;
        ll Sz=Way[i].size();
        queue<ll> Q;
        rep(j, Sz){
            Used[Way[i][j].first]=Way[i][j].second;
            Q.push(Way[i][j].first);
        }
        while(!(Q.empty())){
            ll P=Q.front();
            Q.pop();
            ll SzSz=Way[P].size();
            rep(j, SzSz){
                if(Used[Way[P][j].first]!=-1*INF){
                  	//cout<<P<<" "<<Used[P]<<" "<<Way[P][j].first<<" "<<Used[Used[P]+Way[P][j].second]<<endl;
                    if(Used[Way[P][j].first]!=Used[P]+Way[P][j].second){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
                else{
                    Used[Way[P][j].first]=Used[P]+Way[P][j].second;
                    Q.push(Way[P][j].first);
                }
            }
            
        }

    }
  	/*rep(i, N){
  		cout<<Used[i]<<endl;
    }*/
  
    cout<<"Yes"<<endl;

}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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; }

ll pow5(ll x) {
	ll t = 1;
	rep(i,5) t *= x;
	return t;
}

int main() {
	ll X;
	cin >> X;
	for(ll i = 0; i <= 1000; i++) {
		for(ll j = -1000; j < i; j++) {
			if(pow5(i) - pow5(j) == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}

  return 0;
}


Measured memory_bytes: 3600
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: (x * y) / math.gcd(x, y)
lcm = lambda x, y: x * y // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= (A-1) // C
    cnt -= (A-1) // D

    cnt -= B // lcm(C, D)
    cnt += (A-1) // lcm(C, D)
    print(E - cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5156
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
const int MOD=1e9+7;
const double eps=1e-8;
typedef long long ll;
//orz yht
using namespace std;
int n,m,f[105][105];
char a[105][105];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	scanf(" %c",a[i]+j);
	memset(f,INF,sizeof f);
	f[1][1]=a[1][1]!='.';
	for(int i=1;i<=n;i++)
	for(int j=1+(i==1);j<=m;j++)
	f[i][j]=min(f[i][j-1]+(a[i][j]=='#'&&a[i][j-1]=='.'),f[i-1][j]+(a[i][j]=='#'&&a[i-1][j]=='.'));
	cout<<f[n][m];
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))

C = Counter(D)

for t in T:
    if C[t]:
        C[t] -= 1
    else:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 45000
//0/1_knapsack having optimal substructure and overlapping sub-problems properties
//Let us first solve it using bottom up approach
//Then try for memoization
#include<stdio.h>
typedef long long ll;
ll v[105],w[105];
ll max(ll a,ll b)
{
    return (a>b?a:b);
}
void testcase()
{
    int n,W;

    scanf("%d %d",&n,&W);
    for(int i=1;i<=n;i++)
    {
        scanf("%d %lld",&w[i],&v[i]);
    }
    ll knap[n+2][W+2];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(j==0||i==0)
                knap[i][j]=0;
            else if(w[i]>j)
                knap[i][j]=knap[i-1][j];
            else
                knap[i][j]=max(v[i]+knap[i-1][j-w[i]],knap[i-1][j]);
        }
    }
    printf("%lld\n",knap[n][W]);
}
int main()
{
    testcase();
    return 0;
}


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

int score[5], total = 0, ave;
int main()
{
  for(int i = 0; i < 5; i++) cin >> score[i];
  for(int i = 0; i < 5; i++) total += (score[i] < 40) ? 40 : score[i];
  ave = total / 5;
  cout << ave << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int h,a,i,n=0,sum=0;
   cin>>h>>a;
   for(i=1;i<=a;i++)
   {
       cin>>n;
       sum+=n;
   }
   if(sum>=h)printf("Yes\n");
   else
    printf("No\n");
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x/11*2;
    x%=11;
    if(x>=7)ans+=2;
    else if(x)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int m[][] = new int[n][n];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					m[i][j] = sc.nextInt();
				}
			}
			int h[][] = new int[n][n];
			for (int i = 0; i < n; i++) {
				int min = Integer.MAX_VALUE;
				for (int j = 0; j < n; j++) {
					if (m[i][j] < min) {
						min = m[i][j];
					}
				}
				for (int j = 0; j < n; j++) {
					if (m[i][j] == min)
						h[i][j]++;
				}
			}
			for (int i = 0; i < n; i++) {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if (m[j][i] > max) {
						max = m[j][i];
					}
				}
				for (int j = 0; j < n; j++) {
					if (m[j][i] == max)
						h[j][i]++;
				}
			}
			int ans = 0;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (h[i][j] == 2)
						ans = Math.max(ans, m[i][j]);
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    print(min(A,B)+min(C,D))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
// Created by js0805
#include <bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<string>
#define ll long long
#define fri(a,b) for(ll i=a;i<b;i++)
#define frj(a,b) for(ll j=a;j<b;j++)
#define prDouble(x) cout << fixed << setprecision(10) <<x
#define mod 1000000007
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
void solve() {
    int n, m;
    cin >> n >> m;
    char a[n][m];
    fri(0, n) {
        frj(0, m) {
            cin >> a[i][j];
        }
    }
    int dp[n][m];
    memset(dp, 0, sizeof dp);
    fri(0, n) {
        if (a[i][0] == '#')
            break;
        else
            dp[i][0] = 1;
    }
    fri(0, n) {
        if (a[0][i] == '#')
            break;
        else
            dp[0][i] = 1;
    }
    fri(1, n) {
        frj(1, m) {
            if (a[i][j] == '#')
                dp[i][j] = 0;
            else {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }
    }
    cout << dp[n - 1][m - 1];


}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 8492
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
#include <bits/c++io.h>
#include <cmath>
#define maxn 100000+5
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
 int n,k;
    ll num,sum=0;
    vector<ll>H;
    cin>>n>>k;
    for (int i=0;i<n;i++)
    {
        cin>>num;
        H.push_back(num);
    }
    sort(H.begin(),H.end());
    for (int i=0;i<n-k;i++)
    {
         sum+=H[i];
    }
    cout<<sum;
 }


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

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    cin.tie(NULL);
    ios::sync_with_stdio(0);
    
    long n; cin >> n;
    long arr[100010];
    memset(arr, 0, sizeof arr);
    
    for(int i = 0; i < n; i++){
        long aux; cin >> aux;
        arr[i] = aux;
    }
    
    long contA = 0, contB = 0, sumB = 0, sumA = 0;
    
    if(arr[0] < 0){
        contB += abs(arr[0]) + 1;
        sumB = 1;     
        sumA = arr[0];       
    }else if(arr[0] > 0){
        contA += abs(arr[0]) + 1;
        sumA = -1;
        sumB = arr[0];     
    }
    if(arr[0] == 0){
        contB++;
        contA++;
        sumA = -1;
        sumB = 1;
    }
    //cout << "SUM a "<<sumA<<" SUM b "<<sumB<<'\n';
    //cout <<"A "<< contA <<" B "<<contB<<'\n';
    for(int i = 1; i < n; i++){
        if(sumA > 0){
            sumA += arr[i];
            if(sumA >= 0){
                contA += sumA + 1;
                sumA = -1;
            }
        }else if(sumA < 0){
            sumA += arr[i];
            if(sumA <= 0){
                contA += abs(sumA) + 1;
                sumA = 1;                            
            }
        }
        
        if(sumB > 0){
            sumB += arr[i];
            if(sumB >= 0){
                contB += sumB + 1;
                sumB = -1;
            }
        }else if(sumB < 0){
            sumB += arr[i];
            if(sumB <= 0){
                contB += abs(sumB) + 1;
                sumB = 1;
            }
        }
        //cout << "SUM a "<<sumA<<" SUM b "<<sumB<<'\n';
        //cout <<"A "<< contA <<" B "<<contB<<'\n';
    }
    
    cout << min(contA, contB)<<'\n';
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		
		String s=sc.next();
		//int a=sc.nextInt();
		//int b=sc.nextInt();
		//int c=sc.nextInt();
		int l=s.length();
		int p[]=new int[l-2];
		for(int i=0;i<=l-3;i++) {
			p[i]=Math.abs(753-Integer.parseInt(s.substring(i,i+3)));
		}
		Arrays.sort(p);
		System.out.println(p[0]);
	
		
	}	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 22996
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  DP := make([][]int, N + 1)
  for i := range DP { DP[i] = make([]int, 3) }
  DP[1][0], DP[2][0] = A[0], A[1]
  for i := 3; i <= N; i++ {
    DP[i][0] = DP[i - 2][0] + A[i - 1]
    if i > 3 { DP[i][1] = DP[i - 3][0] + A[i - 1] }
    if i > 4 { DP[i][1] = MaxInt(DP[i - 2][1] + A[i - 1], DP[i][1]) }
    if N % 2 == 1 && i % 2 == 1 {
      if i == 3 { DP[i][1] = A[2] }
      if i > 4 { DP[i][1] = MaxInt(DP[i - 4][0] + A[i - 1], DP[i][1]) }
      if i > 6 { DP[i][2] = DP[i - 3][1] + A[i - 1] }
      if i > 8 { DP[i][2] = MaxInt(DP[i - 2][2] + A[i - 1], DP[i][2]) }
    }
  }
  var ans int
  if N % 2 == 0 {
    ans = MaxInt(DP[N][0], DP[N][1], DP[N - 1][0])
  } else {
    ans = MaxInt(DP[N][1], DP[N][2], DP[N - 1][0], DP[N - 1][1], DP[N - 2][0])
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 21188
#include<stdio.h>
long long int LCM(long long int x,long long int y);
long long int GCD(long long int x,long long int y);
int main(){
    long long int a,b;
    long long int c,d;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
   // long int count=0;
    //long int i;
    long long int A,B;
    A = (a-1) - ((a-1)/c + (a-1)/d - (a-1)/LCM(c,d));
    B = b - (b/c +b/d - b/LCM(c,d));
  //  printf("%lld\n",A);
   // printf("%lld\n",B);
    printf("%lld\n",B-A);
    return 0;
}
long long int GCD(long long int x,long long int y){
long long int r= x%y;
while(r!= 0){/*ユークリッドの互除法*/
x=y;
y=r;
r=x%y;
}
return y;
}

long long int LCM(long long int x,long long int y){
return ((x*y)/GCD(x,y)); //最小公倍数
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> v;
    rep(i, n) {
        int a; cin >> a;
        rep(j, a) {
            v.push_back(i + 1);
        }
    }
    vector<vector<int>> ans(h, vector<int>(w));
    int y = 0, x = 0;
    rep(i, v.size()) {
        if(i > 0 && i % w == 0) {
            x = 0; 
            y++;
        }
        ans[y][x] = v[i];
        x++;
    }
    rep(i, h) {
        if(i % 2 == 1) {
            reverse(ALL(ans[i]));
        }
    }

    rep(i, h) {
        rep(j, w) cout << ans[i][j] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define Would
#define you
#define please

int sosuu(int A) {
	if (A <= 1) return 0;
	int saidai = pow(A, 0.5);
	for (int i = 2; i <= saidai; i++) {
		if (A % i == 0) return 0;
	}
	return 1;
}

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;

	int suuretu[56] = {};
	int iretakazu = 0;

	for (int i = 3; i <= 55555; i += 10) {
		if (sosuu(i) == 1) {
			int dame = 0;
			if (iretakazu >= 4) {
				rep1(i1, iretakazu) {
					for (int i2 = i1 + 1; i2 <= iretakazu; i2++) {
						for (int i3 = i2 + 1; i3 <= iretakazu; i3++) {
							for (int i4 = i3 + 1; i4 <= iretakazu; i4++) {
								int goukei = suuretu[i1] + suuretu[i2] + suuretu[i3] + suuretu[i4] + i;
								if (sosuu(goukei) == 1) dame = 1;
							}
						}
					}
				}
			}
			if (dame == 0) {
				suuretu[iretakazu + 1] = i;
				iretakazu++;
			}
		}
		if (iretakazu == N + 1) break;
	}

	rep1(i, N) cout << suuretu[i] << " ";
	cout << "\n";
	Would you please return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int m; cin >> m;
cout << 48 - m << endl;
}


Measured memory_bytes: 256