akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int MAX = 510000;
const int MOD = 1e9+7;

int main(){
  int m1,d1,m2,d2;
  cin >> m1 >> d1;
  cin >> m2 >> d2;
  if(m1!=m2){
    cout << 1 << endl;
  }
  else cout << 0 << endl;
return 0;}

Measured memory_bytes: 256
class Dice:

	top = 0
	south = 1
	east = 2
	west = 3
	north = 4
	bottom = 5

	def __init__(self, faces):
		self.faces = faces

	def roll(self, direction):

		top_ = self.top
		south_ = self.south
		east_ = self.east
		west_ = self.west
		north_ = self.north
		bottom_ = self.bottom

		if direction == 'E':
			self.top = west_
			self.east = top_
			self.bottom = east_
			self.west = bottom_
		elif direction == 'N':
			self.top = south_
			self.south = bottom_
			self.bottom = north_
			self.north = top_
		elif direction == 'S':
			self.top = north_
			self.south = top_
			self.bottom = south_
			self.north = bottom_
		elif direction == 'W':
			self.top = east_
			self.east = bottom_
			self.bottom = west_
			self.west = top_
		else:
			return

	def get_top(self):
		return faces[self.top]

faces = list(map(int, input().split()))
directions = str(input())

dice = Dice(faces)

for direction in directions:
	dice.roll(direction)

print(dice.get_top())


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

int q, h, s, d, n;
vector<pair<int, int>> v;
vector<int> w;
vector<float> u;
long long sum=0;

