akhauriyash/Code-Regression huggingface dataset:
/**
*    author:  boutarou
*    created: 28.06.2020 21:09:26
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const double PI = 3.1415926535897932;

int d;
int c[30];
int s[400][30];
int ans[400];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
    }
    rep (i, d) {
        cin >> ans[i];
        ans[i]--;
    }
    int cnt = 0;
    int previous[30];
    rep(i, 26) previous[i] = -1;
    rep(i, d) {
        cnt += s[i][ans[i]];
        previous[ans[i]] = i;
        rep(j, 26) {
            cnt -= c[j] * (i - previous[j]);
        }
        cout << cnt << endl;
    }
    
    return 0;
}

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

using namespace std;

#define ll  long long
#define X   first
#define Y   second

#define all(x)  x.begin(),x.end()
#define sz(x)   (int)x.size()

#define pb      emplace_back
#define endl    "\n"

const ll    inf = 1e18;
const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;

    vector<ii>  S;

    for(int i = 1 ; i <= n ; ++i)   {
        int x;  cin >> x;
        int l;  cin >> l;

        S.pb(x + l,x - l);
    }

    sort(all(S));

    int L = -1e9;
    int C = 0;

    for(ii  T : S)
        if (T.Y >= L)   {
            C++;
            L = T.X;
        }
    cout << C << endl;
}


Measured memory_bytes: 1400
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val r = sc.nextInt()

    val handicap =
      if (n <= 10) {
        10 - n
      } else {
        0
      }

    val ans = r + (100 * handicap)

    println(ans)
  }
}


Measured memory_bytes: 25928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll bit[200010]={},n;
 
ll sum(ll i){
  ll s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}
 
void add(ll i,ll x){
  while(i<=n+1){
    bit[i]+=x;
    i+=i&-i;
  }
}

int main(){
  ll k,a[200010],ans=0,s[200010]={};
  P p[200010]={};
  cin>>n>>k;
  fr(i,n){cin>>a[i];a[i]-=k;s[i+1]=s[i]+a[i];}
  Fr(i,n+1) p[i]=mp(s[i-1],i);
  sort(p+1,p+n+2);
  Fr(i,n+1){
    ans+=sum(p[i].sd);
    //cout<<i<<" "<<p[i].sd<<endl;
    add(p[i].sd,1);
    //cout<<i<<" "<<p[i].sd<<endl;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8064
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M = MI()

nl = [list() for _ in range(N + 1)]
rev = [list() for _ in range(N + 1)]
deg = [0 for _ in range(N + 1)]
for _ in range(N - 1 + M):
    A, B = MI()
    nl[A].append(B)
    rev[B].append(A)
    deg[B] += 1

for i, l in enumerate(deg):
    if i > 0 and l == 0:
        root = i
        break

stack = [root]
tsorted = list()
while len(stack) > 0:
    v = stack.pop()
    tsorted.append(v)
    for next_v in nl[v]:
        deg[next_v] -= 1
        if deg[next_v] == 0:
            stack.append(next_v)

ans = [0] * (N + 1)
p = {root: 0}
for v in tsorted:
    ans[v] = p[v]
    for next_v in nl[v]:
        p[next_v] = v
for a in ans[1:]:
    print(a)

Measured memory_bytes: 79920
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

bool check(const vector<int>& A, long long K, long long m) {
  long long count = 0;
  for (size_t i = 0; i < A.size(); i++) {
    // add smallest k s.t. A[i]/k <= m to count
    long long k = (A[i] - 1) / m;
    count += k;
  }
  return (count <= K);
}

int main(void) {
  long N, K;
  cin >> N >> K;
  vector<int> A(N);
  int l = 1, u = 0;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    u = max(u, A[i]);
  }
  while (true) {
    if (l == u) break;
    long long m = (l + u) / 2;
    // cout << l << "," << u << "," << m << endl;
    if (check(A, K, m)) {  // m can be achieved
      u = m;
    } else {
      l = m + 1;
    }
  }
  cout << l << endl;
  return 0;
}

Measured memory_bytes: 3928
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N;
    ll ans = 0;
    cin >> N;
    ll tmp = 0;
    rep(i, N){
        ll a;
        cin >> a;
        tmp += a;
        if(a == 0 || i == N - 1){
            ans += tmp / 2;
            tmp = 0;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
map<char,ll> mp;
int main(){
ll n;
cin>>n;
ll sqr_n=(ll)sqrt((double)n)+10;
int ans=INT_MAX;
for(ll i=1;i<=sqr_n;i++){
    if(n%i==0){
        int cnt=0;
        ll tmp=max(i,n/i);
        while(tmp!=0){tmp/=10;cnt++;}
        ans=min(cnt,ans);
    }
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#define r return
i,j,n,max[6];
dx[8]={1,1,0,-1,-1,-1,0,1};
dy[8]={0,1,1,1,0,-1,-1,-1};
char table[10][10],mark[2]={'o','x'};
 
int l(int dx,int dy,int x,int y,char m,int c){
  if(table[x][y]=='.'||table[x][y]=='0')r 0;
  if(table[x][y]==m)r c;
  r l(dx,dy,x+dx,y+dy,m,c+1);
}
int search(int x,int y,char m){
  int k,c;
  c = 0;
  if(table[x][y]!='.')r 0;
  for(k=0;k<8;k++){
    c += l(dx[k],dy[k],x+dx[k],y+dy[k],m,0);
  }
  r c;
}
int okikae2(int dx,int dy,int x,int y,char m){
  if(table[x][y]=='0'||table[x][y]=='.')r 0;
  else if(table[x][y]==m)r 1;
  else if(okikae2(dx,dy,x+dx,y+dy,m)){
    table[x][y]=m;
    r 1;
  }
  else r 0;
}
int okikae(int x,int y,char m){
  int k;
  table[x][y]=m;
  for(k=0;k<8;k++){
    okikae2(dx[k],dy[k],x+dx[k],y+dy[k],m);
  }
  r 0;
}
 
int main(){
  for(i=0;i<10;i++)table[0][i]=table[9][i]='0';
  for(i=1;i<9;i++){
    scanf("%s",&table[i][1]);
    table[i][0]='0';
    table[i][9]='0';
  }
  max[1]=-1;
  for(n=0;;n=(n+1)%2){
    max[n]=-1;
    for(i=n?8:1;n?i>-1:i<9;n?i--:i++){
      for(j=n?8:1;n?j>-1:j<9;n?j--:j++){
        if(max[n]<search(i,j,mark[n])){
          max[2+n]=i;
          max[4+n]=j;
          max[n]=search(i,j,mark[n]);
        }
      }
    }
    if(max[n]!=0)okikae(max[2+n],max[4+n],mark[n]);
    if(max[0]==0&&max[1]==0)break;
  }
  for(i=1;i<9;i++){
    for(j=1;j<9;j++){
      printf("%c",table[i][j]);
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include <algorithm>
using namespace std;
int a,b,c,d,n,m,num;
int t [2000];
bool flg=false;
void compute(int x){
  if(num!=a){
    for(int i=x;i<n;i++){
      if(num+t[i]<=a){
    num+=t[i];
    if(num==a)flg=true;
    if(i+1<n)compute(i+1);
    num-=t[i];
      }
    }
  }
   
}
 
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    flg=false;
    cin>>a;
    num=0;
    compute(0);
    if(flg)cout<<"yes"<<endl;
    if(!flg)cout<<"no"<<endl;
  }
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

bool is_dislike_nums(int n, string d) {
    string n_str = to_string(n);
    bool is_dislike_num = false;

    for(int i=0; i<n_str.size(); i++) {
        // 嫌いな数字として見つかった場合
        if(find(d.begin(), d.end(), n_str[i]) != d.end()) {
            is_dislike_num = true;
        }
    }
    return is_dislike_num;
}
int main() {
    int n, k;
    cin >> n >> k;
    string d(k, '0');
    for(int i=0; i<k; i++) cin >> d[i];
    
    while(is_dislike_nums(n, d)) {
        n++;
    }
    cout << n << endl;

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



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

int w[100];
int v[100];
long long dp[101][100001];

int main() {
    int n, W;
    cin >> n >> W;
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= W; j++) {
            if (j >= w[i]) {
                dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
            
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 78336
#!python3

import sys
iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, Q = iim()

    S = [[i] for i in range(N)]

    def find(i):
        x = S[i]
        while True:
            k = S[i][0]
            if k == i:
                x[0] = i
                return i
            S[i] = x
            i = k
    def union(i, j):
        ai = find(i)
        aj = find(j)
        if ai != aj:
            S[aj][0] = S[ai][0]
            S[aj] = S[ai]

    def same(i, j):
        ai = find(i)
        aj = find(j)
        return ai == aj

    ans = []
    for com, x, y in (map(int, line.split()) for line in sys.stdin):

        if com == 0:
            union(x, y)
            #print(x, y, *tuple(map(lambda x: (x, hex(id(x))[-4:]), S)))
        elif com == 1:
            ans.append(1 if same(x, y) else 0)
        else:
            raise 1
    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()



Measured memory_bytes: 8164
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;

	bool ans;
	foreach (i; 1..101)
	{
		auto x = A * i - C;
		if (x % B == 0)
			ans = true;
	}

	writeln(ans ? "YES" : "NO");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt(); 
		int h = sc.nextInt(); 
		int w = sc.nextInt(); 
		System.out.println((H-h)*(W-w)); 
	}
}

Measured memory_bytes: 23892
N,M,X,Y = map(int,input().split())
xl = list(map(int,input().split()))
yl = list(map(int,input().split()))

if min(yl)-max(xl)>0:
    if min(yl)<=Y and min(yl)>X:
        ans = 'No War'
    else:
        ans = 'War'
else:
    ans = 'War'
    
print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
#include<cstdio>
#include<vector>
#include<utility>
#include<queue>

typedef vector<pair<int, int> > adj;
  
#define WHITE 0   // not visited yet.
#define GRAY 1    // already finded.
#define BLACK 2   // already searched.

struct current_cost
{
    int index, cost;
    bool operator < (const current_cost &cur) const
    {
        return cost > cur.cost;
    }
};

current_cost init(int i, int c)
{
    current_cost cur;
    cur.index = i, cur.cost = c;
    return cur;
}

int main()
{
    int i, j, k, n, m, r, next, cost;
    scanf("%d %d %d", &n, &m, &r);
    adj *adlist;
    adlist = new adj [n];

    for(int k = 0; k < m; k++){
        scanf("%d %d %d", &j, &next, &cost);
        adlist[j].push_back(make_pair(next, cost));
    }

    int *d;
    d = new int [n];
    for(i = 0; i < n; i++){ d[i] = -1; }
    d[r] = 0;

    priority_queue<current_cost> C;
    current_cost cur = init(r, 0);
    C.push(cur);

    int size;
    int *check;
    check = new int [n];
    for(i = 0; i < n; i++){ check[i] = WHITE; }
	check[r] = GRAY;

	int rest = 1;
    while(!C.empty())
    {
        cur = C.top(); C.pop();
        i = cur.index;
        if(check[i] == BLACK) continue;
        check[i] = BLACK; rest--;
 
        size = adlist[i].size();
        for(int j = 0; j < size; j++){
            int k = adlist[i][j].first;
            if(d[k] < 0 || d[i] + adlist[i][j].second < d[k]){
                d[k] = d[i] + adlist[i][j].second;
                C.push(init(k, d[k]));
				if(check[k] == WHITE){ check[k] = GRAY; rest++; }
            }
        }
		if(rest == 0) break;
    };
    for(i = 0; i < n; i++){
        (check[i] == BLACK ? printf("%d\n", d[i]) : printf("INF\n"));
    }
    return 0;
}

Measured memory_bytes: 11636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll l,r;cin>>l>>r;
    int ans = 10000;
    int f = 0;
    for (int i=l;i<=r;i++){
        for (int j=i+1;j<=r;j++){
            ans = min(ans,(i%2019)*(j%2019)%2019);
            if (i%2019==0 || j%2019==0){
                f = 1;
                break;
            }
        }
        if (f) break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
long long MOD = 1e9+7;
long long n,k;
long long a[2010];
long long b[2010];
long long c[2010];
long long ans;
int main(){
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i]>a[j]){
				if(i<j){
					b[i]++;
				}
				else c[i]++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		ans += (((k*(k-1LL)/2LL)%MOD)*c[i])%MOD;
		ans += (((k*(k+1LL)/2LL)%MOD)*b[i])%MOD;
		ans = ans%MOD;
	}
	printf("%lld\n",ans%MOD);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

ll n;
vector<ll> v;

int main(){
    cin >> n;
    ll m;
    for(int i=0;i<n;i++){
        cin >> m;
        v.push_back(m);
    }
    sort(v.begin(),v.end());
    ll l = v[v.size()-1];
    auto r = lower_bound(v.begin(),v.end(),l/2);
    ll a=-1,b=-1;
    if(r != v.end()) a = *r;
    if(r != v.begin()) b = *(r-1);
    if(a == -1){
        cout << l << " " << b << endl;
        return 0;
    }
    if(b == -1){
        cout << l << " " << a << endl;
        return 0;
    }
    if(l%2 == 0){
        if(abs(l/2-a) >= abs(l/2-b)){
            cout << l << " " << b << endl;
        }else{
            cout << l << " " << a << endl;
        }
    }else{
        if(abs(l/2-a) >= abs(l/2+1-b)){
            cout << l << " " << b << endl;
        }else{
            cout << l << " " << a << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int lenx,leny;
	lenx = x1 - x2;
	leny = y2 - y1;
	cout << " " << x2 - leny<< " " << y2 - lenx << " " << x1 - leny << " " << y1 - lenx;
}

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

#define PROB "PIZZA"
#define vi vector<int>

void init(){
    freopen(PROB".inp","r",stdin);
    freopen(PROB".out","w",stdout);
}

int main(){
    int A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;
    if (X<Y){
        swap(X,Y);
        swap(A,B);
    }
    int res=min(A+B,2*C)*Y;
    X-=Y;
    res+=min(A,2*C)*X;
    cout<<res;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio> 
using namespace std;
int G[100][100];

int main()
{
    int n;
    cin>>n;
    int u,v,k;
    for (int i = 0; i < n; i++)
    {
        cin>>u>>k;
        for (int j = 0; j < k; j++)
        {
            cin>>v;
            G[u-1][v-1] = 1;
        } 
    } 
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout<<G[i][j];
            if (j!=n-1) cout<<" ";
        }  
        cout<<endl;
    } 
    return 0;
}

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


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

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

  vector<vector<long long int> > dp(n, vector<long long int>(n, 0));
  for(int i = 0; i < n; i++){ dp[i][(i + 1) % n] = a[i]; }
  
  for(int k = 1; k < n; k++){
    for(int i = 0; i < n; i++){
      int leftstart = (i - 1 + n) % n;
      int end = (i + k) % n;
      int rightend = (i + k + 1) % n;

      // ??????DP?????????
      // ??????[i, i+k)????????§????£?????????????????????¨????????????
      // ?¬?????£???????????£????a[i-1]???a[i+k]????????????????????§??????
      
      if(dp[i][end] == 0){ continue; }

      // ?£????????????????????????¶??°?????£??????????¬????JOI???????????????
      if(k % 2 == 0){
        dp[leftstart][end] = max(dp[leftstart][end], a[leftstart] + dp[i][end]);
        dp[i][rightend] = max(dp[i][rightend], dp[i][end] + a[end]); 
      }
      // ?£???????????????????????\???°?????£??????????¬????IOI??????????????????
      else{
        if(a[leftstart] > a[end])
          dp[leftstart][end] = max(dp[leftstart][end], dp[i][end]);
        else
          dp[i][rightend] = max(dp[i][rightend], dp[i][end]);
      }
    }
  }
  
  long long int ans = 0;
  for(int i = 0; i < n; i++){ ans = max(ans, dp[i][i]); }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 34264
#include<iostream>
#include<string>
#include<stdio.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	char c;
	cin >> c;
	if (c == 'A') cout << "T" << endl;
	else if (c == 'T') cout << "A" << endl;
	else if (c == 'C') cout << "G" << endl;
	else cout << "C" << endl;
	return 0;
}


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

signed main()
{
    int n , b[101] , a[101] = {};
    bool f = true;

    cin >> n;
    for(int i=0 ;i<n ;i++ ){
        cin >> b[i];
        if( b[i] > i + 1 ){
            f = false;
        }
    }

    if(f){
        for(int i=0 ;i<n ;i++ ){
            for(int j=99 ;j>=b[i] - 1 ;j-- ){
                a[j+1] = a[j];
            }

            a[ b[i] - 1] = b[i];
        }

        for(int i=0; a[i] != 0 ;i++ ){
            cout << a[i];
            if(a[i+1] != 0){
                cout << ' ';
            }
        }
    } else {
        cout << -1;
    }
    cout << endl;

    return (0);
}

Measured memory_bytes: 3640
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int a, b;
    cin >> a >> b;

    if(a >= 13){
        cout << b << endl;
        return 0;
    }
    if(a <= 5){
        cout << 0 << endl;
        return 0;
    }
    cout << b / 2 << endl;

    return 0;
}


Measured memory_bytes: 384
n = int(input())
x,y = 0,0
for i in range(n):
    d = input().split()
    if d[0] == d[1]:
        x += 1
        y += 1
    else:
        a = list(d[0])
        b = list(d[1])
        for i in range(min(len(a),len(b))):
            if int(a[i],36) > int(b[i],36):
                x += 3
                break
            elif int(a[i],36) < int(b[i],36):
                y += 3
                break
            if i == min(len(a),len(b))-1:
                if len(a) < len(b):
                    y += 3
                else:
                    x += 3

print(x,y)

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

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    if (x == 0) return y;
    else if (y == 0) return x;
    if (x%y == 0) {
        return y;
    }
    else {
        return gcd(y, x%y);
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) cin >> A.at(i);
    vector<int> L(N);
    vector<int> R(N+1);
    L.at(0) = 0;
    R.at(N) = 0;
    for (int i=1; i<N; i++) {
        L.at(i) = gcd(L.at(i-1), A.at(i-1));
    }
    for (int i=N-1; i>=0; i--) {
        R.at(i) = gcd(R.at(i+1), A.at(i));
    }
    vector<int> M(N);
    for (int i=0; i<N; i++) {
        M.at(i) = gcd(L.at(i), R.at(i+1));
    }
    sort(M.begin(), M.end());
    cout << M.at(N-1) << endl;
}

Measured memory_bytes: 1792
import itertools

N = int(input())
MARCH=[0]*5
ans = 0
for _ in range(N):
    S = (input())[0]
    if S == 'M':
        MARCH[0]+=1
    if S == 'A':
        MARCH[1]+=1
    if S == 'R':
        MARCH[2]+=1
    if S == 'C':
        MARCH[3]+=1
    if S == 'H':
        MARCH[4]+=1

C =  itertools.combinations(MARCH, 3)
for c in C:
    ans += c[0]*c[1]*c[2]

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int n, q, s, t, x, u, a[1 << 18], i;
iP b[1 << 18];
bool f;

void update(int k, int l, int r) {
	if (!(t < l || r <= s)) {
		if (s <= l&&r - 1 <= t) {
			a[k] = x*(r - l);
			b[k] = mkp(x, i);
		}
		else {
			if (b[k].second > b[k * 2].second) {
				b[k * 2] = b[k];
				a[k * 2] = b[k].first*(r - l) / 2;
			}
			if (b[k].second > b[k * 2 + 1].second) {
				b[k * 2 + 1] = b[k];
				a[k * 2 + 1] = b[k].first*(r - l) / 2;
			}
			update(k * 2, l, (l + r) / 2);
			update(k * 2 + 1, (l + r) / 2, r);
			a[k] = a[k * 2] + a[k * 2 + 1];
		}
	}
}
int getSum(int k,int l,int r){
	if (t < l || r <= s)return 0;
	else if (s <= l&&r - 1 <= t)
		return a[k];
	else {
		if (b[k].second > b[k * 2].second) {
			b[k * 2] = b[k];
			a[k * 2] = b[k].first*(r - l) / 2;
		}
		if (b[k].second > b[k * 2 + 1].second) {
			b[k * 2 + 1] = b[k];
			a[k * 2 + 1] = b[k].first*(r - l) / 2;
		}
		int A = getSum(k * 2, l, (l + r) / 2) + getSum(k * 2 + 1, (l + r) / 2, r);
		a[k] = a[k * 2] + a[k * 2 + 1];
		return A;
	}
}
int main(){
	cin >> n >> q;
	for (u = 1; u < n; u *= 2);
	for (i = 1; i != q + 1; ++i) {
		cin >> f >> s >> t;
		if (f)
			cout << getSum(1, 0, u) << endl;
		else {
			cin >> x;
			update(1, 0, u);
		}
	}
	return 0;
}



Measured memory_bytes: 5944
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    int R, C, K;
    cin >> R >> C >> K;

    vector<vector<vector<ll>>> grid(R+1, vector<vector<ll>>(C+1, vector<ll>(5, 0)));
    vector<vector<ll>> treasure(R+1, vector<ll>(C+1, 0));
    rep(i, 0, K) {
        ll r, c, v;
        cin >> r >> c >> v;
        --r, --c;
        treasure[r][c] = v;
    }

    // dynamic programing
    rep(i, 0, R)
        rep(j, 0, C) {
            // get treasure
            rrep(n, 3, 0)
                grid[i][j][n+1] = max(grid[i][j][n+1], grid[i][j][n]+treasure[i][j]);

            rep(n, 0, 4) {
                // move horizontally
                grid[i][j+1][n] = max(grid[i][j+1][n], grid[i][j][n]);
                // move vertically
                grid[i+1][j][0] = max(grid[i+1][j][0], grid[i][j][n]);
            }
        }

    cout << *max_element(grid[R-1][C-1].begin(), grid[R-1][C-1].end()) << endl;
    return 0;
}


Measured memory_bytes: 706172
from collections import deque
n, m = map(int, input().split())
d = [[] for _ in range(n+1)]
ans = [0] * (n)
for _ in range(m):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

q = deque([1])
while not len(q) == 0:
    x = q.popleft()
    for i in d[x]:
        if ans[i-1] == 0:
            ans[i-1] = x
            q.append(i)

if 0 in ans:
    print('No')
else:
    print('Yes')
    s  = "\n".join(map(str, ans[1:]))
    print(s)

Measured memory_bytes: 41888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<pair<int, ll>>>;
void dfs(int v, int p, Graph &edge, vector<ll> &dist) {
    auto &c = dist[v];
    for (auto x: edge[v]) {
        if (x.first == p) continue;
        dist[x.first] = x.second + c;
        dfs(x.first, v, edge, dist);
    }
}

int main() {
    int n;
    cin >> n;
    Graph edge(n);
    for (int i = 1; i < n; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        edge[a].emplace_back(b, c);
        edge[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    vector<ll> dist(n);
    dist[k] = 0;
    dfs(k, -1, edge, dist);
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        ll ans = dist[x] + dist[y];
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 100005;

int n , ara[N] , k , s;
int main()
{
    FastRead
    cin >> n >> k >> s;

    if(s > n){
        for(int i = 1;i <= k;i++)ara[i] = s;
        for(int i = k + 1;i <= n;i++)ara[i] = s - 1;
    }else{
        for(int i = 1;i <= k;i++)ara[i] = s;
        for(int i = k + 1;i <= n;i++)ara[i] = 1e9;
    }

    for(int i = 1;i <= n;i++)cout << ara[i] << " ";

//    int cnt = 0;
//    for(int i = 1;i <= n;i++){
//        LL sum = 0;
//        for(int j = i;j <= n;j++){
//            sum += ara[j];
//            if(sum == s)cnt++;
//        }
//    }
//    assert(cnt == k);

}



Measured memory_bytes: 1664
import java.util.Scanner;
 
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x[] = new int[n];
    for(int i = 0; i < n; i++){
      x[i] = sc.nextInt();
    }
    int hensa[] = new int[n];
  	double hensa2, hensa3,D2,D3;
    int D1 = 0;
    D2 = 0;
    D3 = 0;
    for(int i = 0; i < n; i++){
      int y = sc.nextInt();
      hensa[i] = x[i] - y;
      if(hensa[i] < 0){
        hensa[i] = -hensa[i];
      }
      hensa2 = Math.pow(hensa[i],2);
      hensa3 = Math.pow(hensa[i],3);
      D1 += hensa[i];
      D2 += hensa2;
      D3 += hensa3;
    }
  	int max = hensa[0];
    for(int i = 1; i < n; i++){
      if(hensa[i] >= max){
        max = hensa[i];
      }
    }
    System.out.println(String.format("%5f",(double)D1));
    System.out.println(String.format("%5f",Math.sqrt(D2)));
    System.out.println(String.format("%5f",Math.cbrt(D3)));
    System.out.println(String.format("%5f",(double)max));
  }
}


Measured memory_bytes: 26488
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

/*1-6,2-5,3-4,4-3,5-2,6-1*/
/*
    5         n
  4-1-3     w-u-e
    2         s
    6         b
*/
int top,west,north;
//map<string,int> table;
static string n="North";
static string s="South";
static string e="East";
static string w="West";
static string u="Up";//top
static string b="Bottom";

