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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e10;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}


int main()
{
    fast;
    ll t;
    
    //~ cin>>t;
    t=1;
    while(t--){
			ll n;
			cin>>n;
			if(n<5 or n&1){
				cout<<0;
				return 0;
			}
			ll ans=0;
			ll a=5;
			ll c1=0,c2=0;
			while(a<n){
				//~ put(a);
				//~ put(c1);
				c1+=((n/a))/2;
				if(a>=1e18)
					break;
				a*=5;
			}
			
			//~ put(c1);
			ans=c1;
			cout<<ans;
    }
    return 0;
}


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

const int MOD = 1000000007;

int main() {
    double W, H, x, y, aveX, aveY;
    cin >> W >> H >> x >> y;

    aveX = W / 2.0;
    aveY = H / 2.0;

    cout << W * H / 2.0;
    if ((x==aveX) && (y==aveY))   cout << " 1" << endl;
    else cout << " 0" << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		if(A.substring(A.length() - 1, A.length()).equals(B.substring(0, 1))){
			if(B.substring(B.length() - 1, B.length()).equals(C.substring(0, 1))) {
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}
}


Measured memory_bytes: 21972
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string a, b, c;
	cin >> a >> b >> c;
	char d = 'A' - 'a';
	cout << (char)(a[0] + d) << (char)(b[0] + d) << (char)(c[0] + d) << endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin

n, m, c = [int(x) for x in stdin.readline().strip().split()]
# read B
b_lst = [int(x) for x in stdin.readline().strip().split()]
# read A and calc
cnt = 0
for _ in range(n):
  abc = sum([b_lst[i] * int(x) for i, x in enumerate(stdin.readline().strip().split())]) + c
  if(abc) > 0:
    cnt += 1
    
print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    byte a = sc.nextByte();
    byte b = sc.nextByte();
    if(a != 2 && b != 2){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22996
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define coyes cout << "Yes" << endl;
#define cono cout << "No" << endl;
#define coYes cout << "YES" << endl;
#define coNo cout << "NO" << endl;
using namespace std;
using ll = long long int;

int main() {
  bool flag = true;
  int n, m;
  cin >> n >> m;
  map<int, int> sc;
  if (m != 0) {
    rep(i, m) { 
      int ss, cc;
      cin >> ss >> cc;
      if (sc.count(ss) == 0) {
        sc[ss] = cc;
      }
      else {
        if (sc[ss] != cc) {
          cout << -1 << endl;
          flag = false;
          break;
        }
      }
      if (ss == 1) {
        if (cc == 0 && n != 1) {
          cout << -1 << endl;
          flag = false;
          break;
        }
      }
    }
  }
  if (m == 0) {
    flag = false;
  }
  if (m == 0 && n == 1) {
    cout << 0 << endl;
  }
  if (m == 0 && n == 3) {
    cout << 100 << endl;
  }
  if (m == 0 && n == 2) {
    cout  << 10 << endl;
  }
  if (n == 1 && flag) {
    cout << sc.at(1) << endl;
  }
  if (flag && n == 2) {
    if (sc.count(2)) {
      if (sc.count(1)) {
        cout << 10 * sc.at(1) + sc.at(2) << endl;
      }
      else {
        cout << 10 + sc.at(2) << endl;
      }
    }
    else {
      cout << 10 * sc.at(1) << endl;
    }
  }
  if (flag && n == 3) {
    if (sc.count(3)) {
      if (sc.count(2)) {
        if (sc.count(1)) {
          cout << 100 * sc.at(1) + 10 * sc.at(2) + sc.at(3) << endl;
        }
        else {
          cout << 100 + 10 * sc.at(2) + sc.at(3) << endl;
        }
      }
      else {
        if (sc.count(1)) {
          cout << 100 * sc.at(1) + sc.at(3) << endl;
        }
        else {
          cout << 100 + sc.at(3) << endl;
        }
      }
    }
    else {
      if (sc.count(2)) {
        if (sc.count(1)) {
          cout << 100 * sc.at(1) + 10 * sc.at(2) << endl;
        }
        else {
          cout << 100 + 10 * sc.at(2) << endl;
        }
      }
      else {
        cout << 100 * sc.at(1) << endl;
      }
    }
  }
}    
      


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int flag = 0;
  if(a==7&&b==5&&c==5)flag = 1;
  if(a==5&&b==7&&c==5)flag = 1;
  if(a==5&&b==5&&c==7)flag = 1;
  if(flag)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

#define MAX 200000

int main() {
    int N, K;
    vector<int> H(MAX);
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    sort(H.begin(), H.begin()+N);
    long long sum = 0;
    for (int i = 0; i < N - K; i++) {
        sum += H[i];
    }
    cout << sum << endl;
    return 0;
}


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

int main(void){
	int a, b;
	char op;
	while(cin >> a >> op >> b){
		if(op == '?') break;
		else if(op == '+') printf("%d\n", a+b);
		else if(op == '-') printf("%d\n", a-b);
		else if(op == '*') printf("%d\n", a*b);
		else if(op == '/') printf("%d\n", a/b);
	}


	return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define reg register
#define ll long long
using namespace std;
const int MAXN = 310;
const int mod = 1e9 + 7;
int n, m, dp[MAXN][MAXN][MAXN];
struct lim {
  int l, x;
};
vector<lim> vec[MAXN];
bool check(int l, int r, int x) {
  return l <= x && x < r;
}
inline void Add(int &x, int y) {
  x += y, x -= x >= mod ? mod : 0;
}
inline void work() {
  scanf("%d%d", &n, &m);
  for(reg int i = 1; i <= m; ++i) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x), vec[r].push_back((lim) { l, x });
  }
  dp[0][0][0] = 1;
  for(reg int i = 1; i <= n; ++i) {
    int la = 0, ra = i, lb = 0, rb = i;
    for(auto it : vec[i]) {
      int tmp = it.l;
      if(it.x == 1) ra = min(ra, tmp), rb = min(rb, tmp);
      if(it.x == 2) rb = min(rb, tmp), la = max(la, tmp);
      if(it.x == 3) la = max(la, tmp), lb = max(lb, tmp);
    }
    for(reg int j = 0; j < i; ++j) for(reg int k = 0; k < j || !k; ++k) {
      int tmp = dp[i - 1][j][k], c = i - 1;
      if(check(la, ra, j) && check(lb, rb, k)) dp[i][j][k] = (dp[i][j][k] + tmp) % mod;
      if(check(la, ra, c) && check(lb, rb, j)) dp[i][c][j] = (dp[i][c][j] + tmp) % mod;
      if(check(la, ra, c) && check(lb, rb, k)) dp[i][c][k] = (dp[i][c][k] + tmp) % mod;
    }
  }
  int ans = 0;
  for(reg int i = 0; i <= n; ++i) for(reg int j = 0; j <= n; ++j) ans = (ans + dp[n][i][j]) % mod;
  printf("%d\n", ans);
}
int main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) work();
  return 0;
}


