akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	vector<ll> a(3*N+2,0);
	FOR(i,1,3*N+1)cin>>a[i];

	ll red[N*2+1];
	red[0]=0;
	priority_queue<ll, vector<ll>, greater<ll>> rq;
	FOR(i,1,N+1){
		red[i] = red[i-1] + a[i];
		rq.push(a[i]);
	}
	FOR(i,N+1,N*2+1){
		red[i] = red[i-1]+a[i];
		rq.push(a[i]);
		red[i] -= rq.top();
		rq.pop();
	}

	ll blue[N*2+1];
	blue[0]=0;
	REV(a);
	priority_queue<ll> bq;
	FOR(i,1,N+1){
		blue[i] = blue[i-1] + a[i];
		bq.push(a[i]);
	}
	FOR(i,N+1,N*2+1){
		blue[i] = blue[i-1]+a[i];
		bq.push(a[i]);
		blue[i] -= bq.top();
		bq.pop();
	}
	ll ans = -INF;
	FOR(i,N,N*2+1){
		ans = max(ans,red[i] - blue[3*N-i]);
	}
	cout << ans << endl;
}	

Measured memory_bytes: 7412
#include <iostream>
using namespace std;
int main() {
    char b;
    cin >> b;
    char base[4] = {'A', 'C', 'T', 'G'};
    for (int i=0; i<4; i++) {
        if (b == base[i]) {
            cout << base[(i+2)%4] << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
signed main(){
    int h,w,k;cin >> h >> w >> k;
    int sx,sy,gx,gy;cin >> sx >> sy >>gx >> gy;
    sx--;sy--;gx--;gy--;
    vector<string> f(h);
    rep(i,h)cin >> f[i];
    vector<vector<int>> dist(h,vector<int> (w,-1));
    queue<P> q;
    q.emplace(sx,sy);
    dist[sx][sy] = 0;
    while(q.size()){
        auto now = q.front();q.pop();
        int x = now.first,y = now.second;
        rep(i,4){
            for(int d = 1;d <= k;d++){
                int nx = x + dx[i]*d,ny = y+ dy[i]*d;
                if(nx < 0 || ny < 0 || nx > h-1 || ny > w-1)break;
                if(dist[nx][ny] != -1 && dist[nx][ny] < dist[x][y] + 1)break;
                if(dist[nx][ny] == dist[x][y] + 1)continue;
                if(f[nx][ny] == '@')break;
                dist[nx][ny] = dist[x][y] + 1;
                q.emplace(nx,ny);
            }
        }
    }
    cout << dist[gx][gy] << endl;

    return 0;
}

Measured memory_bytes: 20040
#include<stdio.h>
#include<string.h>
int main()
{
  char n[102];
  scanf("%s", n);
  int k;
  scanf("%d", &k);
  int m = strlen(n);
  int ans;
  int i;
  int a, b;
  if (k == 1)
    ans = 9 * (m - 1) + (int)(n[0] - '0');

  else if (k == 2)
  {
    a = -1;
    for(i=1; i<m; i++){
      if(n[i] > '0'){
        a = i;
        break;
      }
    }
	ans = 81 * (m-1) * (m-2) / 2;
	ans += 9 * (m-1) * (n[0]-'1');
	if(a > 0){
      ans += n[a]-'0';
      ans += 9 * (m-a-1);
	}
  }
  else{
    a = b = -1;
	for (i=1; i<m; i++){
      if (n[i] > '0'){
        if (a < 0)
          a = i;
        else if (b < 0)
          b = i;
      }  
    }
    ans = 729 * (m-1) * (m-2) * (m-3) / 6;
    ans += 81 * (m-1) * (m-2) / 2 * (n[0]-'1');
    if(a > 0){
      ans += (n[a]-'1') * 9 * (m-a-1);
      ans += 81 * (m-a-1) * (m-a-2) / 2;
      if(b > 0){
		ans += n[b]-'0';
		ans += 9 * (m-b-1);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> vec(3, "#");
 
  for(int l = 0; l < W + 2; l++){
    cout << "#";
  }
  cout << endl;
  
  for(int k = 0; k < H; k++){
    cin >> vec.at(1);
    for(int j = 0; j < 3; j++){
      cout << vec.at(j) ;
    }
    cout << endl;
  }
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int N, M;


const int MAX_N = 1000;

int par[MAX_N];
int Rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    size = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}



int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    int a[M], b[M];
    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    int ans = 0;
    rep(i, M) {
        init(N);
        rep(j, M) {
            if(i != j) unite(a[j], b[j]);
            //dump(size);
        }
        if (size != 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n,m=[int(i) for i in input().split()]
x=[10**5+1 for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  x[a-1]=min([x[a-1],b-1])


y=0
t=10**5+1
r=0
for i,j in enumerate(x):
  if j !=10**5+1:
    if i >= t or r==0:
      y+=1
      r=1
      t=j
    elif t>j:
      t=j

print(y)

Measured memory_bytes: 7080
h, w, k = map(int, input().split())
s = [[-1 if x == "#" else 0 for x in input()] for _ in range(h)]
cnt = 1

for i in range(h):
    if sum(s[i]) == 0: continue
    flg = False
    for j in range(w):
        if s[i][j] == -1:
            if not flg: flg = True
            else: cnt += 1
        s[i][j] = cnt
    cnt += 1

for i in range(1, h):
    if sum(s[i]) == 0 and sum(s[i-1]) != 0:
        for j in range(w):
            s[i][j] = s[i-1][j]

for i in range(h-1)[::-1]:
    if sum(s[i]) == 0 and sum(s[i+1]) != 0:
        for j in range(w):
            s[i][j] = s[i+1][j]

for i in range(h): print(*s[i])

Measured memory_bytes: 7504
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]string, n)
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		a[tmp-1] = strconv.Itoa(i + 1)
	}
	fmt.Println(strings.Join(a, " "))

}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
	int N, K; cin >> N >> K;
    rep(i, K){
        ll res = modint(comb(K-1, i) * comb(N-K+1, i+1));
        cout << res << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
import java.util.Scanner;

/** dp[n][w]: 重さw以下, 荷物nまでのときの品物の価値の総和の最大値 */
public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = Integer.parseInt(scanner.next());
    int w = Integer.parseInt(scanner.next());
    int[][] wv = new int[n][2];
    int wi, vi;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 2; j++) {
        wv[i][j] = Integer.parseInt(scanner.next());
      }
    }
    long[][] dp = new long[n + 1][w + 1];
    for (int i = 0; i < n + 1; i++) {
      dp[0][i] = 0;
      dp[i][0] = 0;
    }
    for (int i = 1; i < n + 1; i++) {
      wi = wv[i - 1][0];
      vi = wv[i - 1][1];
      for (int j = 1; j < w + 1; j++) {
        if (j - wi >= 0) {
          dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - wi] + vi);
        } else {
          dp[i][j] = dp[i - 1][j];
        }
      }
    }
    System.out.println(dp[n][w]);
  }
}