string l="Left";
string r="Right";

/*reference:http://blog.livedoor.jp/kenyoi/archives/4185821.html*/
//a=top,up; b=west; c=north;
int foo(string t){
  int tmp;
  if(t.compare(n)==0){
    tmp=north;north=top;top=7-tmp;
  }
  else if(t.compare(s)==0){
    tmp=top;top=north;north=7-tmp;
  }
  else if(t.compare(e)==0){
    tmp=top;top=west;west=7-tmp;
  }
  else if(t.compare(w)==0){
    tmp=west;west=top;top=7-tmp;
  }
  else if(t.compare(r)==0){
    tmp=north;north=west;west=7-tmp;
  }
  else if(t.compare(l)==0){
    tmp=west;west=north;north=7-tmp;
  }
  return top;
}

int main(void){
  int num;
  while(cin>>num){
    if(num==0) return 0;
    //a=top,up; b=west; c=north;
    top=1,west=4,north=5;
    int sum=1;
    for(int i=0;i<num;i++){
      string tmp;
      cin>>tmp;
      sum+=foo(tmp);
    }
    printf("%d\n",sum);
  }
}












/*
tanorthle.insert(make_pair(n,5));
table.insert(make_pair(s,2));
table.insert(make_pair(u,1));
table.insert(make_pair(b,6));

/*table.insert(make_pair(w,4));
table.insert(make_pair(e,3));

//use the easiest way
//just simulate it....

void bsun(){
  int tmp=table[n];
  table[n]=table[u];
  table[u]=table[s];
  table[s]=table[b];
  table[b]=tmp;
}
void wue(){
  int tmp=table[w];
  table[w]=table[b];
  table[b]=table[e];
  table[e]=table[u];
  table[u]=tmp;
}
void rotate(){
  //clockwise
  int tmp=table[w];
  table[w]=table[s];
  table[s]=table[e];
  table[e]=table[n];
  table[n]=tmp;
}

void test(){
  printf("  %d   \n",table[n]);
  printf("%d-%d-%d\n",table[w],table[u],table[e]);
  printf("  %d   \n  %d   \n",table[s],table[b]);
}

int main(int args, char *argc[]){


  int num;
  while(cin>>num){
    if(num==0) return 0;
    string tmp;
    int sum=1;

    table[n]=5;table[s]=2;
    table[u]=1;table[b]=6;

    table[w]=4;table[e]=3;

    for(int i=0;i<num;i++){
      cin>>tmp;
      if(tmp.compare(n)==0){
        bsun();
      }
      else if(tmp.compare(s)==0){
        bsun();
        bsun();
        bsun();
      }
      else if(tmp.compare(e)==0){
        wue();
      }
      else if(tmp.compare(w)==0){
        wue();
        wue();
      }
      else if(tmp.compare("Right")==0){
        rotate();
      }
      else{//case Left
        rotate();
        rotate();
        rotate();
      }
        sum+=table[u];
        test();printf("sum:%d\n\n",sum);

    }
    cout<<sum<<endl;
  }
  return 0;
}
*/


