akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
  input = input.trim();
  input = input.split("\n")
  var mem = input[1].split(" ")
  var a=mem[0].split("");
  var b= mem[1].split("");
  for(var i=0;i<input[0];i++){
  process.stdout.write(a[i])
  process.stdout.write(b[i])
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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


void solve(long long A, long long B, long long C){
    vector<long long> d(3, 0);
    d[0] = max(A, max(B, C)) - A;
    d[1] = max(A, max(B, C)) - B;
    d[2] = max(A, max(B, C)) - C;
    sort(d.begin(), d.end());
    //for(auto i : d) cout << i << endl;
    long long ans = 0;
    ans += d[1];
    d[2] -= d[1];
    d[1] -= d[1];
    //for(auto i : d) cout << i << endl;
    if(d[2] % 2 == 0) ans += d[2]/2;
    else ans += d[2]/2 + 2;
    cout << ans << endl;
    return;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 3692
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000
typedef long long i64;

int n;
int a[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	return 1;
}

void init() {
}

int cost(int x) {
	int d = 0;
	for (int i=0; i<n; i++) d += (a[i]-x)*(a[i]-x);
	return d;
}

int solve() {
	int s = 0;
	for (int i=0; i<n; i++) s+=a[i];
	int k = s/n;
	return min(cost(k), cost(k+1));
}

void output(int ans) {
	printf("%d\n", ans);
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
#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 each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int n;
  scanf("%d",&n);
  printf("%d\n",n*(n+1)/2);
}


Measured memory_bytes: 256
#!/usr/bin/env pytHon3
# -*- coding: utf-8 -*-


def divisible_length(n):
    min_length = len(str(n))
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            min_length = min(min_length, max(len(str(i)), len(str(n // i))))
    return min_length


def main():
    N = int(input())
    print(divisible_length(N))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in(), m = in(), x = in();
	ll cnt1 = 0, cnt2 = 0;
	REP(i, m)++ *(in() < x ? &cnt1 : &cnt2);
	cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 256
mod = 10**9+7
N = int(input())

A, G, C, T = 0, 1, 2, 3  # 文字を数字に割り当てる
# dp[n][最後の前の前の文字][最後の前の文字][最後の文字]:= 長さnも字列が何通り作れるか
dp = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
# 禁止されている文字列は [AGC, GAC, ACG] と [A*GC, AG*C]
# 数字に対応させると[012, 102, 021] と [0*12, 01*2]
# 末尾の3文字 + 今見ている1文字の合計4文字だけを見ればよい
# 文頭のTが影響を与えることはないので初期化時にTを使ってもよい
dp[0][T][T][T] = 1
for n in range(N):
    for c0 in range(4):
        for c1 in range(4):
            for c2 in range(4):
                for c3 in range(4):
                    # 禁止のパターンならcontinue
                    if c1 == A and c2 == G and c3 == C: continue
                    if c1 == G and c2 == A and c3 == C: continue
                    if c1 == A and c2 == C and c3 == G: continue
                    if c0 == A and c1 == G and c3 == C: continue
                    if c0 == A and c2 == G and c3 == C: continue
                    # nの値を進めるとともに、末尾の3文字列
                    dp[n+1][c1][c2][c3] += dp[n][c0][c1][c2]
                    dp[n+1][c1][c2][c3] %= mod
ans = 0
for c0 in range(4):
    for c1 in range(4):
        for c2 in range(4):
            ans += dp[N][c0][c1][c2]
            ans %= mod
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  
  vector<int> mp(n+1);
  for(int i = 0;i < n;i++){
    int num;
    cin >> num;
    mp.at(num) = i+1;
  }
  
  for(int i = 1;i <= n;i++){
    cout << mp.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 200007;
const int MOD = 1000000007;

void solve() {
    int n, k;
    cin >> n >> k;
    int count, temp;
    set<int> good;
    for (int i = 0; i < k; i++) {
        cin >> count;
        for (int j = 0; j < count; j++) {
            cin >> temp;
            good.insert(temp);
        }
    }
    cout << n - good.size();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    vector<long long int> v(n,0);
    for(long long int i=0;i<n;i++)
    {
        long long int value;
        cin>>value;
        v[i]=value;
    }
    long long int dp[n]={0};
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(long long int i=2;i<n;i++)
    {
        long long int k1=abs(v[i]-v[i-1])+dp[i-1];
        long long int k2=abs(v[i]-v[i-2])+dp[i-2];
        if(k1>k2)
        {
            dp[i]=k2;
        }
        else
        {
            dp[i]=k1;
        }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    if(n %2 == 1){
        cout << n*2 << endl;
    }

    else cout << n << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int flag = 0;
		if(a.length() > b.length())
			flag = 1;
		else if(a.length() < b.length())
			flag = -1;
		else{
			for(int i = 0; i < a.length(); i++){
				int aCur = a.charAt(i) - '0';
				int bCur = b.charAt(i) - '0';
				if(aCur > bCur){
					flag = 1;
					break;
				}
				else if(aCur < bCur){
					flag = -1;
					break;
				}
			}
		}
		
		if(flag == 1){
			System.out.println("GREATER");
		}
		else if(flag == 0){
			System.out.println("EQUAL");
		}
		else{
			System.out.println("LESS");
		}
		
		sc.close();
	}

}

Measured memory_bytes: 22484
#include <stdio.h>

int main(void)
{
    int n, m;
    int a[1000];
    int i, j;
    int max;

    while (1){    
        scanf("%d%d", &n, &m);
        if (n == 0 && m == 0){
            break;
        }
    
        for (i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        
        max = -1;
        for (i = 0; i < n - 1; i++){
            for (j = i + 1; j < n; j++){
                if (a[i] + a[j] <= m){
                    if (max < a[i] + a[j]){
                        max = a[i] + a[j];
                    }
                }
            }
        }
        
        if (max == -1){
            printf("NONE\n");
        }
        else {
            printf("%d\n", max);
        }
    }
    
    return (0);
}



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

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

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,l[10000],r[10000],hito=0;
    cin>>n;
    for(int i=0;i<n;i++){
		cin>>l[i]>>r[i];
		hito+=r[i]-l[i]+1;
	}
	cout<<hito<<endl;
}


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

using namespace std;

int main(void){
	int n, a[5000], res[5000], sum, i, j, ans;
	while(1){
		scanf("%d",&n);
		if(!n){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%d",&a[i]);
		}
		sum = 0;
		for(i = 0;i < n;i++){
			sum += a[i];
			res[i] = sum;
		}
		ans = res[0];
		for(i = 0;i < n;i++){
			ans = max(ans,res[i]);
			for(j = 0;j < i;j++){
				ans = max(ans,res[i] - res[j]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<string.h>
int n,m,t;
char ch1[10],ch2[10];
int abs(int x)
{
	if(x>=0) return x;
	else return 0-x;
}
int main()
{
	while(~scanf("%d",&n)){
		int sum,xi=0,yi=0,ti=0;
		int mark=1;
		for(int i=0;i<n;i++)
		{
			int x0,y0,t0;
			scanf("%d %d %d",&t0,&x0,&y0);
			int ds=abs(x0-xi)+abs(y0-yi);
			int dt=t0-ti;
			if(dt<ds) mark=0;
			else {
				m=dt-ds;
				if(m%2==1) mark=0;
			}
			ti=t0;xi=x0;yi=y0;
		}
		if(mark==0) printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
import math
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
sm = math.ceil(a/10)*10+math.ceil(b/10)*10+math.ceil(c/10)*10+math.ceil(d/10)*10+math.ceil(e/10)*10
mi = max((10-a%10)%10,(10-b%10)%10,(10-c%10)%10,(10-d%10)%10,(10-e%10)%10)
print(sm-mi)

Measured memory_bytes: 38384
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n, m;
char grid[1001][1001];
int memo[1001][1001];
int mod = 1e9 + 7;

int dp(int x, int y)
{
    if (x == n || y == m) return 0;
    if (x == n - 1 && y == m - 1) return 1;
    if (grid[x][y] == '#') return 0;
    if (memo[x][y] != -1) return memo[x][y];
    return memo[x][y] = (dp(x + 1, y) % mod + dp(x, y + 1) % mod) % mod;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    memset(memo, -1, sizeof(memo));
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> grid[i][j];
        }
    }
    cout << dp(0, 0) << endl;

    return 0;
}

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

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.size() / 2; i++)
        if (S[i] != S[S.size() - 1 - i]) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	map<int, int> mp;
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		mp[x]++;
	}
	int ans = 0;
	for(int i = -1; i < 1e5 + 5; i++){
		ans = max(ans, mp[i - 1] + mp[i] + mp[i + 1]);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
#define lnt(s) (ll)s.length()
#define mt(cnt) cnt.empty()
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;

using pll = pair<ll, ll>;
using pl = pair<ll, pll>;
using tll = tuple<ll, ll, ll>;

const ll maxN = 5e5 + 11;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll n, q;

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];
ll bit[maxN];

struct que{
    ll l, r, idx;
};

que queries[maxN];

bool cmp(que x, que y){
    return x.r < y.r;
}

void upd(ll idx, ll val, ll n){
    for(; idx<=n; idx+=idx&-idx)
        bit[idx] += val;
}

ll query(ll idx, ll n){
    ll ans = 0;
    for(; idx>0; idx-=idx&-idx)
        ans += bit[idx];
    return ans;
}

void offAns(){
    memset(bit, 0, sizeof(bit));
    ll lv[maxN];
    memset(lv, -1, sizeof(lv));
    ll ans[q];
    ll quecnt = 0;
    for(ll i=0; i<n; i++){
        if(lv[A[i]] != -1)
            upd(lv[A[i]]+1, -1, n);
        lv[A[i]] = i;
        upd(i+1, 1, n);
        while(quecnt  < q and queries[quecnt].r == i){
            ans[queries[quecnt].idx] = query(queries[quecnt].r+1, n)-query(queries[quecnt].l, n);
            quecnt++;
        }
    }
    for(ll i=0; i<q; i++)
        cout << ans[i] << "\n";
}

inline ll left(ll x){
    return x << 1;
}

inline ll right(ll x){
    return (x<<1) + 1;
}

ll func(ll x){
    return (x*(x+1))/2;
}

ll _pow(ll b, ll p){
    if(p == 0) return 1;
    if(p == 1) return b;
    ll exB = b*b;
    if(p&1) return b*_pow(exB, p/2);
    return _pow(exB, p/2);
}

int main(){
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    for(ll i=0; i<n; i++)
        cin >> A[i];
    for(ll i=0; i<q; i++){
        cin >> queries[i].l >> queries[i].r;
        --queries[i].l, --queries[i].r;
        queries[i].idx = i;
    }
    sort(queries, queries+q, cmp);
    offAns();
    return 0;
}

Measured memory_bytes: 31196
#include<iostream>
#include<queue>
#include<cstdio>
#include<string>
using namespace std;

int main()
{
	int key;
	char c[10];
	priority_queue<int> q;

	while (1) {
		scanf("%s", c);
		if (c[0] == 'e' && c[1] == 'n') break;
		if (c[0] == 'i') {
			scanf("%d", &key);
			q.push(key);
		}
		else if (c[0] == 'e') {
			cout << q.top() << endl;
			q.pop();
		}
	}

	return 0;
}


Measured memory_bytes: 6980
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;
 
int main(){
    string A,B;
 
    cin >> A >> B;

    if(A.size() < B.size()){
        cout << "LESS" << endl;
    }else if(A.size() > B.size()){
        cout << "GREATER" << endl;
    }else{
        if(A.compare(B) > 0){
            cout << "GREATER" << endl;
        }else if(A.compare(B) == 0){
            cout << "EQUAL" << endl;
        }else{
            cout << "LESS" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <string>

using namespace std;
long long f(long long a,long long cnt){
  long long ret=1;
  if(cnt==0)return 1;
  if(cnt%2==1){
    long long x = f(a,cnt/2);
    return a*x*x;
  }
  else {
    long long x = f(a,cnt/2);
    return x*x;
  }
}
int main(){
  long long int n,m,i,j,k,p;
  long long ret=1;
  cin >> n >> p;
  for(i=2;i*i<=p;i++){
    long long cnt=0;
    long long x = 1;
    while(p%i==0){
      cnt++;
      p/=i;
    }
    x = f(i,cnt/n);
    if(cnt>=n)ret*=x;
  }
  if(n==1&&p>0)ret*=p;
  /*map<long long,long long>::iterator itr;
  for(itr=mp.begin();itr!=mp.end();itr++){
    if(itr->second<n)continue;
    ret*=(itr->first)*(itr->second/n);
  }*/
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll M = 1e9 + 7;
ll inf = 1e18;

ll n, m;


int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];
	//rep(i, n) cout << a[i] << " ";
	ll pf[n];
	rep(i, n) {
		if (i == 0)
			pf[i] = a[i];
		else
			(pf[i] = pf[i - 1] + a[i]) %= M;
	}
	ll sum = 0;
	for (i = 0; i < n - 1; i++) {
		sum = (sum % M + (a[i] % M * (pf[n - 1] - pf[i] + M) % M) % M) % M;
	}
	cout << sum;

	return 0;
}

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

#define PQ priority_queue
#define P pair<int,int>
#define CLA(array) memset(array,0,sizeof array)
#define CLINF(array) memset(array,0x3f,sizeof array)
#define CLF(array) memset(array,-1,sizeof array)
#define DB(a) cout << "DEBUG " << a << endl;
#define rep(i,a,b) for(int i=(int)a;i<(int)b;i++)
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100000 + 50;
const int INF = 1 << 30;
const int maxn = 1e5 + 5;


struct edge
{
    int v;
    LL w;
    edge(int v_, LL w_):v(v_), w(w_){}
};
LL dis[maxn];
int vis[maxn];
vector<edge>G[maxn];
void dfs(int u, LL d)
{
    vis[u] = 1;
    dis[u] = d;
    for (int i = 0; i < G[u].size(); i++){
        int v = G[u][i].v;
        if (vis[v]) continue;
        dfs(v, d + G[u][i].w);
    }
}
int main(){
    int n;
    scanf("%d", &n);
    memset(G, 0, sizeof G); 
    for (int i = 1; i < n; i++){
        int u, v;
        LL w;
        scanf("%d %d %lld", &u, &v, &w);
        G[u].push_back(edge(v, w));
        G[v].push_back(edge(u, w));
    }
    int q, k;
    scanf("%d %d", &q, &k);
    memset(vis, 0, sizeof vis); 
    dfs(k, 0);
    for (int i = 1; i <= q; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        cout << dis[u] + dis[v] << endl;
    }

    return 0;
}

Measured memory_bytes: 14720
import java.math.BigInteger;
import java.util.*;
public class Main {

	static int MOD = 1000000007;
	
	static long modpow(int N, int K) {
		return BigInteger.valueOf(N).modPow(BigInteger.valueOf(K), BigInteger.valueOf(MOD)).longValue();
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long ans = 0;
		long[] x = new long[K+1];
		for(int i = K; i >= 1; i--) {
			x[i] = modpow(K/i, N);
			for(int j = i * 2; j <= K; j += i)
				x[i] -= x[j];
			ans = (ans + x[i] * i) % MOD;
		}
		while(ans < 0)
			ans += MOD;
		System.out.println(ans);
	}

}


Measured memory_bytes: 63584
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,v,f[200000],w[101],c[101],ans;
int main()
{
	cin>>n>>v;
	for(int i=0;i<n;i++)
		cin>>w[i]>>c[i];
	for(int i=0;i<=100000;i++)
		f[i]=pow(10,16);
	f[0]=0;
	for(int i=0;i<n;i++)
		for(int j=100000;j>=0;j--)
			if(f[j]!=pow(10,16))
				f[j+c[i]]=min(f[j+c[i]],f[j]+w[i]);
	for(int i=0;i<=100000;i++)
		if(f[i]<=v)
			ans=i;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <unordered_set>
using namespace std;

#define ll long long


int main()
{
	string s;
	cin >> s;
	
	unordered_set<char> us;
	for (int i = 0; i < s.length(); i++)
	{
		us.insert(s[i]);
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, M; cin >> N >> M;
VP ba(M); rep(i, 0, M) cin >> ba[i].second >> ba[i].first;

sort(ALL(ba));
int b = ba[0].first;
int cnt = 1;

rep(i, 1, M){
    if (ba[i].second >= b){
        ++cnt;
        b = ba[i].first;
    }
}

cout << cnt << endl;

}

// 境界，出力文字列 チェック



Measured memory_bytes: 1152
s = str(input())
n = len(s)
if s[0] == "A":
    cntC = 0
    for i in s[2: n - 1]:
        if i == "C":
            cntC += 1
    if cntC == 1:
        cnt = 0
        for j in s:
            if j.isupper():
                cnt += 1
        if cnt == 2:
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<utility>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<queue>
#include<deque>
#include<sstream>
#include<bitset>
#include<bits/stdc++.h>
using namespace std;
bool PD(int x)
{
	int f=x/10000;
	int s=x/1000%10;
	int fo=x%10000%1000%100/10;
	int la=x%10000%1000%100%10;
	if (f==la and s==fo) return true;
	else
	return false;
}
int main()
{
	int a,b,cnt;
	cin>>a>>b;
	for (int i=min(a,b);i<=max(a,b);i++)
	{
		if (PD(i)) cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cout << (s[0] == s[1] && s[2] == s[3] && s[1] != s[2] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(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 push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// C - Shopping Street
int N;
int F[100][10];
int P[100][11];
int sum[100];
int ans = -2000000000;

int main(){
    cin >> N;
    rep(i, 0, N){
        rep(j, 0, 10){
            cin >> F[i][j];
        }
    }
    rep(i, 0, N){
        rep(j, 0, 11){
            cin >> P[i][j];
        }
    }
    int L = 10;
    // 2^L - 1回の全探索
    for(int i=0;i<1<<L;++i){
        if(i==0) continue;
        int r;
        rep(j, 0, N){
            sum[j] = 0;
        }
        for(r=0;r<L;++r){
            // Bitが立っているときの処理
            if((i & (1 << r)) != 0){
                rep(j, 0, N){
                    sum[j] += F[j][r];
                }
            }
        }
        int tmp=0;
        rep(j, 0, N){
            tmp += P[j][sum[j]];
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class c{
    public static void Main(){
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int m = int.Parse(str[1]);
        var dict = new Dictionary<int, List<int>>();
        int[] from = new int[n];
        int cnt = 0;
        for(int i=0; i<m; i++){
            int[] num = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            num[0]--; num[1]--;
            if(!dict.ContainsKey(num[0])){
                dict[num[0]] = new List<int>();
            }
            if(!dict.ContainsKey(num[1])){
                dict[num[1]] = new List<int>();
            }
            dict[num[0]].Add(num[1]);
            dict[num[1]].Add(num[0]);
        }
        for(int i=0; i<n; i++){
            from[i] = -1;
        }
        for(int i=0; i<n; i++){
            if(cnt == n) break;
            var que = new Queue<int>();
            que.Enqueue(i);
            while(que.Count > 0){
                var cur = que.Dequeue();
                if(from[cur] != -1) continue;
                if(dict.ContainsKey(cur)){
                    foreach(var to in dict[cur]){
                        if(from[to] == -1){
                            que.Enqueue(to);
                        }
                    }
                }
                from[cur] = i;
                cnt++;
            }
        }
        //Console.WriteLine(string.Join(" ",from));
        bool[] al = new bool[n];
        int ans = 0;
        for(int i=0; i<n; i++){
            if(al[from[i]]) continue;
            ans++;
            al[from[i]] = true;
        }
        Console.WriteLine(ans-1);
    }
}


Measured memory_bytes: 39520
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
  // input
    int h,w;cin >> h >> w;
    vector<vector<char>> init(h + 1, vector<char>(w + 1));
    for(int i = 1;i < h + 1 ; i++) {
        for(int j = 1; j < w + 1; j++){
            cin >> init[i][j];
        } 
    }
  
    //debug 
    /*
    for(int i = 1;i < h + 1 ; i++) {
      for(int j = 1; j < w + 1; j++){
        cout << init[i][j];
      }
    }   
    */

    vector<vector<int>> a(h + 1, vector<int>(w + 1));
    for(int i = 1;i < h + 1 ; i++) {
        for(int j = 1; j < w + 1; j++){
            if(init[i][j] == '#'){
                a[i][j] = 1;
            }else{
                a[i][j] = 0;
            }
        } 
    }
  
  //debug
   /*
    for(int i = 1;i < h + 1 ; i++) {
        for(int j = 1; j < w + 1; j++){
                cout << a[i][j];
          if(j == w){
                cout << endl;
          }
        } 
    }
    */
  
    

  // compute 
    set<int> st1;
    set<int> st2;
    for(int i = 1;i < h + 1; i++) {
        st1.insert(i);
    }
    for(int i = 1;i < w + 1; i++) {
        st2.insert(i);
    }

    vector<int> check_h(h + 1);
    vector<int> check_w(w + 1);
    for(int i = 1;i < h + 1; i++) {
        check_h[i] = 0;
    }
    for(int i = 1;i < w + 1; i++) {
        check_w[i] = 0;
    }

    for(int i = 1;i < h + 1 ; i++) {
        for(int j = 1; j < w + 1; j++){
            if(a[i][j] == 1){
                check_h[i] = 1;
                break;
            }
        } 
    }

    for(int j = 1;j < w + 1 ; j++) {
        for(int i = 1; i < h + 1; i++){
            if(a[i][j] == 1){
                check_w[j] = 1;
                break;
            }
        } 
    }

    for(int i = 1;i < h + 1 ; i++) {
        if(check_h[i] == 0){
            st1.erase(i);
        }
    }

    for(int i = 1;i < w + 1 ; i++) {
        if(check_w[i] == 0){
            st2.erase(i);
        }
    }

  // output  
    for(int i = 1;i < h + 1 ; i++) {
        	bool p = st1.count(i);
        	if( !p) continue;
      	for(int j = 1; j < w + 1; j++){
			bool q = st2.count(j);
          if(p && q){
            cout << init[i][j];
          }
          if(j == w){
            cout << endl;
          }
        }
    }

}


Measured memory_bytes: 3700
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X;
	cin >> X;

	int big_point = X / 500;
	int small_point = (X % 500) / 5;

	cout << big_point * 1000 + small_point * 5;

	return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int a[100000];
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int c0,c1,c2;
  c0=c1=c2=0;
  for(i=0;i<n;i++){
    if(a[i]%4==0){
      c2++;
    } else if(a[i]%2==0){
      c1++;
    } else {
      c0++;
    }
  }
  if(c0>c2+1){
    printf("No\n");
    return;
  }
  if(c0==c2+1){
    printf("%s\n",c1==0?"Yes":"No");
  } else {
    printf("Yes\n");
  }
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#include <cstdint>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

/*
long solve(long x, long k, long d){
    x = std::abs(x);
    if(x - k*d >= 0){
        return x - k*d;
    }
    long rem = x % (2*d);
    if(rem > d){
        rem = std::abs(rem - 2*d);
    }
    if(k % 2 == 0){
        return rem;
    }else{
        return std::abs(rem - d);
    }
}
//*/

long solve(long x, long k, long d){
    x = std::abs(x);
    if(k-x/d <= 0){
        return x-k*d;
    }
    long rem = x % (2*d);
    long ans;
    if(k % 2 == 0){
        ans = std::min(rem, std::abs(rem-2*d));
    }else{
        ans = std::abs(rem-d);
    }
    return ans;
}

long tester(long x, long k, long d){
    for(int i = 0; i < k; i++){
        if(x < 0){
            x += d;
        }else{
            x -= d;
        }
    }
    return std::abs(x);
}

int main(){
    //*
    long x, k, d;
    scanf("%ld%ld%ld", &x, &k, &d);
    printf("%ld\n", solve(x, k, d));
    //*/
    /*
    std::random_device seed_gen;
    std::mt19937_64 engine(seed_gen());
    while(1){
        long x = engine() % 1000 - 500;
        long k = engine() % 1000;
        long d = engine() % 1000;
        if(solve(x, k, d) != tester(x, k, d)){
            printf("%ld %ld %ld, %ld %ld\n", x, k, d, solve(x, k, d), tester(x, k, d));
            return  0;
        }
    }
    //*/
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char str[N];

int main()
{
    int n;
    cin>>n;
    cin>>str;
    int ans=1;
    for(int i=1;i<n;i++)
    {
        if(str[i]!=str[i-1])
            ans++;
    }
    cout<<ans<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstring>

int n, a;
int x[50];

long long int memo[2501][50][50];

long long int solve(int sum, int m, int num) {
	if (memo[sum][m][num] >= 0)
		return memo[sum][m][num];
	sum += x[num];
	++m;
	long long int res = 0;
	if (sum%m == 0 && sum / m == a) {
		++res;
	}
	for (int i = num + 1; i < n; ++i) {
		res += solve(sum, m, i);
	}
	sum -= x[num];
	--m;
	return memo[sum][m][num] = res;
}

int main() {
	std::memset(memo, -1, sizeof(memo));
	std::cin >> n >> a;
	for (int i = 0; i < n; ++i)
		std::cin >> x[i];
	std::sort(x, x + n);
	long long int ans = 0;
	for (int i = 0; i < n; ++i) {
		ans += solve(0, 0, i);
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int main(void) {
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  vector<int> ans(n, 0);
  
  for (int i=0; i<k; i++) {
    vector<long long> ls(n, 0);
    vector<long long> rs(n, 0);
    
    for (int j=0; j<n; j++) {
      int l = max(j - a[j], 0);
      int r = min(j + a[j], n-1) + 1;
      ls[l]++;
      if (r < n) rs[r]++;
    }
    
    ans[0] = ls[0] - rs[0];
    
    for (int j=1; j<n; j++) {
      ls[j] += ls[j-1];
      rs[j] += rs[j-1];
      ans[j] = ls[j] - rs[j];
    }
      
    for (int j=0; j<n; j++) a[j] = ans[j];
    if (a[0] == n && a[n-1] == n) break;
    
  }
  
  for (int i=0; i<n; i++) cout << ans[i] << " ";

}


Measured memory_bytes: 7996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    string S;
    cin >> N >> S;
    ll red = 0;
    ll blue = 0;
    ll green = 0;
    rep(i,N){
        if (S[i] == 'R') red++;
        if (S[i] == 'B') blue++;
        if (S[i] == 'G') green++;
    }
    ll ans = (red * blue) * green;
    rep(i,N){
        for (int j = i + 1; j < N; j++){
            if (S[i] == 'R' && S[j] == 'B'){
                if (i + i - j >= 0 && S[i + i - j] == 'G'){
                    ans--;
                }
            }
            else if (S[i] == 'R' && S[j] == 'G'){
                if (i + i - j >= 0 && S[i + i - j] == 'B'){
                    ans--;
                }
            }
            else if (S[i] == 'B' && S[j] == 'R'){
                if (i + i - j >= 0 && S[i + i - j] == 'G'){
                    ans--;
                }
            }
            else if (S[i] == 'B' && S[j] == 'G'){
                if (i + i - j >= 0 && S[i + i - j] == 'R'){
                    ans--;
                }
            }
            else if (S[i] == 'G' && S[j] == 'R'){
                if (i + i - j >= 0 && S[i + i - j] == 'B'){
                    ans--;
                }
            }
            else if (S[i] == 'G' && S[j] == 'B'){
                if (i + i - j >= 0 && S[i + i - j] == 'R'){
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  int a = s.size(), z = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') a = min(a, i);
    if (s[i] == 'Z') z = max(z, i);
  }
  cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

struct WeightedUnionFind
{
  vector<int> uni, dw;

  explicit WeightedUnionFind(int n): uni(n+5, -1), dw(n+5, 0) {}

  inline int   weight(int x)       { root(x); return dw[x]; }
  inline int   diff(int x, int y)  { return weight(y) - weight(x); }
  inline bool  same(int x, int y)  { return root(x) == root(y); }

  inline int root(int x) {
    if (uni[x] < 0) { return x; }
    int r = root(uni[x]);
    return dw[x] += dw[uni[x]],  uni[x] = r;
  }

  inline int unite(int x, int y, int w) {
    w += weight(x) - weight(y);
    x = root(x); y = root(y);
    if (x == y) { return false; }
    if (uni[y] < uni[x]) swap(x,y), w = -w;
    uni[x] += uni[y]; uni[y] = x; dw[y] = w;
    return true;
  }
};

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

  int N, M;
  cin >> N >> M;

  WeightedUnionFind wuf(N);

  for (int i= 0; i < M; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    if ( !wuf.unite(l, r, d) && wuf.diff(l,r) != d ) {
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";

  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 200000

vector<int> G[MAX_N];
bool colored[MAX_N] = {};
int cnt = 0;

void dfs(int v, int pre, bool color) {
    colored[v] = color;
    if (color) cnt++;
    for (auto to : G[v]) {
        if (to == pre) continue;
        dfs(to, v, !color);
    }
}

signed main() {
    int n;
    cin >> n;
    int a, b;
    rep(i, n - 1) {
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    dfs(0, -1, true);
    int ans[n];
    if ((n + 1) / 3 > cnt) {
        int now = 3;
        bool fixed[n] = {}, used[n + 1] = {};
        rep(i, n) {
            if (colored[i]) {
                ans[i] = now;
                fixed[i] = true;
                used[now] = true;
                now += 3;
            }
        }
        now = 1;
        rep(i, n) {
            if (!fixed[i]) {
                if (used[now]) now++;
                ans[i] = now;
                now++;
            }
        }
    } else if ((n + 2) / 3 > n - cnt) {
        int now = 3;
        bool fixed[n] = {}, used[n + 1] = {};
        rep(i, n) {
            if (!colored[i]) {
                ans[i] = now;
                fixed[i] = true;
                used[now] = true;
                now += 3;
            }
        }
        now = 1;
        rep(i, n) {
            if (!fixed[i]) {
                if (used[now]) now++;
                ans[i] = now;
                now++;
            }
        }
    } else {
        int now[3];
        iota(now, now + 3, 1);
        rep(i, n) {
            if (colored[i]) {
                if (now[0] > n) {
                    ans[i] = now[2];
                    now[2] += 3;
                } else {
                    ans[i] = now[0];
                    now[0] += 3;
                }
            } else {
                if (now[1] > n) {
                    ans[i] = now[2];
                    now[2] += 3;
                } else {
                    ans[i] = now[1];
                    now[1] += 3;
                }
            }
        }
    }
    rep(i,n){
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 17920
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int N,M;
ll ans;
int t[100003];
bool v[100003];
struct job
{
	int a;ll b;
}j[100003];
inline bool cmp(const job &x,const job &y)
{
	if(x.b==y.b)return x.a>y.a;
	return x.b>y.b;
}
int main()
{
	scanf(" %d %d",&N,&M);
	for(int i=0;i<N;++i)
	{
		scanf(" %d %lld",&j[i].a,&j[i].b);
	}
	for(int i=0;i<=M;++i)t[i]=i-1;
	sort(j,j+N,cmp);
	for(int i=0;i<N;++i)
	{
		int k=M-j[i].a;
		if(k<0)continue;
		if(!v[k])
		{
			ans+=j[i].b;v[k]=true;continue;
		}
		while(v[t[k]])t[k]=t[t[k]];
		if(t[k]>=0)ans+=j[i].b,v[t[k]]=true,t[k]=t[t[k]];
	}
	printf("%lld\n",ans);
	return 0;
}

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


int main(){
	string S;
	cin >> S;
	vector<bool> news(4, false);
	rep(i,S.size()){
		if(S[i] == 'N') news[0] = true;
		if(S[i] == 'W') news[1] = true;
		if(S[i] == 'S') news[2] = true;
		if(S[i] == 'E') news[3] = true;
	}
	if(news[0] == news[2]&&news[1] == news[3]) cout << "Yes" << endl;
	else cout << "No" << endl;

			
}














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

using namespace std;

const int N = 1e5;

vector <int> ad[2 * N];
int n, m;
void dfs(int v, int d)
{
	if(d == 0)
	{
		for(int i = 0; i <= ad[v].size(); i++)
		{
			dfs(ad[v][i], 1);	
		}
	}
	else
	{
		for(int i = 0; i < ad[v].size(); i++)
		{
			int u = ad[v][i];
			if(u == n)
			{
				cout << "POSSIBLE";
				exit(0);
			}
		}
	}
}

int main() {
	cin >> n >> m;
	while(m-- > 0)
	{
		int x, y;
		cin >> x >> y;
		ad[x].push_back(y);
		ad[y].push_back(x);	
	}
	dfs(1, 0);
	cout << "IMPOSSIBLE";
	return 0;
}

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

int root[100001];
long size[100001];
long ans[100001];
int A[100001],B[100001];

int find(int a){
	if(a==root[a]) return a;
	return root[a]=find(root[a]);
}
long unite(int a,int b){
	int x=find(a);
	int y=find(b);
	if(x==y) return 0;
	root[y]=x;
	long ret=size[x]*size[y];
	size[x]+=size[y];
	return ret;
}


int main(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++) cin >> A[i] >> B[i];
	
	for(int i=0;i<n;i++){
		root[i]=i;
		size[i]=1;
	}
	ans[m-1]=1L*n*(n-1)/2;
	for(int i=m-2;i>=0;i--){
		ans[i]=ans[i+1]-unite(A[i+1]-1,B[i+1]-1);
	}
	for(int i=0;i<m;i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 4096
from collections import Counter


def solve():
    N = int(input())
    c = Counter(map(int, input().split()))
    usables = sorted([k for k, v in c.items() if v > 1])

    if len(usables) == 0:
        return 0
    else:
        ans = usables[-1]
        if c[ans] > 3:
            return ans ** 2
        elif len(usables) > 1:
            usables.pop()
            return ans * usables[-1]
        else:
            return 0


print(solve())


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


def main(S, w):
    l = list(S)
    index = 0
    retval = ''
    while index < len(l):
        retval = retval + l[index]
        index += w
    print(retval)
    

if __name__ == '__main__':
    try:
        S = input().strip()
        w = int(input().strip())
        main(S, w)
    except EOFError:
        pass


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long a,i,n=0;
    long long c=100;
    cin>>a;
    for(i=1;i>=1;i++)
    {
        c+=(c/100);
        n++;
        if(c>=a)
        {
            cout<<n<<endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;
const int mod = 998244353;
int n;
long long A, B, K;
long long fct[500000];
long long rfct[500000];
long long mypow(long long n, long long k) {
    if (k == 0) return 1;
    long long x = mypow(n, k / 2);
    x = x * x % mod;
    if (k & 1) x = x * n % mod;
    return x;
}
long long cnk(long long n, long long k) {
    return ((fct[n] * rfct[n - k]) % mod) * rfct[k] % mod;
}
vector<long long> good[500000];
long long solve(int n, long long K) {
    if (K < 0) return 0;
    int x = K % B;
    if (good[x].size() == 0) return 0;
    auto it = upper_bound(good[x].begin(), good[x].end(), K);
    if (it == good[x].begin()) return 0;
    it--;
    long long c = 0, f = 0;
    while (1) {
        if (*it / A <= n &&  (K - *it) / B <= n) {
            f = cnk(n, *it / A);
            f = f * cnk(n, (K - *it) / B) % mod;
            c += f;
            if (c >= mod) c -= mod;
        }
        else break;
        if (it == good[x].begin()) break;
        it--;
    }
    return c;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> A >> B >> K;
    if (A < B) swap(A, B);
    fct[0] = 1;
    for (int i = 1; i <= n; i++) fct[i] = fct[i - 1] * i % mod;
    rfct[0] = 1;
    for (int i = 1; i <= n; i++) rfct[i] = mypow(fct[i], mod - 2);
    long long ans = 0;
    for (int i = 0; i <= n; i++) good[(A * i) % B].push_back(A * i);
    cout << solve(n, K) << "\n";
    return 0;
}


Measured memory_bytes: 24832
#include <iostream>
#include <vector>

using namespace std;

int abs(int a) {
    return a >= 0 ? a : -a;
}

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

    vector<int> a(n + 2, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int base = 0;
    for (int i = 1; i <= n + 1; i++) {
        base += abs(a[i] - a[i - 1]);
    }

    for (int i = 1; i <= n; i++) {
        cout << base - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << endl;
    }
}


Measured memory_bytes: 1664
// https://atcoder.jp/contests/abc160/tasks/abc160_a

use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! { s: String, }
    let s: Vec<char> = s.chars().collect();
    let ans = if s[2] == s[3] && s[4] == s[5] {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 2156
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    char s1[1005],s2[1005];
    scanf("%s",s1);
    scanf(" %s",s2);
    int len1 = strlen(s1);
    int len2 = strlen(s2);
    int ans = 1e8;
    for(int i=0; i+len2<=len1; ++i){
        int t = 0;
        //枚举不相等的个数
        for(int j=0; j<len2; ++j){
            if(s1[i+j]!=s2[j])
                t++;
        }
        ans = min(ans,t);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3720