akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<VL> dt(n, VL(3));
	rep(i, n) cin >>dt[i][0] >>dt[i][1] >>dt[i][2];
	
	ll ans = 0;
	rep(i , 1<<3){
		VL smz; smz.reserve(n);
		rep(j, n){
			ll cnd = 0;
			rep(k, 3) cnd += (i>>k &1)? dt[j][k]: -dt[j][k]; 
			smz.push_back(cnd);
		}
		sort(smz.rbegin(), smz.rend());
		ans = max<ll>(ans, accumulate(smz.begin(), smz.begin()+m, 0LL));
	}
	cout << ans <<endl;
	return 0;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];

    vl dp(n+1);
    dp[0] = 1000;
    rep(i,n){
        dp[i+1] = dp[i];
        rep(j,i){
            dp[i+1] = max(dp[i+1], dp[j+1]%a[j] + dp[j+1]/a[j]*a[i]);
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
using namespace std;
 
#define MAX 200010
#define NIL -1
 
struct Node{
    int parent;
    vector<int> connect;
    int counter;
};
 
Node T[MAX];
 
int set_counter(int point){
  int tmp_point;
  if(T[point].parent!=NIL){
    T[point].counter += T[T[point].parent].counter;
  }
  if(T[point].connect.size()==0){
      return 0;
  }
  for(int i=0; i<T[point].connect.size(); i++){
      tmp_point = T[point].connect[i];
      if(T[point].parent != tmp_point){
          T[tmp_point].parent = point;
          set_counter(tmp_point);
      }
  }
}
 
int main(){
  int N;
  int Q;
  
  cin >> N >> Q;
  
  for(int i=0; i<N; i++){
    T[i].parent = NIL;
    T[i].counter = 0;
  }
  
  for(int i=0; i<N-1; i++){
    int tmp_connect1;
    int tmp_connect2;
    cin >> tmp_connect1 >> tmp_connect2;
    tmp_connect1--;
    tmp_connect2--;
    T[tmp_connect1].connect.push_back(tmp_connect2);
    T[tmp_connect2].connect.push_back(tmp_connect1);    
  }
  
  for(int i=0; i<Q; i++){
    int tmp_point;
    int tmp_counter;
    cin >> tmp_point >> tmp_counter;
    tmp_point--;
    T[tmp_point].counter += tmp_counter;
  }
  
  set_counter(0);
  
  for(int i=0; i<N; i++){
    cout << T[i].counter << " ";
  }
  cout << endl;
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  int a,b;
  cin >> a >> b;
  if(a >= 13) cout << b << endl;
  else if(a >= 6) cout << b/2 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;

bool dp[10001];

int main(){
    int N;
    cin>>N;
    dp[0]=true;
    for(int i=0;i<N;i++){
        int s;
        cin>>s;
        for(int j=10000-s;j>=0;j--){
            dp[j+s]|=dp[j];
        }
    }
    int ans = 0;
    for(int i=0;i<=10000;i++){
        if(i%10!=0&&dp[i]) ans=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char st[5];
	cin >> st;
	for (int i = 0;i < 3;i++) {
		if (st[i] == '1') {
			st[i] = '9';
		}
		else {
			st[i] = '1';
		}
	}
	cout << st << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,m = input().split()

a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc =[]
for i in range(int(m)):
  xyc.append(input())
  
min = min(a) + min(b)
for i in xyc:
  x,y,c = map(int, i.split())
  if min > a[x-1] + b[y-1] - c :
    min = a[x-1] + b[y-1] - c
print(min)


Measured memory_bytes: 19372
#include<stdio.h>
#define N 100000
#define nil -1

typedef struct{
    int p;
    int left;
    int right;
}Tree;

Tree tree[N];

int depth(int);

int main(){
    int i,j,n,num,deg,c,k=0;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        tree[i].p=nil;
        tree[i].left=nil;
        tree[i].right=nil;
    }

    for(i=0;i<n;i++){
        scanf("%d%d",&num,&deg);
        for(j=0;j<deg;j++){
            scanf("%d",&c);
            if(j==0)tree[num].left=c;
            else tree[k].right=c;
            k=c;
            tree[c].p=num;
        }
    }

    for(i=0;i<n;i++){
        printf("node %d: parent = %d, depth = %d, ",i,tree[i].p,depth(i));
        if(depth(i)==0) printf("root, [");
        else if(tree[i].left==nil) printf("leaf, [");
        else printf("internal node, [");
        j=tree[i].left;
        while(j!=nil){
            printf("%d",j);
            j=tree[j].right;
            if(j!=nil){
                printf(", ");
            }
        }
        printf("]\n");
    }
    return 0;
}

int depth(int num){
    int dep=0;
    while(tree[num].p!=nil){
        num=tree[num].p;
        dep++;
    }
    return dep;
}


Measured memory_bytes: 2968
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

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;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

main(){
    int n,x,ans=0;
    cin>>n>>x;
    int a[n];
    rep(i,n)cin>>a[i];
    rep(i,n-1){
        int d=max(0ll,a[i]+a[i+1]-x);
        a[i+1]-=d;
        if(a[i+1]<0){
            //a[i]+=a[i+1];
            a[i+1]=0;
        }
        ans+=d;
    }
    dans;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int n,m,ans;
    cin>>n>>m;
    for (int i=m/n; i>=1; i--) {
        if(m%i==0){
          if(m/i>=i)ans=i;
          break;
        }
    }
  cout<<ans<<endl;
}










Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int A,B,C,D;
    cin>>A>>B>>C>>D;

    if(A!=C){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin>>N>>K;
  int S = 1;
  int i = 0;
  while (i < N) {
    if (S <= K) {
      S += S;
    }
    else {
      S += K;
    }
    i++;
  }
  cout<<S<<endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  string s;
  cin >> s;
  bool ans = true;
  for (ll i = 0; i < sz(s);i +=2){
    if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
      ans = false;
    }
  }
  for (ll i = 1; i < sz(s);i+=2){
    if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
      ans = false;
    }
  }
  if(ans){
    print("Yes");
  }
  else{
    print("No");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    ll L, R; cin >> L >> R;
    if ((L-1) / 2019 != R / 2019) {
        cout << 0 << endl; return 0;
    }
    L = L % 2019; R = R % 2019;
    int ans = 2018;
    FOR(i, L, R+1) {
        FOR(j, i+1, R+1) {
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 256
#include<bits/stdc++.h>
/**CLICK ss---> ctrl+j**/
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
void solve()
{
  int64_t n, m, i, j, k, l;
  long double x;
  cin>>n>>x;
  k=(n*(int64_t)round(x*100))/100;
  cout<<k<<endl;
}
int main()
{
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3780
#include <stdio.h>

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

     int m;
     for(i = 0; i < n-1; i++)
     {
          if(l[i+1] > l[i])
          {
               m = l[i];
               l[i] = l[i+1];
               l[i+1] = m;
               i = -1;
          }
     }

     int s = 0;
     for(i = 0; i < k; i++)
          s += l[i];

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

     return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
int main(){
        int n,k;
        while(~getII(n,k)){
                int ans=0;
                while(n){
                        ans++;
                        n/=k;
                }
                printf("%d\n",ans);
        }
}

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

ll nC2(ll p)
{
    if(p<2)
        return 0;
    else
        return (p*(p-1))/2;
}
int main()
{
    ll n;
    cin>>n;
    vector<ll> v(n);
    map<ll, ll> m;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(m.find(v[i])==m.end())
          m.insert({v[i],1});
        else
          m[v[i]]++;
    }
    ll sum=0;
   for(auto i = m.begin() ; i!=m.end(); i++)
   {
      sum+= nC2(i->second);
      //cout<<i->second<<" ";
   }
   //cout<<"\n"<<sum;
   ll z;
   //cout<<"\n";
   for(int k=0; k<n; k++)
   {
    z = sum - nC2(m[v[k]]) + nC2(m[v[k]]-1);
       cout<<z<<"\n";
   }

    return 0;

}


Measured memory_bytes: 11008
#include "bits/stdc++.h"

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<ll> list(N + 1);
  vector<ll> q(N+1);
  ll sum = 0;
  rep(i, N) { cin >> list[i]; sum += list[i]; q[i]+=sum;}
  int here = 0;
  while (q[here] < sum/2){
    here++;
  }
  //cout << here;
  cout << min(sum - q[here-1]*2, q[here]*2 -sum);
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);


*/


Measured memory_bytes: 3328
from subprocess import run
from os import path

if not path.exists("./tmp215378912379"):
  with open("./tmp215378912379.cpp", mode='w') as f:
    f.write("""
  #include <bits/stdc++.h>
  template <class T>
  concept Integral = std::is_integral_v<T>;

  int main() {
    auto f = []<Integral T>(T a, T b) { return a * b; };
    int a, b;
    std::cin >> a >> b;
    std::cout << f(a, b) << std::endl;
  }
  """)

  run("g++ -o ./tmp215378912379 -std=gnu++2a -fconcepts ./tmp215378912379.cpp", shell=True)

run("./tmp215378912379")

Measured memory_bytes: 10204
import java.util.*;
public class Main {
	HashMap<String, Integer> word;
	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		word = new HashMap<String, Integer>();
		while (sc.hasNext()) {
			String[] words = sc.next().split(" ");
			for (String str : words) {
				if (!word.containsKey(str)) 
					word.put(str, 1);
				else word.put(str, word.get(str)+1);
			}
		}
		String str = "";
		String strl = "";
		int count=0;
		for (Map.Entry<String, Integer> entry: word.entrySet()) {
			if (strl.length() < entry.getKey().length())strl = entry.getKey();
			if (count < entry.getValue()) {
				count = entry.getValue();
				str = entry.getKey();
			}
		}
		System.out.println(str + " " + strl);
		
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

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

const long long INF = 1e18;

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

  vector<vector<long long>> dp(n+1, vector<long long>(2));
  dp[0][0] = 0;
  dp[0][1] = -INF;
  for ( int i = 0; i < n; i++ ) {
    dp[i+1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
    dp[i+1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
  }

  cout << dp[n][0] << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	ll N, H;
	cin >> N >> H;
	vector<ll> A(N), B(N);
	for(int i=0; i<N; i++) {
		cin >> A[i] >> B[i];
	}
	
	sort(A.begin(), A.end(), greater<ll>());
	sort(B.begin(), B.end(), greater<ll>());
	
	ll maxA = A[0];
	ll ans = 0;
	for(int i=0; maxA < B[i] && i < N; i++) {
		ans++;
		H -= B[i];
		if(H <= 0) {
			cout << ans << endl;
			return 0;
		}
	}
	
	ans += H / maxA + ((H%maxA != 0) ? 1 : 0);
	cout << ans << endl;
	return 0;
}


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

#define MAX 100000
#define MAX_E 100000

int par[MAX], rank_[MAX];

void init(int N)
{
    for (int i = 0; i < N; i++) {
	par[i] = i;
	rank_[i] = 0;
    }
}

int find(int x)
{
    if (par[x] == x) {
	return x;
    }
    return par[x] = find(par[x]);
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (rank_[x] < rank_[y]) {
	par[x] = y;
    } else {
	par[y] = x;
	if (rank_[x] == rank_[y]) {
	    rank_[x]++;
	}
    }
}

bool same(int x,int y)
{
    return (find(x) == find(y));
}

struct edge{ int u, v, cost; };

bool comp(const edge &e1, const edge &e2)
{
    return e1.cost < e2.cost;
}

int V,E;
edge es[MAX_E];

int kruskal()
{
    sort(es, es+E, comp);
    init(V); // init union_find
    int res = 0;
    for (int i = 0; i < E; i++) {
	edge e = es[i];
	if (!same(e.u, e.v)) {
	    unite(e.u, e.v);
	    res += e.cost;
	}
    }
    return res;
}

int main()
{
    int s,t,w;
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
	cin >> s >> t >> w;
        es[i]=(edge){s, t, w};
    }
    cout << kruskal() << endl;
    return 0;
}


Measured memory_bytes: 4356
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

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

    int N;
    cin >> N;
    vector<double> v(N);
    double ans = 0;
    REP(i, N) { cin >> v.at(i); }
    sort(ALL(v));
    ans = (v[0] + v[1]) / 2;
    REP(i, N - 2) { ans = (ans + v[i + 2]) / 2; }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, l, r, A = 0;
  cin >> N;
  
  for(int i = 0; i < N; i++) {
    cin >> l >> r;
    A += r - l + 1;
  }
  
  cout << A;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main(){
  int i,n;
  string s,t;
  cin >> s;
  cin >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  n = min(s.size(),t.size());
  for(i=0;i<n;i++){
    if(s[i]>t[i]){
      cout << "No" << endl;
      return 0;
    }else if(s[i]<t[i]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if(n==t.size())cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
#define bug(x) cerr << "[" << #x << "] = ["<<x<<"]"<<'\n'
using namespace std;
ll  h,n;
vector<pair<ll ,ll > > v;
ll  dp[10009];
void call()
{
    for(int i=1;i<=h;i++) dp[i]=INT_MAX;
    for(int i=0;i<=h;i++)
    {
        for(auto x: v)
        {
            dp[i]=min(dp[max(0LL,i-x.first)]+x.second, dp[i]);
        }
    }
    cout<<dp[h]<<endl;
}
int  main()
{
    fast;

    cin>>h>>n;
    for(ll  i=0;i<n;i++)
    {
        ll  a,b;
        cin>>a>>b;
        v.pb(mp(a,b));
    }
    call();

}
	

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main() {

    ll K, S;
    cin >> K >> S;

    ll ans = 0;

    rep(i, min(K + 1, S + 1)) {
        rep(j, min(K + 1, S + 1)) {
            if (i + j <= S && i + j + K >= S) {
                ans++;
            }
        }
    }

    cout << ans;

    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for (int i = 0; i < n; ++i) {
        while(i+1<n&&s[i]==s[i+1])++i;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin>>N;
	vector<LL> A(N);
	for(int i=0;i<N;++i){
		cin>>A[i];
	}
	sort(A.begin(),A.end());
	LL ansL = A[N-1];
	LL ansR;
	A.erase(A.begin()+N-1);//最大値を削除
	vector<LL> sel;
	if(ansL&1 ){
		LL ter = ansL/2;
		vector<LL>::iterator itr;
		itr = lower_bound(A.begin(),A.end(),ter);
		if( itr != A.end() ){
			sel.push_back( *itr );
		}
		if( itr != A.begin() ){
			--itr;
			sel.push_back( *itr );
		}
		ter = ansL/2 + 1;
		itr = lower_bound(A.begin(),A.end(),ter);
		if( itr != A.end() ){
			sel.push_back( *itr );
		}
		if( itr != A.begin() ){
			--itr;
			sel.push_back( *itr );
		}
	}else{
		LL ter = ansL/2;
		vector<LL>::iterator itr;
		itr = lower_bound(A.begin(),A.end(),ter);
		if( itr != A.end() ){
			sel.push_back( *itr );
		}
		if( itr != A.begin() ){
			--itr;
			sel.push_back( *itr );
		}
	}
	int size = sel.size();
	LL MIN = LINF;
	for(int i=0;i<size;++i){
		if(ansL&1){
			LL res1 = abs(ansL/2 -sel[i]);
			LL res2 = abs(ansL/2+1 -sel[i]);
			LL res = min(res1,res2);
			if( res < MIN ){
				MIN = res;
				ansR = sel[i];
			}
		}else{
			LL res = abs( ansL/2 -sel[i] );
			if( res < MIN ){
				MIN = res;
				ansR = sel[i];
			}
		}
	}
	cout << ansL << " " << ansR << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

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

    if (c - 1 <= a + b) {
        cout << b + c;
    } else {
        cout << b + c - (c - a - b - 1);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <bitset>
#include <functional>
#include <set>
#include <map>
#include <array>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
//#define int long long int
const int MOD = 1000000007;
const int INF = 1001001000;
const double EPS = 0.000000001;

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

bool pairCompare(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, u[100001], v[100001], w[100001];
  bool flag[100001];
  bool ans[100001];
  vector<PL> vec[100001];
  cin >> n;
  queue<ll> q;
  REP(i, n){
    flag[i+1] = false;
  }
  REP(i, n-1){
    ll a, b, c;
    cin >> a >> b >> c;
    vec[a].push_back(P(b, c));
    vec[b].push_back(P(a, c));
  }
  flag[1] = true;
  ans[1] = true;
  q.push(1);
  while (!q.empty()) {
    ll ver = q.front();
    q.pop();
    REP(i, vec[ver].size()){
      PL par = vec[ver][i];
      if(par.snd & 1){
        if(!flag[par.fst]){
          ans[par.fst] = !ans[ver];
          flag[par.fst] = true;
          q.push(par.fst);
        }
      }
      else{
        if(!flag[par.fst]){
          ans[par.fst] = ans[ver];
          flag[par.fst] = true;
          q.push(par.fst);
        }
      }
    }
  }
  REP(i, n){
    if(ans[i+1]) cout << 1 << endl;
    else cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
int p=2019;
int arr[p+1];
string s;
cin>>s;
n=s.length();
    memset(arr, 0, sizeof(arr));
    arr[0]=1;
    int mult = 1;
    int cur = 0;
    int ans = 0;
    for(int i=n-1; i>=0; i--){
        int a = s[i]-'0';
        a *= mult;
        a %= p;
        cur += a;
        cur %= p;
        ans += arr[cur];
        // trace(ans);
        arr[cur]++;
        mult *= 10;
        mult %= p;
    }
    cout<<ans;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
    
using namespace std;
bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
} 

  
int main(){
    IOS;
 
 string s;
 cin>>s;
 if(s=="SUN") cout<<"7\n";
 else if(s=="SAT") cout<<"1\n";
 else if(s=="MON") cout<<"6\n";
 else if(s=="TUE") cout<<"5\n";
 else if(s=="WED") cout<<"4\n";
 else if(s=="THU") cout<<"3\n";
 else cout<<"2\n";
  
    return 0;}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main{
    public static void main(String[] a) throws IOException{
    	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
 	int mountains[] = new int[10];
        
        for(int i=0;i<10;i++){
                mountains[i] = Integer.parseInt(in.readLine());
        }
        
        Arrays.sort(mountains);
        
        for(int i = mountains.length-1;i > mountains.length-4;i--){
            System.out.println(mountains[i]);
        }
    }
}

Measured memory_bytes: 17004
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int,int);

int main(){
  int i,x;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  x=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}
int partition(int p,int r){
  int a,b,i,j;
  a=A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j]<=a){
	i++;
	b=A[i];
	A[i]=A[j];
	A[j]=b;
      }
    }
  b=A[i+1];
  A[i+1]=A[r];
  A[r]=b;
  return i+1;
}



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

int main(){
    int N, A, B, C, X;
    int Y[102];

    while(true){
        cin >> N >> A >> B >> C >> X;
        if(N == 0) break;
        for(int i=0;i<N;i++) cin >> Y[i];
        int n = 0;
        int cnt = -1;

        while(n < N){
            if(Y[n] == X) n++;
            X = (A * X + B) % C;
            cnt++;
            // cout << cnt << endl;
            if(cnt > 10000) break;
        }
        if(cnt > 10000){
            cout << -1 << endl;
        }else{
            cout << cnt << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3104
N,A,B= input().split()
l = [N,A,B]
N,A,B = map(int,l)

m = 0

for i in range(1,N+1):

    n = 0
    
    for j in range(len(str(i))):

        n += int(str(i)[j])

    if A <= n <= B:
        m += i

print(m)



Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=200010, inf=2e9;

int n, X[MX], A[MX];

void NOPE(){
    cout<<-1;
    exit(0);
}

ll ans=0;

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++) cin>>A[i];
    for(int i=n, l=n; i>=1; i--){
        int st=i-A[i];
        if(st<1 || l<st) NOPE();
        if(st==l) continue;
        l=min(l,st);
        ans+=A[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	string t = s;
	swap(t[0], t[2]);
	if(s == t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main() {
	int n; cin >> n;
	vector<int> ans(n+1,0);
	
		for(int x=1; x*x<n; x++){
			for(int y=1; y*y<n-x*x; y++){
				for(int z=1; z*z<n-x*x-y*y; z++){
					int p = x*x + y*y + z*z + x*y + y*z + z*x;
					if(p <= n) ans[p]++;
				}
			}
		}
	rep(i,n) cout << ans[i+1] << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int I = scan.nextInt();
        String tmp;
        boolean b = true;
        String[] s = new String[100];
        s[0] = scan.next();
        tmp = s[0].substring(s[0].length() - 1);
        for (int i = 1; i < I; i++) {
            s[i] = scan.next();
            for (int j = 0; j < i; j++) {
                if (s[i].equals(s[j])) {
                    b = false;
                    break;
                }
            }
            if (!s[i].startsWith(tmp)) {
                b = false;
                break;
            }
            tmp = s[i].substring(s[i].length() - 1);
        }
        if(b == false){
                System.out.println("No");
                System.exit(0);
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#define NUMBER 100

void print_array(int array[],int num){
	int i;
	
	for(i = 0; i < num - 1; i++)
		printf("%d ", array[i]);
	
	//スペースを出力したくないので最後の要素だけfor文外で出力
	printf("%d\n", array[i]);
}

void insertionSort(int array[],int num){
	int i, j, v;
	for(i = 1; i <= num - 1 ; i++){
		v = array[i];
		j = i - 1;
		while(j >= 0 && array[j] > v){
			array[j + 1] = array[j];
			j--;
		}
		array[j + 1] = v;
		//配列の出力
		print_array(array, num);
	}
}

int main(void){
	int array[NUMBER];
	int num, i;
	
	scanf("%d", &num);
	
	for(i = 0; i < num; i++){
		//配列を入力
		scanf("%d", &array[i]);
	}
	print_array(array, num);
	
	//挿入ソート
	insertionSort(array, num);

	
	return 0;
}


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

namespace arc078_b
{
	class Program
	{
		public static List<int>[] list;
		public static int[] f, s;
		static void bfs(int x, int len, bool flag)
		{
			if (flag)//fennec
			{
				f[x] = len;
				foreach (var item in list[x])
				{
					if (f[item] < 0) bfs(item, len + 1, flag);
				}
			}
			else//snuke
			{
				s[x] = len;
				foreach (var item in list[x])
				{
					if (s[item] < 0) bfs(item, len + 1, flag);
				}
			}
		}
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			list = new List<int>[n];
			for (int i = 0; i < n; i++) list[i] = new List<int>();
			for (int i = 0; i < n - 1; i++)
			{
				int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
				x[0]--; x[1]--;
				list[x[0]].Add(x[1]); list[x[1]].Add(x[0]);
			}
			f = new int[n]; for (int i = 0; i < n; i++) f[i] = -1; bfs(0, 0, true);
			s = new int[n]; for (int i = 0; i < n; i++) s[i] = -1; bfs(n - 1, 0, false);
			int ret = 0;
			for (int i = 0; i < n; i++)
			{
				ret += f[i] <= s[i] ? 1 : -1;
			}
			Console.WriteLine(ret > 0 ? "Fennec" : "Snuke");
		}
	}
}

Measured memory_bytes: 46848
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
a=array(N)
N.times do|i|
    a[i]=gets.to_i
end
dp=[]
a.each do|v|
  if dp==[] or dp[-1]>=v
      dp.push(v)
  else
      head=-1
      tail=dp.size
      while tail-head>1
          mid=head+(tail-head)/2
          if dp[mid]<v
              tail=mid
          else
              head=mid
          end
      end
      dp[tail]=v
  end
end
puts dp.size

Measured memory_bytes: 15900
L = input()[1:]
mod = 10**9 + 7

sure = 1
possible = 2
for bit in L:
    if bit == '1':
        sure = (sure * 3 + possible) % mod
        possible = possible * 2 % mod
    else:
        sure = sure * 3 % mod

ans = (sure + possible) % mod
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(ll i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const ll N=3e5+7;
const ll INF=1e9+7;
ll n,l,t;
ll x[N],w[N],u[N],a[N];

int main(){
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	scanf("%lld%lld%lld",&n,&l,&t);
	rep(i,n)scanf("%lld%lld",&x[i],&w[i]);
	rep(i,n){
		if(w[i]&1)u[i]=(x[i]+t)%l;
		else u[i]=(x[i]-t%l+l)%l;
	}
	ll nw=u[1],id=0,gg;
	sort(u+1,u+n+1);
	rep(i,n){
		if(w[i]==w[1])continue;
		ll g=(w[1]&1)?(x[i]-x[1]):(x[1]-x[i]+l),q=(2*t)%l;
		(id+=(2*t)/l)%=n;
		if(g<=q)id=(id+1)%n;
	}
	if(w[1]==2)id=n-id;
	id=id%n+1;
	if(w[1]&1){for(ll i=n;i;i--)if(u[i]==nw){gg=i; break;}}
	else {rep(i,n)if(u[i]==nw){gg=i; break;}}
	rep0(i,n)a[(id-1+i)%n+1]=u[(gg+i-1)%n+1];
	rep(i,n)printf("%lld\n",a[i]);
	return 0;
}


Measured memory_bytes: 8064
n,m=map(int,input().split())

if m==0:
    print(0,0)
    import sys
    sys.exit()

p=[list(input().split()) for _ in range(m)]
correct=set([p[i][0] for i in range(m) if p[i][1]=='AC'])

s=set()
sum_wa=0

for i in [p[j] for j in range(m) if p[j][0] in correct]:
    if i[0] in s:
        continue
    else:
        if i[1]=='WA':
            sum_wa+=1
        else:
            s.add(i[0])

print(len(correct),sum_wa)

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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

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

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll c = B / C - (A - 1) / C;
    ll d = B / D - (A - 1) / D;
    ll cd = B / lcm(C, D) - (A - 1) / lcm(C, D);
    // DEBUG(c);
    // DEBUG(d);
    // DEBUG(cd);
    // DEBUG(gcd(C, D));
    // DEBUG(lcm(C, D));
    cout << (B - A + 1) - (c + d - cd) << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

x = [[] for _ in range(N)]
a = [None] * M
for i in range(M):
    P, Y = map(int, input().split())
    x[P-1].append(Y)
    a[i] = (P, Y)

y = {}
for i in range(N):
    x[i].sort()
    for j, Y in enumerate(x[i]):
        y[(i+1, Y)] = j + 1
for i in range(M):
    print('{}{}'.format(str(a[i][0]).zfill(6), str(y[a[i]]).zfill(6)))


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

int a[24][25],n,m,c,b[25];

int main()
{
    cin>>n>>m>>c;
    for(int i=0;i<m;i++)
        scanf("%d",b+i);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        scanf("%d",&a[i][j]);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int tem=0;
        for(int j=0;j<m;j++)
            tem+=(a[i][j]*b[j]);
        tem+=c;
        if(tem>0)ans++;
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int> a;
int main(){
  
  int n,x;
  cin>>n;
  while(n--)
  {
  	  cin>>x;
  	  if(a[x])
  	  {
  	  	 cout<<"NO"<<endl;return 0;
  	  }
  	  a[x]++;
  	  
  }
cout<<"YES";

	return 0;
}


Measured memory_bytes: 9600
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n;
string s, t; 
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>s>>t;
    for (int i = 0; i < n; i++)
    {
        cout<<s[i]<<t[i];
    }
    cout<<"\n";
}



Measured memory_bytes: 256
n = int(input())
c = [0]*n
s = [0]*n
f = [0]*n
ans = [0]*n

for i in range(n-1):
  c[i], s[i], f[i] = map(int, input().split())
    
for i in range(n):
  t = 0
  for j in range(i, n-1):
    if t <= s[j]:
      t = s[j]
    elif t % f[j] is 0:
      t = t
    else:
      t = t + f [j] - t % f [j];
    t += c[j];
  print(t)

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


def main():
    H, W = [int(x) for x in input().split()]
    print("#" * (W + 2))
    for _ in range(H):
        print("#" + input() + "#")
    print("#" * (W + 2))
    pass


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main() {
	string a, b;
	int x, y;
	cin >> a >> b;
	if (a == "1") {
		x = 1;
	}
	else if (a == "2") {
		x = 2;
	}
	else if (a == "3") {
		x = 3;
	}
	else if (a == "4") {
		x = 4;
	}
	else if (a == "5") {
		x = 5;
	}
	else if (a == "6") {
		x = 6;
	}
	else if (a == "7") {
		x = 7;
	}
	else if (a == "8") {
		x = 8;
	}
	else if (a == "9") {
		x = 9;
	}
	else if (a == "A") {
		x = 10;
	}

	else if (a == "B") {
		x = 11;
	}
	else if (a == "C") {
		x = 12;
	}
	else if (a == "D") {
		x = 13;
	}
	else if (a == "E") {
		x = 14;
	}
	else if (a == "F") {
		x = 15;
	}
	if (b == "1") {
		y = 1;
	}
	else if (b == "2") {
		y = 2;
	}
	else if (b== "3") {
		y = 3;
	}
	else if (b == "4") {
		y= 4;
	}
	else if (b == "5") {
		y = 5;
	}
	else if (b == "6") {
		y = 6;
	}
	else if (b == "7") {
		y = 7;
	}
	else if (b == "8") {
		y = 8;
	}
	else if (b == "9") {
		y = 9;
	}
	else if (b == "A") {
		y = 10;
	}

	else if (b == "B") {
		y = 11;
	}
	else if (b == "C") {
		y = 12;
	}
	else if (b == "D") {
		y = 13;
	}
	else if (b == "E") {
		y = 14;
	}
	else if (b == "F") {
		y = 15;
	}
	if (x < y) {
		cout << "<" << endl;
	}
	else if (x == y) {
		cout << "=" << endl;
	}
	else {
		cout << ">" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n, i, j, x;
    char s[100001];

    scanf("%d%s",&n, s);

    x = 0;
    for(i=0; i<n; i++){
        x++;    
        j = i+1;
        while(s[i] == s[j]){
            j++;
        }
        i = j-1;
    }
    printf("%d\n", x);
}

Measured memory_bytes: 1828