akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int sen[10000][10];
int sen_tmp[10000][10];

void turn_r(int p, int r, int c);
int get_ok(int r, int c);

int main(void)
{
	int c, r;
	int n;
	int i, j;
	int max;
	int ok;
		
	while (1){
		scanf("%d %d", &r, &c);
		if (r == 0 && c == 0){
			break;
		}
	
		for (i = 0; i < r; i++){
			for (j = 0; j < c; j++){
				scanf("%d", &sen[j][i]);
			}
		}
	
		
		n = 1;
		for (i = 0; i < r; i++){
			n *= 2;
		}
		
		n--;
		
		max = 0;
		for (i = 0; i <= n; i++){
			turn_r(i, r, c);
			ok = get_ok(r, c);
			if (max < ok){
				max = ok;
			}
		}
	
		printf("%d\n", max);
	}
	
	return (0);
}

void turn_r(int p, int r, int c)
{
	int i, j;
	
	for (i = 0; i < r; i++){
		if (((p >> i) & 1) == 0){
			for (j = 0; j < c; j++){
				sen_tmp[j][i] = sen[j][i];
			}
		}
		else {
			for (j = 0; j < c; j++){
				if (sen[j][i] == 0){
					sen_tmp[j][i] = 1;
				}
				else {
					sen_tmp[j][i] = 0;
				}
			}
		}
	}
}

int get_ok(int r, int c)
{
	int ok;
	int num0;
	int num1;
	int i, j;
	
	ok = 0;
	
	for (i = 0; i < c; i++){
		num0 = num1 = 0;
		for (j = 0; j < r; j++){
			if (sen_tmp[i][j] == 0){
				num0++;
			}
			else {
				num1++;
			}
		}
			if (num0 > num1){
				ok += num0;
			}
			else {
				ok += num1;
			}
	}
	
	return (ok);
}

