akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
vector<int> ans;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int szam;
        cin>>szam;
        a.push_back(szam);
    }
    while(a.size()>0)
    {
        int good=-1;
        for(int i=0; i<a.size(); i++)
        {
            if(i+1==a[i])
            {
                good=i;
            }
        }
        if(good==-1)
        {
            cout<<-1<<endl;
            return 0;
        }
        ans.push_back(a[good]);
        for(int i=good+1; i<a.size(); i++)
        {
            a[i-1]=a[i];
        }
        a.pop_back();
    }
    for(int i=(int)(ans.size())-1; i>=0; i--)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n,k,*l=map(int,open(0).read().split());l.sort();c,a,M=1,0,10**9+7
for i in range(k-1,n):a+=c*(l[i]-l[~i]);c=c*-~i*pow(i-k+2,M-2,M)%M
print(a%M)

Measured memory_bytes: 14060
#include<bits/stdc++.h>
#define show(x) cout<<#x" = "<<x<<endl;
#define show2(x,y) cout<<#x" = "<<x<<" "<<#y<<" = "<<y<<endl;
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> iipair;
typedef pair<unsigned,unsigned> uupair;
typedef vector<int> vec;
typedef vector<unsigned> uvec;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    unsigned n;
    vec a;
    cin>>n;
    a.resize(n);
    for(unsigned i=0;i<n;cin>>a[i++]);
    sort(a.begin(),a.end());
    for(unsigned i=0;i<a.size()-1;++i)
    {
        if(a[i] == a[i+1])
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";

}