Measured memory_bytes: 112896
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
const int inf = 1<<30;

int evaluation(int N, int A, int B, int C, int D, const string& S) {
  if(A > C || B > D || S[A] == '#' || S[B] == '#' || A == B) return inf;
  return abs((C-A) - (D-B));
}

int main() {
  int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
  A--, B--, C--, D--;
  string S; cin >> S;
  bool ok = true;
  while(A != C || B != D) {
    int e1 = evaluation(N, A+1, B, C, D, S);
    int e2 = evaluation(N, A, B+1, C, D, S);
    int e3 = evaluation(N, A+2, B, C, D, S);
    int e4 = evaluation(N, A, B+2, C, D, S);
    int mn = min({e1, e2, e3, e4});
    if(mn == inf) {
      ok = false;
      break;
    }
    if(e1 == mn) A += 1;
    else if(e2 == mn) B += 1;
    else if(e3 == mn) A += 2;
    else B += 2;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 640
<?php
  $stdin = fopen('php://stdin', "r");

  fscanf($stdin, "%d", $x);
  fscanf($stdin, "%d", $a);
  fscanf($stdin, "%d", $b);

  $m = $x - $a;
  $m = $m % $b;

  echo $m.PHP_EOL;


Measured memory_bytes: 4604
N = input()
p = list(map(int, input().split()))

import numpy as np

p_sort = sorted(p)

p = np.array(p)
p_sort = np.array(p_sort)

if np.count_nonzero(p != p_sort) == 2 or np.count_nonzero(p != p_sort) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 21004
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int32_t N;
bool used[100000];
std::vector<std::pair<int,int>> graph[100000];

void dfs(int v)
{
	used[v] = true;
	for (auto& n : graph[v])
	{
		if (used[n.first]) { continue; }
		dfs(n.first);
	}
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int M;
	in >> N>>M;
	for (int i = 0; i < M ; i++)
	{
		int a, b, c;
		in >> a >> b >> c;
		--a; --b; c %= 2;
		graph[a].emplace_back(b, c);
		graph[b].emplace_back(a, c);
	}

	int count = 0;
	for (int i = 0; i < N; i++)
	{
		if (!used[i]) {
			++count;
			dfs(i);
		}
	}
	out << count << endl;

	return 0;
}
#endif


Measured memory_bytes: 8960
#include <stdio.h>

int main(){
  int n,a,i,now=0,count=0;
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a==(now+1)){
      now++;
    } else {
      count++;
    }
  }
  
  if(now==0){
    printf("-1");
  } else {
    printf("%d",count);
  }
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut pv: Vec<(i64, i64)> = vec![];
    let mut minv = std::i64::MAX;

    for _ in 0..n {
        let x: i64 = read();
        let y: i64 = read();
        pv.push((x, y));
    }

    for u in 0..n {
        for d in 0..n {
            for r in 0..n {
                for l in 0..n {
                    let up = pv[u].1;
                    let down = pv[d].1;
                    let right = pv[r].0;
                    let left = pv[l].0;
                    if up <= down {
                        continue;
                    }
                    if right <= left {
                        continue;
                    }
                    let mut cnt = 0;
                    for i in 0..n {
                        let pi = pv[i];
                        if pi.1 <= up && pi.1 >= down && pi.0 <= right && pi.0 >= left {
                            cnt += 1;
                        }
                    }
                    if cnt >= k {
                        let sq = (up - down) * (right - left);
                        if sq < minv {
                            minv = sq;
                        }
                    }
                }
            }
        }
    }
    println!("{}", minv);
}


