akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

#define MAX 100

int main(void) {
  char T[MAX], H[MAX];
  int n, result;
  int i = 0;
  int tp = 0, hp = 0;
  scanf("%d", &n);

  while(i++ < n) {
    scanf("%s %s", T, H);

    result = strcmp(T, H);

    if(result == 0) {
      tp++; hp++;
    }
    else if(result > 0) {
      tp += 3;
    }
    else if(result < 0) {
      hp += 3;
    }
  }

  printf("%d %d\n", tp, hp);

  return 0;
}



Measured memory_bytes: 2112
#include <stdio.h>
 
int main()
{
  long long int i,j,k,l;
  double A,B;
  A=0.0;
  B=0.0;
  scanf("%lf %lf",&A,&B);
  B *= 100.0;
  
  A *= B;
  A /= 100.0;
  i = (long long int)(A);
  
  printf("%lld\n",i);
    
  return 0; 
}

Measured memory_bytes: 1736
import java.io.*
import java.util.*

// コマの数, 座標の数
// all_vars ~ 10 ^ 5
fun solve(N: Int, M: Int, X: IntArray) {
    val x = X.sorted()
    if (N == 1) { println(x.last() - x.first()); return }
    if (N >= M) { println(0); return }
    val diff = mutableListOf<Int>()
    for (i in 1 until M) {
        diff.add(x[i] - x[i - 1])
    }
    diff.sortDescending()
    println(x.last() - x[0] - diff.slice(0 until N - 1).sum())
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val X = IntArray(M)
    for (i in 0 until M) {
        X[i] = sc.next().toInt()
    }
    solve(N, M, X)
}


Measured memory_bytes: 46740
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof (a))
#define endl '\n'
#define pb push_back
typedef long long ll;
const int maxn=200010;
const int inf=1e9;
const ll mod=998244353;
const double pi=3.14159265358979;
const double ep=0.0;
using namespace std;
ll dp[1110000][2];
int main()
{
    string s;
    cin>>s;
    s='0'+s;
    vector<int>vec;
    for (int i=0;i<s.size();i++)
        vec.pb(s[i]-'0');
    for (int i=0;i<=s.size();i++)
        for (int j=0;j<2;j++)
            dp[i][j]=1e18;
    dp[0][0]=0;
    for (int i=0;i<s.size();i++)
    {
        dp[i+1][0]=min(dp[i+1][0],dp[i][0]+vec[i]);
        dp[i+1][1]=min(dp[i+1][1],dp[i][0]+vec[i]+1);
        dp[i+1][0]=min(dp[i+1][0],dp[i][1]+10-vec[i]);
        dp[i+1][1]=min(dp[i+1][1],dp[i][1]+10-vec[i]-1);
    }
    ll ans=dp[s.size()][0];
    cout<<ans<<endl;
    return 0;
}


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

const int MAX=3510;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    for (ll i=1;i<MAX;++i){
        for (ll j=1;j<MAX;++j){
            if (4*i*j-N*(i+j)<=0) continue;
            if ((N*i*j)%(4*i*j-N*(i+j))==0){
                ll k=(N*i*j)/(4*i*j-N*(i+j));
                cout << i << ' ' << j << ' ' << k << '\n';
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

const int MAX_H = 100 + 10;
const int MAX_W = 100 + 10;
bool table[MAX_W][MAX_H];
int W, H, N;

int main(int argc, char const* argv[])
{
    cin >> W >> H >> N;
    REP(i, N) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            REP(ix, x) {
                REP(iy, H) {
                    table[ix][iy] = true;
                }
            }
        } else if (a == 2) {
            FOR(ix, x, W) {
                REP(iy, H) {
                    table[ix][iy] = true;
                }
            }
        } else if (a == 3) {
            REP(ix, W) {
                REP(iy, y) {
                    table[ix][iy] = true;
                }
            }
        } else {
            REP(ix, W) {
                FOR(iy, y, H) {
                    table[ix][iy] = true;
                }
            }
        }
    }
    int ans = 0;
    REP(iy, H) {
        REP(ix, W) {
            //cout << table[ix][iy] << " ";
            if (table[ix][iy]) {
                ans += 1;
            }
        }
        //cout << endl;
    }
    cout << W * H - ans << endl;

    return 0;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  def num(a: Long, b: Long): Long = {
    val x = a % b
    if(x == 0) return b
    else num(b, x)
  }
  val Array(a, b) = readLine().split(" ").map(_.toLong)
  val x = num(a, b)
  val ans = a * (b / x)
  println(ans)
}

Measured memory_bytes: 54832
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int N,L; cin >> N >> L;
    int temp;
    int ind, minim = 1000;
    for(int i = 1; i < N+1; ++i) {
        temp = L+i-1;
        if(abs(temp) < minim) {
            minim = abs(temp);
            ind = i;
        }
    }
    int sumi = 0;
    for(int i = 1; i < N+1; ++i) {
        if(i != ind) {
            sumi += L+i-1;
        }
    }
    cout << sumi;

}

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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
    if(debug_flag){
        cout<<str;
    }
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(10);

    string s;
    cin>>s;
    int a, b, c, d;
    a=stoi(s.substr(0, 1));
    b=stoi(s.substr(1, 1));
    c=stoi(s.substr(2, 1));
    d=stoi(s.substr(3, 1));
    
    if(a+b+c+d==7){cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl; return 0;}
    if(a+b+c-d==7){cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl; return 0;}
    if(a+b-c+d==7){cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl; return 0;}
    if(a+b-c-d==7){cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl; return 0;}
    if(a-b+c+d==7){cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl; return 0;}
    if(a-b+c-d==7){cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl; return 0;}
    if(a-b-c+d==7){cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl; return 0;}
    if(a-b-c-d==7){cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl; return 0;}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

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