Measured memory_bytes: 1024
#include <stdio.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))
int main(void){
	char c[1002];
	int fr[2][1000],n,i,j,x,ans;
	while(scanf("%d",&n)){
		if(n==0)break;
		ans=0;
		fgets(c,1002,stdin);
		for(i=0;i<n;i++){
			fgets(c,1002,stdin);
			for(j=0;j<n;j++){
				if(c[j]=='.'){
					if(i==0 || j==0)fr[1][j]=1;
					else {
						x=MIN(MIN(fr[1][j-1],fr[0][j]),fr[0][j-1])+1;
						if(ans<x)ans=x;
						fr[1][j]=x;
					}
				}
				else fr[1][j]=0;
			}
			for(j=0;j<n;j++){fr[0][j]=fr[1][j];}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
    int n,tmp,a = 0,b = 0;
    bool judge;
    cin >> n;
    while(n--){
        judge = true;
        a = 0;
        b = 0;
        for(int i=0;i<10;i++){
            cin >> tmp;
            if(tmp > a) a = tmp;
            else if(tmp > b) b = tmp;
            else judge = false;
        }
        if(judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

namespace procon
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            while (true) {
                var nr = Console.ReadLine ().Split (' ').Select (e => int.Parse (e)).ToArray ();
                int n = nr [0];
                int r = nr [1];

                if (n == 0 && r == 0)
                    break;
                else {
                    solve (n, r);
                }
            }
        }

        public static void solve (int n, int r)
        {
            int[] cards = new int[n];
            for (int i = 0; i < n; i++) {
                cards [i] = n - i;
            }

            for (int i = 0; i < r; i++) {
                int[] pc = Console.ReadLine ().Split (' ').Select (e => int.Parse (e))
                    .ToArray ();
                int p = pc [0] - 1;
                int c = pc [1];
                int[] former = cards.Skip (p).Take (c).ToArray ();
                int[] latter = cards.Take (p).ToArray ();
                int[] rest = cards.Skip (p + c).Take (cards.Length - p - c).ToArray ();
                cards = former.Concat (latter).Concat (rest).ToArray ();
            }

            Console.WriteLine (cards [0]);
        }
    }
}

Measured memory_bytes: 6260
#include<bits/stdc++.h>
    #define ll long long
    #define db double
    #define mod 1000000007
    #define pb push_back
    #define pp pair<ll,ll>
    #define rep(i,a,b) for(ll i=a;i<b;i++)
    #define repe(i,a,b) for(ll i=a;i<=b;i++)
    #define repr(i,a,b) for(ll i=b;i>=a;i--)
    #define maxn 200005
    #define ss second
    #define ff first
    #define lb lower_bound
    using namespace std;
    void solve()
    {
        ll n,m;
        cin >> n >> m;
        ll i=1,j=n,x=0;
        map<ll,ll> mp;
        while(x < m)
        {
            if(mp[j-i] == 0 and mp[n-(j-i)]==0 and j-i != n-(j-i))
            {
                cout << i <<" " << j <<"\n";
                mp[j-i]++;
                mp[n-(j-i)]++;
                i++,j--;
                x++;
            }
            else{
                j--;
            }
        }
    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll t=1;
        //cin >> t;
        while(t--)
        solve();
        return 0;
    }

Measured memory_bytes: 14844
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll H, W; cin >> H >> W;
	vector<string> MAP(H);
	FOR(i, H)
		cin >> MAP[i];
	vector<vector<char>> SWAPPED_MAP(W, vector<char>(H ));
	FOR(i, H) {
		FOR(j,W) {
			SWAPPED_MAP[j][i] = MAP[i][j];
		}
	}
	
	auto FINAL_MAP = make_v(H, W,0LL);
	
	// 横方向
	FOR(i, H) {
		// 左から
		vector<ll> tmp_left(W, 0);
		vector<ll> tmp_rigt(W, 0);
		ll cnt = 0;
		/*for (auto c : MAP[i]) {*/
		FOR(j, W) {			auto c = MAP[i][j];
			if (c == '.') {
				cnt += 1;
				tmp_left[j] = cnt;
			}
			else {
				cnt = 0;
			}
		}
		cnt = 0;
		FOR(_j, W) {
			auto j = W - 1 - _j;
			auto c = MAP[i][j];
			if (c == '.') {
				cnt += 1;
				tmp_rigt[j] = cnt;
			}
			else {
				cnt = 0;
			}
		}
		FOR(j, W) {
			FINAL_MAP[i][j] = tmp_left[j] + tmp_rigt[j];
		}
	}
	// 縦方向
	swap(H, W);
	FOR(i, H) {
		// 左から
		vector<ll> tmp_left(W, 0);
		vector<ll> tmp_rigt(W, 0);
		ll cnt = 0;
		/*for (auto c : MAP[i]) {*/
		FOR(j, W) {
			auto c = SWAPPED_MAP[i][j];
			if (c == '.') {
				cnt += 1;
				tmp_left[j] = cnt;
			}
			else {
				cnt = 0;
			}
		}
		cnt = 0;
		FOR(_j, W) {
			auto j = W - 1 - _j;
			auto c = SWAPPED_MAP[i][j];
			if (c == '.') {
				cnt += 1;
				tmp_rigt[j] = cnt;
			}
			else {
				cnt = 0;
			}
		}
		FOR(j, W) {
			//FINAL_MAP[i][j] += tmp_left[j] + tmp_rigt[j];
			FINAL_MAP[j][i] += tmp_left[j] + tmp_rigt[j];
		}
	}

	swap(H, W);
	ll ans = 0;
	FOR(i, H) FOR(j, W)
		chmax(ans, FINAL_MAP[i][j]);
	cout << ans - 3 << endl;
	return 0;
}


Measured memory_bytes: 39680
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  ll a;
  ll cnt = 0, bef =0;
  rep(i, n){
    cin >> a;
    cnt += (a+bef)/2;
    bef = (a+bef)%2;
    if (a==0) bef = 0;

  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#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;
static const int INF (1<<30);

int main() {
  int N; cin >> N;
  vector<int> a(N);
  int first = 0, second = 0;
  rep(i, N) {
    int x;
    cin >> x;
    a[i] = x;

    if (x >= first) {
      second = first;
      first = x;
    } else if (x > second) {
      second = x;
    }
  }


  rep(i, N) {
    int y = a[i];
    if (y == first) {
      cout << second << endl;
    } else {
      cout << first << endl;
    }
  }
    

  return 0;
}

Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main(){

	int n = 0;
	int x = 0;

	cin >> n;

	for (int i = 1; i <= n; i++) {

		x = i;

		if (x % 3 == 0) {

			cout << " " << i;

		}
		else {

			while (x) {

				if (x % 10 == 3) {

					cout << " " << i;
					break;

				}

				x /= 10;

			}

		}

	}

	cout << endl;
	

	return 0;

}



Measured memory_bytes: 3116
#include <iostream>
using namespace std;
int N, M;
int DP[2][6005][2];
const int MOD = 1000000007;
void Add(int& x, int y)
{
    x += y;
    if(x >= MOD)
        x -= MOD;
}
void Solve()
{
    for(int i = 0; i <= N; i++)
        DP[0][i][0] = 1;
    int ind = 1;
    for(int i = 1; i <= M; i++, ind = 1 - ind)
    {
        for(int j = 0; j <= N; j++)
        {
            for(int k = 0; k <= 1; k++)
            {
                DP[ind][j][k] = 0;
            }

        }
        for(int j = 0; j <= N; j++)
        {
            for(int k = 0; k <= 1; k++)
            {
                if(j >= 1)
                {
                    if(j > 1 || (j == 1 && k == 1))
                        Add(DP[ind][j - 1][k], DP[1 - ind][j][k]);
                }
                if(j >= 1)
                {
                    if(j > 1 || (j == 1 && k == 1))
                        Add(DP[ind][j][k], DP[1 - ind][j][k]);
                }
                if(j < N)
                {
                    if(j > 0 || (j == 0 && k == 1))
                    Add(DP[ind][j + 1][k], DP[1 - ind][j][k]);
                }
                if(j < N)
                {
                    if(j > 0 || (j == 0 && k == 1))
                    Add(DP[ind][j][k], DP[1 - ind][j][k]);
                }
            }
        }
        Add(DP[ind][0][1], DP[1 - ind][1][0]);
        Add(DP[ind][1][1], DP[1 - ind][1][0]);
        Add(DP[ind][1][1], DP[1 - ind][0][0]);
        Add(DP[ind][0][1], DP[1 - ind][0][0]);
    }
    ind = 1 - ind;
    int ans = 0;
    for(int i = 0; i <= N; i++)
        Add(ans, DP[ind][i][1]);
    cout << ans << "\n";
}
int main()
{
    cin >> N >> M;
    Solve();
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    char[] cs;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int x = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            if (cs[i] == 'I') {
                x++;
                if (max < x) {
                    max = x;
                }
            } else {
                x--;
            }
        }
        System.out.println(max);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21332
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 
unordered_map<ll, ll> parent ;
void makeset(ll x) {
	parent[x] = x;
}
ll findset(ll x) {
	if(x == parent[x]) return x;
	return parent[x] = findset(parent[x]) ;
}
void unioset(ll x, ll y) {

	if(x > y) swap(x, y);
	parent[y] = x;
} 
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, m;
  cin >> n >> m;
  vector<pll> vc ;
  for(ll i = 0; i < n; i++) {
  	ll x, y;
  	cin >> x >> y;
  	if(x <= m) {
  		vc.pb(mp(y, x));
  	}
  }
  for(ll i = 0; i <= m; i++) makeset(i) ;
  sort(all(vc), greater<pll>());
  // vector<ll> visited(m+1, false);
  ll sum = 0;
  for(auto it: vc) {
      ll x = it.first, y = it.second ;
      y = m - y;
      ll tt = findset(y+1) ;
      tt-- ;
      if(tt >=0) {
      	sum+=x;
      	unioset(tt, tt+1) ;
      }
  }
  cout << sum << endl;
  return 0;
} //good night.

Measured memory_bytes: 6000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        //ABC065
        Scanner cin = new Scanner();
        int N = cin.Int();
        var a = cin.ArrayInt(N);

        var color = new int[9]; //color[0]からcolor[7]は灰色から赤色までに対応、colot[8]はレート3200以上に対応
        foreach(var x in a)
        {
            if (1 <= x && x <= 399) color[0]++;
            else if (400 <= x && x <= 799) color[1]++;
            else if (800 <= x && x <= 1199) color[2]++;
            else if (1200 <= x && x <= 1599) color[3]++;
            else if (1600 <= x && x <= 1999) color[4]++;
            else if (2000 <= x && x <= 2399) color[5]++;
            else if (2400 <= x && x <= 2799) color[6]++;
            else if (2800 <= x && x <= 3199) color[7]++;
            else color[8]++;
        }

        int min_ans = 0;
        for(int i = 0; i <= 7; i++)
        {
            if (color[i] > 0) min_ans++;
        }

        if (min_ans == 0) Console.WriteLine(1 + " " + color[8]);
        else Console.WriteLine(min_ans + " "  + (min_ans + color[8]));
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  vector<pair<int, string> > v;
  for (auto e : mp) v.eb(-e.S, e.F);
  sort(all(v));

  rep(i, sz(v)) {
    if (v[i].F == v[0].F) {
      cout << v[i].S << endl;
    }
  }
}


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


