akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 100010
using namespace std;
int main()
{
    int n,m;
    long long sum;
    scanf("%d %d",&m,&n);
    sum=n;
    for(int i=2;i<=m;i++)
    {
        sum=sum*(n-1);
    }
    printf("%lld",sum);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	ll N,Y; cin>>N>>Y;
	for(int i=0;i<=Y/10000;i++){
		for(int j=0;j<=(Y-10000*i)/5000;j++){
			if((N-i-j)*1000==Y-10000*i-5000*j){
				printf("%d %d %d",i,j,N-i-j);
				return 0;
			}
		}
	}
	printf("-1 -1 -1");
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define REPR(i,n) for(int i = n; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b-1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

static const ll mod  = 1e9 + 7;
static const ll inf  = 1e18;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<ll> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A--;B--;C--;D--;
    string S;
    cin >> S;
    vector<ll> v;
    ll cnt = 0;
    ll apoint, bpoint ,cpoint,dpoint;
    ll sum = 0;
    bool flag = 1, can = 0;
    if(C < D){
        FOR(i, A, C){
            if(S[i] == '#' && S[i+1] == '#') flag = 0;
        }
        FOR(i, B, D){
            if(S[i] == '#' && S[i+1] == '#') flag = 0;
        }
        if(flag) p("Yes");
        else p("No");
    }else{
        FOR(i, A, C){
            if(S[i] == '#' && S[i+1] == '#') flag = 0;
        }
        FOR(i, B, D){
            if(S[i] == '#' && S[i+1] == '#') flag = 0;
        }
        FOR(i, B-1, D){
            if(S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') can = 1; 
        }
            if(!can) flag  = 0;
            if(flag) p("Yes");
            else p("No");
    }
    //pvector(v);

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n,m=0;
    vector<int>v;
    for(int i=1;(i*(i+1)*(i+2))/6 < 1e6;++i){
        v.push_back((i*(i+1)*(i+2))/6);
        m++;
    }
    vector<int>dp(1e6,1e9);
    vector<int> dp1(1e6, 1e9);
    dp[0] = 0;
    dp1[0] = 0;
    for (int i = 0; i <= 1e6; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (i + v[j] >= 1e6)
                break;
            dp[i + v[j]] = min(dp[i] + 1, dp[i + v[j]]);
            if (v[j] % 2 == 0)
                continue;
            dp1[i + v[j]] = min(dp1[i] + 1, dp1[i + v[j]]);
        }
    }
    while(cin>>n,n){
        cout<<dp[n]<<" "<<dp1[n]<<endl;
    }
}

Measured memory_bytes: 10504
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
int main()
{
  using namespace std;
  int n;
  double res;
  cin>>n;
  vector<double> vec(n);
  for(int i=0;i<n;i++)
  cin>>vec[i];
  sort(vec.begin(),vec.end());
  for(int i=1;i<n;i++)
  vec[i]=(vec[i-1]+vec[i])/2.0;
  cout<<vec[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input=sys.stdin.readline
    while True:
        n,m=map(int,input().split())
        if n==0:
            break
        kis=[list(map(int,input().split())) for _ in [0]*n]
        dp1=[dict() for _ in [0]*(m+1)]
        dp2=[dict() for _ in [0]*(m+1)]
        dp3=[dict() for _ in [0]*(m+1)]
    
        nows=[dict() for _ in [0]*n]
        for i in range(n):
            j=kis[i][0]
            for k in range(j):
                nows[i][kis[i][2*k+1]]=kis[i][2*k+2]
        for i in range(kis[0][0]):
            dp1[0][kis[0][2*i+1]]=0
        if m>=1:
            for i in range(kis[1][0]):
                dp2[1][kis[1][2*i+1]]=0
        #ここからDP開始
        for k in range(n-1):#行をn-1回分繰り返す
            for l in range(m+1):#飛び越えた回数分
                for i,j in dp1[l].items():#iは現在位置、jはそれまでの最小危険度
                    for x,y in nows[k+1].items():#xは移動先、yは移動先の滑りやすさ
                        plus=j+(nows[k][i]+y)*abs(i-x)
                        if x in dp2[l].keys():
                            dp2[l][x]=min(dp2[l][x],plus)
                        else:
                            dp2[l][x]=plus
            if k==n-2:
                continue
            for l in range(m):#飛び越えた回数-1分
                for i,j in dp1[l].items():#iは現在位置、jはそれまでの最小危険度
                    for x,y in nows[k+2].items():#xは移動先、yは移動先の滑りやすさ
                        plus=j+(nows[k][i]+y)*abs(i-x)
                        if x in dp3[l+1].keys():
                            dp3[l+1][x]=min(dp3[l+1][x],plus)
                        else:
                            dp3[l+1][x]=plus
            dp1=dp2
            dp2=dp3
            dp3=[dict() for _ in [0]*(m+1)]
        m=10**9
        for i in dp1[:-1]:
            if len(i.values())>0:
                m=min(m,min(i.values()))
        for i in dp2:
            if len(i.values())>0:
                m=min(m,min(i.values()))
        print(m)
    
if __name__=='__main__':
    main()


Measured memory_bytes: 5888
a,b,c=map(int,input().split())
if a==1 and b==1 and c==1:
    print(0)
    exit()
if a==b==c:
    print(-1)
    exit()
v=[a,b,c]
v.sort()
tmp=[b-a,c-a,c-b]
ans=10**10
for i in range(len(tmp)):
    cnt=0
    while(tmp[i]%2==0):
        tmp[i]=tmp[i]//2
        cnt+=1
    ans=min(ans,cnt)

print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int main()
{
	while(1)
	{
		int n;
		int ans,ansv=-1;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			if(b+c>ansv)
			{
				ansv=b+c;
				ans=a;
			}
		}
		cout << ans << ' ' << ansv << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

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

  int res = 0;
  while (true) {
    if (*max_element(h.begin(), h.end()) == 0) break;

    int i = 0;
    while (i < N) {
      if (h[i] == 0)
        ++i;
      else {
        ++res;
        while (i < N && h[i] > 0) {
          --h[i];
          ++i;
        }
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
use std::collections::*;

#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn f(a: usize, b: usize) -> String {
    let sa = format!("{:06}", a);
    let sb = format!("{:06}", b);
    return sa + &sb;
}

fn main() {
    let (_pref, city) = get!(usize, usize);
    let mut v = Vec::with_capacity(city);
    for i in 0..city {
        let mut tmp = get!(usize, usize);
        v.push((tmp.0, tmp.1, i));
    }
    v.sort_by(|x, y| x.1.cmp(&y.1));
    let mut ans = vec!["".to_string(); city];
    let mut map = HashMap::new();
    for i in 0..city {
        match map.get(&v[i].0) {
            Some(n) => {
                let s = f(v[i].0, *n as usize + 1);
                ans[v[i].2] = s;
            }
            None => {
                let s = f(v[i].0, 1);
                ans[v[i].2] = s;
            }
        }
        let counter = map.entry(v[i].0).or_insert(0);
        *counter += 1;
    }
    for i in 0..city {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 20400
import numpy as np
from scipy.optimize import fmin

INF = 10**18

mapping = {
    "R": (1, 0),
    "L": (-1, 0),
    "U": (0, 1),
    "D": (0, -1)
}

def f(x, vx, t):
    if t < 0:
        return INF
    nx = x + vx * t
    return nx.max() - nx.min()

def solve(n, x, y, d):
    x = np.asarray(x, dtype=np.float)
    y = np.asarray(y, dtype=np.float)
    vx = np.zeros(n, dtype=np.float)
    vy = np.zeros(n, dtype=np.float)
    for i in range(n):
        vx[i], vy[i] = mapping[d[i]]
    h = lambda t: f(y, vy, t) * f(x, vx, t)
    t = fmin(h, x0=10**8, ftol=1e-9, disp=False)[0]
    return h(t)

n = int(input())
x, y, d = [-1]*n, [-1]*n, [-1]*n
for i in range(n):
    x[i], y[i], d[i] = input().split()
    x[i] = int(x[i])
    y[i] = int(y[i])
print(solve(n, x, y, d))

Measured memory_bytes: 30856
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)

bool isLower(char c){
    if(c - 'a' < 26){
        return true;
    }else{
        return false;
    }
}

int main() {
    string S;
    cin >> S;
    ll size = S.size();

    if(S[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    ll count = 0;
    for(ll i=2;i<size-1;i++){
        if(S[i] == 'C'){
            count++;
        }
    }
    if(count != 1){
        cout << "WA" << endl;
        return 0;
    }

    count=0;
    rep(i,size){
        if('A'<=S[i] && S[i]<='Z'){
            count++;
        }
    }
    if(count == 2){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }



}



Measured memory_bytes: 3576
import java.util.Arrays;
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] list=new int[n];
		boolean flag = false;
		for(int i=0;i<n;i++)list[i]=sc.nextInt();
		Arrays.sort(list);
		for(int i=0;i<n-1;i++) {
			if(list[i]==list[i+1])flag=true;
		}
		if(flag)System.out.println("NO");
		else System.out.println("YES");
	}
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        long n = fs.nextLong();
        int res = (int)1e9;
        for(long i = 1; i <= Math.sqrt(n); i++) {
            if(n%i == 0) {
                res = Math.min(res, Math.max(Long.toString(i).length(), Long.toString(n/i).length()));
            }
        }
        out.println(res);

        out.close();
    }


    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer("");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String line = "";
            try {
                line = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return line;
        }

        public Integer[] nextIntegerArray(int n) {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }
}


Measured memory_bytes: 22868
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        double r,S,l,pi=Math.PI;
        r=sc.nextDouble();
        S=r*r*pi;
        l=2*r*pi;
        System.out.printf("%f %f",S,l);
    }
}


Measured memory_bytes: 28428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin>>a>>b;
	for(ll i = (b-a+1);i<(a+b);i++)cout<<i<<" "; cout<<endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    vi w(n);
    vi e(n);

    w[0] = e[n-1] = 0;
    REP(i, n-1) w[i + 1] = s[i] == 'W' ? w[i] + 1 : w[i];
    for(int i = n - 1; i >= 1; --i) e[i - 1] = s[i] == 'E' ? e[i] + 1: e[i];

    int ans = 1e9;
    REP(i, n) ans = min(ans, w[i] + e[i]);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2964
# 配るDP
def main():
  divisor = 10 ** 9 + 7
  h, w = map(int, input().split())
  a = [input() for _ in range(h)]
  dp = [[0] * w for _ in range(h)]
  dp[0][0] = 1
  for i in range(h):
    ai = a[i]    
    dpi = dp[i]    
    if i + 1 < h:
      ai1 = a[i + 1]
      dpi1 = dp[i + 1]
    for j in range(w):
      if j + 1 < w and ai[j + 1] != '#':
        dpi[j + 1] = (dpi[j + 1] + dpi[j]) % divisor
      if i + 1 < h and ai1[j] != '#':
        dpi1[j] = dpi[j]
  print(dp[h - 1][w - 1])
main()


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

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


int main(){
    int n;
    cin >> n;
    int a[n],left[n],right[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    left[0] = a[0];
    right[n-1] = a[n-1];
    for(int i=0;i<n-1;i++){
        left[i+1] = gcd(a[i+1],left[i]);
        right[n-i-2] = gcd(right[n-i-1],a[n-i-2]);
    }

    int ans = max(left[n-2],right[1]);
    for(int i=1;i<n-1;i++){
        if(ans < gcd(left[i-1],right[i+1])){
            ans = gcd(left[i-1],right[i+1]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

//入力
int a,b ;

int main() {

	cin >> a >> b;

	cout << (a+b)%24 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX/10;
const ll MOD = 1e9+7;
int a[212345],opt[212345],dp[1<<26];
int main(){
	string s;
	cin>>s;
	int N=s.length();
	repeat(i,N)
		a[i+1]=a[i]^(1<<(s[i]-'a'));
	fill(opt,opt+N+1,INF);
	fill(dp,dp+(1<<26),INF);
	opt[0]=0;
	dp[0]=0;
	for(int i=1;i<=N;++i){
		opt[i]=dp[a[i]]+1;
		for(int x=1;x<(1<<26);x<<=1)
			opt[i]=min(opt[i],dp[a[i]^x]+1);
		dp[a[i]]=min(dp[a[i]],opt[i]);
	}
	cout<<opt[N]<<endl;
	return 0;
}


Measured memory_bytes: 264324
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#define MAX 100000007
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll ans=0;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
    ans+=a[i];
  }
  cout << ans-N << endl;
  return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
using namespace std;
#define len(n) (int)n.length()
#define dump cout
#define pb push_back
#define ll long long

int main()
{
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	vector<int> a;
	for (int i = 0; i < n; i++) {
	    int tmp;
		cin >> tmp;
		a.pb(tmp);
	}
	
	bool flag = true;
	int ans = 0;
	for (int k = 0; flag; k++) {
		flag = false;
		for (int i = n-1; i >= k+1; i--) {
			if (a[i] < a[i-1])
			{
				flag = true;
				int tmp = a[i];
				a[i] = a[i-1];
				a[i-1] = tmp;
				ans++;
				
			}
		}
		
	}
	
	for (int i = 0; i < n-1; i++) {
	    cout << a[i] << " ";
	}
	cout << a[n-1] << endl;
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 3140
X, K, D = gets.split(/\s+/).map(&:to_i)

m = 10**15

x = X
k = K
while k > 0
  if x > 0
    if x / D > 0
      minus = [k, x / D].min
      k -= minus
      x -= minus * D
      if x.abs < m
        m = x.abs
      end
    else
      if k % 2 == 0
        m = x.abs
      else
        m = (x-D).abs
      end
      break
    end
  else
    if -x / D > 0
      plus = [k, -x / D].min
      k -= plus
      x += plus * D
      if x.abs < m
        m = x.abs
      end
    else
      if k % 2 == 0
        m = x.abs
      else
        m = (x+D).abs
      end
      break
    end
  end
end

puts m

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

int main(){
	string S;
	cin >> S;
	int len = S.size();
	int min_num = 1000; // init
		
	for (int i=0; i < (len-2); ++i){
		int num = 0;
		for (int k=0; k<3; ++k)
		{
			char c = S[i+k];
			int	degit = (int)(c - '0');
			num += degit *pow(10, (2-k));
		}
		min_num = min(min_num, abs(753-num));
	}

	cout << min_num << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 200001
 
void QSort(int x[ ], int left, int right)
{
    int i, j,temp;
    int pivot;
 
    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */
 
    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */
 
    while (1) {                    /* 無限ループ */
 
        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */
 
        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */
    	temp = x[i];
    	x[i] = x[j];
    	x[j] = temp;
        i++;                       /* 次のデータ */
        j--;
    }
    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}
 
int main(int argc, char const *argv[]){
	int n,i,a,k,s[N]={0},c=0,j=0,tmp;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		s[a-1]++;
	}
	QSort(s,0,n-1);
	for(i=n-k-1;i>=0;i--){
		c+=s[i];
		if(s[i]==0)
			break;
	}
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
ll n;
string s;
cin>>n>>s;
ll count1=0;

ll count2=0;
for(ll i=0;i<n;i++){
if(s[i]=='R')
count1++;
else 
count2++;

}
if(count1>count2)
cout<<"Yes";
else
cout<<"No";
  return 0;
 
}
 

Measured memory_bytes: 256
import numpy as np
N=int(input())
a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
A=np.zeros(11,dtype=int)
for i in range(11):
  A[i]=(26**(i+1))
B=np.cumsum(A)
for i in range(11):
  if N<=B[i]:
    name=[" "]*(i+1)
    if i==0:
      N=N
    else:
      N-=B[i-1]
    for j in reversed(range(i+1)):
      if j>=1:
        if N==0:
          name[i-j]="z"
        else:
          name[i-j]=a[(N-1)//A[j-1]]
        N-=N//A[j-1]*A[j-1]
      else:
        if N==0:
          name[i-j]="z"
        else:
          name[i-j]=a[N-1]
    break

print(''.join(name))

Measured memory_bytes: 27228
import itertools as it
n,m,q=map(int,input().split())
kouho=list(it.combinations_with_replacement(range(1,m+1),n))


lis=[]
for i in range(q):
  lis.append(list(map(int,input().split())))  
keep=0
for i in range(0,len(kouho)):
  attack=kouho[i]
  point=0
  for j in range(0,q):
    if attack[lis[j][1]-1]-attack[lis[j][0]-1]==lis[j][2]:
      point+=lis[j][3]
  if point>keep:
    keep=point
print(keep)
    


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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<vector<int>> G(N, vector<int>());
    vector<bool> visited(N, false);
    vector<pair<int, int>> edges;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        edges.emplace_back(a, b);
    }
    int K = 0;;
    map<pair<int, int>, int> color;
    queue<pair<int, int>> que;
    que.push({0, 0});
    visited[0] = true;
    while (!que.empty()) {
        int top, parent_color;
        tie(top, parent_color) = que.front(); que.pop();
        if (K < G[top].size()) K = G[top].size();
        int cur_color = 1;
        for (int a: G[top]) {
            if (visited[a]) continue;
            if (cur_color == parent_color) {
                cur_color++;
            }
            color[make_pair(top, a)] = cur_color;
            color[make_pair(a, top)] = cur_color;
            // 親の色を指定する必要がある.
            visited[a] = true;
            que.push({a, cur_color});
            cur_color ++;
        }
    }
    cout << K << endl;
    for (auto& e: edges) {
        cout << color[e] << endl;
    }
    return 0;
}

Measured memory_bytes: 20720
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    }

    int count = 0;
    for (int i = 0; i < size - 1; i++) {
      int min = i;
      for (int j = i; j < size; j++) {
        if (array[j] < array[min]) {
          min = j;
        }
      }
      if (min != i) {
        swap(array, min, i);
        count++;
      }
    }

    for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    }
    System.out.println(array[size - 1]);
    System.out.println(count);
  }

  public static void swap(int[] array, int min, int i) {
    int tmp = array[i];
    array[i] = array[min];
    array[min] = tmp;
  }
}



Measured memory_bytes: 26420
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

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

        int ans =0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if(n <= min){
                min = n;
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 62288
#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
const int N = 2e3 + 1;
const int INF = 1e18;
vector<int> g[N];
int n, x, y;
int ans[N];
void solve(int i){
	vector<int> used(n), dist(n, 0);
	queue<int> q;
	q.push(i);
	used[i] = 1;
	while(!q.empty()){
		int Q = q.front();
		q.pop();
		if(Q > i){
			ans[dist[Q]]++;
		}
		for(int to : g[Q]){
			if(!used[to]){
				used[to] = 1;
				dist[to] = dist[Q] + 1;
				q.push(to);
			}
		}		
	}
}
signed main(){
	cin >> n >> x >> y;
	x--, y--;
	for(int i = 1; i < n; ++i){
		g[i].pb(i - 1);
		g[i - 1].pb(i);
	}
	g[x].pb(y);
	g[y].pb(x);
	for(int i = 0; i < n; ++i){
		solve(i);
	}
	for(int i = 1; i < n; ++i){
		cout << ans[i] << '\n';
	}
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int sum = 1;

    if (b == 1) {
        cout << 0 << endl;
        return;
    }

    while (true) {
        ++ans;
        --sum;
        sum += a;
        if (sum >= b) break;
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,m,q] = nexts(3);
  var d = nextm(q,4);
  var a = xArray(1,n);
  var ans = 0;
  while(1){
    var sum = 0;
    for(var i = 0; i < q; i++){
      var [w,x,y,z] = d[i]; 
      if(a[x-1]-a[w-1] === y)sum += z;
    }
    if(ans < sum)ans = sum;
    var f = 1;
    for(var i = n; i-- && f;){
      if(a[i] !== m){
        f = 0, a[i]++;
        for(var j = i+1; j < n; j++)a[j] = a[i];
      }
    }
    if(f)break;
  }
  return ans;
}

Measured memory_bytes: 33856
n=int(input())
t,a=map(int,input().split())
h = list(map(int,input().split()))
minimu = 1234567890

for i in range(n):
        if( minimu > abs(t-h[i]*0.006-a)):
                minimu=abs(t-h[i]*0.006-a)
                ans = i+1
print(ans)

Measured memory_bytes: 3060
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}          // Least Commont Multiple オーバーフローしないように先に割る

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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("b.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int a, b;

    cin >> a >> b;

//    cout << ((b+a-1)/a);

    int ans = 0;

    if (b == 1)
    {
        ans = 0;
    }
    else
    {
        rep(i, 1000)
        {
            if (a >= b)
            {
                ans++;
                break;
            }
            else
            {
                ans++;
                b -= (a-1);
            }

        }
    }

    cout << ans;


    return 0;
}

/*
  - 1e9 : 10^9
  - vector
    vector<int> A(N);
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - string
    - loop
      for (char& c : s) {}
 */



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

int main() {
    string s;
    cin >> s;
    
    int r = 0;
    int l = 0;
    int ans = 0;
    while (r < s.size()) {
        if (s[r] == 'A' || s[r] == 'T' || s[r] == 'C' || s[r] == 'G') {
            r++;
            if (r == s.size()) {
                ans = max(ans, r - l);
                break;
            }
        }
        else {
            ans = max(ans, r - l);
            l = r + 1;
            r = l;
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

const int cy = 201, cx = 201;

struct P{
  int y;
  int x;
};

bool compx(const P& p1, const P& p2)
{
  return p1.x < p2.x;
}

bool compy(const P& p1, const P& p2)
{
  return p1.y < p2.y;
}

int xdir[4] = {-1, 0, 1, 0}, ydir[4] = {0, -1, 0, 1};

int main()
{
  int n, s, t;
  P p;

  while(cin>>n && n){
    vector<P> vec;
    p.x = cx;
    p.y = cy;
    vec.push_back(p);
    for(int i = 1; i < n; i++){
      cin >> s >> t;
      p.x = vec[s].x + xdir[t];
      p.y = vec[s].y + ydir[t];
      vec.push_back(p);
    }
    sort(vec.begin(), vec.end(), compx);
    s = vec[vec.size()-1].x - vec[0].x + 1;
    sort(vec.begin(), vec.end(), compy);
    t = vec[vec.size()-1].y - vec[0].y + 1;

    cout << s << " " << t << endl;
  }

  return 0;
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>

using namespace std;

const int INF = 1 << 30;

inline int enc(int x, int y) { return x + y * 4; }

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

    set<int> paint;  // 選べる長方形領域
    for (int i = 0; i < N; ++i) {
        int H, W;
        cin >> H >> W;

        // 左下を軸に全探索
        for (int lx = -3; lx <= 3; ++lx) {
            for (int ly = -3; ly <= 3; ++ly) {
                int pat = 0;
                for (int dx = 0; dx < H; ++dx) {
                    for (int dy = 0; dy < W; ++dy) {
                        int x = lx + dx, y = ly + dy;
                        if (x < 0 || 4 <= x || y < 0 || 4 <= y) continue;
                        pat |= (1 << enc(x, y));
                    }
                }
                paint.insert(pat);
            }
        }
    }

    vector<string> S(4);
    for (auto& s : S) cin >> s;

    // BFS
    queue<int> que;
    que.push((1 << 16) - 1);

    vector<int> dist(1 << 16, INF);
    dist[(1 << 16) - 1] = 0;

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        // 長方形領域と色を全探索
        for (auto pat : paint) {
            for (char c : string("RGB")) {
                int sv = v;
                for (int x = 0; x < 4; ++x) {
                    for (int y = 0; y < 4; ++y) {
                        if ((pat >> enc(x, y)) & 1) {
                            sv &= ~(1 << enc(x, y));
                            sv |= (S[x][y] != c) << enc(x, y);
                            // 一度bitを消してから、「同じか否か」で書き換える
                            // 同じなら0とする
                        }
                    }
                }

                if (dist[sv] == INF) {
                    dist[sv] = dist[v] + 1;
                    que.push(sv);
                }
            }
        }
    }

    cout << dist[0] << endl;
    return 0;
}



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

#define MAX ((int)100010)
#define DAD(x) ((x) >> 1)
#define LEFT(x) ((x) << 1)
#define RIGHT(x) ((x) << 1 | 1)
#define endl '\n'

using namespace std;

typedef long long ll;

ll num[ MAX ], tree[ MAX << 2 ], lazy[ MAX << 2 ];

void build(ll node, ll a, ll b){
	if(a > b)
		return;
	if(a == b){
		tree[ node ] = num[ a ];
		return;
	}
	build(LEFT(node), a, DAD(a + b));
	build(RIGHT(node), DAD(a + b) + 1, b);
	tree[ node ] = tree[ LEFT(node) ] + tree[ RIGHT(node) ];
}

ll query(ll node, ll a, ll b, ll i, ll j){
	if(a > b || a > j || b<i)
		return 0;
	if(lazy[ node ]){
		tree[ node ] += lazy[ node ] * (b - a + 1);
		if(a != b){
			lazy[ LEFT(node) ] += lazy[ node ];
			lazy[ RIGHT(node) ] += lazy[ node ];
		}
		lazy[ node ] = 0;
	}
	if(a >= i && b <= j)
		return tree[ node ];
	return query(LEFT(node), a, DAD(a + b), i, j) + query(RIGHT(node), DAD(a+b) + 1, b, i, j);
}

void update(ll node, ll a, ll b, ll i, ll j, ll k){
	if(a > b)
		return;
	if(lazy[ node ]){
		tree[ node ] += lazy[ node ] * (b - a + 1);
		if(a != b){
			lazy[ LEFT(node) ] += lazy[ node ];
			lazy[ RIGHT(node) ] += lazy[ node ];
		}
		lazy[ node ] = 0;
	}
	if(a > b || a > j || b < i)
		return;
	if(a >= i && b <= j){
		tree[ node ] += k * (b - a + 1);
		if(a != b){
			lazy[ LEFT(node) ] += k;
			lazy[ RIGHT(node) ] += k;
		}
		return;
	}
	update(LEFT(node), a, DAD(a + b), i, j, k);
	update(RIGHT(node), DAD(a + b) + 1, b, i, j, k);
	tree[ node ] = tree[ LEFT(node) ] + tree[ RIGHT(node) ];
}

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

	int n, q, a, b, c, d;
	cin >> n >> q;
	n--;
	while(q--){
		cin >> a >> b >> c;
		if(!a){
			cin >> d;
			update(1, 0, n, --b, --c, d);
		}
		else
			cout << query(1, 0, n, --b, --c) << endl;
	}
	return 0;
}


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

int main(void) {
	using namespace std;
	int N, M, R;
	cin >> N >> M >> R;
	const long long INF = 0x100000000;
	long long d[200][200];
	fill(d[0], d[200], INF);
	vector<int> r;
	for(int i = 0; i < R; ++i) {
		int t;
		cin >> t;
		r.push_back(t - 1);
	}
	sort(r.begin(), r.end());
	for(int i = 0; i < M; ++i) {
		int A, B, C;
		cin >> A >> B >> C;
		d[A - 1][B - 1] = C;
		d[B - 1][A - 1] = C;
	}
	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]);
			}
		}
	}
	long long res = INF;
	do {
		long long s = 0;
		for(int i = 0; i < R - 1; ++i) {
			s += d[r[i]][r[i + 1]];
		}
		if(s < res) res = s;
	} while(next_permutation(r.begin(), r.end()));
	cout << res << '\n';
	return 0;
}



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