Measured memory_bytes: 2140
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    int K;
    cin >> K;
    vector<pair<int,int> >p;
    for(int i=0;i<K;i++){
        int x,y;
        cin >> x >> y;
        p.push_back(make_pair(x,y));
    }
    long long dp[N+1];
    long long ps[N+1];
    dp[0]=0, dp[1]=1;
    ps[0]=0, ps[1]=1;
    for(int i=2;i<=N;i++){
        dp[i]=0;
        for(int j=0;j<K;j++){
            if(i-p[j].first>=1){
                dp[i]+=ps[i-p[j].first]-ps[max(1,i-p[j].second)-1];
                dp[i]+=998244353ll*3ll;
                dp[i]%=998244353;
            }
        }
        ps[i]=ps[i-1]+dp[i];
        ps[i]%=998244353;
    }
    cout << dp[N];
}

Measured memory_bytes: 6308
n = gets.to_i
c = []
s = []
f = []
(1..n - 1).each do |i|
  c[i], s[i], f[i] = gets.split.map(&:to_i)
end

ans = []
(1..n - 1).each do |i|
  total = 0
  (i..n - 1).each do |j|
    total = s[j] if total < s[j]
    total = ((total - 1) / f[j] + 1) * f[j]
    total += c[j]
  end
  ans << total