int main()
{
    //freopen("A-small-practice.in","r",stdin);
    //freopen("A-large-practice.in","r",stdin);
    //freopen("output.out","w",stdout);

    /*int n;
    cin>>n;
    int A[n];

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

    int dp[(1<<n)-1][n];

    for(int mask = 0;mask < (1<<n);mask++) {
      for(int j = 0;j < n;j++) {


        if(((1<<j)&(mask)) == 0) {
          dp[mask][j] = 0;
        }

        else if(((~(1<<j))&(mask)) == 0) {
            dp[mask][j] = A[j]*2;
        }

        else {
          int t = (~(1<<j))&(mask);
          int ans = 0;
          for(int i=0;i<n;i++) {

            if((1<<i)&(t))
              ans = max(ans, (A[j] > A[i]) ? 2*(A[j]-A[i]) + dp[t][i] : dp[t][i]);
          }

          dp[mask][j] = ans;
          cout<<"hello";
        }



      }
    }

    for(int i=0;i<(1<<n);i++) {
      for(int j=0;j<n;j++) {
        cout<<dp[i][j]<<" ";
      }cout<<endl;
    }*/

  int n;
  int A[300];
  cin>>n;
  for(int i=0;i<2*n;i++) cin>>A[i];
  sort(A, A+2*n);
  int ans = 0;
  for(int i=0;i<2*n;i+=2) {
    ans += A[i];
  }
  cout<<ans;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=5005;
int n,k;
int a[maxn];
bool dp[maxn][maxn];
bool check(int mid)
{
    if(a[mid]>k)
    return 1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<k;j++)
        {
            if(!dp[i][j])
            continue;
            if(i!=mid)
            {
                int next=min(a[i]+j,k);
                dp[i+1][next]=1;
            }
            dp[i+1][j]=1;
        }
    }
    for(int i=k-a[mid];i<k;i++)
    {
        if(dp[n][i])
        return 1;
    }
    return 0;
}
int main()
{ 
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
	}
    sort(a,a+n);
    int l=-1,r=n,mid;
    while(l+1<r)
    {
        mid=(l+r)/2;
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        if(check(mid))
        r=mid;
        else
        l=mid;
    }
    cout<<l+1;
    return 0;
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll h, a;
    cin >> h >> a;
    ll res = h / a;
    if (h % a) res++;
    cout << res << endl;
    return 0;
}

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

