akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define INTMAX  99999999

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int N;
string s,t;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N;
	cin >> s;
	cin >> t;
	int common_len = 0;
	int ans = 0;
	for(common_len=N; common_len>0; common_len--) {
		int si=N-common_len;
		int ti=0;
		for(; ti<common_len;si++,ti++ ) {
			if(s[si]!=t[ti]) {
				break;
			}
		}
		if(ti==common_len) {
			ans = 2*N-common_len;
			break;
		}
	}
	cout << 2*N-common_len << endl;

	return 0;
}



Measured memory_bytes: 256
import numpy as np

k, n = map(int,input().split())
a = np.array(list(map(int, input().split())))
diff = a[1:] - a[:-1]
diff = np.append(diff, k - a[-1] + a[0])
if np.argmax(diff) == len(a) - 1:
    print(a[-1] - a[0])
else:
    print(k - a[np.argmax(diff) + 1] + a[np.argmax(diff)])

Measured memory_bytes: 34160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scan_init()
	n := scanInt()
	inf := 100000007
	x := make([]int,n)
	psum := inf
	// p := 0
	for i:= 0; i<n; i++ {
		x[i] = scanInt()
	}
	for i:= 1; i<=100; i++ {
		// 制約が甘いので
		sum := 0
		for j:=0; j<n; j++ {
			sum += (x[j]-i)*(x[j]-i)
		}
		if psum > sum {
			psum = sum
			// p = i
		}
	}
	fmt.Println(psum)
}
var sc = bufio.NewScanner(os.Stdin)
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
//func scan () string{
//  sc.Scan()
//	return sc.Text()
//}


Measured memory_bytes: 1780
n, k = map(int, input().split())
p = list(map(int, input().split()))

def ev(n):
    return n * (n + 1) / (2 * n)

q = [0]
for i in range(n):
    q.append(ev(p[i]))
    q[i + 1] = q[i] + ev(p[i])
#print(q)

tmp = 0
for j in range(n - k + 1):
    if tmp <= q[j + k] - q[j]:
        tmp = q[j + k] - q[j]
print(tmp)


