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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	int tmp=min(c,a-b);
	cout<<c-tmp<<endl;
	return 0;
}

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


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




int main() {

    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    vector<int> useable(n, -1);
    int m = 0;
    for(int i=n-1; i >= 0; i--) {

        int j = i;
        int sum = 0;


        // 0のパターン
        if(a[i] == 0) {
            // 過去に辿った箇所を確認
            while(j < n) {
                if(useable[j] != -1) sum += useable[j];
                j += i+1;
            }
            if((sum%2) == 0) {
                useable[i] = 0;
            } else {
                useable[i] = 1;
                m++;
            }
        } else {
            // 1の場合
            // すでに過去に通ったところは確定している
            while(j < n) {
                if(useable[j] != -1) sum += useable[j];
                j += i+1;
            }
            // 自分の箇所を埋めるか決める
            if((sum%2) == 1) {
                useable[i] = 0;
            } else {
                useable[i] = 1;
                m++;
            }
        }
    }

    cout << m << endl;

    bool first_falg=true;
    rep(i,n) {
        if(useable[i] == 1) {
            if (first_falg) {
                cout << i+1;
                first_falg=false;
            } else {
                cout << " ";
                cout << i+1;
            }
        }

    }


    return 0;

}

Measured memory_bytes: 2432
n = int(input())
s = list(input())

ans = [None] * (n-1)

for i in range(1,n):
  a = s[0:i]
  b = s[i:n]

  ans[i-1] = len(set(b))-len((set(b)-set(a)))

ans.sort(reverse = True)

print(ans[0])


Measured memory_bytes: 9188
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

X = int(input())

import numpy as np

def make_prime(U):
    """素数判定（エラトステネスの篩）"""
    is_prime = np.zeros(U, np.bool)
    is_prime[2] = 1
    is_prime[3::2] = 1  # 3以上の奇数を一旦すべて素数としてマーク
    M = int(U**.5) + 1
    for p in range(3, M, 2):  # 倍数のふるい落とし
        if is_prime[p]:
            is_prime[p*p::p+p] = 0  # 奇数*奇数+奇数は偶数になり無駄なのでstepをp+pにして回避
    return is_prime, is_prime.nonzero()[0]

LIM = 10 ** 7
is_prime, primes = make_prime(LIM)
ans = list(filter(lambda x: x >= X, primes))[0]
print(ans)

Measured memory_bytes: 55244
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String s = sc.next();

        String t = sc.next();

        int a = sc.nextInt();

        int b = sc.nextInt();

        String u = sc.next();

        if (s.equals(u)) {
            a--;
        } else {
            b--;
        }

        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 22996
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, k = map(int, input().split())

if n==1:
    print(k)
    exit()

ab = [tuple(map(int,input().split())) for i in range(n-1)]
p=10**9+7
es = [[] for i in range(n)]
for i, (a,b) in enumerate(ab):
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

d = [1]*n
for i in range(1,n):
    d[i] *= d[i-1]*max(0,(k-1-i))%p
    d[i] %=p

root=0
ans = k
for i in range(n):
    if i == root:
        ans *= (k-1)*d[len(es[i])-1]%p
    else:
        ans *= d[len(es[i])-1]%p

print(ans%p)




Measured memory_bytes: 106844
import bisect

N = int(input())
A = list(map(int, input().split()))

acc_A = [0]
for i in range(N):
    acc_A.append(acc_A[-1] + A[i])
acc_A.append(acc_A[-1])
half = acc_A[-1] / 2
mid = bisect.bisect_left(acc_A, half)

if acc_A[mid] == half:
    ans = 0
else:
    ans = min(abs((acc_A[mid] - acc_A[0]) - (acc_A[-1] - acc_A[mid])),
              abs((acc_A[mid - 1] - acc_A[0]) - (acc_A[-1] - acc_A[mid - 1])))
print(ans)