Measured memory_bytes: 1228
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d;
    cin >> d;
    vector<int> c(26);
    for(int i=0; i<26; i++) cin >> c[i];
    vector<vector<int>> G(d,vector<int> (26));
    for(int i=0; i<d; i++){
        for(int j=0; j<26; j++){
            cin >> G[i][j];
        }
    }
    vector<int> t(d);
    int sum = 0;
    vector<int> l(26,0);
    vector<int> n(26,0);
    for(int i=0; i<d; i++){
        int mx = -inf;
        int id = -1;
        for(int j=0; j<26; j++){
            if(chmax(mx,c[j]*((i+1)-l[j]))){
                id = j;
            }
        }
        l[id] = i+1;
        n[id] += G[i][id];
        for(int j=0; j<26; j++){
            n[id] -= c[j] * ((i+1) - l[j]);
        }
    }
    for(int i=0; i<26; i++) sum += n[i];
    for(int k=0; k<10000; k++){
        vector<P> pre(100);
        for(int i=0; i<100; i++){
            int a = rand() % d;
            int b = rand() % 26;
            pre[i].first = a;
            pre[i].second = t[a];
            t[a] = b;
        }
        vector<ll> now(26,0);
        vector<int> last(26,0);
        for(int i=0; i<d; i++){
            last[t[i]] = i+1;
            now[t[i]] += G[i][t[i]];
            for(int j=0; j<26; j++){
                now[t[i]] -= c[j] * (i+1 - last[j]);
            }
        }
        int s = 0;
        for(int j=0; j<26; j++){
            s += now[j];
        }
        if(s > sum){
            sum = s;
        }else{
            for(int i=0; i<100; i++){
                t[pre[i].first] = pre[i].second;
            }
        }
    }
    for(int i=0; i<d; i++){
        cout << t[i]+1 << "\n";
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef pair<string, ll> psi;
typedef pair<ll, string> pis;
typedef pair<ll, vll> plv;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define REP(i, a, b) for(ll i=ll(a);i<=ll(b);++i)
#define REPR(i, a, b) for(ll i=ll(a);i>=ll(b);--i)
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()

template<typename T>
T absolute(T a, T b) { return a >= 0 ? a : -a; }

template<typename T>
T sqr(T a) { return a * a; }

ll read() {
    ll res, f = 1;
    register char ch;
    while ((ch = getchar()) > '9' || ch < '0')(ch == '-') && (f = -1);
    for (res = ch - '0'; (ch = getchar()) >= '0' && ch <= '9'; res = res * 10 + ch - '0');
    return res * f;
}

int main() {
    fastio
    ll n;
    cin>>n;ll c=0,maxi=0;
    vll v;
    while(n){
        v.pb(n%10);
        n/=10;
    }
    c=v.size();
    if(v[1]<v[2])maxi=v[2];
    else if(v[1]>v[2]) maxi=v[2]+1;
    else{
        if(v[0]<=v[2])maxi=v[2];
        else maxi=v[2]+1;
    }
    while(c--){
        cout<<maxi;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
struct ToUpper {
    char operator()(char c) { return toupper(c); }
};
struct ToLower {
    char operator()(char c) { return tolower(c); }
};
const int N=200010;
const int P=1000000007;
using ll = long long;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
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;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/

/*
	char s[N];
	strlen(s)
*/

/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/

/*添字1がa個、2がb個
  vector<vector<ll>> map(a,vector<ll>(b));
*/


int main(){
  ll n;
  cin>>n;
  ll ans=0;
  for(ll i=1;i<=n;i++){
    ans+=i*(n/i)*(n/i+1)/2;
  }
  cout<<ans<<endl;
}
      

Measured memory_bytes: 3564
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	long long K;
	cin >> S >> K;
	int ans = 1;
	for (long long n = 0;n<min(K,(long long)S.size());++n) {
		if (1 != S[n]-'0') {
			ans = S[n] - '0';
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

const int MX = 1e5 + 5;
int n, a[MX];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int sign = 1;
	ll curr = 0;
	for (int i = 1; i <= n; ++i, sign = -sign) {
		curr += sign * a[i];
	}
	for (int i = 1; i <= n; ++i) {
		cout << curr << ' ';
		curr = a[i] - curr / 2;
		curr *= 2;
	}
	return 0;
}



Measured memory_bytes: 1664
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
    int n = int.Parse(Console.ReadLine());
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		Console.WriteLine(LargestRectangle(nums));
	}

  static long LargestRectangle(long[] lengths)
  {//x軸に接する底辺1、高さlengthsの長方形を繋げた時、最大長方形の面積をO(n)で返す
    if(lengths.Length == 0) return 0;
    long answer = lengths[0];
    int n = lengths.Length;
    var rectangleStack = new Stack<long[]>();//x座標と高さ
    rectangleStack.Push(new long[2]{0,lengths[0]});
    long[] topMemo = new long[2];
    
    for(int i = 1; i < n; i++)
    {
      if(rectangleStack.Count() > 0) topMemo = rectangleStack.Peek();
      
      if(topMemo[1] < lengths[i]) rectangleStack.Push(new long[2]{i,lengths[i]});
      else if(topMemo[1] > lengths[i])
      {
        long memo = 0;
        while(rectangleStack.Count() > 0)
        {
          if(rectangleStack.Peek()[1] > lengths[i])
          {
            answer = Math.Max(answer, rectangleStack.Peek()[1]*(i-rectangleStack.Peek()[0]));
            memo = rectangleStack.Peek()[0];
            
            if(rectangleStack.Count() == 1)
            {
              rectangleStack.Pop();
              rectangleStack.Push(new long[2]{memo, lengths[i]});
              break;
            }
            else rectangleStack.Pop();
          }else
          {
            rectangleStack.Push(new long[2]{memo, lengths[i]});
            break;
          }
        }
      }

      if(i == n-1 && rectangleStack.Count() > 0)
      {
        while(rectangleStack.Count() > 0)
        {
          answer = Math.Max(answer, rectangleStack.Peek()[1]*(i-rectangleStack.Peek()[0]+1));
          rectangleStack.Pop();
        }
      }
    }

    return answer;
  }
  
}


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

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

ll H, W;
ll dy[4] = { 0,  0, -1, +1};
ll dx[4] = {-1, +1,  0,  0};


// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

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

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

  int cnt = 0;

  std::queue< std::pair<int, int> > que;

  std::cin >> H >> W;
  std::vector< std::vector<int> > grid(H, std::vector<int>(W, -1));
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      char c;
      std::cin >> c;
      if (c == '#') {
	grid[y][x] = 0;
	que.push({y, x});
	cnt++;
      }
    }
  }

  int chk = 0;
  while (cnt < H * W) {

    int N = que.size();
    for (int i = 0; i < N; i++) {
      std::pair<int, int> p = que.front(); que.pop();
      int y = p.first;
      int x = p.second;
      for (int d = 0; d < 4; d++) {
	int ny = y + dy[d];
	int nx = x + dx[d];
	if (ny >= 0 && nx >= 0 && ny < H && nx < W && grid[ny][nx] < 0) {
	  grid[ny][nx] = chk + 1;
	  que.push({ny, nx});
	  cnt++;
	}
      }
    }

    //for (int y = 0; y < H; y++) {
    //  print(grid[y]);
    //}
    //print(cnt);

    chk++;
  }

  print(chk);
  return 0;
}


Measured memory_bytes: 12432
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  string a,b;
  cin >> a >> b;

  REP(i,(int)b.size()){
    cout << a[i] << b[i];
  }
  if(a.size()>b.size()) cout << a.back();
  return 0;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    V, E = 0, 0
    # 辺を自由に張れるとして、頂点数の総当たりを求める
    for i in range(1, N + 1):
        V += i * (N - i + 1)

    # 辺が張られるL,Rの組み合わせ
    # 条件より:
    # 1≦L≦U:U通り, V≦R≦N:N-V+1通り
    for _ in range(N - 1):
        a, b = map(int, input().split())
        # L <= R の順序にする
        if a > b:
            a, b, = b, a
        E += a * (N - b + 1)

    # 1つの辺が有効となる場合、連結成分が1つ減る
    # 頂点数の総当たり数から有向になった辺の頂点を差し引く
    print(V - E)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9168