int main(){
	cin >> q >> h >> s >> d >> n;
	v={make_pair(q*4, 0), make_pair(h*2, 1), make_pair(s*1, 2), make_pair(d/2, 3)};
	w={q, h, s, d};
	u={0.25, 0.5, 1, 2};
	sort(v.begin(), v.end());
	
	for(auto x: v){
		int index=x.second;
		long long cost=w[index];
		double size=u[index];
		sum+=((long long)(n/size))*cost;
		n=n-(int(n/size))*size;
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int m, f, b;
	int miyamoto_nobuko;
	if (scanf("%d%d%d", &m, &f, &b) != 3) return 1;
	if (m >= b) {
		miyamoto_nobuko = 0;
	} else {
		miyamoto_nobuko = b - m;
		if (miyamoto_nobuko > f) {
			puts("NA");
			return 0;
		}
	}
	printf("%d\n", miyamoto_nobuko);
	return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int p[1500]; 
int main() {
	int n,k; cin >> n >> k;
	rep(i,n) cin >> p[i];
	sort(p,p+n);
	int ans = 0;
	rep(i,k) ans += p[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
from array import array
from itertools import islice, repeat


def main():
    number = int(input())

    divisor_count_of = array('B', repeat(2, number + 1))
    for i in range(2, number // 2 + 1):
        for j in range(i * 2, number + 1, i):
            divisor_count_of[j] += 1

    print(sum(1 for divisor_count in islice(
        divisor_count_of, 1, None, 2) if divisor_count == 8))


if __name__ == '__main__':
    main()


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

const ll MOD = 998244353;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fmemo;
    vector<ll> imemo;
    vector<ll> ifmemo;
    
    Combination(int maxn) : maxn(maxn){
        fmemo.resize(maxn + 1);
        imemo.resize(maxn + 1);
        ifmemo.resize(maxn + 1);
        for(ll i = 1; i <= maxn; i++){
            imemo[i] = modpow(i, MOD - 2);
        }
    }

    ll fact(ll n){
        if(n == 0) return 1;
        if(fmemo[n]) return fmemo[n];
        return fmemo[n] = n * fact(n - 1) % MOD;
    }

    ll ifact(ll n){
        if(n == 0) return 1;
        if(ifmemo[n]) return ifmemo[n];
        return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n) return 0;
        if(k == n || k == 0) return 1;
        return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
    }
};

int main()
{
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    Combination com(n + 1);
    for(int i = 0; i <= n; i++){
        if(k - a * i >= 0 && (k - a * i) % b == 0){
            int j = (k - a * i) / b;
            if(j > n) continue;
            ans = (ans + com.com(n, i) * com.com(n, j) % MOD) % MOD;
        }
    }
    cout << ans << endl;
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A==B && B==C)cout << "No" << endl;
    else if(A==B || B==C || A==C)cout << "Yes" << endl;
    else cout << "No" << endl;;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define NEWMAT(N, M, ini) MAT(N, vector<lint>(M, ini))
#define MOD 1000000007

typedef long long lint;
typedef pair<lint, lint> P;
typedef vector<lint> V;
typedef vector<vector<lint>> MAT;
bool lessPair(const P& l, const P& r){return l.second < r.second;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint R; cin >> R;
    lint G; cin >> G;
    lint B; cin >> B;
    lint N; cin >> N;

    lint res = 0;
    REP(r, 3001) {
      lint current = N - r*R;
      if(current == 0) {
        res++;
        break;
      }
      if(current < 0) {
        break;
      }
      REP(g, 3001) {
        lint current2 = current - g*G;
        if(current2 < 0) {
          break;
        }
        if(current2%B == 0) {
          res++;
        }
      }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
using namespace std; 
  
int count = 0;

int isPalindrome(int n) 
{ 
    int rev = 0; 
    for (int i = n; i > 0; i /= 10) 
        rev = rev*10 + i%10; 
  
    return (n==rev); 
} 
  
 
void countPal(int min, int max) 
{ 
    for (int i = min; i <= max; i++) 
        if (isPalindrome(i)) 
          // cout << i << " ";
          count++;
} 
  

int main() 
{	
  	long long a, b;
  	cin >> a >> b;
    countPal(a,b); 
    cout << count;
} 

Measured memory_bytes: 256
#include <map>
#include <stdio.h>
#include <stdlib.h>

const int MAX_N = 1e5 + 10 ;

std::map<int , int> cnt ;
std::map<int , bool> ap ;

int n , a[MAX_N] ;

int main() {
	scanf("%d" , &n) ;
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d" , &a[i]) ;
		++cnt[a[i]] ;
	}

	///

	int ans = 0 ;
	for (int i = 0 ; i < n ; ++i) {
		if (ap[a[i]]) continue ;
		ap[a[i]] = 1 ;

		int tmp = cnt[a[i]] ;
		if (tmp >= a[i]) ans += tmp - a[i] ;
		else ans += tmp ;
	}

	printf("%d\n" , ans) ;

	return 0 ;
}

Measured memory_bytes: 9600
#include <iostream>
using namespace std;
int main(void){
    int i,x,y;
    for (i=0;i<3000;i++){
        cin >> x >> y;
        if (x==0 && y==0){
            break;
        }
        if (x<y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl; 
        }
    }
}


Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
#define ff      first
#define ss      second
#define ll      long long
#define int     long long
#define ull     unsigned long long
#define mod     1000000007
#define vi      vector<ll>
#define ppi     pair<ll,pair<ll,ll>>
#define pb      push_back
#define mp      make_pair
#define str     string
#define pi      2*acos(0.0)
#define pr(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define p(a)    cout<<a;
#define sp(x,y) fixed<<setprecision(y)<<x
#define w(x)    ll x; cin>>x; while(x--)
#define e       cout<<'\n';
#define all(v)  v.begin(), v.end()
#define test    cout<<"LOL_ABHISHEK"<<endl;
void kehsihba() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
	//kehsihba();
	str s;cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]==','){cout<<" ";}
		else{cout<<s[i];}
	}
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n,m;
	cin>>n>>m;

	vector<pair<lli,char>> d;

	REP(i,0,m){
		lli s;
		char c;
		cin>>s>>c;
		s--;
		d.push_back(mp(s,c));
	}

	REP(i,0,1000){
		string s = to_string(i);
		if(s.size()!=n)continue;

		bool ok = true;
		REP(i,0,m){
			if(s.at(d[i].first) != d[i].second){
				ok = false;
				break;
			}
		}
		if(ok){
			cout<<s<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define outl2(x,y) cout<< (x) << ' ' << (y) << '\n'
using pii = pair<int,int>;
using ll = long long;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
static constexpr int INF = 0x3f3f3f3f;


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

    int N;
    int x[105], y[105], h[105];

    cin >> N;
    rep(i, N) {
        cin >> x[i] >> y[i] >> h[i];
    }

    for (int cx = 0; cx <= 100; ++cx) {
        for (int cy = 0; cy <= 100; ++cy) {
            int ans;

            for(int i = 0; i < N; ++i) {
                if (h[i] <= 0) continue;
                ans = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
            }
            for (int i = 0; i < N; ++i) {
                if (max(0, ans - abs(cx - x[i]) - abs(cy - y[i])) != h[i]) {ans = INF; break; }
            }

            if (ans == INF) continue;
            cout << cx << " " << cy << " " << ans << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int h[n];
    for(int i = 0; i < n; i++){
       cin>>h[i] ;
    }
    int ans = 0 ;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            ans+=h[i]*h[j];
        }
    }
    cout << ans << endl;
    return 0 ;
}


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

const int MAX_N = 100010;
int N;
int a[MAX_N][3];

int dp[MAX_N][3];

int rec(int x, int p) {
  if (dp[x][p] != 0) {
    return dp[x][p];
  }
  int res;
  if (x == 0) {
    res = a[x][p];
  }
  else {
    if (p == 0) {
      res = max(rec(x-1, 1) + a[x][p], rec(x-1, 2) + a[x][p]);
    }
    if (p == 1) {
      res = max(rec(x-1, 0) + a[x][p], rec(x-1, 2) + a[x][p]);
    }
    if (p == 2) {
      res = max(rec(x-1, 0) + a[x][p], rec(x-1, 1) + a[x][p]);
    }
  }
  return dp[x][p] = res;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  rec(N, 0); rec(N, 1); rec(N, 2);
  cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}


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

int main(){
    string s;
    cin >> s;
    int n=s.size()+1;
    vector<int> a(n,-1);

//0の入力
    if(s.at(0)=='<') a.at(0)=0;
    for(int i=1; i<n-1; i++){
        if(s.at(i-1)!=s.at(i)) a.at(i)=0;
    }
    if(s.at(n-2)=='>') a.at(n-1)=0;

    int num=0;
    long long int ans=0;
    for(int i=0; i<n-1; i++){
        num=0;
        if(a.at(i)==0){
            while(s.at(i)=='<'){
                i++;
                num++;
                a.at(i)=num;
                if(i==n-1) break;
            }
        }
    }
/*    for(int i=0; i<n; i++){
        cout << a.at(i) << endl;
    }
    cout << endl;*/

    for(int i=n-1; i>0; i--){
        num=0;
        if(a.at(i)==0){
            while(s.at(i-1)=='>'){
                i--;
                num++;
                a.at(i)=max(a.at(i),num);
                if(i==0) break;
            }
        }
    }

    for(int i=0; i<n; i++){
        ans+=a.at(i);
        //cout << a.at(i) << endl;
    }
    cout << ans << endl;

}


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

  string s;
  cin >> s;

  s.append("S");
  
  int Srainy = 0;
  int Nrainy = 0;

  for (int i=0;i<s.length();i++){
      
    if(s[i]=='R'){
      Nrainy++;    
    }else{
      Srainy=max(Nrainy, Srainy);
      Nrainy=0;
    }
  }

  printf("%d\n", Srainy);

  return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
// using Graph = vector<vector<int>>;

struct edge {
    int to, cost;
    edge(){}
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
};
using Graph = vector<vector<edge>>;

// undirected
void addEdge(Graph& G, int x, int y, int c) {
    G[x].emplace_back(y, c);
    G[y].emplace_back(x, c);
}

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

    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m) {
        int x, y, t;
        cin >> x >> y >> t;
        x--; y--;
        addEdge(G, x, y, t);
    }

    int v0;
    cin >> v0;
    int a, b, c;
    cin >> a >> b >> c;

    // dijkstra

    using Vertex = tuple<int, int, int>; // {i, j, k}
    using State = pair<int, Vertex>;
    priority_queue<State, vector<State>, greater<State>> pq; // cost, vertex
    vvvi d(n, vvi(c + 1, vi(2, inf)));
    d[0][v0][0] = 0;
    pq.push(State(0, make_tuple(0, v0, 0)));

    while (!pq.empty()) {
        int cost;
        Vertex vertex;
        tie(cost, vertex) = pq.top(); pq.pop();
        int i, j, k;
        tie(i, j, k) = vertex;
        if (d[i][j][k] < cost) continue;
        for (const auto& e : G[i]) {
            int ni = e.to;
            int nj = (a * j + b) % c;
            int nk = k ? 1 : (i == n - 1);
            int edge_cost = e.cost * j;
            if (d[ni][nj][nk] > cost + edge_cost) {
                d[ni][nj][nk] = cost + edge_cost;
                pq.push(State(d[ni][nj][nk], Vertex(ni, nj, nk)));
            }
        }
    }

    int ans = inf;
    rep(j, c + 1) {
        ans = min(ans, d[0][j][1]);
    }
    cout << ans << endl;

}

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

