akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll f(ll a) {
    return a*a*a*a*a;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll x;
    cin >> x;
    for(ll i=-120;i<=120;++i) {
        for(ll j=-120;j<=120;++j) {
            if(f(i) - f(j) == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3640
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	int A, B, C; cin >> A >> B >> C;
	int ans = C - (A - B);
	if (ans < 0) ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  if (S == "SUN") cout << 7 << endl;
  if (S == "MON") cout << 6 << endl;
  if (S == "TUE") cout << 5 << endl;
  if (S == "WED") cout << 4 << endl;
  if (S == "THU") cout << 3 << endl;
  if (S == "FRI") cout << 2 << endl;
  if (S == "SAT") cout << 1 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B=MAP()

if A==B:
    print(A*2)
else:
    print(max(A, B)*2-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//(char-'0') 数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a;
  ci(a);
  vec b(a);
  ll an=0;
  For(i,0,a){
    ci(b[i]);
    an+=b[i];
  }
  ll k=0,j=0;
  For(i,0,a){
    k+=b[i];
    if(k*2>=an){
      j=k-b[i];
      break;
    }
  }
  //co(k*2-an);co(an-j*2);
  co(min(k*2-an,an-j*2));
}

Measured memory_bytes: 1792
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports)]

use std::cmp::*;
use std::collections::*;

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {return a};
    return gcd(b, a % b);
}

fn main() {
    input! {
        N : usize,
        A : [usize; N]
    }
    // 左からGCDを累積する
    let mut left_gcd = vec!(A[0]);
    for n in 1..N {
        let temp = gcd(*left_gcd.last().unwrap(), A[n]);
        left_gcd.push(temp);
    }
    // 右からGCDを累積する
    let mut right_gcd = vec!(A[N - 1]);
    for n in 1..N {
        let temp = gcd(*right_gcd.last().unwrap(), A[N - 1 - n]);
        right_gcd.push(temp);
    }
    right_gcd.reverse();
    // 挟み撃ちでGCDを列挙する
    let mut all_gcd = vec!(left_gcd[N - 2], right_gcd[1]);
    for n in 0..N - 2 {
        all_gcd.push(gcd(left_gcd[n], right_gcd[n + 2]));
    }
    //println!("{:?}", left_gcd);
    //println!("{:?}", right_gcd);
    //println!("{:?}", all_gcd);
    println!("{}", all_gcd.iter().max_by(|a, b|  a.partial_cmp(b).unwrap()).unwrap());
}


Measured memory_bytes: 10492
#include<stdio.h>
int q[10010];
int topo(int v,int e,int *a,int *b){
  int ta[10010],nt[100010];
  int i,t,r,c[10010]={0};
  for(i=0;i<e;i++)c[b[i]]++;
  for(i=r=0;i<v;i++){
    ta[i]=-1;
    if(c[i]==0)q[r++]=i;
  }
  for(i=0;i<e;i++){
    nt[i]=ta[a[i]];
    ta[a[i]]=i;
  }
  for(t=0;t<v;t++){
    for(i=ta[q[t]];i+1;i=nt[i]){
      if(--c[b[i]]==0)q[r++]=b[i];
    }
  }
}
int main(){
  int v,e,m,i,s,a[100010],b[100010];
  scanf("%d %d",&v,&e);
  for(i=0;i<e;i++)scanf("%d %d",&a[i],&b[i]);
  topo(v,e,a,b);
  for(i=0;i<v;i++)printf("%d\n",q[i]);
  return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
char s[N], t[N];
map<long long, char> M;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s%s", s, t);
	long long ans = 1ll * n * m / __gcd(n, m);
	for (int i = 0; i < n; i++) M[ans / n * i + 1] = s[i];
	for (int i = 0; i < m; i++) {
		long long p = ans / m * i + 1;
		if (M.count(p) && M[p] != t[i]) {
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6144
#include <stdio.h>

int main (void){
    char s[3];
    scanf("%s",s);
    int i = -1;
    int flg = 0;
    while(++i < 3){
        if(s[i] != s[0])
            flg = 1;
    }
    if(flg)
        printf("Yes\n");
    else 
        printf("No\n");
    return 0;
}

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

typedef long long ll;
const int NMAX = 3e5 + 10;
const int MOD = 1e9 + 7;
int col[NMAX],row[NMAX];
bool col_vised[NMAX],row_vised[NMAX];

int main(int argc, char const *argv[])
{
	int h,w,m;
	int x,y;
	vector<pair<int,int> >v;
	scanf("%d%d%d",&h,&w,&m);
	for(register int i = 0;i < m;i++)
		scanf("%d%d",&x,&y),col[y]++,row[x]++,v.push_back({x,y});
	if(h == 1 || w == 1)
		return 0*printf("%d\n", m);

	int ans = 0;
	int row_max = 0 , col_max = 0;
	int col_num = 0 , row_num = 0;
	for(register int i = 1;i <= h;i++)
		row_max = max(row_max,row[i]);
	for(register int i = 1;i <= h;i++)
		if(row[i] == row_max)
			row_vised[i] = true,row_num++;
	
	for(register int i = 1;i <= w;i++)
		col_max = max(col_max,col[i]);
	for(register int i = 1;i <= w;i++)
		if(col[i] == col_max)
			col_vised[i] = true,col_num++;
	int tot = 0;
	for(register int i = 0;i < v.size();i++)
		tot += row_vised[v[i].first] && col_vised[v[i].second] ? 1:0;
	printf("%d\n",tot == col_num * row_num ? col_max + row_max - 1:col_max + row_max);
	return 0;
}

Measured memory_bytes: 9800
#pragma GCC optimize("O3")
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int  ans=INT_MAX;
    for(int i=0;i<=n-m;i++){
        int res=0;
        for(int j=0;j<m;j++){
            if(i+j>=n){
                res=INT_MAX;
                break;
            }
            if(s[i+j]!=t[j])res++;
        }
        chmin(ans,res);
    }
    cout<<ans<<"\n";
}


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

ll N,M,Q;
vector<ll> a(51),b(51),c(51),d(51);
vector<ll> A(51);
ll ma = 0;
ll sum=0;


int keisan(int now,int num){
	if(now==N){
		for(int j=0;j<Q;j++){
			//cout<<A.at(j)<<" ";
			//cout<<A.at(b.at(j)-1)-A.at(a.at(j)-1)<<" "<<c.at(j)<<" "<<d.at(j)<<endl;
			if(A.at(b.at(j)-1)-A.at(a.at(j)-1)==c.at(j))
				sum+=d.at(j);
		}
		//cout<<ma<<" "<<sum<<endl;
		ma = max(ma,sum);
		sum=0;
		//cout<<endl;
		return 0;
	}
	else{
		for(int i=num;i<=M;i++){
			//cout<<i<<" "<<M<<endl;
			A.at(now)=i;
			keisan(now+1,i);
		}

	}
	return 0;
}

int main(){
	cin>>N>>M>>Q;
	//cout<<N<<M<<Q;

	//a.resize(Q);
	//b.resize(Q);
	//c.resize(Q);
	//d.resize(Q);
	//A.resize(Q);
	for(int i=0;i<Q;i++)
		cin>>a.at(i)>>b.at(i)>>c.at(i)>>d.at(i);
	keisan(0,1);
	cout<<ma<<endl;

}

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

int main()
{
    string s;
    int i, n;
    
    cin >> s;
    
    n = s.size();
    
    for(i = 0; i < n; i++) {
        if((i % 2) == 0) {
            cout << s[i];
        }
    }
    
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 512
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().rstrip().split())
ret = 0
if N > 1:
    ret += combinations_count(N, 2)
if M > 1:
    ret += combinations_count(M, 2)
print(ret)


Measured memory_bytes: 3060
#include <stdio.h>

int main(int argc, char *argv[])
{
  int num, i, j;
  int card[4][13] = {0};
  char* mark[4] = {"S","H","C","D"};

  scanf("%d", &num);

  for (i = 0; i < num; i++) {
    char type[10];
    int value;

    scanf("%s %d", type, &value);
    switch (type[0]) {
    case 'S' : card[0][value - 1] = 1; break;
    case 'D' : card[3][value - 1] = 1; break;
    case 'C' : card[2][value - 1] = 1; break;
    case 'H' : card[1][value - 1] = 1; break;
    }
  }

  for (i = 0; i < 4; i++)
    for (j = 0; j < 13; j++)
      if (card[i][j] == 0)
	printf("%s %d\n", mark[i], j+1); 
  
  return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

int main() {
    while(true) {
        int n; scanf("%d", &n);
        if(n==0) break;
        int a=0,b=0;
        while(n--) {
            int x,y; scanf("%d%d", &x, &y);
            (x>=y?a:b)+=x;
            (x<=y?b:a)+=y;
        }
        printf("%d %d\n", a, b);
    }
    return 0;
}

Measured memory_bytes: 0
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

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

  vll as(n);
  rep(i, n) cin >> as[i];
  Sort(as);

  ll l = 0LL;
  ll r = 2LL * 1e5 + 1LL;

  auto f = [&](ll x) {
    ll ret = 0;
    rep(i, n) ret += n - Lower_bound(as, x - as[i]);
    return ret;
  };

  while (l + 1 != r) {
    ll mid = (l + r) / 2;
    ll fmid = f(mid);
    if (fmid < m)
      r = mid;
    else
      l = mid;
  }

  ll fl = f(l);

  vll ascum(n + 1, 0);
  rep(i, n) ascum[i + 1] = ascum[i] + as[i];

  ll ans = 0;
  ll minv = LONG_LONG_MAX;
  rep(i, n) {
    ll idx = Lower_bound(as, l - as[i]);
    if (idx == n) continue;
    ans += ascum[n] - ascum[idx] + (n - idx)*as[i];
    chmin(minv, as[i] + as[idx]);
  }

  ans -= minv * (fl - m);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  _L = a[left..mid-1]
  _R = a[mid..right-1]
  _L[n1] = _R[n2] = 1.0 / 0.0
  i = j = 0
  cnt = 0
  left.upto(right-1){|k|
    if _L[i] <= _R[j] then
      a[k] = _L[i]
      i += 1
    else
      a[k] = _R[j]
      j += 1
      cnt += n1 - i
    end
  }
  return cnt
end

def mergeSort(a, left, right)
  count = 0
  if left+1 < right then
    mid = (left + right) / 2
    count += mergeSort(a, left, mid)
    count += mergeSort(a, mid, right)
    count += merge(a, left, mid, right)
  end
  return count
end

n = gets.to_i
a = gets.split.map(&:to_i)

count = mergeSort(a, 0, n)

#puts a.join(" ")
puts count

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

int main() {
  int X, N, ans;
  cin >> X >> N;
  vector<int>P(N);
  
  for(int i=0; i<N; i++){
    cin >> P.at(i);
  }
  
  for(int i=0; i<52; i++){
    int a=0; int b=0;
    for(int j = 0; j<N; j++){
      if(X-i!=P.at(j)){
        a++;
      }
      if(X+i!=P.at(j)){
        b++;
      }
    }
    
    if(a==N){
      cout << X-i << endl;
      break;
    }
    if(b==N){
      cout << X+i << endl;
      break;
    }
  }
}

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

const int MAX_N = 205;
int N, M, R, d[MAX_N][MAX_N], r[10];

void warshall_floyd(){
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++)
            for(int j=0;j<N;j++) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
    }
}

int main(){
    cin >> N >> M >> R;
    for(int i=0;i<R;i++) cin >> r[i];
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) d[i][j] = 1e9;
    for(int i=0;i<M;i++){
        int a, b, c; cin >> a >> b >>c;
        d[a-1][b-1] = d[b-1][a-1] = c;
    }
    warshall_floyd(); sort(r, r+R);

    int ans = 1e9;
    do{
        int cur = 0;
        for(int i=0;i<R-1;i++) cur += d[r[i]-1][r[i+1]-1];
        ans = min(ans, cur);
    } while(next_permutation(r, r+R));

    cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();

		Double PI = 3.1415926535;

		Double enshu = 2*R*PI;
		
		System.out.println(enshu);
		sc.close();
	}

}