Measured memory_bytes: 26024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p)*(b))%m;
		b=((b)*(b))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	string s;
	cin>>s;
	for (int i = 0; i < s.length(); ++i)
	{
		s[i]=='?'?s[i]='D':s[i]=s[i];
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 27180
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

bool check(double x1, double y1, double x2, double y2){
  return x1 * y2 - y1 * x2 > 0;
}

int main(void) {

  vector<double> x(4);
  vector<double> y(4);
  while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) != EOF ){
    bool f = true;
    for(int i=0; i<4; i++){
      int j = i + 1;
      bool a = check(x[i%4]-x[(i+1)%4], y[i%4]-y[(i+1)%4], x[(i+1)%4]-x[(i+2)%4], y[(i+1)%4]-y[(i+2)%4]);
      bool b = check(x[j%4]-x[(j+1)%4], y[j%4]-y[(j+1)%4], x[(j+1)%4]-x[(j+2)%4], y[(j+1)%4]-y[(j+2)%4]);
      if( a != b ){
        f = false;
        break;
      }
    }
    cout << ( f ? "YES":"NO") << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    string s; cin >> s;

    int ans = s.size();
    REP(i,s.size()-1) {
        if (s[i] != s[i+1]) ans = min(ans,max(i+1,(int)s.size()-i-1));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s; cin >> s;
	cout << s.substr(0, 4) << " " << s.substr(4) << endl;		
	return 0;                                              
}
	


Measured memory_bytes: 256
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  int h, w;
  cin >> h >> w;
  rep(h){
    string s;
    cin >> s;
    cout << s << endl << s << endl;
  }

}


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