int	main()
{
	string S, T;
	cin >> S >> T;
	int	cnt = 0;
	for (int i = 0; i < static_cast<int>(S.size()); ++i) {
		if (S.at(i) != T.at(i))
			++cnt;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3828
#include<stdio.h>

#include<algorithm>


using namespace std ;



int main()
{
	int n ,k ;

	while( 1 )
	{
		scanf( "%d %d" ,&n ,&k ) ;


		if( !( n | k ) )
		{
			return 0 ;
		}


		int if_k = k - 1 ;

		int ans = -10001 ,other[ 100000 ] ;
		
		int sum = 0 ;

		int i ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d" ,&other[ i ] ) ;

			sum += other[ i ] ;


			if( i > if_k )
			{
				sum -= other[ i - k ] ;
			}

			if( i >= if_k )
			{
				ans = max( ans ,sum ) ;
			}
		}


		printf( "%d\n" ,ans ) ;
	}
}

Measured memory_bytes: 2960
S = input()
ans = 0
cnt = 0
for i in range(len(S)):
  if S[i] == "A" or S[i] =="G" or S[i] =="C" or S[i] =="T":
    cnt += 1
  else:
    ans = max(ans,cnt)
    cnt = 0

print(max(ans,cnt))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  string s;
  ll x,y;
  cin >> s >> x >> y;
  vec X,Y;
  ll sign=0;
  ll c=0;
  for(ll i=0;i<s.size();i++){
    if(s[i]=='T'){
      if(sign==0){
        X.push_back(c);
        c=0;
      }
      else{
        Y.push_back(c);
        c=0;
      }
      sign=1-sign;      
    }
    else{
      c++;
    }
  }
  if(sign==0)X.push_back(c);
  else Y.push_back(c);

  vec xo={0},yo={0};
  for(ll i=0;i<X.size();i++){
    vec xp=xo;
    xo.clear();
    for(ll j=0;j<xp.size();j++){
      xo.push_back(xp[j]+X[i]);
      if(i!=0)xo.push_back(xp[j]-X[i]);
    }
    sort(xo.begin(),xo.end());
    xo.erase(unique(xo.begin(),xo.end()),xo.end());
  }

  for(ll i=0;i<Y.size();i++){
    vec yp=yo;
    yo.clear();
    for(ll j=0;j<yp.size();j++){
      yo.push_back(yp[j]+Y[i]);
      yo.push_back(yp[j]-Y[i]);
    }
    sort(yo.begin(),yo.end());
    yo.erase(unique(yo.begin(),yo.end()),yo.end());
  }

  bool ok1=0,ok2=0;
  for(ll i=0;i<xo.size();i++)if(xo[i]==x)ok1=1;
  for(ll i=0;i<yo.size();i++)if(yo[i]==y)ok2=1;

  if(ok1 && ok2)cout << "Yes" << endl;
  else cout << "No" << endl;

  //for(ll i=0;i<xo.size();i++)cout << xo[i] << endl;

  return 0;
}