int main() {
  int n, cost=0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      cost += abs(a[i]);
    else
      cost += abs(a[i] - a[i - 1]);
  }
  cost += abs(a[n - 1]);
  for (int i = 0; i < n; i++) {
    int this_cost = cost;
    if (i == 0) {
      this_cost -= abs(a[i]) + abs(a[i] - a[i + 1]);
      this_cost += abs(a[i + 1]);
    }
    else if (i == n - 1) {
      this_cost -= abs(a[i] - a[i - 1]) + abs(a[i]);
      this_cost += abs(a[i - 1]);
    }
    else {
      this_cost -= abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1]);
      this_cost += abs(a[i + 1] - a[i - 1]);
    }
    cout << this_cost << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using static System.Math;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var s = ReadLine();
            bool f =true;
            long count = 0;
            long ans = 0;
            long right = 0;
   
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '<')
                {
                    if (f) count++;
                    else
                    {
                        ans -= Min(count, right);
                        count = 1;
                    }
                    
                    f = true;               
                }
                else
                {
                    if (f)
                    {
                        right = count;
                        count = 1;
                    }
                    else
                    {
                        count++;
                    }
                    f = false;
                }
                ans += count;
            }
            if(!f)ans-= Min(count, right);
            WriteLine(ans);
            


            Console.Out.Flush();
        }
    }
}




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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	int n,h,w;
	cin >> n >> h >> w;
	cout << (n-h+1) * (n-w+1) << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split());input();a,MAP,w1,h1=list(map(int,input().split())),[[0 for i in range(w)] for j in range(h)],0,0