int main() {
  int N;
  long K;
  cin >> N >> K;
  vector<ll> A(N), F(N);
  rep(i, N)  cin >> A.at(i);
  rep(i, N)  cin >> F.at(i);
  sort(A.begin(), A.end());
  sort(F.begin(), F.end());
  reverse(F.begin(), F.end());
  ll ng = -1 , ok = A.at(N - 1) * F.at(0);
  while ( abs(ok-ng) > 1 ) {
    ll mid = (ng + ok) / 2;
    ll count = 0;
    rep(i, N) {
      count += max((ll)0, (A.at(i) * F.at(i) - mid + F.at(i) - 1) / F.at(i));
    }
    if (count <= K)  ok = mid;
    else  ng = mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 3328
#!/usr/bin/env python
# coding: utf-8

# In[14]:


N,M = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(list(map(int, input().split())))


# In[15]:


AB_s = sorted(AB, key=lambda x: x[0])

cnt = 0
ans = 0
for idx,lst in enumerate(AB_s):
#     print(lst)
    c = lst[0]
    n = lst[1]
    if n <= M-cnt:
        ans += c*n
        cnt += n
#         print(cnt)
    else:
        ans += c*(M-cnt)
        cnt += (M-cnt)
#         print(cnt)
        break
print(ans)


# In[ ]:






Measured memory_bytes: 29752
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
	string s;
	cin >> s;
	cout << "2018" << s.substr(4,s.size()-4) << endl;
}


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

int G[101][101];

bool inF(int x, int y) { return 0<=x<10 && 0<=y<10; }

void draw(int x, int y) {
  if(inF(x, y)) {
    G[y][x] ++;
  }
}

int main() {
  int a, b, c;
  char d;

  fill(G[0], G[10], 0);
  
  while(cin >> a >> d >> b >> d >> c) {
    draw(a, b);
    switch(c) {
    case 3:
      draw(a-2, b);
      draw(a+2, b);
      draw(a, b-2);
      draw(a, b+2);
    case 2:
      draw(a-1, b-1);
      draw(a+1, b-1);
      draw(a-1, b+1);
      draw(a+1, b+1);
    case 1:
      draw(a-1, b);
      draw(a+1, b);
      draw(a, b-1);
      draw(a, b+1);
      break;
    }
  }
  
  int clrNum = 0, mx=0;  
  
  for(int i=0; i<10; i++) {
    for(int j=0; j<10; j++) {
      mx = max(mx, G[i][j]);
      if(G[i][j]==0) clrNum ++;
    }
  }

  cout << clrNum << endl << mx << endl;
  
  return 0;
}

Measured memory_bytes: 1164
import sys
import bisect
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w, n = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    dt = collections.defaultdict(int)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        a -= 1
        b -= 1
        for j in range(max(1, a - 1), min(h-1, a + 2)):
            for k in range(max(1, b - 1), min(w-1, b + 2)):
                d[j, k] += 1
                dt[d[j, k]] += 1
                dt[d[j, k]-1] -= 1
    dt[0] += (h - 3 + 1) * (w - 3 + 1)
    for i in range(10):
        print(dt[i])


if __name__ == '__main__':
    slove()


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

int main() {
    int n, x, cnt = 0;
    while(cin >> n >> x){
        if(n == 0 && x == 0)return 0;
        for(int i=1; i <= n; i++)for(int j=i+1; j<=n; j++)for(int k =j+1; k<=n; k++)if(i+j+k == x)cnt++;
        cout << cnt << endl;
        cnt = 0;
    }
}



Measured memory_bytes: 3100
#include<cstdio>
int n, m,ans;
int a[100][100];
bool b[100][100];

void dfs(int x,int y) {
	b[x][y] = true;
	for (int i = -1; i < 2; i++) {
		for (int j = -1; j < 2; j++) {
			if (0 <= x + i&&x + i < n) {
				if (0 <= y + j&&y + j < m) {
					if (a[x+i][y+j] == 1 && !b[x+i][y+j])dfs(x+i, y+j);
				}
			}
		}
	}
	return;
}

int main(void) {

	while (true) {
		scanf("%d %d", &m, &n);
		if (n == 0 && m == 0)return 0;
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				a[i][j] = 0;
				b[i][j] = false;
			}
		}
		for (int i = 0; i < n;i++) {
			for (int j = 0; j < m; j ++) {
				scanf("%d", &a[i][j]);
			}
		}
		ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i][j] == 1 && !b[i][j]) {
					dfs(i, j);
					ans++;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> broken(N + 1);
  rep(i, M)
  {
    int a;
    cin >> a;
    broken[a] = 1;
  }
  vector<int> dp(N + 2);
  const int mod = 1e9 + 7;
  dp[N] = 1;
  for (int i = N - 1; i >= 0; i--)
  {
    if (broken[i])
    {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
  }
  cout << dp[0] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main() {
	int x;
	cin >> x;
	int sum = (x/500)*1000;
	x %= 500;
	sum += (x/5)*5;
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;

struct UnionFind {
public:
  std::vector<ll> par;
  std::vector<ll> size;
  int groupNum;

  explicit UnionFind(ll N)
    : par(N), size(N, 1LL), groupNum(N) {
    std::iota(par.begin(), par.end(), 0LL);
  }

  ll find(ll x) {
    if (par[x] == x) {
      return x;
    } else {
      return (par[x] = find(par[x]));
    }
  }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size[x] += size[y];
    size[y] = size[x];

    par[y] = x;
    groupNum--;
  }

  bool is_same(ll x, ll y){
    return find(x) == find(y);
  }

  ll get_size(ll x){
    return size[find(x)];
  }
};


void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}


void solve()
{
  ll N, M, K;
  std::cin >> N >> M >> K;

  UnionFind uf(N);

  std::vector< ll > vans(N, 0LL);
  for (ll i = 0; i < M; i++) {
    ll a, b;
    std::cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
    vans[a]--, vans[b]--;
  }

  for (ll i = 0; i < N; i++) {
    vans[i] += uf.get_size(i) - 1;
  }

  for (ll i = 0; i < K; i++) {
    ll a, b;
    std::cin >> a >> b;
    a--; b--;
    if (uf.is_same(a, b)) {
      vans[a]--; vans[b]--;
    }
  }

  for (auto ans : vans) {
    std::cout << ans << " ";
  }
  std::cout << std::endl;

  return;
}

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



Measured memory_bytes: 3584
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll x[1005];
ll y[1005];
ll z[1005];
ll sign[8][3]={
	1ll,1ll,1ll,
	1ll,1ll,-1ll,
	1ll,-1ll,1ll,
	1ll,-1ll,-1ll,
	-1ll,1ll,1ll,
	-1ll,1ll,-1ll,
	-1ll,-1ll,1ll,
	-1ll,-1ll,-1ll
};

vector<ll>vec;

int main(){

	int N,M;

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

	int i,j;

	for(i=0;i<N;i++){
		scanf("%lld %lld %lld",&x[i],&y[i],&z[i]);
	}

	ll ans=-(1ll<<60);

	for(i=0;i<8;i++){
		vec.clear();
		for(j=0;j<N;j++){
			vec.push_back((x[j]*sign[i][0])+(y[j]*sign[i][1])+(z[j]*sign[i][2]));
		}
		sort(vec.begin(),vec.end());
		ll sum=0ll;
		for(j=N-1;j>=N-M;j--){
			sum+=vec[j];
		}
		ans=max(ans,sum);
	}

	printf("%lld\n",ans);

	return 0;
}

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

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

int main() {
   int N, K;
   ll x[60], y[60];
   cin >> N >> K;
   rep (i, 0, N) cin >> x[i] >> y[i];

   ll area = 1LL << 62;
   rep (xi, 0, N) rep (xj, 0, N) rep (yi, 0, N) rep (yj, 0, N) {
      if (x[xi] <= x[xj] && y[yi] <= y[yj]) {
         int cnt = 0;
         rep (p, 0, N) {
            if (x[p] >= x[xi] && x[p] <= x[xj] && y[p] >= y[yi] && y[p] <= y [yj]) cnt++;
         }

         if (cnt >= K) area = min(area, (x[xj]-x[xi]) * (y[yj]-y[yi]));
      }
   }
   cout << area << endl;

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define N 400010
#define ll long long
#define mod 200003
#define G 11
using namespace std;
ll num[N],cnt[N],_11[N];
const double pi=acos(-1);
struct xu{
	double s,x;
	xu(double S=0.0,double X=0.0):s(S),x(X){};
	xu operator +(const xu a){return xu(s+a.s,x+a.x);}
	xu operator -(const xu a){return xu(s-a.s,x-a.x);}
	xu operator *(const xu a){return xu(s*a.s-x*a.x,s*a.x+x*a.s);}
};

void fft(xu a[],int n,int len,int opt)
{
	int rev[n];
	rev[0]=0;
	for(int i=1;i<n;i++)
	{
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
		if(rev[i]>i) swap(a[rev[i]],a[i]);
	}
	for(int i=1;i<n;i<<=1)
	{
		xu omg(cos(pi/i),opt*sin(pi/i));
		for(int j=0;j<n;j+=i*2)
		{
			xu orz(1,0);
			for(int k=0;k<i;k++)
			{
				xu n1=a[j+k],n2=orz*a[i+k+j];
				a[j+k]=n1+n2;
				a[i+j+k]=n1-n2;
				orz=orz*omg;
			}
		}
	}
	if(opt==1) return;
	for(int i=0;i<n;i++)
	{
		a[i].s=a[i].s/n;
		a[i].x=a[i].x/n;
	}
}
xu f[mod*4];
int main()
{
    int n;
    ll s=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&num[i]);
    _11[0]=1;
    for(int i=1;i<=mod-2;i++)
    {
        _11[i]=1ll*_11[i-1]*G%mod;
        cnt[_11[i]]=i;
    }
    int m=1,l=0;
    while(m<=mod*2) m=m*2,l++;
    for(int i=1;i<=n;i++)
    if(num[i])f[cnt[num[i]]].s++;
    fft(f,m,l,1);
    for(int i=0;i<m;i++) f[i]=f[i]*f[i];
    fft(f,m,l,-1);
    // for(int i=0;i<m;i++)
    // if((ll)(f[i].s+0.5)) printf("%d:%d - %d\n",i,_11[i%mod],(ll)(f[i].s+0.5));
    ll ans=0;
    for(int i=0;i<mod*2;i++)
        ans+=1ll*_11[i%(mod-1)]*(ll)(f[i].s+0.5);
    for(int i=1;i<=n;i++) ans-=1ll*num[i]*num[i]%mod;
    ans/=2;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 23340
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
int n;
string S;
int nr=0;
cin >> n >> S;
for(int i=0;i<n-2;i++){
    if(S[i]=='A'&& S[i+1]=='B'&&S[i+2]=='C')
          nr++;
}
cout << nr;
}


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

int main(int argc, char *argv[])
{
    int ch;
    int c[100] = { 0 };

    while ((ch = getchar()) != EOF) {
        if (isalpha(ch)) {
            c[tolower(ch) - 'a']++;
        }
    }

    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", 'a' + i, c[i]);
    }

    return 0;
}