int main() {
  char alpha;
  cin >> alpha;
  if(isupper(alpha)) cout << 'A' << endl;
  else cout << 'a' << endl;
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define MIN(c) (*min_element(ALL(c))) 
#define MAX(c) (*max_element(ALL(c)))
#define ACC(c) (accumulate(ALL(c), 0))
#define SLL(x, n) ((x) << (n))
#define SRL(x, n) ((x) >> (n))
#define MIN2(a, b) ((a) < (b)) ? (a) : (b)
#define MAX2(a, b) ((a) > (b)) ? (a) : (b)
#define MP(a, b) (make_pair((a), (b)))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

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

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.second < y.second);};

int N;
vector<int> c;
int d[10000];
bool visited[10000];
vector<int> adj[10000];

int dfs(int node, int prev){
    if(visited[node]) return 0;
    visited[node] = true;
    d[node] = c.back();
    c.pop_back();
    int ret = MIN2(prev, d[node]);
    for(auto next : adj[node]){
        ret += dfs(next, d[node]);
    }
    return ret;
}

signed main(){
    cin >> N;
    int a, b;
    REP(i, N - 1){
        cin >> a >> b;
        adj[a - 1].push_back(b - 1);
        adj[b - 1].push_back(a - 1);
    }
    REP(i, N){
        cin >> a;
        c.push_back(a);
    }
    sort(ALL(c));
    REP(i, N) visited[i] = false;
    int M = dfs(0, 0);
    PRINT(M);
    REP(i, N){
        cout << d[i];
        if(i < N - 1) cout << " ";
    }
    cout << ENDL;
    return 0;
}

Measured memory_bytes: 1408
import java.util.AbstractMap;
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();
		sc.nextLine();

		String[] p = new String[n];
		int[] t = new int[n];
//		LinkedHashMap<String, Integer> hmi = new LinkedHashMap<>();
//		LinkedHashMap[] hm = new LinkedHashMap[n];
		ArrayDeque<AbstractMap.SimpleEntry<String, Integer>> ad =
				new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			p[i] = sc.next();
			t[i] = sc.nextInt();
//			hmi.put(p[i], t[i]);
//			( (LinkedHashMap<String, Integer>) hm[i] ).put(p[i], t[i]);
			AbstractMap.SimpleEntry<String, Integer> pair =
					new AbstractMap.SimpleEntry<>(p[i], t[i]);
			ad.add(pair);
		}

//		System.out.println(Arrays.toString(p));
//		System.out.println(Arrays.toString(t));
//		System.out.println(ad.poll());

		int time = 0;
		while (!ad.isEmpty()) {
			AbstractMap.SimpleEntry<String, Integer> pair = ad.poll();
			// pt: pair time
			int pt = pair.getValue() - q;
			// pp : pair name
			String pn = pair.getKey();

			if (pt > 0) {
				pair.setValue(pt);
				ad.add(pair);
				time += q;
			} else {
				time += pair.getValue();
				System.out.println(pn + " " + time);
			}
		}
	}
}