Measured memory_bytes: 36020
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int D;
    cin >> D;
    vector<int>c(26);
    for(int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    vector<vector<int>>s(D,vector<int>(26));
    for(int i = 0; i < D; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int>t(D);
    for(int i = 0; i < D; i++) {
        int mx = 0;
        int as = 0;
        for(int j = 0; j < 26; j++) {
            if(mx < s[i][j]) {
                mx = s[i][j];
                as = j;
            }
        }
        t[i] = as+1;
    }
    int ans = 0;
    vector<int>Last(26);
    for(int i = 0; i < D; i++) {
        ans+=s[i][t[i]-1];
        Last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            ans-=c[j]*(i+1-Last[j]);
        }
    }
    for(int z = 0; z < 666666; z++) {
        int M = 3;
        for(int i = 0; i < M; i++) {
            int d = rand()%D+1;
            int q = rand()%26+1;
            int ord = ans;
            int X = 0;
            int Y = 0;
            int A = 0;
            int B = 0;
            ans+=s[d-1][q-1]-s[d-1][t[d-1]-1];
            for(int j = 0; j < D; j++) {
                if(t[j] == t[d-1]) {
                    if(j == d-1) {
                        Y = j+1;
                    }
                    else {
                        X = j+1;
                    }
                    A = j+1;
                }
                if(t[j] == q) {
                    Y = j+1;
                    B = j+1;
                }
                ans-=c[t[d-1]-1]*(j+1-X)-c[t[d-1]-1]*(j+1-A);
                ans+=c[q-1]*(j+1-B)-c[q-1]*(j+1-Y);
            }
            if(ans > ord) {
                ord = ans;
                t[d-1] = q;
            }
            else {
                ans = ord;
            }
        }
        int Z = 1;
        for(int i = 0; i < Z; i++) {
            int d = rand()%D+1;
            int q = rand()%26+1;
            int ord = ans;
            int X = 0;
            int Y = 0;
            int A = 0;
            int B = 0;
            ans+=s[d-1][q-1]-s[d-1][t[d-1]-1];
            for(int j = 0; j < D; j++) {
                if(t[j] == t[d-1]) {
                    if(j == d-1) {
                        Y = j+1;
                    }
                    else {
                        X = j+1;
                    }
                    A = j+1;
                }
                if(t[j] == q) {
                    Y = j+1;
                    B = j+1;
                }
                ans-=c[t[d-1]-1]*(j+1-X)-c[t[d-1]-1]*(j+1-A);
                ans+=c[q-1]*(j+1-B)-c[q-1]*(j+1-Y);
            }
            if(ans < ord) {
                ord = ans;
                t[d-1] = q;
            }
            else {
                ans = ord;
            }
        }
    }
    for(int i = 0; i < D; i++) {
        cout << t[i] << endl;
    }
}