Measured memory_bytes: 2100
using namespace std;
#include<bits/stdc++.h>
#define debug(x) clog<<#x<<" = "<<x<<'\n'
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define sz(c) ((int)c.size())
#define all(c) (c).begin(),(c).end()
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define fn "A"  /// ___FILE_NAME_HERE___
#define rep(c,it) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define __rep(c,it) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();it++)

template <class T,class U>
void maximize(T &x,U y)
{
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y)
{
    if(x > y)x=y;
}
template <class T>
T Abs(T x)
{
    return (x < 0 ? -x : x);
}
template <class T>
T safe_sqrt(T x)
{
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD)
{
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD)
{
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD)
{
    return (ll)x*y%MOD;
}
/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

void solve()
{
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    cout<<(Abs(x - a) < Abs(x - b) ? 'A' : 'B');
}}

int main(void)
{
    task::solve();
}


Measured memory_bytes: 256
//Author : Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i = a; i<b; ++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
#define ff first
#define ss second
const int M=1e9+7;


int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
	cin>>n;
	if(n%1000 == 0)
	cout<<"0\n";
	else
	{
		int x = n%1000;
		int r = 1000 - x;
		cout<<r<<"\n";
	}
   return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if (a == b && a != c) printf("Yes\n");
  else if (b == c && b != a) printf("Yes\n");
  else if (c == a && c != b) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#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 pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//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;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
ll table[201] = {0,1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692};