Measured memory_bytes: 3772
n,k=map(int, input().split())
a = list(map(int, input().split()))
a=sorted(a,reverse=True)
if k==0:
    print(max(a))
    exit()
import math
lo=0
hi=10**9
oldmid=0
while True:
    mid=(hi+lo)/2
    cnt=0
    for i in range(n):
        cnt+=round(a[i]/mid-0.5)
    if cnt>k:
        lo=mid
    elif cnt<=k:
        hi=mid
    if oldmid-0.000001<=(hi+lo)/2<=oldmid+0.000001:
        print(min(math.ceil(lo), max(a)))
        break
    oldmid=mid


Measured memory_bytes: 93912
#include<bits/stdc++.h>
using namespace std;
#define N 200020
const int inf = 0x3f3f3f3f;
struct tree{
    int l, r, min, tag;
} t[N << 2];
int a[N], b[N];
int n, m;
int ls(int cur){ return cur << 1; }
int rs(int cur){ return cur << 1 | 1; }
void lazy(int cur, int k){
    t[cur].tag = k; t[cur].min = k;
}
void pushdown(int cur){
    if(!t[cur].tag) return ;
    int mid = (t[cur].l + t[cur].r) >> 1;
    lazy(ls(cur), t[cur].tag); lazy(rs(cur), t[cur].tag + mid - t[cur].l + 1); 
    t[cur].tag = 0;
    return ;
}
void build(int cur, int l, int r){
    t[cur].l = l; t[cur].r = r; t[cur].min = t[cur].tag = 0;
    if(l == r) return ;
    int mid = (l + r) >> 1;
    build(ls(cur), l, mid);
    build(rs(cur), mid + 1, r);
    return ;
}

void update(int cur, int ul, int ur, int k){
    if(t[cur].l >= ul && t[cur].r <= ur){
        lazy(cur, k); return ;
    }
    pushdown(cur);
    int mid = (t[cur].l + t[cur].r) >> 1;
    if(mid >= ul) update(ls(cur), ul, ur, k);
    if(mid < ur) update(rs(cur), ul, ur, k + max(0, (mid - max(t[cur].l, ul) + 1)));
    t[cur].min = min(t[ls(cur)].min, t[rs(cur)].min);
    return ;
}

int query(int cur, int ql, int qr){
    if(t[cur].l >= ql && t[cur].r <= qr) return t[cur].min;
    pushdown(cur);
    int mid = (t[cur].l + t[cur].r) >> 1;
    int res = inf;
    if(mid >= ql) res = min(res, query(ls(cur), ql, qr));
    if(mid < qr) res = min(res, query(rs(cur), ql, qr));
    return res;
}

void init(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
    return ;
}
void solve(){
    build(1, 1, m);
    for(int i = 1; i <= n; i++){
        int k = (a[i] == 1) ? (m + 1) : query(1, a[i] - 1, a[i] - 1) + 1;
        update(1, a[i], b[i], k);
        if(t[1].min >= m + 1) printf("-1\n");
        else printf("%d\n", t[1].min + i);
    }
    return ;
}
int main(){
    init();
    solve();
    return 0;
}

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

int main() {

string s; cin>>s;
  int c=0;
  rep(i,3)if(s.at(i)=='R')c++;
  if(c==2&&s.at(1)=='S')cout<<1<<endl;
  else{cout<<c<<endl;}
  

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int s,t,c;
void solve(){
	int n,C;
	cin>>n>>C;
	unordered_map<int,vector<PII> > ma;
	rep(i,0,n){
		cin>>s>>t>>c;
		ma[c].pb({s,t});
	}
	multiset<PII> mt;
	for(auto m:ma){
		vector<PII> ret = m.se;
		sort(all(ret));
		int i=1;
		while(i<sz(ret)){
			if(ret[i].fi!=ret[i-1].se)mt.insert(ret[i-1]);
			else ret[i].fi = ret[i-1].fi;
			i++;
		}
		mt.insert(ret[sz(ret)-1]);
	}
	vector<int> tab;
	for(auto m:mt){
		s = m.fi,t = m.se;
		int f=0;
		for(int i=0;i<sz(tab);i++){
			if(s>tab[i]){
				tab[i] = t;
				f = 1;
				break;
			}
		}
		if(!f)tab.pb(t);
	}
	cout<<sz(tab); 
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

Measured memory_bytes: 6144
import java.util.*;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
      	int N = scanner.nextInt();//会社に何人いるか
      
      //List <Integer> n = new ArrayList<Integer>();//各社員の部下の数を格納
      List <Integer> a = new ArrayList <Integer>();//各社員の上司番号を格納
      int n[] = new int[N];
      for(int i=0; i<N; i++){
      //n.add(0);//各社員の部下の数の表記を一旦0と置く...[0,0,0,0,0]
        n[i] = 0;
      }
      
      for(int i=0; i<N-1; i++){
         a.add(scanner.nextInt());//各社員の上司番号を入れる...[1,1,2,2]
      }
      
      int b = 0;
      for(int i=0; i<N-1; i++){
        b = a.get(i);//[1,1,2,2]をbに一つずつ代入していく
        //n.set(b-1,n.get(b-1)+1);//n.set(0,1)...0番目のところに1を置き換える
        n[b-1] ++;
      }
      for(int i=0; i<N; i++){
       System.out.println(n[i]);
      }
    }
 }

