akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    static int MAX = 1001006;  // (1 ≦ k ≦ n ≦ 10^7 程度)
    static int MOD = 1000000007;
    static long[] fac;  // 階乗
    static long[] finv;
    static long[] inv;  // 逆元
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        COMinit();
        
        int r = sc.nextInt();
        int b = sc.nextInt();
        
        if (Math.abs(r - b) > 1) {
            System.out.println(0);
            return;
        }
        
        long ans = fac[r] * fac[b];
        ans %= MOD;
        if (r == b) {
            ans *= 2;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    // テーブルを作る前処理
    public static void COMinit() {        
        fac = new long[MAX];
        finv = new long[MAX];
        inv = new long[MAX];
        
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    
    // 二項係数計算(1 ≦ k ≦ n ≦ 10^7 程度)
    public static long nCkMOD(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
    public static long modpow(long a, long n) {
        long res = 1;
        while (n > 0) {
            long tmp = n & 1;
            if (tmp > 0) res = res * a % MOD;
            a = a * a % MOD;
            n >>= 1;
        }
        return res;
    }
}

Measured memory_bytes: 48212
N = int(input())
A = [int(a) for a in input().split()]

M = 10**5+1
L = [0]*M
for a in A:
    L[a] += 1

ans = 0
cnt = 0
for i in range(M):
    if L[i] > 0:
        ans += 1
    if L[i] > 1 and L[i]%2 == 0:
        cnt += 1

if cnt%2 == 1:
    ans -= 1
print(ans)

Measured memory_bytes: 14396
N = int(input())
A_s = list(map(int, input().split()))

if (N % 2 == 0):
    FLAG = True
else:
    FLAG = False

even = A_s[1::2]
odd = A_s[0::2]
ans = []


if (FLAG):
    even = even[::-1]
    even.extend(odd)
    ans = even
    
else:
    odd = odd[::-1]
    odd.extend(even)
    ans = odd

ans = map(str, ans)

print(' '.join(ans))

Measured memory_bytes: 30404
#include <bits/stdc++.h>
using ll = long long;
constexpr ll pow(const ll a, const ll b, const ll mod) { return b == 0 ? 1LL : b % 2 == 1 ? pow(a, b - 1, mod) * a % mod : pow(a * a % mod, b / 2, mod); }
constexpr ll inverse(const ll a, const ll mod) { return pow(a, mod - 2, mod); }
constexpr ll MOD0 = 1000000007LL, MOD1 = 1000000009LL, MOD2 = 1000000021;
constexpr ll X = 121234243;
constexpr ll XINV0 = inverse(X, MOD0), XINV1 = inverse(X, MOD1), XINV2 = inverse(X, MOD2);
int main()
{
    int N;
    std::string S;
    std::cin >> N >> S;
    using P = std::tuple<ll, ll, ll>;
    std::vector<int> deg(N + 1, 0);
    std::vector<P> value(N + 1, P{0, 0, 0});
    auto plus = [](const P& p1, const P& p2) { return P{(std::get<0>(p1) + std::get<0>(p2)) % MOD0, (std::get<1>(p1) + std::get<1>(p2)) % MOD1, (std::get<2>(p1) + std::get<2>(p2)) % MOD2}; };
    auto minus = [](const P& p1, const P& p2) { return P{(std::get<0>(p1) + MOD0 - std::get<0>(p2)) % MOD0, (std::get<1>(p1) + MOD1 - std::get<1>(p2)) % MOD1, (std::get<2>(p1) + MOD2 - std::get<2>(p2)) % MOD2}; };
    auto rshift = [](const P& p) { return P{std::get<0>(p) * X % MOD0, std::get<1>(p) * X % MOD1, std::get<2>(p) * X % MOD2}; };
    auto lshift = [](const P& p) { return P{std::get<0>(p) * XINV0 % MOD0, std::get<1>(p) * XINV1 % MOD1, std::get<2>(p) * XINV2 % MOD2}; };
    auto mul = [](const P& p1, const P& p2) { return P{std::get<0>(p1) * std::get<0>(p2) % MOD0, std::get<1>(p1) * std::get<1>(p2) % MOD1, std::get<2>(p1) * std::get<2>(p2) % MOD2}; };
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == '-') {
            deg[i] = deg[i + 1], value[i] = minus(value[i + 1], P{1, 1, 1});
        } else if (S[i] == '+') {
            deg[i] = deg[i + 1], value[i] = plus(value[i + 1], P{1, 1, 1});
        } else if (S[i] == '>') {
            deg[i] = deg[i + 1] + 1, value[i] = rshift(value[i + 1]);
        } else {
            deg[i] = deg[i + 1] - 1, value[i] = lshift(value[i + 1]);
        }
    }
    constexpr int L = 250000;
    std::vector<P> power(L + 1, P{1, 1, 1});
    std::vector<P> invpower(L + 1, P{1, 1, 1});
    auto invp = [&](const int i) { return i >= 0 ? invpower[i] : power[-i]; };
    for (int i = 1; i <= L; i++) { power[i] = rshift(power[i - 1]), invpower[i] = lshift(invpower[i - 1]); }
    const P answer = value[0];
    for (int i = 0; i <= N; i++) { value[i] = mul(minus(value[i], answer), invp(deg[i])); }
    std::map<P, ll> mp;
    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        const P obj = plus(value[i], mul(invp(deg[i]), answer));
        if (mp.find(obj) != mp.end()) { ans += mp[obj]; }
        mp[value[i]]++;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 38532
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int h, w, a, b;
      cin >> h >> w >> a >> b;
      int ans = h*w;
      ans -= h*b + w*a;
      ans += a*b;
      cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a[5];
	vll b;
	ll sum=0;
	rep(i, 5){
		cin >> a[i];
		sum += a[i];
		if (a[i]%10 != 0){
			sum += 10-a[i] % 10;
			b.pb(10-a[i] % 10);
		}
	}
	if (b.size()){
		sort(rall(b));
		sum -= b[0];
	}
	cout << sum << "\n";
	return 0;
}

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