int main() {
	INIT
	int k;
	cin >> k;
	cout << table[k];

	return 0;
}

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

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

    set<char> W;
    for (int i = 0; i < 3; i++) {
        W.insert(S[i]);
    }

    if (W.size() == 3) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int n;
void dfs(string str)
{
    if ((int)str.size() == n)
    {
        cout << str << '\n';
        return;
    }
    int str_max = 0;
    if (str.size() >= 1)
    {
        rep(i, str.size())
        {
            str_max = max(str_max, str[i] - 'a');
        }
    }
    for (int i = 0; i <= str_max + 1; i++)
    {
        string nex = str;
        nex += ('a' + i);
        dfs(nex);
    }
}

int main()
{
    cin >> n;
    dfs("a");
    return 0;
}


Measured memory_bytes: 3568
Imports System

Module Program
    Sub Main(args As String())

        Dim StrS As String = Console.ReadLine()
        Dim LenS As Integer = Len(StrS)
        Dim StrX As String = ""

        Dim i As Integer = 1
        For i = 1 To LenS
            StrX = StrX & "x"
        Next

        Console.WriteLine(StrX)
    End Sub
End Module


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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

ll cost = 0,ok = (1ll<<51)-2;

int n,a[55],b[55];

bool test(){
	for(int i=0;i<n;i++){
		bool cc[60] = {0};
		cc[a[i]]=1;
		for(int j=50;j>=1;j--){
			if(ok&(1ll<<j)){
				for(int k=0;k<=50;k++)cc[k%j]|=cc[k];
			}
		}
		if(!cc[b[i]])return 1;
	}
	return 0;
}
int main() {
	read(n);
	for(int i=0;i<n;i++) read(a[i]);
	for(int i=0;i<n;i++) read(b[i]);
	if(test()){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=50;i>=1;i--){
		ok^=1ll<<i;
		if(test())ok^=1ll<<i;
	}
	cout<<ok<<endl;
	return 0;
}


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

int tensu(int k)
{
	int score, sum = 0;
	rep(i, k)
	{
		cin >> score;
		if(score<40) sum += 40;
		else sum += score;
	}
	return sum;
}

int ave(int sum, int n)
{
	return sum/n;
}

int main(void)
{
	int score_sum = tensu(5);
	int ans = ave(score_sum, 5);
	cout << ans << endl;
	return 0;
}



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

int main()
{
    int a,b;
    cin>>a>>b;
    int l,s=0,sum=1;
    while(a--)
    {cin>>l;
    s=s+l;
    if(s<=b)
    sum++;
    }
    cout<<sum;
    return 0;
}


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

using namespace std;

