akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <limits>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl


using namespace std;

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template<class T, class U>
ostream& operator<<(ostream& os, pair<T, U> const& p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
    int64_t gcd(int64_t u, int64_t v) {
        while (v != 0) {
            int64_t r = u % v;
            u = v;
            v = r;
        }
        return u;
    }
    int64_t lcm(int64_t m, int64_t n)
    {
        if ((0 == m) || (0 == n))
            return 0;

        return ((m / math::gcd(m, n)) * n);
    }
}

int main(void) {
    int A, B, C;
    cin >> A >> B >> C;

    cout << min(C, B / A) << endl;

    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Reversi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_C = 200000;
const int MOD = 1000000007;

/* typedef */

/* global variables */

int cs[MAX_N], nxts[MAX_N], ps[MAX_C], dp[MAX_N + 1];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

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

  for (int i = 0; i < n; i++) scanf("%d", cs + i), cs[i]--;

  memset(nxts, -1, sizeof(nxts));
  memset(ps, -1, sizeof(ps));

  for (int i = n - 1; i >= 0; i--) {
    int &pci = ps[cs[i]];
    if (pci >= 0) nxts[i] = pci;
    pci = i;
  }

  dp[0] = 1;

  for (int i = 0; i < n; i++) {
    addmod(dp[i + 1], dp[i]);
    if (nxts[i] > i + 1)
      addmod(dp[nxts[i]], dp[i]);
  }

  printf("%d\n", dp[n]);
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	char s[1010];
	int w,l,i;
	cin >> s;
	cin >> w;
	l = strlen(s);
	for(i=0;i<l;i+=w)
		cout << s[i];
	cout << endl;
	return 0;
}

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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> v(n), c(n);

  int p = 0;
  for (auto &i : v) {
    std::cin >> i;
  }

  for (auto &i : c) {
    std::cin >> i;
  }

  for (int i = 0; i < n; i++) {
    if (c[i] < v[i]) {
      p += v[i] - c[i];
    }
  }

  std::cout << p << std::endl;
  return 0;
}


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

#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

const int N = 200005;
int ar[2000][2];
int n;

int dp[20000];
int solve(int h){
    if (h <= 0) return 0;
    if (dp[h] != -1) return dp[h];
    int ans = solve(h - ar[0][0]) + ar[0][1];
    for (int i = 1; i < n; i++){
        ans = min(ans, solve(h - ar[i][0]) + ar[i][1]);
    }
    return dp[h] = ans;
}

integer main(){
    ios_base::sync_with_stdio(false);

    int h;
    cin >> h >> n;
    for (int i = 0; i < n ; i++){
        cin >> ar[i][0] >> ar[i][1];
    }
    memset(dp, -1, sizeof dp);
    cout << solve(h) << endl;
}


Measured memory_bytes: 896
#include <stdio.h>
 
int main(){
  long long int A,B,C,min;
  scanf("%lld %lld %lld",&A,&B,&C);
  if(A%2 && B%2 && C%2){
    min=A*B;
    if(A*C<min)min=A*C;
    if(C*B<min)min=C*B;
    printf("%lld\n",min);
  }else{
    printf("0\n");
  }
}

Measured memory_bytes: 128
'use strict';

const main = (input) => {
    const t = input.split('\n');
    const nx = t[0].split(' ');
    const xs = t[1].split(' ');
    const N = parseInt(nx[0], 10);
    const X = parseInt(nx[1], 10);

    // f(a) = (X - x(a)), 全てのxでf(a)がDの倍数となるような最大のDを求める、
    // 簡単のため X = 0 に座標系をずらす、最大公約数を求める問題となった
    const xk = {};
    let m = Math.pow(10, 10); // 最小値
    xs.forEach(v => {
        v = Math.abs(parseInt(v, 10) - X);
        if (v != 0) {
            xk[v] = true;
        }
        if (v < m) {
            m = v;
        }
    });
    const x = Object.keys(xk);
    // 最小公倍数は必ず最小値より小さい。
    let d = m;
    while (d != 1) {
        let r = x.every(v => {
            return (v % d) == 0;
        });
        if (r) {
            break;            
        }
        // 見つからなかった... m == d の時だけ 次は d/2 に飛ばす
        if (m == d) {
            d = Math.floor(d / 2);
        } else {
            d--;
        }
    }
    console.log(d);
};