int a[15];
int n;

int main(){
	scanf("%d", &n);
	int ans = 1;
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
		ans *= 3;
	}
	int res = 1;
	for(int i=1;i<=n;i++){
		int tmp = 0;
		for(int j=a[i]-1;j<=a[i]+1;j++){
			if(j%2 == 1) tmp++;
		}
		res*=tmp;
	}
	printf("%d\n", ans-res);
}

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 = "";

		String[] oct = new String[] { "0", "1", "2", "3", "5", "7", "8", "9" };

		String s;
		StringBuilder sb;
		while (!(line = br.readLine()).equals("0")) {
			s = Integer.toOctalString(Integer.parseInt(line));
			sb = new StringBuilder();
			for (char c : s.toCharArray()) {
				sb.append(oct[c - '0']);
			}
			System.out.println(sb.toString());
		}
	}
}

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

U = 10**5
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD
 
def perm(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[n-k]
    z %= MOD
    return z

n, k = map(int, input().split())
T = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  T[a].append(b)
  T[b].append(a)
  
seen = [False]*n
def dfs(v):
  seen[v] = True
  res = 1
  b = 1
  count = 0
  for i in T[v]:
    if seen[i]:
      b = 2
      continue
    count += 1
    res *= dfs(i)
    res %= MOD
  res *= perm(k-b, count)
  return res

ans = dfs(0) * k % MOD
print(ans)

Measured memory_bytes: 96048
import math
a,b,h,m =map(int,input().split())
 
x =30*h+(m*0.5)%360
 
y=m*6
sa =abs(x-y)
if a>b:
    c=b
    b=a
    a=c
t =(math.sin(math.radians(sa)))*b
 
f=math.sqrt(b**2-t**2)
if 90 <= sa <= 270:
    a =-a
print(math.sqrt((f-a)**2+t**2))


Measured memory_bytes: 9392
while True:
    try:
        x_a, y_a, x_b, y_b, x_c, y_c, x_d, y_d = map(float, input().split())
        ab_x, ab_y = x_b - x_a, y_b - y_a
        cd_x, cd_y = x_d - x_c, y_d - y_c
        dp = ab_x*cd_x + ab_y*cd_y
        if abs(dp) > 1e-10:
            print("NO")
        else:
            print("YES")
    except:
        break



Measured memory_bytes: 5588
#include <stdio.h>

#define NNN 100

int main() {
    int i, j, n, m, a[NNN][NNN], b[NNN], c[NNN];
    
    scanf("%d%d", &n, &m);
    
    for (i = 0; i < n; i++) {
        c[i] = 0;
        
        for (j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    
    for (i = 0; i < m; i++) {
        scanf("%d", &b[i]);
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            c[i] += a[i][j] * b[j];
        }
    }
    
    for (i = 0; i < n; i++) {
        printf("%d\n", c[i]);
    }
    return 0;
}


Measured memory_bytes: 2144
# Your code here!
use strict;
use warnings;
use List::Util qw(max);
use utf8;

my ($K,$N) = split(/ /,<STDIN>);
chomp($N);
my @a = split(/ /,<STDIN>);
chomp($a[$N-1]);
my @b;

for(my $i=0; $i<$N-1; $i ++)
{
    $b[$i] = $a[$i+1] - $a[$i]; 
}

$b[$N-1] = $K - $a[$N-1] + $a[0];
my $ans = $K-max(@b);
print("$ans\n");





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

using namespace std;

int main()
{
    int n,x,y,brojac = 0;
    cin >> n;
    int a[n],b[n],a1[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
        a1[i] = a[i];
    }
    for (int i = 0; i < n; i++){
        cin >> b[i];
    }
    sort(a1, a1+n);
    do {
    bool niza = true;
    bool nizb = true;
    for(int i =0;i<n;i++){
        if(a1[i] != a[i]){
            niza = false;
        }
        if(a1[i] != b[i])
            nizb = false;
    }
    if(niza == true)
        x=  brojac;

    if(nizb == true)
        y= brojac;
        brojac++;
    }
    while ( next_permutation(a1,a1+n) );
    cout << abs(x-y)<< endl;

    return 0;
}



Measured memory_bytes: 256
// abco54c: One-stroke Path
#include <bits/stdc++.h>
using namespace std;

struct vertex{vector<int> v; bool visit;};
using graph = vector<vertex>;

int dfs(graph &g, int p, int v_count){
  if(v_count==g.size()) return 1;
  int count = 0;
  g[p].visit = true;
  for(int c:g[p].v) if(!g[c].visit) count += dfs(g,c,v_count+1);
  g[p].visit = false;
  return count;
}

int main(){
  int n,m; cin>>n>>m;
  graph g(n);
  for(int i=0;i<m;i++){
    int a,b; cin>>a>>b;
    g[--a].v.push_back(--b);
    g[b].v.push_back(a);
  }
  cout<<dfs(g,0,1)<<endl;
}

Measured memory_bytes: 256
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
lrs = lambda: [_ for _ in rs().split()]
lri = lambda: [int(_) for _ in rs().split()]
lrf = lambda: [float(_) for _ in rs().split()]

A, B, N = lri()
def f(x):
    return ((A * x) // B) - A * (x // B)
print(max(f(N), f(max((N // B) * B - 1, 1))))

Measured memory_bytes: 61872
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string a, b;
  cin>>a>>b;
  a += b;
  int x = stoi(a);
  bool can = false;
  for(int i=1;i*i<=x;++i) {
    if(i*i==x) can = true;
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

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

	int ans = 0;
	int i = 0;
	while(i<=n-2){
		if(a[i] == a[i+1]){
			ans++;
			i += 2;
		}else{
			i++;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}


long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

vector<ll> divisors(ll num) {
    ll now = 1;
    vector<ll> divs;
    if (num==1) {
        // cout << "return"<<endl;
        divs.push_back(1);
        return divs;
    }
    while(now*now<=num) {
        if (num % now==0) {
            divs.push_back(now);
            if (now*now!=num){
                divs.push_back(num/now);
            }
        }
        now++;
    }
    return divs;
}

map<ll,ll> prime_fact(ll num) {
    ll now = 2;
    map<ll,ll> divisors; 
    while(now*now<=num) {
        while(num%now==0) {
            divisors[now]++;
            num /= now;
        }
        now++;
    }
    if (num != 1) {
        divisors[num]++;
    }
    return divisors;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll res = 0;
    vector<ll> memo(k+100,0);
    // repr(i,1,k+1) {
    for(ll i=k;i>=1;i--) {
        // cout << i << endl;
        ll x = k/i;
        ll count = MOD + modpow(x, n, MOD) - memo[i];
        res = (res + count * i % MOD) % MOD;
        vector<ll> divs = divisors(i);
        // map<ll,ll> primes = prime_fact(i);
        for (auto d:divs) {
            // cout << "d: "<<d.first<< endl; 
            if (d==i) {
                continue;
            }
            memo[d] += count;
            memo[d] %= MOD;
        } 
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3928
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    if(N>=M/2){
        ans = M/2;
    }else{
        ans=N;
        M-=N*2;
        ans+=M/4;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
 int x;
 int seki=0;
  
  public void solve(){
    Scanner sc= new Scanner(System.in);
    x= sc.nextInt();
    seki=x*x*x;
    System.out.println(seki);

}


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

Measured memory_bytes: 17352
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int total = 0;
	int maxNum = 0;
	vector<int> L;
	for (int i = 0; i < N; i++) {
		int l;
		cin >> l;
		total += l;
		maxNum = max(maxNum, l);
		L.push_back(l);
	}

	if (total - maxNum > maxNum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}






Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
# case.rb

loop{ # 無限ループをするメソッド

  a, op, b = STDIN.gets.split(' ')
  a = a.to_i
  b = b.to_i

  case op
  when '+' 
    puts a + b
  when '-'
    puts a - b
  when '*'
    puts a * b
  when '/'
    puts a / b
  else
    break
  end
}

Measured memory_bytes: 8588
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n,k;
int a[110000];

int f(int t){
  if(t>k) return 0;

  int ans=0;
  rep(i,n){
    ans+= t^a[i];
  }
  return ans;
}

signed main(){
  cin>>n>>k;
  rep(i,n){
    cin>>a[i];
  }

  if(k==0){
    int ans=0;
    rep(i,n){
      ans+= a[i];
    }
    cout<<ans<<endl;
    return 0;
  }

  int t=1;
  while(t<=k){
    t*=2;
  }
  t/=2;

  int m=0;
  int ans=0;
  while(t>0){
    int b=f(m),c=f(m+t);
    if(b>c){
      ans = max(ans,b);
    }
    else{
      ans = max(ans,c);
      m+=t;
    }
    t/=2;
  }

  cout<<ans<<endl;
}




Measured memory_bytes: 1024
#include<cstdio>
#include<map>
#include<algorithm>
#define N 100000
#define LL long long
#define mod 1000000007
using namespace std;
typedef pair<LL,LL> PLL;
typedef map<LL,int>::iterator miter;
int n,p[N+5],pcnt,ans,cnt0;
bool vis[N+5];
map<LL,int> cnt,calc;
map<LL,LL> iv;
void init()
{
	for(int i=2;i<=N;i++)
	{
		if(!vis[i]) p[++pcnt]=i,calc[1ll*i*i]=i;
		for(int j=1;i*p[j]<=N;j++)
		{
			vis[i*p[j]]=true;
			if(i%p[j]==0) break;
		}
	}
}
int main()
{
	scanf("%d",&n);
	init();
	for(int i=1;i<=n;i++)
	{
		LL a,tmp,h1=1,inv=1;
		scanf("%lld",&a); tmp=a;
		for(int j=1;j<=pcnt&&1ll*p[j]*p[j]*p[j]<=a;j++)
			if(tmp%p[j]==0)
			{
				int xcnt=0;
				while(tmp%p[j]==0) tmp/=p[j],xcnt++;
				xcnt%=3;
				for(int i=1;i<=xcnt;i++) h1*=1ll*p[j];
				for(int i=1;i<=(3-xcnt)%3;i++) inv*=1ll*p[j];
			}
		if(tmp>1)
		{ 
			h1*=1ll*tmp;
			miter it=calc.find(h1);
			if(it!=calc.end()) inv*=it->second;
			else inv*=1ll*tmp*tmp;
		}
		if(h1==1) { cnt0=1; continue; }
		cnt[h1]++;
		iv[h1]=inv,iv[inv]=h1;
	}
	for(miter it=cnt.begin();it!=cnt.end();it++)
		if(cnt.find(iv[it->first])==cnt.end()) ans+=it->second;
		else
		{
			ans+=max(it->second,cnt[iv[it->first]]);
			it->second=cnt[iv[it->first]]=0; 
		}
	printf("%d\n",ans+cnt0);
}

Measured memory_bytes: 19712
#include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

#define MOD 1000000007
using namespace std;
#define ll long long
inline long  toInt(string s) {long  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(){
  ll a,b;
  while(cin >> a >> b){
    cout << __gcd(a,b) << ' ' << a / __gcd(a,b) * b << endl;
  }
  
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, ans = 0;
    cin >> n;
    deque<int>dq(n);
    for(int i = 0;i < n;++i)
        cin >> dq[i];
    sort(dq.begin(), dq.end());
    while(dq.size() > 2)
    {
        int a = dq[0];
        for(int j = 1;j < dq.size();++j)
        {
            int b = dq[j];
            if(a > b)   swap(a, b);
            int hi = lower_bound(dq.begin(), dq.end(), a + b) - dq.begin();
            ans += hi - j - 1;
        }
        dq.pop_front();
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    while (n) {
        vector<string> data(n);
        rep(i, n) {
            string tmp;
            cin >> tmp;
            data[i].pb(tmp[0]);
            rep(j, tmp.length()-1) {
                if (tmp[j] == 'a' || tmp[j] == 'i' || tmp[j] == 'u' || 
                        tmp[j] == 'e' || tmp[j] == 'o') {
                    data[i].pb(tmp[j+1]);
                }
            }
        }
        bool out = false;
        Rep(k, 51) {
            bool fl = true;
            set<string> s;
            rep(i, n) {
                if (s.find(data[i].substr(0, k)) != s.end()) {
                    fl = false;
                    break;
                } else {
                    s.insert(data[i].substr(0, k));
                }
            }
            if (fl) {
                cout << k << endl;
                out = true;
                break;
            }
        }
        if (!out) {
            cout << -1 << endl;
        }
        cin >> n;
    }
    return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n,k,ans=0;
    cin>>n>>k;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    for(int i=0;i<k;i++){
        ans+=l[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
c=[list(map(int,input().split())) for i in range(3)]
xd=[[c[i][1]-c[i][0],c[i][2]-c[i][1]] for i in range(3)]
yd=[[c[1][i]-c[0][i],c[2][i]-c[1][i]] for i in range(3)]
if(xd[0]==xd[1]==xd[2] and yd[0]==yd[1]==yd[2]):
    print("Yes")
else:
    print("No")

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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define FORR(i,j,k,l) for(int i=j;i<=k;i+=l)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c)    scanf("%d %d %d", &a, &b, &c)
#define clean(mat,n)   FOR(i,0,n) mat[i].clear()
#define minn          (long long)-1000000000000000000
#define maxx          (long long) 1000000000000000000
#define mod          1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define LL           long long
#define NL '\n'
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define PB push_back
#define F first
#define S second
#define MAX 200010
#define MP make_pair
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
typedef pair<int,int> PR;

int n, m;
vector<int> mat[MAX];
string str;
int col[MAX], dude[MAX][4], can[MAX];
stack<int> stk;

int main()
{
    ios::sync_with_stdio(false);
    //inf;
    //outf;
    int a, b;

    cin >> n >> m;
    cin >> str;
    FOR(i,0,n-1)
    {
        int x = str[i] - 'A';
        col[i + 1] = x;
    }

    FOR(i,0,m-1)
    {
        cin >> a >> b;

        mat[a].PB( b ); dude[a][ col[b] ]++;
        mat[b].PB( a ); dude[b][ col[a] ]++;
    }

    FOR(i,1,n)
    {
        if(dude[i][0] && dude[i][1]) continue;

        stk.push( i );
        can[i] = 1;
    }

    while(!stk.empty())
    {
        int p = stk.top(); stk.pop();

        for(auto x : mat[p])
        {
            if(can[x]) continue;

            dude[x][ col[p] ]--;
            if(dude[x][0] && dude[x][1]) continue;

            stk.push( x );
            can[x] = 1;
        }
    }

    FOR(i,1,n)
    {
        if(can[i]) continue;
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 15696
def insertionSort(A, n, g):
        global count
        for i in range(g, n):
                v = A[i]
                j = i - g
                while j >= 0 and A[j] > v:
                        A[j + g] = A[j]
                        j = j - g
                        count += 1
                A[j + g] = v

def shellSort(A, n):
        global count
        count = 0
        G = [1]
        h = 4
        while h < n:
                G.append(h)
                h = 3 * h + 1
        G.reverse()
        m = len(G)
        strG = map(str, G)

        print(m)
        print(" ".join(strG))
        for i in range(m):
                insertionSort(A, n, G[i])

num = int(input())
array = []

for i in range(num):
        array.append(int(input()))

shellSort(array, len(array))
print(count)

for i in range(num):
        print(array[i])


Measured memory_bytes: 45516
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>x>>y>>z;
        cnt = (x+(z-1))/z;
        if(cnt<=y)
            cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;

long long gcd(long long a, long long b) { // 2つの場合の最大公約数
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
 
long long gcd_vec(vector<long long> const &A) { // N個の要素に対する最大公約数
    int size = (int)A.size();
    long long ret = A[0];
    for (int i = 1; i < size; i++) {
        ret = gcd(ret, A[i]);
    }
    return ret;
}

int main() {

int N;
ll X;
cin>>N>>X;

vector<ll> dist(N);
rep(i,N){
    ll x;
    cin>>x;
    dist[i]=abs(x-X);
}
ll ans = gcd_vec(dist);
cout<<ans<<endl;



return 0;
}



Measured memory_bytes: 1024
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
A = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    A[i] = (x, y)

A = sorted(A)

d = defaultdict(int)
for i in range(N):
    x1, y1 = A[i]
    for j in range(i + 1, N):
        x2, y2 = A[j]
        d[(x2 - x1, y2 - y1)] += 1

freq = 0
for v in d.values():
    freq = max(freq, v)
print(N - freq)

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

int main() {
  ll N, m=0;
  cin >> N;
  vector<string> S(N);
  set<string> ss;
  map<string,ll> M;
  for (ll i=0; i<N; i++) {
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
    ss.insert(S[i]);
    M[S[i]]++;
  }
  
  for (ll i=0; i<S.size(); i++) {
    string sss=S[i];
    if (ss.count(sss)) {
      ss.erase(sss);
      ll w=M[sss];
      m+=w*(w-1)/2;
    }
  }
  
  cout << m << endl;
}

Measured memory_bytes: 21860
#include<bits/stdc++.h>
using namespace std;
string debug_string(const string& s) {
	return '"' + s + '"';
}
string debug_string(bool b) {
	return (b ? "true" : "false");
}
string debug_string(const char* s) {
	return debug_string((string)s);
}
template<class T, class U>
string debug_string(const pair<T, U>& p);
template<class U>
struct can_be_string {
	template<typename...>
	static int f(...) {
		return 0;
	}
	template<typename T>
	static char f(decltype(to_string(T()), char())) { 
		return 'a';
	}
	static const bool value = sizeof(f<U>(char())) == sizeof(char);
};
template<class T> 
typename enable_if<can_be_string<T>::value, string>::type debug_string(const T& a) {
	string s = to_string(a);
	return s;
}
template<class T>
typename enable_if<!can_be_string<T>::value, string>::type debug_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += debug_string(x);
	}
	s += "}";
	return s;
}
template<class T, class U>
string debug_string(const pair<T, U>& p) {
	string s = "(";
	s += debug_string(p.first);
	s += ", ";
	s += debug_string(p.second);
	s += ")";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << debug_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18l + 100;
void max_self(int& a, int b) {
	a = max(a, b);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	vector<vector<int>> dp(n, vector<int>(m));
	vector<vector<pair<int, int>>> nax(n, vector<pair<int, int>>(m));
	dp[0][0] = s[0] == t[0];
	nax[0][0] = {-1, -1};
	pair<int, int> l = {0, 0};
	for (int i = 1;i < n;++i) {
		dp[i][0] = dp[i - 1][0];
		nax[i][0] = {i - 1, 0};
		max_self(dp[i][0], s[i] == t[0]);
	}
	l = {0, 0};
	for (int j = 1;j < m;++j) {
		dp[0][j] = dp[0][j - 1];
		nax[0][j] = {0, j - 1};
		max_self(dp[0][j], s[0] == t[j]);
	}
	for (int i = 1;i < n;++i) {
		for (int j = 1;j < m;++j) {
			int mx = max(dp[i - 1][j], dp[i][j - 1]);
			dp[i][j] = mx;
			if (mx == dp[i - 1][j]) {
				nax[i][j] = {i - 1, j};
			}
			else {
				nax[i][j] = {i, j - 1};
			}
			if (s[i] == t[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
				nax[i][j] = {i - 1, j - 1};
			}
		}
	}
	debug(dp);
	string cur;
	bool ok = false;
	pair<int, int> p = {n - 1, m - 1}, nax_p = {inf, inf};
	while (p != make_pair(-1, -1)) {
		if ((nax_p.first == 0 || nax_p.second == 0) && ok == false && s[nax_p.first] == t[nax_p.second]) {
			cur += s[nax_p.first];
			ok = true;
		}
		else if (p.first == nax_p.first - 1 && p.second == nax_p.second - 1) {
			cur += s[nax_p.first];
		}
		nax_p = p;
		p = nax[p.first][p.second];
	}
	if (s[0] == t[0] && !ok) {
		cur += t[0];
	}
	reverse(cur.begin(), cur.end());
	cout << cur << '\n';
	return 0;
}


Measured memory_bytes: 105984
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# import os
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str

    # write code
    A = list(S)
    A[K-1] = A[K-1].lower()
    print(''.join(A))


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

const int INF = 1e9;
int n, m, x;
int c[15], a[15][15];
int algo[15];
int ans = INF, cost;

bool ok() {
    for (int i = 0; i < m; i++)
        if (algo[i] < x) return false;
    return true;
}

void dfs(int i) {
    if (i == n) {
        if (ok()) ans = min(ans, cost);
        return;
    }
    cost += c[i];
    for (int j = 0; j < m; j++) algo[j] += a[i][j];
    dfs(i + 1);
    cost -= c[i];
    for (int j = 0; j < m; j++) algo[j] -= a[i][j];
    dfs(i + 1);
}

int main() {
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    dfs(0);
    cout << (ans == INF ? -1 : ans);
}


Measured memory_bytes: 3640
using System;




class Test {

    static void Main() {

        int a, b;

        string[] s = Console.ReadLine().Split(' ');

        a = int.Parse(s[0]);
        b = int.Parse(s[1]);
            
        Console.WriteLine("{0} {1}", a*b, a*2+b*2);

    }
    
}

Measured memory_bytes: 5620
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

constexpr int INF = (1 << 29);

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

int dist2(int x1, int y1, int x2, int y2) {
	const int diff_x = x1 - x2;
	const int diff_y = y1 - y2;
	return diff_x * diff_x + diff_y * diff_y;
}

string solve() {
	int n, X, Y;
	cin >> n >> X >> Y;

	int nx, ny;
	cin >> nx >> ny;

	vector<int> xs(n), ys(n), label(n, INF);
	queue<int> que;
	vector<vector<int>> es(n);

	for(int i = 0; i < n; ++i) {
		cin >> xs[i] >> ys[i];
		if(dist2(nx, ny, xs[i], ys[i]) <= 10 * 10) {
			que.push(i);
			label[i] = 1;
		}

		for(int j = 0; j < i; ++j) {
			if(dist2(xs[i], ys[i], xs[j], ys[j]) <= 50 * 50) {
				es[i].emplace_back(j);
				es[j].emplace_back(i);
			}
		}
	}

	if(X > Y) {
		if(que.empty()) return "0";
		while(!que.empty()) {
			const int v = que.front();
			for(const auto &to : es[v]) {
				if(label[to] == INF) return "You're always welcome!";
			}
			que.pop();
		}
		return to_string(X);
	}

	int mx = 0;
	while(!que.empty()) {
		const int v = que.front();
		que.pop();
		chmax(mx, label[v]);

		for(const auto &to : es[v]) {
			if(label[to] == INF) {
				label[to] = label[v] + 1;
				que.push(to);
			}
		}
	}
	return to_string(mx * X);
}

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

	int t;
	cin >> t;
	while(t--) cout << solve() << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5240
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef long long ll;
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
#define LAR(a, b) ((a)=max((a), (b)))
#define SML(a, b) ((a)=min((a), (b)))

int main(){
	int x, a; scanf("%d%d", &x, &a);
	printf("%d\n", x<a ? 0 : 10);
}


Measured memory_bytes: 256
N = int(input())
red = [[int(x) for x in input().split()] for _ in range(N)]
blue = [[int(x) for x in input().split()] for _ in range(N)]

red.sort(reverse=True)
blue.sort(key=lambda x: x[1])
pairedBlue = [False] * N

ans = 0
for r in red:
    for id, b in enumerate(blue):
        if pairedBlue[id]:
            continue
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            pairedBlue[id] = True
            break

print(ans)

Measured memory_bytes: 3064
N = int(input())
h = list(map(int, input().split()))

dp = [0]*N
for i in range(1,N):
    if i-2<0:
        dp[i] = dp[i-1] + abs(h[i]-h[i-1])
    else:
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]),
                   dp[i-2] + abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

struct UnionFind
{
    vector<long long> d;
    UnionFind(long long n = 0) : d(n, -1)
    {
    }

    //root : -size, not root: root
    long long root(long long x){
        if(d[x] < 0){
            return x; 
        }
        return d[x] = root(d[x]);
    }

    bool unite(long long x, long long y){
        x = root(x);
        y = root(y);
        if(x == y){
            return false;
        }
        if(d[x] > d[y]){
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    long long size(long long x){
        return -d[root(x)];
    }

    bool issame(long long a, long long b){
        return root(a) == root(b);
    }
};

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m; cin >> n >> m;
    UnionFind uf(n);
    vector<pll> vec(m);
    rep(i, m){
        cin >> vec[i].first >> vec[i].second;
        vec[i].first--; vec[i].second--;
    }

    vector<ll> ans(m);

    rep(i, m){
        if(i == 0){
            ans[i] = n * (n-1) / 2;
            continue;
        }
        ll l = vec[m-i].first;
        ll r = vec[m-i].second;
        if(uf.issame(l, r)){
            ans[i] = ans[i-1];
            continue;
        }
        ll num = uf.size(l) * uf.size(r);
        ans[i] = max(ans[i-1] - num, (ll)0);
        uf.unite(l, r);
    }

    rep(i, m){
        cout << ans[m - 1 - i] << endl;
    }


}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
#define time Time
#define pii pair<int,int>    
#define x first    
#define y second 
#define N 10000005   
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))    
#define sqr(x) ((x)*(x))
typedef long long LL;  
using namespace std;
const int mod=1e9+7;
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		long long 	int a[100005];
		int op[100005];
		op[0]=1;
		scanf("%lld",&a[0]);
		for(int i=1;i<n;i++){
			char c;
			while(scanf("%c",&c)&&c!='+'&&c!='-');
			if(c=='+')
			op[i]=1;
			else
			op[i]=0;
			scanf("%lld",&a[i]);
		} 
		long long int sum=0;
		for(int i=0;i<n;i++){
			sum+=a[i];
		}
		long long int ans=1e18;
		int i;
		int last;
		for(i=0;op[i]==1;i++);
		long long int ssum=0,sssum=0;
		for(;i<n;i++)
		{
			ssum+=a[i];
			if(op[i]==0)
			sssum+=a[i],last=i;
			if(op[i+1]==0||i+1==n)
			ans=min(ssum+sssum-a[last],ans),ssum=0;
			//printf("%lld\n",sssum);
		}
		ans=min(sssum,ans);
		printf("%lld\n",sum-2*ans);
	}
}
/*

 1 - 1 + 2 + 10 - 2 + 3  + 5
 1  - 2  - 3  
*/


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  int ans = 0;
  cin >> a >> b;
  if(a >= 13) ans = b;
  else if(a <= 5) ans = 0;
  else ans = (b / 2);
  cout << ans << endl;
}

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

class Dice{
  private:
    int* num;
  public:
    Dice(){
      num = new int[6];
    };
    ~Dice(){
      delete[] num;
    };
    void DiceSet(int index, int x){
      num[index] = x;
    };
    void DiceRoll(char x){
      int swp;
      switch(x){
        case 'E':
	  SwapFour(num[0],num[2],num[5],num[3]);
	  break;
	case 'S':
	  SwapFour(num[0],num[1],num[5],num[4]);
	  break;
	case 'W':
	  SwapFour(num[0],num[3],num[5],num[2]);
	  break;
	case 'N':
	  SwapFour(num[0],num[4],num[5],num[1]);
	  break;
      }
    };
    int DicePutTop(){
      return num[0];
    }
  private:
    // a->b->c->d->a
    void SwapFour(int &a, int &b, int &c, int &d){
      a ^= b; b ^= a; a ^= b;
      a ^= c; c ^= a; a ^= c;
      a ^= d; d ^= a; a ^= d;
    }
};

int main(){
  Dice dice;
  int label;
  char com;
  string s;

  for(int i=0;i<6;i++){
    cin >> label;
    dice.DiceSet(i,label);
  }
  cin >> s;
  for(int i=0;i<s.size();i++) dice.DiceRoll(s[i]);

  cout << dice.DicePutTop() << endl;
}


Measured memory_bytes: 3176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int[] A = new int[N];
			int[] copy = new int[N];
			for (int i = 0; i < N; i++) {
				A[i] = in.nextInt();
			}
			System.arraycopy(A, 0, copy, 0, N);
			Arrays.sort(copy);
			int max1 = copy[N - 1];
			int max2 = copy[N - 2];
			for (int i = 0; i < N; i++) {
				if(A[i] == max1) {
					out.println(max2);
				} else {
					out.println(max1);
				}
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 46428
#include "bits/stdc++.h"
using namespace std;
int n,l[2010];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",l+i);
	sort(l,l+n);
	int ans=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			int pos=lower_bound(l,l+n,l[i]+l[j])-l;
			ans+=max(0,pos-1-j);
		}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N; cin >> N;
int d[N], ans=0;
for(int i=0; i<N; i++){cin >> d[i];}
for(int i=0; i<N-1; i++){ for(int j=i+1; j<N; j++){ ans+=d[i]*d[j]; }}  
cout << ans << "\n";
}

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

long long n, a[MAXN], b[MAXN], c[MAXN], dp[MAXN][3];

int main() {
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	for (int i=1; i<=n; i++) {
		dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
	}

	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
}

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

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; }

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

    ll total = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                total += gcd(gcd(a, b), c);
            }
        }
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int H, W, K;

void init(vector< vector<int> > &v, vector< vector<int> > &E){
  E[0][0] = v[0][0];
  FOR(i, 1, H) E[i][0] = E[i - 1][0] + v[i][0];
  FOR(i, 1, W) E[0][i] = E[0][i - 1] + v[0][i];
  FOR(y, 1, H)
    FOR(x, 1, W)
    E[y][x] = v[y][x] + E[y - 1][x] + E[y][x - 1] - E[y - 1][x - 1];
}

int calc(int Y1, int X1, int Y2, int X2, vector< vector<int> > &E){
  int ret = E[Y2][X2];
  if(X1 - 1 >= 0) ret -= E[Y2][X1 - 1];
  if(Y1 - 1 >= 0) ret -= E[Y1 - 1][X2];
  if(X1 - 1 >= 0 && Y1 - 1 >= 0) ret += E[Y1 - 1][X1 - 1];
  return ret;
}

int main() {
  cin >>H >>W >>K;
  vector< vector<int> > J(H, vector<int>(W, 0));
  vector< vector<int> > cntJ(H, vector<int>(W, 0));
  vector< vector<int> > O(H, vector<int>(W, 0));
  vector< vector<int> > cntO(H, vector<int>(W, 0));
  vector< vector<int> > I(H, vector<int>(W, 0));
  vector< vector<int> > cntI(H, vector<int>(W, 0));
  REP(i, H){
    REP(j, W){
      char c; cin >>c;
      if(c == 'J') J[i][j] = 1;
      if(c == 'O') O[i][j] = 1;
      if(c == 'I') I[i][j] = 1;
    }
  }
  init(J, cntJ);
  init(O, cntO);
  init(I, cntI);
  REP(i, K){
    int x1, y1, x2, y2;
    cin >>y1 >>x1 >>y2 >>x2;
    --x1; --y1; --x2; --y2;
    cout <<calc(y1, x1, y2, x2, cntJ) <<" ";
    cout <<calc(y1, x1, y2, x2, cntO) <<" ";
    cout <<calc(y1, x1, y2, x2, cntI) <<endl;
  }


  return 0;
}

Measured memory_bytes: 24496
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	string s;cin>>s;
	if(s[0]!='A'){
		puts("WA");return 0;
	}
	string t=s.substr(2,s.size()-2-1);
	if(count(t.begin(),t.end(),'C')!=1){
		puts("WA");return 0;
	}
	string k=s.substr(1,1)+s.back();
	for(char c:k){
		if(isupper(c)){
			puts("WA");return 0;
		}
	}
	for(char c:t){
		if(c!='C'&&isupper(c)){
			puts("WA");return 0;
		}
	}
	puts("AC");
}

Measured memory_bytes: 256