end
ans << 0
puts ans


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string n;
  cin >> n;
  for(int i = 0;i < 3;i++) {
      if(n[i] == '9') {
          n[i] = '1';
      } else {
          n[i] = '9';
      }
  }
  cout << n << '\n';
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    R, C, K, *RCV = map(int, read().split())

    item = [[0] * C for _ in range(R)]
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

    dp = [0] * (C + 1)
    for i in range(R):
        dp, dp_prev = [0] * (C + 1), dp
        v = [0] * 4
        for j in range(C):
            for k in range(4):
                if v[k] < dp_prev[j + 1]:
                    v[k] = dp_prev[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if v[k + 1] < v[k] + item[i][j]:
                        v[k + 1] = v[k] + item[i][j]
            dp[j + 1] = v[3]

    print(dp[C])

    return


if __name__ == '__main__':
    main()


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

string s;

void read() {
  cin >> s;
}

void solve() {
  int cnt1 = 0, cnt2 = 0;
  string cl = s;
  for(int i = 1; s[i]; ++i)
    if (s[i] == s[i - 1]) {
      s[i] = '1' - s[i] + '0';
      ++cnt1;
    }
  //cout << s << "\n";
  for(int i = cl.size() - 2; i >= 0; --i)
    if (cl[i] == cl[i + 1]) {
      cl[i] = '1' - cl[i] + '0';
      ++cnt2;
    }
  //cout << cl << "\n";
  cout << min(cnt1, cnt2);
}

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


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

#define ll long long
const int MOD = 1e9 + 7;

class mint {
    long long x;
public:
    mint(long long x=0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main() {
  ll n, a;
  mint result;
  vector<ll> one(61);
  cin >> n;
  for(int i = 0; i < n; i++) {
      cin >> a;
      bitset<60> bs(a);
      for(int j = 0; j < 60; j++) {
          one[j] += bs[j];
      }
  }
  mint bit = 1;
  for(int i = 0; i < 60; i++) {
      result += bit * one[i] * (n - one[i]);
      bit *= 2;
  }
  
  cout << fixed << result;
}

Measured memory_bytes: 256
n,x,y=map(int,input().split())
s= input()
c=0
d=x+y
e = 0
f= False
for i in range(n):
    if s[i]=="a":
        if c<d:
            f=True
    elif s[i]=="b":
        if c<d and e<y:
            f=True
            e+=1
    if f:
        print("Yes")
        c+=1
    else:
        print("No")
    f=False

Measured memory_bytes: 76100
#include <stdio.h>

int main(void)
{
	int h, w;
	int i, j;

	while(scanf("%d %d", &h, &w)!=EOF && !(h==0 && w==0)){
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i == 0 || i==h-1 || j==0 || j==w-1)
					printf("#");
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 572
import math

N = int(input())

for i in range(N):
  side_len = list(map(int, input().split(" ")))
  side_len.sort()
  if int(math.pow(side_len[0], 2)) + int(math.pow(side_len[1], 2)) == int(math.pow(side_len[2], 2)):
    print("YES")
  else:
    print("NO")


Measured memory_bytes: 5664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	ll ans = 100000000000000000ll;
	cin >> N;
	vector<ll> data(N);
	ll sum = 0;
	

	for (int i = 0; i < N; i++)
	{
		cin >> data[i];
		sum += data[i];
	}
	
		ll SUM = 0;
	
		for (int i = 0; i < N; i++)
		{
			SUM += data[i];
			if(i+1<N)ans = min(ans, abs(sum - 2 * SUM));
			
			
		}
	

		cout << ans << endl;
	
	
	return 0;

	


}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    string ans = "APPROVED";
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        if(x%2 == 0){
            if(x%3 != 0 && x%5 != 0){
                ans = "DENIED";
            }
        }
    }
    cout << ans;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

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

int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    pair<bool,int> a[502][502]; // visited?, num_of_coin
    pair<int,int> pos;
    dire d[4] = {
        {0,1},{1,0},{0,-1},{-1,0}
    };
    int H, W; cin >> H >> W;
    for (int j = 1; j <= H; j++) {
        for (int i = 1; i <= W; i++) {
            cin >> a[j][i].second;
            a[j][i].first == false;
        }
    }
    for(int i = 0; i <= W+1; i++) {
        a[0][i].first = true;
        a[H+1][i].first = true;
    }
    for(int j = 0; j <= H+1; j++) {
        a[j][0].first = true;
        a[j][W+1].first = true;
    }
    pos = {1,1};
    int di = 0;
    bool grab = false;
    vector<pair<pair<int,int>,pair<int,int>>> v;
    while (1){
        a[pos.first][pos.second].first = true;
        pair<int, int> next;
        next.first = pos.first + d[di].first;
        next.second = pos.second + d[di].second;
        if (a[next.first][next.second].first == true) {
            di = (di + 1)% 4;
            next.first = pos.first + d[di].first;
            next.second = pos.second + d[di].second;
            if (a[next.first][next.second].first == true) break;
        }
        if (a[pos.first][pos.second].second % 2 == 1) {
            v.push_back(make_pair(pos, next));
            a[next.first][next.second].second++;
        } 
        pos = next;
    }
    cout << v.size() << endl;
    REP(i, v.size()) {
        cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second.first << " " << v[i].second.second << endl;
    }
    return 0;
}


Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
const int MM=100013;
const int P=1e9 + 7;
vector<int> W[MM];
long long Bl[MM], Wh[MM]; //pokolorowany lub nie
void DFS(int w, int p)
{
    Bl[w]=1;
    Wh[w]=1;
    for(auto v:W[w])
    {
        if(v!=p)
        {
            DFS(v,w);
            Bl[w]*=Wh[v];
            Bl[w]%=P;
            Wh[w]*=(Wh[v]+Bl[v]);
            Wh[w]%=P;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    int n,a,b;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        W[a].push_back(b);
        W[b].push_back(a);
    }
    DFS(1,-1);
    cout<<(Bl[1]+Wh[1])%P;
    return 0;
}


Measured memory_bytes: 14208
#include<stdio.h>

int main(){
  char s[11];scanf("%s",s);
  char ans[11]={0};
  int i,count=0;
  for(i=0;s[i]!=0;i++){
  if(s[i]=='0'||s[i]=='1')ans[count++]=s[i];
  if(s[i]=='B'&&count>0){
  ans[count-1]=0;count--;
  }
  }
  printf("%s\n",ans);
  return 0;
}

Measured memory_bytes: 128
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
ans = 0
if n == 2:
    if k == 0:
        print(1)
        print(1, 2)
    else:
        ans = -1
else:
    if k > combinations_count(n - 1, 2):
        ans = -1
    else:
        print(combinations_count(n - 1, 2) - k + n - 1)
        delcnt = combinations_count(n - 1, 2) - k
        cnt = 0
        # print(combinations_count(n - 1, 2), delcnt)
        for i in range(2, n + 1):
            if cnt >= delcnt:
                break
            for j in range(i + 1, n + 1):
                print(i, j)
                cnt += 1
                if cnt >= delcnt:
                    break
            if cnt >= delcnt:
                break
        for i in range(1, n):
            print(1, i + 1)

if ans == -1:
    print(ans)

Measured memory_bytes: 42864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
using Graph = vector<vector<int>>;
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 = 2e9;
const ll LINF = (1LL<<60);

ll dp[3100][3100][4];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int R,C,k; cin >> R >> C >> k;
  Graph field(R, vector<int>(C, 0));
  REP(i,k){
    int r,c,v;
    cin >> r >> c >> v;
    r--, c--;
    field[r][c] = v;
  }

  if(field[0][0]>0){
    dp[0][0][1] = field[0][0];
  }

  REP(i,R) REP(j,C) REP(k,4){
    // go right
    if(j<C-1){
      chmax(dp[i][j+1][k], dp[i][j][k]);
      if(k<3 && field[i][j+1]>0) chmax(dp[i][j+1][k+1], dp[i][j][k] + field[i][j+1]);
    }

    // go down
    if(i<R-1){
      chmax(dp[i+1][j][0], dp[i][j][k]);
      if(field[i+1][j]>0) chmax(dp[i+1][j][1], dp[i][j][k] + field[i+1][j]);
    }
  } 
  /*
  REP(i,R) REP(j,C){ 
    REP(k,4){
      cout << dp[i][j][k] << " ";
    }
    cout << '\n';
  } 
  */
  ll ans = 0;
  REP(k,4) chmax(ans, dp[R-1][C-1][k]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 328916
#!/usr/bin/perl
use Data::Dumper;
my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);

my $f = &factr($n);

my @facts = keys %$f;

my %f0 = ();

my %oki = ();

while(1){
  my $gosei = 1;
  foreach my $f1 (@facts){
    $gosei *= ( $f1 ** ( $f0{$f1} - 0 ) );
  }
  if( $gosei >= 3 ){
#    print "gosei = $gosei\n";
    my $syo = $n / $gosei;
    if( $syo <= $gosei - 2 ){
      my $g1 = $gosei - 1;
      $oki{$g1} = 1;
    }
  }
  my $cu = 0;
  my $carry = 1;
  while($carry > 0){
    $f0{$facts[$cu]} += 1;
    $carry = 0;
    if( $f0{$facts[$cu]} > $f->{$facts[$cu]} ){
      $f0{$facts[$cu]} = 0;
      $carry = 1;
      $cu++;
    }
    last if( $cu > $#facts );
  }
  last if $cu > $#facts;
}
my $res = 0;
foreach my $o1 (keys %oki){
  $res += ( $o1 - 0);
}
#print &Dumper(\%oki);
print "$res\n";
exit(0);


sub factr {
  my $n0 = shift;
  my %f = ();
  
  while($n0>1){
    if( $n0 == 2 or $n0 == 3 or $n0 == 5 or $n0 == 7 or $n0 == 11 or $n0 == 13 or $n0 == 17 or $n0 == 19 ){
      $f{$n0} += 1;
      last;
    }
    my $n1 = 1+int(sqrt($n0));
    my $f1 = 0;
    for(my $i=1;$i<=$n1;$i+=2){
      my $ii = $i;
      $ii = 2 if $i==1;
      if( $n0 % $ii == 0 ){
        $f1 = $ii;
        last;
      }
    }
    if( $f1 == 0 ){
      $f{$n0} += 1;
      last;
    }
    $f{$f1} += 1;
    $n0 /= $f1;
  }
  return \%f;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define MAXC 80
#define MAXBAL (MAXC + MAXC)*MAXC

int R, C, A[MAXC + 3][MAXC + 3], B[MAXC + 3][MAXC + 3];
bool dp[2][MAXC + 3][2 * MAXBAL + 3];

int main() {
    cin >> R >> C;
    for (int i = 1; i <= R; i++) {
        for (int j = 1; j <= C; j++)
            cin >> A[i][j];
    }

    for (int i = 1; i <= R; i++) {
        for (int j = 1; j <= C; j++)
            cin >> B[i][j];
    }

    memset(dp, false, sizeof(dp));

    //base case
    dp[0][0][0 + MAXBAL] = dp[1][0][0 + MAXBAL] = true;

    int t = 0;
    for (int i = 1; i <= R; i++) {
        t = 1 - t;
        for (int j = 1; j <= C; j++) {
            for (int bal = -MAXC * (i + j - 1); bal <= MAXC * (i + j - 1); bal++) {
                dp[t][j][bal + MAXBAL] = false;

                int ab = A[i][j] - B[i][j];
                int ba = -ab;

                if (i > 1) {
                    if (dp[1 - t][j][bal - ab + MAXBAL])
                        dp[t][j][bal + MAXBAL] = true;

                    if (dp[1 - t][j][bal - ba + MAXBAL])
                        dp[t][j][bal + MAXBAL] = true;
                }

                if (j > 1 || i == 1) {
                    if (dp[t][j - 1][bal - ab + MAXBAL])
                        dp[t][j][bal + MAXBAL] = true;

                    if (dp[t][j - 1][bal - ba + MAXBAL])
                        dp[t][j][bal + MAXBAL] = true;
                }
            }
        }
    }

    int answer = MAXBAL;
    for (int bal = -MAXBAL; bal <= MAXBAL; bal++) {
        if (dp[t][C][bal + MAXBAL])
            answer = min(answer, abs(bal));
    }

    cout << answer << endl;
}


Measured memory_bytes: 4480
N, D = map(int, input().split())

X = [input().split() for i in range(N)]

count = 0
d_2 = 0
d = 0

for i in range(1, N):
    for j in range(0, i):
        d_2 = 0
        d = 0
        for k in range(D):
            d_2 += (float(X[i][k]) - float(X[j][k]))**2
        d = d_2**(1/2)
        if d.is_integer() == True:
            count += 1

print("{}".format(count))

Measured memory_bytes: 9372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++){
        cin>>s[i];
    }
    vector<vector<int>> dpr(h+2),dpl(h+2),dpu(h+2),dpd(h+2);
    for(int i=0; i<=h+1; i++){
        vector<int> r(w+2,0),l(w+2,0),u(w+2,0),d(w+2,0);
        dpr[i]=r,dpl[i]=l,dpu[i]=u,dpd[i]=d;
    }
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(s[i-1][j-1]=='.')dpl[i][j]=dpl[i][j-1]+1;
            else dpl[i][j]=0;
            if(s[i-1][w-j]=='.')dpr[i][w-j+1]=dpr[i][w-j+2]+1;
            else dpr[i][w-j+1]=0;

        }
    }
    for(int j=1; j<=w; j++){
        for(int i=1; i<=h; i++){
            if(s[i-1][j-1]=='.')dpu[i][j]=dpu[i-1][j]+1;
            else dpu[i][j]=0;
            if(s[h-i][j-1]=='.')dpd[h-i+1][j]=dpd[h-i+2][j]+1;
            else dpd[h-i+1][j]=0;
        }
    }
    int ans=0;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            ans=max(ans,dpr[i][j]+dpl[i][j]+dpu[i][j]+dpd[i][j]);
        }
    }
    cout<<ans-3;

    return 0;
}