Measured memory_bytes: 74240
import java.util.Scanner;

public class Main {
	int[][] parent;
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] nrs = in.nextLine().split(" "); // nrs stands for nodes and relations
		int nodes = Integer.parseInt(nrs[0]);
		int rels = Integer.parseInt(nrs[1]);
		Main graph = new Main(nodes);
		for (int i = 0; i < nodes; i++) {
			graph.set(i);
		}
		
		for (int i = 0; i < rels; i++) {
			String[] holder = in.nextLine().split(" ");
			int num1 = Integer.parseInt(holder[0]);
			int num2 = Integer.parseInt(holder[1]);
			graph.union(num1, num2);
		}
		int q = in.nextInt();
		String lastSeen = "";
		for (int i = 0; i < q; i++) {
			
			int q1 = in.nextInt();
			int q2 = in.nextInt();
			if (graph.find(q1) == graph.find(q2)) {
				System.out.println("yes");
			}
			else {
				System.out.println("no");
			}
		}
		
	}
	
	public Main(int n) {
		// Each node will have a degree to which indicates the length of its subtree
		parent = new int[n][2];
	}
	
	
	public void set(int x) {
		parent[x] = new int[] {x, 0};
		
	}
	
	// Union function
	public void union(int x, int y) {
		int[] r1 = find(x);
		int[] r2 = find(y);
		// If r1 is the smaller tree 
		if (r1[1] < r2[1] ) {
			parent[r1[0]] = r2;			
		}
		else if (r1[1] > r2[1]) {
			parent[r2[0]] = r1;
		}
		else {
			parent[r2[0]] = r1;
			parent[r1[0]][1] += 1;
		}
	}
	
	// Find parent function
	public int[] find(int x) {
		int[] curr = parent[x];
		while(parent[curr[0]][0] != curr[0]) {
			curr = parent[curr[0]];
		}
		return curr;
	}
	
}




Measured memory_bytes: 171816
#include <stdio.h>
int main()
{
	int L, A, B, C, D, ansa, ansb, ansc, ans;
	scanf("%d",&L);
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
	ansa = A/C;
	if(A%C != 0){
		ansa += 1;
	}
	ansb = B/D;
	if(B%D != 0){
		ansb += 1;
	}
	if(ansa >= ansb){
		ansc = ansa;
	}else{
		ansc = ansb;
	}
	ans = L - ansc;
	printf("%d\n",ans);
	return 0;
}

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

bool cmp_le(string const & a, string const & b) {
    int i = 0;
    int j = 0;
    while (i < a.size() and j < b.size()) {
        if (isdigit(a[i]) and isdigit(b[j])) {
            ll x = 0;
            ll y = 0;
            for (; i < a.size() and isdigit(a[i]); ++ i) x = 10 * x + a[i] - '0';
            for (; j < b.size() and isdigit(b[j]); ++ j) y = 10 * y + b[j] - '0';
            if (x != y) return x <= y;
        } else {
            if (a[i] != b[i]) return a[i] <= b[i];
            ++ i;
            ++ j;
        }
    }
    if (i < a.size()) return false;
    if (j < b.size()) return true;
    assert (a == b);
    return true;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    REP (i, n) {
        string t; cin >> t;
        cout << (cmp_le(s, t) ? '+' : '-') << endl;
    }
    return 0;
}



Measured memory_bytes: 3208
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>

#define ll long long
#define ld long double
#define ull unsigned ll
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  Inf = 2 * 1000 * 1000 * 1000;
ll LINF = (ll)4e18;
using namespace std;
#define M_PI       3.14159265358979323846   // pi

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

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	vector<int>a(5);
	for (auto &x : a) cin >> x;

	int mn = 2e9;

	do {
		int time = 0;

		for (auto &x : a) {
			if (time % 10) {
				time /= 10;
				time *= 10;
				time += 10;
			}
			time += x;
		}
		mn = min(mn, time);
	} while (next_permutation(all(a)));
	cout << mn;
 	return 0;
}

Measured memory_bytes: 256
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        Set<Integer> set = new HashSet<>();
        for(int i=0; i<N; i++){
            set.add(nextInt());
        }

        println(N==set.size() ? "YES" : "NO");
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


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

    map <string, int> mp;
    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        mp[s]++;
    }
    for (auto s : {"AC", "WA", "TLE", "RE"}) {
        auto ptr = mp.find({s});
        if (ptr != mp.end()) {
            cout << s << " x " << (*ptr).second << endl;
        } else {
            cout << s << " x " << 0 << endl;
        }

    }
}