Measured memory_bytes: 127568
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int A, B;
  cin >> A >> B;
  if(A < 10 && B < 10)
    cout << A * B << endl;
  else
    cout << -1 << endl;
  return 0;
}



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

int main()
{
    int a,b;
    cin>>a>>b;
    bool flag=false;
    for(int i=0;i<=a;i++){
        if(i*2+(a-i)*4==b){
            flag=true;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

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

    int res = 0;
    for (int i = 0; i < 1000; i++) {
        string pin = to_string(i);
        pin = string(3 - pin.length(), '0') + pin;
        int pos = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] == pin[pos]) pos++;
            if (pos == 3) break;
        }
        if (pos == 3) res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [[0]*3 for i in range(N)]

for i in range(N):
  a[i] = [int(i) for i in input().split()] 

def summerVacation(n, i):
  if n ==0:
    dp[n][i] = a[n][i]
    return
  i1 = (i+1) % 3
  i2 = (i+2) % 3  
  dp[n][i] = max( dp[n-1][i1], dp[n-1][i2] ) + a[n][i]  
  
dp =[[None]*3 for _ in range(N)]
for n in range(N):
  for i in range(3):
    summerVacation(n, i)
    
print( max( dp[N-1][0], dp[N-1][1], dp[N-1][2] ))

  

Measured memory_bytes: 44148
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    rep(i,N){
        int a,b,c; cin >> a >> b >> c;
        int ans=0;
        if(a%3==0){
            int m=10-b;
            ans+=20-c+1;
            ans+=m*20;
        } else {
            int m=10-b;
            if(b%2==0){
                ans+=19-c+1;
            }else{
                ans+=20-c+1;
            }
            ans+=m/2*20;
            ans+=(m-m/2)*19;
        }
        int y=1000-a-1;
        ans+=y/3*200;
        if(y%3>0){
            ans+=200;
            ans+=(y-y/3-1)*195;
        } else {
            ans+=(y-y/3)*195;
        }
        cout << ans << endl;
    }
}


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

int main() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
}