Measured memory_bytes: 1380
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int c,e;
	cin>>c>>e;
	if(abs(c-e)%2==0)
	{
		cout<<abs(c-e)/2+min(c,e);
	} 
	else
	{
		cout<<"IMPOSSIBLE";
	}
	return 0;	
}

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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
vector<T> Vec(int n, T v)
{
    return vector<T>(n, v);
}
template <class... Args>
auto Vec(int n, Args... args)
{
    auto val = Vec(args...);
    return vector<decltype(val)>(n, move(val));
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    vector<vector<int>> d(A, vector<int>(B, 0));
    for (int i = 0; i < A; i++) {
        for (int j = 0; j < B; j++) {
            cin >> d[i][j];
        }
    }
    constexpr int MAX = 100;
    vector<vector<int>> c(MAX + 1, vector<int>(MAX + 1, -1));
    int M = 0;
    constexpr int N = MAX + 1;
    for (int a = 0; a <= MAX; a++) {
        for (int b = 0; b <= MAX; b++) {
            for (int x = 1; x <= A; x++) {
                for (int y = 1; y <= B; y++) {
                    c[a][b] = max(c[a][b], d[x - 1][y - 1] - x * a - y * b);
                }
            }
            if (c[a][b] >= 0) {
                M++;
            }
        }
    }

    for (int a = 1; a <= A; a++) {
        for (int b = 1; b <= B; b++) {
            int mini = INF<int>;
            for (int i = 0; i <= MAX; i++) {
                for (int j = 0; j <= MAX; j++) {
                    mini = min(mini, a * i + b * j + c[i][j]);
                }
            }
            if (mini != d[a - 1][b - 1]) {
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }


    constexpr int S = 1;
    constexpr int T = 2 * MAX + 2;
    cout << "Possible" << endl;
    cout << T << " " << M + 2 * MAX << endl;
    for (int i = 0; i < MAX; i++) {
        cout << i + 1 << " " << i + 2 << " "
             << "X" << endl;
        cout << N + i + 1 << " " << N + i + 2 << " "
             << "Y" << endl;
    }
    for (int i = 0; i <= MAX; i++) {
        for (int j = 0; j <= MAX; j++) {
            if (c[i][j] >= 0) {
                cout << i + 1 << " " << 2 * MAX + 2 - j << " " << c[i][j] << endl;
            }
        }
    }
    cout << S << " " << T << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    cin >> a >> b;
    
    if((a*b) % 2 == 0){
        cout << "Even" << endl;
    }
    
    else{
        cout << "Odd" << endl;
    }
    
}


Measured memory_bytes: 3612
N = int(input())

if N == 1:
    print("Yes")
    exit()

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

last = -1
can_make_down = True

for h in H:
    if h > last:
        can_make_down = True
    elif h == last:
        pass
    elif h == last - 1:
        if can_make_down:
            can_make_down = False
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
        
    last = h

print("Yes")


Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int ans=0;
const int INF = 1<<29;
void dfs(int step,int n,int k,int sum){
	if(step>=n){
		ans=min(ans,sum);
		return ;
	}
	dfs(step+1,n,k,sum+k);
	dfs(step+1,n,k,sum*2);
}
int main(){
	int n,k;
	while(cin>>n>>k)
	{
		ans=INF;
		dfs(0,n,k,1);
		cout<<ans<<endl;
	}
}

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

using namespace std;
typedef long long ll;

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

  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.rbegin(), a.rend());

  ll ans = a[0];
  int cur = 1;
  int cnt = 0;
  for (int i = 2; i < n; ++i) {
    if (cnt == 2) {
      cur++;
      cnt = 0;
    }
    cnt++;
    ans += a[cur];
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 4848
n = int(input())
s = input()
stack_num = 0
ind = 0
ret = ""
nr = 0
for c in s:
    if(c == "("):
        stack_num += 1
    else:
        stack_num -= 1
    if(stack_num < 0):
        ret += "("
        stack_num += 1
if(stack_num < 0):
    ret += "(" * (-stack_num)
ret += s
if(stack_num >= 0):
    ret += ")" * stack_num
print(ret)

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

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i,s.size()) {
    if (s.at(i) != t.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long LL;

const int nmax = 200007; const LL inf = 2e18; const int mod = 1000000007;

int N,cnt[nmax],t[nmax];
vector<int>G[nmax],T[nmax];
bool v1[nmax],v2[nmax],viz[nmax];

void DFS(int nod,int x){
 t[nod] = x;
 viz[nod] = true;

   for(auto it: G[nod])
      if(!viz[it])
         DFS(it,x);
}

int p[nmax],u[nmax];

void DFS2(int nod){
   p[++p[0]] = nod;
   viz[nod] = true;
   ++u[t[nod]];
      for(auto it: T[nod])
         if(!viz[it])
            DFS2(it);
}

int main(){
//   #ifndef GLOBAL_JUDGE
//      freopen("txt.in","r",stdin);
//      freopen("txt.out","w",stdout);
//   #endif // GLOBAL_JUDGE
   int i,j,x,y,L,R;
   cin >> N >> L >> R;
   for(i = 1; i <= L; ++i){
      cin >> x >> y;
      v1[x] = v1[y] = true;
      G[x].push_back(y);
      G[y].push_back(x);
   }
   for(i = 1; i <= R; ++i){
      cin >> x >> y;
      v2[x] = v2[y] = true;
      T[x].push_back(y);
      T[y].push_back(x);
   }
   for(i = 1; i <= N; cnt[i] = 1,++i);
   int nr = 0;
   for(i = 1; i <= N; ++i)
         if(!viz[i]){
            ++nr;
            DFS(i,nr);
         }
   for(i = 1; i <= N;viz[i]=0,++i);
   for(i = 1; i <= N; ++i)
      if(!viz[i]){
            p[0] = 0;
            DFS2(i);
            for(j = 1; j <= p[0]; ++j)
               cnt[p[j]]+=u[t[p[j]]];
            for(j = 1; j <= p[0]; ++j)
               u[t[p[j]]] = 0;
      }
   for(i = 1; i <= N; ++i)
      cout << cnt[i]-1 <<' ';
   cout << '\n';
   return 0;
}


Measured memory_bytes: 19072
import Control.Monad (forM_)

main = do
    n <- readLn
    if n == 0 then return () else do
        forM_ (solve n) (putStrLn . unwords . map show)
        main

solve :: Int -> [[Int]]
solve n = map extract (divisions n)

type Count = Int

divisions :: Int -> [[(Int,Count)]]
divisions n = spare n n
    where
    spare 1 r = [[(1,r)]]
    spare m r = concatMap spare' [c,c-1..0]
        where
        spare' c = map ((m,c):) (spare (m-1) (r-m*c))
        c = r `div` m

extract :: [(Int,Count)] -> [Int]
extract = concatMap (\(n,c) -> replicate c n)

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
int main(){
  string S;
  cin>>S;
  string T="hi";
  for(int i=0;i<S.size()+1;i++){
    if(S==T){cout<<"Yes"<<endl;return 0;}
    T+="hi"; }
    cout<<"No"<<endl;
  return 0;
}

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

# In[13]:


import sys
from collections import deque
input = sys.stdin.readline


# In[14]:


N, M = map(int, input().split())


# In[2]:


link = [[] for _ in range(N)]
for _ in range(M):
    L, R, D = map(int, input().split())
    link[L-1].append((R-1, D))
    link[R-1].append((L-1, -D))


# In[9]:


def func():
    houmon = [False] * N
    x = [0] * N
    
    for start in range(N):
        if houmon[start]:
            continue
        stack = deque([start])
        while stack:
            n1 = stack.pop()
            houmon[n1] = True
            for n2, d in link[n1]:
                if houmon[n2]:
                    if x[n2] != x[n1] + d:
                        return False
                else:
                    x[n2] = x[n1] + d
                    stack.append(n2)
        
#         if max(x) - min(x) > 10 ** 9:
#             return False
    
    return True


# In[10]:


if func():
    print('Yes')
else:
    print('No')


# In[ ]:






Measured memory_bytes: 75828
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: usize,
        A: [i64; N],
    }

    let mut cnt: HashMap<i64, u64> = HashMap::new();
    let mut ans = 0;

    for (i, &a) in A.iter().enumerate() {
        ans += *cnt.entry(((i + 1) as i64) - a).or_default();
        *cnt.entry(((i + 1) as i64) + a).or_insert(0) += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 18408
import heapq
INF = 1e7
def main():
    H,W=map(int, input().split())
    sx, sy = map(int, input().split())
    dh, dw = map(int, input().split())
    sx -= 1
    sy -= 1
    S = [input() for _ in range(H)]
    def dijkstra(sx, sy):
        D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
        D[sx][sy] = 0
        PQ = [(0, (sx, sy))]
        heapq.heapify(PQ)
        while PQ: # PQに候補がある限り
            _, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu
            for dx in range(-2, 3):
                for dy in range(-2, 3):
                    xx, yy = ux+dx, uy+dy
                    if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
                        is_not_neighbor = int(abs(dx) + abs(dy) != 1)
                        # neighborでなければコストが1増える
                        if abs(dx) + abs(dy) == 1:
                            if D[ux][uy] < D[xx][yy]:
                                D[xx][yy] = D[ux][uy]
                                heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
                        else:
                            if D[ux][uy] + 1 < D[xx][yy]:
                                D[xx][yy] = D[ux][uy] + 1
                                heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
        return D
    D = dijkstra(sx, sy)
    if D[dh-1][dw-1] >= INF:
        print(-1)
    else:
        print(D[dh-1][dw-1])
main()

Measured memory_bytes: 124884
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    ll a;string s;cin>>a>>s;
    if(a>=3200)cout<<s;
    else cout<<"red";
    cout<<"\n";
}


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

int main() {
  int n;
  cin >> n;
  set<int> s;
  int a=0;
  for(int i=0;i<n;i++){
    cin >> a;
    s.insert(a);
  }
  if(s.size()==n) cout << "YES";
  else cout << "NO"; 
}


Measured memory_bytes: 9600
#include <cstdio>
#include <map>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

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

map <int, int> M;

int main()
{
  int n;
  scanf("%d", &n);
  REP(i, n) {
    int x;
    scanf("%d", &x);
    M[x]++;
  }

  int m;
  scanf("%d", &m);
  REP(i, m) {
    int x;
    scanf("%d", &x);
    M[x]--;
    if (M[x] < 0) {
      printf("NO\n");
      return 0;
    }
  }

  printf("YES\n");

  return 0;
}


Measured memory_bytes: 9728
import sys
import numpy as np
from numba import njit

MOD = 2019

@njit('(i4[::1],)', cache=True)
def f(S):
    dp = np.zeros(MOD, np.int64)
    temp = np.empty_like(dp)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % MOD
        temp[x:] = dp[:-x]
        temp[:x] = dp[-x:]
        dp, temp = temp, dp
        answer += dp[0]
        pow10 *= 10
        pow10 %= MOD
    return answer


S = np.int32(list(input().rstrip()))
print(f(S))


Measured memory_bytes: 109268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    ll sum = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        sum += (itr->second)*(itr->second-1)/2;
    }
    for(int i = 0; i < n; i++){
        cout << sum - ((mp[a[i]])*(mp[a[i]]-1)/2 - (mp[a[i]]-1)*(mp[a[i]]-2)/2) << endl;
    }


    return 0;

}


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

