akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    string c = t.substr(0,s.size());
    if (s==c) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,input,total=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&input);
		if(input%2==1)
			total++;
	}
	if(total%2==0)
		printf("YES\n");
	else
		printf("NO\n");
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>
#include<climits>

typedef int Node;
class CompleteBinaryTree {
    Node* Tree;
    Node nil = -2000000001;
    int size;
    
    public :CompleteBinaryTree(int c){
        size = c;
        Tree = new Node[size+1];
        for(int i =1;i <= c;++i) Tree[i] = nil;
    }
    
    void AddChild(int c, int n) {
            Tree[n] = c;
	}
    
    int GetParent(int n){
        return (n/2) != 0 ? Tree[n/2]:nil;
    }
    
    int GetRightChild(int n){
        return (2*n+1) <= size ? Tree[2*n+1]:nil;
    }

    int GetLeftChild(int n){
        return (2*n) <= size ? Tree[2*n]:nil;
    }
    
    void print(int n){
        printf("node %d: key = %d, ",n,Tree[n]);
        if(GetParent(n) != nil) printf("parent key = %d, ",GetParent(n));
        if(GetLeftChild(n) != nil) printf("left key = %d, ",GetLeftChild(n));
        if(GetRightChild(n) != nil) printf("right key = %d, ",GetRightChild(n));
        printf("\n"); 
    }
};

int main(){
    int n,k;
    CompleteBinaryTree *cbt;
    scanf("%d",&n);
    cbt = new CompleteBinaryTree(n);
    for(int i = 1;i <= n;++i){
        scanf("%d",&k);
	    cbt -> AddChild(k,i);
    }
    for(int i = 1;i <= n;++i) cbt -> print(i);
    
}