Measured memory_bytes: 256
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
ans = 0
for i in range(N):
    for j in range(100):
        if a[i]%2 == 0:
            ans += 1
            a[i] = a[i]//2
        else:
            break
print(ans)

Measured memory_bytes: 6204
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define ll long long
#define MAX 100000

using namespace std;

int n,m,k;
char ma[500][500];
int mark[500];
int ans[500][500];

int main()
{
   // freopen("in.txt","r",stdin);
    cin>>n>>m>>k;
    lp(i,n) {
     int cnt = 0;
     lp(j,m) {
        cin>>ma[i][j];
        if(ma[i][j]=='#') cnt++;

      }
      mark[i]=cnt;
    }

    int ji=0;

    lp(i,n){
      if(mark[i]==0) continue;
      ji++;
      int cnt = 0;
      lp(j,m){

        if(ma[i][j]=='.')
          ans[i][j]=ji;
        else {
          cnt += 1;
          ans[i][j]=ji++;
          if(cnt == mark[i]) ji--;
        }
      }
    }

    lp(i,n){
      lp(j,m){
        if(ans[i][j] == 0) {
          for (int x = i+1; x <= n; x++) {
            if(ans[x][j]!=0) {
               ans[i][j]=ans[x][j];
               break;
            }
          }
        }
      }
    }

    lpd(i,n,1){
      lpd(j,m,1){
        if(ans[i][j] == 0) {
          for (int x = i-1; x >= 1; x--) {
            if(ans[x][j]!=0) {
               ans[i][j]=ans[x][j];
               break;
            }
          }
        }

      }
    }

    lp(i,n){
      lp(j,m){
        cout<<ans[i][j]<<" ";
      }
      cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main(){
	int n, m = 0;
	scanf("%d",&n);
	while(n != 0)
	{
		m *= 10;
		if(n % 10 == 1)
			m += 9;
		else
			m += 1;		
		n /= 10;
	}
	while(m != 0)
	{
		printf("%d", m%10);
		m /= 10;
	}
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int a, flag = 1;
    string b;

    cin>>a>>b;
    if(a%2==0)
    {
        int c= b.length()/2;
        for(int i=0; i<c; i++)
            if(b.at(i)!=b.at(i+c))
            {
                flag = 0;
                break;
            }
        if(flag==1)
            cout<< "Yes"<<endl;
        else
            cout<< "No"<<endl;
    }
    else
        cout<< "No"<<endl;
}


Measured memory_bytes: 3600
n = int(input())
a = list(map(int, input().split()))

if 0 in a:
    print(0)
else:
    ans = 1
    flag = False
    for i in range(n):
        ans = ans * a[i]
        if ans > 10**18:
            flag = True
            break

    if flag:
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 21644
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	priority_queue<pair<int, int> > pq;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		if (b[i] > a[i])
			pq.push(make_pair(b[i], i));
		if (b[i] < a[i])
			return cout << "-1", 0;
	}
	long long ans = 0;
	while (!pq.empty()) {
		int i = pq.top().second;
		pq.pop();
		int reduce = b[(i - 1 + n) % n] + b[(i + 1) % n];
		if ((b[i] - a[i]) % reduce == 0) {
			ans += (b[i] - a[i]) / reduce;
			b[i] = a[i];
			continue;
		}
		if (reduce >= b[i])
			return cout << "-1", 0;
		ans += b[i] / reduce;
		b[i] %= reduce;
		if (b[i] < a[i])
			return cout << "-1", 0;
		pq.push(make_pair(b[i], i));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4980
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
#include <iterator>
#include <complex>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(x, y) memset((x),(y),sizeof(x))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
class Point
{
public:
	int x, y;
};
Point p1[N], p2[N];
int dis(int i, int j)
{
	return abs(p1[i].x - p2[j].x) + abs(p1[i].y - p2[j].y);
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> p1[i].x >> p1[i].y;
	}
	for (int i = 1; i <= m; i++)
	{
		cin >> p2[i].x >> p2[i].y;
	}
	for (int i = 1; i <= n; i++)
	{
		int minv = INF;
		int k = 0;
		for (int j = 1; j <= m; j++)
		{
			int d = dis(i, j);
			if (d < minv) minv = d, k = j;
		}
		cout << k << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def get_ints():
  return map(int, input().split())

N, _, C = get_ints()
B = list(get_ints())

n = 0
for _ in range(N):
  A = list(get_ints())
  J = sum(a * b for a, b in zip(A, B)) + C
  if J > 0:
  	n += 1
    
print(n)


Measured memory_bytes: 2940
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
#define ll long long
#define x first
#define y second
#define pb push_back
#define pii pair<ll,ll>
#define vi vector<ll>
#define MOD 1000000007
#define INF 1000000000
using namespace std;

const int N = 1e5+5;
ll h[N];
ll dp[N];

void solve(){
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++)
		cin >> h[i];
	dp[1] = 0;
	for(int i=2;i<=n;i++){
		dp[i] = INF;
		int r = max(1,i-k);
		for(int j=i-1;j>=r;j--){
			dp[i] = min(dp[i],dp[j]+abs(h[j]-h[i]));
		}
	}
	cout << dp[n] << endl;
}   
    
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
#define INF 0X3f3f3f3f
#define M 1000000007
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back 
#define fi first
#define se second
#define endl "\n"
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

int n;
ll y;

int main(void){
	scanf("%d%lld", &n, &y);

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			ll falta = y - (10000LL*i + 5000LL*j);
			if(falta >= 0 and falta%1000 == 0 and i + j + falta/1000 == n){
				printf("%d %d %lld\n", i, j, falta/1000);
				return 0;
			}
		}
	}

	printf("-1 -1 -1\n");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 60;

using namespace std;

vector<int> Graph[N];
bool vis[N];
int tin[N]={0},low[N]={0};
int timer=0,ans=0;

//Calculate bridges in a given Graph
void dfs (int v, int p)
{
    vis[v]=1;
    tin[v]=low[v]=timer++;
    for (int to: Graph[v])
    {
        if (to==p)
            continue;
        if (vis[to])
            low[v]=min(low[v],tin[to]);
        else
        {
            dfs(to,v);
            low[v]=min(low[v],low[to]);
            if (low[to]>tin[v])
                ans++;
        }
    }
}

main()
{
    fast;
    int n,m,i,j;
    cin>>n>>m;
    int a,b;
    for (i=0;i<m;i++)
    {
        cin>>a>>b;
        Graph[a].pb(b);
        Graph[b].pb(a);
    }
    dfs(1,-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, M; string S;
set<int> E[201010];
int ok[201010], acnt[201010], bcnt[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> S;
    rep(i, 0, M) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].insert(b);
        E[b].insert(a);
    }

    rep(cu, 0, N) ok[cu] = 1;

    queue<int> ng;
    rep(cu, 0, N) {
        fore(to, E[cu]) {
            if (S[to] == 'A') acnt[cu]++;
            else bcnt[cu]++;
        }
        if (acnt[cu] == 0 or bcnt[cu] == 0) {
            ng.push(cu);
            ok[cu] = 0;
        }
    }

    while (!ng.empty()) {
        int cu = ng.front(); ng.pop();

        fore(to, E[cu]) if (ok[to]) {
            if (S[cu] == 'A') acnt[to]--;
            else bcnt[to]--;

            if (acnt[to] == 0 or bcnt[to] == 0) {
                ng.push(to);
                ok[to] = 0;
            }
        }
    }

    rep(cu, 0, N) if (ok[cu]) {
        printf("Yes\n");
        return;
    }
    
    printf("No\n");
}

Measured memory_bytes: 30416
/*
g++ -std=c++11 -o2 -Wall ABC100C.cpp -o ./out/ABC100C.out
./out/ABC100C.out
*/

#include <bits/stdc++.h>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

ll a[10000];

int main(){
//    freopen("./input/input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    /*
    int ans = 0;
    bool flag = true;
    while (flag) {
      int ev = -1;
      for (int i = 0; i < n; ++i) {
        if (a[i] % 2 == 0 && (ev == -1 || a[i] > a[ev])) {
          ev = i;
        }
      }
      if (ev < 0) break;
//      cout << ev << "\n";
      for (int i = 0; i < n; ++i) {
        if (a[i] % 2 == 1) a[i] *= 3LL;
        else if (ev == i) a[i] /= 2LL;
        else  a[i] *= 3LL;
      }

      for (int i = 0; i < n; ++i) {
        cout << a[i];
        if (i == n - 1) cout << "\n";
        else cout << " ";
      }

      ++ans;
    }
    */
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      int aa = a[i];
      while (aa % 2 == 0) {
        aa /= 2;
        ++cnt;
      }
    }
    cout << cnt << "\n";
}


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