for i,j in enumerate(a):
  for _ in range(j):
    if w1<w:
      MAP[h1][w1]= i+1
      w1+=1
      if w1==w:
        w1=0
        h1+=1
for i in range(h):
  if i%2!=0: MAP[i] = MAP[i][::-1]
[print(*i,sep=' ') for i in MAP]

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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define pb push_back
#define ll long long
const int maxn=2e5+10;
const int mod=1e9+7;
const double pi=-acos(-1);

int main()
{
    ll n;
    cin>>n;
    ll k=n/500;
    ll s=(n-k*500)/5;
    cout<<k*1000+s*5<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,l,r,ans;
int main(){
	scanf("%d",&n);
	fo(i,1,n){
		scanf("%d%d",&l,&r);
		ans+=r-l+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int n; cin >>n;
  string s; cin >>s;
  if (s.size() <= n){
    cout <<s;
  }else{
    for (int i=0; i<n; i++) cout <<s[i];
    cout <<"...";
  }
  cout <<"                           ";
  cout <<endl;
}


Measured memory_bytes: 3628
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = [0]*M
y = [0]*M
c = [0]*M
for i in range(M):
    x[i],y[i],c[i] = map(int, input().split())
ans = min(a)+min(b)
for i in range(M):
    ans=min(a[x[i]-1]+b[y[i]-1]-c[i],ans)
print(ans)

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

int main() {
	// your code goes here
	for (int i = 1;i<10;i++) {
		for (int j = 1; j<10;j++) {
			cout << i << "x" << j << "=" << (i*j) << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3068
h, w = gets.split.map &:to_i
mat = h.times.map { gets.chomp }

dp = h.times.map {[]}

dp[0][0] = 0

(w-1).times do |j|
  c = mat[0][j]
  dp[0][j+1] = [
    c == '.' && mat[0][j+1] == '#' ? dp[0][j] + 1 : dp[0][j]
    ].min
end

(h-1).times do |i|
  c = mat[i][0]
  dp[i+1][0] = [
    c == '.' && mat[i+1][0] == '#' ? dp[i][0] + 1 : dp[i][0]
    ].min
end

(1...h).each do |i|
  (1...w).each do |j|
    c = mat[i][j]
    dp[i][j] = [
      c == '#' && mat[i-1][j] == '.' ? dp[i-1][j] + 1 : dp[i-1][j],
      c == '#' && mat[i][j-1] == '.' ? dp[i][j-1] + 1 : dp[i][j-1]
      ].min
  end
end

cost = dp[h-1][w-1]
cost += 1 if mat[0][0] == '#'

p cost

Measured memory_bytes: 14324
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var S = Read();
            var black = 0;
            var white = 0;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == '.') white++;
            }
            var ans = white;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == '#')
                {
                    black++;
                }
                else
                {
                    white--;
                }
                if (black + white < ans) ans = black + white;
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt();
			System.out.println((a + b >= c) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 35808
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

int main()
{
    int n,t;
    cin >> n >> t;
    int a[n];
    rep(i,n) cin >> a[i];
    map<int,int> mp;
    vector<int> v(n);
    int tmp = a[0];
    rep(i,n){
        v[i] = a[i] - tmp;
        mp[v[i]]++;
        tmp = min(a[i],tmp);
    }
    sort(all(v));
    cout << mp[v[n-1]] << endl;
}

Measured memory_bytes: 5760
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= 1
ans = []
for _ in range(N):
    M = len(A)
    for i in range(M - 1, -1, -1):
        if A[i] > i:
            print(-1)
            exit()
        if A[i] == i:
            ans.append(A[i] + 1)
            A.pop(i)
            break
    if len(ans) == N:
        break
ans.reverse()
for a in ans:
    print(a)


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

using namespace std;

int n, q, t[200010];
vector < vector < int > > a;

void Dfs(int o, int pre)
{
    t[o] += t[pre];

    for (int i=0; i<=a[o].size()-1; i++)
        if (a[o][i] != pre) Dfs(a[o][i], o);
}

void Process()
{
    for (int i=1; i<=q; i++)
    {
        int x, val;     cin >> x >> val;
        x--;    t[x] += val;
    }

    Dfs(0, n);

    for (int i=1; i<=n; i++)
        cout << t[i-1] << " ";
}

void Input()
{
    ios_base::sync_with_stdio(0);   cin.tie(0);

    cin >> n >> q;      a.resize(n);

    for (int i=1; i<=n-1; i++)
    {
        int x, y;   cin >> x >> y;    x--;    y--;
        a[x].push_back(y);
        a[y].push_back(x);
    }
}

int main()
{
    Input();
    Process();
    return 0;
}


Measured memory_bytes: 23552