int L,M,N,tmp,ans;

int main(){
	while(true){
		cin >> L;
		if(!L)
			return 0;
		tmp = 0;
		ans = 0;
		for(int i=0; i<12; i++){
			cin >> M >> N;
			tmp += M-N;
			if(tmp >= L && !ans)
				ans = i+1; 
		}
		if(ans)
			cout << ans << endl;
		else
			cout << "NA\n";
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
using namespace std;
int nrcif(int n)
{
 int cnt=0;
 while(n)
 {
  cnt++;
  n/=10;
 }
 return cnt;
}
int put(int k)
{
 int cnt=1;
 while(k)
 {
  cnt*=10;
  k--;
 }
 return cnt;
}
int main()
{
    int a,b,x,nrnou,y;
    cin>>a>>b;
    x=put(nrcif(b));
    nrnou=a*x+b;
    y=(int)sqrt(nrnou);
    if(y*y==nrnou)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

using Pair = pair<int, int>; // いた人数、出席番号

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

  int A;
  vector<Pair> ps;
  for(int i = 1; i <=N; ++i) {
    cin >> A;
    ps.push_back(Pair(A, i));
  }
  sort(ps.begin(), ps.end());
  for(int i = 0; i < ps.size(); ++i) {
    auto p = ps[i];
    if(i == ps.size() - 1) {
      cout << p.second << endl;;
    }
    else {
      cout << p.second << " ";
    }
  }

  return 0;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n; ll totW, v[105], w[105], mx, memo[102][(int)1e5+2];
ll solve(int i, ll curr){
    if(curr > totW) return -1*v[i-1];
    if(i == n) return 0;
    if(memo[i][curr] != -1) return memo[i][curr];
    mx = max(solve(i + 1, curr), //leave
        solve(i + 1, curr + w[i]) + v[i] //take
    );
    return  memo[i][curr] = mx;
}
int main()
{
    cin>> n>> totW;
    for(int i = 0; i < n; i++){
        cin>> w[i] >> v[i];
    }
    memset(memo, -1, sizeof memo);
    cout<< solve(0, 0);
    return 0;
}


Measured memory_bytes: 79872
h, w = gets.strip.split.map(&:to_i)

aa = Array.new(h) { [0]*w }
dist = Array.new(h) { [-1]*w }
q = []

counter=0
h.times do |i|
  gets.chomp.each_char.with_index do |c,j|
    next if c == '.'
    aa[i][j] = 1
    q << [i, j]
    dist[i][j]=0
    counter+=1
  end
end

result = 0
until counter == h*w
  cy, cx = q.shift

  nc = dist[cy][cx]+1

  x=cx
  if (y = cy+1) < h && dist[y][x] == -1
    counter+=1
    result = nc if nc > result
    dist[y][x]=nc
    q.push([y, x])
  end

  if (y = cy-1) >= 0 && dist[y][x] == -1
    counter+=1
    result = nc if nc > result
    dist[y][x] = nc
    q.push([y, x])
  end

  y=cy
  if (x = cx-1) >= 0 && dist[y][x] == -1
    counter+=1
    result = nc if nc > result
    dist[y][x] = nc
    q.push([y, x])
  end

  if (x = cx+1) < w && dist[y][x] == -1
    counter+=1
    result = nc if nc > result
    dist[y][x] = nc
    q.push([y, x])
  end
end

p result


Measured memory_bytes: 91644
//
//  main.cpp
//  code league
//
//  Created by TAlimul BAri SHresTho on 7/18/20.
//  Copyright © 2020 SHresTho. All rights reserved.
//

#include <iostream>

#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<iomanip>
#define ll                      long long
#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(min(a,b),min(c,d))
#define max4(a,b,c,d)           max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)         max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)         min(min3(a,b,c),min(d,e))
#define LCM(a,b)                (a/__gcd(a,b))*b
#define GCD(a,b)                __gcd(a,b)
#define INPUT(x)                freopen(x,"r",stdin)
#define OUTPUT(x)               freopen (x,"w",stdout)
#define PI                      acos(-1.0)
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define joldi               ios_base::sync_with_stdio(0);cin.tie(NULL);

 
using namespace std;
int main(){
    joldi
    int t;
    cin>>t;
    int n=3*t;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        
    }
    sort(a,a+n);
    ll k=0;
    
    for(int j=n-2;j>=t;j=j-2)
    {
        k=k+a[j];
    }
    cout<<k<<endl;
    
    
}


Measured memory_bytes: 4776
def gcd(x,y):
    if x<y:
        x,y=y,x
    #x>y
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)

N=int(input())
A=[int(i) for i in input().split()]
X=[0 for i in range(N)]
Y=[0 for i in range(N)]
for i in range(1,N):
    X[i]=gcd(X[i-1],A[i-1])
for i in range(N-1)[::-1]:
    Y[i]=gcd(Y[i+1],A[i+1])
Z=[gcd(X[i],Y[i]) for i in range(N)]
print(max(Z))


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

/*
部屋1からの距離を求めれば良い
bfsでいける
多分存在しないことはない
*/

int	main(void)
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> edge(n);
	int a, b;
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	vector<bool> is_visit(n, false);
	vector<int> ans(n, -1);
	queue<int> q;
	q.push(0);
	is_visit[0] = true;
	while (q.size())
	{
		int size = q.size();
		for (int i = 0; i < size; i++)
		{
			int room = q.front(); q.pop();
			for (int j = 0; j < edge[room].size(); j++)
			{
				if (is_visit[edge[room][j]]) continue;
				ans[edge[room][j]] = room + 1;
				is_visit[edge[room][j]] = true;
				q.push(edge[room][j]);
			}
		}
	}
	cout << "Yes" << endl;
	for (int i = 1; i < n; i++) cout << ans[i] << endl;
	return (0);
}


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