string s;
int a[555];
int n;
int K;
int at;


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

    vector<int> divs;
    for(int i = 1; i*i <= tot; i++) {
        if(tot % i == 0) {
            divs.push_back(i);
            divs.push_back(tot/i);
        }
    }
    sort(divs.begin(), divs.end());
    int sz = divs.size();
    sort(a, a+n);
  
    for(int p = 0; p < divs.size(); p++) {

        int j = divs[sz-1-p];
        
        if(tot % j != 0) continue;

        at = j;

        long long tot_extra = 0;
        vector<int> extras;
        for(int i = 0; i < n; i++) {
            tot_extra += (at - (a[i] % at));
            extras.push_back((at - (a[i] % at)));
        }   
        
        sort(extras.begin(), extras.end());
        
        int x = tot_extra/at; // these many subtractions of 'at' needed to make it zero
        
        long long neg = 0;
        
        for(int i = 0; i < x ; i++) {
            // convert from addition to subtraction from largest additions, 
            // that ensures less chance of exceeding K. I.e. minimized neg
            neg += (at - extras[n-1-i]);
            tot_extra -= extras[n-1-i];
        }
        if(neg <= K) {cout << at; return 0;}
        
    

        
    }


}



Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
    char s[4];
    int ans = 0;

    scanf("%s", s);
    for (int i = 0; i < 4; i++) {
        if (s[i] == '+') {
            ans++;
        } else {
            ans--;
        }
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    int ans = 1;
    x -= y+2*z;
    ans += x/(y+z);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        String S = sc.next();
        String st = "ID";
        int x = 0;
        int max = 0;

        for(int i=0; i<N; i++){
            if(S.charAt(i)==st.charAt(0)){
                x += 1;
            }
            else{
                x -= 1;
            }
            max = Math.max(max, x);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,m;cin >> n >> m;
    int a[n][3];
    rep(i,n)cin >> a[i][0] >> a[i][1] >> a[i][2];
    int ret = 0;
    rep(mask,1<<3){
        vector<int> res;
        rep(i,n){
            int tmp = 0;
            rep(j,3){
                if(mask>>j&1){
                    tmp -= a[i][j];
                }
                else tmp += a[i][j];
            }
            res.push_back(tmp);
        }
        sort(res.rbegin(),res.rend());
        int cur = 0;
        rep(i,m){
            cur += res[i];
        }
        //trace(mask,cur);
        ret = max(ret,cur);

    }
    cout << ret << endl;
    return 0;
}   

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
void print(vector<T> vec)
{
    int n = vec.size();
    for (int i = 0; i < n; i++)
    {
        cout << vec[i] << (i == n - 1 ? "\n" : " ");
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    bool go = true;
    vector<int> b;
    while (a.size() > 0 && go)
    {
        go = false;
        for (int i = a.size() - 1; i >= 0; i--)
        {
            if (a[i] == i + 1)
            {
                b.push_back(a[i]);
                a.erase(a.begin() + i);
                go = true;
                break;
            }
        }
    }
    //print(b);
    reverse(b.begin(), b.end());
    if (b.size() != N)
    {
        cout << -1 << endl;
    }
    else
    {
        for (int i = 0; i < N; i++)
        {
            cout << b[i] << endl;
        }
    }
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>x(m);


  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  
  rep(i,m) cin >> x[i];
  sort(x.begin(),x.end());

  vector<int> d(m-1);
  rep(i,m-1) d[i] = x[i+1]-x[i];
  sort(d.begin(),d.end());

  int ans = 0;
  rep(i,m-1-(n-1)){
    ans += d[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4048
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50
bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

/*****************************************************************************/
int n, m;
LL ans = 0;
void dfs(int v) {
	bool all = true;
	f(i, 0, n) {
		if (visited[i]==false) {
			all = false;
		}
	}
	if (all)ans++;
	f(v2, 0, n) {
		if (graph[v][v2] == false)continue;
		if (visited[v2] == true)continue;
		visited[v2] = true;
		dfs(v2);
		visited[v2] = false;
	}
	return;
}

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

	cin >> n >> m;
	vi a(m), b(m);
	link(a, b, m);
	visited[0] = true;
	dfs(0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int i,j,k,n,m,p[200001];
int r(int i){
  if(i==p[i])return i;
  return p[i]=r(p[i]);
}
int main(){
  for(scanf("%d%d",&n,&m);++i<=n+m;p[i]=i);
  // for(i=0;++i<=n;)for(scanf("%d",&k);k--;p[r(j+n)]=r(i))scanf("%d",&j);
  for(i=0;++i<=n;)for(scanf("%d",&k);k--;p[r(i)]=r(j+n))scanf("%d",&j);
  // for(i=1;i<=n+m;i++)printf("%d %d\n",i,p[i]);
  // for(i=1;i<=n+m;i++)printf("%d %d\n",i,r(i));
  for(k=r(n),i=1;i<n;++i)if(r(i)!=k)break;
  if(i<n)puts("NO");else puts("YES");
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <string.h>
#include <math.h>
typedef long long ll;
typedef long long int lli;
#define INF			100000
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define SWAP
#define REP(i,x,y)	for (int (i)=(x);(i)<(y);(i)++)
#define REP_(i,x,y)	for ((i)=(x);(i)<(y);(i)++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

lli n,c,x[100002],v[100002],f[100002],g[100002],vs,vsa,vsb,a,b,ans;


int main() {
	
	cin >> n >> c;
	
	x[0] = 0;
	x[n+1] = c;
	v[0] = 0;
	v[n+1] = 0;
	
	REP(i,1,n+1) {
		cin >> x[i] >> v[i];
		vs += v[i];
	}
	
	vsa = 0;
	vsb = 0;
	
	REP(i,1,n+1) {
		vsa += v[i];
		vsb += v[n-i+1];
		f[i] = MAX(f[i-1],vsa-x[i]);
		g[n-i+1] = MAX(g[n-i+2],vsb-(c-x[n-i+1]));
	}

	vsa = 0;
	vsb = 0;
	
	REP(i,0,n+1) {
		vsb += v[n-i+1];
		vsa += v[i];
		b = vsb - 2*(c - x[n-i+1]) + f[n-i];
		a = vsa - 2*x[i] + g[i+1];
		ans = MAX(ans,MAX(a,b));
	//	ans = MAX(ans,b);
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a; cin >> a;
    string s; cin >> s;
    if(a >= 3200){
        cout << s <<endl;
    }else{
        cout << "red" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x,y,n,a[10000],i,p,q,u,h,w;
	while(~scanf("%d%d",&y,&x))
	{
		scanf("%d",&n);
		for(i=0,p=0;i<n;i++)
		{
			scanf("%d",&q);
			u=p;
			for(;p<q+u;p++)
			{
				a[p]=i+1;
			}
		}
		for(h=0,w=0;h<y;h++)
		{
			if(h%2==0) 
			{
				u=w;
				for(;w<x+u;w++)
				{
			
				printf(w==(u+x-1)?"%d\n":"%d ",a[w]);
			    }
			}
			else
			{
				u=w;
				for(w=w+x-1;w>=u;w--)
				{
				
				printf(w==(u)?"%d\n":"%d ",a[w]);
			    }
			    w=u+x;
			}
		}
		
	}
} 

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val A = listOfDouble().sortedDescending()
    val total = A.sum()
    val limit = 1.0 / M.toDouble() / 4.0
    var good = A.subList(0, M).all { (it / total) >= limit }
    val ans = if (good) "Yes" else "No"
    println(ans)
}


fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun listOfInt(vararg offset: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + offset[index % offset.size] }
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun listOfLong(vararg offset: Long) = listOfString().map { java.lang.Long.parseLong(it) }.mapIndexed { index, long -> long + offset[index % offset.size] }
fun listOfDouble(delta: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + delta }
fun pairIntLong() = listOfLong().let { Pair(it[0].toInt(), it[1]) }
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun tripleIntLongLong() = listOfLong().let { Triple(it[0].toInt(), it[1], it[2]) }
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }
fun tripleIntIntLong(offset: Triple<Int, Int, Long> = Triple(0, 0, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1].toInt() + offset.second, it[2] + offset.third) }
fun tripleIntLongLong(offset: Triple<Int, Long, Long> = Triple(0, 0L, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1] + offset.second, it[2] + offset.third) }





Measured memory_bytes: 37908
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1<<17
int n,dat[2*(MAX_N)-1];

//0で初期化
void init(int n_){
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=0;
}

//k番目の要素の値を返す
int find(int k){
  k+=n-1;
  int ans=dat[k];
  while(k>0){
    k=(k-1)/2;
    ans+=dat[k];
  }
  return ans;
}

//[a,b)の最小値を求める
void update(int a,int b,int x,int k=0,int l=0,int r=n){
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b){
    dat[k]+=x;
  }else{
    update(a,b,x,k*2+1,l,(l+r)/2);
    update(a,b,x,k*2+2,(l+r)/2,r);
  }
}

int main(){
  int q;
  cin>>n>>q;
  init(n);
  for(int i=0;i<q;i++){
    int com,s,t,x;
    cin>>com;
    if(com){
      cin>>t;
      cout<<find(t-1)<<endl;
    }else{
      cin>>s>>t>>x;
      update(s-1,t,x);//[s,t)にxを加算
    }
  }
  return 0;
}



Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n;
	cin >> n;
	int a = n, k;
	for(k = 1;a > 0;k++){
		a-=k;
	}
	if(a == 0){
		cout << "Yes" << endl;
		VVI ans(k,VI(0));
		int p = 1;
		for(int i = 0;i < k-1;i++){
			for(int j = i+1;j < k;j++){
				ans[i].push_back(p);
				ans[j].push_back(p);
				p++;
			}
		}
		cout << k << endl;
		REP(i,k){
			cout << k - 1 << ' ';
			REP(j,k-1){
				cout << ans[i][j] << ' ';
			}
			cout << endl;
		}
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <vector>

using namespace std;

const int MAXN = 2E5 + 10, MAXD = 19;

int n;
int X, Y;
vector<int> E[MAXN], F[MAXN];

/* for F */
int dep[MAXN];
int p[MAXD][MAXN];

/* for E */
bool mark[MAXN];

void DFS(int u, int pre){
	dep[u] = dep[pre] + 1;
	p[0][u] = pre;
	for (int v, i = 0; i < F[u].size(); ++i){
		if ((v = F[u][i]) == pre)
			continue;
		DFS(v, u);
	}
}

void LCA_build(int n){
	for (int i = 1; i < MAXD; ++i)
		for (int j = 1; j <= n; ++j)
			p[i][j] = p[i - 1][p[i - 1][j]];
}

int LCA_query(int u, int v){
	if (dep[u] < dep[v])
		swap(u, v);
	for (int t = dep[u] - dep[v], i = 0; t; t >>= 1, ++i)
		if (t & 1)
			u = p[i][u];
	if (u == v)
		return u;
	for (int i = MAXD - 1; i >= 0; --i)
		if (p[i][u] != p[i][v])
			u = p[i][u], v = p[i][v];
	return p[0][u];
}

int LCA_dis(int u, int v){
	return dep[u] + dep[v] - (dep[LCA_query(u, v)] << 1);
}

int ans;

void DFS2(int u, int pre, int dep){
	int t;
	if (dep >= (t = LCA_dis(u, Y)))
		return;
	ans = max(ans, t);
	if (mark[u])
		ans = n + 1;
	for (int v, i = 0; i < E[u].size(); ++i){
		if ((v = E[u][i]) == pre || v == Y)
			continue;
		DFS2(v, u, dep + 1);
	}
}

int main(){
	scanf("%d%d%d", &n, &X, &Y);
	for (int u, v, i = 1; i < n; ++i){
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	for (int u, v, i = 1; i < n; ++i){
		scanf("%d%d", &u, &v);
		F[u].push_back(v);
		F[v].push_back(u);
	}
	DFS(1, 0);
	LCA_build(n);
	for (int i = 1; i <= n; ++i){
		for (int j = 0; j < E[i].size(); ++j)
			if (LCA_dis(i, E[i][j]) >= 3)
				mark[i] = true;
	}
	DFS2(X, 0, 0);
	printf("%d\n", ans <= n ? ans << 1 : -1);
	return 0;
}


Measured memory_bytes: 46720
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

o = input().strip()
e = input().strip()

ans = []
for i, v in enumerate(o):
    ans.append(v)
    if (i != len(o) - 1) or (len(o) == len(e)):
        ans.append(e[i])
print(''.join(ans))


Measured memory_bytes: 61616
#include<stdio.h>  
#include<string.h>  
#include<algorithm>  
#define INF 0xfffffff  
using namespace std;  
int map[1100][1100];  
int main()  
{  
    int n,m,k,i,j,a,b,c,sum1;  
    while(scanf("%d",&n),n)  
    {  
        for(i=0;i<1100;i++)  
        for(j=0;j<1100;j++)  
        {  
            map[i][j]=INF;  
            map[i][i]=0;  
        }  
        int Max=0;  
        for(i=0;i<n;i++)  
        {  
            scanf("%d%d%d",&a,&b,&c);  
            Max=max(Max,a);  
            Max=max(Max,b);  
            map[a][b]=c;  
            map[b][a]=c;  
        }  
        for(k=0;k<=Max;k++)  
        for(i=0;i<=Max;i++)  
        for(j=0;j<=Max;j++)  
        {  
            if(map[i][j]>map[i][k]+map[k][j])  
            map[i][j]=map[i][k]+map[k][j];  
        }  
        int sum=INF;  
        int ans=0;  
        for(i=0;i<=Max;i++)  
        {  
            sum1=0;  
            for(j=0;j<=Max;j++)  
            {  
               sum1+=map[i][j];  
            }  
            if(sum1<sum)  
            {  
                sum=sum1;  
                ans=i;  
            }  
        }  
        printf("%d %d\n",ans,sum);  
    }  
    return 0;  
}  

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int A, B;
    cin >> A >> B;
    rep(i, 1100) {
        int p8 = i * 0.08;
        int p10 = i * 0.10;
        if (p8 == A && p10 == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
from collections import deque

INF = float("inf")

H,W = map(int,input().split())

N = H*W

data = ["#" * (W+2)]
for i in range(H):
  data.append("#"+input()+"#")
data.append("#" * (W+2))

offsets = [(0,1),(0,-1),(1,0),(-1,0),]

nodes = []
for i in range(1,H+1):
  for j in range(1,W+1):
    if data[i][j] == ".":
      nodes.append((i,j))

FARTHEST = 0

for start_node in nodes:
  i = start_node[0]
  j = start_node[1]
  d = [[INF]*(W+2) for i in range(H+2)]
  d[i][j] = 0
  q = deque([(i,j)])
  res = 0
  while q:
    x,y = q.popleft()
    nd = d[x][y]+1
    for o in offsets:
      nx, ny = x+o[0], y+o[1]
      if data[nx][ny] == "#":
        continue
      if nd < d[nx][ny]:
        d[nx][ny] = nd
        q.append((nx,ny))
        res = nd
  if res > FARTHEST:
    FARTHEST = res

print(FARTHEST)

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

signed main() {
  int N;
  cin >>N;
  vector<long long> A(N);
  for(int i=0; i<N; i++) cin >> A[i];

  for(int i=0; i<N; i++) {
    if(A[i] == 0) {
      puts("0");
      return 0;
    }
  }

  long long ans = 1;

  for(int i=0; i<N; i++) {
    if(ans > (long long)1e18 / A[i]){
      puts("-1");
      return 0;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 4048