using namespace std;

int main(void){
	int n,m;
	while(true){
		string s1, s2;
		cin >> s1;
		if(s1 == ".")break;
		cin >> s2;
		if(s1 == s2){
			cout << "IDENTICAL" << endl;
			continue;
		}
		int close = 0;
		bool quo = false;
		int i = 0, j = 0;
		while(true){
			if(i==s1.size() || j == s2.size()) break;
			if(s1[i]=='"' && s2[j]=='"'){
				quo = !quo;
				i++; j++; continue;
			}
			if(s1[i]==s2[j]){
					i++; j++; continue;
			}
			if(!quo){
				close = -1;
				break;
			}else{
				close++;
				while(s1[i++]!='"'); i--;
				while(s2[j++]!='"'); j--;
			}
		}
		if(!(i==s1.size() && j == s2.size())) close = -1;
		cout << (close == 1 ? "CLOSE" : "DIFFERENT") << endl;
		
	}

	return 0;
}


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

#define all(x) x.begin(),x.end()
#define pb push_back
#define ss second
#define ff first

int main(){
	int n,cnt=0;	cin>>n;
	vector<int>A(n);
	for(int i=0;i<n;i++)	cin>>A[i];
	int maxval = *max_element(all(A));
	int maxval2 = INT_MIN;
	for(int i=0;i<n;i++){
		if(A[i] == maxval)	cnt++;
		if(A[i] != maxval){
			maxval2 = max(maxval2,A[i]);
		}
	}
	
	vector<int> ans(n,maxval);
	if(cnt==1){
		int indx = max_element(all(A))-A.begin();
		ans[indx] = maxval2;
		
	}
	for(int i=0;i<n;i++)	cout<<ans[i]<<endl;
}