const isTest = false;

if (isTest) {
    main('3 3\n1 7 11');
    main('3 81\n33 105 57')
    main('1 1\n1000000000')
} else {
    main(require('fs').readFileSync('/dev/stdin', 'utf8'));
}

Measured memory_bytes: 40016
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n,a,b;
    cin>>n>>a>>b;
    if(a==b)
    {
        cout<<"0"<<endl;
        return 0;
    }
    if(a>b)swap(a,b);
    int gap=(b-a)-1;
   if(gap%2==1)
   {
       cout<<(gap+1)/2<<endl;
       return 0;
   }
   int x,y,ses;
   int na,nb,tym;
   na=1;
   tym=a-na+1;
   nb=b-tym;
   gap=max(nb-na-1,0LL);
   x=((gap+1)/2)+tym;
   nb=n;
   tym=n-b+1;
   na=a+tym;
   gap=max(nb-na-1,0LL);
   y=((gap+1)/2)+tym;
   ses=min(x,y);
   cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  int k;
  int a,b;
  
  cin>>k>>a>>b;
  
  int _a=a%k;
  int _b=b%k;
  a=b-a;
  
  if(_a==0||_b==0||k<=_a+a)
  {
    cout<<"OK"<<endl;
  }
  else
  {
   	cout<<"NG"<<endl; 
  }

  return 0;
}

Measured memory_bytes: 3652
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

ll table[405][405];
int start(){
    REP(i,0,400){
        table[i][0] = (ll)1;
        REP(j,1,400) table[i][j] = (table[i][j-1] * (ll)i) % MOD;
    }
    REP(j,0,400) REP(i,1,400) (table[i][j] += table[i-1][j]) %= MOD;
    return 0;
}

pii dat[405];
ll cost[405][405];
ll dp[405][405];