Measured memory_bytes: 67200
/**
 * @author: Podugu Rohith Surya
 * @link: Link
 * @desc: Write something about problem
 * Input:
 * Output:
 **/
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mset(A, a) memset(A, a, sizeof(A))
#define REP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;  // Change according to needs
int main() {
int apples, applepieces;
cin>>apples>>applepieces;
cout<<(apples*3+applepieces)/2;
}

Measured memory_bytes: 256
Key_in = list(input())

output = []
for key in Key_in:
    if key == '0':
        output.append('0')
    elif key == '1':
        output.append('1')
    elif key =='B':
        if len(output) != 0:
            output.pop()
        else:
            pass

for char in output:
    print(char, end='')
print()

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

map<ll,ll> prime_factor(ll n){ //素因数分解
    map<ll,ll> table;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            table[i]++;
            n/=i;
        }
    }
    if(n!=1) table[n]=1;
    return table;// key->素因数, value->べき乗
}

int main(){
    ll N; cin >> N;
    map<ll,ll> ma=prime_factor(N);
    ll ans=0;
    for(auto it=ma.begin();it!=ma.end();it++){
        ll cur=it->first;
        while(true){
            N/=cur;
            cur*=it->first;
            ans++;
            //cout  << cur << " " << N << endl;
            if(N%cur!=0){
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF (1<<24)
main(){
  int n,m,k;
  int cost[302][302];
  int time[302][302];
  while(1){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++)
      for(int j=1;j<=m;j++){cost[i][j]=INF;time[i][j]=INF;}
    if(n==0 && m==0) break;
    for(int i=0;i<n;i++){
      int a,b,c,t;
      scanf("%d %d %d %d",&a,&b,&c,&t);
      cost[a][b]=c;
      cost[b][a]=c;
      time[a][b]=t;
      time[b][a]=t;
    }
    for(int i=1;i<=m;i++)
      for(int j=1;j<=m;j++)
	for(int l=1;l<=m;l++){
	  cost[j][l]=min(cost[j][l],cost[j][i]+cost[i][l]);
	  time[j][l]=min(time[j][l],time[j][i]+time[i][l]);
	}
      
    scanf("%d",&k);
    for(int i=0;i<k;i++){
      int p,q,r;
      scanf("%d %d %d",&p,&q,&r);
      if(r==0) printf("%d\n",cost[p][q]);
      else printf("%d\n",time[p][q]);
    }

  }
}

Measured memory_bytes: 1124
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <boost/range/adaptors.hpp>
#include <iomanip>

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

    std::vector<int> A(N, 0);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }
    // std::vector<int> distance(N, 0);
    int max_distance = -1;
    for (int i = 1; i < N; ++i) {
        // distance[i - 1] = A[i] - A[i - 1];
        max_distance = std::max(max_distance, A[i] - A[i - 1]);
    }
        max_distance = std::max(max_distance,K + A[0] - A[N - 1]);
    // distance[N - 1] = K + A[0] - A[N - 1];
    // for (int i = 0; i < N; ++i) {
    //     std::cout << distance[i] << std::endl;
    // }
    std::cout << K - max_distance << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define mp make_pair
#define mp3(a,b,c) mp(mp(a,b),c)
#define pii pair<int,int>
#define piii pair<pii,int>
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
const int mod=1e9+7;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%d",&x);return x;}
IL void gi(int &x){int _w=scanf("%d",&x);}
IL void write(int x){printf("%d\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
int n,m;
vector<int>g,f;
int main(){
	n=gi(),m=gi();
	g.resize(n+1);f.resize(n+1);
	g[1]=1;
	rep(i,1,n)f[i]=1;
	rep(i,1,m){
		int x=gi(),y=gi();
		if(g[x]==1){
			g[y]=1;
			if(f[x]==1)g[x]=0;
		}
		f[x]--;
		f[y]++;
	}
	int ans=0;rep(i,1,n)ans+=g[i];cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <limits.h>

int main(void) {
  int min, max, count, i, current;
  long int sum;
  scanf(" %d", &count);
  min = INT_MAX;
  max = INT_MIN;
  sum = 0;
  for (i = 0; i < count; i++) {
    scanf(" %d", &current);
    sum += current;
    if (min > current) {
      min = current;
    }
    if (max < current) {
      max = current;
    }
  }
  printf("%d %d %ld\n", min, max, sum);
}



Measured memory_bytes: 1792
///Coder ---->>>> Kael (Joan Marcos Rivera)
///Team ACM : CyberSpace ____ IPVCE FEDERICO ENGELS
///Copyright

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;

typedef unsigned long long ll;
typedef pair < int , int > par;

#define pb push_back
#define mp make_pair
#define s second
#define f first
#define maxn 510
#define eps 1e-9
#define mod 1000000007
#define less(n) order_of_key(n)
#define en_pos(n) find_by_order(n) /// --- >> iterador --- >> empieza en 0

ll dp[maxn][maxn],a[maxn];
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            dp[i][j]=1e17;

    for(int i=1;i<=n;i++)
        cin >> a[i],dp[i][i]=0,dp[i-1][i]=a[i-1]+a[i];

    for(int p=3;p<=n;p++){

        for(int i=1;i<=n;i++){
            int j=i+p-1;
            if(j > n)break;
            ll suma = 0;
            for(int k=i;k<=j;k++){
                suma += a[k];
            }
            for(int k=i;k<j;k++){
                dp[i][j]=min(dp[i][j],suma + dp[i][k] + dp[k+1][j]);
            }
        }
    }

    cout << dp[1][n];
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;

struct Solver {
	void solve() {
		int A, B, C, D;
		cin >> A >> B >> C >> D;

		for( int i = 1; A>0 && C>0; ++i ) {
			if( i&1 ) { C -= B; }
			else { A -= D; }
		}

		cout << (A>0 ? "Yes" : "No") << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();

	return 0;
}


Measured memory_bytes: 3648
#include <iostream>

#define SIZE 100001

struct HASH{
		int value[SIZE] = {0};
  	int MAX;
  	int nextMAX;
  	HASH(){
      	this->MAX = 0;
      	this->nextMAX = 0;
    }
  	void CountingValue(int x){
      	++this->value[x];
    }
  	void CountingHindou(){
    	int max_count = 0;
      	for(int i = 1; i < SIZE; i++){
        	int tmp = this->value[i];
          	if(tmp > max_count){
            		max_count = tmp;
              	this->MAX = i;
            }
        }

      	max_count = 0;
      	for(int i = 1; i < SIZE; i++){
          	if(i == this->MAX){
            	continue;
            }
          
        		int tmp = value[i];
          	if(tmp > max_count){
            		max_count = tmp;
              	this->nextMAX = i;
            }          	
        }
    }
};

int main(void){
		int n;
  	std::cin >> n;
  	HASH odd;
		HASH even;
  	for(int i = 0; i < n; i++){
      	int tmp;
      	std::cin >> tmp;
    		i%2 == 0 ? even.CountingValue(tmp) : odd.CountingValue(tmp);
    }
  	odd.CountingHindou();
  	even.CountingHindou();
  	if(odd.MAX != even.MAX) std::cout << n - odd.value[odd.MAX] - even.value[even.MAX];
  	else{
    	int diff_1 = odd.value[odd.MAX] + even.value[even.nextMAX];
      	int	diff_2 = even.value[even.MAX] + odd.value[odd.nextMAX];
      	diff_1 > diff_2 ? std::cout << n - diff_1 : std::cout << n - diff_2;
    }
  	return 0;
}


Measured memory_bytes: 1024
import sys; input = sys.stdin.readline
# n, m , k = map(int, input().split())
# matrix = [list(input().strip()) for _ in range(n)]

n = int(input())
lis = sorted(map(int, input().split()), reverse=True)
ans = lis[0]
i = 1
c = 1
while c<n-1:
	if c < n-1: ans += lis[i]; c+=1
	if c < n-1: ans += lis[i]; c+=1
	i+=1
print(ans)



Measured memory_bytes: 105112
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,M = mint()
C = []
for _ in range(M):
    s,c = mint()
    C.append([s,c])

for x in range(10**(N-1)-(N==1),10**N):
    x = str(x)
    if all([x[s-1]==str(c) for s,c in C]):
        print(x)
        exit()
print(-1)

Measured memory_bytes: 69108
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  if(a+b-c<0){
    if ((a + b - c) * (a + b - c) > 4LL * a * b) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
  
  /*√a+√b<√c
  =(√a+√b)^2<c
  =a+2√ab+b<c
  =a+b-c<-2√ab
  =(a+b-c)^2>4ab
  */
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

ll dp[2000002];

int main(){
    ll W,w[102],n,v[102],i,j;

    cin>>n>>W;

    for ( i = 0; i < n; i++)
    {
        cin>>w[i]>>v[i];
    }
    
    for ( i = 0; i < n; i++)
    {
        for ( j = W-w[i]; j >=0; j--)
        {
            dp[j+w[i]]=max(dp[j]+v[i],dp[j+w[i]]);
        }
    }

    cout<<dp[W]<<endl;

    return 0;
}

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

using P = pair<int,int>;
using ll = long long int;

int main() {
    int n;
    cin >> n;
    vector<string> str(n);
    for(int i=0;i<n;i++){
        cin >> str[i];
    }
    vector<P> v[2];
    for(int i=0;i<n;i++){
        int cnt = 0, mi = 0;
        for(int j=0;j<int(str[i].size());j++){
            if(str[i][j] == '(') cnt++;
            else cnt--;
            mi = min(mi, cnt);
        }
        if(cnt > 0) v[0].push_back(P(mi,cnt));
        else v[1].push_back(P(cnt-mi,cnt));
    }
    sort(v[0].rbegin(), v[0].rend());
    sort(v[1].rbegin(),v[1].rend());

    int x = 0;
    bool ok = true;
    for(auto p : v[0]){
        if(x+p.first < 0) ok = false;
        x += p.second;
    }
    for(auto p : v[1]){
        if(x-(p.first-p.second) < 0) ok = false;
        x += p.second;
    }
    if(x != 0) ok = false;
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3232
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long INT;
double PI = 3.14159265;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//
int rem[2019][2] = {};

int main(){
    string S;
    cin >> S;

    int n, num = 0,pow10[200010],nnum,sum = 0;
    n = S.size();
    pow10[0] = 1;
    rep(i, n-1)pow10[i + 1] = pow10[i] * 10 % 2019;

    rem[0][0] = 1;
    rep(i, n) {
        num = (num * 10 + (S[i] - '0')) % 2019;
        nnum = num * pow10[n - i - 1] % 2019;
        if (rem[nnum][0] > 0)rem[nnum][1] += rem[nnum][0];
        rem[nnum][0]++;
    }

    rep(i, 2019) if (rem[i][0] > 1)sum += rem[i][1];

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
 
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
 
int main(){





            int n;
    cin>>n;



 
    if(n==1)cout<<1<<endl;
    else if(2<=n&&n<4)cout<<2<<endl;
    else if(4<=n&&n<8)cout<<4<<endl;
    else if(8<=n&&n<16)cout<<8<<endl;
    else if(16<=n&&n<32)cout<<16<<endl;
    else if(32<=n&&n<64)cout<<32<<endl;
    else if(n>=64)cout<<64<<endl;


    
   
 
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<string> START = {"SS", "SW", "WS","WW"};
    string SW = "SW";

    rep(i, 4) {
        string t = START[i];
        FOR(j, 1, n - 1) {
            // t[j-1] == t[j+1]
            if((t[j] == 'S' && s[j] == 'o')
                || (t[j] == 'W' && s[j] == 'x')) {
                t += t[j - 1];
            }
            else {
                if(t[j - 1] == SW[0])
                    t += SW[1];
                else
                    t += SW[0];
            }
        }

        bool f = true;
        FOR(j, n - 1, n + 1) {
            if((t[j%n] == 'S' && s[j%n] == 'o')
                || (t[j%n] == 'W' && s[j%n] == 'x')) {
                if(t[(j + 1) % n] != t[(j - 1) % n]) f = false;
            }
            else {
                if(t[(j + 1) % n] == t[(j - 1) % n]) f = false;
            }
        }
        if(f) {
            cout << t << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 776
#include<iostream>
using namespace std;
int max(int a,int b){
  return (a<b)?b:a;
}
int main(){
  int n,v[101],w[101],W;
  int dp[101][10001];
  cin >> n>>W;
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }
  for(int i=0;i<=n;i++){
    for(int j=0;j<=W;j++){
      if(i==0||j==0)dp[i][j]=0;
      else if(j<w[i-1])dp[i][j]=dp[i-1][j];
      else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
    }
  }
  cout << dp[n][W]<<endl;
}



Measured memory_bytes: 6940
# B
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
D.sort()
T.sort()
cnt = 0
ans = "YES"
for i in range(M):
    now = T[i]
    for j in range(cnt, N):
        if now > D[j]:
            pass
        elif now == D[j]:
            cnt = j+1
            break
        else:
            ans = "NO"
            break
print(ans)

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

int main(){
	ll n,sum=0,a1;
	cin>>n;
	vector <ll> a(n);
	for(a1=0;a1<n;++a1){
		cin>>a[a1];
		sum+=a[a1];
	}
	sort(a.begin(),a.end());
	// cout<<max(sum,sum-(2*a[0]+2*a[1]));
	for(a1=0;a1+1<n;a1+=2){
		sum=max(sum,sum-(2*a[a1]+2*a[a1+1]));
	}
	cout<<sum;
	return 0;
}

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

using namespace std;

#define int long long
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define FI first
#define SE second
typedef pair< int,pair<int,pair<int, int> > > P3;
typedef pair<int, pair<int, int> > P2;
typedef pair<int, int> P1;
typedef tuple<int,int,int,int> T3;
typedef tuple<int,int,int> T2;
typedef tuple<int,int> T1;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int N;
int A[100005],B[100005];
int ans=0;

int func(int a,int b){
    if(a%b==0)return a;
    if(b==1)return a;
    if(a==0)return b;
    if(a<=b)return b;
    else if(a>b) return b+(a/b)*b;
}

signed main(){
    cin>>N;
    int t=0;
    for(int i=0;i<N;++i)cin>>A[i]>>B[i];
    for(int i=N-1;i>=0;--i){
        A[i]+=t;
        int cost=func(A[i],B[i])-A[i];
        //cout<<func(A[i],B[i])<<endl;
        ans+=cost;
        t+=cost;
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

/*

A, B, (S-A-B)
S-2A-B+C, C, 2A+B-2C
A+B-C, (S-B-C), (S-A-C)

S = 3C 
*/

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

  int A, B, C; cin >> A >> B >> C;
  int S = 3*C;
  cout << A << " " << B << " " << S-A-B << endl
	   << S-2*A-B+C << " " << C << " " << 2*A+B-2*C << endl
	   << A+B-C << " " << S-B-C << " " << S-A-C << endl;

  return 0;
}


Measured memory_bytes: 256