Measured memory_bytes: 3704
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] times = {
            sc.nextInt(),
            sc.nextInt(),
            sc.nextInt(),
            sc.nextInt(),
            sc.nextInt()
        };
        int num = 0; 
        for (int t : times) {
            int mod = t % 10;
            if (mod != 0) {
                if (num == 0) {
                    num = mod;
                } else if (num > mod) {
                    num = mod;
                } 
            }
        }

        int total = 0;
        for (int t : times) {
            int mod = t % 10;
            if (mod == 0) {
                total += t;
            } else if (mod == num ){
                total += t;
                num = 0;
            } else {
                total += (t + 10 - mod);
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> S;
    auto c = S.back();
    if (c == '3') {
        cout << "bon" << endl;
    } else if (c == '0' || c == '1' || c == '6' || c == '8') {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
  exit(0);
}


Measured memory_bytes: 3508
####################
####################
####################
####################
from heapq import*
i=input
for s in[0]*int(i()):
 n,x,*y=int(i()),[]
 for _ in'_'*n:
  k,l,r=map(int,i().split())
  if l>=r:s+=r;x+=[[k,l-r]]
  else:s+=l;y+=[[n-k,r-l]]*(k<n)
 for x in x,y:
  x.sort();h=[]
  for k,d in x:
   heappush(h,d)
   if len(h)>k:heappop(h)
  for d in h:s+=d
 print(s)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  int H,W,D;
  cin >> H >> W >> D;
  int A[H][W];
  map<int,pair<int,int> > num;
  rep(i,H)rep(j,W){
    cin >> A[i][j];
    num[A[i][j]] = make_pair(i,j);
  }

  //cost
  vector<int> sumCost(H*W+1,0);
  FOR(i , D+1, H*W+1){
    sumCost[i] =  abs(num[i].first - num[i-D].first) +
                  abs(num[i].second - num[i-D].second);
  }

  FOR( i , 1, H*W-D+1){
    sumCost[i+D] += sumCost[i];
  }

  int Q;
  cin >> Q;
  rep(i,Q){
    int l,r;
    cin >> l >> r;
    cout << sumCost[r] - sumCost[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 7424
# seishin.py
A, B = map(int, input().split())
D = [list(map(int, input().split())) for i in range(A)]

N = 101
F = [[0]*N for i in range(N)]
for a in range(N):
    for b in range(N):
        res = 0
        for x in range(A):
            for y in range(B):
                res = max(res, D[x][y] - (x+1)*a - (y+1)*b)
        F[a][b] = res

for x in range(A):
    for y in range(B):
        v = 101
        for a in range(N):
            for b in range(N):
                v = min(v, (x+1)*a + (y+1)*b + F[a][b])
        if v != D[x][y]:
            print("Impossible")
            exit(0)
print("Possible")
print(2*N, N**2 + 2*(N-1))
ans = 0
for i in range(N-1):
    print(i+1, i+2, "X")
    print(103+i, 102+i, "Y")
    ans += 2
for a in range(N):
    for b in range(N):
        ans += 1
        print(a+1, 102+b, F[a][b])
print(1, 102)

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

using namespace std;

const int N = (1<<19) , mod = 1e9 +7;


int main()
{
    int a , b ;
    cin>>a>>b;
    string aa , bb ;
    aa = string(b , char(a+'0') );
    bb =string(a ,char(b+'0'));
    if(aa<bb)
        cout<<aa;
    else cout<<bb;
    return 0;
}


Measured memory_bytes: 256
s = list(map(int, input().split()))
n=s[0]
k=s[1]
s = list(map(int, input().split()))
ep=[]
for i in s:
    ep.append((1+i)/2)
s={}
s[k-1]=0
for i in range(k):
    s[k-1]+=ep[i]
for i in range(k-1,n-1):
    s[i+1]=s[i]+ep[i+1]-ep[i-k+1]
print(max(s.values()))

Measured memory_bytes: 40536
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    string s;
    cin>>s;
    if (s[1]=='B')
    {
    	cout<<"ARC"<<endl;
	}
	else
	{
		cout<<"ABC"<<endl;
	}
}

Measured memory_bytes: 3648
<?php

$n = (int)trim(fgets(STDIN));
$p = implode('', explode(" ", trim(fgets(STDIN))));
$q = implode('', explode(" ", trim(fgets(STDIN))));

function createPermutation($n, $r)
{
  if (!$r || $n < $r) {
    return array();
  }
  
  $return = array();
  $n2 = $n - 1;
  
  if ($r == 1) {
    for ($i=0; $i < $n ; $i++) { 
      $return[] = array($i);
    }
    return $return;
  }
  //(n-1)Prは、ほしい順列の一部
  foreach (createPermutation($n2, $r) as $row) {
    $return[] = $row;
  }
  //(n-1)P(r-1)各行の左端から右端まで、n-1を挿入したものを追加。
  foreach (createPermutation($n2, $r-1) as $row) {
    for ($i=0; $i < $r; $i++) { 
      $return[] = array_merge(array_slice($row, 0, $i), array($n2), array_slice($row, $i));
    }
  }
  return $return;
}

$arr = array_map ( function($obj){
    $s = '';
    foreach ($obj as $d) {
        $s .= ($d+1);
    }
    return $s;
}, createPermutation($n, $n));

sort($arr);

$a = 0;
$b = 0;
foreach ($arr as $index => $s) {
    if ($s == $p) {
        $a = $index+1;
    }

    if ($s == $q) {
        $b = $index+1;
    }
}

echo abs($a-$b)."\n";

Measured memory_bytes: 27512
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    
    double area = w * h;
    
    if (2 * x == w && 2 * y == h){
        cout << area / 2.0 << " " << 1 << endl;
    }else{
        cout << area / 2.0 << " " << 0 << endl;
    }
    
    return 0;
}



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

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b;
	cin>>a>>b;
	if (b%a==0){
		cout<<a+b;
	}
	else {
		cout<<b-a;
	}
	return 0;
}

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

using namespace std;

#define MAX 10000

int main(){
	
	int n;
	string s;
	string stm;
	vector<int> num[MAX];
	cin>>n;
	int lay;
	int sum;
	bool f;

	for(int i=0;i<n;i++){
		cin>>s;
		lay=0;
		for(int j=0;j<s.size();j++){
			if(s[j]=='[') lay++;
			else if(s[j]==']'){
				if(stm==""){
					sort(num[lay+1].begin(),num[lay+1].end());
					sum=0;
					for(int i=0;i<num[lay+1].size()/2+1;i++){
						if(f) sum+=num[lay+1][i]/2+1;
						else sum+=num[lay+1][i];
					}
					f=false;
					num[lay+1].clear();
					num[lay].push_back(sum);
					lay--;
				}
				else{
					num[lay].push_back(atoi(stm.c_str()));
					lay--;
					stm=("");
				}
			}
			else{
				stm+=s[j],f=true;
			}
			
		}
		sort(num[lay+1].begin(),num[lay+1].end());
		sum=0;
		for(int i=0;i<num[lay+1].size()/2+1;i++){
			sum+=num[lay+1][i];
		}
		cout<<sum<<endl;
		for(int i=0;i<MAX;i++){
			if(!num[i].empty()) num[i].clear();
		}
	}
}

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

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c-b-a;
    if(4 * a * b < d*d && c-a-b > 0)    cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long
signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (a > b)cout << 0 << endl;
	else {
		int m = a*(n - 1) + b;
		int u = b*(n - 1) + a;
		if (n == 1 && a != b)cout << 0 << endl;
		else cout << u - m + 1 << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	cin.tie(NULL);
	
	ll a,b, GCD, LCM;
	while(scanf("%lld %lld", &a, &b) != EOF){
		GCD = __gcd(a,b);
		LCM = a/GCD * b;
		printf("%lld %lld\n", GCD, LCM);
	}

	return 0;
}

Measured memory_bytes: 3164
#include<stdio.h>

int main(){
	
	long a,b,x,y,c;
	long a1,a2;
	
	while (1) {
		
	scanf("%ld %ld",&a,&b);
		if (getchar() == EOF)break;
		a1=a;
		a2=b;
		while(a1>0&&a2>0){
			if(a1<a2){
				c=a2;
				a2=a1;
				a1=c;
			}
			c=a2;
			a2=a1-a2;
			a1=c;
		}
		x=a1;
		y=a/x;
		y=y*b;
		printf("%ld %ld\n",x,y);
	}
	
	return 0;
}

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

int main() {
  int N, n = 0, sum = 0;
  cin >> N;

  n = N;
  while (true) {
    sum += n % 10;
    n = n / 10;
    if (n == 0) {
      sum += n;
      break;
    }
  }

  if (N % sum == 0)
    cout << "Yes";
  else
    cout << "No";
  cout << endl;
}

Measured memory_bytes: 256
/*author - Ashutosh Chitranshi*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007
#define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update>
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define mp make_pair
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
ll power(ll a,ll b)
{
    ll res = 1ll;
    while(b)
    {
        if(b%2==1)
            res = (res*a)%mod;
        a = (a*a)%mod;
        b /= 2;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll ans = power(10,n);
    ll ans1 = power(9,n);
    ll ans2 = power(9,n);
    ll ans3 = power(8,n);
    ans = (ans-ans1+mod)%mod;
    ans = (ans-ans2+mod)%mod;
    ans = (ans+ans3)%mod;
    cout << ans << nl;
    return 0;
}

Measured memory_bytes: 3668
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = input()

s = 0
for i in n:
    s += int(i)

if int(n) % s == 0:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 8932
#include<bits/stdc++.h>
#define ll long long
#define amaterasu ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
    amaterasu
    int n, k;
    cin >> n >> k;
    vector<ll> monsters(n);
    for(int i = 0; i < n; i++) cin >> monsters[i];
    sort(monsters.begin(), monsters.end(), greater<>());
    ll res = 0;
    for(int i = 0; i < n; i++)
    {
        if(k){
            k--;
        }
        else{
            res += monsters[i];
        }
    }
    cout << res;
    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	vi h(n);
	rep(i, n) cin >> h[i];

	int ans = 0;
	int step = 0;
	rep(i, n-1)
	{
		//cerr << step << endl;
		if(h[i+1] <= h[i])
			step++;
		else
		{
			chmax(ans, step);
			step = 0;
		}
	}
	chmax(ans, step);

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <typename T>
struct SegmentTree {
 private:
  ll n;            //最下段のサイズ
  T e;             //単位元
  vector<T> node;  //セグメント木を表現する配列
  typedef function<T(T, T)> Func;
  Func f;  //区間クエリで使う処理

 public:
  SegmentTree(vector<T> v, Func f_input, T e_input) {
    f = f_input;
    e = e_input;
    ll sz = SZ(v);
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, e);
    REP(i, sz) node[i + n - 1] = v[i];
    IREP(i, n - 1) node[i] = f(node[2 * i + 1], node[2 * i + 2]);
  }

  // x番目(0-indexed)の要素をvalに更新する
  void update(ll x, T val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = f(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  // [a, b) に対する区間クエリに答える
  // k := 自分がいるノードのインデックス
  // [l, r) : ノードkの対象区間
  T query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }

  // 添字でアクセス
  T operator[](ll i) { return node[i + n - 1]; }
};

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<ll> a(n);
  REP(i, n) {
    ll c = s[i] - 'a';
    a[i] = (1LL << c);
  }

  SegmentTree<ll> sg(a, [](ll x, ll y) { return x | y; }, 0LL);
  ll q;
  cin >> q;
  while (q--) {
    ll t;
    cin >> t;
    if (t == 1) {
      ll i;
      cin >> i;
      i--;
      char c;
      cin >> c;
      ll d = c - 'a';
      sg.update(i, 1LL << d);
      continue;
    }
    ll l, r;
    cin >> l >> r;
    l--;
    ll b = sg.query(l, r);
    ll ans = 0;
    REP(j, 26) {
      if ((1LL << j) & b) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 16900
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;

void sayNo() {
	cout << "No" << endl;
}

void sayYes() {
	cout << "Yes" << endl;
}

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

	 int count = 1;
	 int range = 1 + 2 * D;
	 while (range < N) {
		 count++;
		 range += 2 * D + 1;
	 }
	 cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt[26];
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++)cnt[s[i]-'a']++;
  for(int i=0;i<26;i++)if(cnt[i]%2!=0)return cout<<"No",0;
  cout<<"Yes\n";
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static  Map<Integer, List<int[]>> adj = new HashMap<Integer, List<int[]>>();
	static int V, E;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		V = sc.nextInt();
		E = sc.nextInt();
		// 隣接リストの作成
		for(int i = 0; i < E; i++) {
			int s = sc.nextInt();
			int v = sc.nextInt();
			int w = sc.nextInt();
			// s -> v
			if(adj.containsKey(s)) {
				int[]pair = {v, w};
				adj.get(s).add(pair);
			}else {
				List<int[]> list = new ArrayList<int[]>();
				int[]pair = {v, w};
				list.add(pair);
				adj.put(s, list);
			}
			// v -> s
			if(adj.containsKey(v)) {
				int[]pair = {s, w};
				adj.get(v).add(pair);
			}else {
				List<int[]> list = new ArrayList<int[]>();
				int[]pair = {s, w};
				list.add(pair);
				adj.put(v, list);
			}
		}
		sc.close();
		int ans = prim();
		System.out.println(ans);

	}
	static class Edge implements Comparable<Edge>{
		int from;
		int to;
		int cost;
		public Edge(int from, int to, int cost) {
			this.from = from;
			this.to = to;
			this.cost = cost;
		}
		@Override
		public int compareTo(Edge e) {
			return this.cost - e.cost;
		}
	}
	static int prim() {
		int totalCost = 0;
		boolean[] color = new boolean[V];
		Queue<Edge> pq = new PriorityQueue<Edge>();
		pq.add(new Edge(0, 0, 0));
		while(!pq.isEmpty()) {
			Edge e = pq.poll();
			if(color[e.to]) continue;
			color[e.to] = true;
			totalCost += e.cost;
			if(adj.containsKey(e.to)) {
				List<int[]> list = adj.get(e.to);
				for(int i = 0; i < list.size(); i++) {
					pq.add(new Edge(e.from, list.get(i)[0], list.get(i)[1]));
				}
			}
		}
		return totalCost;
	}
}


Measured memory_bytes: 113764
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int w=in.nextInt();
			int h=in.nextInt();
			if((w|h)==0)
				return;
			String state="U";
			int nh=1,nw=1;
			for(;;)
			{
				String s=in.next();
				if(s.equals("STOP"))
					break;
				
				if(s.equals("RIGHT"))
				{
					if(state.equals("U"))
						state="R";
					else if(state.equals("R"))
						state="D";
					else if(state.equals("D"))
						state="L";
					else if(state.equals("L"))
						state="U";
				}
				else if(s.equals("LEFT"))
				{
					if(state.equals("U"))
						state="L";
					else if(state.equals("L"))
						state="D";
					else if(state.equals("D"))
						state="R";
					else if(state.equals("R"))
						state="U";
				}
				else
				{
					int go=in.nextInt();
					if(s.equals("FORWARD"))
					{
						if(state.equals("U"))
							while(nh<h&&go-->0)
								nh++;
						else if(state.equals("L"))
							while(nw>1&&go-->0)
								nw--;
						else if(state.equals("D"))
							while(nh>1&&go-->0)
								nh--;
						else if(state.equals("R"))
							while(nw<w&&go-->0)
								nw++;	
					}
					else if(s.equals("BACKWARD"))
					{
						if(state.equals("U"))
							while(nh>1&&go-->0)
								nh--;
						else if(state.equals("L"))
							while(nw<w&&go-->0)
								nw++;
						else if(state.equals("D"))
							while(nh<h&&go-->0)
								nh++;
						else if(state.equals("R"))
							while(nw>1&&go-->0)
								nw--;	
					}
				}
			}
			System.out.println(nw+" "+nh);
		}
	}
}

Measured memory_bytes: 25844
import sys
n,a,b=map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  sys.exit()

ans=[]
L=[a]*b
x=a*b-n
for i in range(1,b):
  L[i]-=min(a-1,x)
  x-=min(a-1,x)
L.reverse()

ct=1
for i in range(b):
  l=[]
  for j in range(L[i]):
    l.append(str(ct))
    ct+=1
  ans.append(' '.join(l))
ans.reverse()

print(' '.join(ans))

Measured memory_bytes: 82780
N = int(input())
T, A = map(int, input().split())
H = [int(i) for i in input().split()]

avg_t = [abs(A - (T - h * 0.006)) for h in H]
ans = 0
min_t = min(avg_t)
for i in range(N):
    if avg_t[i] == min_t:
        print(i + 1)
        exit()

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);
ll n , m ,k;
ll nbr;
 vector<ll> mp[501501];
bool visited[501501];
vector <ll> dist; /// distance dans un arbre
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

void dfs(ll s)
{
    visited[s]=true; nbr++;
    dist[s]++;
    for (int i=0;i<mp[s].size();i++)
    {
        if (visited[mp[s][i]]==false)
        {
            dist[mp[s][i]]=dist[s];
            dfs(mp[s][i]);
        }
    }
}

bool valid(ll x,ll y)
	{
	    return ( x<n && y<m);
	}

int main()
{
	IOS;
    ll n;
    cin >> n;
    vector<ll> H;
    vector <ll> dp(n+1,0);
   // cout << dp[0];
    //cout << endl;
    for(int i=0;i<n;i++)
    {
        ll h;
        cin >> h;
        H.push_back(h);
    }
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(H[1]-H[0]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(H[i-1]-H[i-2]),dp[i-2]+abs(H[i-1]-H[i-3]));

    }
    /*for(int i=0;i<=n;i++)
        cout << dp[i] << " ";*/
    cout << dp[n];



    return 0;
}