//********************************template END****************************************//

void solve(void){

	int N, M;
	cin >> N >> M;

	vec as(N), bs(N), cs(M), ds(M);

	rep(N, i)
	{
		cin >> as[i] >> bs[i];
	}

	rep(M, i)
	{
		cin >> cs[i] >> ds[i];
	}

	rep(N, i)
	{
		int ans = -1, tmp = INF;
		rep(M, j)
		{
			if (abs(as[i]-cs[j]) + abs(bs[i]-ds[j]) < tmp)
			{
				ans = j+1;
				tmp = abs(as[i]-cs[j]) + abs(bs[i]-ds[j]);
			}
		}

		cout << ans << endl;
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define pb push_back
using namespace std;
const int N=200010;
const ll P=924844033;
int n;
vector<int>g[N];
int siz[N];
int rev[N<<2],lim,lev;
ll pwr(int ll x,ll y){
	if(!y)return 1;
	if(y&1)return pwr(x,y-1)*x%P;
	ll z=pwr(x,y/2);
	return z*z%P;
}
inline void ntt(ll *a,int t){
	for(int i=0;i<lim;i++)
		if(i<rev[i])
			swap(a[i],a[rev[i]]);
	for(int mid=1;mid<lim;mid<<=1){
		int rgt=mid<<1;
		ll wn=pwr(5,(P-1)/rgt);
		if(t==-1)wn=pwr(wn,P-2);
		for(int loc=0;loc<lim;loc+=rgt){
			ll w=1;
			for(int k=0;k<mid;k++){
				ll x=a[loc+k],y=w*a[loc+mid+k]%P;
				a[loc+k]=(x+y)%P;
				a[loc+mid+k]=(x-y+P)%P;
				w=w*wn%P;
			}
		}
	}
	if(t==-1){
		ll invlim=pwr(lim,P-2);
		for(int i=0;i<lim;i++)
			a[i]=a[i]*invlim%P;
	}
}
ll a[N<<2],b[N<<2];
ll fac[N],inv[N];
void dfs(int x,int f){
	siz[x]=1;
	int i,k;
	for(i=g[x].size()-1;~i;i--){
		k=g[x][i];
		if(k==f)continue;
		dfs(k,x);
		a[siz[k]]++;
		siz[x]+=siz[k];
	}
	a[n-siz[x]]++;
}
inline void init(){
	fac[0]=1;
	int i;
	for(i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%P;
	inv[n]=pwr(fac[n],P-2);
	for(i=n;i;i--)
		inv[i-1]=inv[i]*i%P;
}
int main(){
	int i;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,0);
	for(i=1;i<n;i++)
		a[i]=P-a[i];
	a[n]=n;
	init();
	for(i=1;i<=n;i++)
		a[i]=a[i]*fac[i]%P;
	for(i=1;i<=n;i++)
		b[i]=inv[n-i];
	//(i)+(n-(i-k))=(n+k)
	lim=1;
	while(lim<=n*2){
		lim<<=1;
		lev++;
	}
	for(i=0;i<lim;i++)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(lev-1));
	ntt(a,1);
	ntt(b,1);
	for(i=0;i<lim;i++)
		a[i]=a[i]*b[i]%P;
	ntt(a,-1);
	for(i=1;i<=n;i++)
		printf("%lld\n",a[i+n]*inv[i]%P);
	return 0;
}

Measured memory_bytes: 45952
#include <stdio.h>

int main(void){
    int x[10000], y[10000];
    int i, t;
    int e1, e2;
    e1 = 0;
    e2 = 0;

    for( i = 0; e1 == 0; i++ ){
        scanf("%d %d", &x[i], &y[i]);
        if( x[i] == 0 ){
            if( y[i] == 0 ) e1 = 1;
        }
    }
    
    for( t = 0; e2 == 0; t++ ){
        if( y[t] > x[t] ){   
            printf("%d %d\n", x[t], y[t]);
        } else {
            printf("%d %d\n", y[t], x[t]);
        }
        if( i == t + 2 )    e2 = 1;
    }
    return 0;
}


Measured memory_bytes: 2032
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        1000000007
#define all(x)     x.begin(),x.end()  
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
  ll i,j,k,l,m,n,r;
  string s;
  cin>>n>>s;
  ll dp[n+1][3];
  dp[n][0]=0;
  dp[n][1]=0;
  dp[n][2]=0;
  fld(i,n-1,-1) {
  	if(s[i]=='R') {
  		dp[i][0]=dp[i+1][0]+1;
  		dp[i][1]=dp[i+1][1];
  		dp[i][2]=dp[i+1][2];
  	}
  	else if(s[i]=='G') {
  		dp[i][0]=dp[i+1][0];
  		dp[i][1]=dp[i+1][1]+1;
  		dp[i][2]=dp[i+1][2];
  	}
  	else if(s[i]=='B') {
  		dp[i][0]=dp[i+1][0];
  		dp[i][1]=dp[i+1][1];
  		dp[i][2]=dp[i+1][2]+1;
  	}
  }
  ll ans=0;
  map<ll,ll>m1;
  fl(i,s.length()) {
  	fli(j,i+1,s.length()) {
  		if(s[i]!=s[j]) {
  			m1[s[i]]=1;
  			m1[s[j]]=1;
  			if(m1['R']==0) {
  				ans+=dp[j+1][0];
  				l=j-i;
  				if(j+l<n) {
  					if(s[j+l]=='R') ans--;
  				}
  			}
  			else if(m1['G']==0) {
  				ans+=dp[j+1][1];
  				l=j-i;
  				if(j+l<n) {
  					if(s[j+l]=='G') ans--;
  				}
  			}
  			else if(m1['B']==0) {
  				ans+=dp[j+1][2];
  				l=j-i;
  				if(j+l<n) {
  					if(s[j+l]=='B') ans--;
  				}
  			}
  			m1.clear();
  		}
  	}
  }
  cout<<ans<<endl;
}