Measured memory_bytes: 32136
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		label:
		for (int i = s.length - 1; i > 0; i--) {
			if (i % 2 == 0) {
				int i2 = i / 2;
				for (int j = 0; j < i2; j++) {
					if (s[j] != s[j + i2]) {
						continue label;
					}
				}
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 21716
#include<stdio.h>

int main(){
  int N;
  scanf("%d", &N);

  double X[N];
  char s[5];
  double sum = 0;

  int i;
  
  for(i = 0; i < N; i++){
    scanf("%lf %s", &X[i], s);
    if(s[0] == 74) sum += X[i];
    else if(s[0] == 66) sum += X[i] * 380000.0;
  }

  printf("%lf\n", sum);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  double n,m,x,y;
  cin >> n >> m >> x >> y;
  if(n/2==x&&m/2==y) printf("%.10f %d\n",n*m/2,1);
  else printf("%.10f %d\n",n*m/2,0);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<stdio.h>
#define min(p,q)((p)<(q)?(p):(q))

int a[200010];
int main(){
	int n,t;
	scanf("%d%d",&n,&t);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	int ans=0;
	for(int i=0;i<n-1;i++)ans+=min(a[i+1]-a[i],t);
	printf("%d",ans+t);
}


Measured memory_bytes: 896
#include <cstdio>

long long dp[1000][1000];

int main()
{
  int h, w;
  char s[1000][1001];
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i)
  {
    scanf("%s", s[i]);
  }
  dp[0][0] = 1;
  for (int i = 1; i < w; ++i)
  {
    dp[0][i] = s[0][i] == '.' ? dp[0][i - 1] : 0;
  }
  for (int i = 1; i < h; ++i)
  {
    dp[i][0] = s[i][0] == '.' ? dp[i - 1][0] : 0;
    for (int j = 1; j < w; ++j)
    {
      dp[i][j] = s[i][j] == '.' ? (dp[i - 1][j] + dp[i][j - 1]) % 1000000007 : 0;
    }
  }
  printf("%lld\n", dp[h - 1][w - 1]);
  return 0;
}

Measured memory_bytes: 8960
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, q;
    cin >> n >> q;
    ll ans = (n - 2) * (n - 2);
    set<pll> hor, ver;
    hor.emplace(n - 2, n - 2);
    ver.emplace(n - 2, n - 2);
    while(q--) {
        int t, x;
        cin >> t >> x;
        --x;
        if(t == 1) {
            auto i = hor.lower_bound(pll(x, 0ll));
            ans -= i->second;
            ver.emplace(i->second, x - 1);
        }
        else {
            auto i = ver.lower_bound(pll(x, 0ll));
            ans -= i->second;
            hor.emplace(i->second, x - 1);
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

int T,m,n,f1[2005][2005],f2[2005][2005],f3[2005][2005];
char a[2005][2005];

int main()
{
    //freopen("TEST.INP","r",stdin);
    cin>>m>>n>>T;
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            if(a[i][j]=='1')
            {
                if(i>1&&a[i-1][j]=='1')
                    f2[i][j]++;
                if(j>1&&a[i][j-1]=='1')
                    f3[i][j]++;
            }
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
        {
            f1[i][j]=f1[i-1][j]+f1[i][j-1]-f1[i-1][j-1]+(a[i][j]=='1');
            f2[i][j]+=f2[i-1][j]+f2[i][j-1]-f2[i-1][j-1];
            f3[i][j]+=f3[i-1][j]+f3[i][j-1]-f3[i-1][j-1];
        }
    int u1,v1,u2,v2;
    while(T--)
    {
        cin>>u2>>v2>>u1>>v1;
        int s1=f1[u1][v1]-f1[u1][v2-1]-f1[u2-1][v1]+f1[u2-1][v2-1];
        int s2=f2[u1][v1]-f2[u1][v2-1]-f2[u2][v1]+f2[u2][v2-1];
        int s3=f3[u1][v1]-f3[u1][v2]-f3[u2-1][v1]+f3[u2-1][v2];
        cout<<s1-s2-s3<<"\n";
    }
}


Measured memory_bytes: 52864
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.14159265358979
#define coutdb cout<<fixed<<setprecision(50)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

#define int long long

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

int invmod(int a, int p){ // a^-1 mod p
	int b = p, u = 1, v = 0;
	while(b){
		int t = a / b;
		a -= t*b; swap(a, b);
		u -= t*v; swap(u, v);
	}
	u %= p;
	if(u < 0) u += p;
	return u;
}

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

  int N, A[100000], B[100000];
  cin >> N;
  REP(i, N) cin >> A[i];
  REP(i, N-1) B[i] = A[i+1] - A[i];
  int invsum[100010] = {};
  for(int i = 1; i <= N; i++){
  	invsum[i] = invmod(i, MOD);
  	invsum[i] += invsum[i-1];
  	invsum[i] %= MOD;
  }
  int ans = 0;
  REP(i, N-1){
  	int pls = B[i] * invsum[i+1] % MOD;
  	ans += pls; ans %= MOD;
  }
  for(int i = 1; i < N; i++){
  	ans *= i; ans %= MOD;
  }
  cout << ans << endl;
}

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

#define vi vector<int>
#define vii vector<vector<int> >
#define vi_(n) vector<int>((n))
#define vii_(n,m) vector<vector<int> >((n), vector<int>((m)))
#define vi_def(n, def) vector<int>((n), (def))
#define vii_def(n, m, def) vector<vector<int> >((n), vector<int>((m), (def)))

#define rep(i, n) for(int i=0; i < (n); ++i)
#define per(i, n) for(int i=(n)-1 i >= 0; --i)

int main(){
	int N;
	cin >> N;
	vi p(N);
	rep(i, N){
		int P;
		cin >> P;
		p[i] = P;
	}

	int cnt = 0;
	rep(i, N){
		if(p[i] != i+1){
			++cnt;
		}
	}

	cout << (cnt >= 3 ? "NO" : "YES") << endl;

}


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

int main() {
    int N, L; cin >> N >> L;
    int ans = 0;
    if(L<0 && L+N-1<0){
        for(int i=0; i<N-1; i++){
            ans += L + i;
        }
    }
    else if(L > 0){
        for(int i=1; i<N; i++){
            ans += L + i; 
        }
    }
    else{
        for(int i=0; i<N; i++){
            ans += L + i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))

ans = 100 * 100 * N
for p in np.arange(np.min(X), np.max(X) + 1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    if s < ans:
        ans = s

print(ans)

Measured memory_bytes: 27224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main()
{
  string str;
  cin >> str;
  
  int sum = 0;
  while(1){
    if(str.empty()) break;
    
    char c = str[0];
    int n = c - '0';
    sum = (sum + n) % 9;
    str.erase(0,1);  
  }
  
  string ans;
  if(sum%9 == 0) ans = "Yes";
  else ans = "No";
  
  cout << ans << endl;
  
  return 0;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N;
    cin >> N;
    vector<pair<pair<unsigned long, unsigned long>, unsigned long>> tapi(1048576, {{1, 0}, 0});
    unsigned long ans{0}, t{500000004}, a{0}, z{0}, A;
    while(cin >> A)if(a ^= A){
        (tapi[a].first.second += (tapi[a].first.first += tapi[a].first.second * (z - tapi[a].second)) %= MOD) %= MOD;
        ans += tapi[a].first.first;
        tapi[a].second = z;
    }else ++z, (t *= 2) %= MOD;
    cout << (a ? tapi[a].first.first : (ans + t) % MOD) << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n = 0;
	cin >> n;
	int x = 0, y = 0, z = 0, ans = 0;
	auto ans_list = vector<int>(n + 1, 0);



	for (int i = 1; i <= 100; i++)
	{
		for (int j = 1; j <= 100; j++)
		{
			for (int k = 1; k <= 100; k++)
			{
				ans = i * i + j * j + k * k + i * j + j * k + i * k;
				if (ans <= n)
				{
					ans_list[ans] += 1;
				}
			}
		}
	}


	for (int i = 1; i <= n; i++)
	{
		cout << ans_list[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;

int main(){
      int N;
      cin >> N;
      string W[N+10];
      cin >> W[0];
      for(int j=1; j<N; j++){
        cin >> W[j];
        if(W[j-1][W[j-1].size()-1]!=W[j][0]){
          cout << "No" << endl;
          return 0;
        }
      }for(int a=0; a<N-1; a++){
        for(int b=a+1; b<N; b++){
          if(W[a]==W[b]){
            cout << "No" << endl;
            return 0;
          }
        }
      }
      cout << "Yes" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)


def 関数(s,t):
    tlen = len(t)
    fois = 0

    for i in range(tlen):
        if s[i] != t[i]:
            fois += 1

    return fois

def çözmek():
    S = sys.stdin.readline().rstrip()
    T = sys.stdin.readline().rstrip()

    res = []
    res.append(関数(S, T))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()


Measured memory_bytes: 9388
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define LL long long
#define N 100010

LL a,b,ans;

int main() {
    scanf("%lld%lld",&a,&b);
    if(b == 1) {
        puts("0");
        return 0;
    }
    LL cnt = 1;
    while(true) {
        cnt = cnt + a - 1;
        ans++;
        if(cnt >= b) break;
    }
    printf("%lld",ans);
    //system("pause");
    return 0;
}

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

int main() {
  int H, W, A, B, N;
  int y=0;
  long int x=0;
  string S;
  cin >> A;
  vector<int> vec(N);

  for (int i=1; i<10; i++) {
    for (int j=1; j<10; j++) {
      if (A ==i*j) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;    
}


Measured memory_bytes: 256
n = int(input())
s = [int(input()) for i in range(n)]
s.sort()
score = sum(s)
score2 = score
c=0
for i in range(n):
    if score2%10 == 0:
        score2 = score - s[i]
        c+=1
    else:
        break
if c==n:
    score2=0
print(score2)

Measured memory_bytes: 3064
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
ans=sum(b)
for i in range(n-1):
    if a[i+1]==a[i]+1:
        ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
        int n;
        cin >> n;
        int mx = -1, sm = 0;
        for (int i = 0; i < n; i++) {
                int a;
                cin >> a;
                sm += a;
                mx = max(a, mx);
        }
        sm -= mx;
        sm += mx / 2;
        cout << sm;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG
#define M 1000000007

/*
 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} */

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/


int main() {
  ll N, K, ans;
  cin >> N >> K;

  ans = 0;

  for (ll i = K; i<=N+1; i++){
    ll min, max;
    min = i*(i+1)/2;
    max = i*((N+1) + (N+1-i + 1))/2;
    ans += (max - min +1) % M ;
    ans %= M;
  }
   
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<30)
 
struct segtree{
  vector<int> datasum;
  vector<int> delay;
   
  int n;
   
  void init(int _n){
    n = 1;
    while( n < _n ) n *= 2;
    datasum.resize( 2 * n );
    delay.resize( 2 * n );
  }
 
  void delaycalc(int k){
    datasum[k] = datasum[k] + delay[k];
    if( k + 1 < n ){
      for(int i=1;i<=2;i++){
        delay[2 * k + i] = delay[ 2 * k + i] + delay[k];
      }
    }
    delay[k] = 0;
  }
 
  void add(int a,int b,int x,int k,int l,int r){
    delaycalc(k);
    if( r <= a || b <= l ) return;
    else if( a<= l && r <= b ) {
      delay[k] = x;
      delaycalc(k);
    } else {
      add( a, b, x, 2*k + 1, l, (l+r)/2 );
      add( a, b, x, 2*k + 2, (l+r)/2, r );
      datasum[k] = min(datasum[ 2 * k + 1] , datasum[ 2 * k + 2]);
    }
  }
 
  int query(int a,int b,int k,int l,int r){
    delaycalc(k);
    if( r <= a || b <= l ) return INF;
    if( a <= l && r <= b ) {
      return datasum[k] + delay[k];
    } else {
      int vl = query( a, b, 2*k+1, l, (l+r)/2 );
      int vr = query( a, b, 2*k+2, (l+r)/2, r );
      return min( vl , vr );
    }
  }
 
  void add( int a,int b,int x) {//[a,b) add x
    add( a, b, x, 0,0, n );
  }
  int query(int a,int b){//[a,b) 's sum
    return query(a,b,0,0,n);
  }
};
 
segtree T;
int N,Q;
char str[300005];
set< int > U;
 
int main(){
  scanf("%d %d",&N,&Q);
  scanf("%s",str);
  T.init(N+2);
 
 
  for(int i=0;i<N;i++){
    if(str[i]=='('){
      T.add(i,N,1);
    }else{
      T.add(i,N,-1);
      U.insert(i);
    }
  }
 
 
  set<int> :: iterator it;
  int p,a;
  while(Q--){
 
 
    scanf("%d",&p);
    p--;
    if(str[p]=='('){
      U.insert(p);
      str[p]=')';
      T.add(p,N,-2);
 
      it=U.begin();
      a= *it;
      printf("%d\n",a+1);
      U.erase(it);
      str[a]='(';
      T.add(a,N,2);
    }else if(str[p]==')'){
      it=U.find(p);
      U.erase(it);
      str[p]='(';
      T.add(p,N,2);
 
 
 
       
      int l=0,r=N-1,m,k;
      while(l<r){
        m=(l+r)/2;
        k=T.query(m,N);
         
        if(k<2){
          l=m+1;
        }else{
          r=m;
        }
      }
      printf("%d\n",l+1);
      str[l]=')';
      T.add(l,N,-2);
      U.insert(l);
    }
 
 
 
 
  }
  return 0;
}

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

int main() {
  int N;cin>>N;
  string C;
  for(int i=0;i<N;i++){
    char Cn;cin>>Cn;
    C.push_back(Cn);
  }
  int X=0;//XはC中のRの数
  for(int i=0;i<N;i++){
    if(C.at(i)=='R') X++;
  }
  int S=0;//取り替えるとかかる回数
  for(int i=0;i<X;i++){
    if(C.at(i)=='R') S++;
  }
  cout<<X-S<<endl;
}

Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstLine = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = firstLine[0];
            var B = firstLine[1];
            var sum = A + B;
            var minus = A - B;
            var multi = A * B;
            Console.WriteLine(Math.Max(Math.Max(sum,minus),multi));
        }
    }
}

Measured memory_bytes: 13268
module Main where

import Control.Applicative
import Control.Monad
import Data.List

f :: Int -> Int -> Int
f h w = minimum $ fmap f [1 .. w - 1]
  where
    (h1, h2) = let (q, r) = h `divMod` 2 in (q, q + r)
    r1 i = i * h
    r2 i = (w - i) * h1
    r3 i = (w - i) * h2
    rs i = [r1 i, r2 i, r3 i]
    f i = maximum (rs i) - minimum (rs i)

main :: IO ()
main = do
    [h, w] <- fmap read . words <$> getLine :: IO [Int]

    if any ((== 0) . (`mod` 3)) [h, w]
        then print 0
        else print $ minimum [h, w, f h w, f w h]

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s; 
  cin >> s;
  int a=300000, z=0;
  
  for(int i=0; i<s.size(); i++){
  	if(s[i] == 'A') a = min(i,a);
    if(s[i] == 'Z') z = max(i,z);
  }
  
  cout << z - a + 1 << endl;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <string.h>
#include <cstring>
#include <queue>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	int N, K;
	cin >> N >> K;
	N--;
	K--;
 
	for (int i = 0; i <= N; ++i) {
		int A;
		cin >> A;
	}
 
	if (N%K == 0) 
	{
		cout << N / K;
	}
	else
	{
		cout << N / K + 1;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;
int ans;
string s1,s2;

int main()
{
	int i,j,l1,l2,f=0;
	cin>>s1>>s2;
	if(s1==s2)
	{
		printf("0\n");
		return 0;
	}
	l1=s1.size(),l2=s2.size();
	ans=l2;
	for(i=0;i<l1-l2+1;i++)
	{
		int sum=0;
		string ts=s1.substr(i,l2);
		if(ts==s2)
		{
			printf("0\n");
			return 0;
		}
		for(j=0;j<l2;j++)
		{
			if(sum>=ans) break;
			if(ts[j]!=s2[j]) sum++;
		}
		if(sum) ans=min(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3724
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
def divisor(n):
    d = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            d.append(i)
            if i != n//i:
                d.append(n//i)
    #d.sort()
    return d

d = divisor(n)
ans = 0
for num in d:
    if num>1 and n%(num-1)==n//(num-1):
        ans+=num-1
print(ans)


Measured memory_bytes: 9752
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,m;
vector<string> nm;
int p[1000]; map<string,int> id;

bool ck(int a,int b)
{
	for(;a>=0;a=p[a])if(a==b)return 1;
	return 0;
}
int main()
{
	while(cin>>n>>m,n)
	{
		nm.clear(); id.clear();
		cin.ignore(); string str;
		
		int sp=0,psp=0,pa=-1;
		rep(i,n)
		{
			getline(cin,str);
			for(sp=0;str[sp]==' ';sp++);
			nm.pb(str.substr(sp));
			id[nm[i]]=i;
			
			if(psp>sp)
			{
				rep(j,psp-sp)pa=p[pa];
				p[i]=pa;
			}
			else if(psp==sp)p[i]=pa;
			else if(psp<sp)p[i]=i-1,pa=i,sp++;
			psp=sp;
		}
		
		rep(i,m)
		{
			getline(cin,str);
			stringstream ss(str);
			string n1,n2,t; ss>>n1>>str>>str>>t>>str>>n2;
			n2.erase(n2.end()-1);
			
			int a=id[n1],b=id[n2];
			bool ans=0;
			if(t=="child")ans=p[a]==b;
			else if(t=="parent")ans=p[b]==a;
			else if(t=="sibling")ans=p[a]==p[b];
			else if(t=="ancestor")ans=ck(b,a);
			else ans=ck(a,b);
			
			cout<<(ans?"True":"False")<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22)
    {
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }
}

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

int main() {
  int N, T, S1, S2;
  cin >> N;
  int W[N + 1], S[N];

  for (int i = 1; i <= N; i++) {
    cin >> W[i];
  }

  for (int T = 1; T < N; T++) {
    S1 = 0;
    S2 = 0;
    for (int j = 1; j <= T; j++) S1 += W[j];
    for (int k = T + 1; k <= N; k++) S2 += W[k];
    S[T] = abs(S1 - S2);
  }

  sort(S + 1, S + N);

  cout << S[1] << endl;
  return 0;
}

Measured memory_bytes: 256
let () =
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in
    let lcm a b = a / gcd a b * b in
    let main () =
        let a, b = Scanf.scanf "%d %d" (fun a b -> a, b) in
        Printf.printf "%d\n" (lcm a b)
    in
    main ()

Measured memory_bytes: 4480
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int n;
int a[MAXN];
int b[MAXN];

int c[MAXN];
int d[MAXN];

bool test(int bit) {
	int l=1<<bit,h=2<<bit;
	REP(i,n) c[i]=a[i]%h,d[i]=b[i]%h;
	sort(c,c+n); sort(d,d+n);
	ll cnt=0;
	{ int at=n; REP(i,n) { while(at>0&&c[i]+d[at-1]>=l) --at; cnt-=at; } } ll cnt1=cnt;
	{ int at=n; REP(i,n) { while(at>0&&c[i]+d[at-1]>=h) --at; cnt+=at; } } ll cnt2=cnt-cnt1;
	{ int at=n; REP(i,n) { while(at>0&&c[i]+d[at-1]>=l+h) --at; cnt+=n-at; } } ll cnt3=cnt-cnt2-cnt1;
	if(cnt==0) return false;
	//printf("l=%d h=%d\n",l,h);
	//printf("c:"); REP(i,n) printf(" %d",c[i]); puts("");
	//printf("d:"); REP(i,n) printf(" %d",d[i]); puts("");
	//printf("->%lld (%lld,%lld,%lld)\n",cnt,cnt1,cnt2,cnt3);
	return cnt%2==1;
}

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]); REP(i,n) scanf("%d",&b[i]);
	int ans=0; REP(i,29) if(test(i)) ans^=1<<i; printf("%d\n",ans);
}

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


Measured memory_bytes: 3328
def solve():
    S = input()
    len_s = len(S)
    ans = 0
    i = 0
    last = [""]
    while i < len_s:
        for j in range(i + 1, len_s + 1):
            if last[-1] != S[i:j]:
                last.append(S[i:j])
                ans += 1
                break
        i = j
    print(ans)
solve()


Measured memory_bytes: 8008
#include<stdio.h>
#define MAX 25000
int parent(int k){return k/2;}
int lefttree(int k){return 2*k;}
int righttree(int k){return 2*k+1;}

int main()
{
  int i,size,A[MAX+1];
  
  scanf("%d",&size);
  for(i=1;i<=size;i++)scanf("%d",&A[i]);

  for(i=1;i<=size;i++)
    {
      printf("node %d: key = %d, ",i,A[i]);
      if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
      if(lefttree(i)<=size)printf("left key = %d, ",A[lefttree(i)]);
      if(righttree(i)<=size)printf("right key = %d, ",A[righttree(i)]);
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

// (a/b)%P の場合は，(a%P)*modinv(b)%P とする
ll modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

ll kai(int a){
    ll res=1;
    for(ll i=1;i<=a;i++){
        res*=i;
        res%=MOD;
    }
    return res;
}

int main() {
    int x,y;
    cin>>x>>y;
    if(x>y)swap(x,y);
    if(x*2==y){
        fin(1);
        return 0;
    }
    ll a=0,b=0;
    while(1){
        if(x-2<0){
            fin(0);
            return 0;
        }
        x-=2;
        y--;
        a++;
        if(2*x==y){
            break;
        }
    }
    
    b+=x;
    fin(kai(a+b)%MOD*modinv(kai(a)*kai(b))%MOD);
    // cout<<a<<" "<<b<<endl;
}


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

int main() {

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }

  bool f = true;
  for (int i = 0; i < N; i++){
    if (A.at(i) % 2 == 0){
      if(A.at(i) % 3 != 0 && A.at(i) % 5 != 0){
        f = false;
      }
    }
  }

  if(f == false) cout << "DENIED" << endl;
  else cout << "APPROVED" << endl;

}

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;


void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	vector<vector<int>> happ(n + 1, vector<int> (4));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 3; j++)
			cin >> happ[i][j];
	}
	
	vector<vector<int>> dp(n + 1, vector<int>(4, 0));
	dp[1][1] = happ[1][1];
	dp[1][2] = happ[1][2];
	dp[1][3] = happ[1][3];
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= 3; j++) {
			for (int f = 1; f <= 3; f++) {
				if (j != f)
					dp[i][j] = max(dp[i][j], dp[i-1][f] + happ[i][j]);
			}
		}
	}
	
	cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
}

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




Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

int bit[1<<19+1], n = 1<<19;

int sum(int i){
	int s = 0;
	for( ;i>0;i&=i-1) s += bit[i];
	return s;
}

void add(int i, int x){
	for( ;i<=n;i+=i&-i)	bit[i] += x;
}

int getXth(int x, int end){
	int L = 1, R = end;
	while(R-L>1){
		int mid = (L+R)/2;
		int cur = mid - sum(mid);
		if(cur < x) L = mid;
		else if(x < cur) R = mid;
		else{
			if(mid == 1 || mid-1-sum(mid-1) != cur) return mid;
			R = mid;
		}
	}
	return L;
}

int main(){
	int q, lim;
	int id[400000];
	while(cin >> q >> lim, q){
		int end = 1, size = 0;
		map< int, int > mp;
		memset(bit, 0, sizeof(bit));
		for(int Q=0;Q<q;Q++){
			int query, x; scanf("%d %d", &query, &x);
			if(query == 0){
				id[end] = x;
				mp[x] = end;
				end++; size++;
			}
			if(query == 1){
				int idx = getXth(x, end);
				add(idx, 1);
				size--;
			}
			if(query == 2){
				int idx = getXth(x, end);
				printf("%d\n", id[idx]);
			}
			if(query == 3){
				int idx = mp[x];
				add(idx, 1);
				size--;
			}
			while(size > lim){
				int idx = getXth(1, end);
				add(idx, 1);
				size--;
			}
		}
		printf("end\n");
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, y;
  cin >> n >> y;
  
  if(y < 1000*n or 10000*n < y) {
    cout << "-1 -1 -1" << "\n";
    return 0;
  }
  
  rep(i, 0, y/10000 +1) {
    rep(j, 0, (y-10000*i)/5000 +1) {
      if(10000*i +5000*j +1000*(n-i-j) == y) {
        cout << i << " " << j << " " << n-i-j << "\n";
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << "\n";
}

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> Tree;

#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define For(i,n) for(int i=0;i<(n);++i)
#define Forr(i,n) for(int i=n-1;i>=0;i--)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define sz(a) (int)a.size()
#define Fill(a,b) memset(a,b,sizeof(a));
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
const int INF=1e9;
#define vvi vector<vi>



void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int &x:a)cin>>x;
    ll ans=0LL;
    for(int i=1;i<n;i++){
        if(a[i-1]<=a[i])continue;
        else ans+=abs(a[i-1]-a[i]),a[i]=a[i-1];
        //cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;    
}



int main()
{
    fin;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

using namespace std;

// unsigned int e[101];
// unsigned int d[101];
char e[101][2];
char d[101][2];

unsigned int cnt = 0;

void insertsort(unsigned int *d, unsigned int n, unsigned int g)
{
	for (unsigned int i = g; i < n; ++i) {
		unsigned int v = d[i];
		int j = i - g;
		while (j >= 0 && d[j] > v) {
			d[j+g] = d[j];
			j -= g;
			++cnt;
		}
		d[j+g] = v;
	}
}

void shellsort(unsigned int* d, unsigned int n)
{
	unsigned int m[101];
	unsigned int j = 1;
	unsigned int i;
	for (i = 0; i < n; ++i) {
		m[i] = j;
		j = j * 3 + 1;
		if (j >= n)
			break;
	}
	unsigned int mmax = i + 1;
	cout << mmax << "\n";
	cnt = 0;
	for (int i = mmax - 1; i > 0; --i) {
		cout << m[i] << " ";
		insertsort(d, n, m[i]);
	}
	cout << "1\n";
	insertsort(d, n, m[0]);
}

int main()
{
	unsigned int n;
	vector<unsigned int> s;
	cin >> n;
	s.resize(n);
	for (unsigned int i = 0; i < n; ++i) {
		cin >> s[i];
	}

	shellsort(&(s[0]), n);
	cout << cnt << "\n";
	for (unsigned int i = 0; i < n - 1; ++i) {
		cout << s[i] << "\n";
	}
	cout << s[n-1] << endl;

	return 0;
}



Measured memory_bytes: 6764
import Control.Monad
import Data.Char
import Data.Function
import Data.List
import qualified Data.ByteString.Char8 as BS

main ::IO()
main = do
  n <- readLn
  nss <- replicateM n getIntList
  let [ns, ms] = transpose $ sortBy (flip compare `on` sum) nss
  print $ solve ns ms
  where
    solve [] [] = 0
    solve (n:ns) (m:ms) = n - solve ms ns

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

Measured memory_bytes: 42876
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

x = int(input())
div = make_divisors(x)

if x == 1: print("0 -1")

for i in range(len(div)//2):
    u = div[i*2]
    if len(div)%2 == 1: v = div[i*2]
    else: v = div[i*2+1]
    t = int(v**(1/2))
    for j in range(t):
        a = j
        b = j-u
        if a**4 + (a**3)*b +(a**2)*(b**2) + a*(b**3) + b**4 == v:
            print(a, b)
            break

Measured memory_bytes: 9364
import math
from functools import reduce

def gcd(*nums):
  return reduce(math.gcd, nums)


input_num = int(input()) + 1
result = 0
for a in range(1, input_num):
  for b in range(1, input_num):
    for c in range(1, input_num):
        result += gcd(a, b, c)

print(result)


Measured memory_bytes: 69500
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int[] planes = {a, b, c};
        Arrays.sort(planes);
        
        System.out.println(planes[0] + planes[1]);
    }
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void llchmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  ll ans = a*c;
  llchmax(ans, a*d);
  llchmax(ans, b*c);
  llchmax(ans, b*d);
  
  cout << ans << endl;
  
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> h(n);

  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  sort(h.begin(), h.end());
  int tmp = 1e9;
  for (int i = 0; i < n + 1 - k; i++) {
    int big = h.at(i + k - 1);
    int sm = h.at(i);
    tmp = min(tmp, abs(big - sm));
  }
  cout << tmp;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll

int h, w;
int a[500][501];
int cnt;
vector<int> ans[4];
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            cin >> a[i][j];
            a[i][j] = a[i][j] % 2;
        }
    }
    for (int i=0;i<h;i++) {
        for (int j=0;j<w-1;j++) {
            if (a[i][j]) {
                a[i][j]--; a[i][j+1] ^= 1;
                ans[0].push_back(i+1);
                ans[1].push_back(j+1);
                ans[2].push_back(i+1);
                ans[3].push_back(j+2);
                cnt++;
            }
        }
    }
    for (int i=0;i<h-1;i++) {
        if (a[i][w-1]) {
            a[i][w-1]--; a[i+1][w-1] ^= 1;
            ans[0].push_back(i+1);
            ans[1].push_back(w);
            ans[2].push_back(i+2);
            ans[3].push_back(w);
            cnt++;
        }
    }

    cout << cnt << endl;
    for (int i=0;i<ans[0].size();i++) {
        for (int j=0;j<4;j++) {
            cout << ans[j][i];
            if (j != 3) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 8148
N = gets.to_i
a_list = gets.split.map(&:to_i)
minus_count = a_list.count { |a| a < 0 }
abs_a_list = a_list.map(&:abs)
ans = if minus_count.even?
  abs_a_list.reduce(&:+)
else
  min, *rest = abs_a_list.sort
  -min + rest.reduce(0, &:+)
end
puts ans


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, q, d[200000];
string s, t;

bool g(int p) {
	inc(i, q) {
		if(t[i] == s[p]) { p += d[i]; }
		if(p == -1) { return true; }
		if(p == n) { break; }
	}
	return false;
}

int f() {
	int L = -1, H = n;
	while(H - L > 1) {
		int M = (L + H) / 2;
		(g(M) ? L : H) = M;
	}
	return H;
}

int main() {
	cin >> n >> q >> s;
	inc(i, q) {
		string T, D;
		cin >> T >> D;
		t += T;
		d[i] = (D == "L" ? -1 : +1);
	}
	
	int ans = n;
	ans -= f();
	reverse(ALL(s));
	inc(i, q) { d[i] *= -1; }
	ans -= f();
	
	cout << ans << endl;
	
	return 0;
}


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


int gcd (int a,int b, int c){
    int m = min(min(a,b),c);
    for(int i = m;i > 0;i--){
        if(a%i == 0 && b%i == 0 && c%i == 0) return i;
    }
}

int main(){
    int k;
    cin >> k;
    int sum = 0; 
    rep(a,k){
        rep(b,k){
            rep(c,k){
                sum += gcd(a,b,c);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, const vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

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

  string s; cin >> s;
  int n = s.size();

  REPE(i,n){
    FORE(j,i,n){
      string t;
      t += s.substr(0,i);
      t += s.substr(j);
      dump(t);

      if(t == "keyence"){
	cout << "YES" << endl;
	return 0;
      }
    }
  }
  cout << "NO" << endl;
 
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int A;
    int B;

    //printf("今何時？？\n");
    scanf("%d", &A);

    //printf("コンテスト何時間後？\n");
    scanf("%d", &B);

    if(A + B >= 24){
        printf("%d\n", A + B - 24);
    }else{
        printf("%d\n", A + B);
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  string stones = "";
  cin >> stones;
  vector<int> white(n+1), black(n+1);
  for (int i=1; i<n+1; i++) {
    if (stones.at(i-1) == '#') {
      black.at(i) = black.at(i-1) + 1;
    } else {
      black.at(i) = black.at(i-1);
    }
  }
  for (int i=n-1; i>=0; i--) {
    if (stones.at(i) == '.') {
      white.at(i) = white.at(i+1) + 1;
    } else {
      white.at(i) = white.at(i+1);
    }
  }
  int ans = n + 1;
  for (int i=0; i<n+1; i++) {
    ans = min(ans, black.at(i) + white.at(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2180
A, B = map(int, input().split())
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

# 高速素因数分解
def factorize(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr
n = gcd(A, B)
ans = factorize(n)
if ans[0][0] == 1:
    print(1)
else:
    print(len(ans)+1)

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

int main() {
  string a , b;
  cin >> a >> b;
  
  if (a == "H" && b == "H" ){
    cout << "H" << endl;
  }
    else if ( a == "H" && b == "D" ){
      cout << "D" << endl;
    }
   else if ( a == "D" && b == "H" ){
      cout << "D" << endl;
    }
 else if ( a == "D" && b == "D" ){
      cout << "H" << endl;
    }
}


Measured memory_bytes: 256