Measured memory_bytes: 3588
function main(input){
    let nums = input.split(" ").map(item=>parseFloat(item));
    let d = Math.sqrt((Math.pow(nums[0]-nums[2],2)+Math.pow(nums[1]-nums[3],2)))
    console.log(d);

}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 15464
#!/usr/bin/env python
# -*- coding: utf-8 -*-
while True:
    n = input()
    if n == 0:
        break
    a = []
    b = []
    sa = 0
    sb = 0
    for i in range(0, n):
        card = map(int, raw_input().split())
        a.append(card[0])
        b.append(card[1])
    for i in range(0, n):
        if a[i] > b[i]:
            sa += a[i] + b[i]
        elif a[i] < b[i]:
            sb += a[i] + b[i]
        else:
            sa += a[i]
            sb += a[i] 
    print sa, sb

Measured memory_bytes: 4736
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		String s = sc.next();
		
		if(a < 3200) {
			System.out.println("red");
		}else {
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 23636
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
h = Counter()
for x in a:
    h[x] += 1
f = True
for k, v in h.most_common():
    if n % 2 == 1 and k == 0:
        if v != 1:
            f = False
            break
    elif v != 2:
        f = False
        break
MOD = 1000000007
def mpow(n, p, mod):
    r = 1
    while p > 0:
        if p & 1 == 1:
            r = r * n % mod
        n = n * n % mod
        p >>= 1
    return r
print(mpow(2, n // 2, MOD) if f else 0)

Measured memory_bytes: 16096
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	int N, W;
	scanf("%d%d", &N, &W);
	vector<ll> vec[4];
	ll w1;
	for(int i = 1; i <= N; i++) {
		int w, v;
		scanf("%d%d", &w, &v);
		if(i == 1) w1 = w;
		vec[w - w1].PB(v);
	}
	for(int i = 0; i < 4; i++) {
		vec[i].PB(1e9 + 100);
		sort(ALL(vec[i]));
		reverse(ALL(vec[i]));
		vec[i][0] = 0;
		for(int j = 1; j < SZ(vec[i]); j++)
			vec[i][j] += vec[i][j - 1];
	}
	ll ans = 0;
	for(int i0 = 0; i0 < SZ(vec[0]); i0++)
	for(int i1 = 0; i1 < SZ(vec[1]); i1++)
	for(int i2 = 0; i2 < SZ(vec[2]); i2++) {
		ll Wuse = i0 * w1 + i1 * (w1 + 1) + i2 * (w1 + 2);
		ll Wremain = (ll)W - Wuse;
		if(Wremain < 0) continue;
		int get = min(SZ(vec[3]) - 1, (int)Wremain / ((int)w1 + 3));
		ans = max(ans, vec[0][i0] + vec[1][i1] + vec[2][i2] + vec[3][get]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = []
n.times do |i|
  if i % 2 == 0
    b.push(a[i])
  else
    b.unshift(a[i])
  end
end
if n % 2 != 0
  b.reverse!
end
puts b.join(" ")

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

int main() {
  char c;
  cin >> c;

  if( c == 'a'|| c == 'i'|| c == 'u'|| c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }
  
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(q)]

import itertools
cr = itertools.combinations_with_replacement(range(1, m+1), n)
M = 0
for seq in cr:
  score = sum([d for a, b, c, d in abcd if seq[b-1] - seq[a-1] == c])
  M = max(M, score)
print(M)

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

using namespace std;

int te[5],Dte[4];
int ans[5];

int main(void){
	int a;
	while(1){
		for(a=0;a<5;a++)te[a]=0,ans[a]=0;
		for(a=0;a<4;a++)Dte[a]=0;
		for(a=0;a<5;a++){
			cin >> te[a];
			Dte[te[a]]=1;
			if(te[a]==0)break;
		}
		if(te[0]==0)break;
		if(Dte[1]==1 && Dte[2]==1 && Dte[3]==1)for(a=0;a<5;a++)ans[a]=3;
		else if(Dte[1]==1 && Dte[2]==1 && Dte[3]==0){
			for(a=0;a<5;a++)if(te[a]==1)ans[a]=1;else if(te[a]==2)ans[a]=2;
		}else if(Dte[1]==0 && Dte[2]==1 && Dte[3]==1){
			for(a=0;a<5;a++)if(te[a]==2)ans[a]=1;else if(te[a]==3)ans[a]=2;
		}else if(Dte[1]==1 && Dte[2]==0 && Dte[3]==1){
			for(a=0;a<5;a++)if(te[a]==3)ans[a]=1;else if(te[a]==1)ans[a]=2;
		}else for(a=0;a<5;a++)ans[a]=3;
		for(a=0;a<5;a++){
			cout << ans[a] <<endl;
		}
	}
	return 0;
}

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

result =[]
while len(a) > 0:
    ok = False
    for i in range(len(a)-1, -1, -1):
        if i+1 == a[i]:
            result.append(a[i])
            a.pop(i)
            ok = True
            break
    if not ok:
        result = [-1]
        break
for i in result[::-1]: print(i)

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}


main(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  vector<ll> divisible_two(n);
  rep(i,n){
    ll v = a[i];
    ll cnt = 0;
    while(!(v&1)){
      cnt++;
      v>>=1;
    }
    divisible_two[i] = cnt;
  }

  map<ll,ll> mp;
  for(auto x:divisible_two)mp[(x>=2?2:x)]++;

  if(mp[2]>=mp[0]+mp[1])puts("Yes");
  else if(mp[2]>=mp[0])puts("Yes");
  else if(mp[1]==0&&mp[2]>=mp[0]-1)puts("Yes");
  else puts("No");

}

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

int main() {
  int n;
  cin >> n;
  int p[25];
  int sum;
  sum = 0;

  for(int i = 0; i < n; i++){
      cin >> p[i];
  }

  for(int i = 1; i < n - 1; i++){
      if(p[i - 1] < p[i] && p[i] < p[i + 1]){
          sum = sum + 1;
      }else if(p[i + 1] < p[i] && p[i] < p[i - 1]){
          sum = sum + 1;
      }
  }
    cout << sum << endl;
}

Measured memory_bytes: 256
a = int(input())
b=list(map(int,input().split()))
ans = 0

for i in range(a):
    if i == 0:
        ans += b[0]
    elif i != a-1:
        A = b[i-1]
        B = b[i]
        if A > B:
            ans += B
        else:
            ans += A
    else:
        ans += b[-1]
print(ans)

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

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

    if (a<=c && d<=b) cout << d-c << endl;
    else if (c<=a && b<=d) cout << b-a << endl;
    else if (a < c) {
        if (c < b) cout << b - c << endl;
        else cout << 0 << endl;
    }
    else if (c < a) {
        if (a < d) cout << d - a << endl;
        else cout << 0 << endl;
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;

  if(s.length() != a+b+1){
    cout << "No" << "\n";
    return 0;
  }
  for(int i;i<a;i++){
    if(isdigit(s[i]) == 0){
      cout << "No" << "\n";
      return 0;
    }
  }
  if((s[a]) != '-'){
    cout << "No" << "\n";
    return 0;
  }

  for(int i=a+2;i<a+b+1;i++){
    if(isdigit(s[i]) == 0){
      cout << "No" << "\n";
      return 0;
    }
  }
  cout << "Yes" << "\n";

return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N == 24){
		  System.out.println("Christmas Eve");
		} else if(N==25){
		  System.out.println("Christmas");
		} else if(N==23){
		  System.out.println("Christmas Eve Eve");
		} else if(N==22){
		  System.out.println("Christmas Eve Eve Eve");
		}
	}
}


Measured memory_bytes: 20692
S = input()

pluses = [""]*(3)
for i in range(2 ** 3):
    for j in range(3):
        if (i >> j) & 1:
            pluses[j] = "+"
        else:
            pluses[j] = "-"
    F = S[0]+pluses[0]+S[1]+pluses[1]+S[2]+pluses[2]+S[3]
    if eval(F) == 7:
        print(F+"=7")
        exit()



Measured memory_bytes: 3060
S = input()
L=len(S)
longest=0
for i in range(L):
  for j in range(i+1):
    DUP=S[j:i+1]
    DUP=DUP.replace("A","#")
    DUP=DUP.replace("T","#")
    DUP=DUP.replace("G","#")
    DUP=DUP.replace("C","#")
    count=0
    for a in range(len(DUP)):
      if DUP[a]=="#":
        count+=1
      else:
        break
    else:
      longest=max(longest,count)
print(longest)


Measured memory_bytes: 3064
using System;

class P2197
{
  public static void Main()
  {
    int N = Int32.Parse(Console.ReadLine());
    while(N!=0)
      {
	int ans = 0;
	for(int i=1; i<=N/2; i++)
	  {
	    int sum = 0;
	    int num = i;
	    while(sum<N)
	      {
		sum += num;
		num++;
	      }
	    if(sum==N)ans++;
	  }

	Console.WriteLine(ans);

	N = Int32.Parse(Console.ReadLine());
      }
  }
}

Measured memory_bytes: 5620
def group(x , y):

    gx = 0
    gy = 0

    groups = [[1 , 3 , 5 , 7 , 8 , 10 , 12] , [4 , 6 , 9 , 11] , [2]]

    for i in range(3):
        if groups[i].count(x) != 0:
            gx = i
        if groups[i].count(y) != 0:
            gy = i

    return "Yes" if gx == gy else "No"

def main():
    x , y = map(int , input().split())
    print(group(x , y))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
w1=[]
check=False
for i in xrange(n):
    if w[i]==1:
        check=True
        w1.append(i)
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t)%l)
if not check:
    for i in xrange(n):
        print pos[i]/2
    exit()
