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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vli;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define I cin
#define O cout
#define EN endl
#define ln cout<<endl
#define pb(a) push_back(a)
#define x first
#define y second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main()
{
  llint ans = 100000;
  llint h, w;
  I >> h >> w;

  if(h % 3 == 0 || w % 3 == 0) {
    
    O << 0 << EN;
    
  } else {

    llint mx, mn;

    for(int j = 0; j < 2; j++) {
      swap(h, w);
      
      for(int i = 1; i < h; i++) {
	llint tmp = h;
	mx = i * w;
	h  -= i;
	
	if(h % 2 == 0 || w % 2 == 0) {
	  mn = h * w / 2;
	} else {
	  mx = max(max((w / 2) * h, (w - w / 2) * h), i * w);
	  mn = min(min((w / 2) * h, (w - w / 2) * h), i * w);
	  ans = min(ans, abs(mx - mn));
	  mx = max(max((h / 2) * w, (h - h / 2) * w), i * w);
	  mn = min(min((h / 2) * w, (h - h / 2) * w), i * w);
	}
	
	ans = min(ans, abs(mx - mn));
	h = tmp;
      }
    }
      
    O << ans << EN;
    
  }

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = Counter(a)
mc = c.most_common()[::-1]
if k >= len(mc):
    print(0)
else:
    ans = 0
    for i in range(len(mc) - k):
        ans += mc[i][1]
    print(ans)

Measured memory_bytes: 39352
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const int infi = 2147483647;
const ll infl = 1e17;

int main()
{
    ll n, m;
    cin>>n>>m;
    vvll cake(n, vll(3, 0));
    rep(i,n){
        cin >> cake[i][0] >> cake[i][1] >> cake[i][2];
    }
    vvll check = {{1, 1, 1},
                  {1, 1, -1},
                  {1, -1, 1},
                  {1, -1, -1},
                  {-1, 1, 1},
                  {-1, 1, -1},
                  {-1, -1, 1},
                  {-1, -1, -1}};
    ll ans = -infl;
    rep(i,8){
        ll xp = check[i][0], yp = check[i][1], zp = check[i][2];
        vll now(n);
        rep(j,n){
            now[j]=cake[j][0] * xp + cake[j][1] * yp + cake[j][2] * zp;
        }
        sort(all(now));
        ll res = 0;
        rep(j,m){
            res += now[n - 1 - j];
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(i, name)in(i)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(i,v) for(auto &i:(v))
#define all(v) (v).begin(),(v).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

ll power(ll a,ll n){ll ret=1;for(;n>0;n>>=1,a=a*a%MOD)if(n%2==1)ret=ret*a%MOD;return ret;}
ll comb(ll n,ll r){ll x=1,y=1;rep(i,0,r){x=x*(n-i)%MOD;y=y*(i+1)%MOD;}return x*power(y,MOD-2)%MOD;}

void solve() {
  VAR(ll, N, K);
  ll ans = 0;
  if (N != 3) {
    // return;
  }
  vl v1(N + 2);
  vl v2(N + 2);

  v1[1] = 0;
  rep(i, 2, N + 2) {
    v1[i] = v1[i - 1] + ll(i - 1);
  }

  v2[1] = N;
  rep(i, 2, N + 2) {
    v2[i] = v2[i - 1] + N - ll(i - 1);
    // print(v2[i]);
  }
  // print("");

  rep(i, K, N + 2) {
    ans %= MOD;
    // print(v1[i]);
    // print(v2[i]);
    ans += max(v2[i] - v1[i], 0LL) + 1LL;
    // ans += (v2[i-K] - i + 1) % MOD;
  }
  print(ans % MOD);
}


Measured memory_bytes: 6332
#include <vector>
#include <string>
#include <iostream>

std::vector<int> scan(std::vector<int> line) {
  auto scores = std::vector<int>(line.size(),0);
  int lead = -1;
  int cont = 0;
  for(int i = 0; i < line.size(); ++i) {
    if (line[i] == 1) {
      for(int j = lead+1; j < i; ++j) {
        scores[j] = cont;
      }
      cont = 0;
      lead = i;
      continue;
    }
    cont += 1;
  }
  for(int j = lead+1; j < line.size(); ++j) {
    scores[j] = cont;
  }
  return scores;
}

int main() {
  int H,W;
  std::cin >> H >> W;
  std::cerr << H << std::endl << W << std::endl;
  auto S = std::vector< std::vector<int> >(H);
  auto SS = std::vector< std::vector<int> >(H);
  for(int i = 0; i < H; ++i) {
    std::string s;
    std::cin >> s;
    auto line = std::vector<int>(W);
    for(int j = 0; j < W; ++j) {
      line[j] = s[j] == '.' ? 0 : 1;
    }
    S[i] = line;
    SS[i] = scan(line);
  }
  auto ST = std::vector< std::vector<int> >(W);
  for(int i = 0; i < W; ++i) {
    auto line = std::vector<int>(H);
    for(int j = 0; j < H; ++ j) {
      line[j] = S[j][i];
    }
    ST[i] = scan(line);
  }

  int ans = 0;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      auto v = SS[i][j] + ST[j][i] - 1;
      if (v > ans) { ans = v; }
    }
  }
  std::cout << ans << std::endl;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		stack<P>st;
		rep(i, n) {
			int d; scanf("%d", &d);
			if (!i)st.push(P(d, 1));
			else if (d == st.top().first)st.top().second++;
			else if (!(i & 1))st.push(P(d, 1));
			else {
				P p = st.top(); st.pop();
				if (st.empty())st.push(P(d, p.second + 1));
				else st.top().second += p.second + 1;
			}
		}
		int cnt = 0;
		while (!st.empty()) {
			P p = st.top(); st.pop();
			if (!p.first)cnt += p.second;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
using namespace std;	
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int n, x, t;

signed main() {
	cin >> n >> x >> t;
	cout << (n / x + !!(n % x)) * t;
}

Measured memory_bytes: 3628
n = int(input())

k = int(input())

keta = len(str(n))

dp = [[[0 for j in range(k+2)] for _ in range(2)]  for i in range(keta)]

s = str(n)

#dp[何桁目か][未満フラグ 0 = 未満][ゼロ以外のの個数]

x = int(s[0])
if x == 1:
    dp[0][1][0] = 1
else:
    dp[0][1][0] += 1
    dp[0][0][0] += x - 1


for index, c in enumerate(s[1:]):
    i = index + 1
    x = int(c)
    dp[i][0][0] += 9
    for j in range(k+1):
        dp[i][0][j] += dp[i - 1][0][j]
        if x == 0:
            dp[i][1][j] += dp[i - 1][1][j]
            dp[i][0][j + 1] += dp[i - 1][0][j] * 9
        elif x:
            dp[i][1][j + 1] += dp[i - 1][1][j]
            dp[i][0][j]     += dp[i - 1][1][j]
            dp[i][0][j + 1] += dp[i - 1][0][j] * 9
            dp[i][0][j + 1] += dp[i - 1][1][j] * (x - 1)
    # print(sum(dp[i][0]) + sum(dp[i][1]))
    # print(s[:index + 2])
    # print(dp)




print(dp[-1][0][k-1] + dp[-1][1][k-1])


Measured memory_bytes: 3192
# coding: utf-8
# Your code here!

n=int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

point = 0
before = -2
for a in al:
    if a - before == 1:
        point += cl[before - 1]
    before = a
    point += bl[a - 1]
print(point)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,w;
  while(cin>>n>>w,n+w){
    map<ll,ll>MP;
    for(int i=0;i<n;i++){
      ll a;cin>>a;
      MP[a/w]++;
    }
    double ans = 0;
    ll ma = 0;
    ll mapo = 0;
    for(auto a:MP){
      ma = max(ma,a.S);
      mapo = max(mapo,a.F);
    }
    for(auto a:MP){
      ans +=(double)((double)a.S/ma)*((double)(mapo-a.F)/mapo);
    }
    ans += 0.01;
    printf("%.10f\n",ans);
  }

  return 0;
}



Measured memory_bytes: 3156
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

ans = []
def operate(i, j, k, l):
    a[i][j] -= 1
    a[k][l] += 1
    ans.append([i+1, j+1, k+1, l+1])

for j in range(0, w):
    for i in range(0, h-1):
        if a[i][j]%2 == 1:
            operate(i, j, i+1, j)
for j in range(0, w-1):
    if a[h-1][j]%2 == 1:
       operate(h-1, j, h-1, j+1)

print(len(ans))
for i in ans:
    print("{} {} {} {}".format(i[0], i[1], i[2], i[3]))

Measured memory_bytes: 29804
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <typeinfo>
#include <stdlib.h>


using namespace std;


int main(int argc, char* argv[]){
  int n, max,max_diff=-2147483648, diff;
  cin >> n;
  // cout << "n = " << n << endl;
  std::vector<int> a(n+1), b(n+1);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  //最大値のリストb[]
  max = a[n-1];
  for(int i=n-1; i>0; i--){
    if (i==n-1){
      //何もしない
      b[i] = a[i];
    }else{
      if (a[i]>max){
        max = a[i];
      }
      b[i] = max;  
    }
  }

  for(int i=0; i<n-1; i++){
      diff = b[i+1]-a[i];
      // cout << "diff = " << diff << endl;
      if (diff > max_diff){
        max_diff = diff;
        // cout << "new max = " << max << endl;
      }
  }

  cout << max_diff << endl;
  return 0;
}



Measured memory_bytes: 4336
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    H, W = mi()
    C = [input() for i in range(H)]
    for i in range(H):
        print(C[i], C[i], sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 62864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vi vin(n);
    REP(i, n)
    {
        cin >> vin[i];
    }
    int mini, maxi;
    mini = vin[0];
    maxi = vin[0];
    int now = 1000;

    REP(i, n)
    {
        if (vin[i] < maxi)
        {
            now = (now - (now / mini) * mini) + (now / mini) * maxi;
            mini = vin[i];
            maxi = vin[i];
        }
        else
        {
            maxi = vin[i];
        }
    }
    if (mini < maxi)
    {
        now = (now - (now / mini) * mini) + (now / mini) * maxi;
    }
    cout << now << endl;

    return 0;
}

Measured memory_bytes: 3612
import math
import bisect
def seachPrimeNum(N):
    max = int(math.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

L=seachPrimeNum(10**5)
L=[i for i in L if (i+1)//2 in L]
Q=int(input())
for _ in range(Q):
    l,r=map(int,input().split())
    print(bisect.bisect_right(L,r) - bisect.bisect_left(L,l))

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

using namespace std;
#define ll long long

const int N = 1e5 + 5;
ll INF = 998244353;

void dfs(vector<vector<int>>& graph, vector<bool>&isVisited, int src)
{
    isVisited[src] = true;
    for(int i=0;i<graph[src].size();i++)
    {
        int id = graph[src][i];
        if(!isVisited[id])
            dfs(graph,isVisited,id);
    }
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;

    vector<vector<int>> graph(n);

    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        graph[a-1].push_back(b-1);
        graph[b-1].push_back(a-1);
    }

    vector<bool> isVisited(n, false);

    int count = 0;

    for(int i=0;i<n;i++)
    {
        if(!isVisited[i])
        {
            dfs(graph,isVisited, i);
            count++;
        }
    }

    cout<<count-1<<endl;
}


Measured memory_bytes: 9536
using System;
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var toll = ToInt32(input[1]);
        var start = ToInt32(input[2]);
        var gate = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var result = 0;
        var resultNum = 0;
        for(var i = 0; i < toll; i++)
        {
            if (gate[i] <= start) result++;
            else resultNum++;
        }
        WriteLine(Math.Min(result, resultNum));
    }
}



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

int main() {

	int n; cin >> n;

	for (int i = 1; i <= 9; i++) {
		int tmp = 111 * i;
		if (tmp < n) {
		}
		else{
			cout << tmp << endl;
			break;
		}
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

  vector<pii> v;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    v.pb(mp(a, b));
  }

  sort(all(v));

  ll ans = 0;
  int cnt = 0;
  for(auto u : v){
    int x = min(u.second, m-cnt);
    cnt += x;
    ans += (ll)u.first*x;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#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;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll inf =1LL << 62;

const int maxn=1000010;
bool prime[maxn];
bool dp[maxn];

int main(void){
	for(int i=2;i<maxn;i++)
		prime[i]=true;
	prime[0]=prime[1]=false;
	for(int i=2;i*i<maxn;i++)
		if(prime[i])
			for(int j=i*i;j<maxn;j+=i)
				prime[j]=false;

	int n,t;
	while(cin >> n >> t,n|t){
		clr(dp,0);
		dp[0]=true;
		int m;
		rep(i,n){
			cin >> m;
			rep(j,t+1){
				if(dp[j]&&j+m<=t)
					dp[j+m]=true;
			}
		}
		int ans=-1;
		rep(i,t+1)
			if(prime[i]&&dp[i])
				ans=i;
		if(ans!=-1)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

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

vector<int> g[200005];
ll val[200005];

void dfs(int p, int c, ll sum){
  val[c] += sum;
  for(auto v : g[c]){
    if(v!=p){
      dfs(c, v, val[c]);
    }
  }
}

int main() {
  int n,q;
  cin>>n>>q;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for(int i=0;i<q;i++){
    int p,x;cin>>p>>x;
    p--;
    val[p] += x;
  }
  dfs(-1, 0, 0);

  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<val[i];
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 24320
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{

        int a, b;

        string[] s = Console.ReadLine().Split(' ');
        a = int.Parse(s[0]);
        b = int.Parse(s[1]);

        Console.WriteLine("{0}",Gcd(a,b));

		//Console.WriteLine("");


	}

	public static int Gcd(int a, int b)
	{
		if (a < b)
			// ?????°?????\??????????????????????????????
			return Gcd(b, a);
		while (b != 0)
		{
			var remainder = a % b;
			a = b;
			b = remainder;
		}
		return a;
	}
}

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

int main()
{
    int n;
    cin>>n;
    int i,j,k=0,a[n+5];
    for(i=0;i<n;i++){
        cin>>a[i];
        k=k^a[i];
    }
    if(k==0){
        cout<<"Yes";
        
    }
    else{
        cout<<"No";
    }
    
    
    
}


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

int main() {
	int a,b;
	string s,i;
	cin >> i;
	a = stoi(i);
	while(cin >> s,s != "="){
		cin >> i;
		b = stoi(i);
		if(s == "+") a += b;
		else if(s == "-") a -= b;
		else if(s == "*") a *= b;
		else if(s == "/") a /= b;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
string a;
int b[15],q;
int main()
{
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]=='0'){q++;b[q]=0;}	
		if(a[i]=='1'){q++;b[q]=1;}
		if(a[i]=='B'&&q>=1)q--;	
	}	 
	for(int i=1;i<=q;i++)cout<<b[i];
	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_right
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[a[0]]
for i in range(1,n):
  aa.append(aa[-1]+a[i])

x=k
ans=0
for i in range(m):
  if x>=0:
    ans1=bisect_right(aa,x)+i
    ans=max(ans1,ans)
    x-=b[i]
if x>=0:
  ans1=bisect_right(aa,x)+m
  ans=max(ans1,ans)
print(ans)

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << ", ";
#define endln cerr << "\n";
#define chkpt cerr << "-----\n";

const int maxn = 1e5 + 5;
string s, t;
int difs[maxn];
int dift[maxn];

void solve() {
	cin >> s >> t;
	FOR(i, 0, sz(s)) {
		if (s[i] == 'A') {
			difs[i + 1] = difs[i] + 1;
		}
		else {
			difs[i + 1] = difs[i] - 1;
		}
	}
	FOR(i, 0, sz(t)) {
		if (t[i] == 'A') {
			dift[i + 1] = dift[i] + 1;
		}
		else {
			dift[i + 1] = dift[i] - 1;
		}
	}
	int q; cin >> q;
	while (q--) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		int x = (difs[b] - difs[a - 1]) - (dift[d] - dift[c - 1]);
		if (x % 3) {
			cout << "NO\n";
		}
		else {
			cout << "YES\n";
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using itn = int;

int main(void){
    int n,m;
    cin >> n >> m;
    int p[m],y[m];
    vector<pair<int,int>> v;
    for(int i = 0;i < m;i++){
        cin >> p[i] >> y[i];
        v.push_back(pair<int,int>(y[i],p[i]));
    }
    sort(v.begin(),v.end());
    
    int num[n+1];
    for(int i = 1;i <= n;i++)num[i] = 1;
    
    map<pair<int,int>,string> mp;
    for(int i = 0;i < m;i++){
        int a = 6 - to_string(v[i].second).size();
        string s;
        for(int i = 0;i < a;i++)s += "0";
        s += to_string(v[i].second);
        
        int b = 6 - to_string(num[v[i].second]).size();
        for(int i = 0;i < b;i++)s += "0";
        s += to_string(num[v[i].second]);
        num[v[i].second]++;
        
        mp[pair<int,int>(v[i].second,v[i].first)] = s;
    }
    
    for(int i = 0;i < m;i++)cout << mp[pair<int,int>(p[i],y[i])] << endl;
}

Measured memory_bytes: 13092
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

bool rec(vector<vector<bool>> &dp,vector<vector<bool>> &close,const vector<ll> &in,ll k,ll t){
    if(close[k][t]){
        return dp[k][t];
    }
    bool ret = false;
    for(int i = 0; i < in.size(); i++){
        if(k - in[i] >= 0){
            ret |= rec(dp,close,in,k-in[i],t^1);
        }
    }
    dp[k][t] = !ret;
    close[k][t] = true;
    return dp[k][t];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin >> n >> k;

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

    vector<vector<bool>> dp(k+1,vector<bool>(2)),close(k+1,vector<bool>(2,false));

    bool ans = rec(dp,close,in,k,0);

    if(!ans){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 23680
#include<stdio.h>

int main(void)
{
	int i;
	int j;
	int k;
	int count;
	int n;
	int x;
	
	while(1){
		scanf("%d %d", &n, &x);
		if(n == 0 && x == 0){
			break;
		}
		count = 0;
		for(i = 1;i <= n;i++){
			for(j = i;j <= n;j++){
				for(k = j;k <= n;k++){
					if(i + j + k == x && k != i && j != k && i != j){
						count++;
					}
				}
			}
		}
		printf("%d\n", count);
	}
	return (0);
}

Measured memory_bytes: 600
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	long N;
	cin >> N;
	vector<long long> H(N);
	for (long i = 0; i < N; ++i)
	{
		cin >> H[i];
	}
	bool result = true;
	long long before = 0;
	for (long i = 0; i < N; ++i)
	{
		if (before - H[i] > 1)
		{
			result = false;
			break;
		}
		else
		{
			if (before <= H[i])		before = H[i];
		}
	}
	cout << (result ? "Yes" : "No") << endl;
	return 0;
}


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

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        Double[] a = new Double[n+1];
        a[0] = 0d;
        double sum = 0;
        for(int i = 1; i <= n; i++){
            sum += Double.parseDouble(sc.next());
            a[i] = sum;
        }
        
        double middle = sum / 2;
        int l = lowerBound(a, middle);
        
        System.out.println((long)(Math.min(middle - a[l-1], a[l] - middle)*2));
    }
    
    private static int lowerBound(Double[] a, double key){
        
        return ~Arrays.binarySearch(a, key, (x, y) -> (x.compareTo(y) >= 0) ? 1 : -1);
    }
}

Measured memory_bytes: 63652
def main():
    s = input()

    def is_palin(s_):
        return s_ == "".join(list(reversed(s_)))

    n = len(s)
    if is_palin(s) and is_palin(s[:(n - 1) // 2]) and is_palin(s[(n + 3) // 2 - 1:]):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
template<typename T> ostream& operator<<(ostream& os, vector<T> a){os<<"( ";for(T &x:a)os<<x<<" ";os<<")\n";return os;}
template<typename T> ostream& operator<<(ostream& os, set<T> a){os<<"( ";for(T x:a)os<<x<<" ";os<<")\n";return os;}
template<typename T> ostream& operator<<(ostream& os, pair<T,T> a){os<<"("<<a.first<<" "<<a.second<<") ";return os;}
template<typename T> ostream& operator<<(ostream& os, complex<T> a){os<<"(r="<<a.real()<<" i="<<a.imag()<<") ";return os;}
typedef long long ll;
typedef double dd;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
#define all(a) a.begin(),a.end()
#define DEBUG 1
#define debug(a) if(DEBUG)cout<<#a<<" = "<<a<<endl
#define x first
#define y second
//===========================Head=========================//
const int nmax=100011, base=1000000007;
char s[nmax];

int n,A[nmax],AB[nmax],ABC[nmax];

int main(int argc,char** argv){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    scanf("%s",s+1);
    n=strlen(s+1);
    int qqq=1;
    for (int i=1;i<=n;++i){
        ABC[i]=ABC[i-1]*(s[i]=='?'?3LL:1LL)%base;
        if (s[i]=='C' || s[i]=='?') ABC[i]=(ABC[i]+AB[i-1])%base;
        AB[i]=AB[i-1]*(s[i]=='?'?3LL:1LL)%base;
        if (s[i]=='B' || s[i]=='?') AB[i]=(AB[i]+A[i-1])%base;
        A[i]=A[i-1]*(s[i]=='?'?3LL:1LL)%base;
        if (s[i]=='A' || s[i]=='?') A[i]=(A[i]+qqq)%base;
        if (s[i]=='?') qqq=qqq*3LL%base;
    }
    cout<<ABC[n];
}


Measured memory_bytes: 1536
k,a,b=map(int,input().split())
import sys

if k<a-1 or b-a <2:
  print(k+1)
  sys.exit()
if (k+1-a) %2 ==0:
  print(a+(b-a)*(k+1-a)//2)
else:
  print(a+(b-a)*((k-a)//2)+1)    


Measured memory_bytes: 61860
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(n, m) = sc.nextLine.split(" ").map(_.toInt)
    val sortedInput = List.fill(n, 2)(sc.nextLong).sortBy(_.head)

    println(sortedInput.foldLeft((0L, m.toLong)){
      case ((acc, mTemp), _) if mTemp == 0 => (acc, 0)
      case ((acc, mTemp), item) => {
        val numberOfBuying = Math.min(mTemp, item.last)
        (acc + item.head * numberOfBuying, mTemp - numberOfBuying)
      }
    }._1)
  }

}


Measured memory_bytes: 120792
#include<stdio.h>

int main()
{
	int a, b, res;
	scanf("%d %d", &a, &b);

	if(abs(b-a) % 2 == 0)
	{
		res = abs(b - a) / 2;
		if (a < b) res = a + res;
		else res = b + res;
		printf("%d", res);
	}

	else
	{
		printf("IMPOSSIBLE\n");
	}
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char S[6];
char res[10] = "0+0+0+0=7";
int main(){
  int i, j, mask;
  rd(S);
  for(i=0;i<4;i++){
    res[2*i] = S[i];
  }
  for(i=0;i<4;i++){
    S[i] -= '0';
  }
  for(mask=0;mask<1<<3;mask++){
    j = S[0];
    for(i=0;i<3;i++){
      if(mask&1<<i){
        j +=S[i+1];
      }
      else{
        j -=S[i+1];
      }
    }
    if(j==7){
      for(i=0;i<3;i++){
        if(mask&1<<i){
          res[2*i+1] ='+';
        }
        else{
          res[2*i+1] ='-';
        }
      }
      wt_L(res);
      wt_L('\n');
      break;
    }
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// char S[6];
// char res[10] = "0+0+0+0=7";
// {
//   int i, j, mask;
//   rd(S);
// 
//   rep(i,4) res[2i] = S[i];
//   rep(i,4) S[i] -= '0';
// 
//   rep(mask, 1<<3){
//     j = S[0];
//     rep(i,3) j if[mask&1<<i, +=, -=] S[i+1];
//     if(j==7){
//       rep(i,3) res[2i+1] = if[mask&1<<i, '+', '-'];
//       wt(res);
//       break;
//     }
//   }
// }


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

public class Main {

    long MAX = (long)1e15;

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

        int n = sc.nextInt(), w = sc.nextInt();
        int len = 1000 * n;
        long[] dp = new long[len + 1];
        long[] wn = new long[n];
        int[] vn = new int[n];

        Arrays.fill(dp, MAX);
        dp[0] = 0;

        for (int i = 0; i < n; i++) {
            wn[i] = sc.nextLong();
            vn[i] = sc.nextInt();
        }


        for(int j = 0; j < n; j++) for (int i = len; i >= 0; i--) if (dp[i] + wn[j] <= w && i + vn[j] <= len) {
            dp[i + vn[j]] = Math.min(dp[i + vn[j]], dp[i] + wn[j]);
        }

        long ans = 0;
        for (int i = len;; i--) if (dp[i] != MAX) {
            System.out.println(i);
            break;
        }
    }


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

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


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> parent;
std::vector<int> depth;

void dfs(int i, int prev) {
	parent[i] = prev;
	for (auto j : hen[i]) {
		if (j == prev) continue;
		depth[j] = depth[i] + 1;
		dfs(j, i);
	}
}

int main() {
	int n = ri();
	int u = ri() - 1;
	int v = ri() - 1;
	hen.resize(n);
	for (int i = 0; i + 1 < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	if (hen[v].size() == 1 && hen[v][0] == u) {
		std::cout << 0 << std::endl;
		return 0;
	}
	
	parent.resize(n);
	depth.resize(n);
	dfs(v, -1);
	int dist = depth[u];
	int d2 = std::max(0, (dist - 1) / 2);
	int t = u;
	for (int i = 0; i < d2; i++)
		t = parent[t];
	int tmp = parent[t];
	parent.assign(n, -1);
	depth.assign(n, 0);
	dfs(t, tmp);
	std::cout << (!(dist & 1)) + d2 + *std::max_element(depth.begin(), depth.end()) << std::endl;
	return 0;
}



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

int main() {
    int x, y;
    cin >> x >> y;
    vector<vector<int>> g { { 1, 3, 5, 7, 8, 10, 12 }, { 4, 6, 9, 11 }, { 2 } };
    string ans = "No";
    for (auto& e : g) {
        auto xin = find(begin(e), end(e), x);
        auto yin = find(begin(e), end(e), y);
        if (xin != end(e) && yin != end(e)) ans = "Yes";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner
 
object Main {
  def main(args:Array[String]):Unit = {
    val sc:Scanner = new Scanner(System.in)
    val tmp = Array(sc.nextInt(), sc.nextInt(), sc.nextInt())
 
    //if ((a == b && a < c) || (b == c && a > b) || (c == a && a < b)) {
    if (tmp.sorted sameElements Array(5, 5, 7)) {
      print("YES")
    } else {
      print("NO")
    }
  }
}

Measured memory_bytes: 25636
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    ll ans = 0;
    for(int i=0; i<n-1; i++){
        if(a[i] % 2 && a[i+1]){
            a[i]--, a[i+1]--;
            ans++;
        }

        ans += a[i] / 2;
    }

    ans += a[n-1] / 2;

    cout << ans << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
#ABC114 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
e = [0]*(n+1)
for i in range(2,n+1):
    cur = i
    for j in range(2,i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x: x >= m-1, e)))

ans = num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2) // 2
print(ans)


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast()    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	fast()
	string s;
	cin>>s;
	if(s[0]==s[1] &&s[1]==s[2])
	cout<<"No";
	if(s[0]!=s[1] || s[1]!=s[2]|| s[0]!=s[2])
	cout<<"Yes";
}
	
	
	
	


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if(y == NIL)root = z;

  else if(z->key < y->key)y->left = z;

  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u==NULL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char string[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", string);
    if ( string[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( string[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}



Measured memory_bytes: 25152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

ll gcd(ll a, ll b) {return(b?gcd(b,a%b):a);}

//エラストテネスの篩
struct sieve {
    int n;
    vector<int> f, primes;
    sieve(int n = 1) : n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; i++) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if(!f[j]) f[j] = i;
            }
        }
    }
    bool is_prime(int x) {return f[x] == x;}
    // 素因数分解したものを返す(12=2x2x3)
    vector<int> factor_list(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    // xが小さいときはエラストテネスの篩を用いて素因数分解
    vector<P> factor(int x) {
        vector<int> fl = factor_list(x);
        if (fl.size() == 0) return {};
        vector<P> res(1,P(fl[0],0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p,1);
            }
        }
        return res;
    }
    vector<pair<ll,int>> factor(ll x) {
        vector<pair<ll,int>> res;
        for (int p : primes) {
            int y = 0;
            while (x % p == 0) {
                x /= p;
                y++;
            }
            if (y != 0) res.emplace_back(p,y);
        }
        if (x != 1) res.emplace_back(x,1);
        return res;
    }
};

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    ll gd = 0;
    rep(i,n) gd = gcd(gd,a[i]);
    if (gd != 1) cout << "not coprime" << endl;
    else {
        set<int> st;
        sieve sv(1000000);
        rep(i,n) {
            auto data = sv.factor(a[i]);
            rep(j,data.size()) {
                if (st.count(data[j].first)) {
                    cout << "setwise coprime" << endl;
                    return 0;
                } else {
                    st.insert(data[j].first);
                }
            }
        }
        cout << "pairwise coprime" << endl;
    }
}

Measured memory_bytes: 11672
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
const int maxn = (ll) 3e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int T = 1;
int cntb, cnta, cntab;
int fac[maxn];

void solve() {
    fac[0] = 1;
    rep(i, 1, maxn - 1)fac[i] = fac[i - 1] * 2 % mod;
    map<pii, int> mp;
    int n;
    cin >> n;
    rep(i, 1, n) {
        int a, b;
        cin >> a >> b;
        if (a * b == 0) {
            if (a == 0 && b == 0)
                ++cntab;
            else if (a == 0)
                ++cnta;
            else if (b == 0)
                ++cntb;
            continue;
        }
        int d = __gcd(a, b);
        a /= d, b /= d;
        if (b < 0)
            a = -a, b = -b;
        mp[{a, b}]++;
    }
    int ans = ((fac[cnta] + fac[cntb] - 1) % mod + mod) % mod;
    for (auto &to:mp) {
        if (to.second == 0)
            continue;
        int a = to.first.first, b = to.first.second;
        int num = to.second;
        pii j = a > 0 ? pii(-b, a) : pii(b, -a);
        ans = ans * ((fac[num] + fac[mp[j]] - 1 + mod) % mod) % mod;
        mp[j] = 0;
    }
    cout << (ans - 1 + cntab + mod) % mod;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}
/*
6
 1 4
 1 4
 -4 1
 -3 1
 1 3
 1 3
 */

Measured memory_bytes: 30952
/* 
	بسم الله الرحمن الرحیم

	(; طلا یک جهانی
*/

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
typedef pair<int, int> pii;

const int MAX_N = 100 * 1000 + 5;
int n, a[MAX_N];

void read_input() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
}

int tah(vector<int> &vec) {
	int res = vec.back();
	vec.pop_back();
	return res;
}

void solve() {
	vector<int> pos, neg;
	for (int i = 0; i < n; i++)
		if (a[i] < 0)
			neg.push_back(a[i]);
		else
			pos.push_back(a[i]);
	reverse(pos.begin(), pos.end());
	if (neg.empty())
		neg.push_back(tah(pos));
	if (pos.empty())
		pos.push_back(tah(neg));
	int x = tah(neg);
	vector<pii> ans;
	while ((int)pos.size() > 1) {
		int t = tah(pos);
		ans.push_back({x, t});
		x -= t;
	}
	int t = tah(pos);
	ans.push_back({t, x});
	x = t - x;
	for (int i: neg) {
		ans.push_back({x, i});
		x -= i;
	}
	cout << x << endl;
	for (auto i: ans)
		cout << i.F << ' ' << i.S << endl;
}

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


Measured memory_bytes: 3828
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			int week = Integer.parseInt(br.readLine());

			BigDecimal interest = new BigDecimal("0.05");
			BigDecimal debt = new BigDecimal("100000");

			for (int i = 0; i < week; i++) {

				debt = debt.add(debt.multiply(interest))
						.setScale(-3, BigDecimal.ROUND_UP);

			}

			System.out.println(debt.toPlainString());

		} finally {
			br.close();

		}
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int n,cost,limit;
map<vector<int>,int> memo;
vector<vector<int> > LOOP;

int dfs(int cur,int cnt,vector<int> &remain){

  if( cur >= limit ) {
    return cnt;
  }

  if( memo.find(remain) != memo.end() ) return memo[remain];

  vector<int> tmp = remain;
  bool update = true;
  int ret = cnt;
  while( update ){
    ret = max(ret,dfs(cur+1,cnt,remain));
    cnt++;
    REP(i,1,10) {
      remain[i] -= LOOP[cur][i];
      if( remain[i] < 0 ) {
        update = false;
        break;
      }
    }
  }
  remain = tmp;
  return memo[remain] = ret;
}

void precalc(int value,int sum,vector<int> &vec) {
  if( value >= 10 ) {
    if( sum == 10 ) LOOP.push_back(vec);
    return;
  }
  rep(i,11){
    if( sum + i * value > 10 ) break;
    vec[value] = i;
    precalc(value+1,sum+i*value,vec);
    vec[value] = 0;
  }
  return;
}

int main() {

  vector<int> buf(10,0);
  precalc(1,0,buf);
  sort(LOOP.begin(),LOOP.end());

  while( cin >> n, n ) { 
    memo.clear();
    vector<int> remain;
    remain.resize(10);
    cost = limit = 0;
    int coef = 0,input;
    rep(i,n) {
      cin >> input;
      if( input == 10 ) coef++;
      if( input >= 10 ) continue;
      remain[input]++;
    }

    REP(i,1,5) {
      int tmp = min(remain[i],remain[10-i]);
      coef += tmp;
      remain[i] -= tmp, remain[10-i] -= tmp;
    }
    int tmp = remain[5] / 2;
    coef += tmp, remain[5] -= 2*tmp;
    limit = LOOP.size();

    cout << coef + dfs(0,0,remain) << endl;

  }
  return 0;
}

Measured memory_bytes: 7760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

void solve(){
    
}

int main()
{
    IO;
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    ll v;
    for(int i=0;i<m;i++){
        cin>>v;
        sum+=v;
    }
    if(sum>n)
        cout<<"-1"<<endl;
    else cout<<n-sum<<endl;
    return 0;
    
}   

Measured memory_bytes: 3652