Measured memory_bytes: 13944
from collections import defaultdict

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

Disguise = [list(map(int, input().split())) for _ in range(C)]
Color = [list(map(int, input().split())) for _ in range(N)]

C0 = defaultdict(int)
C1 = defaultdict(int)
C2 = defaultdict(int)

for i in range(N):
    for j in range(N):
        if (i + j + 2) % 3 == 0:
            C0[Color[i][j]] += 1
        elif (i + j + 2) % 3 == 1:
            C1[Color[i][j]] += 1
        else:
            C2[Color[i][j]] += 1

ans = float('inf')
for x in range(C):
    for y in range(C):
        for z in range(C):
            if x == y or y == z or z == x:
                continue
            ansi = 0
            for key, value in C0.items():
                ansi += Disguise[key - 1][x] * value
            for key, value in C1.items():
                ansi += Disguise[key - 1][y] * value
            for key, value in C2.items():
                ansi += Disguise[key - 1][z] * value
            ans = min(ansi, ans)
print(ans)


Measured memory_bytes: 47708
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll N, M , K;
    cin >> N >> M >> K;
    vector<ll> a(N), b(M),asum(N+1), bsum(M+1);
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<M; i++) cin >> b[i];
    asum[0] = 0;
    bsum[0] = 0;
    for(int i=1; i<=N; i++) {
        asum[i]=asum[i-1]+a[i-1];
    }
    for(int i=1; i<=M; i++) {
        bsum[i]=bsum[i-1]+b[i-1];
    }
    ll maxcount = 0;
    //consider picking up to books i on shelf a time x
    //then binary search for book time sum under k-x in b prefix sum
    for(int i=0; i<=N; i++) {
        //i=0 no books from a, i=N, all books from i
        //the cost must be under the allowed
        if(asum[i]>K) break;
        ll bmax = K-asum[i];
        //binary search lower bound
        //get the largest element <= number
        auto it = upper_bound(bsum.begin(), bsum.end(), bmax);
        if(it != bsum.end()) {
            //get how many b prefix sum are < than this iter
            ll bcount = (it-bsum.begin())-1;
            maxcount = max(maxcount, i+bcount);
        } else {
            maxcount = max(maxcount, i+M);
        }
    }
    cout << maxcount << "\n";
    
    return 0;
}


Measured memory_bytes: 9592
"""
連番が割り振られた重りがある
振られている数がある数よりも大きい番号と小さい番号に分け、それぞれの重さの和を取る
このとき、重さの和の絶対値が最小となるのはどこか
"""

n = int(input())

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

num = 0
sep = sum(weights)

for i in range(1, len(weights)):
    """以下と、それより大きいを境とした合計値を取得する"""
    left = sum(weights[:i])
    right = sum(weights[i:])

    """差の絶対値を取得"""
    abs_num = abs(left - right)

    if abs_num < sep:
        sep = abs_num

print(sep)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	char a[1000];
	scanf("%s",a);
	scanf("%d",&n);
	for(i=0;i<strlen(a);i+=n)
	{
		printf("%c",a[i]);
	}
	return 0;
}

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

using namespace std;

int main()
{
	for(int a[5];scanf("%d%d%d%d%d",a,a+1,a+2,a+3,a+4)==5;){
		sort(a,a+5);
		reverse(a,a+5);
		printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
	}
	
	return 0;
}

Measured memory_bytes: 0