for i in xrange(len(w1)):
    if pos.count(pos[w1[i]])==1:
        start=w1[i]
        break
#print start
ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(start,start+n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=nokori/(l/2)+1
idx=(start+cnt)%n
#print idx
ans[idx]=pos[start]
pos.sort()
for i in xrange(n):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(idx+1,idx+n):
    ans[i%n]=pos[(now+i-idx)%n]
for i in xrange(n):
    print ans[i]/2

Measured memory_bytes: 17208
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	int t = -1;
	int f = vec.size();
	while (f - t > 1) {
		int m = (t + f) / 2;
		if (vec[m] < xx) {
			t = m;
		}
		else {
			f = m;
		}
	}
	return f;
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>
void vecin(vector<TT>& vec) { 
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx == 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}





signed main() {
	int n,k,ans=0;
	cin >> n>>k;
	vector<int>vec(n);
	vecin(vec);
	sort(all(vec));
	rep(i, k) {
		ans += vec[i];
	}
	cout << ans << endl;
}


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

int main() {
  int x,a,b;
  cin>>x>>a>>b;
  int da=abs(x-a);
  int db=abs(x-b);
  if(da<=db){
    cout<<"A"<<endl;
  }
  else{
    cout<<"B"<<endl;
  }  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

string S[2020];
int sumE[2020][2020],sumV[2020][2020];
// 境界をまたがる辺の数
int cntR[2020][2020], cntC[2020][2020];

int main(){
  int N,M,Q; cin>>N>>M>>Q;
  rep(i,N) cin>>S[i];
  rep(i,N) for(int j=1;j<M;j++){
    if(S[i][j]=='1'&&S[i][j-1]=='1'){
      sumE[i+1][j+1]++;
      cntR[i+1][j]++;
    }
  }
  rep(j,M) for(int i=1;i<N;i++){
    if(S[i][j]=='1'&&S[i-1][j]=='1'){
      sumE[i+1][j+1]++;
      cntC[i][j+1]++;
    }
  }
  rep(i,N) rep(j,M) if(S[i][j]=='1') sumV[i+1][j+1]++;

  rep(i,N) rep(j,M){
    sumE[i+1][j+1]+=sumE[i+1][j];
    sumV[i+1][j+1]+=sumV[i+1][j];
    cntC[i+1][j+1]+=cntC[i+1][j];
  }
  rep(j,M) rep(i,N){
    sumE[i+1][j+1]+=sumE[i][j+1];
    sumV[i+1][j+1]+=sumV[i][j+1];
    cntR[i+1][j+1]+=cntR[i][j+1];
  }


  rep(i,Q){
    int a,b,c,d; cin>>a>>b>>c>>d; a--,b--;
    int SV=sumV[c][d]-sumV[a][d]-sumV[c][b]+sumV[a][b];
    int SE=sumE[c][d]-sumE[a][d]-sumE[c][b]+sumE[a][b];
    SE-=(cntR[c][b]-cntR[a][b])+(cntC[a][d]-cntC[a][b]);
    cout<<SV-SE<<endl<<endl;
  }
  return 0;
}


Measured memory_bytes: 69760
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<String> list2 = new ArrayList<>();
    int n = sc.nextInt();
    int count = 0;
    
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    List<Integer> list2= new ArrayList<Integer>(list);
    
    Collections.sort(list);


    for(int i = 0; i < n ; i++){
        if(list.get(i) != list2.get(i)){
            count++;
        }
    }

    if(count <= 2){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }

    
    



















    
    






    

    



    
  

    


    


    

    
    
    



    





}
}

Measured memory_bytes: 35928
n, q = map(int, input().split())
s = input()
sl = [0]
for i in range(1, n):
    if s[i-1:i+1] == 'AC':
        sl.append(sl[i-1]+1)
    else:
        sl.append(sl[i-1])

for _ in range(q):
    l, r = map(int, input().split())
    print(sl[r-1]-sl[l-1])


Measured memory_bytes: 11444