Measured memory_bytes: 3200
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    // int N, K;
    // int a,b,c;

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3, y3, x4, y4;
    x3 = - y2 + y1 + x2;
    y3 = y2 + x2 - x1;
    x4 = - y3 + y2 + x3;
    y4 = y3 + x3 - x2;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


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

#define INF (INT64_MAX/2)
typedef pair<long long, int> P;

int main()
{
	int n;
	cin >> n;
	vector<vector<P>> g( n );
	for( int i = 0; i < n; i++ ) {
		int u, k;
		cin >> u >> k;
		g[u].resize( k );
		for( int j = 0; j < k; j++ ) {
			int v, c;
			cin >> v >> c;
			g[u][j] = P( c, v );
		}
	}

	vector<long long> d( n, INF );
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push( P( 0, 0 ) );
	while( !que.empty() ) {
		P p = que.top();
		que.pop();
		int c = p.first;
		int u = p.second;
		for( P e : g[u] ) {
			int cost = e.first;
			int v = e.second;
			if( d[v] <= d[u] + cost ) continue;
			d[v] = d[u] + cost;
			que.push( e );
		}
	}

	for( int i = 0; i < n; i++ ) {
		cout << i << " " << d[i] << endl;
	}
}



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

char str[100001];
int flag[26];

int main(void){
	register int i,len;
	gets(str);
	for(i=0,len=strlen(str);i<len;i++)
		flag[str[i]-'a']=true;
	for(i=0;i<26;i++)
		if(!flag[i])
			return printf("%c\n",i+'a'),0;
	puts("None");
	return 0;
}

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

int main(){

  stack<int> S;
  int a,b,x;
  string word;

  while(cin >> word ){
    if(word == "+"){
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a+b);
    }else if(word == "-"){
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a-b);      
    }else if(word == "*"){
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a*b);  
    }else{
      S.push(atoi(word.c_str())); //string???char?????§????????????
    }
  }
  cout << S.top() << endl;

  return 0;
}

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

using namespace std;