Measured memory_bytes: 3212
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll _pow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; b >> i; i++) {
		if ((b >> i) & 1) ans *= a;
		a *= a;
	}
	return ans;
}
char inp[100];
int main(void) {
	scanf("%s", inp);
	for (int i = 0; i < 3; i++) {
		if (inp[i] == inp[i + 1]) {
			printf("Bad\n");
			return 0;
		}
	}
	printf("Good\n");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int W, a, b; cin >> W >> a >> b;
	int ans = max(0, max(b - (a + W), a - (b + W)));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
typedef struct Node{
    int id;
    struct Node *left;
    struct Node *right;
} Node;

Node *insert_iter(Node *subtree, Node *z){
    if(subtree == nullptr) return z;
    if(z->id <= subtree->id) subtree->left = insert_iter(subtree->left, z);
    else subtree->right = insert_iter(subtree->right, z);
    return subtree;
}

void insert(Node **root, Node *z){
    *root = insert_iter(*root, z);
}

void print_inorder(Node *node){
    if(node == nullptr) return;
    print_inorder(node->left);
    std::printf(" %d", node->id);
    print_inorder(node->right);
}

void print_preorder(Node *node){
    if(node == nullptr) return;
    std::printf(" %d", node->id);
    print_preorder(node->left);
    print_preorder(node->right);
}

int main(){
    int n;
    std::scanf("%d", &n);
    std::vector<Node> treeArray(n);
    int numNodes = 0;
    Node *root = nullptr;
    for(int i = 0; i < n; ++i){
        char op[8];
        std::scanf("%s", op);
        if(std::strncmp(op, "insert", 6) == 0){
            Node node;
            std::scanf("%d", &node.id);
            node.left = nullptr;
            node.right = nullptr;
            treeArray[numNodes] = node;
            insert(&root, &treeArray[numNodes++]);
        } else if(std::strncmp(op, "print", 5) == 0){
            print_inorder(root);
            std::printf("\n");
            print_preorder(root);
            std::printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 13916
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {
	os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T,class U> ostream& operator<<(ostream &os, const tuple<S,T,U> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class S, class T,class U,class V> ostream& operator<<(ostream &os, const tuple<S,T,U,V> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
#else
#define out
#endif
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	ll x,y;
	cin>>x>>y;
	if(x%y==0){
		cout<<-1<<endl;
	}else{
		cout<<x<<endl;
	}
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	if (n / 10 == 9)
		cout << "Yes" << endl;
	else if (n % 10 == 9)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] arg)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] div = str.split(" ");
		int a =  Integer.parseInt(div[0]);
		int b =  Integer.parseInt(div[1]);
		int c =  Integer.parseInt(div[2]);

		if ((a < b) &&(b < c)){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}	
}

Measured memory_bytes: 16908
n = int(input())
w = [input() for i in range(n)]
ans = "Yes"
for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        ans = "No"
w.sort()
for i in range(n-1):
    if w[i]==w[i+1]:
        ans = "No"
print(ans)

Measured memory_bytes: 62444
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();

        double tanTheta;
        if (a * a * b / 2 < x) {
            tanTheta = 2 * (a * a * b - x) / (double)(a * a * a);
        } else {
            tanTheta = (a * b * b) / (double)(2 * x);
        }
        double theta = Math.toDegrees(Math.atan(tanTheta));

        System.out.println(theta);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

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

using namespace std;

int main()
{
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> cor(n, 0);
  rep(i, q)
  {
    int a;
    cin >> a; 
    a--;
    ++cor[a];
  }
  rep(i, n)
  {
    if(0 < k - (q - cor[i]))
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
# モジュールのインポート
import sys

# 標準入力を取得
S = input()
T = input()

# 求解処理


def get_match_count(s1: str, s2: str) -> int:
    match_count = 0
    for c1, c2 in zip(s1, s2):
        if c1 == c2:
            match_count += 1
    return match_count


N = len(S)
M = len(T)
ans = sys.maxsize
for i in range(N - M + 1):
    ans = min(ans, M - get_match_count(S[i:i + M], T))

# 結果出力
print(ans)


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

using namespace std;

const long mod=1000000007;

int main(){
  long n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  
  bool flag;
  long num,res;
  
  if(s[0]==t[0]) {
    flag=true;
    num=1;
    res=3;
  }
  else {
   flag=false;
    num=2;
    res=6;
  }
  
  while(num<s.size()){
   if(s[num]==t[num]){
    num++;
    if(flag) res*=2;
    flag=true;
   }
   else {
    num+=2;
    if(flag) res*=2;
    else res*=3;
    flag=false; 
   }
   res%=mod;
  }
    
 cout << res << endl;
}

Measured memory_bytes: 256
data = [0] * 1000
data[0] = 111
data[1] = 1111

idx = -1
def alloc():
	global idx
	idx += 1
	return idx
ans = []
def plus(i,j,k):
	data[k] = data[i] + data[j]
	ans.append(('+', i, j, k))
def lower(i,j,k):
	data[k] = int(data[i] < data[j])
	ans.append(('<', i, j, k))
def leq(i,j,k):
	lower(j, i, k)
	lower(k, one, k)

A = alloc()
B = alloc()
C = alloc()
zero = alloc()
one = alloc()

# 1 を作る
plus(A, B, one)
lower(zero, one, one)

# 2 ** i を作る
pow2 = [alloc() for i in range(30)]
plus(one, zero, pow2[0])
for i in range(29):
	plus(pow2[i], pow2[i], pow2[i + 1])

# a を 2 進数展開
a = [alloc() for i in range(30)]
x = alloc()
A_ = alloc() # i bit 目まで見たときの A
for i in reversed(range(30)):
	plus(A_, pow2[i], x)
	leq(x, A, a[i])
	plus(a[i], zero, x)
	for j in range(i):
		plus(x, x, x)
	plus(A_, x, A_)

# b を 2 進数展開
b = [alloc() for i in range(30)]
B_ = alloc() # i bit 目まで見たときの B
for i in reversed(range(30)):
	plus(B_, pow2[i], x)
	leq(x, B, b[i])
	plus(b[i], zero, x)
	for j in range(i):
		plus(x, x, x)
	plus(B_, x, B_)

# bit ごとに掛け算して a[2] に足す
for i in range(30):
	for j in range(30):
		plus(a[i], b[j], x)
		lower(one, x, x)
		for k in range(i + j):
			plus(x, x, x)
		plus(C, x, C)

print(len(ans))
for a, b, c, d in ans:
	print(a, b, c, d)

Measured memory_bytes: 11708
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int N, W;
  cin >> N >> W;
  vvi dp(N + 1, vi(W + 1));
  vi v(N), w(N);
  rep(i, N) cin >> v[i] >> w[i];
  rep(i, N) rep(j, W + 1) {
    dp[i + 1][j] = dp[i][j];
    if (j >= w[i]) cmax(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 10776
# 累積計算

from itertools import product

if __name__ == "__main__":
    while True:
        try:
            col = 0
            n = int(input())
            #print(n)
            if n > 36:
                print(0)
            else:
                for a, b, c, d in product(range(0, 10), repeat=4):
                    if a + b + c + d == n:
                        col += 1
                    else:
                        pass
                print(col)

        except EOFError:
            break  # escape from while loop

pass
#

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

int main()
{
    int n, max = 0;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) {
        if (a[i] < max) {
            cout << "No" << endl;
            return 0;
        }
        if (a[i] >= a[i + 1]) {
            a[i]--;
            if (a[i] > max) max = a[i];
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC125 {
	class ABC125_B {
		static void Main(string[] args) {
			var N = int.Parse(Console.ReadLine());
			var V = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var C = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var sub = new List<int>();
			for(int i=0; i<N; i++) { sub.Add(V[i] - C[i]); }
			Console.WriteLine(sub.Where(n => n > 0).Sum());
		}
	}
}


Measured memory_bytes: 13396
#pragma GCC optimize("-Ofast")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define MOD ((long long)1e9+7)

//#define TEST

/* 10のk乗を13で割った余りを求める */
int ModPower(int k){
    if (k == 0) return 1;
    int t = ModPower(k / 2); // 10のk/2乗の場合を計算
    if (k & 1){ // kが奇数の場合
        return t * t * 10 % 13;
    }
    return t * t % 13; // kが偶数の場合
}

signed main(){
    /* 入力の受け取り */
    string s;
    cin >> s;
    int n = s.length(); // sの桁数

    /*
        dp[i][j] : 上からi桁目までを見て、余りjをつくる作り方
    というDPを行う。
    初期条件
        dp[0][0] = 1
        それ以外は0
    遷移
        sのi+1桁目がk(=0,1,...,9)なら
            dp[i][j] -> dp[i+1][(j+k*ModPower(n-i-1))%13]
        に移る。
     */
    // dpテーブルの作成
    ll** dp = new ll*[n+1];
    for (int i = 0;i <= n;++i)
        dp[i] = new ll[13];
    // dpテーブルの初期化
    for (int i = 0;i <= n;++i)
        for (int j = 0;j < 13;++j)
            dp[i][j] = 0;
    dp[0][0] = 1;
    // dpテーブルの更新
    for (int i = 0;i < n;++i){
        for (int j = 0;j < 13;++j){
            if (s[i] != '?'){
                int k = s[i] - '0';
                int j_ = (j + k * ModPower(n-i-1)) % 13; 
                dp[i+1][j_] += dp[i][j];
                dp[i+1][j_] %= MOD;
            }
            else {
                for (int k = 0;k < 10;++k){
                    int j_ = (j + k * ModPower(n-i-1)) % 13; 
                    dp[i+1][j_] += dp[i][j];
                    dp[i+1][j_] %= MOD;
                }
            }
        }
    }
    // dpテーブルの出力
#ifdef TEST
    for (int i = 0;i <= n;i++){
        for (int j = 0;j < 13;j++)
            cout << dp[i][j] << " ";
        cout << endl;
    }
#endif
    // 答えの出力
    cout << dp[n][5] << endl;

    /* メモリの開放、プログラムの終了 */
    for (int i = 0;i <= n;++i)
        delete[] dp[i];
    delete[] dp;
    return 0;
}

Measured memory_bytes: 12032
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define fi first
#define se second

#ifdef _DEBUG
ifstream ifs("input.txt");
#define input ifs
#else
#define input cin
#endif
#define DEBUG(x) cout<<#x<<": "<<x<<endl

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

    int n;
    ll a = 1, t = 1;
    input >> n;
    rep(i, n){
        ll x, y;
        input >> x >> y;
        ll k = max((a + x - 1) / x, (t + y - 1) / y);
        a = k * x;
        t = k * y;
    }
    cout << a + t << endl;
    return 0;
}



Measured memory_bytes: 764
#include<stdio.h>
int n,c;
void F(int*a,int*b)
{
	int ab,at,bb,bt;
	ab=n/2;at=n-1;bb=0;bt=ab-1;
	int i=0,t;
	for(;i<n;)
	{
		if((t=ab+c-1)>at)t=at;
		for(;ab<=t;++ab)b[i++]=a[ab];
		if((t=bb+c-1)>bt)t=bt;
		for(;bb<=t;++bb)b[i++]=a[bb];
	}
}
int main()
{
	int r,i,a[2][50];
	while(scanf("%d%d",&n,&r)>1)
	{
		for(i=0;i<n;++i)a[0][i]=i;
		for(i=0;r--;i=!i)
		{
			scanf("%d",&c);
			F(a[i],a[!i]);
		}
		printf("%d\n",a[i][n-1]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h> 
    using namespace std; 
    using namespace std::chrono; 
    #define ll long long int 
     
    int main() 
    { 
    	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
    	
    	ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll n;
        cin>>n;
        map<string,ll>m;
        ll max1=-(INT_MAX);
        while(n--){
                string s;
                cin>>s;
                m[s]++;
                max1=max(max1,m[s]);
        }
        vector<string>v;
        for(auto itr=m.begin();itr!=m.end();itr++){
           if(itr->second==max1)
           v.push_back(itr->first);
        }
        sort(v.begin(),v.end());
        for(auto x: v)
            cout<<x<<endl;
    	return 0; 
    } 
     


Measured memory_bytes: 25584
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 100005
#define MOD 1000000007


/*nまでの素数を列挙して配列に保持*/
vector<ll> Eratosthenes(ll n,vector<ll>& arr){
    
    for(ll i = 0; i < n;i++){
        arr[i] = 1;
    }
    arr[0] = arr[1] = 0;
    for(ll i = 2; i < sqrt(n); i++){
        if(arr[i]){
            for(ll j = 0; i * (j + 2) < n; j++){
                arr[i *(j + 2)] = 0;
            }
        }
    }
    return arr;
}


int main(){

    ll q;
    cin >> q;
    vector<ll> a(ARRAY_MAX,0),b(ARRAY_MAX,0);
    a = Eratosthenes(ARRAY_MAX,a);
   
    for(int i = 3;i <= a.size();i+=2){
        if(a[i] && a[(i+1)/2]){
            b[i] = 1;
        }
    }
      
    for(int i = 0;i <= b.size()-1;i++){
        b[i+1]+=b[i];
    }

    ll l,r;
    REP(i,q){
        cin >> l >> r;
        cout << b[r] - b[l-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<math.h>
struct node{
  double x,y;
};
void koch(int n,struct node a,struct node b){
  if(n==0)return;
  struct node s,t,u;
  double th=M_PI/3.0;
  s.x=((2.0*a.x)+b.x)/3.0;
  s.y=((2.0*a.y)+b.y)/3.0;
  t.x=(a.x+(2.0*b.x))/3.0;
  t.y=(a.y+(2.0*b.y))/3.0;
  u.x=((t.x-s.x)*cos(th))-((t.y-s.y)*sin(th))+s.x;
  u.y=((t.x-s.x)*sin(th))+((t.y-s.y)*cos(th))+s.y;
  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}
void in(){
  struct node a,b;
  int n;
  scanf("%d",&n);
  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
}
int main(){
  in();
  return 0;
}



Measured memory_bytes: 2052
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    for j in range(-1, 2):
        if a[i] + j in d.keys():
            d[a[i] + j] += 1
        else:
            d[a[i] + j] = 1
print(max(d.values()))


Measured memory_bytes: 19732
n,m=map(int,input().split())
binlist=[]
for iii in range(m):
  ks=[int(_) for _ in input().split()]
  k=ks[0]
  s=ks[1:]
  binn=0
  for kkk in range(k):
    binn+=2**(s[kkk]-1)
  binlist.append(binn)
q=[int(_) for _ in input().split()]
cnt=0
for iii in range(2**n):
  res=[]
  for jjj in binlist:
    res.append(bin(jjj & iii).count("1")%2)
  if res==q:
    cnt+=1
print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		String s=sc.next();

		String[] str=s.split("");

		boolean YYMM=true;
		boolean MMYY=true;

		YYMM=check_YYMM(str);

		MMYY=check_MMYY(str);

		if(YYMM && MMYY) System.out.println("AMBIGUOUS");
		else if(YYMM && !MMYY) System.out.println("YYMM");
		else if(!YYMM && MMYY) System.out.println("MMYY");
		else System.out.println("NA");

		sc.close();

	}

	public static boolean check_YYMM(String[] str){
		int MM=Integer.parseInt(str[2]+str[3]);
		if(MM>12) return false;
		if(MM==0) return false;
		return true;
	}

	public static boolean check_MMYY(String[] str){
		int MM=Integer.parseInt(str[0]+str[1]);
		if(MM>12) return false;
		if(MM==0) return false;
		return true;
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 400010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

priority_queue<int> L;
priority_queue<int, vector<int>, greater<int> > R;
ll A, B;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int q;
    cin >> q;
    while (q--) {
        int ch, u, v;
        cin >> ch;
        if (ch == 1) {
            cin >> u >> v;
            B += v;
            L.push(u); R.push(u);
            if (L.top() > R.top()) {
                int g = L.top(); L.pop();
                int h = R.top(); R.pop();
                A += abs(g - h);
                L.push(h);
                R.push(g);
            }
        }
        else {
            cout << L.top() << ' ' << A+B << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 200010
#define LL long long

using namespace std;

inline LL read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

LL n, D, x, y, cnt;

int main() {
    n = read(); D = read();
    for(int i = 1; i <= n; ++i) {
        x = read(); y = read();
        if(x * x + y * y <= D * D) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


ll calc(ll x){
    return x * (x - 1) / 2;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, x, d;
    cin >> n >> x >> d;
    if(x == 0 && d == 0) return cout << 1, 0;
    if(d == 0) return cout << n + 1, 0;
    if(x == 0) return cout << calc(n) + 1, 0;
    if(d < 0){
        d = -d;
        x = -x;
    }
    map<int, vector<pair<ll, ll>> > mp;
    for(int i = 0; i <= n; i++){
        ll l = x * i + (calc(i)) * d;
        ll r = x * i + (calc(n) - calc(n - i)) * d;
        mp[((l % d) + d) % d].push_back({l, r});
    }
    ll ans = 0;
    for(auto &i: mp){
        sort(i.second.begin(), i.second.end());
        ll l, r;
        bool found = 0;
        for(auto &j: i.second){
            if(!found){
                found = 1;
                l = j.first;
                r = j.second;
            }
            else{
                if(j.first <= r) r = max(r, j.second);
                else{
                    ans += (r - l) / d + 1;
                    l = j.first;
                    r = j.second;
                }
            }
        }
        ans += (r - l) / d + 1;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 25424
#include <iostream>
using namespace std;
 
int main() {
  int x, y;
  cin >> y >> x;
  while (x != 0 && y != 0) {
    for(int o = 0; o < y; o++){
    	for(int i = 0; i < x; i++){
    		if(i == 0 || i == x - 1 || o == 0 || o == y - 1) {
    	  	cout << "#";
    		}
    		else cout << '.';
    	}
    	cout << endl;
    }
    cout << endl;
    cin >> y >> x;
  }
}


Measured memory_bytes: 3084
N, K = map(int, input().split())
A = list(map(int, input().split())) #どこに行くかのリスト
now = 0 #どこにいるか
LOG = {}
roop = 0
count = 0

while now not in LOG and count < K:
    LOG.setdefault(now, count)
    now = A[now] -  1
    count += 1

if count < K:
    roop = len(LOG) - LOG[now]
    K = (K - count) % roop
    count = 0
    while count < K:
        now = A[now] -  1
        count += 1

print(now+1) #行った場所を保存

Measured memory_bytes: 104312
n = int(input())
ta = [[int(item) for item in input().split()] for _ in range(n)]

p, q = ta[0]
for t, a in ta[1:]:
    rate1 = p//t
    rate2 = q//a
    if p % t != 0:
        rate1 += 1
    if q % a != 0:
        rate2 += 1
    rate = max(rate1, rate2)
    p = t*rate 
    q = a*rate 
print(p + q)

Measured memory_bytes: 3188
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1e+7
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>>  Table(H, vector<char>(W));
	rep(i, H) {
		rep(j, W) {
			cin >> Table[i][j];
		}
	}
	vii DP(H, vector<int>(W));
	for (int i = H - 1; i >= 0; i--) {
		for (int j = W - 1; j >= 0; j--) {
			if (i == H - 1 && j == W - 1) {
				if (Table[i][j] == '#') {
					DP[i][j] = 1;
				}
				else {
					DP[i][j] = 0;
				}
			}
			else {
				int RouteH, RouteW;
				if (i < H - 1) {
					if (Table[i][j] == '.') {
						RouteH = DP[i + 1][j];
					}
					else {
						if (Table[i + 1][j] == '#') {
							RouteH = DP[i + 1][j];
						}
						else {
							RouteH = DP[i + 1][j] + 1;
						}
					}
				}
				else {
					RouteH = int_INF;
				}

				if (j < W - 1) {
					if (Table[i][j] == '.') {
						RouteW = DP[i][j + 1];
					}
					else {
						if (Table[i][j + 1] == '#') {
							RouteW = DP[i][j + 1];
						}
						else {
							RouteW = DP[i][j + 1] + 1;
						}
					}
				}
				else {
					RouteW = int_INF;
				}

				DP[i][j] = min(RouteH, RouteW);
			}
		}


	}

	cout << DP[0][0] << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bitset>
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lowbit(x) x&(-x)
#define PA pair<int, int>
#define MK make_pair
using namespace std;
typedef unsigned long long LL;
inline LL read()
{
	LL l = 0, f = 1;
	char a = getchar();
	for (; a < '0' || a > '9'; a = getchar())
		if (a == '-') f = -1;
	for (; a >= '0' && a <= '9'; a = getchar())
		l = l*10+a-48;
	return l*f;
}
const int N = 100005;
LL n, mn, mx, a[N];
int main()
{
	n = read();
	for (LL i = 1; i <= n; ++i) a[i] = read();
	if (a[n] != 2)
	{
		printf("-1\n");
		return 0;
	}
	mn = mx = 2;
	for (LL i = n; i >= 1; --i)
	{
		LL l = ((mn+a[i]-1)/a[i])*a[i], r = (mx/a[i])*a[i];
		if (l > mx)
		{
			printf("-1\n");
			return 0;
		}
		mn = l, mx = r+a[i]-1;
	}
	printf("%llu %llu\n", mn, mx);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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 = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    cout << (10000 - n) % 1000 << endl;
    return;
}

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

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int N = 25;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

struct node{
	int x, y;
	int time;
} t, p;

char s[N][N];
bool ok[N][N];
queue<node> q;

int main()
{
	int h, w, res = 0;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
		cin >> s[i];
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (s[i][j] == '.'){
				t.x = i; t.y = j; t.time = 0;
				q.push(t);	ok[i][j] = 1;
				while (!q.empty()){
					t = q.front(); q.pop();
					res = max(res, t.time);
					for (int i = 0; i < 4; i++){
						int nx = t.x + dx[i];
						int ny = t.y + dy[i];
						if (nx >= 0 && nx < h && ny >= 0 && ny < w && !ok[nx][ny] && s[nx][ny] == '.'){
							p.x = nx; p.y = ny; p.time = t.time + 1;
							ok[nx][ny] = 1;	q.push(p);
						}
					}
				}
				memset(ok, 0, sizeof(ok));
			}
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
// E - Sequence Sum
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	ll N; int X, M; cin>>N>>X>>M;

	int mn = min(N, (ll)M);
	set<ll> S;
	vector<ll> A;
	ll a = X;
	ll ans = 0;

	rp(_i, 0, mn){
		if(S.find(a) != S.end()) break;
		S.insert(a);
		A.push_back(a);
		ans += a;
		a = a*a % M;
		if(a == 0){ cout<< ans <<endl; return 0; }
	}

	if((int)A.size() >= mn){ cout<< ans <<endl; return 0; }

	int st_len = 0;
	while(st_len < (int)A.size() && a != A[st_len]) st_len += 1;
	int cyc_len = A.size() - st_len;
	int ed_len = (N - st_len) % cyc_len;

	ll st = 0; rp(i, 0, st_len) st += A[i];
	ll cyc_sum = 0; rp(i, st_len, A.size()) cyc_sum += A[i];
	ll cyc_num = (N - st_len) / cyc_len;
	ll ed = 0; rp(i, st_len, st_len + ed_len) ed += A[i];

	cout<< st + cyc_sum * cyc_num + ed <<endl;
}


Measured memory_bytes: 5928
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
 
ll n;
 
int solve();
 
int main()
{
    cin >> n;
    cout << solve() << endl;
    return 0;
}
 
int solve(){
    ll res=0;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll now=0;
            while(n%i==0){
                now++;
                n/=i;
            }
            ll cnt=1;
            while(cnt<=now){
                now -= cnt;
                cnt++;
                res++;
            }
        }
    }
    if(n!=1) res++;
    return res;
}

Measured memory_bytes: 3640
#include <stdio.h>
int result(int);

int main(void) {
	int x, y;
	scanf("%d%d", &x, &y);
	if (x==4||x==6||x==9||x==11) {
		if (y==4||y==6||y==9||y==11) {
			result(0);
		}	
		else {
			result(1);
		}
	}
	else if (x==1||x==3||x==5||x==7||x==8||x==10||x==12) {
		if (y==1||y==3||y==5||y==7||y==8||y==10||y==12) {
			result(0);
		}
		else {
			result(1);
		}
		
	}
	else if (x == 2) {
		if (y == 2) {
			result(0);
		}
		else {
			result(1);
		}
	}
	return 0;
}
int result(int a) {
	if (a == 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_HUMAN_MAX		100000									// 最大人数

// 内部構造体 - 人情報
typedef struct Human {
	int miDNo;													// 代表グループ番号 1～
	int miLen;													// 代表からの距離
} Human;

// 内部変数
static Human sz1Human[D_HUMAN_MAX + 5];							// 人情報

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 代表グループ番号取得
int
fGetDNo(
	int piHNo					// <I> 人番号 1～
)
{
	// 代表番号
	int liDNo = sz1Human[piHNo].miDNo;

	// 本当に代表かチェック
	if (sz1Human[liDNo].miLen == 0) {
		return liDNo;
	}

	// 下位へ
	int liNNo = fGetDNo(liDNo);

	// 情報更新
	sz1Human[piHNo].miDNo = liNNo;						// 代表グループ番号
	sz1Human[piHNo].miLen += sz1Human[liDNo].miLen;		// 代表からの距離

	return liNNo;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, liRet, liWork;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 人情報初期化
	for (i = 1; i <= D_HUMAN_MAX; i++) {
		sz1Human[i].miDNo = i;
		sz1Human[i].miLen = 0;
	}

	// 情報数取得
	int liICnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &liWork, &liICnt);

	// 情報数でループ
	liRet = 0;
	for (i = 0; i < liICnt; i++) {

		// 情報取得
		int liNo1, liNo2, liLen;
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
		fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
		sscanf(lc1Buf, "%d%d%d", &liNo1, &liNo2, &liLen);

		// 代表グループ番号取得
		int liGNo1 = fGetDNo(liNo1);
		int liGNo2 = fGetDNo(liNo2);

		// 比較
		if (liGNo1 == liGNo2) {																// 一致
			int liDF = sz1Human[liNo2].miLen - sz1Human[liNo1].miLen;							// 差
			if (liDF != liLen) {																// 情報不一致
				liRet = -1;
				break;
			}
		}
		else {																				// 不一致
			sz1Human[liGNo2].miDNo = liGNo1;													// 代表変更
			sz1Human[liGNo2].miLen = liLen - sz1Human[liNo2].miLen + sz1Human[liNo1].miLen;		// 距離セット
		}
	}

	// 結果セット
	if (liRet == 0) {
		sprintf(lc1Out, "Yes\n");
	}
	else {
		sprintf(lc1Out, "No\n");
	}

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 896
#include<stdio.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a<b && b<c)
	{
		printf("Yes\n");
	}
	else 
	{
		printf("No\n");
	}

	

	return 0;
} 


Measured memory_bytes: 2124
#include <iostream>
using namespace std;
int main ()
{
	int n, i=0, pas=0;
	string s;
	cin>>n;
	cin>>s;
	for(i=0; i<n-2; i++){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
		pas++;
		i+=2;
		}
	}
	cout<<pas;
}

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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define E "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAX = 1e18;

#define N 5010

int sum(int x){
    int s=0;
    while(x>0){
        s+=x%10;
        x/=10;
    }
    return s;
}

void solve()
{
    int n,m=INF;
    cin>>n;
    vi a(n,0),b(n,0);
    REP(i,n) cin>>a[i];
    b[0] = a[0];
    for (int i=1; i<n;i++){
        b[i] = b[i-1]+a[i];
    }
    REP(i,n-1){
        m = min(m,abs(b[n-1]-2*b[i]));
    }
    cout<<m;

}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}




Measured memory_bytes: 3576
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vi s;

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


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

using namespace std;
using ll = long long;


int main()
{
    int n, k;
    cin >> n >> k;
    vector<vector<int>> hen(n);

    if(k > (n - 1) * (n - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }


    int m = n - 1;
    for(int i = 1; i < n; i++) {
        hen[0].push_back(i);
    }

    int t = (n - 1) * (n - 2) / 2;

    for(int i = 1; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(t == k)goto LAST;
            hen[i].push_back(j);
            m++;
            t--;
        }
    }
    LAST:;


    cout << m << endl;
    for(int i = 0; i < n; i++) {
        for(auto j : hen[i]) {
            cout << i + 1 << " " << j + 1 << endl;
        }
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	cout << min(N * A, B) << endl;
}

Measured memory_bytes: 3608
#-------最強ライブラリSCC(Python) ver25252------
class scc_graph:
  # n 頂点数
  def __init__(s, n): 
    s._n = n
    s.g = {}
    s.rg = {}
  def num_vertices(s): return s._n
  # 辺を追加 frm 矢元 to 矢先
  # O(1)
  def add_edge(s, frm, to): 
    if frm in s.g: s.g[frm].append(to)
    else: s.g[frm] = [to]
    if to in s.rg: s.rg[to].append(frm)
    else: s.rg[to] = [frm]

  # グループの個数と各頂点のグループidを返す
  def scc_ids(s):
    def dfs(v):
      stack = [v]
      while stack:
        t = stack[-1]
        vis[t] = True
        if t not in s.g:
          vs.append(stack.pop())
          continue
        for i in s.g[t]:
          if not vis[i]:
            stack.append(i)
            break
        else:
          vs.append(stack.pop())

    def rdfs(v, n):
      stack = [v]
      vis[v] = True
      ids[v] = n
      while stack:
        t = stack.pop()
        vis[t] = True
        if t not in s.rg: continue
        for i in s.rg[t]:
          if not vis[i]:
            ids[i] = n
            stack.append(i)

    vis = [False] * s._n 
    vs = []
    ids = [-1] * s._n
    for i in range(s._n):
      if not vis[i]:
        dfs(i)
    group_num = 0
    vis = [False] * s._n 
    for i in vs[::-1]:
      if not vis[i]:
        rdfs(i, group_num)
        group_num += 1
    return group_num, ids 

  # 強連結成分となっている頂点のリストのリスト トポロジカルソート済み
  # O(n + m)
  def scc(s):
    ids = s.scc_ids()
    group_num = ids[0]
    counts = [0] * group_num
    for x in ids[1]: counts[x] += 1
    groups = [[] for _ in range(group_num)]
    for i in range(s._n):
      groups[ids[1][i]].append(i)
    return groups

#-------最強ライブラリここまで------

import sys
def main():
  input = sys.stdin.readline

  n, m = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]

  g = scc_graph(n)

  for i in range(m):
    u, v = ab[i]
    g.add_edge(u, v)

  scc = g.scc()

  print(len(scc))

  for v in scc:
    print(len(v), end = " ")
    for x in v:
      print(x, end = " ")
    print("")

main()

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

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

ll n, k;
vector<ll> a;

bool check(ll m) {
	ll count = 0;
	rep(i, n) {
		count += (a[i] + m - 1)/m - 1;
	}
	if (count > k) return false;
	else return true;
}

int main() {
	cin >> n >> k;
	a.resize(n);
	rep(i, n) cin >> a[i];
	ll r = 1e+9;
	ll l = 0;
	while (r - l > 1) {
		ll m = (r + l) / 2;
		if (check(m)) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << r << endl;
	return 0;
}



Measured memory_bytes: 4724
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        a: i64, b: i64, _c: i64, k: i64,
    }
    if k % 2 == 0 {
        println!("{}", a - b);
    } else {
        println!("{}", b - a);
    }
}


Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int m,t,p,r;
	while(cin>>m>>t>>p>>r)
	{
		if(m==0&&t==0&&p==0&&r==0)break;
		vector<pair<int, int> > a;//score time 
		int num[150];
		int miss[150][20]={};
		for(int i=0;i<150;i++)num[i]=i;
		for(int i= 0;i<60;i++)
		{
			pair<int,int> l;
			l.first=0;
			l.second=0;
			a.push_back(l);
		}
		
		for(int i =0;i<r;i++)
		{
			
			int time,team,prob,stat;
			cin>>time>>team>>prob>>stat;
			team--;
			
			if(stat==0)
			{
				a[team].first++;
				a[team].second+=miss[team][prob]*20+time;
			}
			else
			{
				miss[team][prob]++;
			}
		}
		
		
		bool end=true;
		while(end)
		{
			end = false;
			for(int i=1;i<t;i++)
			{
				if(a[i].first>a[i-1].first)
				{
					swap(a[i],a[i-1]);
					swap(num[i],num[i-1]);
					end = true;
				}
				else if(a[i].first==a[i-1].first&&a[i].second<a[i-1].second)
				{
					swap(a[i],a[i-1]);
					swap(num[i],num[i-1]);
					end= true;
				}
				else if(num[i]>num[i-1]&&a[i].first==a[i-1].first&&a[i].second==a[i-1].second)
				{
					
					swap(a[i],a[i-1]);
					swap(num[i],num[i-1]);
					end=true;
				}
			}
		}
		cout<<num[0]+1;
		for(int i=1;i<t;i++)
		{
			if(a[i]==a[i-1])cout<<"=";
			else cout<<",";
			cout<<num[i]+1;
		}
		cout<<endl;
		
		
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	
	vector<vector<int>> roots(n);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		roots[a - 1].push_back(b - 1);
		roots[b - 1].push_back(a - 1);
	}
	
	vector<int> sign(n, -1);
	queue<int> que;
	
	sign[0] = 0;
	que.push(0);
	
	while (!que.empty()) {
		auto cur = que.front();
		que.pop();
		
		for (auto && root : roots[cur]) {
			if (sign[root] != -1)
				continue;
			
			que.push(root);
			sign[root] = cur;
		}
	}
	
	if (count(sign.begin(), sign.end(), -1))
		cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		
		for (int i = 1; i < n; ++i)
			cout << sign[i] + 1 << endl;
	}
}

Measured memory_bytes: 10216
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h+2);
    rep(i, w+2)s[0] += '.';
    rep(i, h){
        cin >> s[i+1];
        s[i+1] = "." + s[i+1];
        s[i+1] += ".";
    }
    rep(i, w+2)s[h+1] += '.';
    REP(i, h){
        REP(j, w){
            int now = 0;
            if(s[i][j] == '#'){cout << '#'; continue;}
            if(s[i-1][j-1] == '#')now++;
            if(s[i-1][j] == '#')now++;
            if(s[i-1][j+1] == '#')now++;
            if(s[i][j-1] == '#')now++;
            if(s[i][j+1] == '#')now++;
            if(s[i+1][j-1] == '#')now++;
            if(s[i+1][j] == '#')now++;
            if(s[i+1][j+1] == '#')now++;
            cout << now;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256