Measured memory_bytes: 66260
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  sort(all(a));
  cout << a[n - 1] - a[0] << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3644
n = gets.to_i
h = gets.split.map(&:to_i)
count = -1
max = 0
prev = 1000000000
for i in 0...n do
  if h[i] <= prev
    count += 1
  else
    max = count if max < count
    count = 0
  end
  prev = h[i]
end
max = count if max < count
puts max


Measured memory_bytes: 8580
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


vector<pair<int,int>> soinsuu(int n){
    vector<pair<int,int>> ret;
    for(int i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));
    return ret;
}

int mod=pow(10,9)+7;

signed main(){ 
    int n,k; cin>>n>>k;

    int sum=0;

    for(int i=k;i<=(n+1);i++){
        int sma=i*(i-1)/2;
        int big=n*(n+1)/2 - (n-i+1)*(n-i)/2;

        sum+=(big-sma+1LL)%mod;
    }

    cout<<sum%mod<<endl;
}  

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

vector<vector<ll>> to(200005);
vector<ll> ans;

void dfs( ll v, ll p=-1 ){
  for( ll u : to.at(v) ){
    // 親にはdfsしない
    if( u == p ) continue;

    ans.at(u) += ans.at(v);
    dfs(u,v);
  }
}

int main(){
  ll n,q;cin >> n >> q;
  rep(i,n-1){
    ll a,b;cin >> a >> b;
    --a;--b;
    to.at(a).push_back(b);
    to.at(b).push_back(a);
  }
  ans.resize(n);
  rep(i,q){
    ll p,x;cin >> p >> x;
    --p;
    ans.at(p) += x;
  }
  dfs( 0 );
  rep(i,n){
    cout << ans.at(i);
    if( i != n-1 ) cout << " ";
    else cout << endl;
  }
  return 0;
}


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

int main(){
    long long H, W; cin >> H >> W;

    if(H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        if(H % 2 == 0) {
            cout << H / 2 * W << endl;
        } else if(H % 2 == 1) {
            if(W % 2 == 0) {
                cout << H / 2 * W + (W / 2) << endl;
            } else {
                cout << H / 2 * W + (W / 2 + 1) << endl;
            }
        }
    }
}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            if (input[2] * 2 >= input[1] - input[0] + 1)
            {
                for (int i = input[0]; i <= input[1]; i++)
                    Console.WriteLine(i);
            }
            else
            {
                for (int i = input[0]; i < input[0] + input[2]; i++)
                    Console.WriteLine(i);
                for (int i = input[1] - input[2] + 1; i <= input[1]; i++)
                    Console.WriteLine(i);
            }

#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 13268
MOD = 10 **9 + 7
INF = 10 ** 10

def main():
    N = int(input())
    w = input()
    W = {w}
    before = w
    flag = True
    for _ in range(N - 1):
        w = input()
        if w in W:
            flag = False
            break
        else:
            if before[-1] != w[0]:
                flag = False
                break
            before = w
            W.add(w)
    print('Yes' if flag else 'No')
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

signed main() { 
        int a, b, c;
        cin >> a >> b >> c;
        int ans = a * 100 + b * 10 + c;
        cout << (ans % 4 == 0 ? "YES" : "NO") << endl;
        return 0;
}               



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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    vector<int> AC(n + 1);
    vector<int> WA(n + 1);
    int ans1 = 0, ans2 = 0;
    for (int i = 0; i < m; i++){
        int x;
        string s;
        cin >> x >> s;
        if (AC[x] == 1) continue;
        if (s == "AC"){
            AC[x] = 1;
            ans1++;
            ans2 += WA[x];
        }
        else WA[x]++;
    }
    cout << ans1 << ' ' << ans2;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int inf=3e3+9;
string a,b;
int dp[inf][inf],n,m,par[inf][inf];
int main(){
 
    cin>>a>>b;
    n=a.size();
    m=b.size();
 
    for(int i=0;i<n;i++){
 
        for(int j=0;j<m;j++){
 
            if(i==0 || j==0){
                dp[i][j]=(a[i]==b[j]);
                if(dp[i][j])
                    par[i][j]=-1;
                if(i && dp[i-1][j] )
                    dp[i][j]=1,par[i][j]=1;
                if(j && dp[i][j-1])
                    dp[i][j]=1,par[i][j]=2;
                continue;
            }
            if(dp[i-1][j]>dp[i][j-1])
                par[i][j]=1;
            else par[i][j]=2;
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            if(a[i]==b[j] && dp[i-1][j-1]+1>dp[i][j])
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1),par[i][j]=-1;
        }
    }
   string ans="";
   int l=n-1,r=m-1;
   while(l>=0 && r>=0){
    if(par[l][r]==1)
        l--;
    else if(par[l][r]==2)
        r--;
    else if(par[l][r]==-1)
        ans+=a[l],l--,r--;
    else l--,r--;
   }
   reverse(ans.begin(),ans.end());
   cout<<ans<<endl;
}