int main() {
	char N[5];
	cin >> N;
	int cnt = 0;

	if (N[0] == N[1] && N[1] == N[2]) {
		cout << "Yes" << endl;
	}
	else if (N[1] == N[2] && N[2] == N[3]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;

}

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

#define ff first
#define ss second
#define all(abcc) (abcc).begin(), (abcc).end()
#define endl '\n'
#define left aba
#define right abc

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N=3003;

string s, t;
int ss, st;

int lcs[N][N];

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

    cin>>s>>t;
    ss=(int)s.size();
    st=(int)t.size();

    for(int i=1; i<=ss; ++i) {
        for(int j=1; j<=st; ++j) {
            if(s[i-1]==t[j-1]) {
                lcs[i][j]=lcs[i-1][j-1]+1;
            }
            else lcs[i][j]=max(lcs[i-1][j], lcs[i][j-1]);
        }
    }

    int i=ss, j=st;
    string res="";

    while(i && j) {
        if(s[i-1]==t[j-1]) {
            res+=s[i-1];
            i--;
            j--;
        } else if(lcs[i-1][j]>lcs[i][j-1]) {
            i--;
        } else j--;
    }

    reverse(all(res));
    cout<<res<<endl;

    //cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<"s"<<'\n';
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

int main(){
  int N;cin >> N;
  vi p;
  for (int i=0;i<N;++i){
    int p_;cin>>p_;p.push_back(p_-1);
  }

  int single_same=0;
  int double_same=0;
  int flag=0;
  for (int i=0;i<N;++i){
    if(flag==0&&p[i]==i){single_same++;flag=1;}
    else if(p[i]!=i){flag=0;}
    else if(flag==1&&p[i]==i){double_same++;flag=0;}
  }
  cout << single_same << endl;
  return 0; 
}

Measured memory_bytes: 892
#include<stdio.h>
#define N 100
int main()
{
    int a,i,j,tmp;
    int cnt = 0;
    int A[N];

    scanf("%d",&a);
    for(i = 0 ; i < a ; i++){
        scanf("%d",&A[i]);
    }
    for(i = 0 ; i < a - 1 ; i++){
        for(j = a - 1 ; j >=i+1 ; j--){
            if(A[j] < A[j-1]){
                tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
                cnt++;
        }
    }
}
    for(i = 0 ; i < a ; i++){
        printf("%d",A[i]);
        if(i < a - 1)printf(" ");
    }
    printf("\n%d\n",cnt);
    return 0;
}




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

int LCS(char *x, char *y){
    
    int i, j, m, n, c[1002][1002];
    
    m = strlen(x);
    n = strlen(y);
 
    for(i = 0; i <= m; i++){
        for(j = 0; j <= n; j++){
            if(i == 0 || j == 0) c[i][j] = 0;
            if(x[i] == y[j]) c[i+1][j+1] = c[i][j] + 1;
            else if(c[i][j+1] >= c[i+1][j]) c[i+1][j+1] = c[i][j+1];
            else c[i+1][j+1] = c[i+1][j];
        }
    }
    
    return c[m][n];
  
}

int main(){
    
    char x[1002], y[1002];
    int i, q;
    
    scanf("%d", &q);
    
    while(q--){
        scanf("%s%s", x, y);
        printf("%d\n", LCS(x, y));
    }
   
    return 0;
    
}

Measured memory_bytes: 4532
#include<iostream>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    if(S.size() % 2 == 1){
        std::cout << "No" << std::endl;
        return 0;
    }
    for(int i=0; i<S.size(); i=i+2){
        if(S[i] != 'h' || S[i+1] != 'i'){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
//#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    int N;
    std::string S;
    std::cin >> N;
    std::cin >> S;

    std::vector<int> east_bits(N);
    std::vector<int> west_bits(N);
    for (int i = 0; i < N; i ++) {
        east_bits[i] = S[i] == 'E';
        west_bits[i] = S[i] == 'W';
    }
    std::vector<int> east_cumsum;
    std::partial_sum(east_bits.begin(), east_bits.end(), std::back_inserter(east_cumsum));
    std::vector<int> west_cumsum;
    std::partial_sum(west_bits.begin(), west_bits.end(), std::back_inserter(west_cumsum));

    int min_changes = N;
    for (int i = 0; i < N; i ++) {
        if (i == 0) {
            int changes = east_cumsum[N - 1] - east_cumsum[0];
            min_changes = std::min(min_changes, changes);
        } else {
            int changes_r = east_cumsum[N - 1] - east_cumsum[i];
            int changes_l = west_cumsum[i - 1];
            min_changes = std::min(min_changes, changes_r + changes_l);
        }
    }
    std::cout << min_changes << std::endl;
}


Measured memory_bytes: 9080
a, b, c, d, e, f = gets.split.map(&:to_i)
a, b = a > b ? [a, b] : [b, a]
wa, wb = a * 100, b * 100
wperm = []
0.step(f, wa){|wa_|
  0.step(f, wb){|wb_|
    if (sum = wa_ + wb_) <= f
      wperm << sum
    end
  }
}

sperm = []
0.step(f, c){|c_|
  0.step(f, d){|d_|
    if (sum = c_ + d_) <= f
      sperm << sum
    end
  }
}
wperm = wperm.uniq.select{|x| !x.zero?}
sperm.uniq!

res = [0, 0, 0]
wperm.each{|w|
  sperm.each{|s|
    next if (ws = w + s) > f || w / 100 * e < s
    res_ = [s.to_f / ws, ws, s]
    res = res_ if res[0] <= res_[0]
  }
}
puts res[1..2] * " "


Measured memory_bytes: 3836
import sys
X = int(input())
L = []
for i in range(1,32):
  for j in range(1,10):
    if X < i**j:
      if j != 2:
        L.append(i**(j-1))
        break
      break
    elif X == i**j and j != 1:
      print(i**j)
      sys.exit(0) #平方数忘れ
print(max(L))

Measured memory_bytes: 3060
begin
	writeln('1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1');
end.


Measured memory_bytes: 1372
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(void){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        A[i]--;
    }

    int s = 0, t = 0;
    ll icnt = 0;
    do{
        s = A[s];
        t = A[A[t]];
        icnt++;
    }while(s != t);
    ll jcnt = 0;
    do{
        s = A[s];
        t = A[A[t]];
        jcnt++;
    }while(s != t);
    int ans = 0;
    for(int i = 0; i < min(K, icnt); i++) ans = A[ans];
    K -= icnt;
    K %= jcnt;
    for(int i = 0; i < K; i++) ans = A[ans];
    cout << ans + 1 << endl;
    return 0;
}


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

