akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 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 llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 100005
#define MOD 1000000007


int main(){

    ll n,k;
    cin >> n >> k;
    vector<ll> a(ARRAY_MAX,0);
    REP(i,n){
        cin >> a[i];
    }

    int index = 0;
    bool flag = true;
    REP(i,n){
        if(a[i] > 0){
            index = i;
            flag = false;
            break;
        }
    }
    if(flag){
        //全て負数の場合
        index = n+1;
    }
    a.insert(a.begin()+index,0);
    /*cout << index << endl;
    REP(i,n+1){
        cout << a[i] << " ";
    }
    cout << endl;
    */
    ll ans = INF;
    for(int i = 0;i <= k;i++){
        //0から右にi個使い、0から左にk-i個の数字を使う

        ll right = index + i;
        ll left = index - (k-i);
        if(index == n+1){
            right--;
            left--;
        }
        //cout << left << " " << right << endl;
        if(right > n || left < 0){
            continue;
        }
        
        ll tmp1 = a[right] + abs(2*a[left]);
        ll tmp2 = 2*a[right] + abs(a[left]);
        ans = min(ans,min(tmp1,tmp2));
        //cout << i << "個右から使う " << left << " " << right << " " << " " << ans << endl;
    }
    /*if(ans == INF){
        //移動の必要がない
        ans = 0;
    }*/
    cout << ans << endl;

   
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main ( void )
{
	string in;
	
	while (cin >> in)
	{
		int ans = -1;
		
		for (int i = 0; i < 10; i += 1)
		{
			int value = 0;
			
			int ii, m;
			
			for (ii = in.size() - 1, m = 1; in[ii] != '='; --ii, m *= 10)
			{
				value += ((in[ii] == 'X') ? (i * m) : ((in[ii] - '0') * m));
			}
			
			if (!i && m != 10 && in[ii+1] == 'X')
				continue;
				
			for (--ii, m = 1; in[ii] != '+'; --ii, m *= 10)
			{
				value -= ((in[ii] == 'X') ? (i * m) : ((in[ii] - '0') * m));
			}
			
			if (!i && m != 10 && in[ii+1] == 'X')
				continue;
			
			for (--ii, m = 1; ii >= 0; --ii, m *= 10)
			{
				value -= ((in[ii] == 'X') ? (i * m) : ((in[ii] - '0') * m));
			}
			
			if (!i && m != 10 && in[0] == 'X')
				continue;
				
			if (!value)
			{
				ans = i;
				break;
			}
		}
		
		if (ans == -1)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <string.h>
#define rep(i,j,k) for(i = j;i <= k;i++)

int main(){
  char a[10000];
  int i,countj,counti;


  while(scanf("%s",a) != EOF){
    countj = 0;
    counti = 0;
    rep(i,0,strlen(a)-3){
      if(a[i] == 'J')if(a[i+1] == 'O')if(a[i+2] == 'I') countj++;
      
      if(a[i] == 'I')if(a[i+1] == 'O')if(a[i+2] == 'I') counti++;
    }

    printf("%d\n%d\n",countj,counti);
  }

  return 0;
}

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

using namespace std;

int main(void) {
    long long n;
    vector <long long> a;
    cin >> n;
    for (long long i = 0; i < 3 * n; i++) {
        long long ai;
        cin >> ai;
        a.push_back(ai);
    }

    multiset <long long> left;
    long long sleft = 0;
    long long sl[300000];
    for (long long i = 0; i < 3 * n; i++) {
        left.insert(a[i]);
        sleft += a[i];
        if (left.size() > unsigned(n)) {
            int j;
            j = *left.begin();
            left.erase(left.begin());
            sleft -= j;
        }
        sl[i] = sleft;
    }

    multiset <long long> right;
    long long sright = 0;
    long long sr[300000];
    for (long long i = 3 * n - 1; i >= 0; i--) {
        right.insert(a[i]);
        sright += a[i];
        if (right.size() > unsigned(n)) {
            int j;
            j = *(--right.end());
            right.erase(--right.end());
            sright -= j;
        }
        sr[i] = sright;
    }

    long long res;
    res = -999999999999999;
    for (int i = n - 1; i < 2 * n; i++) {
        res = max(res, sl[i] - sr[i + 1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 18284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

vector<long long> enum_divisor(long long n)
{
  vector<long long> dst;
  for (long long i = 1; i * i <= n; i++)
  {
    if (n % i != 0)
      continue;
    dst.push_back(i);
    if (i * i != n)
      dst.push_back(n / i);
  }
  return dst;
}

int main()
{
  long long N;
  cin >> N;
  if (N == 1)
  {
    cout << 0 << endl;
    return 0;
  }

  long long ans = 0;
  long long tempN = N;
  long long lasti = 0;
  vector<pair<long long, long long>> prims;
  for (long long i = 2; i * i <= tempN; i++)
  {
    if (N % i == 0)
    {
      prims.push_back(make_pair(i, 0));
      while (N % i == 0)
      {
        prims.back().second++;
        N /= i;
      }
    }
  }
  if (N != 1)
    prims.push_back(make_pair(N, 1));
  rep(i, prims.size())
  {
    long long count = 1;
    while (prims[i].second - count >= 0)
    {
      prims[i].second -= count;
      count++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		try {
		    Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();		   
		    String s=sc.next();
		    if(n>=s.length())
		   { System.out.println(s);}
		    else
		    {
		        System.out.println(s.substring(0,n)+"...");
		    }
		} catch(Exception e) {
		} finally {
		}
	}
}


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

int main()
{
    int N;
    cin >> N;
    if     (N%10 == 0) cout << "pon" << endl;
    else if(N%10 == 1) cout << "pon" << endl;
    else if(N%10 == 2) cout << "hon" << endl;
    else if(N%10 == 3) cout << "bon" << endl;
    else if(N%10 == 4) cout << "hon" << endl;
    else if(N%10 == 5) cout << "hon" << endl;
    else if(N%10 == 6) cout << "pon" << endl;
    else if(N%10 == 7) cout << "hon" << endl;
    else if(N%10 == 8) cout << "pon" << endl;
    else if(N%10 == 9) cout << "hon" << endl;
    else {abort();}

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long ll;
 
int main()
{
  string O, E;
  cin >> O >> E;

  string a = "";
  REP(i,O.size()+E.size()){
    if(i%2 == 0){
      a.push_back(O.at(i/2));
    }else{
      a.push_back(E.at((i-1)/2));
    }
  }

  cout << a << endl;
}

Measured memory_bytes: 256
X = int(input())

sq = [a ** 2 for a in range(32)[1:]]
sq += [a ** 3 for a in range(11)[1:]]
sq += [a ** 4 for a in range(6)[1:]]
sq += [a ** 5 for a in range(4)[1:]]
sq += [a ** 6 for a in range(4)[1:]]
sq += [a ** 7 for a in range(4)[1:]]
sq += [a ** 8 for a in range(4)[1:]]
sq += [a ** 9 for a in range(4)[1:]]
sq = [a for a in sq if a <= X]
print(max(sq))

Measured memory_bytes: 3064
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a=sorted(a, key=lambda x: x[0])
res=0
i=0
while True:
    if m==0:
        print(res)
        exit()
    if a[i][1]!=0:
        a[i][1]-=1
        res+=a[i][0]
        m-=1
    else:
        i+=1
        a[i][1]-=1
        res+=a[i][0]
        m-=1

Measured memory_bytes: 29792
#include <iostream>
using namespace std;
int main() {
    int r, g, b, n; cin >> r >> g >> b >> n;
    int ans = 0;
    for (int i = 0; i*r <= n; i++)
        for (int j = 0; i*r+j*g <= n; j++) 
            if ((n - i*r - j*g) % b == 0) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=br.readLine();
		
		int i=0;
		
		while(!str.equals("0")){
			i++;
			sb.append("Case ").append(i).append(": ").append(str).append("\n");
			str=br.readLine();
			
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 29216
#include <bits/stdc++.h>
#define db(x) cout<<x<<" "
#define db1(x) cout<<x<<'\n'
#define db2(x,y) cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pair(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ll  long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vpi vector<pair<ll,ll>>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define mod 1000000007
#define MAX_N 100000
using namespace std;
// int dx[4] = {1,-1,0,0};
// int dy[4] = {0,0,1,-1};
ll dp[1000001][2];
ll solve(vector<vector<ll>> &graph, ll root, ll type, ll parent){

    if(dp[root][type]!=-1)
        return dp[root][type];
    ll ans=0;
    ll w1=1;
    for(auto child : graph[root]){
        if(parent!=child)
        w1 = (w1*solve(graph, child, 0, root))%mod;
    }
    ans+=w1;
    ans%=mod;
    if(type==0){
        ll w2 = 1;
        for(auto child : graph[root]){
        if(parent!=child)    
        w2 = (w2*solve(graph, child, 1, root))%mod;
        }
        ans+=w2;
        ans%=mod;
    }
    return dp[root][type] = ans;

}


void solve(){

   ll n;
   cin>>n;
   memset(dp,-1,sizeof(dp));
   vector<vector<ll>> graph(n+1);

   rep(i,n-1){
    ll x,y;
    cin>>x>>y;
    graph[x].push_back(y);
    graph[y].push_back(x);
   }
    
   ll ans = solve(graph, 1, 0, -1);
   db1(ans);

}


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


Measured memory_bytes: 28288
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define pb(x) push_back(x)
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
#define eps 1e-8 
#define ll long long
#define ull unsigned long long
using namespace std;
const int mod=1e9+7;
const int inf=0x3f3f3f3f,maxn=1e5+100;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
double d[20][20];
int n,m;
int dis(int i,int j)
{
	double sum=0;
	FOR(k,1,m)
	sum+=(d[i][k]-d[j][k])*(d[i][k]-d[j][k]);
	double ans=sqrt(sum);
	if(fabs(ans-floor(ans))<eps) return 1;
	else return 0;
}
int main()
{
	cin>>n>>m;
	FOR(i,1,n)
	{
		FOR(j,1,m) 
		cin>>d[i][j];
	}
	int sum=0;
	FOR(i,1,n)
	FOR(j,i+1,n)
	{
		if(dis(i,j)) sum++;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
//ABC164 C

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint n;
string s[200000];

int main() {
  cin >> n;

  rep(i,n){
    //scanf("%s",&s[i]);
    cin >> s[i];
  }
  sort(s,s+n);
  ans = 1;
  rep(i,n-1){
    if(s[i] != s[i+1]) ans++;
  }
  

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


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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);
	ll n;
	cin >> n;
	ll ans = inf;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ll a = n / i;	
			ans = min(ans, a + i);
		}
	}	
	cout << ans - 2 << "\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<ll> v(n);
    ll ans = 0;
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }

    sort(v.begin(),v.end());
    for (int i = 0; i < n-1; i++) {
        for (int j = 1; j < n; j++) {
            if (v[j]-v[i] > ans) {
                ans = v[j]-v[i];
            }
        }
    }
    cout << ans << endl;
    return 0;   
}

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

using namespace std;

#define lint long long

vector<pair<lint, lint>> List(51);
lint num(lint i, lint N){
    if(N == 0){
        if(i == 0){
            return 0;
        } else {
            return 1;
        }
    }
    else if(i >= List[N - 1].first + 2){
        return List[N - 1].second + 1 + num(i - List[N - 1].first - 2, N - 1);
    } else if(i == 1 | i == 0){
        return 0;
    } else {
        return num(i - 1, N - 1);
    }
}


int main(){
    lint N, X;
    cin >> N >> X;
    
    lint l = 1;
    lint p = 1;
    
    for(int i = 0; i < 50; ++i){
        List[i] = make_pair(l, p);
        l = 2 * l + 3;
        p = 2 * p + 1;
    }
    
    cout << num(X, N) << endl;
    
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
MAP = [[0]*10 for _ in range(10)]

for i in range(1,N+1):
    k = list(str(i))
    st = int(k[0])
    ls = int(k[-1])
    MAP[st][ls] += 1
ANS = 0
for i in range(1,10):
    k = MAP[i]
    for j in range(1,10):
        m = k[j]
        ANS += m*MAP[j][i]
print(ANS)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

auto input() {
    return InputType();
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

using ll = long long;
using ull = unsigned long long;

int main() {
    vector<pair<ll, ll>> xy = input();
    auto n = xy.size();
    auto order = make_order(n);
    double av = 0.0;
    size_t m = 0;
    do{
        for (size_t i = 1; i < n; ++i) {
            auto& prev = xy[order[i - 1]];
            auto& elem = xy[order[i]];
            auto vx = elem.first - prev.first;
            auto vy = elem.second - prev.second;
            av += hypot(vx, vy);
        }
        ++m;
    }while(next_permutation(order));
    av /= double(m);
    printf("%.7f", av);
    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;

int main() {

  int a;
  string b,c;
  cin >> a >> b >> c;
  
  rep(i,a) {
    cout << b[i] << c[i];
  }
  
  cout << endl;

}


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

int main() {

  int x,a,b;
  cin >> x >> a >> b;
  
  if(a>=b){
    cout << "delicious" << endl;
  }
  
  else if((b-a)<=x){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: usize,
        B: usize,
        C: usize,
        X: usize,
    }
    let mut ans = 0;
    for i in 0..A+1{
        for j in 0..B+1{
            for k in 0..C+1{
                if 500*i+100*j+50*k == X{
                    ans += 1;
                }
            }
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
void main()
{
    long n, k;
    rdVals(n, k);

    long a = n % k;

    min(a, k-a).writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

bool check( int t, int x, int y, int x2, int y2 )
{
    int x3 = abs( x2 - x );
    int y3 = abs( y2 - y );

    int t_2 = x3 + y3;
    if( t_2 <= t && (t%2) == (t_2%2) ) return true;

    return false;
}

int main() 
{
    int N;
    cin >> N;
    int x, y, x2, y2, t, t2;
    x = y = t = 0;

    for( int i=0 ; i<N ; i++ )
    {
        cin >> t2 >> x2 >> y2;
        if( !check( t2 - t, x, y, x2, y2 ) ) goto ERROR;

        t = t2;
        x = x2;
        y = y2;
    }

    cout << "Yes" << endl;
    return 0;

ERROR:
    cout << "No" << endl;
}

Measured memory_bytes: 256
function Main(input){
	input = input.split("\n");
	var mem = input[1].split(" ").map(Number)
	var a = mem[0];
	var b = mem[1];
	var sum = [0,0,0];
	var arr = input[2].split(" ").map(Number);
	for(var i=0;i<arr.length;i++){
		if(arr[i]<=a){
			sum[0]++;
		}else if(arr[i]<=b){
			sum[1]++;
		}else{
			sum[2]++;
		}
	}
			console.log(Math.min.apply(null,sum));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

int main(){
  int x;
  cin >> x;
  if(x >= 2100) cout << 1 << endl;
  else {
    int a = x/100;
    int b = x % 100;
    if(b <= a*5) cout << 1 << endl;
    else cout << 0 << endl;
  }
  return 0;
}

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

typedef long long ll;

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

    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";
    return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MOD 1000000007
#define MX 105

int n,m,k;
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for (int i=0;i<=n;i++)
    {
        for (int j=0;j<=m;j++)
        {
            int temp=i*m+n*j-2*i*j;
            if (temp==k)
            {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <map>
#include <iostream>

using namespace std;

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

  map<int, int> score;
  int t;
  for (int i=0; i<q; i++) {
    cin>>t;
    score[t]++;
  }

  for (int i=1; i<=n; i++) {
    if (k - (q-score[i]) > 0)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 5376
import numpy as np

N, W = map(int, input().split())
inf = 10**18
M = 10**5
#dp = [0 for i in range(10**5+1)]


dp = np.array([inf for i in range(M+1)])
dp[0] = 0
for i in range(N):
    w, v = map(int, input().split())
    dp[v:] = np.minimum(dp[:-v]+w, dp[v:])
    
for i in range(M+1):
    if dp[M-i] <= W:
        print(M-i)
        break
    

Measured memory_bytes: 16848
N = int(input())
def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        # print("invalid  ",s)
        return 0
    # print("valid    ",s)
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
    for c in '753':
        ret += dfs(s+c) #ここに再起表現が入る
    return ret

print(dfs('0')) 

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a,b) (((a)-(b))>0?((a)-(b)):((b)-(a)))

using namespace std;

int main(){
	int N;
	cin >> N;
	int L[N];
	rep(i,0,N) cin >> L[i];
	sort(L,L+N);
	int cnt = 0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			for(int k=j+1;k<N;k++){
				if( L[i]+L[j] > L[k] ){
					if( L[i]!=L[j] && L[j]!=L[k] ) cnt++;
				}else break;
			}
		}
	}
	
	cout << cnt;
	
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
 
using namespace std;
 
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c;
 
    if(c < b)
    {
        d = b;
        b = c;
        c = d;
    }
    if(b < a)
    {
        d = a;
        a = b;
        b = d;
    }
    if(c < b)
    {
        d = b;
        b = c;
        c = d;
    }
    cout << a << " " << b << " " << c << endl;
 
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include <bits/stdc++.h>

using namespace std;

typedef pair<long long,bool> Pair;
const long long INF = 1LL<<60;

int main(){

long long N,M;
long long all;
long long oddNumber;

cin >> N >> M;

all = ((N+M)*(N+M-1))/(2);

oddNumber = N*M;

cout << all - oddNumber << 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++) 
typedef long long ll;

int main(){
    vector<int> x(5);
    for(int i=0;i<5;i++){
        cin >> x[i];
    }

    for(int i=0;i<5;i++){
        if(x[i]==0){
            cout << i+1 << endl;
        }
    }

    
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int h,w,k;
    cin >> h >> w >> k;
    vvi s(h,vi(w));
    rep(i,h) rep(j,w) {
        char c;
        cin >> c;
        s[i][j] = (int)c-'0';
    }
    int ans = inf;
    rep(bit,1<<(h-1)) {
        int cnt = __builtin_popcount(bit);
        int nans = cnt;
        vi v(cnt+1,0);
        int last = -1;
        map<int,int> pos;
        pos[0] = 0;
        rep2(i,1,h) {
            if(bit>>(i-1)&1) pos[i] = pos[i-1]+1;
            else pos[i] = pos[i-1];
        }
        bool flag2 = false;
        rep(i,w) {
            rep(j,h) v[pos[j]] += s[j][i];
            bool flag = false;
            for(auto j : v) {
                if(j > k) {
                    if(i == last+1) {
                        flag = true;
                        break;
                    }
                    last = i-1;
                    nans++;
                    rep(l,cnt+1) v[l] = 0;
                    rep(l,h) v[pos[l]] += s[l][i];
                    rep(l,cnt+1) if(v[l] > k) flag = true;
                    break;
                }
            }
            if(flag) {
                flag2 = true;
                break;
            }
        }
        if(flag2) continue;
        chmin(ans,nans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
const int N = 1e5+2;
signed main()
{
    fast;
    string s;
    cin>>s;
    if(s=="Sunny")
        cout<<"Cloudy";
    else if(s=="Cloudy")
        cout<<"Rainy";
    else cout<<"Sunny";
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = list(input())
c = Counter(S)
left_facing_west = 0
right_facing_east = c['E']
ans = float('inf')
for s in S:
    if s == 'W':
        ans = min(ans,left_facing_west+right_facing_east)
        left_facing_west += 1
    else:
        right_facing_east -= 1
        ans = min(ans,left_facing_west+right_facing_east)
print(ans)

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

int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long ans = 0;
  
  if (K <= A) {
    ans = K;
  }
  else if (K <= (A + B)) {
    ans = A;
  }
  else {
    ans = 2 * A + B - K;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    ll n,t;
    std::cin >> n>>t;
    VEC(ll,a,n);
    a.pb(INF64);
    ll ans=0;
    rep(i,n){
        ans+=min(t,a[i+1]-a[i]);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 4736
/**
 * @author: Jun
 * @date  : 03-18-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int res=0;
    res += k*x;
    if(n>k){
        res += (n-k)*y;
    } else {
        res = n*x;
    }
    cout << res << el;
    return 0;
}

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if((b-a)%2 == 0){
        cout << (b-a)/2 << endl;
    }else{
        ll m = min(a + b - 2, 2 * n - a - b);
        cout << (m + 1) / 2 << endl;
    }
    
}

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

namespace ABC112A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N,A,B;

            N = int.Parse(Console.ReadLine());


            if (N == 1)
                Console.Write("Hello World");
            else if (N == 2)
            {
                A = int.Parse(Console.ReadLine());
                B = int.Parse(Console.ReadLine());
                Console.WriteLine(A + B);
            }

            Console.ReadKey();
        }
    }
}


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

int main(){
    int x,y,z;
    char s1,s2;
    cin >> x >> s1 >> y >> s2 >> z;
    if(y > 4){
        cout << "TBD" << endl;
        return 0;
    }
    cout << "Heisei" << endl;
}

Measured memory_bytes: 256
// AOJ 1310: Find the Multiples
// 2017.10.3 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HASHSIZ 300017
typedef struct { int b; int v; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

int lookup(int b)
{
	HASH *p = hash + b % HASHSIZ;
	while (p->b) {
		if (p->b == b) return p->v;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(int b)
{
	HASH *p = hash + b % HASHSIZ;
	while (p->b) {
		if (p->b == b) { p->v++; return; }
		if (++p == hashend) p = hash;
	}
	p->b = b, p->v = 1;
}

int a[100002];
int b[100002];
int tr[10][6];

int main()
{
	int n, s, w, q, g, i, k, ans;

	tr[0][2] = tr[2][2] = tr[4][2] = tr[6][2] = tr[8][2] = tr[0][5] = tr[5][5] = 1;

    while (scanf("%d%d%d%d", &n, &s, &w, &q) && n > 0) {
		g = s;
		for (i = 0; i < n; i++) {
			a[i] = (g/7) % 10;
			if (g & 1) g = (g >> 1) ^ w;
			else g >>= 1;
		}

		ans = 0;
		if (q == 2 || q == 5) {
			for (k = 0, i = 0; i < n; i++) {
				if (a[i]) k++;
				if (tr[a[i]][q]) ans += k;
			}
		} else {
			memset(hash, 0, sizeof(hash));
			for (k = 1, b[n] = 0, i = n-1; i >= 0; i--){
				b[i] = (k*a[i] + b[i+1]) % q;
				k = ((k<<3)+(k<<1)) % q;
			}
			for (i = 0; i < n; i++) {
				if (a[i]) insert(b[i]+1);
				ans += lookup(b[i+1]+1);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 4848
N = int(input())
H = list(map(int,input().split()))
H.append(10**9+1)
count = [-1]
H.append(10**9+1)
temp_count = 0
temp = 0
for i in range(N+1):
  if H[i] <= temp:
    temp = H[i]
    temp_count += 1
  else:
    temp = H[i]
    count.append(temp_count)
    temp_count = 0
print(max(count))      

Measured memory_bytes: 14252
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

bool isSameDigits(int x) {
    int left = x % 10;
    bool isSame = true;
    while (x > 0) {
        if (left != x % 10) isSame = false;
        x /= 10;
    }
    return isSame;
}

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

    int ans;
    for (int i = N; i <= 999; i++) {
        if (isSameDigits(i)) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define modadd(x,y,m) x=(x+(y))%m
#define modmul(x,y,m) x=(x*(y))%m

int N;
string S;

ll solve(){
	N = S.size();
	int m = 2019;
	vector<int> r_count(m, 0); // [r] count
	int ten = 1; // S[left, right) -> 10^right init 10^0 = 1
	int r = 0; // remainder
	r_count[r]++;

	irp(left,N-1,0-1){ // left:[N-1,0]
		// cout<<S.substr(left,N-left)<<"\n";//
		modadd(r, (S[left]-'0')*ten, m);
		modmul(ten, 10, m);
		r_count[r]++;
	}

	// cout<<" N "<<N;
	// cout<<" S "<<S;
	// cout<<"\n";
	// rp(r,0,m){
	// 	if(r_count[r]>0){
	// 		cout<<" r "<<r;
	// 		cout<<" cnt "<<r_count[r];
	// 		cout<<"\n";
	// 	}
	// }

	ll ans = 0;
	rp(r,0,m){
		ans += r_count[r]*(r_count[r]-1)/2; // rC2
	}
	return ans;
}


int main(){
	cin>>S;
	cout<< solve() <<endl;
}


Measured memory_bytes: 3724
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
// #MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(int argc, char const *argv[]) {
  int n; std::cin >> n;
  int a[n]; REP(i,n-1) std::cin >> a[i];
  int v[n]={0};
  REP(i,n-1) {
    v[a[i]-1]++;
  }
  REP(i,n) std::cout << v[i] << '\n';
  return 0;
}


Measured memory_bytes: 5196
from collections import defaultdict
N = int(input())
dict = defaultdict(list)
dlist = []
names =[]
newnums = []
for n in range(N):
    s,p = input().split()
    dlist.append((s,int(p)))
    dict[s].append(int(p))
    names.append(s)
names.sort()
usedname = []
for name in names:
    if name in usedname:
        continue
    usedname.append(name)
    numlist = dict[name]
    numlist.sort(reverse=True)
    for num in numlist:
        print(dlist.index((name,int(num)))+1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
const int inf = 1e9+7;
int mod = 1e9+7;

bitset<4000004> dp;
int a[2000];
signed main(){
	int n, sum = 0;
	scanf("%lld", &n);
	rep(i,n)scanf("%lld", &a[i]);
	dp[0] = 1;
	rep(i,n)dp |= dp<<a[i];
	rep(i,n)sum += a[i];
	repi(i,(sum+1)/2,sum+1)if(dp[i]){
		printf("%lld\n", i);
		break;
	}
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long mod = 1000000007;
        int[] c = new int[n]; //c[i] -> i番目の色
        for(int i = 0; i < n; i++){
            c[i] = sc.nextInt() - 1;
        }
        long[] x = new long[200000]; //x[i] -> ここまでの色iの直前のansの総和
        long[] ans = new long[n]; //ans[i] -> i番目までの数字での並び方の総数
        x[c[0]] = 1;
        int last = c[0];
        ans[0] = 1;
        for(int i = 1; i < n; i++){
            ans[i] = ans[i-1];// + Math.max(0, 2 * x[c[i]] - 1);
            if(last != c[i]){
                ans[i] += x[c[i]];
                x[c[i]] += ans[i-1];
                x[c[i]] %= mod;
                last = c[i];
            }
            ans[i] %= mod;
        }
        System.out.println(ans[n-1]);
    }
}

Measured memory_bytes: 84508
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m;
ll a[100005],b[100005];
ll ans=0;
string s,t;
bool flag=false;

int main(){
	cin>>n>>s>>t;
	for(i=0;i<n;i++){
		if(s.substr(i,n-i)==t.substr(0,n-i)){
			flag=true;
			break;
		}
	}
	if(!flag)i=n;
	cout<<n+i<<endl;
	
	return 0;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

int main(void){
	
	string s;

	int y, m, d;



	cin >> s;

	y = stoi(s);

	s.erase(s.begin(), s.begin() + 5);

	m = stoi(s);

	s.erase(s.begin(), s.begin() + 3);

	d = stoi(s);

//	cout << s<<"\n";

	if (y < 2019) {
		cout << "Heisei\n";
	}
	else if (y == 2019 && m < 4) {
		cout << "Heisei\n";
	}
	else if (m == 4 && d <= 30) {
		cout << "Heisei\n";
	}
	else {
		cout << "TBD\n";
	}

//	printf("%d %d %d\n",y,m,d);

	return 0;
}

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

using namespace std;

int getRank(char rank){
  if(isdigit(rank)){ return rank-'0'; }
  if(rank == 'T'){ return 10; }
  if(rank == 'J'){ return 11; }
  if(rank == 'Q'){ return 12; }
  if(rank == 'K'){ return 13; }
  if(rank == 'A'){ return 14; }
  return -1;
}

int getSuit(char suit){
  if(suit == 'C'){ return 0; }
  if(suit == 'H'){ return 1; }
  if(suit == 'D'){ return 2; }
  if(suit == 'S'){ return 3; }
  return -1;
}

int main(){
  char T;
  while(cin >> T, T != '#'){
    string Card;
    int Trump = getSuit(T);
    int rank[4][13],suit[4][13];
    for(int i = 0 ; i < 4 ; i++){
      for(int j = 0 ; j < 13 ; j++){
        cin >> Card;
        rank[i][j] = getRank(Card[0]);
        suit[i][j] = getSuit(Card[1]);
      }
    }
    int dealer = 0;
    int team[2] = {0};
    for(int turn = 0 ; turn < 13 ; turn++){
      int winner = dealer;
      int s = suit[dealer][turn];
      int r = rank[dealer][turn];
      if(s == Trump){ r += 13; }
      for(int i = 1 ; i < 4 ; i++){
        int player = (dealer+i) % 4;
        int ns = suit[player][turn];
        int nr = rank[player][turn];
        if(ns == Trump){ nr += 13; }
        if(ns != s && ns != Trump){
          continue;
        }
        if(r < nr){
          r = nr;
          winner = player;
        }
      }
      team[winner%2]++;
      dealer = winner;
    }
    for(int i = 0 ; i < 2 ; i++){
      team[i] -= 6;
    }
    if(team[0] < team[1]){
      cout << "EW " << team[1] << endl;
    }else{
      cout << "NS " << team[0] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>

int main() {
	int h1, m1, h2, m2, k;
	scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
	if (m1 > m2)
	{
		h2--;
		m2 += 60;
	}
	int duration = (h2-h1)*60 + (m2-m1);
	duration > k ? printf("%d\n",duration-k) : printf("0\n");
	return 0;
}



Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;

int main(){

    fastio ;

    vector<ll> a(105);
    vector<ll> dp(100005);
    ll n,k;

    cin >> n >> k;
    for(ll i = 0; i < n; i++) cin >> a[i];

    // OPTIMAL SUB-PROBLEM :

    // dp[i] = 1 if Taro wins with k = i
    //         2 otherwise

    // BASE CASE :

    for(ll i = 0; i < a[0]; i++) dp[i] = 2;
    for(ll i = 0 ; i < n ;i++) dp[a[i]] = 1;

    // RECURSIVE RELATION :

    for(ll i = a[0]+1; i <= k ; i++){
        if(dp[i] != 0) continue;
        ll any2 = 0;
        ll all2 = 1;

        for(ll j = 0; j < n; j++){
            if(i - a[j] >= 0 && dp[i-a[j]] == 2) any2 = 1;
            if(i - a[j] >= 0 && dp[i-a[j]] == 1) all2 = 0;
        }

        if(any2 == 1 || all2 == 1) dp[i] = 1;
        else dp[i] = 2;
    }
    // OPTIMAL SOLUTION :

    if(dp[k] == 1) cout << "First";
    else cout << "Second";
}

Measured memory_bytes: 1024
/*
 *  Author :: Kattu37
 */

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

#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortallr(x) sort(allr(x))
#define PI 3.1415926535897932384626
#define mod 1000000007

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

void solve()
{
	int n;
	cin >> n;
	if(n%1000!=0)
		cout << 1000 - n % 1000 << "\n";
	else cout<<0<<"\n";
}

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

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}


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

using namespace std;
typedef long long int lld;
#define INF 1000000000000000000
#define MOD 1000000007
int DP[1000000];
int n,k;
int arr[400];
int compute(int pos){//cout<<a<<" "<<b<<" "<<c<<endl;
	if(DP[pos]!=-1)return DP[pos];
	DP[pos]=0;
	for(int i=0;i<n;i++){
		if(pos-arr[i]>=0)DP[pos]=max(DP[pos],1-compute(pos-arr[i]));
	}
	return DP[pos];
}
int main(){
	cin>>n>>k;
	
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	for(int i=0;i<=k;i++){
		DP[i]=-1;
	}
	DP[0]=0;
	int ans=compute(k);
	if(ans==1)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	
	return 0;
}

Measured memory_bytes: 5376
from collections import deque
from bisect import bisect_left, bisect_right
from itertools import accumulate


n,m,k = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

al_sums = list(accumulate(al))
bl_sums = list(accumulate(bl))

ans = 0
for i in range(0,n+1):
    if i == 0: 
        a_sum = 0
    else:
        a_sum = al_sums[i-1]
    if a_sum > k: 
        continue
    cnt = bisect_right(bl_sums, k-a_sum)
    curr_ans = i+cnt
    ans = max(ans,curr_ans)

print(ans)

Measured memory_bytes: 130736
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];

        PriorityQueue<Point> que = new PriorityQueue<>((k, l) -> l.y - k.y);

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            que.add(new Point(i, a[i] + b[i]));
        }

        boolean t = true;

        long ts = 0;
        long as = 0;

        while (!que.isEmpty()) {
            if (t) {
                ts += a[que.poll().x];
            } else {
                as += b[que.poll().x];
            }
            t = !t;
        }

        System.out.println(ts - as);
    }
}

Measured memory_bytes: 88940