akhauriyash/Code-Regression huggingface dataset:
B,W = map(int, input().split())
N = B+W
mod = 10**9+7

factorial = [1]
for i in range(N+1):
    factorial.append( factorial[-1] * (i+1) % mod)
# print(factorial)



de_factorial = [0] * (N+1)
de_factorial[N] = pow(  factorial[N] , mod-2, mod  )

for i in range( N, 0, -1):
    de_factorial[i-1] = de_factorial[i] * i % mod
    
def comb(n,r):
    if n < r: return 0
    if n == r: return 1
    return (factorial[n] * de_factorial[r] * de_factorial[n-r]) % mod


p = [0] * (N+1) # Bを食べきった確率
q = [0] * (N+1) # Wを食べきった確率

de2 = de_factorial[2]
for i in range(1, N+1):
    p[i] = p[i-1] + comb(i-1 ,B-1) * de2 % mod 
    q[i] = q[i-1] + comb(i-1 ,W-1) * de2  % mod 
    de2 = de2 * de_factorial[2] % mod

    tmp = ( q[i-1] + 1-p[i-1] ) * de_factorial[2] % mod
    
    print(tmp)

Measured memory_bytes: 32024
#include <iostream>
#include <algorithm>

int n, m;
int s[100005], t[100005];
int c[100005];
int tt[100005];
int sm[100005];
int num;
int main() {
	std::cin >> n >> m;
	for (int i = 0; i < n; ++i)
		std::cin >> s[i] >> t[i] >> c[i];

	for (int i = 1; i <= m; ++i) {
		std::fill(tt, tt + 100005, 0);

		for (int j = 0; j < n; ++j)
			if (i == c[j])
				++tt[s[j] - 1], --tt[t[j]];

		for (int j = 0; j < 100005 - 1; ++j)
			tt[j + 1] += tt[j];

		for (int j = 0; j < 100005; ++j)
			if (tt[j] > 0)
				++sm[j];
	}

	int ans = 0;
	for (int i = 0; i < 100005; ++i)
		ans = std::max(ans, sm[i]);
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>

using namespace std;

const double PI = 3.14159265358979323846;

int main() {
  int n;

  cin >> n;

  cout << 2 * PI * n << endl;

  return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    string S;
    cin >> S;
    int64_t s_size = S.size();
    int64_t split_count = 0;
    int skip_count = 0;
    for (int i=0; i<s_size; i++) {
        if (skip_count > 0) {
            skip_count--;
        } else {
            if (i<s_size-2) {
                split_count += 1;
                if (S[i] == S[i+1]) {
                    split_count += 1;
                    skip_count += 2;
                }
            } else if (i<s_size-1) {
                split_count += 1;
                if (S[i] == S[i+1]) {
                skip_count += 1;
                }
            } else {
                split_count += 1;
            }
        }
    }

    cout << split_count << endl;
    return 0;
}

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

int main(){
  int h,w,k,ans=0;
  cin>>h>>w>>k;
  char c[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>c[i][j];
    }
  }
  for(int i=0;i<pow(2,h);i++){
    bitset<6> a(i);
    for(int j=0;j<pow(2,w);j++){
      bitset<6> b(j);
      int now=0;
      for(int k=0;k<h;k++){
        for(int l=0;l<w;l++){
          if(!a.test(k) && !b.test(l) && c[k][l]=='#')now++;
        }
      }
      if(now==k)ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4096
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mx[400010],mn[400010],s[400010],t[400010];
void pushup(int x){
	mx[x]=max(mx[x<<1],mx[x<<1|1]);
	mn[x]=min(mn[x<<1],mn[x<<1|1]);
	s[x]=s[x<<1]+s[x<<1|1];
}
void gao(int x,int len,ll v){
	mx[x]=mn[x]=v;
	s[x]=len*v;
	t[x]=v;
}
void pushdown(int x,int ln,int rn){
	if(t[x]){
		gao(x<<1,ln,t[x]);
		gao(x<<1|1,rn,t[x]);
		t[x]=0;
	}
}
void modify(int L,int R,ll v,int l,int r,int x){
	if(L<=l&&r<=R)return gao(x,r-l+1,v);
	int mid=(l+r)>>1;
	pushdown(x,mid-l+1,r-mid);
	if(L<=mid)modify(L,R,v,l,mid,x<<1);
	if(mid<R)modify(L,R,v,mid+1,r,x<<1|1);
	pushup(x);
}
ll query(int L,int R,int l,int r,int x){
	if(L<=l&&r<=R)return s[x];
	int mid=(l+r)>>1;
	ll s=0;
	pushdown(x,mid-l+1,r-mid);
	if(L<=mid)s+=query(L,R,l,mid,x<<1);
	if(mid<R)s+=query(L,R,mid+1,r,x<<1|1);
	return s;
}
int query(ll v,int l,int r,int x){
	if(l==r)return l;
	int mid=(l+r)>>1;
	pushdown(x,mid-l+1,r-mid);
	if(mn[x<<1]<=v)return query(v,l,mid,x<<1);
	return query(v,mid+1,r,x<<1|1);
}
void dfs(int l,int r,int x){
	if(l==r){
		printf("%lld\n",s[x]);
		return;
	}
	int mid=(l+r)>>1;
	pushdown(x,mid-l+1,r-mid);
	dfs(l,mid,x<<1);
	dfs(mid+1,r,x<<1|1);
}
int main(){
	int n,m,x,p;
	ll y,l,r,mid,ans,t;
	scanf("%d%d",&n,&m);
	while(m--){
		scanf("%d%lld",&x,&y);
		l=query(x,x,1,n,1);
		r=query(1,1,1,n,1)+y;
		while(l<=r){
			mid=(l+r)>>1;
			p=query(mid,1,n,1);
			t=(x-p+1)*mid-query(p,x,1,n,1);
			if(t<=y){
				ans=mid;
				l=mid+1;
			}else
				r=mid-1;
		}
		p=query(ans,1,n,1);
		y-=(x-p+1)*ans-query(p,x,1,n,1);
		modify(p,x,ans,1,n,1);
		if(y)modify(p,p+y-1,ans+1,1,n,1);
	}
	dfs(1,n,1);
}

Measured memory_bytes: 13824
#include<bits/stdc++.h>
using namespace std;
int W, n, v[100010], w[100010];
long long dp[100010][101];
int main()
{
	cin>>n>>W;
	for (int i = 1; i <= n; ++i){
		scanf("%d %d", &w[i], &v[i]);
	}
	for (int i = 1; i <= W; ++i){
		for (int j = 1; j <= n; ++j){
			dp[i][j] = dp[i][j-1];
			if (i - w[j] >= 0)
				dp[i][j] = max(dp[i-w[j]][j-1] + v[j], dp[i][j-1]);
		}
	}
	cout<<dp[W][n]<<endl;
	return 0;
} 

Measured memory_bytes: 79104
n = int(input())
s = input()

ruiseki_w = [0]
ruiseki = 0
for i in s[:-1]:
    if i == 'W':
        ruiseki += 1
        ruiseki_w.append(ruiseki)
    else:
        ruiseki_w.append(ruiseki)

ruiseki_e = [0]
ruiseki = 0
for i in s[::-1][:-1]:
    if i == 'E':
        ruiseki += 1
        ruiseki_e.append(ruiseki)
    else:
        ruiseki_e.append(ruiseki)
ruiseki_e.reverse()
        
ninzu = [ruiseki_w[i] + ruiseki_e[i] for i in range(n)]
print(min(ninzu))

Measured memory_bytes: 29984
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
    if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}


int main()
{
  string Str;
  vector<string> ans;
  int a,b;
  
  getline(cin, Str);


  ans = split(Str,' ');

  
  a = stoi(ans[0]);
  b = stoi(ans[2]);

  if(ans[1]=="+")
    printf("%d\n",a+b);
  else
    printf("%d\n",a-b);

  
  return 0;
}


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

using namespace std;

int main(){
  int N,i;
  cin >> N;
  long int total,A[N];
  for(i=0;i<N;i++){
    cin >> A[i];
  }
  total=0;
  
  for(i=1;i<N;i++){
    if(A[i]<A[i-1]){
      total=total+A[i-1]-A[i];
      A[i]=A[i-1];
    }
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 5196
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import product
def main():
    n=int(input())
    A=[[int(_) for _ in input().split()] for i in range(n)]
    dp=[0]*(1<<n)
    dp[0]=1
    mod=10**9+7
    for s in range(1<<n):
        i=bin(s).count("1")
        for j in range(n):
            if (s>>j)&1 and A[i-1][j]==1:
                dp[s]=(dp[s]+dp[s^(1<<j)])%mod
    print(dp[(1<<n)-1])

if __name__=='__main__':
    main()

Measured memory_bytes: 57964
#include<stdio.h>
int main(){
	int a,b,c;
	int t;
	scanf ("%d %d %d",&a,&b,&c);
	
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	if(b>c){
		t=b;
		b=c;
		c=t;
	}
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	printf ("%d %d %d\n",a,b,c);
	
	
return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main()
{
	long long int n, ctr = 0;
	char str[101] = {};
	char str2[101] = {};
	scanf("%lld", &n);
	for(int i = 0; n > 0; i++)
	{
		if(n%26 == 0)
		{
			n/=26;
			n--;
			str[i] = 'z';
			ctr++;
		} else
		{
			str[i] = n%26+96;
			n/=26;
			ctr++;
		}
	}
	for(int i = 0; i < ctr; i++)
	{
		str2[i] = str[i];
		str2[i] = str[ctr-i-1];
	}
	printf("%s", str2);
	return 0;
}

Measured memory_bytes: 1716
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 200005

int N,K;
double table[SIZE];

int main(){

	scanf("%d %d",&N,&K);

	double tmp;
	for(int i = 0; i < N; i++){

		scanf("%lf",&tmp);
		table[i] = (tmp+1.0)/2.0;
	}

	double ans = 0,work = 0;
	for(int i = 0; i < K; i++){

		work += table[i];
	}
	ans = work;

	for(int i = 1; i+K-1 < N; i++){

		work -= table[i-1];
		work += table[i+K-1];
		ans = max(ans,work);
	}

	printf("%.10lf\n",ans);

	return 0;
}


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

int main(){
  string str;
  cin >> str; 
  
  for (int i = 0; i < 19; i++)
  {
    if (str.at(i) == *","){
      str.at(i) = *" ";
    }
  }
  cout << str << endl;
}


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

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

using namespace std;

int month[] = {0, 0, 20, 39, 59, 78, 98, 117, 137, 156, 176, 195, 215, 234 };

int year(int y) {
    int sum = 0;
    for ( int i = 1; i < y; i++ ) {
        if ( i%3 == 0 ) sum += 200;
        else sum += 195;
    }
    return sum;
}

int getdate(int y, int m, int d) {
    return year(y) + (y%3==0? (m-1)*20 : month[m]) + d;
}
int _old(int y, int m, int d) {
    return y * 195 + (y/3) * 5 + month[m] + d;
}

int main() {
    int n, y, m, d;
    int today = getdate(1000, 1, 1);
    // int _today = _old(1000, 1, 1);

    cin >> n;
    while(n--) {
        int sub = 0;
        cin >> y >> m >> d;

        sub = today - getdate(y, m, d);
        cout << sub << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
d, n = map(int,input().split())

if d == 0:
    if n < 100:
        print(n)
    if n == 100:
        print(101)
if d == 1:
    if n < 100:
        print(n * 100)
    if n == 100:
        print(10100)
if d == 2:
    if n < 100:
        print(n * 10000)
    if n == 100:
        print(1010000)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
  	ll N;
  	cin>>N;
  
  	cout<<N*(N-1)/2<<endl;
  	
  	
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exist(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}
inline ll modpow(ll x, ll y) {
    ll res = 1;
    while(y) {
        if(y&1) res = mul(res,x);
        y >>= 1;
        x = mul(x,x);
    }
    return res;
}

int main(){
    string s; cin >> s;
    cout << string(s.size(),'x') << endl;
    return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});
/*
process.on('SIGINT', function(){
    input_stdin_array = input_stdin.split("\n");
    main();
    process.exit();
});
*/
process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////


function main() {
	var s = readLine();
	var alpha = "qwertyuiopasdfghjklzxcvbnm";
	var cont = {};
	
	/*Initialazing asociative array cont*/
	for (var i=0; i < alpha.length; i++){
		cont[alpha.charAt(i)]=0;
	}
	
	for (var i=0; i < s.length; i++){
		cont[s.charAt(i)]++;
	}
	
	for (var i=0; i < alpha.length; i++){
		if (cont[alpha.charAt(i)]%2 == 1){
			console.log("No");
			return;
		}
	}
	console.log("Yes");
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];

  ll m;
  cin >> m;

  REP(i,m){
    ll k;
    cin >> k;
    ll lb, ub;
    ll lef, rig;

    lef = -1; rig = n;
    while(rig - lef > 1){
      ll mid = (lef + rig) / 2;
      if(a[mid] >= k) rig = mid;
      else lef = mid;
    }
    lb = rig;

    lef = -1; rig = n;
    while(rig - lef > 1){
      ll mid = (lef + rig) / 2;
      if(a[mid] > k) rig = mid;
      else lef = mid;
    }
    ub = rig;

    //cout << lb << " " << ub << endl;
    if(lb == ub){
      cout << 0 <<endl;
      return 0;
    }
  }

  cout << 1 <<endl; 
  return 0;
}




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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll a, b;
  cin >> a >> b;
  ll c;
  c = b - a;
  ll sum = 0;
  for(int i = 1; i < c; i++) {
    sum += i;
  }
  cout << sum - a << endl;
	return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n,a,b;
    cin>>n>>a>>b;
    string s; cin>>s;
    for (int i=0;i<n;i++){
        if (s[i]=='a' and a+b){
            cout << "Yes"<<endl;
            if (a) a--;
            else b--;
        }
        else if (s[i]=='b' and b){
            cout << "Yes"<<endl;
            b--;
        }
        else cout << "No" << endl;
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3688
#include <memory>
#include <map>
#include <cassert>
#include <array>
#include <iterator>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <array>
#include <numeric>

class Solution {
public:
    std::vector<std::vector<int>> v;
    std::vector<bool> visited;
    void dfs (int k, int steps)
    {
      visited[k] = true;
      if (steps == 2)
        return;

      for (auto next : v[k])
        if (!visited[next])
          dfs(next, steps + 1);
    }

    void solve(std::istream& in, std::ostream& out) {
      int n, m;
      in >> n >> m;
      v.resize (n);
      visited.resize(n);
      for (int i = 0; i < m; ++i)
      {
        int a, b;
        in >> a >> b; --a; --b;
        v[a].push_back(b);
        v[b].push_back(a);
      }
      dfs (0, 0);
      if (visited[n - 1])
        out << "POSSIBLE\n";
      else
        out << "IMPOSSIBLE\n";
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

#include <iostream>

int main ()
{
  solve (std::cin, std::cout);
}


Measured memory_bytes: 12016
import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Scanner;
     
    public class Main {
     
    static Scanner sc = new Scanner(System.in);
    static int N;
    static int R;
    static long[] x, y;
     
    static int solve() {
    HashSet<Grid> set = new HashSet<Grid>();
    for (int i = 0; i < N; ++i) {
    Grid grid = new Grid(x[i], y[i]);
    set.add(grid);
    }
    int ans = 0;
    Iterator<Grid> itr = set.iterator();
    HashSet<Grid> visited = new HashSet<Grid>();
    while (itr.hasNext()) {
    Grid cur = itr.next();
    if (visited.contains(cur)) continue;
    ++ans;
    for (int i = -1; i <= 1; ++i) {
    for (int j = -1; j <= 1; ++j) {
    Grid grid = new Grid();
    grid.xl = cur.xl + i;
    grid.yl = cur.yl + j;
    if (set.contains(grid)) {
    visited.add(grid);
    }
    }
    }
    }
    return ans;
    }
     
    static class Grid {
    long xl, yl;
    boolean visited = false;
     
    Grid(long x, long y) {
    this.xl = x / R;
    this.yl = y / R;
    }
     
    Grid() {}
     
    public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + (int) (xl ^ (xl >>> 32));
    result = prime * result + (int) (yl ^ (yl >>> 32));
    return result;
    }
     
    public boolean equals(Object obj) {
    Grid other = (Grid) obj;
    if (xl != other.xl) return false;
    if (yl != other.yl) return false;
    return true;
    }
     
    }
     
    public static void main(String[] args) {
    N = sc.nextInt();
    R = toInt(sc.next());
    x = new long[N];
    y = new long[N];
    for (int i = 0; i < N; ++i) {
    x[i] = toInt(sc.next()) + (long) 1e9;
    y[i] = toInt(sc.next()) + (long) 1e9;
    }
    System.out.println(solve());
    }
     
    static int toInt(String ds) {
    return Integer.parseInt(ds.replaceAll("\\.", ""));
    }
     
    }

Measured memory_bytes: 36000
#include <vector>
#include <iostream>
using namespace std;
int n, a[10001]; 

int gcd(int a, int b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (a < b) swap(a, b);
    while (b > 0) {
        int t = a; a = b; b = t % b;
    }
    return a;
}

void check(int p) {
    if (a[0] % p) return;
    for (int i = 0; i <= min(n, p-1); i++) {
        long long sum = 0;
        for (int k = i; k <= n; k += p-1) sum += a[k];
        if (sum % p) { return; }
    }
    cout << p << endl;
}

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

    vector<bool> b(10001, true);
    vector<int> primes;
    for (int p = 2; p < b.size(); p++) {
        if (b[p]) {
            check(p);
            primes.push_back(p);
            for (int q = p*p; q < b.size(); q += p) b[q] = false;
        }
    }
    int g = a[0];
    for (int i = 1; i <= n; i++) g = gcd(a[i], g);
    for (int p : primes) while (g % p == 0) g /= p;
    if (g > 1) cout << g << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int c1, c2, c3;
			c1 = c2 = c3 = 0;
			if (line.length() < 6) {
				System.out.println("INVALID");
			} else {
				for (char c : line.toCharArray()) {
					if (c >= '0' && c <= '9') {
						c1++;
					} else if (c >= 'A' && c <= 'Z') {
						c2++;
					} else {
						c3++;
					}
				}
				if (c1 > 0 && c2 > 0 && c3 > 0) {
					System.out.println("VALID");
				} else {
					System.out.println("INVALID");
				}
			}
		}
	}
}

Measured memory_bytes: 17064
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
using namespace std;
long long a[405];
long long x[405][4];
long long c[405][10];
map<long long,int>m;
long long get(long long x,long long y,long long z,long long h)
{
    long long ret = x;
    ret = (ret<<10)+y;
    ret = (ret<<10)+z;
    ret = (ret<<10)+h;
    return ret;
}
long long pack(long long x,long long y,long long z,long long h)
{
    return min(min(get(x,y,z,h),get(y,z,h,x)),min(get(z,h,x,y),get(h,x,y,z)));
}
long long fac(long long x)
{
    long long ret = 1;
    FOR(i,1,x)ret*=i;
    return ret;
}
long long rot(long long key)
{
    int k[4];
    FOR(i,0,3)
    {
        k[i] = key&((1<<10)-1);
        key>>=10;
    }
    if(k[0] == k[1]&&k[1] == k[2]&&k[2] == k[3])return 4;
    if(k[0] == k[2]&&k[1] == k[3])return 2;
    return 1;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
        c[1][0] = c[1][1] = 1;
        FOR(i,2,n)
        {
            c[i][0] = 1;
            FOR(j,1,min(4,i-1))c[i][j] = c[i-1][j]+c[i-1][j-1];
            c[i][i] = 1;
        }
        FOR(i,1,n)
        {
            FOR(j,0,3)cin>>x[i][j];
            a[i] = pack(x[i][0],x[i][1],x[i][2],x[i][3]);
        }
        long long ans = 0;
        m.clear();
        FOR(i,1,n)
        {
            FOR(ii,1,i-1)
            {
                FOR(j,0,3)
                {
                    long long y[4];
                    y[0] = pack(x[ii][(j+1)%4],x[ii][(j+0)%4],x[i][1],x[i][0]);
                    y[1] = pack(x[ii][(j+0)%4],x[ii][(j+3)%4],x[i][2],x[i][1]);
                    y[2] = pack(x[ii][(j+3)%4],x[ii][(j+2)%4],x[i][3],x[i][2]);
                    y[3] = pack(x[ii][(j+2)%4],x[ii][(j+1)%4],x[i][0],x[i][3]);
 
                    sort(y,y+4);
                    long long ret = 1;
                    for(int p = 0;p<4;)
                    {
                        int cnt = 1;
                        for(int r = p+1;r<4&&y[r] == y[p];r++)cnt++;
                        int num = m.count(y[p])?m[y[p]]:0;
                        if(y[p] == a[ii])num--;
                        if(num<cnt)
                        {
                            ret = 0;
                            break;
                        }
                        ret*=c[num][cnt]*pow(rot(y[p]),cnt)*fac(cnt);
                        p+=cnt;
                    }
                    ans+=ret;
                }
            }
            if(m.count(a[i]))m[a[i]]++;
            else m[a[i]] = 1;
        }
        cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
SA=[]
SB=[]
goukeiA=0
goukeiB=0
for i in range(N):
    goukeiA+=A[i]
    SA.append(goukeiA)
for i in range(M):
    goukeiB+=B[i]
    SB.append(goukeiB)

#def binary_search()
Mcount=0



for i in range(N+1):
    if i!=N:
        
    
        count=0
        nokori=K-SA[i]
        if nokori >=0 and nokori >=SB[M-1]:
            count+=i+1+M
        elif nokori >=0:
            count+=i+1
            tmp=nokori
            left=0
            right=M-1
            #flag=False
            while left<=right:
                #print("mohu")
                mid=(left+right)//2
                if SB[mid]<=nokori and SB[mid+1]>nokori:
                    count+=mid+1
                    #print("es",count,mid)
                    break
                elif SB[mid]>nokori:
                    #print(nokori,mid)
                    right=mid-1
                elif SB[mid]<nokori:
                    #print(nokori,mid)
                    left=mid+1
                else:
                    print("イレギュラーな例につかまりました")
                    exit()
    else:
        count=0
        nokori=K
        if nokori >=SB[M-1]:
            count+=M
        elif nokori >0:
            tmp=nokori
            left=0
            right=M-1
            #flag=False
            while left<=right:
                #print("mohu")
                mid=(left+right)//2
                if SB[mid]<=nokori and SB[mid+1]>nokori:
                    count+=mid+1
                    #print("es",count,mid)
                    break
                elif SB[mid]>nokori:
                    #print(nokori,mid)
                    right=mid-1
                elif SB[mid]<nokori:
                    #print(nokori,mid)
                    left=mid+1
                else:
                    print("イレギュラーな例につかまりました")
                    exit()        
    
    if Mcount<count:
        #print("kita",count)
        Mcount=count
            
    
        
print(Mcount)



Measured memory_bytes: 126484
n = int(input())
a = list(map(int, input().split()))

if 0 in a:
    ans = 0
    for x in a:
        ans += abs(x)
    print(ans)
    exit()

c = 0
for i in range(n):
    if a[i] < 0:
        a[i] *= -1
        c += 1

if c % 2 == 0:
    print(sum(a))
else:
    print(sum(a) - (min(a) * 2))

Measured memory_bytes: 14412
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll cou[15][15];

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

  cin >> n;
  rrep(i, 1, n + 1) {
    s = to_string(i);
    ll fr = s[0] - '0', af = s[Size(s) - 1] - '0';
    cou[fr][af]++;
  }
  rrep(i, 1, n + 1) {
    s = to_string(i);
    ll af = s[0] - '0', fr = s[Size(s) - 1] - '0';
    if (fr == 0) continue;
    ans += cou[fr][af];
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 256
from itertools import product

n = int(input())
xy = [[] for i in range(n)]

for i in range(n):
    for j in range(int(input())):
        xy[i].append(list(map(int, input().split())))

ans = 0
for bit in product([0, 1], repeat=n):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x - 1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)


Measured memory_bytes: 9224
#include <stdio.h>

int main(){
  
  char s[100],*p;
  
  scanf("%s",s);
  p = s;
  do{
    p++;  
  }while(*p != '\0');
  
  do{
    p--;
    printf("%c",*p);
  }while(p != s);
  printf("\n");
  return 0; 

}

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

#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define ABS(X) ((X)>0?(X):-(X))

int main(){
  int n, t, a, h , ans;
  double minDif;
  
  cin >> n >> t >> a;
  minDif = 1<<19;
  for (int i=0; i<n; i++){
    double h, ti;
    cin >> h;
    ti = t - 0.006*h;
    minDif = MIN(minDif, ABS(a-ti));
    //cout << ABS(a-ti) << " " << minDif << endl;
    if (minDif==ABS(a-ti)) ans = i+1;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	
	int n;
	cin >> n;
	vector<tuple<string, int, int>> p(n);
	rep(i, n){
		string s;
		int a;
		cin >> s >> a;
		p[i] = make_tuple(s, 100 - a, i);
	}
	sort(p.begin(), p.end());
	rep(i, n){
		cout << get<2>(p[i]) + 1 << endl;
	}
	
	return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;

    char s[60][60];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> s[i][j];
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (s[i][j] != '#') continue;
            bool isDrawable = false;
            if (i > 0) {
                if (s[i-1][j] == '#') isDrawable = true;
            }
            if (i < H-1) {
                if (s[i+1][j] == '#') isDrawable = true;
            }
            if (j > 0) {
                if (s[i][j-1] == '#') isDrawable = true;
            }
            if (j < W-1) {
                if (s[i][j+1] == '#') isDrawable = true;
            }
            if (!isDrawable) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int l[N];

int main() {
	int n,k; cin>>n>>k;
	rep(i,n) cin>>l[i];
	sort(l,l+n,greater<int>());
	int ans=0;
	rep(i,k) ans+=l[i];
	cout<<ans<<endl;
}


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 4000000000;
constexpr auto MOD = 1000000007;

int n, a, b;

ll lpow(ll l, ll m) {
	ll hoge = 1;
	ll piyo = l;
	while (m) {
		if (m % 2) hoge *= piyo;hoge %= MOD;
		m /= 2;
		piyo *= piyo; piyo %= MOD;
	}
	return hoge;
}


ll com(int i, int j) {
	ll t = 1, b = 1;
	rep(k, j) {
		t *= (ll)i - j + k + 1; t %= MOD;
		b *= (ll)k + 1; b %= MOD;
	}
	return (t * lpow(b, MOD - 2))%MOD;
}



int main() {

	cin >> n >> a >> b;

	ll ans = 0;
	ans += lpow(2, n);
	ans--;
	ans += MOD - com(n, a);ans %= MOD;
	ans += MOD - com(n, b);ans %= MOD;

	cout << ans << endl;
}

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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


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

  ll ans = 1e15;
  for(ll i = 1; i*i <= n; i++){
    if(n%i == 0){
      ans = min<ll>(ans,(n/i - 1 ) + (i-1));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

const ll MOD = 1e9 + 7;
const ll MAXC = 2 * 1e5;
void mainsolve(){
	ll n;
	cin >> n;
	vector<ll> c(n);
	rep(i,n) cin >> c[i];
	vector<vector<ll>> memo(MAXC);
	rep(i,n){
		memo[--c[i]].push_back(i);
	}

	vector<ll> dp(n);
	dp[n-1] = 1;

	for(ll i = n-2; i >= 0; i--){
		dp[i] = dp[i+1] % MOD;
		if(c[i] == c[i+1]) continue;
		//if(memo[c[i]].empty()) continue;
		auto loc = upper_bound(memo[c[i]].begin(), memo[c[i]].end(), i+1);
		if(loc != memo[c[i]].end() && *loc <= n-1) dp[i] = (dp[i] + dp[*loc]) % MOD;
	}
	cout << dp[0] << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
struct node{
    int x,y,id;
}a[100010];
struct edge{
    int a,b,w;
}e[200010];
bool cmp(edge a,edge b){
    return a.w<b.w;
}
bool cmpx(node a,node b){
    return a.x<b.x;
}
bool cmpy(node a,node b){
    return a.y<b.y;
}
int pre[200010];
int find(int x){
    return pre[x]=(x==pre[x]?x:find(pre[x]));
}
int main(){
//    freopen("B-small-attempt1.in","r",stdin);
//    freopen("output.txt","w",stdout);
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].x>>a[i].y;
        a[i].id=i;
    }
    sort(a,a+n,cmpx);
    int cnt=0;
    for(int i=1;i<n;i++,cnt++){
        e[cnt].a=a[i-1].id;
        e[cnt].b=a[i].id;
        e[cnt].w=a[i].x-a[i-1].x;
    }
    sort(a,a+n,cmpy);
    for(int i=1;i<n;i++,cnt++){
        e[cnt].a=a[i-1].id;
        e[cnt].b=a[i].id;
        e[cnt].w=a[i].y-a[i-1].y;
    }
    for(int i=0;i<n;i++)
        pre[i]=i;
    sort(e,e+cnt,cmp);
    LL ans=0;
    int tot=0;
    for(int i=0;i<cnt&&tot+1<n;i++){
        int u=e[i].a,v=e[i].b;
        int fa=find(u),fb=find(v);
        if(fa!=fb){
            pre[fa]=fb;
            ans+=e[i].w;
            tot++;
        }
    }
    cout<<ans<<endl;
	return 0;
}
/*
*/


Measured memory_bytes: 4224
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
	        String s = kb.readLine();
	        String p = kb.readLine();
	        
	        int slen = s.length();
	        int plen = p.length();
	        int j = 0;
			for( int i = 0; i<slen; i++ ) {
				if( p.charAt( 0 ) == s.charAt( i ) ) {
					int ij = i;
					for( j = 0; j<plen; j++ ) {
						ij = ( i+j ) % slen;
						if( p.charAt( j ) != s.charAt( ij ) ) {
							break;
						}
					}
				}
				if( plen == j ) { break; }
			}
			
			if( plen == j ) {
				System.out.println( "Yes" );			
			} else {
				System.out.println( "No" );
			}
		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 17060
package main
import(
  "fmt"
  "strconv"
  "os"
  "bufio"
)
func main(){
  var(
    a int
    b []int
  )
  scanner:=bufio.NewScanner(os.Stdin)
  for scanner.Scan() {
    a,_=strconv.Atoi(scanner.Text())
    b=append(b,a)
  }
  if b[4]-b[0]>b[5]{
    fmt.Println(":(")
  }else{
    fmt.Println("Yay!") 
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        i64 n;
        cin >> n;
        set<i64> S;
        i64 N = n - 1;
        for (i64 i = 1; i * i <= N; ++i) {
            if (N % i == 0) {
                if (i >= 2)
                    S.insert(i);
                if (N / i >= 2)
                    S.insert(N / i);
            }
        }
        S.insert(n);
        for (i64 i = 2; i * i <= n; ++i) {
            if (n % i == 0) {
                N = n;
                while (N % i == 0) {
                    N /= i;
                }
                N--;
                if (N % i == 0)
                    S.insert(i);
                i64 j = n / i;
                N = n;
                while (N % j == 0)
                    N /= j;
                N--;
                if (N % j == 0)
                    S.insert(j);
            }
        }
        // for (auto i : S)
        //     cout << i << " ";
        // cout << endl;
        cout << S.size() << "\n";
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

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

int main(){
    string s;
    int l,x,y;
    cin >> s;
    l=s.size();
    vector <int> amari(2019);
    vector <int> rui(l);
    int ans;
    ans=0;
    x=0;
    y=1;
    string z;
    
    rep(i,l){
        z=s[l-i-1];
        x+=stoi(z)*y;
        
        x=x%2019;
        ans+=amari[x];
        ++amari[x];

        y=(y*10)%2019;

    }
    ans+=amari[0];
    
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 4412
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=10;
char s[N];

int main()
{
	int flag=0;
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<n;++i)
		if(s[i]=='A'&&s[i+1]=='C')	flag=1;
	if(flag)	puts("Yes");
	else	puts("No");	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define mk make_pair
using namespace std;
 main(){
  int n,m,t;
  cin>>n>>m>>t;
  vector<pair<int,int> >a[n];
  rep(i,m){
    int q,w,e;
    cin>>q>>w>>e;
    a[q].push_back(mk(w,e));
  }
    priority_queue<P,vector<P>,greater<P> >q;
    int d[n];
    fill(d,d+n,INF);
    q.push(mk(0,t));
    d[t]=0;
    while(!q.empty()){
      P p=q.top();q.pop();
      int v=p.second;
      if(d[v]<p.first)continue;
      for(int i=0;i<a[v].size();i++){
        P ed=a[v][i];
        if(d[ed.first]>d[v]+ed.second){
          d[ed.first]=d[v]+ed.second;
          q.push(mk(d[ed.first],ed.first));
        }
      }
    }
  rep(i,n){
if(d[i]==INF)cout<<"INF"<<endl;
else cout<<d[i]<<endl;
}
}

Measured memory_bytes: 19332
#include <stdio.h>
#include <math.h>
 
int main(){
  int N=0;
  int M=0;
  int A[10010]={0};
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    scanf("%d",&A[i]);
  }
  for(int i=0;i<M;i++){
    N -= A[i];
    if(N<0){
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n",N );
  return 0;
}

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

using namespace std;

int N; vector<pair<string, long long> > R;

struct sort1 : public binary_function<pair<string, long long>, pair<string, long long>, bool>
{
	bool operator()(pair<string, long long> p1, pair<string, long long> p2)
	{
		int l1 = p1.first.size();
		int l2 = p2.first.size();

		return (l1 < l2 ? true : l1 == l2 ? p1.first < p2.first : false);
	}
};

int main()
{
	cin >> N;

	R = vector<pair<string, long long> >(N);

	for (int i = 0; i < N; i++)
	{
		cin >> R[i].first >> R[i].second;
	}

	sort(R.begin(), R.end(), sort1());

	int sum = R[0].second;

	for (int i = 1; i < N; i++)
	{
		if (R[i - 1].first != R[i].first)
		{
			cout << R[i - 1].first << ' ' << sum << endl; sum = 0;
		}
		
		sum += R[i].second;
	}

	cout << R[N - 1].first << ' ' << sum << endl;

	return 0;
}

Measured memory_bytes: 3700
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
ll A[2000];
vector<pair<ll, int>> v;

ll memo[2000][2000];
ll solve(int l, int r){
    if(l > r) return 0;
    if(memo[l][r] != -1) return memo[l][r];
    int n = (N-1)-r + l;
    return memo[l][r] = max(solve(l+1, r) + abs(v[n].second-l)*v[n].first,
        solve(l, r-1) + abs(v[n].second-r)*v[n].first);
}

signed main(){
    cin >> N;
    rep(i, N){
        cin >> A[i];
        v.pb({ A[i], i });
    }
    sort(all(v));
    reverse(all(v));
    memset(memo, -1, sizeof(memo));
    cout << solve(0, N-1) << endl;
}

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

using namespace std;

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

    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        v.push_back(a);
    }
    sort(begin(v), end(v));

    auto check = [](int x) {
        auto s = to_string(x);
        for (size_t i = 0; i < s.size() - 1; ++i) {
            if (s[i] + 1 != s[i + 1]) {
                return false;
            }
        }
        return true;
    };
    int max_ = -1;
    for (size_t i = 0; i < v.size(); ++i) {
        for (size_t j = i + 1; j < v.size(); ++j) {
            auto p = v[i] * v[j];
            if (check(p)) {
                max_ = max(max_, p);
            }
        }
    }
    cout << max_ << endl;
}


Measured memory_bytes: 3288
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
    
    int H,W,tate,yoko,i;
    
    while(1){
     cin>> H >> W;
     if(H==0 && W==0){
         break;
     }else
       for(tate=0; tate<H; tate++){
          for(yoko=0; yoko<W; yoko++){
             i=tate+yoko;
             i %= 2;
             if(i==0){
                 cout<<"#";
              }else{
              cout<<".";   
              }
            
          }
       cout << endl;
      }
      cout<<endl;
     }
    
    return 0;
}



Measured memory_bytes: 3104
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1234576891234601LL;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, M, a0, ad, b0, bd;
	cin >> N >> M >> a0 >> ad >> b0 >> bd;
	vector<int> a(N), b(M);
	a[0] = a0;
	for (int i = 1; i < N; i++)
		a[i] = (a[i - 1] * 58 + ad) % (M + 1);
	b[0] = b0;
	for (int j = 1; j < M; j++)
		b[j] = (b[j - 1] * 58 + bd) % (N + 1);
	vector<int> c(N + 1);
	for (int j = 0; j < M; j++)
		c[b[j]]++;
	for (int i = N - 1; i >= 0; i--)
		c[i] += c[i + 1];
	vector<int> d(M + 1);
	for (int i = 0; i < N; i++)
		d[a[i]]++;
	ll unko = 0, ans = 0;
	int i = 1;
	for (int j = M; j >= 0; j--)
		while (d[j]--) {
			int k = min((ll)j, unko + c[i]);
			ans += k;
			unko += c[i] - k;
			i++;
		}
	cout << ans << endl;
}

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

int t1, t2;
string s1, s2, s;
const int maxS = 3000;
int m[maxS + 1][maxS + 1];

int main()
{
	cin >> s1 >> s2;

	t1 = s1.size();
	t2 = s2.size();

	for (int i = 0; i < t1; i++) {
		for (int j = 0; j < t2; j++) {
			if (s1[i] == s2[j])
				m[i + 1][j + 1] = m[i][j] + 1;
			else
				m[i + 1][j + 1] = max(m[i][j + 1], m[i + 1][j]);
		}
	}
	
	int i = t1, j = t2;

	while (i > 0 && j > 0) {
		if (s1[i - 1] == s2[j - 1]) {
			s = s1[i - 1] + s;
			i--;
			j--;
		}
		else if (m[i - 1][j] >= m[i][j - 1])
			i--;
		else
			j--;
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 35456
#DISCO presents ディスカバリーチャンネル コードコンテス a
def get_money(num):
    if num==3:
        return 100000
    elif num==2:
        return 200000
    elif num==1:
        return 300000
    else:
        return 0
x,y=map(int,input().split())
money=get_money(x)+get_money(y)
if x==y and x==1:
    money+=400000
print(money)

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

using namespace std;

const long long MOD = 1000000007;

long long dp[100001], psa[100001];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, k;
    cin >> n >> k;

    dp[0] = 1;

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

        int a; cin >> a;

        // maybe optimize with psa?

        psa[0] = 0;
        for(int j = 1; j <= k; ++j)
            psa[j] = (psa[j - 1] + dp[j - 1]) % MOD;

        for(int j = k; j > a; --j)
            dp[j] = (dp[j] + psa[j] - psa[j - a] + MOD) % MOD;
        for(int j = a; j > 0; --j)
            dp[j] = (dp[j] + psa[j]) % MOD;

    }

    cout << dp[k] << "\n";

    return 0;
}

Measured memory_bytes: 1792
def resolve():
    n=int(input())
    s={}
    for i in range(n):
        x=str(sorted(list(input())))
        if x in s.keys():
            s[x]+=1
        else:
            s[x]=1
    ans=0
    if s:
        for i in s.values():
            ans+=i*(i-1)//2
    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 26144
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <memory.h>
#include <deque>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int M=100005;
const int N=1000001;
const int K=1000000000;
const ll MAX=1000000000000000000ll;
int n,a[M],dp[M];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)
    	scanf("%d",a+i);
    dp[n-2]=abs(a[n-2]-a[n-1]);
    for(int i=n-3;i>=0;i--)
    	dp[i]=min(dp[i+1]+abs(a[i]-a[i+1]),dp[i+2]+abs(a[i]-a[i+2]));
    cout<<dp[0];
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define lli long long int
#define timesave ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

void solve()
{
    lli n;

    cin >> n;

    lli arr[n+5], xr = 0;

    for(int i = 1; i <= n; i++){
        cin >> arr[i];
        if(i != n) xr ^= arr[i];
    }

    lli brr[n+5];
    brr[n] = xr;

    for(int i = n-1; i >= 1; i--){
    	xr = arr[i] ^ arr[i+1] ^ brr[i+1];
    	brr[i] = xr;
    }

    for(int i = 1; i <= n; i++) cout << brr[i] << " \n"[i==n];
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //timesave; 

    int tc = 1;
    //cin >> tc;
    while(tc--	) solve();
 
    return 0;
}

Measured memory_bytes: 6604