int main(){
    int n, h;
    cin >> n >> h;
    vector<int>a(n);
    vector<int>b(n);
    rep(i, n)	cin >> a[i] >> b[i];
    //solve
    sort(b.rbegin(), b.rend());	//昇順ソート
    ll ans = 0;
    int max = *max_element(a.begin(), a.end());
    for(int i = 0; i < n; i++){
	if(max < b[i]){
	    h -= b[i];
	    ans++;
	    if(h <= 0)	break;
	}
    }
    if(h > 0)	ans += (h + (max - 1))/max;
    cout << ans << endl;
}


Measured memory_bytes: 1024
N = gets.to_i
a, b, c, d = -10**10, -10**10, 10**10, 10**10
N.times{
  x, y = gets.split.map &:to_i
  a = [a, x-y].max
  b = [b, x+y].max
  c = [c, x-y].min
  d = [d, x+y].min
}
p [a-c, b-d].max


Measured memory_bytes: 14360
#include<stdio.h>
 


#define WHITE 1
#define BLACK 0
 
int main(){
 
  int d[100], color[100], w[100][100],i, j, v, c,n, u, k,min;
 
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    for(j = 0; j  < n; j++){
      w[i][j] = -1;
    }
  }
 
  for(i = 0; i < n; i++){
    scanf("%d %d",&u, &k);
    for(j = 0; j < k; j++){
      scanf("%d %d", &v, &c);   
      w[i][v] = c;
    }
  }
 
  for(i = 0; i < n; i++){
    d[i] = 1000000;
    color[i] = WHITE;
  }
 
  d[0] = 0;
   
  while(1){
    min =1000000;
    for(i = 0; i < n; i++){
      if(d[i] < min && color[i] ==WHITE){
        min = d[i];
        u = i;
      }
    }
     
    if(min == 1000000)break;
    color[u] = BLACK;
     
    for(v = 0; v < n; v++){
      if(w[u][v] == -1) continue;
      if(d[v] >  d[u] + w[u][v]) d[v] = d[u] + w[u][v];
    }
  }  
  for(i = 0; i < n; i++){
    printf("%d %d\n",i, d[i]);
  }
 
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
signed main(){
  char a[10000];
  int  w=0,n=0,s=0,e=0;
  cin>>a;
  for(int i=0;i<1000;i++){
    if(a[i]=='N'){
      n++;
    }
    if(a[i]=='W')
      w++;
    if(a[i]=='S')
      s++;
    if(a[i]=='E')
      e++;
  }
  if(n>=1 && s>=1 || n==0 && s==0){
    if(w>=1 && e>=1 || w==0 && e==0){
    cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
      return(0);
    }
  }
    else
    cout<<"No"<<endl;
  
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool foo(int a){
  if(a % 400 == 0) return true;
  else if(a % 100 == 0) return false;
  else if(a % 4 == 0) return true;
  else return false;
}
int main(void){
  int y1,m1,d1,y2,m2,d2;
  int m[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  unsigned long long a1,a2;
  for( ; ; ){
    cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
    if(y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0) break;

    a1 = a2 = 0;

    for(int i = 0;i < y1; i++){
      if(foo(i)) a1 += 366;
      else a1 += 365;
    }

    for(int i = 0;i < y2; i++){
      if(foo(i)) a2 += 366;
      else a2 += 365;
    }

    for(int i = 1;i < m1; i++) a1 += m[i];
    for(int i = 1;i < m2; i++) a2 += m[i];

    a1 += d1;
    a2 += d2;

    if(m1 >= 3){
      if(foo(y1)) a1++;
    }
    if(m2 >= 3){
      if(foo(y2)) a2++;
    }
    
    cout << a2 - a1 << endl;
  }
}


Measured memory_bytes: 1152
a, b = input().split()

b_sp = b.split('.')
b_seisu = int(b_sp[0])
b_shosu = 0
if(len(b_sp) > 1):
    b_shosu = int(b_sp[1])

# print(b_seisu, b_shosu)

mul = int(a)*(100*b_seisu + b_shosu)
mul_seisu = mul//100
print(mul_seisu)


Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int x,k,d;
	cin>>x>>k>>d;
	x=llabs(x);
	if(k<x/d)
		cout<<x-k*d;
	else
		if(x/d%2==k%2)
			cout<<x%d;
		else
			cout<<d-x%d;
	return 0;
}

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

int main(){
  int N;
  cin >>N;
  long long a[N];//入力
  for (int i=0;i<N;i++){
    cin>>a[i];
  }
  
  sort(a,a+N);//ソート
  bool flagtate=0;//たてが決まったか
  bool flagyoko=0;//横が決まったか
  long long tate=0;//決まったタテを入力
  long long yoko=0;//決まった横を入力
  long long temp=0;//現在着目している数字
  
  for (int i=N-1;i>-1;i--){
    //cout<<i<<" "<<flagtate<<" "<<flagyoko<<" "<<temp<<endl;
  
    if((flagtate==0)&&(a[i]==temp)){
      tate=temp;
      flagtate=1;
      temp--;
    }
    else if((flagtate==0)&&(!(a[i]==temp))){
      temp=a[i];
    }  

   else if((flagtate==1)&&(flagyoko==0)&&(a[i]==temp)){
      yoko=temp;
      flagyoko=1;
      //cout<<tate<<" "<<yoko<<endl;
      cout<<setprecision(20)<<tate*yoko<<endl;
      return 0;
    }
    else if((flagtate==1)&&(flagyoko==0)&&(!(a[i]==temp))){
      temp=a[i];
    }
  }
  //cout<<a[0]<<a[1]<<a[2]<<a[3]<<" "<<temp<<endl;//check
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
/*
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
*/

using namespace std;

int main()
{
    int ans = 0;

    string w;
    cin >> w;

    string t;
    cin >> t;

    while (t != "END_OF_TEXT")
    {
        for (int i = 0; i < t.size(); i++)
            if ('A' <= t[i] && t[i] <= 'Z')
                t[i] += 32;
        if (t == w)
            //if (t.find(w) != std::string::npos)
            ans++;
        cin >> t;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3120
/***************************************************************
	File name: B.cpp
	Author: huhao
	Create time: Sun 07 Jun 2020 08:22:30 PM CST
***************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=r*10+c-48;
		c=getchar();
	}
	return r*t;
}
const int N=1000010;
int f,g,F,G,n;
char s[N];
void solve(int m,int w,int l,int r)
{
	if(l<0){ f=std::max(f,m); l+=2; }
	if(r>w){ g=std::max(g,m); r-=2; }
	if(l>r) return ;
	if(m>n){ printf("%d\n",w); exit(0); }
	if(s[m]=='0') solve(m+1,w,l+1,r+1);
	else if(s[m]=='1') solve(m+1,w,l-1,r-1);
	else solve(m+1,w,l-1,r+1);
}
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	f=g=1;
	fr(i,1,n)
	{
		F=f; G=g; f=-1; g=-1;
		if(F!=-1) solve(F,i,0,0);
		if(G!=-1) solve(G,i,i,i);
	}
	return 0;
}

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

int main(void){
  int N, M;
  cin >> N >> M;
  vector<int> height(N+1);
  for(int i = 1; i <= N; i++){
    cin >> height.at(i);
  }
  vector<bool> good(N+1, true);

  int a, b;
  int cnt = N;
  for(int i = 1; i <= M; i++){
    cin >> a >> b;
    if(height.at(a) >= height.at(b)){
      if(good.at(b) == true){
        --cnt;
      }
      good.at(b) = false;
    }
    if(height.at(a) <= height.at(b)){
      if(good.at(a) == true){
        --cnt;
      }
      good.at(a) = false;
    }
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll W,H; cin>>W>>H;
    vector<P> A;
    rep(i,W){
        ll p; cin>>p;
        A.emplace_back(p,0);
    }
    rep(i,H){
        ll p; cin>>p;
        A.emplace_back(p,1);
    }
    SORT(A);
    ll ans=0;
    ++H; ++W;
    for(auto a: A){
        if(a.second==0){
            ans+=a.first*H;
            --W;
        }
        else{
            ans+=a.first*W;
            --H;
        }
    }
    cout<< ans<<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 6512