Measured memory_bytes: 70912
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math


def get_int():return int(stdin.readline().strip())
def get_tuple():return map(int, stdin.readline().split())
def get_list():return list(map(int, stdin.readline().split()))

s = input()
t = input()
ans = float('inf')
n,m = len(s),len(t)
for i in range(n-m+1):
    c = 0
    for j in range(m):
        if s[i+j]!=t[j]: c+= 1
    ans = min(ans,c)
print(ans)


Measured memory_bytes: 9596
#include<stdio.h>
int main()
{
	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: 2600
#include<stdio.h>

int main()
{
    int b,f,r,v;
    int i,j,k,n,num;
    int Nin[4][3][10]={0};
    
    scanf("%d",&num);
    
    for(n=0; n<num; n++){
        scanf("%d %d %d %d",&b, &f, &r, &v);
        Nin[b-1][f-1][r-1] += v;
    }

    
    for(i=0; i<4; i++){
        for(j=0; j<3; j++){
            for(k=0; k<10; k++){
                printf(" %d" ,Nin[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3) printf("####################\n");
    }

    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  
  int ans = b;
  
  if(ans > n*a){
    ans = n*a;
    cout << ans << endl;
  }
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
class UF:
    def __init__(self, n):
        self.n = n
        self.tree = [-1] * n

    def union(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return

        if self.size(a) < self.size(b):
            tmp = a
            a = b
            b = tmp

        self.tree[a] += self.tree[b]
        self.tree[b] = a

    def size(self, a):
        return -self.tree[self.root(a)]

    def root(self, a):
        if self.tree[a] < 0:
            return a
        res = self.root(self.tree[a])
        self.tree[a] = res
        return res


n, m = map(int, input().split())
a = []
b = []
for _ in range(m):
    ai, bi = map(int, input().split())
    a.append(ai - 1)
    b.append(bi - 1)

uf = UF(n)

res = n * (n - 1) // 2
outs = [0] * m
for i in range(m - 1, -1, -1):
    outs[i] = res
    if uf.root(a[i]) != uf.root(b[i]):
        res -= uf.size(a[i]) * uf.size(b[i])
        uf.union(a[i], b[i])

for o in outs:
    print(o)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

string S;
signed main(){
    cin>>S;
    int a=count(all(S),'0');
    int b=S.size()-a;
    cout<<min(a,b)*2<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int n, m;
vector< pair<int, int> > p;

bool ss(int a){

  vector<int> vis(n, 0);
  queue<int> q;
  q.push(0);
  while( !q.empty() ){
    int pos = q.front();
    q.pop();
    vis[pos]++;
    for(int i=0; i<m; i++){
      if( i == a ) continue;
      if( p[i].first == pos && vis[p[i].second] == 0 ){
        q.push(p[i].second);
      }else if( p[i].second == pos && vis[p[i].first] == 0 ){
        q.push(p[i].first);
      }
    }
  }
  for(int i=0; i<n; i++){
    if( vis[i] == 0 ) return false;
  }
  return true;
}


int main() {

  cin >> n >> m;
  p.resize(m);
  for(int i=0; i<m; i++) cin >> p[i].first >> p[i].second;
  for(int i=0; i<m; i++){
    p[i].first--;
    p[i].second--;
  }

  int cnt = 0;
  for(int i=0; i<m; i++){
    if( !ss(i) ) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


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

int main(){
  string S;
  cin >> S;
  
  deque<char>d;
  rep(i,S.size()){
    d.push_back(S[i]);
  }
  bool ch1 = true; //反転してたらfalse
  ll n;
  cin >> n;
  rep(i,n){
    ll now;
    cin >> now;
    if(now ==1) ch1 = !ch1;
    else{
      ll f;
      cin >> f;
      if(f == 2){
        f = 0;
      }
      char t;
      cin >> t;
      if(f == ch1){ //f=1かつ反転していないとき
        d.push_front(t); //先頭に
      }
      else{
        d.push_back(t);
      }
    }
  }
  if(ch1){ //反転していないとき
    for(auto itr = d.begin(); itr!=d.end() ; itr++){
      cout << *itr;
    }
  }
  else{ //反転してる
    vector<char>x;
    for(auto itr = d.begin(); itr!=d.end(); itr++){
      x.push_back(*itr);
    }
    reverse(x.begin(),x.end());
    rep(i,x.size()){
      cout << x[i];
    }
    
  }
  cout << endl;
  
}


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

int main()
{
    int n,a;
    int x1,y1,xy[16][16];

    rep(i, 16)
        rep(j, 16)
            xy[i][j] = -1;

    cin >> n;
    rep(i, n) {
        cin >> a;
        rep(j, a) {
            cin >> x1 >> y1;
            xy[i][x1 - 1] = y1;
        }
    }

    int ans = 0;
    rep(bit, (1 << n)) {
        vector<int> nn(n);
        int bitcnt = 0;
        rep(i, n)
            if ((bit >> i) & 1) {
                nn[i] = 1;
                ++bitcnt;
            }

        bool ok = true;
        rep(i, n) {
            if (nn[i] == 1) {
                rep(j, n) {
                    if (xy[i][j] == -1)
                        continue;
                    if (xy[i][j] != nn[j])
                        ok = false;
                }
            }
        }
        if (ok == true)
            ans = max(ans,bitcnt);
    }

    cout << ans << endl;
}

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

int main() {
    int p,q,r;
    cin >> p >> q >> r;

    int s = p+q+r;
    cout << s-max(p,max(q,r));
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

def solve():
    global S, T
    if len(S) < len(T):
        print("UNRESTORABLE")
        return

    inds = []
    for i in reversed(range(len(S) - len(T) + 1)):
        s = S[i:i+len(T)]
#         print(i, S[i], S[i:i+len(T)])

        yes = True
        for j in range(len(s)):
#             print(T[j], s[j])
            if s[j] == '?' or s[j] == T[j]:
                continue
            else:
                yes = False
                break
        if yes:
            inds.append(i)
#     print(inds)
    if len(inds) == 0:
        print("UNRESTORABLE")
        return
    
    ans = []
    for ind in inds:
        ss = S[:]
        for i in range(len(S)):
            if ind<= i < ind+len(T):
                ss[i] = T[i-ind]
            elif  ss[i] == '?':
                ss[i] = 'a'
        ans.append(ss)
#     print(ans)
    ans = list(map(lambda x: ''.join(x), ans))
    print(min(ans))
        
solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PI;
typedef pair< PI, int> PII;
#define pb push_back
#define Key_value ch[ch[root][1]][0]
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define MS(x,y) memset(x,y,sizeof(x))
const double eps = 1e-8;
const double pi = acos (-1.0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int M = 1000100;
const int MAXN = 10010;
const int MAXM = 100010;



int main()
{
    LL n, m;
    cin >> n >> m;
    LL ans = 0;
    if(n < m / 2)
    {
        ans += n;
        m -= n * 2;
        ans += m / 4;
        cout << ans << endl;
        return 0;
    }
    else if(n > m / 2)
    {
        ans += m / 2;
        cout << ans << endl;
        return 0;
    }
    else
    {
        ans += m / 2;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long

using namespace std;


int main() {
	pair<double,string> pea;
	int N;
	cin >> N;
	double sum = 0;
	rep(i, N) {
		cin >> pea.first;
		cin >> pea.second;
	
		if (pea.second == "BTC") {
			sum += pea.first * 380000;
		}
		else if (pea.second == "JPY") {
			sum += pea.first;
		}
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 100;
int a[maxn];
int main(){
   int n;
   scanf("%d",&n);
   int pr = 0;
   int tot = 0;
   for (int i = 0; i < n; i++){
     scanf("%d",&a[i]);
     tot += abs(pr - a[i]);
     pr = a[i];
   }
   tot += abs(pr);
   //cout<<tot<<endl;
   for (int i = 0; i < n; i++){
        int res = tot - (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1]);
        cout<<res<<endl; 
   }
} 

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int get_time(int h, int m, int s){
  return (h / 5) * 3600 + m * 60 + s;
}

string toStr(int S){
  int h = S / 3600;
  int m = S % 3600 / 60;
  int s = S % 60;
  ostringstream o;
  o << setw(2) << setfill('0') << h % 24 << ":"
    << setw(2) << setfill('0') << m << ":"
    << setw(2) << setfill('0') << s;
  return o.str();
  
}

int main(){
  int n;
  while(cin >> n && n){
    vector<P> event;
    
    REP(i, n){
      vector<int> p(3), v(3), tmp_v(3);
      REP(j, 3) cin >> v[j];
      REP(j, 3) p[j] = j;
      
      do{
        REP(j, 3) tmp_v[j] = v[p[j]];
        
        REP(j, 60){
          vector<int> ts;
          ts.push_back(get_time(tmp_v[0], tmp_v[1], tmp_v[2]));
          ts.push_back(get_time(tmp_v[0] + 60, tmp_v[1], tmp_v[2]));
          REP(k, 2){
            int t = tmp_v[0] % 5;
            if(12 * t <= tmp_v[1] && tmp_v[1] < 12 * (t + 1)){
              event.push_back(P(ts[k], i));
            }
          }
          REP(k, 3) tmp_v[k] = (tmp_v[k] + 1) % 60;
        }
      }while(next_permutation(ALL(p)));
    }
    
    sort(ALL(event));
    event.erase(unique(ALL(event)), event.end());
    int best = INF;
    string start, last;
    
    size_t l = 0, r = 0;
    int count = 0;    
    vector<int> icount(n, 0);
    
    while(l < event.size()){
      while(r < event.size() && count < n){
        if(icount[event[r++].second]++ == 0) count++;
      }
      
      if(count == n){
        int range = event[r-1].first - event[l].first;
        
        if(range < best){
          best = range ;
          start = toStr(event[l].first);
          last =  toStr(event[r-1].first);
        }
      }
      
      if(--icount[event[l++].second] == 0) count--;
    }
    cout << start <<" "  << last << endl;
  }

  return 0;
}

Measured memory_bytes: 1312
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

pair<int, int>getco(const int num, const int w) {
	return make_pair(num / w, num%w);
}
int getdis(const pair<int, int>&l, const pair<int, int>&r) {
	return abs(l.first - r.first) + abs(l.second - r.second);
}

int main() {
	int N; cin >> N;
	int a, b, c, d; cin >> a >> b >> c >> d;
	a--; b--; c--; d--;
	int ans = 1e9;
	for (int w = 1; w < 1001; ++w) {
		auto aco = getco(a, w);
		auto bco = getco(b, w);
		auto cco = getco(c, w);
		auto dco = getco(d, w);
		ans = min(ans, getdis(aco, bco) + getdis(cco, dco));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3100
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    else:
        re += 1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 69836
import java.util.*;

// {U,R,D,L}:{0,1,2,3}

public class Main {
    int[] dx = {0,1,0,-1};
    int[] dy = {-1,0,1,0};
    String[] direction = {"U","R","D","L"};

    void run(){
        Arc arc = new Arc(5);
 //       arc.printArc();
        int x = 0, y = 0, d = 2;
        while (true) {
            d = arc.getNextP(x,y,d);
            x = x+dx[d];
            y = y+dy[d];
            System.out.print(direction[d]);
            if (x == 0 && y == 0){
                System.out.println();
                break;
            }
        }
    }

    class Arc {
        int[][] arc;
        Scanner sc;
        int size;
        Arc(int size) {
            this.size = size;
            sc = new Scanner(System.in);
            arc = new int [2*(size+1)+1][size+2];
            for (int i=0;i<2*(size+1)+1;i++) {
                for (int j=0;j<size+2;j++) arc[i][j] = 0;
            }
            String line;
            for (int i=2;i<2*size+1;i++) {
                line = sc.next();
                if (i%2 == 0) {
                    for (int j=1;j<size;j++)
                        arc[i][j] = line.charAt(j-1)-'0';
                }
                else {
                    for (int j=1;j<size+1;j++)
                        arc[i][j] = line.charAt(j-1)-'0';
                }
            }
        }

        int[] dx = {1,1,1,0};
        int[] dy = {-1,0,1,0};
        int getNextP(int x,int y, int d) {
            for (int i=3;i<7;i++) {
                if (arc[2*(y+1)+dy[(d+i)%4]][x+dx[(d+i)%4]] == 1) return (d+i)%4;
            }
            return -1;
        }
        void printArc() {
            for (int i=0;i<2*(size+1)+1;i++) {
                for (int j=0;j<size+2;j++) {
                    System.out.print(arc[i][j] + " ");
                }
                System.out.println();
            }
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 0
# 入力
N = int(input())
a = list(map(int, input().split()))

b = [x for x in a]
c = 0
while max(b) >= N:
    i = max(range(N), key=lambda i: b[i])
    c += b[i] // N
    for j in range(N):
        if j != i:
            b[j] += b[i] // N
    b[i] %= N

ans = c

# 出力
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr int inv(LL x, int m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr int mpow(LL a, LL k, int m) { int r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

const int N = 2e5 + 5;
int n, A[N], S[N * 3];
LL L[N], R[N];

void calc(LL *F) {
    for (*S = 0; *S < n;) S[++*S] = 0;
    LL sum = 0;
    FI(i, 2, n) {
        LL x = A[i - 1], y = A[i];
        while (x < y) sum += i - 1 - S[(*S)--], x *= 4;
        while (x >= y * 4) S[++(*S)] = i - 1, y *= 4;
        F[i] = sum * 2;
    }
}

int main() {
    scanf("%d", &n);
    FI(i, 1, n) scanf("%d", A + i);
    calc(L), reverse(A + 1, A + 1 + n), calc(R);
    LL ans = LLONG_MAX;
    FI(i, 1, n) ans = min(ans, L[i - 1] + i - 1 + R[n - i + 1]);
    printf("%lld\n", ans);
}


Measured memory_bytes: 6528
inp = [int(input()) for i in range(10)]
m1, m2, m3 = 0, 0, 0
for h in inp:
    if(h > m1):
        m3 = m2
        m2 = m1
        m1 = h
    elif(h > m2):
        m3 = m2
        m2 = h
    elif(h > m3):
        m3 = h
print(m1)
print(m2)
print(m3)

Measured memory_bytes: 7724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int temp;
        int temp2;
        int temp3;

        if( X % 5 == 0) {
            System.out.println(X*2);
        } else if (X % 5 != 0) {
            temp = X - (X%5);
            temp2 = (temp / 500) * 1000;
            temp3 = temp % 500;
            System.out.println(temp2 + temp3);
        }
    }
}

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

int main(){
  int N,t,i,A=0,p=1;
  cin >> N;
  for(i=0;i<N;i++){
    cin >> t;
    while(t%2==0){
      t /= 2;
      A++;
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256