const int MAX_N = 20002;
int N;

int P[MAX_N];

ll A[MAX_N];
ll B[MAX_N];
ll C[MAX_N];

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

    cin >> N;

    for (int i = 0; i < N; ++i) {
        cin >> P[i];
        P[i]--;

        C[P[i]] = i+1;
    }

    A[0] = C[0];
    B[0] = 0;

    for (int i = 1; i < N; ++i) {
        A[i] = A[i-1] + C[i];
        B[i] = -A[i-1]; 
    }

    for (int i = 0; i < N; ++i) {
        B[i] += (-B[N-1] + 1);
    }

    //for (int i = 0; i < N; ++i) {
    //    A[i] = 20000 * i + 1;
    //    B[i] = 20000 * (N - 1 - i) + 1;
    //}

    //for (int i = 0; i < N; ++i) {
    //    B[P[i]] += i;
    //}

    //for (int i = 0; i < N; ++i) {
    //    cout << B[i];
    //    if (i != N-1) {
    //        cout << " ";
    //    }
    //}
    //cout << endl;



    for (int i = 0; i < N; ++i) {
        cout << A[i];
        if (i != N-1) {
            cout << " ";
        }
    }
    cout << endl;

    for (int i = 0; i < N; ++i) {
        cout << B[i];
        if (i != N-1) {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
 
#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
 
const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };
 
 
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(??´????????`)(??´????????`)(??´????????`)(??´????????`)(??´????????`)(??´????????`)///
ll mypow(ll a, ll n) {
    if (n == 0)return 1;
    if (n % 2 == 0)return mypow(a, n / 2)*mypow(a, n / 2) % MOD;
    return (a*mypow(a, n / 2) % MOD)*mypow(a, n / 2) % MOD;
}
struct UnionFind {
    vector<int> par;
    vector<int> ran;
 
    UnionFind(int n) {
        par.resize(n);
        ran.resize(n);
        REP(i, n) {
            par[i] = i;
            ran[i] = 0;
        }
    }
 
    int root(int a) {
        return par[a] == a ? a : par[a] = root(par[a]);
    }
 
    bool same(int x, int y) {
        return root(x) == root(y);
    }
 
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)return;
        if (ran[x] < ran[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if (ran[x] == ran[y]) ran[x]++;
        }
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n)break;
        UnionFind u(n);
     
        REP(i, m) {
            int a, b;
            cin >> a >> b;
            a--; b--;
 
            u.unite(a, b);
        }
        vi cnt(n, 0);
        REP(i, n) {
            cnt[u.root(i)]++;
        }
        int c = 0;
        REP(i, n) {
            if (cnt[i] > 0)c++;
        }
        ll res = mypow(2, c);
        if (m != 0)res++;
        cout << res%MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
ll n,k;
ll dp[100011];
ll a[101];
ll mn=1e12;

ll getans(ll stone)
{
if(dp[stone]!=-1)
{
	return dp[stone];
}
ll ans=0;
for(ll i=0;i<n;i++)
{
	if(stone>=a[i])
	{
		if(getans(stone-a[i])==0)
		{
			ans=1;
			break;
		}
		else
		{
			
		}
	}
}
return dp[stone]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
cin>>n>>k;
memset(dp,-1,sizeof(dp));
for(ll i=0;i<n;i++)
{
	cin>>a[i];
}
if(getans(k)==1)
{
	cout<<"First"<<endl;
}
else
{
	cout<<"Second"<<endl;
}
}



 


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

int N;
int A[210];

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

    int res = 0;
    while (true){
        bool exist_odd = false;
        for (int i=0;i <N; ++i){
            if (A[i] % 2 != 0) exist_odd = true;
        }

        if (exist_odd) break;

        for (int i = 0; i <N; ++i){
            A[i] /= 2;
        }
        ++res;
    }
    cout << res <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	int N, K;
	cin >> N >> K;
	int res = 0;
	for(int a = 1; a <= N; ++a) {
		int rev = (K - a % K) % K;
		if (rev != a % K) {
			continue;
		}
		int t = N / K;
		if (rev != 0 && N - N / K * K >= rev) {
			t++;
		}
		// cout << a << " " << rev << " " << t << " " << t * t << endl;
		res += t * t;
	}
	cout << res << endl;

	return 0;
}


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