int main() {
    speedup;
    ll i=0,t;
    //cin>>t;
    t=1;
    while(t--) {
        comp();
    }
    return 0;
}


Measured memory_bytes: 3676
N = int(input())
edges = [[] for _ in range(N)]
cnt_edges = [0]*N
colors = [0]*(N-1)
di = {}
A = []
K = 0
for i in range(N-1):
    a,b = [int(x) for x in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

    K=max(K,len(edges[a-1]),len(edges[b-1]))
    di[(a-1,b-1)] = i
    di[(b-1,a-1)] = i
    A.append((a-1,b-1))
#%%
#K = max(cnt_edges)

stk = [(0,0)]
seen = set()
while(stk):
    n,used_color = stk.pop()
    available_color = 1
    next_stk = []
    for next in edges[n]:
        if(next in seen):
            continue
        if(available_color == used_color):
            available_color += 1
        next_stk.append((next,available_color))
        i = di[(next,n)]
        colors[i] = available_color
        available_color += 1
    stk += next_stk
    seen.add(n)

print(K)
for col in colors:
    print(col)


Measured memory_bytes: 117152
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i<(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;

int chk(vector<int> a){
    int n=a.size();
    fr(i,0,n){
        cout << a.at(i);
    }
    cout << endl;
}

int gcd(int a,int b){ //a>b
    int tmp=a%b;
    a=b;
    b=tmp;
    if(b!=0){
        return gcd(a,b);
    }else{
        return a;
    }
}

ll power(ll a,ll n){
    if(n==1){
        return a;
    }
    else if(n&1==1){
        --n;
        return power(a,n)*a;
    }else{
        n=n>>1;
        return power(a,n)*power(a,n);
    }
}

int main(void){
    int N,R;
    cin >> N >> R;

    if(N>10){
        cout << R << endl;
    }else{
        cout << (R+100*(10-N)) << endl;
    }
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int D; cin >> D;

    string res = "Christmas";
    rep(_, 25 - D){
        res += " Eve";
    }

    cout << res << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define INF (1e9)

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

typedef long long ll;

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

    int x, a, b;
    cin >> x >> a >> b;

    if(-a + b <= 0) cout << "delicious" << endl;
    else if(-a + b <= x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;

int main(){
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if(b<n*a) printf("%d",b);
	else printf("%d",n*a);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;

int main(){
  ll n;
  string a,b,c;
  ll ans=0;
  cin>>n>>a>>b>>c;
  for(ll i=0;i<n;i++){
    if(a[i]==b[i]&&b[i]==c[i]){}
    else if(a[i]==b[i]||c[i]==a[i]||b[i]==c[i]){
      ans++;
    }
    else{
      ans+=2;
    }
  }
  cout<<ans<<endl;
}


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

int main(){
	int n;
	cin>>n;
	int ans=1;
	int f=-1;
	int a;
	cin>>a;
	
	for(int i=1;i<n;i++){
		int b;
		cin>>b;
		if(f==-1){
			if(a>b){
				f=0;
			}else if(a<b){
				f=1;
			}
		}else if(f==0){
			if(a<b){
				f=-1;
				ans++;
			}
		}else if(f==1){
			if(a>b){
				f=-1;
				ans++;
			}
		}
		a=b;
	}
	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define ull unsigned long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i,start,stop)  for(int i=(start); i < (stop); i++)
#define FORD(i,start,stop) for(int i=(start); i >= (stop); i--)
#define RIP(i,stop) FOR(i,0,stop)
#define PI 3.141592653589793
#define PRECISION(c,f) fixed << setprecision(c) << f
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n; cin >> n;
  
  int a,b,c;

  a = n%10;
  n /= 10;
  b = n%10;
  n /= 10;
  c = n%10;

  if(a == 7 or b == 7 or c == 7) yes;
  else no;

  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>

int main(){
    
    size_t n;
    std::cin >> n;

    std::vector<std::pair<size_t, size_t>> v;

    for(size_t i = 0; i < n; i++){
        size_t a;
        std::cin >> a;
        v.emplace_back(a, i + 1);
    }

    std::sort(v.begin(), v.end());

    for(const auto& e : v){
        std::cout << e.second << ' ';
    }std::cout << std::endl;
    
    return 0;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        while(a % 2 == 0){
            a /= 2;
            ++ans;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

int main()
{
	int n, a, i, c1=0, c2=0, c4=0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d", &a);
		if(a%4==0)
			c4++;
		else if(a%2==0)
			c2++;
		else
			c1++;
	}
	if(c2>0 && c4>=c1 || c2==0 && c4>=c1-1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;	
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
using namespace std;

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

void solve() {
    int l, r, d;
    cin >> l >> r >> d;
    cout << (r / d) - (l - 1) / d << '\n';
} 

int main() {
    FASTIO;
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
const int N=2e5+5;
inline int Read(){
    char ch;
    int f=1;
    while((ch=getchar())<'0'||ch>'9')
        if(ch=='-') f=-1;
    int x=ch^48;
    while((ch=getchar())>='0'&&ch<='9')
        x=(x<<3)+(x<<1)+(ch^48);
    return x*f;
}
int n,k;
double Answer;
double Sum[N];
inline double Max(const double x,const double y){
    return x>y?x:y;
}
int main(){
    n=Read();k=Read();
    for(register int i=1;i<=n;i++){
        int p=Read();
        Sum[i]=Sum[i-1]+(1+p)/2.0;
    }
    for(register int i=k;i<=n;i++)
        Answer=Max(Answer,Sum[i]-Sum[i-k]);
    printf("%.10lf\n",Answer);
    return 0;
}

Measured memory_bytes: 1664
N = input()
N = int(N)
xs = []
xs.append(1)
xs.append(2)
xs.append(3)
xs.append(4)
xs.append(5)
xs.append(6)
xs.append(7)
xs.append(8)
xs.append(9)

for i in range(len(xs)):
  if N % xs[i] == 0:
    a = N // xs[i]
    if a >= 1 and a <= 9:
      result = "Yes"
      break
    else:
      result = "No"
  else:
    result = "No"

print(result)

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
void print(char str[],int a,int b){
    for(int i = a; i <= b; i++)  printf("%c",str[i]);
    printf("\n");
}
 
void replace(char str[],char p[],int a,int b){
    int p_length = b-a+1;
    for(int i = 0; i < p_length;i++) str[a+i] = p[i];
}
 
void reverse(char str[],int a,int b){
    int left = a,right = b;
    while(left < right){
        swap(str[left++],str[right--]);
    }
}
 
int main(){
    char str[1001],p[1001],order[8];
    int q,a,b;
    scanf("%s",str);
    scanf("%d",&q);
    for(int i = 0; i < q; i++){
        scanf("%s %d %d",order,&a,&b);
        switch(order[2]){
        case 'i':
            print(str,a,b);
            break;
        case 'v':
            reverse(str,a,b);
            break;
        case 'p':
            scanf("%s",p);
            replace(str,p,a,b);
            break;
        }
    }
}


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

long long dp[55][55][3000];

int main(){
	int n,a,x[60]={};
	cin>>n>>a;
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	dp[0][0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<3000;k++){
				dp[i+1][j][k]+=dp[i][j][k];
				dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
			}
		}
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<3000;j++){
			if(j%i==0&&j/i==a){
				ans+=dp[n][i][j];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 66560
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/

/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    char c[100][100];
    REP(i, H) {
        REP(j, W) {
            cin >> c[i][j];
        }
    }

    REP(i, 2*H) {
        REP(j, W) {
            cout << c[i/2][j];
        }
        cout << endl;
    }
}


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

int main() {
  int n; cin >> n;
  map<int, int> mp;
  int a = 0;
  cin >> a;
  mp[a] = 1;
  long long s = a;
  for (int i=0; i<n-1; i++) {
    cin >> a;
    auto itr = mp.find(a);
    if( itr != mp.end() ) {
      mp[a] += 1;
    } else {
      mp[a] = 1;
    }
    s += a;
  }
  
  int q,b,c;
  cin >> q;
  for (int i=0; i<q; i++){
    cin >> b >> c;

    s += (c - b) * mp[b];

    auto itr = mp.find(a);
    if( itr != mp.end() ) {
	  mp[c] += mp[b];
    } else {
      mp[c] = mp[b];
    }
    mp[b] = 0;
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 8048
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    ld A, B;
    cin >> A >> B;
    cout << (ll)(A*B) << endl;
    

    return 0;
}

Measured memory_bytes: 3752
// clang-format off
#include "bits/stdc++.h"
using namespace std;

#define int long long
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

template <typename iterator> size_t maxElement(iterator beginIt, iterator endIt) { return max_element(beginIt, endIt); }
template <typename iterator> size_t minElement(iterator beginIt, iterator endIt) { return min_element(beginIt, endIt); }
template <typename iterator> size_t maxIndex(iterator beginIt, iterator endIt) { return distance(beginIt, *max_element(beginIt, endIt)); }
template <typename iterator> size_t minIndex(iterator beginIt, iterator endIt) { return distance(beginIt, *min_element(beginIt, endIt)); }
template <typename iterator> int sum(iterator beginIt, iterator endIt) { return accumulate(beginIt, endIt, 0); }
// clang-format on

signed main(void) {
  // -- Defined in template --
  int num = 0;
  // int num = numeric_limits<int>::min(); // max
  // int num = numeric_limits<int>::max(); // min
  int N;
  // int A[2 * 100000];
  array<int, 2 * 100000> A;
  string S;
  // -- Defined in template --

  cin >> N;

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

  sort(A.begin(), A.begin() + N);

  int b = A[N / 2];
  for (int i = 0; i < N; ++i) { num += abs(A[i] - b); }

  cout << num << endl;
  return 0;
}


Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <fstream>
#include <complex>
#include <math.h>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------

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

const long double EPS = 1e-12;
const int INF = 10000;


int main(){
	int n,m,p;
	while(cin>>n>>m>>p){
		if(n==0&&m==0&&p==0)break;
		int sum=0,win=0;
		REP(i,n){
			int temp;cin>>temp;
			if(i+1==m)win+=temp;
			sum+=temp;
		}
		if(win==0)cout<<0<<endl;
		else cout<<(sum*(100-p))/win<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    odd = 0
    even = 0
    for a in A:
        if a&1:
            odd += 1
        else:
            even += 1
    if P:
        if odd == 0:
            print(0)
        else:
            print(2**(N - 1))
    else:
        if odd == 0:
            print(2**N)
        else:
            print(2**(N - 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

set<ll> ans;
ll max_v = 3234566667;

int rec(vector<ll> &n) {
  int ei = -1;
  rep(i,0,10) {
    if (n[i] == -1) {ei = i; break;}
  }
  ll k = 1;
  ll l = 0;
  rep(i,0,10) {
    if (n[i] == -1) break;
    l += k*n[i];
    k *= 10;
  }
  if (1 <= l && l <= max_v) {
    ans.insert(l);
  }
  if (ei == -1) return 0;
  rep(i,n[ei-1]-1,n[ei-1]+2) {
    if (i == -1 || i == 10) continue;
    n[ei] = i;
    rec(n);
  }
  n[ei] = -1;
  return 0;
}

int main() {
  vector<ll> n(10,-1);
  rep(i,0,10) {
    n[0] = i;
    rec(n);
  }
  int k;
  cin >> k;
  auto itr = ans.begin();
  rep(i,0,k-1) {
    ++itr;
  }
  cout << *itr << endl;
  return 0;
}


Measured memory_bytes: 8248
n = int(input())
a = []
for i in range(n):
    b = list(map(int, input().split()))
    c = [-1] * n
    for j in range(b[1]):
        c[b[2 + j * 2]] = b[3 + j * 2]
    a.append(c)

m = [float('inf')] * n
f = [0] * n
m[0] = 0
f[0] = 1
v = 0

for i in range(n-1) :
    for j in range(n) :
        if (a[v][j] + m[v] < m[j]) & (f[j] == 0) & (a[v][j] != -1):
            m[j] = a[v][j] + m[v]
    
    min = 2001
    minj = 0
    for j in range(n) :
        if (m[j] < min) & (f[j] == 0):
            min = m[j]
            minj = j
    
    v = minj
    f[minj] = 1

[print(i, m[i]) for i in range(n)]


Measured memory_bytes: 5860
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
    ll n,a,min=200001,cnt=0;
    cin>>n;
    rep(i,n){
        cin>>a;
        if(min>a){
            min=a;
        }else{
            cnt++;
        }
    }
    cout<<n-cnt;
}

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

int main()
{
	char S[11];
	cin >> S;

	int max = 0;
	int tmp = 0;
	for (int i = 0; i < 11; i++)
	{
		if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G')
		{
			tmp++;
			if (tmp > max)
				max = tmp;
		}
		else
		{
			if (tmp > max)
				max = tmp;

			tmp = 0;
		}

	}

	cout << max;
	return 0;

}

Measured memory_bytes: 256
require 'prime'

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

x = Array.new(a[-1] + 1)
b = 0

n.times do |i|
    next if x[a[i]]

    b -= 1 if i < n-1 && a[i] == a[i+1]

    a[i].step(a[-1], a[i]) {|j| x[j] = true}
    b += 1
end

p b

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  int N, K;
  cin >> N >> K;
  ll maxs = 0, mins = 0;
  ll ans = 0;
  REP(i, N+1){
    mins += i;
    maxs += N-i;
    if(i+1 >= K){
      ans += maxs - mins + 1;
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>


#define endl '\n'
#define pi acos(-1)
#define euler_e 2.71828
#define pii pair<int,int>
#define pb push_back
#define all(a) a.begin(),a.end()
#define ll long long
#define ull unsigned long long
#define io freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
void mycode();
const ll int mod=998244353;
ll int ceil(ll int a,ll int b){return (a+b-1)/b;}
ll int min(ll int a, ll int b){if(a>b)return b;else return a;}
bool bit_check(ll int a,int i){
  if((a & (1LL<<i)))return 1;
  return 0;
}
ll int bit_toggle(ll int a,int i){
  return (a^(1LL<<i));
}
ll int bit_sum(ll int a,int i){
  return a+(1LL<<i);
}
ll int bit_sub(ll int a,int i){
  return a-(1LL<<i);
}
ll int mod_power(ll int x,ll int y){//x^y%p
  ll int p=mod;
  ll int res = 1;
  x = x % p;
  while (y > 0) { 
    if (y & 1)res = (res*x) % p;
    y = y>>1;x = (x*x) % p;
  }
  return res;
}
ll int power_of(ll int a,int b){
  if(a==0)return -1;
  return 1+power_of(a/b,b);
}
ll int power(ll int a, ll int b) {
	if(a==1)return 1;
    ll int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
//__int128
int main(){
	boost;
	//io;
	//auto start = chrono::high_resolution_clock::now();
	mycode();
	//auto end = chrono::high_resolution_clock::now();cerr << "\nExecution time: "<< chrono::duration_cast<chrono::milliseconds>(end - start).count() << " ms" << endl;
	return 0;
}
#include<map>
void mycode(){
	int t,k;
	cin>>t;
	ll int sum=0;
	map<int,int>mp;
	for(int i=0;i<t;i++){cin>>k;mp[k]++;sum+=k;}
	int q,a,b;
	cin>>q;
	while(q--){
		cin>>a>>b;
		sum+=-mp[a]*a+mp[a]*b;
		cout<<sum<<endl;
		mp[b]+=mp[a];
		mp.erase(a);
	}
}

Measured memory_bytes: 6592
-- FileName   : 164a
-- CreatedDate: 2020-04-26 20:56:13

import Control.Monad
import Data.List

main = do
   [s,w] <- getIntegerList
   if s > w
      then putStrLn "safe"
      else putStrLn "unsafe"


--------------------------------------------
getIntList        = map (read :: String -> Int) . words <$> getLine
getIntegerList    = map (read :: String -> Integer) . words <$> getLine
getIntegerListN m = map (read :: String -> Integer) <$> replicateM m getLine


base :: Integer
base = 1000000007

plus :: Integer -> Integer -> Integer
plus a b = (a+b) `mod` base

times :: Integer -> Integer -> Integer
times a b = a * b `mod` base

minus :: Integer -> Integer -> Integer
minus a b
   | a < b     = a-b + base
   | otherwise = a-b

power :: Integer -> Integer -> Integer
power n k
   | k == 0         = 1
   | k `mod` 2 == 0 = power (times n n) (k`div`2)
   | otherwise      = times n $! power n (k-1)

inv :: Integer -> Integer
inv n = power n $ base - 2

binom :: Integer -> Integer -> Integer
binom n m
   | (n-m) < m = times (foldr times 1 [m+1..n]) $ inv $ foldr times 1 [1..n-m]
   | otherwise = times (foldr times 1 [n-m+1..n]) $ inv $ foldr times 1 [1..m]


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

struct Node
{
    vector<int> cost;
    vector<int> vertex;

    bool visited = false;
    int minCost = 100000000;
};

int N;
vector<Node> firstNodes(100);

int findNode(const vector<Node>& nodes)
{
    int minCost = 1000000000;
    int index = -1;
    for (int i = 0; i < nodes.size(); i++)
    {
        if(minCost > nodes[i].minCost && !nodes[i].visited)
        {
            minCost = nodes[i].minCost;
            index = i;
        }   
    }
    return index;
}

int main()
{
    cin >> N;
    int u;
    int k;
    int temp;
    for(int i = 0;i < N;i++)
    {
        cin >> u;
        cin >> k;
        for(int i = 0;i < k;i++)
        {
            cin >> temp;
            firstNodes[u].vertex.push_back(temp);
            cin >> temp;
            firstNodes[u].cost.push_back(temp);
        }
    }

    firstNodes[0].minCost = 0;
    
    for(int vi = 0;vi < N;vi++)
    {
        vector<Node> nodes = firstNodes;
        while(nodes[vi].visited != true)
        {
            //find a node that is visited and has minimum cost
            int index = findNode(nodes);

            Node& minNode = nodes[index];
            int vertex;
            int cost;
            minNode.visited = true;
            for (size_t i = 0; i < minNode.vertex.size(); i++)
            {
                vertex = minNode.vertex[i];
                cost = minNode.cost[i];
                nodes[vertex].minCost = min(nodes[vertex].minCost,minNode.minCost + cost);
            }
        }
        cout << vi << " " << nodes[vi].minCost << endl;
    }
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
const int N = 2007;
const int INF = 2e9 + 7;
int a[N];
int dp[N][2][N];
int pos[N];
int post[2];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, A, B;
    cin >> n >> A >> B;
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector <int> c;
    c.push_back(A); c.push_back(B);
    for (int i = 0; i < n; ++i) c.push_back(a[i]);
    sort(c.begin(), c.end()); c.resize(unique(c.begin(), c.end()) - c.begin());
    for (int i = 0; i < n; ++i) {
        pos[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
    }   
    post[0] = INF; post[1] = -INF;
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < (int)c.size(); ++j) {
            dp[i][0][j] = max(abs(a[n - 1] - c[j]), post[1]);
            /*
            for (int k = i; k < n - 1; ++k) {
                dp[i][0][j] = max(dp[i][0][j], dp[k + 1][1][pos[k]]);
            }
            */
        }
        for (int j = 0; j < (int)c.size(); ++j) {
            dp[i][1][j] = min(abs(a[n - 1] - c[j]), post[0]);
            /*
            for (int k = i; k < n - 1; ++k) {
                dp[i][1][j] = min(dp[i][1][j], dp[k + 1][0][pos[k]]);
            }
            */  
        }   
        if (i) {
            post[0] = min(post[0], dp[i][0][pos[i - 1]]);
            post[1] = max(post[1], dp[i][1][pos[i - 1]]);
        }
    }
    cout << dp[0][0][lower_bound(c.begin(), c.end(), B) - c.begin()] << '\n';   
}   

Measured memory_bytes: 31616
#include <stdio.h>
#include <stdlib.h>
#define int long long

int less(int a, int b){
	int ans;
	for(ans = 0; a <= b; ans++){
		a *= 4;
	}
	return ans - 1;
}

int more(int a, int b){
	int ans;
	for(ans = 0; a > b; ans++){
		b *= 4;
	}
	return ans;
}

int min(int a, int b){
	return a <= b ? a : b;
}

int max(int a, int b){
	return a >= b ? a : b;
}

signed main(){
	int N, M = 15, i, j, k;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	int **dp1 = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		dp1[i] = (int *)malloc(sizeof(int) * (M + 1));
	}
	for(j = 0; j <= M; j++){
		dp1[N - 1][j] = j;
	}
	for(i = N - 2; i >= 0; i--){
		for(j = 0; j <= M; j++){
			if(A[i] < A[i + 1]){
				k = less(A[i], A[i + 1]);
				dp1[i][j] = dp1[i + 1][max(0, j - k)] + j;
			}
			else{
				k = more(A[i], A[i + 1]);
				if(j + k <= M){
					dp1[i][j] = dp1[i + 1][j + k] + j;
				}
				else{
					dp1[i][j] = dp1[i + 1][M] + (j + k - M) * (N - i - 1) + j;
				}
			}
		}
	}
	int tmp;
	for(i = 0; i < N / 2; i++){
		tmp = A[i];
		A[i] = A[N - 1 - i];
		A[N - 1 - i] = tmp;
	}
	int **dp2 = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		dp2[i] = (int *)malloc(sizeof(int) * (M + 1));
	}
	for(j = 0; j <= M; j++){
		dp2[N - 1][j] = j;
	}
	for(i = N - 2; i >= 0; i--){
		for(j = 0; j <= M; j++){
			if(A[i] < A[i + 1]){
				k = less(A[i], A[i + 1]);
				dp2[i][j] = dp2[i + 1][max(0, j - k)] + j;
			}
			else{
				k = more(A[i], A[i + 1]);
				if(j + k <= M){
					dp2[i][j] = dp2[i + 1][j + k] + j;
				}
				else{
					dp2[i][j] = dp2[i + 1][M] + (j + k - M) * (N - i - 1) + j;
				}
			}
		}
	}
	int ans = min(2 * dp1[0][0], 2 * dp2[0][0] + N);
	for(i = 1; i < N; i++){
		ans = min(ans, 2 * dp1[i][0] + 2 * dp2[N - i][0] + i);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 61056
# 同じ数を2回以上移動するのは無駄。最後の1回だけやればいいから。
# したがって全ての数は移動が0回または1回になる。
# 移動しない数はそのままの並び順になる。
# 逆に言えば、連続する数値からなる部分列の最長のものを見つければ、それ以外の数を移動させればよい。
# 例2では「3, 4」または「5, 6」が該当する。
# ではそれをどうやって見つけるか?
# 各数の位置を格納した配列を作る（1の位置を探して、2の位置を……とやるとO(N^2)でダメ。数列の先頭から順にやる）
# その配列を順に舐めて最大単調増加部分を見つければ良い

n = int(input())
posi = [-1] * n  # posi[i-1]には、数iの場所が0-indexで入る。

for k in range(n):
    temp = int(input())
    posi[temp - 1] = k - 1

temp = 1
maxx = 0
for i in range(n-1):
    if posi[i] < posi[i+1]:
        temp += 1
    else:
        maxx = max(maxx, temp)
        temp = 1

maxx = max(maxx, temp)

print(n - maxx)


Measured memory_bytes: 12064
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = nal(N)
    Sorting.quickSort(A)

    val ans = if (N % 2 == 0) {
      -2 * A.take(N / 2).sum + 2 * A.drop(N / 2).sum + A(N / 2 - 1) - A(N / 2)
    } else {
      val n1 = N / 2
      val n2 = N / 2 - 1
      val w = -2 * A.take(n1).sum + A.drop(n1).take(2).sum + 2 * A.takeRight(n2).sum
      val m = -2 * A.take(n2).sum + -1 * A.drop(n2).take(2).sum + 2 * A.takeRight(n1).sum
      max(w, m)
    }
    out.println(ans)
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

Measured memory_bytes: 70784
#include<stdio.h>

int main(void)
{
	int a, b, c;
	int counter = 0;

	scanf("%d %d %d", &a, &b, &c);
	for (; a <= b; a++)
	{
		if (c % a == 0)
		{
			counter++;
		}
	}
	printf("%d\n", counter);

	return 0;
}

Measured memory_bytes: 596
using System;

namespace TestApp
{
    class Program
    {
        public static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            if(N % 1000 == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1000 - N % 1000);
            }
            
        }
    }
}


Measured memory_bytes: 27544
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

// idx, (未処理、偶数左、奇数、偶数右)
const int VARI = 5;
int dp[200010][VARI];
signed main() {
    int N; cin >> N;
    vector<int> v(N);
    for(int i=0; i<N; i++) {
        cin >> v[i];
    }

    // DP
    const int M1 = 0;
    const int M2 = 1;
    const int E1 = 2;
    const int E2 = 3;
    const int O  = 4;
    fill(dp[0], dp[N+1], INF);
    for(int i=0; i<VARI; i++) dp[0][i] = 0;
    for(int i=0; i<N; i++) {
        /*
        vector<string> vs = {"M1", "M2", "E1", "E2", "O "};
        for(int k=0; k<VARI; k++) {
            fprintf(stderr, "dp[%lld][%s] = %lld\n", i, vs[k].c_str(), dp[i][k]);
        }
        */
        
        // 未処理左 (未処理左につづく)
        chmin(dp[i+1][M1], dp[i][M1] + v[i]);

        // 偶数左 (偶数左か未処理左につづく)
        int cost1 = (v[i] == 0 ? 2 : (v[i] % 2));
        chmin(dp[i+1][E1], min(dp[i][E1], dp[i][M1]) + cost1);

        // 偶数右 (奇数か偶数右につづく)
        int cost2 = (v[i] == 0 ? 2 : (v[i] % 2));
        chmin(dp[i+1][E2], min(dp[i][O], dp[i][E2]) + cost2);

        // 奇数 (偶数左か奇数か未処理左につづく)
        int cost3 = 1 - (v[i] % 2);
        int mi = min({dp[i][E1], dp[i][O], dp[i][M1]});
        chmin(dp[i+1][O], mi + cost3);

        // 未処理右 (未処理左以外のすべてにつづく)
        int mi2 = min({dp[i][E1], dp[i][E2], dp[i][O], dp[i][M2]});
        chmin(dp[i+1][M2], mi2 + v[i]);
    }

    int ans = INF;
    for(int i=0; i<VARI; i++) {
        chmin(ans, dp[N][i]);
    }
    cout << ans << endl;
    return 0;
}


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

string s;

int main() {
  cin >> s;
  bool f=false;
  for(auto t : s){
    if(t=='C')
    f=true;
    if(f && t=='F'){
    cout << "Yes" << endl; return 0;
    }
  }
  cout << "No" << endl; return 0;
}

Measured memory_bytes: 256