int main(){
    start();
    // input
    int n,c; scanf("%d %d", &n, &c);
    REP(i,1,n) scanf("%d", &dat[i].fi);
    REP(i,1,n) scanf("%d", &dat[i].se);
    // get cost
    REP(i,1,n) REP(j,0,c){
        ll ret = table[dat[i].se][j] - table[dat[i].fi-1][j] + MOD;
        cost[i][j] = ret % MOD;
    }
    // dp
    REP(j,0,c) dp[0][j] = 0; dp[0][0] = 1;
    REP(i,1,n) REP(j,0,c){
        dp[i][j] = 0;
        REP(k,0,j) dp[i][j] += (cost[i][k] * dp[i-1][j-k]) % MOD;
        dp[i][j] %= MOD;
    }
    // print
    printf("%lld\n", dp[n][c]);
    return 0;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read(),sum=0,ans=inf,cur=0;
	vi a(n);REP(i,n)sum+=a[i]=read();
	REP(i,n-1){
		cur+=a[i];
		sum-=a[i];
		chmin(ans,abs(cur-sum));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
	char s;
	bool flag = true;
	cin >> s;
	char arr[5] = {'a', 'e', 'i', 'o', 'u'};
	for (int i = 0; i < 5; i++) {
		if (s == arr[i]) {
			cout << "vowel" << endl;
			flag = false;
			break;
		}
		
	}
	if (flag) {
		cout << "consonant" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(void){

  int A, B;     cin >> A >> B;
  int ans = (A + B < A - B) ? A - B : A + B;
  ans = (ans < A * B)? A * B : ans;

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
// E - Colorful Blocks
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int N,M,K;

#define MOD 998244353
#define MAX 200100 // [n+1] 1_origin
ll fac[MAX]; // 階乗 n!
ll inv[MAX]; // 逆元 1/n
ll finv[MAX]; // 逆元の階乗 (n^-1)! = (1/n)!

// n 個の配列に、mod p で前処理する
void init(int n){
	int p = MOD;
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rp(i,2,n+1){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}

// 組み合わせ nCr(mod m)
ll nCr(int n, int r){
	int m = MOD;
	if(n<r || n<0 || r<0) return 0;
	return fac[n] * (finv[n-r] * finv[r] % m) % m;
}

int main(){
	cin>>N>>M>>K;
	init(N); // combination init
	ll ans = 0;
	ll colors = M; // color allocation
	for(int p=N-1; p>=0; --p){ // p:[N-1,0] number of pairs
		if(p <= K){
			ll groups = nCr(N-1, p); // number divided into groups
			ll now = groups * colors % MOD;
			ans = (ans + now) % MOD;
		}
		colors = colors * (M-1) % MOD;
	}
	cout<< (ans + MOD) % MOD <<endl; // if negative
}


Measured memory_bytes: 8328
n = int(input())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]

pos = [None, None]


def fn(digits, maxlen, index, pos):
    for x in range(1, maxlen + 1):
        if x in digits:
            continue
        ndigits = digits + [x]
        if len(ndigits) < maxlen:
            index = fn(digits + [x], maxlen, index, pos)
        else:
            if ndigits == p:
                pos[0] = index
            if ndigits == q:
                pos[1] = index
            index = index + 1
            # print(f"{index}:" + " ".join(str(x) for x in ndigits))
    return index


fn([], n, 0, pos)
print(abs(pos[0] - pos[1]))


Measured memory_bytes: 9084
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> time(N);
    for (int i = 0; i < N; i++){
        int T;
        cin >> T;
        // 問題i <=> time.at(i-1)
        // 問題1 <=> time.at(0)
        time.at(i) = T;
    }

    int sum_of_time = 0;
    for (int i = 0; i < N; i++){
        sum_of_time += time.at(i);
    }

    int M;
    cin >> M;
    //ドリンクの番号と紐付け
    vector<vector<int>> time_in_drinking(M, vector<int>(2));
    for(int i = 0; i < M; i++){
        int P, X;
        cin >> P >> X;
        time_in_drinking.at(i) = {P, X};
    }

    for(int i = 0; i < M; i++){
        int result = sum_of_time - time.at(time_in_drinking.at(i).at(0) - 1) + time_in_drinking.at(i).at(1);
        cout << result << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

A,B = inpl()
print(max(A+B,A-B,A*B))


Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
    int n,m;
    cin >> n>> m;
    vector<vector<char>> A_field(n,vector<char>(n));
    vector<vector<char>> B_field(m,vector<char>(m));
    rep(i,0,n){
        string s;
        cin >> s;
        rep(j,0,n){
            A_field[i][j]=s[j];
        }
    }
    rep(i,0,m){
        string s;
        cin >> s;
        rep(j,0,m){
            B_field[i][j]=s[j];
        }
    }
    //cout<<B_field[0][0]<<endl;
    rep(i,0,n-m+1){
        rep(j,0,n-m+1){
            int check = 1;
            rep(k,0,m){
                rep(l,0,m){
                    if(A_field[i+k][j+l]!=B_field[k][l]){
                        check = 0;
                    }
                }
            }
            if(check){
                cout<<"Yes"<<endl;
                return 0;
            }
            
        }
    }
    cout<<"No"<<endl;
    

    return 0;
}


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

int main(){
  int n;
  while(cin>>n){
    long long c=1;
    if(n==0)c=0;
    else
      for(int i=n;i>0;i--)
	c*=i;
    cout<<c<<endl;

  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>

using namespace std;


int main()
{
    int N = 0;
    int W = 0;
    cin >> N >> W;
    vector<pair<int, int>> vws;
    int v = 0;
    int w = 0;
    for (int i = 0; i != N; ++i){
        cin >> v >> w;
        vws.emplace_back(v, w);
    }
    vector<int> dp(W + 1, 0);  // dp[w]: maximum value of items with total weight = w.
    for (auto vw : vws){
        tie(v, w) = vw;
        dp[w] = max(dp[w], v);
        for (int cum_w = w + 1; cum_w <= W; ++cum_w){
            if (dp[cum_w - w]) dp[cum_w] = max(dp[cum_w], dp[cum_w - w] + v);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 3144
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define MP make_pair
#define PB push_back
const int N=1e3+10;
int main(){
    int n,ans,d[N];
    pi temp;
    vector<pi> v;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        v.clear();
        ans=0;
        while(n--){
            scanf("%d%d",&temp.F,&temp.S);
            v.PB(temp);
        }
        scanf("%d",&n);
        while(n--){
            scanf("%d%d",&temp.F,&temp.S);
            v.PB(temp);
        }
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++){
            d[i]=1;
            for(int j=0;j<i;j++)if(v[i].F>v[j].F&&v[i].S>v[j].S)d[i]=max(d[i],d[j]+1);
            ans=max(ans,d[i]);
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 2616
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0 ; i<n1 ; i++) L[i] = A[left+i];
  for(i=0 ; i<n2 ; i++) R[i] = A[mid+i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left ; k<right ; k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;
  x = A[r];
  i=p-1;
  for(j=p ; j<r ; j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];
      A[i] = A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1] = A[r];
  A[r]= t;
  return i+1;
}

void quickSort(struct Card A[],int n, int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0 ; i<n ; i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0 ; i<n ; i++){
    if(A[i].suit != B[i].suit) stable = 0;
  }
  if(stable == 1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0 ; i<n ; i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;

    int L = S.length();
    
    int res = 0;
    REP(i, int(L/2)){
        if(S[i] != S[L-1-i]){
            res++;
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
 
 
int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  
  if(a.at(0)+a.at(1)==a.at(2))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
  int R,G,B,N,ct,r,g,b;
  cin >> R >> G >> B >> N;
  ct = 0;
  for(r=0;r*R<=N;r++){
    for(g=0;g*G<=N-r*R;g++){
      ct = ((N-r*R-g*G)%B==0) ? ct+1 : ct;
    }
  }
  cout << ct << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    if(N == 0){
        cout<<0<<endl;
        return 0;
    }
    vec ans(40,0);
    rep(i,20){
        N += (1LL << (i*2 + 1));
        ++ans[i*2 + 1];
    }
    rep(i,40){
        ans[i] ^= ((N >> i)&1);
    }
    bool print = false;
    rep(i,40){
        if(ans[39-i] == 1) print = true;
        if(print) cout<<ans[39-i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main()
{
    ll N, M;

    cin >> N >> M;

    if(N==1&&M==1) cout << 1 << endl;
    else if(N==1) cout << N*(M-2) << endl;
    else if(M==1) cout << (N-2)*M << endl;
    else cout << (N-2)*(M-2) << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    TIN(string, s);
    if (s == "SSS") cout << 0 << endl;
    else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR") cout << 1 << endl;
    else if (s == "RRS" || s == "SRR") cout << 2 << endl;
    else cout << 3 << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>

int main(void){
    int N;
    scanf("%d", &N);
    int *A = new int[N];
    long long int allsum = 0;
    for(int i = 0; i < N; i++){
        scanf("%d", (A+i));
        if(i > 0 && i < N){
            allsum += abs(A[i] - A[i-1]);
        }else if(i == 0){
            allsum += abs(A[0]);
        } 
    }
    allsum += abs(A[N-1]);

    for(int i = 0; i < N; i++){
        if(i > 0 && i < N-1){
            printf("%lld\n", allsum - abs(A[i]-A[i - 1]) -abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]));
        }else if(i == 0){
            printf("%lld\n", allsum - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]));
        }else if(i == N-1){
            printf("%lld\n", allsum - abs(A[N-1]) - abs(A[N-1] - A[N-2]) + abs(A[N-2]));
        }
    }
    delete[] A;
    return 0;
}

Measured memory_bytes: 1664
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


a, b, c, k = sp()
answer = min(a, k)
k -= min(a, k)
if k > 0:
    k -= min(b, k)
    if k > 0:
        answer -= k
out(answer)


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

int main(){
	int a, b;
	cin >> a >> b;

	if(a < b){
		cout << "a < b" << endl;
	}else if( b < a){
		cout << "a > b" << endl;
	}else{
		cout << "a == b" << endl;
	}

	return 0;
}

Measured memory_bytes: 3092
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int [] p = new int [n];
        for(int i=0;i<n;i++){
            p[i] = scan.nextInt();
        }
        int count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    }
    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s; cin>>s;
    int x = 0;
    for(int i=0;i<sz(s);i++) x+=s[i]-'0';
    if(x%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ====================================================================

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

  // aが左下、bが右上のイメージ
  vector<pair<int, int> > a(n), b(n);  // aは(y,x)だけどbは(x,y)にしてます（わかりづらい）
  for (int i = 0; i < n; i++) { cin >> a[i].second >> a[i].first; }
  for (int i = 0; i < n; i++) { cin >> b[i].first >> b[i].second; }
  sort(a.rbegin(), a.rend());  // 上にある順
  sort(b.begin(), b.end());    // 左にある順

  int ans = 0;  // ペアの数
  for (int i = 0; i < b.size(); i++) {
    vector<pair<int, int> > koho;
    for (int j = 0; j < a.size(); j++) {
      if (a[j].second < b[i].first && a[j].first < b[i].second) {
        koho.push_back(a[j]);  // ペア候補に追加
      }
    }
    sort(koho.rbegin(), koho.rend());  // 上にある順にする
    if (1 <= koho.size()) {
      ans++;
      a.erase(find(a.begin(), a.end(), koho[0]));
    }
  }

  cout << ans << endl;
}


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

namespace aziz
{
    class Program
    {
        static void Main(string[] args)
        {
          string S = Console.ReadLine().Trim();
          string T = Console.ReadLine().Trim();
          int result = 0;
          for(int i = 0; i < T.Length; i++)
          {
            if(T[i] != S[i]) result++;
          }
          Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 27248
using System;
using System.Linq;

namespace ABC120A{
	public class Program{
  		public static void Main(){
  			var ABC = Console.ReadLine().Split().Select(int.Parse).ToList();
          	if(ABC[1]>ABC[0]*ABC[2]){
            	Console.WriteLine(ABC[2]);
               	return;
            }else{
            	Console.WriteLine(ABC[1]/ABC[0]);
              	return;
            }
        }
	}
}

Measured memory_bytes: 11220
local n, p = io.read("*n", "*n", "*l")
local str = io.read()
if p == 2 then
  local ret = 0
  for i = n, 1, - 1 do
    local num = tonumber(str:sub(i, i))
    if num % 2 == 0 then
      ret = ret + i
    end
  end
  print(ret)
elseif p == 5 then
  local ret = 0
  for i = n, 1, - 1 do
    local num = tonumber(str:sub(i, i))
    if num % 5 == 0 then
      ret = ret + i
    end
  end
  print(ret)
else
  local t = {}
  for i = 1, p do
    t[i] = 0
  end
  t[1] = 1
  local mul = 1
  local cur = 0
  local ret = 0
  for i = n, 1, - 1 do
    local num = tonumber(str:sub(i, i))
    cur = (cur + mul * num) % p
    ret = ret + t[cur + 1]
    t[cur + 1] = t[cur + 1] + 1
    mul = (mul * 10) % p
  end
  print(ret)
end


Measured memory_bytes: 760
#![allow(dead_code)]
use std::io;
use std::f64;

fn main() {
    solve_c();
}

fn solve_c() {
    loop {
        let mut n = String::new();
        io::stdin().read_line(&mut n).unwrap();
        let n = n.trim().parse::<u32>().unwrap();
        if n == 0 {
            break;
        }

        let mut students = String::new();
        io::stdin().read_line(&mut students).unwrap();
        let students: Vec<_> = students
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<f64>().unwrap())
            .collect();
        let sum: f64 = students.iter().sum();
        let m = sum / n as f64;

        let mut pre_a = 0_f64;
        for s in students {
            pre_a += (s - m).powi(2);
        }
        println!("{:.4}", (pre_a / n as f64).sqrt());
    }
}



Measured memory_bytes: 5084
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,i=0,j,c=0,p,h[1000010];
    cin >> n;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            if(n==i*j)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;

}


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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  vector<ll> kosu(n+1);
  rep(i,n){
    cin>>a[i];
    kosu[a[i]]++;
  }
  
  ll kumi = 0;
  rep(i,n+1){
    kumi += kosu[i]*(kosu[i]-1)/2;
  }
  
  rep(i,n){
    cout << kumi - kosu[a[i]] +1 << endl;
  }
}



Measured memory_bytes: 4992
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int n,a,b,c;
int L[8];

int calc(int g, int p){
  int mp = 0;
  int s = 0;
  rep(i, 8){
    if (g&1){
      mp++;
      s += L[i];
    }
    g = g>>1;
  }
  int res = 10*(mp-1) + abs(s-p);
  return res;
}

int solve(){
  cin>>n>>a>>b>>c;
  rep(i, n) {cin>>L[i];}

  int ress = calc(3, 80);
  // dump(ress);
  // assert(calc(3, 80)==68);
  // dump(1&4);
  // assert((1&4)==0);

  int res = INF;
  rep(i, 1<<n){
    rep(j, 1<<n){
      rep(k, 1<<n){
        if (i==0 or j==0 or k==0) continue;
        int tmp = 0;
        if ((i&j)==0 && (j&k)==0 && (k&i)==0){
          tmp += calc(i, a);
          tmp += calc(j, b);
          tmp += calc(k, c);
          chmin(res, tmp);
        }
      }
    }
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 384
s = list(raw_input())
Q = input()
for q in range(Q):
  str_order = raw_input().split()
  a = int(str_order[1])
  b = int(str_order[2])
  if str_order[0] == 'print':
    print ''.join(s[a:b+1])
  elif str_order[0] == 'reverse':
    tmp = s[a:b+1]
    tmp.reverse()
    s[a:b+1] = tmp
  elif str_order[0] == 'replace':
    s[a:b+1] = list(str_order[3])

Measured memory_bytes: 6456
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#define LL long long
#define num 10000000
#define rep(i,n) for(i=0;i<(n);i++)
using namespace std;

int main(){
  
  LL N,i,H[num],pre;
  
  scanf("%lld",&N);
  rep(i,N){
    scanf("%lld",&H[i]);
  }
  //一番左側の値の定義
  pre=-1000;
  rep(i,N){
  	if(pre<=H[i]-1){
      pre=H[i]-1;
    }else if(pre<=H[i]){
      pre=H[i];
    }else{
      puts("No");
	 return 0;
    }
  }
  puts("Yes");
 
     return 0;
  
}


Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
static const int MAX_N=10e5;
struct P{int maxs,num;};
pair<int,int > A[MAX_N+100];
P B[MAX_N+100];
bool C[MAX_N+100];
stack <int>D;


int main(void){
	int N,K;
		cin >> N >> K;
	for(int i=0;i<MAX_N+100;i++)
		B[i].num=-1;
	for(int i=0;i<N;i++){
		int s,o;
			cin >> s >> o;
		s--;
		A[i].first=o*-1;
		A[i].second=i;
		if(B[s].maxs<o){
			B[s].maxs=o;
			B[s].num=i;
		}
	}
	for(int i=0;i<N;i++){
		if(B[i].num==-1)continue;
		C[B[i].num]=true;
	}
	sort(A,A+N);
	
	
	
	long long res=0,typer=0;
	for(int i=0;i<K;i++){
		res+=(long long)A[i].first*(-1);
		typer+=C[A[i].second];
		if(!C[A[i].second])
			D.push(A[i].first);
	}
	long long ans=res+(long long)typer*typer;
	for(int i=K;i<N && D.size();i++){
		if(C[A[i].second]){
			res-=D.top()*(-1);
			res+=(long long)A[i].first*(-1);
			D.pop();
			typer++;
			ans=max(ans,(long long)res+(long long)typer*typer);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9728
#include <stdio.h>
#include <math.h>

int main (void){
    int a,b,h,m;
    double angle,h_ang,m_ang;
    double ans;
    scanf("%d %d %d %d",&a,&b,&h,&m);
    h_ang = 2.0*M_PI*h/12.0 + 30.0/360.0*2.0*M_PI*m/60.0;
    m_ang = 2.0*M_PI*m/60.0;
    angle = fabs(h_ang-m_ang);
    if(angle > M_PI) angle = 2*M_PI - angle;
    ans = sqrt(a*a + b*b - 2*a*b*cos(angle));
    printf("%.10f",ans);
    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, A, B;
int main(){
	cin >> N >> A >> B;
	if(N == 1){
		if(A == B)	puts("1");
		else puts("0");
	}
	else if(N == 2)	puts("1");
	else{
		printf("%lld\n", max(0LL, 1 + B * (N - 2) - A * (N - 2)));
	}
	return 0;
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(1999999999999999)
b.append(1999999999999999)

o = 0
aa = 0
be = 0
for i in range(n+1):
    o += a[i]
    aa += 1
    if o > k:
        break
        
ans = aa-1
an = aa
cur = k - o
for i in range(aa):
    cur += a[aa-1-i]
    an -= 1
    
    for j in range(m+1):
        cur -= b[be]
        if cur < 0:
            cur += b[be]
            break
        an += 1
        be += 1
        
    ans = max(an,ans)
    
print(ans)

Measured memory_bytes: 110792
#include<cstdio>
#include<cstring>
using namespace std;

bool visit[26],g[26][26];

bool dfs(int v){
  visit[v] = true;
  bool f = false;
  for(int i=0;i<26;i++)
    if(g[v][i]){
      f = true;
      if(!visit[i])dfs(i);
    }
  return f;
}
 
int graph_num(void){
  int res = 0;
  for(int i=0;i<26;i++)
    if(!visit[i] && dfs(i))res++;
  return res;
}
  
int main(){
  int i,n,pre[26],suf[26],h,t;

  while(scanf("%d",&n) && n){
    for(i=0;i<26;i++){
      visit[i] = false;
      pre[i] = suf[i] = 0;
      for(int j=0;j<26;j++)g[i][j] = false;
    }
    
    for(i=0;i<n;i++){
      char s[40];
      scanf("%s",s);
      int len = strlen(s);
      h = s[0]-'a';
      t = s[len-1]-'a';
      
      pre[h]++;
      suf[t]++;
      g[h][t] = g[t][h] = true;
    }
  
    if(graph_num() != 1)printf("NG\n");
    else{
      for(i=0;i<26;i++)if(pre[i] != suf[i])break;
      
      if(i==26)printf("OK\n");
      else printf("NG\n");
    }
  }
}

Measured memory_bytes: 0
# coding: utf-8
def main():
    l = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    n = int(input())
    S = input()
    print_line = []
    for s in S:
        print_line.append(l[(l.index(s)+n)%26])
    print(''.join(print_line))

if __name__ == '__main__':
    main()


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

using namespace std;
int n;
int k;
int a[100001];
int d[100001];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        d[i]=INT_MAX;
    }
    d[1]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=min(i+k,n);j++)
        {
            d[j]=min(d[j],d[i]+abs(a[i]-a[j]));
        }
    }
    cout<<d[n];
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if(a+b==c+d) puts("Balanced");
  else if(a+b>c+d) puts("Left");
  else puts("Right");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
int b;
string s;
string t;
int main() {
	cin >> s >> t;
	int n = 0;
	if (t.size() > s.size()) {
		cout <<"UNRESTORABLE";
	return 0;
	}
	for (int i = 0; i <= s.size() - t.size(); i++) {
		for (int j = 0; j < t.size(); j++) {
			if (s[i + j] != t[j] && s[i + j] != '?') {
				break;
			}
			if (j == t.size() - 1) {
				b = 1;
				n = i;
			}
		}
	}
	if (b == 1) {
		for (int i = 0; i < n; i++) {
			cout << (s[i] == '?' ? 'a' : s[i]); 
		}
		cout << t;
		for (int i = n + t.size(); i < s.size(); i++) {
			cout << (s[i] == '?' ? 'a' : s[i]); 
		}
	}
	else cout <<"UNRESTORABLE";
	return 0;
}



Measured memory_bytes: 256
#https://qiita.com/sage-git/items/90c342fd2127ec39b874
import numpy as np
M=int(input())
P=200003
a=[int(i) for i in input().split()]
b=[0 for i in range(P)]
for i in range(M):
    b[a[i]]+=1
c=[0 for i in range(P-1)]
tmp=1
for i in range(P-1):
    c[i]=b[tmp]
    tmp=tmp*2
    tmp%=P
N = P-1
n0 = 2**int(np.ceil(np.log2(2*N - 1)))

A = np.zeros(n0)
B = np.zeros(n0)
for i in range(N):
    A[i],B[i]=c[i],c[i]

C = np.fft.ifft( np.fft.fft(A)*np.fft.fft(B) )

ret = [int(ci) for ci in np.real(C[:2*N - 1] + 0.5)]
ans=0
for k in range(2*N-1):
    ans+=ret[k]*pow(2,k,P)
for i in range(M):
    ans-=(a[i]*a[i])%P
print(ans//2)

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

#define fio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define tc(t) int t; cin >> t; while (t--)
#define for0(i, n)  for(int i = 0; i < n; i++)
#define pb push_back
#define int long long 

void solve()
{
  int a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  int d1 = abs(a-b);
  int d2 = (v-w)*t;
  cout<<(d1 <= d2 ? "YES" : "NO");
}

signed main() {

  fio;
  //tc(tt) {
    solve();
    cout<<"\n";
  //}
  
  return 0;
}

Measured memory_bytes: 3596
MOD = 1000000007


S = int(input())
Ans = 0

for i in range(1,S//3 +1):
    #iは数列の長さ
    #自由に割り振れるのはremain個
    remain = S - 3*i
    
    #長さiの数列で条件を満たすのはcomb(M+i-1,M)個
    num = 1
    for j in range(1,i):
        num = num*(remain+i-j)
        num = num//j
    num = num%MOD
    Ans = (Ans+num)%MOD

print(Ans)

Measured memory_bytes: 9036
#include <stdio.h>

int main(void) {

 int a,b;

 scanf("%d""%d",&a,&b);

 if (a<b){

  printf("a < b\n");

 }

 else if (a>b)

 {

  printf("a > b\n");

 }

 else{

  printf("a == b\n");

 }

 return 0;

}

Measured memory_bytes: 580
#include <iostream>

using namespace std;

int ar[1001];

int main() {
    for (int i=1;i<1001;i++)
    {
        for (int j=2;j<1001;j++)
        {
            int k = 1;
            bool t = true;
            int z = 1;
            while (z<=j)
            {
                k*=i;
                if (k >= 1001) {t=false; break; }
                z++;
            }
            if (t)
                ar[k] = 1;
        }
    }
    int x;
    cin >> x;
    while (x)
    {
        if (ar[x] == 1) return cout << x,0;
        x--;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  printf((n % 2 == 0) == (s[0] == s[n - 1]) ? "First\n" : "Second\n");
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;

void solve()
{
	vector<int> ans;
	while(true)
	{
		int a,b;
		char op;
		cin >> a >> op >> b;
		if(op =='+')ans.push_back(a+b);
		else if(op =='-')ans.push_back(a-b);
		else if(op =='*')ans.push_back(a*b);
		else if(op =='/')ans.push_back(a/b);
		else break;
	}
	rep(i,sz(ans))cout << ans[i] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  cout << (n % 2 == 0 ? n / 2 : n /2 + 1) << endl;
}


Measured memory_bytes: 256
import math

n = int(input())
s = list(map(int,input().split()))

b = c = 0
for i in s:
    b += i
    c += i**2

if b%n == 0:
    print(int(c-b**2/n))
else:
    koho1 = math.floor(b/n)
    koho2 = math.ceil(b/n)
    ans = min(n*(koho1**2)-2*b*koho1+c,n*(koho2**2)-2*b*koho2+c)
    print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
using namespace std;
long long gcd(long long a,long long b)
{
	if (b==0)
		return a;
	else
		return gcd(b,a%b);
}
int n;
long long a,b,u,v,t,hh;
int main()
{
	scanf("%d",&n);
	scanf("%lld%lld",&u,&v);
	t=gcd(u,v);
	a=u/t,b=v/t;
	for (int i=2;i<=n;i++)
	{
		scanf("%lld%lld",&u,&v);
		t=gcd(u,v);
		u/=t,v/=t;
		hh=max(b/v+(b%v!=0),a/u+(a%u!=0));
		b=hh*v,a=hh*u;
	}
	printf("%lld",a+b);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int>d(n);
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  cout << d[n/2]-d[n/2-1];
  return 0;
}

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


int main(void) {
    int h, w, uh, uw;
    cin >> h >> w;
    cin >> uh >> uw;

    int global = h * w;
    int selected = uh* w + h * uw - uh*uw;

    cout << global - selected << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
 
int main()
{
    int n;
 
    std::cin >> n;
 
    double x1,y1,x2,y2,x3,y3,xp,yp,r;
 
    for(int i=0;i<n;++i)
    {
        std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
 
        xp = 1.0*((x1*x1+y1*y1)*(y2-y3)+(x2*x2+y2*y2)*(y3-y1)+(x3*x3+y3*y3)*(y1-y2))/(2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)));
 
        yp = 1.0*((x1*x1+y1*y1)*(x2-x3)+(x2*x2+y2*y2)*(x3-x1)+(x3*x3+y3*y3)*(x1-x2))/(2*(y1*(x2-x3)+y2*(x3-x1)+y3*(x1-x2)));
 
        double a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
 
        double b = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
 
        double c = sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
 
        r = a*b*c/(sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c)));
 
        printf("%.3f %.3f %.3f\n",xp,yp,r) ;
    }
}

Measured memory_bytes: 1244