const int maxn=51,INF=1e9;
int n,x[maxn],y[maxn],used[maxn];

int solve(int p,int q){
	memset(used,0,sizeof(used));
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			if (x[i]+p==x[j] && y[i]+q==y[j])
				used[j]=1;
	return n-accumulate(used,used+n,0);
}

int main(){
	cin>>n;
	for (int i=0;i<n;i++) cin>>x[i]>>y[i];
	int ans=INF;
	if (n==1) ans=1;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++){
			if (i==j) continue;
			ans=min(ans,solve(x[j]-x[i],y[j]-y[i]));
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])

ans = ''.join(t)
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)

Measured memory_bytes: 109528
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  cout << dup(n,2) << endl;
  return 0;
}

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

void StrSort(char *str[ ], int n)
{
    int i, j;
    char *temp;           
	
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if ((strcmp(str[j], str[i])) < 0) {
                temp = str[i];               
                str[i] = str[j];             
                str[j] = temp;               
            }
        }
    }
}

int main(void){
  int n,l;
  char *s[110];
  char st[110][110];
  scanf("%d %d",&n,&l);
  int i;
  //printf("test\n");
  for(i=0;i<n;i++){
    scanf("%s",st[i]);
  }
  for(i=0;i<n;i++){
    s[i] = st[i];
  }
  //printf("test1\n");
  StrSort(s, n);	
  //printf("test2\n");
  for (i=0;i<n;i++){
    printf("%s", s[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;

namespace EDPC
{
    class A
    {
        static void Main(string[] args)
        {
            // input
            long N = long.Parse(Console.ReadLine());
            long[] h = Console.ReadLine().Split().Select(long.Parse).ToArray();

            //DP table
            long[] DP = new long[N].Select(x => x = int.MaxValue).ToArray();

            // Main
            DP[0] = 0;
            DP[1] = Math.Abs(h[1] - h[0]);
            for (long i = 2; i < N; i++)
            {
                for (long j = 1; j <= 2; j++)
                {
                    DP[i] = Math.Min(DP[i], DP[i - j] + Math.Abs(h[i] - h[i - j]));
                }
            }
            Console.WriteLine(DP[N - 1]);
        }
    }
}


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

using namespace std;
int main(void)
{
  int n;
  cin >> n;
  
  vector<string> s;
  long long num_head[5];
  for(int i=0; i<5; i++)
    num_head[i]=0LL;

  for(int i=0; i<n; i++){
    string tmp;
    cin >> tmp;
    s.push_back(tmp);
    //cout << s[i] << " " << s[i][0] << endl;
    switch(s[i][0])
    {
      case 'M':
        num_head[0]++; break;
      case 'A':
        num_head[1]++; break;
      case 'R':
        num_head[2]++; break;
      case 'C':
        num_head[3]++; break;
      case 'H':
        num_head[4]++; break;
    }
  }
  
  //for(int i=0; i<n; i++)
  //  cout << num_head[i] << endl;
 
  long long count = 0;   
  //mar
  if(num_head[0] && num_head[1] && num_head[2])
    count += num_head[0] * num_head[1] * num_head[2];
  //mac
  if(num_head[0] && num_head[1] && num_head[3])
    count += num_head[0] * num_head[1] * num_head[3];
  //mah
  if(num_head[0] && num_head[1] && num_head[4])
    count += num_head[0] * num_head[1] * num_head[4];
  //mrc
  if(num_head[0] && num_head[2] && num_head[3])
    count += num_head[0] * num_head[2] * num_head[3];
  //mrh
  if(num_head[0] && num_head[2] && num_head[4])
    count += num_head[0] * num_head[2] * num_head[4];
  //mch
  if(num_head[0] && num_head[3] && num_head[4])
    count += num_head[0] * num_head[3] * num_head[4];
  //arc
  if(num_head[1] && num_head[2] && num_head[3])
    count += num_head[1] * num_head[2] * num_head[3];
  //arh
  if(num_head[1] && num_head[2] && num_head[4])
    count += num_head[1] * num_head[2] * num_head[4];
  //ach
  if(num_head[1] && num_head[3] && num_head[4])
    count += num_head[1] * num_head[3] * num_head[4];
  //rch
  if(num_head[2] && num_head[3] && num_head[4])
    count += num_head[2] * num_head[3] * num_head[4];

  cout << count << endl;
  return 0;
}
    


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

using namespace std;

double dist(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

struct State {
    double d;
    int l, r;

    State () {}
    State (double d, int l, int r) : d{d}, l{l}, r{r} {}

    bool operator < (const State &s) const {
        return d > s.d - (1e-9);
    }
};

double dijkstra(const vector<double>& X, const vector<double>& Y)
{
    int N = X.size();
    map<int, map<int, double>> d;
    d[0][N - 1] = 0;

    priority_queue<State> pq;
    pq.push(State(0, 0, N - 1));

    while (!pq.empty()) {
        State s = pq.top(); pq.pop();
        int l = s.l, r = s.r;
        
        if (l > r) continue;
        if (d[l][r] < s.d) continue;
        if (l == r) return d[l][r];

        for (int i : {-1, +0, +1}) {
            int nl = l + i;
            for (int j : {-1, +0, +1}) {
                int nr = r + j;
                if (nl < 0 || nl >= N ||
                    nr < 0 || nr >= N) continue;

                if (Y[nl] != Y[nr]) continue;
                
                double ld = dist(X[l], Y[l], X[nl], Y[nl]);
                double rd = dist(X[r], Y[r], X[nr], Y[nr]);
                double nd = s.d + ld + rd;
                
                if (d[nl].count(nr) == 0 || nd < d[nl][nr]) {
                    d[nl][nr] = nd;
                    pq.push(State(nd, nl, nr));
                }               
            }
        }       
    }
    return -1;
}

int main()
{
    int N;
    while (1) {
        cin >> N;
        if (N == 0) break;
        vector<double> x(N), y(N);
        set<double> ys;
        for (int i = 0; i < N; i++) {
            cin >> x[i] >> y[i];
            ys.insert(y[i]);
        }

        set<pair<double, double>> v;
        for (int i = 0; i < N - 1; i++) {
            int sign = +1;
            double sy = y[i], ty = y[i + 1];
            
            if (sy > ty) {
                sign = -1;
                swap(sy, ty);
            }
            
            for (auto& cy : ys) {                
                double dx = x[i + 1] - x[i], dy = ty - sy;
                double s = (dy != 0 ? dx * sign / dy : 1);
                if (sy <= cy && cy <= ty) {
                    v.insert(make_pair(x[i] + s * (cy - y[i]), cy));
                }
            }
        }

        v.insert(make_pair(x[N - 1], y[N - 1]));
        
        vector<double> X, Y;
        for (auto& p : v) {
            X.emplace_back(p.first);
            Y.emplace_back(p.second);
        }
            
        printf("%.10f\n", dijkstra(X, Y));
    }        
    return 0;
}

Measured memory_bytes: 5324
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define PB push_back
#define ll long long
using  namespace std;
template <class T>
inline void read(T &x)
{
   x=0; char c=getchar(); int f=1;
   while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
   while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
vector<int> G[N];
int ans[N],sub[N],p[N],son[N],head[N],sz[N],ecnt,n;
int fa[N],mx[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
struct ed{int to,next;}e[N<<1];
void ad(int x,int y)
{
	e[++ecnt]=(ed){y,head[x]}; head[x]=ecnt;
	e[++ecnt]=(ed){x,head[y]}; head[y]=ecnt;
}
void dfs1(int u,int last)
{
	p[u]=last,mx[u]=max(mx[last],last);
	//if(mx[u]) G[mx[u]].PB(u);
	for(int k=head[u];k;k=e[k].next)
	{
		int v=e[k].to; if(v==last) continue;
		dfs1(v,u);
	}
}
void dfs2(int u)
{
	if(u!=1) ans[u]+=ans[mx[u]]-sub[son[mx[u]]];
	for(int k=head[u];k;k=e[k].next)
	{
		int v=e[k].to; if(v==p[u]) continue;
		son[u]=v,dfs2(v);
	}
}
void un(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(sz[fx]>sz[fy]) swap(fx,fy);
	fa[fx]=fy,sz[fy]+=sz[fx];
}
int main()
{
	int x,y; read(n);
	for(int i=1;i<n;i++) read(x),read(y),ad(x,y);
	dfs1(1,0);
	for(int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
	for(int i=2;i<=n;i++) G[mx[i]].PB(i);
	for(int i=1;i<=n;i++)
	{
		int tot=G[i].size();
		for(int j=0;j<tot;j++)
		{
			int u=G[i][j]; ans[u]=1;
			if(u<i) ans[u]+=sz[find(u)]-1;
			else
			{
				for(int k=head[u];k;k=e[k].next)
				{
					int v=e[k].to;
					if(v<i)
					{
						if(v!=p[u]) sub[v]=sz[find(v)];
						ans[u]+=sz[find(v)];
					}
				}
			}
		}
		for(int k=head[i];k;k=e[k].next)
		{
			int v=e[k].to;
			if(v<i) un(v,i);
		}
	}
	dfs2(1);
	for(int i=2;i<=n;i++) printf("%d ",ans[i]); puts("");
	return 0;
}

Measured memory_bytes: 22772
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
const lli N = 1e7 + 10;
lli cnt[N];
void pre() {
	for (lli i = 1; i * i < N; i++) {
		for (lli j = i * i; j < N; j += i) {
			if (i * i == j) {
				cnt[j]++;
			} else {
				cnt[j] += 2;
			}
		}
	}
}
void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
void solve() {
	lli n;
	cin >> n;
	lli ret = 0;
	for (lli i = 1; i <= n; i++) {
		ret += cnt[i] * i;
	}
	cout << ret << endl;
}
int main()
{

	zanj0();
	pre();
	solve();
	return 0;
}

Measured memory_bytes: 81740
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
from collections import Counter

# def f2(s):
#     n = len(s)
#     c = 0
#     ans = 0
#     for i in range(n-1):
#         if s[i] == s[i+1]:
#             c += 1
#             if i == n-2:
#                 ans += (c+1) // 2
#         else:
#             ans += (c+1) // 2
#             c = 0
#     return ans

def f(s):
    n = len(s)
    i = 0
    ans = 0
    while i < n-1:
        c = 0
        while i < n-1 and s[i] == s[i+1]:
            c += 1
            i += 1
        ans += (c+1) // 2
        i += 1
    return ans

def main():
    s = input().strip()
    k = int(input().strip())
    n = len(s)
    if len(Counter(s)) == 1:
        print(n * k // 2)
        return
    ini = f(s)
    dif = f(s*2) - ini
    print(ini + dif * (k-1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
N, M = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(N)]
points = [list(map(int, input().split())) for _ in range(M)]
for i in range(N):
    c = -1
    min_dis = 10**9
    for j in range(M):
        k = abs(students[i][0]-points[j][0]) + abs(students[i][1]-points[j][1])
        if k < min_dis:
            min_dis = k
            c = j+1
    print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define N 1000000
int A[N],B[N];
int ans=0;

double mid(int n,int S[])
{
	if (n&1)
		return S[(n>>1)+1];
	else
		return (S[n>>1]+S[(n>>1)+1])/2.0;
}

void solve()
{
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)
		cin>>A[i]>>B[i];
	sort(A+1,A+n+1);
	sort(B+1,B+n+1);
	if (n&1)
		cout<<(ll)(mid(n,B)-mid(n,A)+1);
	else
		cout<<(ll)(2*(mid(n,B)-mid(n,A))+1);
}



int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	int t;
//	cin>>t;
//	while (t--) 
	solve();
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int v[30] = {};
    for(auto c: s){
        v[c-'a']++;
        if(v[c-'a'] > 1){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        char[,] table = new char[N, N];
        for (int i = 0; i < N; i++)
        {
            var line = ReadLine();
            for (int j = 0; j < N; j++)
            {
                table[i, j] = line[j];
            }
        }
        int count = 0;
        for (int B = 0; B < N; B++)
        {
            if (isGoodTable(table, N, 0, B)) count++;
        }
        WriteLine(count*N);
    }
    static bool isGoodTable(char[,] table, int N, int offsetX, int offsetY)
    {
        char[,] tmp = new char[N, N];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                var tmpI = (i + offsetX) % N;
                var tmpJ = (j + offsetY) % N;
                tmp[i, j] = table[tmpI, tmpJ];
                if (j<i)
                {
                    if (tmp[i, j] != tmp[j, i]) return false;
                }
            }
        }
        return true;
    }
}

Measured memory_bytes: 29952
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

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

	vector<bool> change(S.size());
	int n_change = 0;
	for(int i=0; i<S.size()-1; i++){
		if(S[i]==S[i+1]){
			change[i+1] = true;
			n_change++;
			i++;
		}
	}
	if(K==1 || S[0]!=S[S.size()-1] || change[S.size()-1]){
		cout << n_change*K << endl;
		return 0;
	}
	string T = S+S;
	vector<bool> changeT(T.size());
	int n_changeT = 0;
	for(int i=0; i<T.size()-1; i++){
		if(T[i]==T[i+1]){
			changeT[i+1] = true;
			n_changeT++;
			i++;
		}
	}
	if(changeT[T.size()-1]){
		if(K%2==0){
			cout << n_changeT*K/2 << endl;
		} else {
			cout << n_changeT*(K/2)+n_change << endl;
		}
	} else {
		cout << (n_changeT-n_change)*(K-1) + n_change << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

vector<int>cnt,ans;
vector<vector<int>>g;

void dfs(int v,int p,int scr){
    cnt[v]+=scr;
    for(int x:g[v]){
        if(x==p)continue;
        dfs(x,v,cnt[v]);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    g.resize(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].pb(b);g[b].pb(a);
    }
    cnt.resize(n,0);
    rep(i,q){
        int a,b;
        cin>>a>>b;
        a--;
        cnt[a]+=b;
    }
    //愚直にやるとO(NQ)となり間に合わないため累積和みたいなことをする
    dfs(0,0,0);
    rep(i,n){
        if(i)cout<<" ";
        cout<<cnt[i];
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 23424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int aPrice = sc.nextInt();
        int bPrice = sc.nextInt();
        int abPrice = sc.nextInt();
        int aNeed = sc.nextInt();
        int bNeed = sc.nextInt();
        
        int minPrice = Math.min((aPrice + bPrice), abPrice * 2);
        long total = Math.min(aNeed, bNeed) * minPrice;

        if (aNeed <= bNeed) {
            int remainNeed = bNeed - aNeed;
            total += remainNeed * Math.min(bPrice, abPrice * 2);
        } else {
            int remainNeed = aNeed - bNeed;
            total += remainNeed * Math.min(aPrice, abPrice * 2);
        }

        System.out.print(total);
    }
}


Measured memory_bytes: 21844
let fold_int f a n =
  let rec fold f a i n =
    if i >= n then
      a
    else
      fold f (f a i) (i + 1) n
  in
    fold f a 0 n

(* O(n^3) (n = max {a, b, c}) *)
let solve a b c x =
  fold_int
    (fun sofar_a i ->
      fold_int
        (fun sofar_b j ->
          fold_int
            (fun sofar_c k ->
              if 500 * i + 100 * j + 50 * k = x then
                sofar_c + 1
              else
                sofar_c)
            sofar_b
            (c + 1))
        sofar_a
        (b + 1))
    0
    (a + 1)

let _ =
  let a = read_int () in
  let b = read_int () in
  let c = read_int () in
  let x = read_int () in
  solve a b c x |> string_of_int |> print_endline

Measured memory_bytes: 512