akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
using namespace std;

char convert(int x) {
  int x1 = x/10;
  int x2 = x-x1*10;
  if(x1 == 1) {
    if(x2 == 1) return 'a';
    if(x2 == 2) return 'b';
    if(x2 == 3) return 'c';
    if(x2 == 4) return 'd';
    if(x2 == 5) return 'e';
  }
  if(x1 == 2) {
    if(x2 == 1) return 'f';
    if(x2 == 2) return 'g';
    if(x2 == 3) return 'h';
    if(x2 == 4) return 'i';
    if(x2 == 5) return 'j';
  }
  if(x1 == 3) {
    if(x2 == 1) return 'k';
    if(x2 == 2) return 'l';
    if(x2 == 3) return 'm';
    if(x2 == 4) return 'n';
    if(x2 == 5) return 'o';
  }
  if(x1 == 4) {
    if(x2 == 1) return 'p';
    if(x2 == 2) return 'q';
    if(x2 == 3) return 'r';
    if(x2 == 4) return 's';
    if(x2 == 5) return 't';
  }
  if(x1 == 5) {
    if(x2 == 1) return 'u';
    if(x2 == 2) return 'v';
    if(x2 == 3) return 'w';
    if(x2 == 4) return 'x';
    if(x2 == 5) return 'y';
  }
  if(x1 == 6) {
    if(x2 == 1) return 'z';
    if(x2 == 2) return '.';
    if(x2 == 3) return '?';
    if(x2 == 4) return '!';
    if(x2 == 5) return ' ';
  }
  return '1';
}

int main() {
  string str;
  bool r;
  char ans[200];
  while(cin >> str) {
    if(str.size() % 2 == 1) {
      cout << "NA" << endl;
    }
    else {
      int j=0;
      r = true;
      for(unsigned int i=0;i<str.size();i+=2) {
	int x = atoi(str.substr(i,2).c_str());
	ans[j] = convert(x);
	j++;
	if(convert(x) == '1') {
	  r=false;
	}
      }
      if(r) {
	ans[j] = '\0';
	cout << ans << endl;
      }
      else {
	cout << "NA" << endl;
      }
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
	}
	long long S = 0;
	for (int i = 0; i < N; i++){
		S += A[i];
	}
	vector<long long> f;
	for (int i = 1; (long long) i * i <= S; i++){
		if (S % i == 0){
			f.push_back(i);
			if ((long long) i * i < S){
				f.push_back(S / i);
			}
		}
	}
	long long ans = 0;
	for (long long x : f){
		vector<long long> r(N);
		for (int i = 0; i < N; i++){
			r[i] = A[i] % x;
		}
		sort(r.rbegin(), r.rend());
		long long sum = 0;
		for (int i = 0; i < N; i++){
			sum += r[i];
		}
		long long cnt = 0;
		for (int i = sum / x; i < N; i++){
			cnt += r[i];
		}
		if (cnt <= K){
			ans = max(ans, x);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    ll n, x, m;
    cin >> n >> x >> m;
    pair<int, ll> dp[m + 1][41];
    fill(dp[0], dp[m + 1], pair<int, ll>(0, 0));
    for (int i = 0; i <= m; i++) {
        dp[i][0].first = ((ll)i * i) % m;
        dp[i][0].second = ((ll)i * i) % m;
    }
    for (int i = 0; i < 40; i++) {
        for (int j = 0; j <= m; j++) {
            dp[j][i + 1].first = dp[dp[j][i].first][i].first;
            dp[j][i + 1].second =
                dp[j][i].second + dp[dp[j][i].first][i].second;
        }
    }
    int cur = x;
    ll ans = x;
    for (int i = 40; i >= 0; i--) {
        if (n >= (1LL << i)) {
            ans += dp[cur][i].second;
            cur = dp[cur][i].first;
            n -= (1LL << i);
        }
    }
    cout << ans - cur << endl;
    return 0;
}

Measured memory_bytes: 67632
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        int a,b,k;
        cin >> a >> b >> k;
        int i,j;
        int m=max(a,b);
        vector<int>v;
        for(i=1; i<=m; i++){
            if(a%i==0 && b%i==0){
                v.pb(i);
            }
        }
        sort(v.rbegin(),v.rend());
        cout << v[k-1];
        
        

}


Measured memory_bytes: 256
#include<math.h>
#include<stdio.h>
int main()
{
int a[10001]={0};int i=1;
while(i<10002){
    scanf("%d",&a[i]);if(a[i]==0)break ;
    i=i+1;
}
i=1;
while(a[i]!=0){printf("Case %d: %d\n",i,a[i]);i=i+1;}
return 0;
}





Measured memory_bytes: 2616
import java.util.*;
import static java.lang.Math.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        String s = sc.next();
        String t = sc.next();

        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != t.charAt(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 41044
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	//freopen("input.txt","r",stdin);
	int a,b;
	string s,str,c;
	cin >> s >> str;
	cin >> a >> b;
	cin >> c;
	if(s==c){
		cout << a-1 << " " << b << endl;
	}
	else if (s!=c){
		cout << a << " " <<  b-1 << endl;
	
	}
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        string str = Console.ReadLine();
        int a = str.Length - 1;
        if (str[a] == '3')
        {
            Console.WriteLine("bon");
        }
        else if (str[a] == '0' || str[a] == '1' || str[a] == '6' | str[a] == '8')
        {
            Console.WriteLine("pon");
        }
        else
        {
            Console.WriteLine("hon");
        }
    }
}

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

if 0 in a:
    print(0)
else:
    ans = 1
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            exit()
    if ans > 1000000000000000000:
        print(-1)
    else:
        print(ans)


Measured memory_bytes: 21656
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    int i;
    for (i = s.size() - t.size(); i >= 0; i--) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i+j] != '?' && s[i+j] != t[j])
                goto Continue;
        }
        break;
    Continue:;
    }

    if (i < 0) {
        cout << "UNRESTORABLE\n";
        return 0;
    }

    s.replace(i, t.size(), t);
    replace(s.begin(), s.end(), '?', 'a');

    cout << s << endl;

    return 0;
}

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

int main(){
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  vector<int64_t> sub(N-1);
  for(int i=0; i<N-1; i++){
    sub.at(i) = vec.at(i) + vec.at(i+1);
  }
  
  int64_t ans = 0;
  for(int i=0; i<N-2; i++){
    if(sub.at(i) > M){
      int64_t x = sub.at(i) - M;
      sub.at(i) -= x;
      sub.at(i+1) -= x;
      if(sub.at(i+1) < vec.at(i+2)){
        sub.at(i+1) = vec.at(i+2);
      }
      ans += x;
    }
  }
  if(sub.at(N-2) > M){
    int64_t y = sub.at(N-2) - M;
    ans += y;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

ans = 0
while sum(A) > 0:
    ans += 1
    flag = False
    for i in range(N):
        if A[i] > 0:
            A[i] -= 1
            flag = True
        elif flag is True:
            break
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main()
{
int A,B,C,K;
int k=0;
int S=0;
cin >>A>>B>>C>>K;
for(int a=1;a<=A;a++){
S++;
k++;
if(k==K){
break;
}
}
if(k!=K){
for(int b=1;b<=B;b++){
k++;
if(k==K){
break;
}
}
}

if(k!=K){
for(int c=1;c<=C;c++){
S=S-1;
k++;
if(k==K){
break;
}
}
}
std::cout<<S<<std::endl;

return 0;
}

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

bool isinfield(int h, int w, int i, int j) {
    return (0 <= i && i < h) && (0 <= j && j < w);
}

int bfs(int i, int j, int h, int w, vector<vector<bool>> wall) {
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    dist[i][j] = 0;
    que.push(make_pair(i, j));
    while (!que.empty()) {
        pair<int, int> p = que.front();
        //cout << "p:=" << p.first << " " << p.second << endl;
        que.pop();
        if (isinfield(h, w, p.first - 1, p.second) && wall[p.first - 1][p.second] != true && dist[p.first - 1][p.second] == -1) {
            dist[p.first - 1][p.second] = dist[p.first][p.second] + 1;
            que.push(make_pair(p.first - 1, p.second));
            //cout << "add queue " << p.first - 1 << " " << p.second << endl;
        }
        if (isinfield(h, w, p.first, p.second - 1) && wall[p.first][p.second - 1] != true && dist[p.first][p.second - 1] == -1) {
            dist[p.first][p.second - 1] = dist[p.first][p.second] + 1;
            que.push(make_pair(p.first, p.second - 1));
            //cout << "add queue " << p.first << " " << p.second - 1 << endl;
        }
        if (isinfield(h, w, p.first + 1, p.second) && wall[p.first + 1][p.second] != true && dist[p.first + 1][p.second] == -1) {
            dist[p.first + 1][p.second] = dist[p.first][p.second] + 1;
            que.push(make_pair(p.first + 1, p.second));
            //cout << "add queue " << p.first + 1 << " " << p.second << endl;
        }
        if (isinfield(h, w, p.first, p.second + 1) && wall[p.first][p.second + 1] != true && dist[p.first][p.second + 1] == -1) {
            dist[p.first][p.second + 1] = dist[p.first][p.second] + 1;
            que.push(make_pair(p.first, p.second + 1));
            //cout << "add queue " << p.first << " " << p.second + 1 << endl;
        }
        //rep (i, h) {
        //    rep (j, w) {
        //        printf("%3d", dist[i][j]);
        //    }
        //    cout << endl;
        //}
        //cout << endl;
    }
    int max_dist = 0;
    rep (i, h) {
        rep (j, w) {
            max_dist = max(max_dist, dist[i][j]);
        }
    }
    //cout << endl;
    return max_dist;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> maze_wall(h, vector<bool>(w));
    char wall;
    rep(i, h) {
        rep(j, w) {
            cin >> wall;
            if (wall == '#') maze_wall.at(i).at(j) = true;
            else maze_wall.at(i).at(j) = false;
        }
    }
    int max_route = 0;
    rep (i, h) {
        rep (j, w) {
            if (maze_wall[i][j] == false) max_route = max(max_route, bfs(i, j, h, w, maze_wall));
        }
    }
    cout << max_route << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    ll n; cin >> n;
    vector<ll> a(n);
    deque<ll> deq;
    for (int i = 0; i < n;i++) {
        cin >> a[i];
        if(i %2 == 0)deq.push_back(a[i]);
        else deq.push_front(a[i]);
    }
    if (n % 2 != 0) {
        for (auto it = deq.rbegin(); it != deq.rend();it++) {
            cout << *it << " ";
        }
        cout << endl;
    }
    else {
        for (auto it = deq.begin();it != deq.end();it++) {
            cout << *it << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 5376
#include<stdio.h>
int main(){
  int n=0,i=0,j=0;
  int R[200000];
  int max=0,min=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
  max=-1000000000;
  min=R[0];
  for(j=1;j<n;j++){
      if(max<R[j]-min)max=R[j]-min;
      if(min>R[j])min=R[j];
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2548
def C_Takahashis_Information():
    a,b,c= map(int, input().split())
    d,e,f= map(int, input().split())
    g,h,i= map(int, input().split())
    if (a+e==b+d) and (b+f==c+e) and (d+h==e+g) and (e+i==f+h):
        print('Yes')
    else:
        print('No')
    
C_Takahashis_Information()

Measured memory_bytes: 3060
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let s = it.next().unwrap();
    let c: std::collections::HashSet<_> = s.chars().collect();
    if c.len() == 1 {
        println!("{}", "No");
    } else {
        println!("{}", "Yes");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	for(int i=0;i<=n;i+=7)
		if((n-i)%4==0){
			cout<<"Yes"<<endl;
			return 0;
		} 
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>

using namespace std;

int main() {
  int counts[26] = {};
  while (true) {
    string line;
    getline(cin, line);
    if (line.size() == 0) {
      break;
    }
    for (char c : line) {
      int i;
      if ('A' <= c && c <= 'Z') {
        i = c - 'A';
      } else if ('a'<= c && c <= 'z') {
        i = c - 'a';
      } else {
        continue;
      }
      counts[i] += 1;
    }
  }

  for (int i = 0; i < 26; ++i) {
    cout << char('a' + i) << " : " << counts[i] << endl;
  }
}

Measured memory_bytes: 3156
a,b,c,k = map(int,input().split())
#l = [1 for i in range(a)] + [0 for i in range(b)] + [-1 for i in range(c)]
#ans = sum(l[:k])
if k <= a:
    ans = k
elif (a < k) & (k <= a + b):
    ans = a
elif (a + b < k) & (k <= a + b + c):
    ans = a - (k - (a + b))

print(ans)

Measured memory_bytes: 9120
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll n;
	cin >> n;
	vll p(n);
	rep(i, 0, n) {
		cin >> p[i];
	}
	ll ans = 0;
	rep(i, 0, n - 2) {
		if ((p[i]<p[i+1]&&p[i+1]<p[i+2])||p[i]>p[i+1]&&p[i+1]>p[i+2]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;

}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    vi dp ( 3 ) ;
    for ( int i=0 ; i < 3 ; i ++ )
        cin >> dp[i] ;

    int a , b , c ;

    for ( int i = 1 ; i < n ; i ++ )
    {
        cin >> a >> b >> c ;

        a += max ( dp[2] , dp[1] ) ;
        b += max ( dp[0] , dp[2] ) ;
        c += max ( dp[0] , dp[1] ) ;

        dp[0] = a ; dp[1] = b ; dp[2] = c ;
    }

    int ans = max ( { dp[0] , dp[1] , dp[2] } ) ;
    cout << ans << "\n" ;

}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  bool flag;
 
  cin >> s;
 
  sort(s.begin(),s.end());
 
  flag = (s[0]==s[1])&(s[1]!=s[2])&(s[2]==s[3]);
 
  cout << (flag?"Yes":"No") << endl;
 
  return 0;
}

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

using namespace std;

struct Line {
    int h, p, q;
    bool operator<(const Line &r) const {
        return h > r.h;
    }
};

int main() {

    int n, m, a;

    while(cin >> n >> m >> a, n | m | a) {

        int amida[n];
        Line line[m];

        for(int i = 0; i < n; ++i) {
            amida[i] = i + 1;
        }

        for(int i = 0; i < m; ++i) {
            cin >> line[i].h >> line[i].p >> line[i].q;
        }

        sort(line, line + m);

        for(int i = 0; i < m; ++i) {
            swap(amida[line[i].p - 1], amida[line[i].q - 1]);
        }

        for(int i = 0; i < n; ++i) {
            if(amida[i] == a) {
                cout << i + 1 << endl;
                break;
            }
        }

    }

}

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

using namespace std;

int main() {
	int K;
	string S;
	cin >> K;
	cin >> S;
	if (S.length() > K) {
		cout << S.substr(0, K) <<"..."<< endl;
	}
	else {
		cout << S << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){

  double n,h,w,i;
  double BMI;

  while( cin >> n , n ){

    double risou = 9999999;
    int num = 9999999;

    for( int j = 0 ; j < n ; j++ ){
      cin >> i >> h >> w;

      BMI = w / pow( h/100 , 2 );

      if( abs(22 - BMI) <= abs(22 - risou) ){
	if( abs(22 - BMI) == abs(22 - risou) ){
	  if( i < num ) num = i;
	  continue;
	}
	risou = BMI;
	num = i;
      }
    }
    cout << num << endl;

  }
  return 0;
}

Measured memory_bytes: 1220
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
roads = []
for i in range(m):
    a,b = map(int,input().split())
    roads.append([a,b])
#print(roads)
terrace = [1] * n
for road in roads:
    if h_list[road[0]-1] > h_list[road[1]-1]:
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] == h_list[road[1]-1]:
        terrace[road[0]-1] = 0
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] < h_list[road[1]-1]:
        terrace[road[0]-1] = 0
print(terrace.count(1))

Measured memory_bytes: 28956
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


int main(){
    int K;
    ll A[110000],a,minans=2,maxans=2;
    cin>>K;
    for(int i=0;i<K;i++) cin>>A[i];

    for(int i=K-1;i>=0;i--){
        a=A[i];
        if(minans%a==0 || a-minans%a<=maxans-minans){
            if(minans%a==0) ;
            else minans+=(a-minans%a);
            maxans=(maxans-maxans%a)+a-1;
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<minans<<" "<<maxans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define F first
#define S second

using namespace std;

typedef long long ll;

ll n;
string s;
ll a[1000005], b[1000005];
ll x, y;
vector<pair<ll, ll> > va, vb;

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        cin>>s;
        ll now = 0, mx = 0, mn = 0;
        for(ll j = 0; j < s.size(); j++)
        {
            if(s[j] == '(') now++;
            else now--;
            mx = max(mx, now);
            mn = min(mn, now);
        }
        a[i] = max(-mn, 0LL);
        b[i] = now + a[i];
        if(a[i] == 0) x += b[i];
        else if(b[i] == 0) y += a[i];
        else if(now > 0) va.push_back(make_pair(a[i], now));
        else vb.push_back(make_pair(b[i], -now));
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    for(ll i = 0; i < va.size(); i++)
    {
        if(va[i].F <= x)
        {
            x += va[i].S;
        }
        else
        {
            printf("No\n");
            return 0;
        }
    }
    for(ll i = 0; i < vb.size(); i++)
    {
        if(vb[i].F <= y)
        {
            y += vb[i].S;
        }
        else
        {
            printf("No\n");
            return 0;
        }
    }
    if(x != y)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 19236
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a<b && b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26264
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i, a, n, step) for (int (i) = (a); (i) < (int)(n); (i) += (step))
#define ROF(i, a, n, step) for (int (i) = (a); (i) >= (int)(n); (i) += (step))
#define FOREACH(it, v) for (auto (it) : (v))
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll ;
typedef long double ld;
typedef pair <int, int> pii;
 
template <class T>
const bool is_impar(const T &x) {return (bool) (x & 1);}
 
int a, b, c;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b >> c;
    if (a > b)
        swap(a, b);
    if (a > c)
        swap(a, c);
    if (b > c)
        swap(b, c);
    cout << b - a + c - b << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 45
long long fib(int);
int f[MAX];
int main(){
  int n;

  

  scanf("%d",&n);
  printf("%lld\n",fib(n));

  return 0;
}

long long fib(int x){
  int i;
  f[0]=1;
  f[1]=1;
  for(i=2;i<=x;i++) f[i]=f[i-2]+f[i-1];
  return f[x];
}



Measured memory_bytes: 2036
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    const long long INF = 100000000LL * 100000000LL;
    long long X;
    long long K;
    long long D;
    long long ans = INF;

    cin >> X >> K >> D;
    long long maxMove = min(abs(X/D), K);
    K -= maxMove;
    // cout << "MAXMOVE " << maxMove << " " << K << endl;

    if (X < 0) {
        X += maxMove*D;

        if (K%2 != 0) {
            ans = abs(X+D);
        } else {
            ans = abs(X);

            if (K >= 2) {
                ans = min(ans, abs(X+2*D));
            }
        }
    } else {
        X -= maxMove*D;

        if (K%2 != 0) {
            ans = abs(X-D);
        } else {
            ans = abs(X);

            if (K >= 2) {
                ans = min(ans, abs(X-2*D));
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  double w, h, x, y;
  cin >> w >> h >> x >> y;

  cout << fixed << setprecision(6) <<  w*h/2 << " "; 
  cout << (w==2*x && h==2*y ? 1 : 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,k;
long double p[200001];
long double ans;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n){
		long double q;
		cin>>q; 
		p[i]=(q+1.00)/2.00;
		p[i]*=100.00;
	}
	long double ans1=0.00;
	rep(i,k)
	ans1+=p[i];
	ans=ans1;
	for(int i=1;i<=n-k;i++){
		ans1-=p[i-1];
		ans1+=p[i+k-1];
		ans=max(ans,ans1);
	}
	cout<<fixed<<setprecision(7)<<ans/100.00;
	re 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

struct restaurant {
  string city_name;
  int point;
  int number;
};


int main(){
    int N;
    int p;
    string name;
    vector<restaurant> restaurants;
    scanf("%d", &N);
    for(int i=0 ; i<N ; i++){
        cin >> name >> p;
        restaurants.push_back({name, p, i+1});
    }

    sort(restaurants.begin(), restaurants.end(), 
     [](const restaurant& x, const restaurant& y) { return (x.city_name < y.city_name) || (x.city_name == y.city_name && x.point > y.point);});
    
    for (vector<restaurant>::iterator itr = restaurants.begin(); itr != restaurants.end() ; itr++ )
    {
        printf("%d\r\n", itr -> number);
        fflush(stdout);
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
	cout<<(n+1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
R,C,K = map(int, input().split())
a = [[0] * (C+1) for i in range(R+1)]
dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]
for i in range(K):
  r,c,v = map(int, input().split())
  a[r-1][c-1] = v

for i in range(R):
  for j in range(C):
    for k in range(2, -1, -1):
      dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j]+a[i][j])
    for k in range(4):
      dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
      dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])

    
ans = 0
for k in range(4):
  ans = max(ans, dp[k][R-1][C-1])
print(ans)


Measured memory_bytes: 430108
fun main(arg:Array<String>){
  var (a,b) = readLine()!!.split(" ").map(String::toInt)
  var num = 0
  for(i in 0..1){
    if(a > b){
      num += a
      a--
    }else{
      num += b
      b--
    }
  }
  println(num)
}

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

a_b_c_list = []

for i in range(N):
    a_b_c_list.append(list(map(int, input().split())))

dp = [[0 for i in range(3)] for j in range(100010)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            if dp[i+1][k] < dp[i][j] + a_b_c_list[i][k]:
                dp[i+1][k] = dp[i][j] + a_b_c_list[i][k]

print(max(dp[N]))

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

int main() {
  int L, R, d; cin >> L >> R >> d;
  int c = 0;
  rep(i,R-L+1) {
    if ((i+L)%d==0) c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n,done=0,doen=0;
    scanf("%d",&n);
    long long sum=1;
    while(n--)
    {
        long long t;
        scanf("%lld",&t);
        if(t==0)
            done=1;
         else if(sum>1000000000000000000/t)
         doen=1;
         else if(doen==0)
            sum*=t;

    }
    if(done)
        printf("0\n");
    else if(doen)
        printf("-1\n");
    else printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 2152
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<ll> fact,inv;

ll f(ll a,ll b, ll p)  // a^b mod pを求める
{
	if (b == 0)
	{
		return 1;
	}else if (b % 2 == 0)
	{
		ll d = f(a,b/2,p);  //a^b = a^(2k) = (a^k)^2  k = b / 2
		return d * d % mod;
	}else
	{
		return a * f(a,b-1,p) % mod;
	}
}

void init(ll n)
{
	fact.resize(n+1,1);
	inv.resize(n+1,1);

	for(int i = 2; i <= n; i++)  //　nまでの階乗を求める
	{
		fact[i] = fact[i-1] * i % mod;
	}
	for(int i = 2; i <= n; i++)  //a^(-1) mod p = a^(p-2) mod p  ここをもう少し早くできるぽい
	{
		inv[i] = f(fact[i],mod-2,mod) % mod;
	}
}

ll comb(ll n,ll k)  //n_C_k
{
	if (n < k)
	{
		return 0;
	}
	return (fact[n] * inv[k] % mod) * inv[n-k] % mod;
}

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

	init(n*m+10);
	ll ans = 0;

	for (int d = 1; d < m; d++){
		ans += d*(m-d)%mod*(n*n)%mod*comb(m*n-2,k-2);
		ans %= mod;
	}
	for (int d = 1; d < n; d++){
		ans += d*(n-d)%mod*(m*m)%mod*comb(m*n-2,k-2);
		ans %= mod;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3328
import sys

n = int(raw_input())
t = 0
d = 0
min_b = -1
for i in range(n):
  a, b = map(int, raw_input().split())
  t += a
  if a < b:
    d += b - a
  elif a > b:
    if min_b == -1 or min_b > b:
      min_b = b
if d == 0:
  print 0 
else:
  print t - min_b

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

int main(int argc, char *argv[])
{
  int x,y,w[1000];
  cin >> x >> y;

  for(int i=0; i<x; i++)
    cin >> w[i];

  int num=x;
  while(num%y)
    num += x;

  int sum = 0;
  int max=0;
  int min=0;

  for(int i=0; i<num; i++){
    int ind = i%x;

    if(w[max]<w[ind])
      max=ind;
    else if(w[min]>w[ind])
      min=ind;
    
    if(i%y == y-1){
      sum += w[max]-w[min];
      max = ind+1;
      min = max;
    }

  }
  cout << sum<< "\n";
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=110000;

ll x[N];

int main() {
    ll i, n, m=0, s=0;
    scanf("%lld", &n);
    for(i=0; i<n; i++)
        scanf("%lld", &x[i]);
    sort(x, x+n);
    for(i=0; i<n; i++) {
        if(2*s<x[i]) m=i;
        s+=x[i];
    }
    printf("%lld\n", n-m);
    return 0;
}

Measured memory_bytes: 1024
a_list = []
check_list = []
for i in range(3):
    a_list.extend(list(map(int, input().split())))
    check_list.extend([False, False, False])

n = int(input())

for i in range(n):
    b = int(input())
    if b in a_list:
        place = a_list.index(b)
        check_list[place] = True

bingo = False
while True:
    for i in range(3):
        if check_list[i*3] and check_list[i*3+1] and check_list[i*3+2]:
            bingo = True
            break
        if check_list[i] and check_list[i+3] and check_list[i+6]:
            bingo = True
            break
    if check_list[0] and check_list[4] and check_list[8]:
        bingo = True
        break
    if check_list[2] and check_list[4] and check_list[6]:
        bingo = True
        break
    break

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



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll= long long;
using ld= long double;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vvl= vector<vector<ll>>;
using vvd= vector<vector<ld>>;
using vvs= vector<vector<string>>;
using vvb= vector<vector<bool>>;
using pll= pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

template <class T>
inline void chmin(T &a, T b) {
    if(a > b) { a= b; }
}

template <class T>
inline void chmax(T &a, T b) {
    if(a < b) { a= b; }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll N,M;
    cin >> N >> M;
    vl A(N);
    vl B(M);
    REP(i,N)cin >> A[i];
    REP(i,M)cin >> B[i];
    vl C = convolution(A,B);
    REP(i,C.size())cout << C[i] << (i == C.size()-1 ? "\n": " ");
}

Measured memory_bytes: 27300
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  if (n <= k) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) << "..." << endl;
  }
  return 0;
}

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

typedef long long LL;
const int B = 12;

LL dp[B][2][2], ans;
int d[B * 2];
void solve(int b) {
	std::memset(dp, 0, sizeof dp);
	int p = b + 1 >> 1; dp[0][0][0] = 1;
	for (int i = 0; i < p; ++i) {
		for (int j = 0; j < 2; ++j)
			for (int k = 0; k < 2; ++k) if (LL v = dp[i][j][k]) {
				for (int x = 0; x <= 9; ++x) {
					int l = x + d[i] + j, _j = 0, _k = 0;
					if (l >= 10) _j = 1, l -= 10;
					if (!i && !l) continue;
					_k = x + k * 10 - l - d[b - i];
					if (_k == 0 || _k == 1) dp[i + 1][_j][_k] += v;
				}
			}
	}
	if (b & 1) ans += dp[p][0][0] + dp[p][1][1];
	else {
		for (int j = 0; j < 2; ++j)
			for (int k = 0; k < 2; ++k)
				if (d[p] + j == k * 10) ans += dp[p][j][k] * 10;
	}
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	int _d, tot = -1; std::cin >> _d;
	while (_d) d[++tot] = _d % 10, _d /= 10;
	for (int b = tot; b <= tot * 2 + 2; ++b) solve(b);
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A = input()

if A == "1":
    print("Hello World")
else:
    X = int(input())
    Y = int(input())
    print(X + Y)

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

using namespace std;
typedef long long LL;

#define MAXN 200001
#define MOD 1000000007

int N;
int A[MAXN];

int main(int argc, char** argv) {
#ifdef OJ	
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);

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

    if (A[0])  {
        cout << -1 << endl; return 0;
    }

    LL ans = 0;
    int ok = 1;
    for (int i = 1; i < N; i++) {
        int d = A[i] - A[i-1];
        if (d >= 2) {ok = 0; break;}

        if (d == 1) ans++;
        else ans += A[i];
    }

    if (!ok) {
        cout << -1 << endl; return 0;
    }

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

Measured memory_bytes: 1024
#!/usr/bin/env python3


def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = 50
    dp = [[[0]*(N*X +1) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for j in range(1,N+1):
        for k in range(N+1):
            for s in range(N*X+1):
                if s >= x[j-1] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:# x[j]を選ぶと合計sにできない
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 91996
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;

#define BUFFNUM 1000000

//関数のプロトタイプ宣言
void insertionSort(int A[], int n, int g);//挿入ソート関数
int shellSort(int A[], int n); //シェルソート関数(挿入ソートを間隔gで行う

vector<int> G;
int cnt;

int main()
{
	int N, m;
	int A[BUFFNUM] = {};
	cnt = 0;

	cin >> N;

	for (int i = 0;i<N;i++)
	{
		cin >> A[i];
		//scanf_s("%d", &A[i]);
	}
	m = shellSort(A, N);

	cout << m << endl;	//数列Gの要素数m出力
	
	//数列Gの各要素を出力
	for (int i = m-1; i >= 0; i--)
	{
		if (i == 0)
		{
			cout << G[i] << endl;
		}
		else
		{
			cout << G[i] << " ";
		}
	}

	//cnt値表示
	cout << cnt << endl;

	//ソート後の配列出力
	for (int i = 0; i < N; i++)
	{
		cout << A[i] << endl;
	}

	return 0;
}

//挿入ソート関数
//要素数ｎの配列Aを、間隔int gだけ離れた要素についてだけソートを繰り返す。
void insertionSort(int A[], int n, int g)
{
	int v, j;

	for (int i = g; i < n; i++)
	{
		v = A[i];						//ソート用のバッファvに代入
		j = i - g;						//iより gだけ小さい要素 j

		while (j >= 0 && A[j] > v)		//挿入ソート。jが0以上、かつAのj番目の要素とi番目の要素が逆順のとき、順序入れ替え
		{
			A[j + g] = A[j];
			j = j - g;	
			cnt++;
		}
		A[j + g] = v;
	}
}

//シェルソート関数
//関数内で、ソート間隔指定用の数列G作成
int shellSort(int A[], int n)
{
	for (int h = 1;;)
	{
		if (h > n)	break;
		G.push_back(h);
		h = 3 * h + 1;
	}

	for (int i = G.size()-1 ; i >= 0 ; i--)
	{
		insertionSort(A, n, G[i]);
	}
	return G.size();
}

void trace(int A[], int N)
{
	cout << A[0];
	for (int i = 1;i < N;i++)
	{
		cout << " " << A[i];
	}
	cout << endl;
}


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

b=[0]*n
for i in range(n):
    b[i]=a[i]-(i+1)
b.sort()

#中央値
med = b[n//2]

res = 0
for i in range(n):
    res+=abs(b[i]-med)
print(res)

Measured memory_bytes: 88148
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
#define br "\n"
#define MAXIM 100003
ll mod = 1e9 + 7;


void solve(){
	ll n;
	cin >> n;
	string s;
	cin >>s;
	ll l = 0,r = n - 1;
	ll ans = 0;
	while(l < r){
		if(s[l] == 'R') l++;
		if(s[r] == 'W') r--;

		if(s[l] == 'W' && s[r] == 'R'){
			ans++;
			l++;
			r--;
		}

	}
	cout << ans;
}
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif  
	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int n,i;
 	cin>>n;
  	int a[n],b[n],c[n-1];
    for(i=0;i<n;i++)
      cin>>a[i];
    for(i=0;i<n;i++)
      cin>>b[i];
    for(i=0;i<n-1;i++)
      cin>>c[i];
    int ans=0;
  	for(i=0;i<n;i++){
        int ind=a[i]-1;
    	ans+=b[ind];
        if(i>=1)
        {
          if(a[i-1]+1==a[i])
               ans+=c[ind-1];
        }
    }
  cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll

const int MOD = 1e9 + 7;
inline int sum(int a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}

inline void add(int &a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
}

inline int mult(int a, int b) {
  return (a * 1ll * b) % MOD; 
}

const int N = 5010;
int dp[N][N], pw[N], kek[N];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  pw[0] = 1;
  for (int i = 1; i <= m; i++) {
    pw[i] = sum(pw[i - 1], pw[i - 1]);
  }
  for (int i = 0; i <= m; i++) {
    dp[i][0] = 1;
    for (int j = 1; j <= n; j++) {
      dp[i][j] = mult(dp[i][j - 1], i + 1);
      if (i >= 2) {
        kek[j] = sum(kek[j], kek[j]);
        add(kek[j], mult(dp[i - 1][j - 1], i - 1));
        add(dp[i][j], kek[j]);
      }
    }
  }
  cout << dp[m][n] << '\n';
} 

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


int main(){
	//入力機構
	unsigned long long k;
	std::string s;
	std::cin>>s>>k;//k<10^18,|s|<=100

	//処理機構
	//5000兆日後、1は1個だけ、2は2^50000000000個、3は……と増えていくが、2^(5*10^11)個の時点で10^18個を超える。
	//2^(5*10^11)=32^(10^11)>10^18
	//つまり、sを先頭から見ていって、初めて出てきた'1'以外の文字が5000兆日目のk番目の文字である。
	//k<|s|の時は注意
	const unsigned long long size=s.size();
	char ans='0';//暫定。'0'が出たら間違っている
	for(unsigned long long i=0;i<size;i++){
		if(i+1==k){
			//k番目に達したら、k番目の文字を取得する
			ans=s[i];
			break;
		}else if(s[i]!='1'){
			//1以外の文字を見つけたら、その文字がk文字目
			ans=s[i];
			break;
		}
	}

	//出力機構
	std::cout<<ans<<std::endl;

	return 0;
}


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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int h, w;
    cin >> h >> w;
    VI p(h);
    REP(i, h) {
        cin >> p[i];
    }
    VI q(w);
    REP(i, w) {
        cin >> q[i];
    }

    sort(ALL(p), greater<int>());
    sort(ALL(q), greater<int>());

    int i = 0, j = 0, ans = 0;
    while (i < h || j < w) {
        if (i < h  && j < w ) {
            if (p[i] > q[j]) {
                ans += p[i]*(j+1);
                i++;
            }else{
                ans += q[j]*(i+1);
                j++;
            }
        }else if(i < h){
            ans += p[i]*(j+1);
            i++;
        }else{
            ans += q[j]*(i+1);
            j++;
        }
    }

    cout << ans << ENDL;

    return 0;
}

Measured memory_bytes: 1920