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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e7 + 7;
const int MX = 998244353;
const LL INF = 1LL * MX * MX;

int n;
int rv[N];
int sil[N];

int fast(int a, int b){
	int ret = 1;
	while(b){
		if(b & 1)
			ret = (1LL * ret * a) % MX;
		
		b >>= 1;
		a = (1LL * a * a) % MX;
	}
	
	return ret;
}

inline int newton(int a, int b){
	return (((1LL * sil[a] * rv[b]) % MX) * rv[a - b]) % MX;
}

int main(){
	scanf("%d", &n);
	sil[0] = 1;
	for(int i = 1; i <= n; ++i)
		sil[i] = 1LL * i * sil[i - 1] % MX;
	
	rv[n] = fast(sil[n], MX - 2);
	for(int i = n; i >= 1; --i)
		rv[i - 1] = 1LL * i * rv[i] % MX;
	
	int cur = 1, ans = 0;
	for(int i = n; i + i > n; --i){
		ans = (ans + 1LL * cur * newton(n, i)) % MX;
		cur = (cur + cur) % MX;
	}

	ans = (ans + ans) % MX;
	ans = (fast(3, n) + MX - ans) % MX;
	printf("%d\n", ans);
	return 0;
}

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

// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve_main()
{
    int n;cin>>n;
    string s;cin>>s;
    int ans =0 ;
    for(int i=0;i<n;++i)
    {
    	if(s[i]!='A')continue;
    	if(i+2>=n)continue;
    	if(s[i+1]=='B' && s[i+2]=='C')
    		ans++;
    }
    cout<<ans;
}

int main()
{
	#ifndef ONLINE_JUDGE
    	freopen("/home/suryakant/input.txt","r",stdin);
        freopen("/home/suryakant/output.txt","w",stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void) {
   int N, T;

   scanf("%d %d", &N, &T);
   int c[N];
   int t[N];

   for(int i = 0; i < N; i++) {
      scanf("%d %d", &c[i], &t[i]);
   }

   int cnt = 0;
   int c_min = 1001;

   for(int i = 0; i < N; i++) {
      if(t[i] <= T && c_min > c[i]) {
         c_min = c[i];
         cnt++;
      }
   }

   if(cnt == 0) {
      printf("TLE\n");
   } else {
      printf("%d\n", c_min);
   }
   
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;

	cin >> N;
	cout << (N + 1) / 2 << endl;

	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
	ll N, M;
	cin >> N >> M;
	ll graph[N][N];
	REP(i, N)REP(j, N) graph[i][j] = 0;
	REP(i, M){
		ll a, b;
		cin >> a >> b;
		a--;b--;
		graph[a][b] = 1;
		graph[b][a] = 1;
	}

	vector<ll> perm(N);
	REP(i, N) perm[i] = i;
	bool flag = true;
	ll res = 0;
	while(flag){
		bool path = true;
		REP(i, N-1){
			if(graph[perm[i]][perm[i+1]]==0) path = false;
		}
		if(perm[0]==0) res += path;
		flag= next_permutation(perm.begin(), perm.end());
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
ans = [0, 0]
cnt = 0
while True:
    try:
        x, y = map(int, input().split(','))
        cnt += 1
    except:
        break
    ans[0] += x*y
    ans[1] += y
ans[1] = ans[1]/cnt
if int(str(ans[1]).split(".")[0]) > 4:
    ans[1] += 1
ans[1] = int(ans[1])
print(*ans, sep="\n")

Measured memory_bytes: 7620
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int r=0,l=0,t[100007]={},n=s.size();
    for(int i=0;i<n-1;i++){
        if(s[i]=='R') r++;
        if(s[i]=='L') l++;
        if(l==0&&s[i+1]=='L'){
            t[i+1] += r/2;
            t[i] += r-r/2;
            r=0;
        }
        if(r==0&&(s[i+1]=='R'||i==n-2)){
            int c = l+(i==n-2);
            t[i-l] += c/2;
            t[i-l+1] += c-c/2;
            l=0;
        }
    }
    for(int i=0;i<n;i++) cout << t[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 4128
//abc173_d.cpp
//Sun Jul  5 20:55:27 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

int main(){
	ll n;
	cin >> n;

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

	sort(a,a+n,greater<ll>());

	queue<ll> q;

	ll prevn = a[0];
	q.push(a[0]);
	ll ans = 0;
	for (int i=1;i<n;i++){
		ans += q.front(); q.pop();
		q.push(a[i]);
		q.push(a[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 6568
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    double bunbo=0,bunsi=1;
    for(int i=0;i<n;i++)bunsi *= a[i];
    for(int i=0;i<n;i++)bunbo += bunsi/a[i];

    double ans = bunsi / bunbo;
    cout << ans<< endl;
    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
map<ll, ll> mp;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  cin >> n;
  set<ll> st;
  vector<ll> yakusuu = divisor(n);
  rep(i, Size(yakusuu)) {
    if (yakusuu[i] == 1) continue;
    tmp = n;
    while (1) {
      if (tmp % yakusuu[i] != 0) break;
      tmp /= yakusuu[i];
    }
    tmp--;
    if (tmp % yakusuu[i] == 0) {
      // debug(yakusuu[i]);
      st.insert(yakusuu[i]);
    }
  }

  vector<ll> ya = divisor(n - 1);
  rep(i, Size(ya)) {
    if (ya[i] == 1) continue;
    st.insert(ya[i]);
  }
  Cout(Size(st));
  return 0;
}

Measured memory_bytes: 384
N = int(input())
s1 = input()
s2 = input()

ans = 1

for i in range(N) :
    if i == 0 :
        if s1[i] == s2[i] :
            ans *= 3
            state = 0
        else :
            ans *= 6
            state = 1
    else :
        if (s1[i] == s1[i-1]) and (s2[i] == s2[i-1]) :
            continue
        if s1[i] == s2[i] :
            if state == 0 :
                ans *= 2
            else :
                ans *= 1
            state = 0
        else :
            if state == 0 :
                ans *= 2
            else :
                ans *= 3
            state = 1
    ans %= 10**9+7

print(ans)


Measured memory_bytes: 3064
c = input()
alp = ["a", "b", "c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
count = 0
for i in range(len(alp)):
    if c == alp[i]:
        break
    count += 1
print(alp[count+1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc113_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  double T, A;
  cin >> N >> T >> A;

  vector<double> c(N);
  rep(i, N) { cin >> c[i]; }

  ll ans = 0;
  double minT = INF;
  rep(i, N) {
    double tmp = abs(A - (T - c[i] * 0.006));
    if (minT > tmp) {
      ans = i;
      minT = tmp;
    }
  }

  cout << ans + 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

int n,m,q;

int h[100001],D[100001],nxt[300001],to[300001],w1[300001],w2[300001],tot;
void ins(int x,int y){nxt[++tot]=h[x];to[tot]=y;h[x]=tot;}
void ins2(int x,int y,int c,int i){nxt[++tot]=D[x];to[tot]=y;w1[tot]=c;w2[tot]=i;D[x]=tot;}

int C[100001],T[100001];
int C2[100001],T2[100001];

int main(){ int x,y;
	scanf("%d%d",&n,&m);
	F(i,1,m) scanf("%d%d",&x,&y), ins(x,y), ins(y,x);
	scanf("%d",&q);
	F(i,1,q){
		int v,d,c;
		scanf("%d%d%d",&v,&d,&c);
		ins2(d,v,c,i);
	}
	dF(k,10,0){
		F(i,1,n) C2[i]=T2[i]=0;
		F(i,1,n){
			if(C[i]){
				for(int j=h[i];j;j=nxt[j]){
					if(T2[to[j]]<T[i])
						T2[to[j]]=T[i], C2[to[j]]=C[i];
				}
				if(T2[i]<T[i])
					T2[i]=T[i], C2[i]=C[i];
			}
		}
		F(i,1,n) C[i]=C2[i],T[i]=T2[i];
		for(int i=D[k];i;i=nxt[i]){
			int u=to[i], c=w1[i], t=w2[i];
			if(T[u]<t) C[u]=c, T[u]=t;
		}
	}
	F(i,1,n) printf("%d\n",C[i]);
	return 0;
}

Measured memory_bytes: 6784
#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
  freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/ACM/output.txt", "w", stdout);
  //freopen("out.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
    //cout << "Case #" << testNum++ << ": ";
    //cerr << testNum << endl;
    solve(true);
    //cerr << testNum - 1 << endl;
  }
  cout.flush();
#ifdef AIM1
  while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

  return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
  if (!w)
    return 1 % mod;
  if (w & 1)
    return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template<typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
  sort(all(a));
  a.erase(unique(all(a)), a.end());
}

void precalc() {}

template<typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}

//#define int li
//const int mod = 1000000007;

void solve(bool read) {
    int n, m, k;
    cin >> n >> m >> k;
    for (int x = 0; x <= n; ++x) {
        for (int y = 0; y <= m; ++y) {
            if (x * (m - y) + y * (n - x) == k) {
                cout << "Yes\n";
                return;
            }
        }
    }
    cout << "No\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	int mx = 0, ans = 0;
	for(int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if(x < mx) ans += mx - x;
		else mx = x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
N,M = map(int,input().split())
A = list(map(int,input().split()))

dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[N])


                





Measured memory_bytes: 14668
package main

import "fmt"

func index(val int, vs []int) int {
	for i, v := range vs {
		if v == val {
			return i
		}
	}
	return -1
}

func div_roundup(a, b int) int {
	if a == 0 {
		return 0
	}
	return (a-1)/b + 1
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	as := make([]int, N)
	for i := range as {
		fmt.Scan(&as[i])
	}

	i := index(1, as)
	l := i
	r := len(as) - 1 - i
	fmt.Println(l/(K-1) + r/(K-1) + div_roundup(l%(K-1)+r%(K-1), K-1))
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const ll maxn_warshall_floyd=505;
ll dist[maxn_warshall_floyd][maxn_warshall_floyd];
ll n;
void warshallfloyd(){
  for(ll k = 0; k < n; k++)
    for(ll i = 0; i < n; i ++)
      for(ll j = 0; j < n; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  n=10;
  rep(i,n){
    rep(j,n) cin>>dist[i][j];
  }
  warshallfloyd();
  ll ans=0;
  rep(i,h){
    rep(j,w){
      ll a; cin>>a;
      if(a==-1) continue;
      ans+=dist[a][1];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <stdio.h>
#include <sstream>
using namespace std;

int main(){
	//carryªIChaveªÁÄ¢é
	int carry,have,sum_prize;
	long int mod[8]={100000000,10000000,1000000,100000,10000,1000,100,10};
	while(cin >> carry >> have){
//		cout << carry <<" " << have << endl;
		if(carry == 0 && have == 0) break;
		string number;
//		char *number[100];
		int prize[100],index[100],num[100];
		for(int icarry=0;icarry<carry;icarry++){
			cin >> number >> prize[icarry];
//			cout << number << endl;
			index[icarry] = number.rfind("*");
//			cout << number << " " << index[icarry] << endl;
			for(int i=0;i<=index[icarry];i++){
//				if(index[icarry]==-1) break;
				number.replace(number.find("*"),1," ");
//				cout << number << endl;
			}
			istringstream ss(number);
			ss >> num[icarry];
//			cout << num[icarry] << " " << prize[icarry] << endl;
		}
//		cout << endl;
		int lotnum[1000];
		for(int ihave=0;ihave<have;ihave++){
			cin >> lotnum[ihave];
//			cout << lotnum[ihave] << endl;
		}

		sum_prize = 0;
		//numªIÔ,prizeªIàz
		for(int j=0;j<carry;j++){
			for(int k=0;k<have;k++){
				if((lotnum[k]-num[j])%mod[index[j]+1]==0){
						sum_prize += prize[j];
				}
			}
//				cout << index[j] << endl;
		}
		cout << sum_prize << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false; cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
vector<pair<lli, bool>> a;
int main() {
  cin >> n; 
  a = decltype(a)(n, { 0, true });
  for (lli i=0; i<n; ++i) cin >> a[i].first;
  sort(begin(a), end(a));
  lli i = n-1;
  lli ans = 0;
  for (lli m=32; m>0; --m) {
    lli s = 1ll << m;
    for (; i>=0 && a[i].first>=s>>1ll; --i) {
      if (!a[i].second) continue;
      auto p = equal_range(begin(a), begin(a) + i, 
	  make_pair(s-a[i].first, true));
      lli idx = p.first - begin(a);
      if (p.first != p.second && a[i].second) {
	++ans;
	a[idx].second = false;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
from collections import Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N = int(stdin.readline().rstrip())
A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))

A_ = Counter(A)

for i in range(1,N+1):
    print(A_[i])

Measured memory_bytes: 35532
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=3000+10,mo=1000000007;
int f[maxn][maxn][2],g[maxn][maxn][2][2];
int i,j,k,l,t,n,m,ans;
int main(){
    scanf("%d%d",&n,&m);
    f[0][0][1]=1;
    fo(i,1,n) f[0][i][0]=1;
    fo(i,0,m-1)
        fo(j,0,n)
            fo(k,0,1){
                if (j) (f[i+1][j-1][k|(j-1==0)]+=f[i][j][k])%=mo;
                if (j) (f[i+1][j][k|(j==1)]+=f[i][j][k])%=mo;
                if (n-j) (f[i+1][j][k]+=f[i][j][k])%=mo;
                if (n-j) (f[i+1][j+1][k]+=f[i][j][k])%=mo;
            }
    fo(i,0,n) (ans+=f[m][i][1])%=mo;
    printf("%d\n",ans);
}

Measured memory_bytes: 71040
#include<iostream>
#include<algorithm>

using namespace std;

struct P{
    P(double a, double b){
	x = a;
	y = b;
    }
    double x, y;
    double det(P a){
	return x * a.y - y * a.x;
    }
    P operator-(P a){
	return P(x - a.x, y - a.y);
    }
};

int main(){
    double x1, x2, x3, xp, y1, y2, y3, yp;
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
	P a = P(x1, y1);
	P b = P(x2, y2);
	P c = P(x3, y3);
	P p = P(xp, yp);
	if(((a - p).det(b - a) <= 0) == ((b - p).det(c - b) <= 0) &&
	   ((b - p).det(c - b) <= 0) == ((c - p).det(a - c) <= 0)) {
	    cout << "YES" << endl;
	}
	else{
	    cout << "NO" << endl;
	}
				
    }
    return 0;
}

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

using namespace std;

int main () {
	int N;
	cin >> N;
	int a = 0, b = 0, c = 0, ta, tb, tc;
	for (int i = 0; i < N; i++) {
		cin >> ta >> tb >> tc;
		ta += max(b, c);
		tb += max(c, a);
		tc += max(a, b);
		a = ta;
		b = tb;
		c = tc;
	}
	cout << max(a, max(b, c)) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <climits>
using namespace std;

// 50 * 6, *6は座標圧縮で増える分
#define MAX_N 310

int field[MAX_N][MAX_N];

vector<int> compress(const vector<int>& v, vector<int>& invert) {
    vector<int> xs;
    for (int i=0; i<v.size(); i++) {
        for (int d=-1; d<=1; d++) {
            xs.push_back(v[i] + d);
        }
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());

    vector<int> res;
    for (int i=0; i<v.size(); i++) {
        int nx = find(xs.begin(), xs.end(), v[i]) - xs.begin();
        res.push_back(nx);
    }

    // 逆引き
    for (int i=0; i<xs.size(); i++) {
        invert.push_back(xs[i]);
    }
    return res;
}

// (x1,y1)が左上、(x2,y2)が右下
int countPoint(int x1, int y1, int x2, int y2) {
    int res = 0;
    res += field[y2][x2];
    if (x1 > 0) res -= field[y2][x1-1];
    if (y1 > 0) res -= field[y1-1][x2];
    if (x1 > 0 && y1 > 0) res += field[y1-1][x1-1];
    return res;
}

// 左上(x1,y2), 右下(x2,y2) どちらも座標圧縮された座標
long long calcRectangleArea(int x1, int y1, int x2, int y2, const vector<int>& ix, const vector<int>& iy) {
    return abs((long long)ix.at(x1) - (long long)ix.at(x2)) * abs((long long)iy.at(y1) - (long long)iy.at(y2));
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    vector<int> invert_x, invert_y;

    for (int i=0; i<N; i++) {
        cin >> x[i] >> y[i];
    }
    vector<int> cx = compress(x, invert_x);
    vector<int> cy = compress(y, invert_y);

    for (int i=0; i<N; i++) {
        field[cy[i]][cx[i]]++;
    }

    // 累積和
    for (int i=1; i<MAX_N; i++) {
        field[0][i] += field[0][i-1];
        field[i][0] += field[i-1][0];
    }
    for (int i=1; i<MAX_N; i++) {
        for (int j=1; j<MAX_N; j++) {
            field[i][j] += field[i-1][j] + field[i][j-1] - field[i-1][j-1];
        }
    }

    // 適当に長方形を選ぶ
    int W = 0;
    int H = 0;
    for (int i=0; i<cx.size(); i++) W = max(W, cx[i]);
    for (int i=0; i<cy.size(); i++) H = max(H, cy[i]);


    long long sum = LLONG_MAX;
    for (int y1=0; y1<=H; y1++) {
        for (int x1=0; x1<=W; x1++) {
            for (int y2=y1+1; y2<=H; y2++) {
                for (int x2=x1+1; x2<=W; x2++) {
                    int k = countPoint(x1,y1,x2,y2);
                    if (K <= k) {
                        long long s = calcRectangleArea(x1, y1, x2, y2, invert_x, invert_y);
                        sum = min(sum, s);
                    }
                }
            }
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 768
package main

import (
	"fmt"
	"strings"
)

func main() {
	solve()
}

func solve() {
	var S string
	fmt.Scan(&S)
	if strings.HasSuffix(S, "s") {
		fmt.Println(S + "es")
	} else {
		fmt.Println(S + "s")
	}
}


Measured memory_bytes: 1784
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

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

bool maps[100][100];
int w, h, n;

int main() {
	cin >> w >> h >> n;
	
	REP(i, n) {
		int x, y, a;
		scanf("%d %d %d", &x, &y, &a);
		
		int cnt = 0;
		switch (a) {
		case 1:
			REP(j, x) REP(i, h) maps[i][j] = true;
			break;
		case 2:
			FOR(j, x, w) REP(i, h) maps[i][j] = true;
			break;
		case 3:
			REP(i, y) REP(j, w) maps[i][j] = true;
			break;
		case 4:
			FOR(i, y, h) REP(j, w) maps[i][j] = true;
			break;
		}
	}
	
	int ans = 0;
	REP(i, h) REP(j, w) if (!maps[i][j]) ans++;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = n-1; i > 0; i--)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  ll n;cin>>n;
  vector<ll>A(n);
  rep(i,n){
    cin>>A[i];
  }
  sort(all(A),greater<ll>());
  //１つ目は+。その後負の値が出てきたら
  vector<pair<ll,ll>>v;
  for(int i=1;i<n-1;i++){
    if(A[i]<=0){
      v.push_back(make_pair(A[0],A[i]));
      A[0]-=A[i];
    }
  }
  for(int i=1;i<n-1;i++){
    if(A[i]>0){
      v.push_back(make_pair(A[n-1],A[i]));
      A[n-1]-=A[i];
    }
  }
  v.push_back(make_pair(A[0],A[n-1]));
  cout<<A[0]-A[n-1]<<endl;
  for(auto&&i:v)cout<<i.first<<" "<<i.second<<endl;
  return false;
}


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 4336
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef long long ll;

const int MAX_SIZE = 10000;

struct edge{
	int to;
	int cost;
};

class Situation{
public:
	int cost;
	int idx;
	int change;

	Situation(int cost_,int idx_,int change_){
		cost=cost_;
		idx=idx_;
		change=change_;
	}
	Situation();

	bool operator<(const Situation &s)const{
		return s.cost < this->cost;
	}
};

//typedef pair<int,int> P;
int V;

const int MAX_V = 101;

vector<edge> G[MAX_V];
int d[MAX_V][1001];
const int INF = 1000000000;
int m;

void dijkstra(int s){
	priority_queue<Situation> que;
	for(int i=0;i<101;i++)for(int j=0;j<1001;j++)d[i][j]=INF;
	d[s][0] = 0;
	que.push(Situation(0,s,0));
	while(!que.empty()){
		Situation p = que.top();
		que.pop();
		int v = p.idx;
		int k= p.change;
		if(d[v][k] < p.cost)continue;
		for(int i = 0; i < (int)G[v].size(); i++){
			edge e = G[v][i];
			if(k+1<=m&&d[e.to][k+1] > d[v][k]){
				d[e.to][k+1] = d[v][k];
				que.push(Situation(d[e.to][k+1],e.to,k+1));
			}
			if(d[e.to][k] > d[v][k] + e.cost){
				d[e.to][k] = d[v][k] + e.cost;
				que.push(Situation(d[e.to][k],e.to,k));
			}
		}
	}
}

int main(){

	int n,c;
	while(cin>>n>>m>>c&&(n|m|c)){
		for(int i=0;i<MAX_V;i++)G[i].clear();
		for(int i=0;i<m;i++){
			int f,t,ct;
			cin>>f>>t>>ct;
			edge e;
			e.cost=ct;
			e.to=t;
			G[f].push_back(e);
		}
		dijkstra(1);
		for(int i=0;i<1001;i++){
			if(d[n][i]<=c){
				cout<<i<<endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
# ABC133C - Remainder Minimization 2019
def main():
    L, R = list(map(int, input().rstrip().split()))
    MOD = 2019
    if (R // MOD) - (L // MOD) > 0:  # L <= 2019n <= R
        print(0)
    else:  # R - L <= 2018 -> max: 2018 * 2017 patterns
        ans = float("inf")
        for i in range(L, R):
            for j in range(i + 1, R + 1):
                i, j = i % MOD, j % MOD
                ans = min(ans, (i * j) % MOD)
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 1e5 + 10;
ll dp[MAX_N];
ll h[MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i ++) {
        cin >> h[i];
    }
    fill_n(dp, MAX_N, mod * mod);
    dp[0] = 0;
    for(int i = 1; i < n; i ++) {
        for(int q = 1; q <= k; q ++) {
            if(i - q >= 0) {
                chkmin(dp[i], dp[i - q] + abs(h[i] - h[i - q]));
            }
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}




Measured memory_bytes: 1920
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5, oo = 1e9;
int n, a[N], s[N], top, t[N], b[N], ans;
bool valid(int k)
{
    t[0] = 1; for(int i = 1; i <= n+1; ++i) t[i] = min((i64)t[i-1]*k, (i64)oo);
    s[top = 1] = 1, b[top] = 1;
    for(int i = 1+(a[1] == 1); i <= n; ++i)
    {
        if(s[top] < a[i]) s[++top] = a[i], b[top] = 1;
        else if(s[top] == a[i]) ++b[top];
        else
        {
            while(top>1&&s[top-1] > a[i]) b[top-1] += (b[top]-1)/t[min(s[top]-s[top-1], n+1)], --top;
            if(s[top-1] == a[i]) b[top-1] += (b[top]-1)/t[min(s[top]-s[top-1], n+1)]+1, --top; 
            else b[top] = (b[top]-1)/t[min(s[top]-a[i], n+1)]+2, s[top] = a[i];            
        }
    }
    while(top > 1) b[top-1] += (b[top]-1)/t[min(s[top]-s[top-1], n+1)], --top;
    return b[1] <= k;
}
int main()
{
    n = read(); for(int i = 1; i <= n; ++i) a[i] = read();
    for(int l = 1, r = n, x; l <= r; ) valid(x = (l+r)>>1)?(ans = x, r = x-1):(l = x+1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(void){
  int a,b,c,k,max;
  scanf("%d%d%d%d",&a,&b,&c,&k);
  max=a>b?a:b;
  max=max>c?max:c;
  int p=a+b+c-max;
  for(int i=0;k>i;++i)
    max*=2;
  printf("%d",max+p);
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    s,w = MI()
    if w>=s:
        print("unsafe")
    else:
        print("safe")




if __name__ == "__main__":
	main()

Measured memory_bytes: 61728
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[][]=new int[n][2];
        for(int i=0;i<n;i++)
        {
            arr[i][0]=sc.nextInt();
            arr[i][1]=sc.nextInt();
        }
        for(int i=0;i<=n-3;i++)
        {
            boolean yes=true;
            for(int j=i;j<i+3;j++)
            {
                if(arr[j][0]!=arr[j][1])
                {
                    yes=false;
                    break;
                }
            }
            if(yes)
            {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 36028
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = int(input())

@jit
def main(s):
  while True:
    flag = False
    for i in range(2, int(s**(1/2)+1)):
      if s%i == 0:
        flag = True
    if not flag:
      return s
    s += 1
print(main(s))

Measured memory_bytes: 109444
H, N = map(int, input().split())
M = [list(map(int, input().split())) for _ in range(N)]

dp = [float("inf")]*(H+1)

for i in range(1, H+1):
    for atk, mp in M:
        if i - atk > 0:
            dp[i] = min(dp[i], dp[i-atk]+ mp)
        else:
            dp[i] = min(dp[i], mp)

print(dp[H])

Measured memory_bytes: 42588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

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


int main (){
    string s;
    cin >> s;
    if(10*(s[0]-'0')+s[1]-'0' <= 12 && 1 <= 10*(s[0]-'0')+s[1]-'0'){
        if(10*(s[2]-'0')+s[3]-'0' <= 12 && 1 <= 10*(s[2]-'0')+s[3]-'0'){
            cout << "AMBIGUOUS" << "\n";
        }else{
            cout << "MMYY" << "\n";
        }
    }else{
        if(10*(s[2]-'0')+s[3]-'0' <= 12 && 1 <= 10*(s[2]-'0')+s[3]-'0'){
            cout << "YYMM" << "\n";
        }else{
            cout << "NA" << "\n";
        }
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():

    n = [int(x) for x in input().split(' ')]
    a = n[0]
    b = n[1]
    c = n[2]
    k = n[3]

    point = 0
    count = k

    a_ = a
    a_b = a + b
    if k <= a:
        point = k
    elif k >= a and k <= a+b:
        point = a
    else:
        take_c = k - (a + b)
        point = a - take_c

    # 出力
    print(point)

if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define $ vector< int > :: iterator

#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(auto i=0; i<(n); i++)
#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);


int main() {
 Boost;
 pair<ll, ll> a[4];
 ll n,x[4],p=8,ans=0;
 rep(i,4) {
     cin>>x[i];
     a[i].F=x[i]*p;
     a[i].S=i+1;
     p/=2;
 }
 cin>>n;
 sort(a,a+4);
 rep(i,4){
    if(a[i].S==1){
        ans=ans+(n*4)*x[0];
        break;
    }
    else if(a[i].S==2) {ans=ans+(n*2)*x[1];break;}
    else if(a[i].S==3) {ans=ans+n*x[2];break;}
    else {
        ans=ans+(n/2)*x[3];
        n=n%2;
    }
 }

    cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a;scanf("%d",&a);
	int ret=0;
	for(int i=0;i<a;i++){
		int p,q;scanf("%d%d",&p,&q);ret+=q-p+1;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
# Str -> Bool
def solve(s):

    if len(s) < 3:
        return False

    history = []
    t = s
    while t.find("ABC") != -1:
        if t[0:3] == "ABC":
            t = t.replace("ABC", "A")
            history.append("A")
        elif t[-3:] == "ABC":
            t = t.replace("ABC", "C")
            history.append("C")
        else:
            t = t.replace("ABC", "B")
            history.append("B")

    # ??????1???????????§????????????
    if len(t) > 1:
        return False

    # ?§?????????´???????¢????
    for cmd in reversed(history):
        t = t.replace(cmd, "ABC")
    
    return t == s

def main():
    s = input()
    if solve(s):
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 7584
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let k: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let _: String = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = (n - 1) / (k - 1) + if ((n - 1) % (k - 1)) == 0 { 0 } else { 1 };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long  i = 0; i < (long long)(n); i++)






int main() {
	string S, T,U;
	int a, b;
	cin >>S>>T>> a >> b>>U;
	if (U == S) {
		a--;
	}
	else {
		b--;
	}

	cout << a<<" "<<b << endl;
}

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

public class Main {
	// AtCoder Beginner Contest 129
	// https://atcoder.jp/contests/abc129/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int prevT = 0;
		int prevX = 0;
		int prevY = 0;
		
		for (int i = 0; i < n; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			int dist = Math.abs(x - prevX) + Math.abs(y - prevY);
			int timeDiff = t - prevT;
			
			if (dist > timeDiff || (dist % 2 != timeDiff % 2)) {
				System.out.println("No");
				System.exit(0);
			}
			prevT = t;
			prevX = x;
			prevY = y;
		}
		
		System.out.println("Yes");
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 36616
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#define MP make_pair
#define F first
#define S second
using namespace std;
typedef long long ll;

int n;

bool q[220];
bool query () {
	cout << "? ";
	for (int i = 1; i <= 2 * n; i ++)
		if (q[i])
			cout << i << ' ';
	cout << endl;
	string T;
	cin >> T;
	return (T == "Red");
}

bool ans[220];

int main () {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i ++)
		q[i] = true;
	bool ini = query ();
	int l = 1, r = n; 
	while (l != r) {
		int mid = (l + r) >> 1;
		memset(q, 0, sizeof q);
		for (int i = 1; i <= mid; i ++)		q[i] = true;
		for (int i = mid + 1; i <= n; i ++)	q[n + i] = true;
		bool res = query ();
		if (res == ini)	r = mid;
		else			l = mid + 1;
	}
	//res is the place which red is more, but res - 1 is blue is more
	int res = l;
	
	for (int t = 1; t <= 2 * n; t ++) {
		memset(q, 0, sizeof q);
		for (int i = 1; i <= res - 1; i ++)	 q[i] = true;
		for (int i = res + 1; i <= n; i ++)	 q[n + i] = true;
		if (q[t])
			continue ;
		q[t] = true;
		ans[t] = query ();
	}

	for (int t = 1; t <= 2 * n; t ++) {
		memset(q, 0, sizeof q);
		for (int i = 1; i <= res - 1; i ++)	 q[n + i] = true;
		for (int i = res + 1; i <= n; i ++)	 q[i] = true;
		if (q[t])
			continue ;
		q[t] = true;
		ans[t] = query ();
	}

	cout << "! ";
	for (int i = 1; i <= 2 * n; i ++) {
		cout << (ans[i] == 1 ? 'R' : 'B');
	}
	cout << endl;

	return 0;
}

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

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; }
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
queue<int> quex,quey;
const int MOD = 1000000007;




int main(){
    int a[3][3];
    int cnt=0;
    rep(i,3) rep(j,3) cin >> a[i][j];
    int n;  cin >> n;
    int b[n];
    rep(i,n) cin >> b[i];

    rep(i,n) {
        rep(j,3) {
            rep(k,3){
            if(b[i]==a[j][k]) a[j][k]=0;
            }
            }

    }

    rep(i,3)  if(a[i][0]==0 && a[i][1]==0  && a[i][2]==0) cnt++;
    rep(i,3)  if(a[0][i]==0 && a[1][i]==0  && a[2][i]==0) cnt++;
    if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0) cnt++;
    if(a[2][0]==0 && a[1][1]==0 && a[0][2]==0) cnt++;

if(cnt!=0) cout << "Yes" << endl;
else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using pint = pair<int, int>;

int n;
vector<vector<pint>> v;

bool judge(int bit) {
    for (int i = 0; i < n; ++i) {
        if (!((bit >> i) & 1)) continue; // 不親切な人の証言は無視する。

        for (auto xy: v[i]) {
            int x = xy.first;
            int y = xy.second;

            if (y == 1 && !((bit >> x) & 1)) return false;
            if (y == 0 &&  ((bit >> x) & 1)) return false;
        }
    }

    return true;
}


int main() {
    cin >> n;
    v.resize(n);

    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        v[i].resize(a);

        for (int j = 0; j < a; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first;
        }
    }

    int res = 0;
    for (int bit = 0; bit < (1 << n); ++bit) { // 0: 不親切な人 1: 正直者
        if (judge(bit)) { // 矛盾がなかったら、1の数を数える。
            int cnt = 0;
            for (int i = 0; i < n; ++i) if ((bit >> i) & 1) ++cnt;
            res = max(res, cnt);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001
#define MAX_M 100001

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main() {
  ll n, m;
  ll x[MAX_N], y[MAX_M];
  cin >> n >> m;
  for (ll i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (ll i = 0; i < m; i++) {
    cin >> y[i];
  }

  sort(x, x + n);
  sort(y, y + m);

  ll X = 0, Y = 0;
  for (ll i = 1; i < n; i++) {
    X = mod(X + i * (n - i) * (x[i] - x[i-1]));
  }
  for (ll j = 1; j < m; j++) {
    Y = mod(Y + j * (m - j) * (y[j] - y[j-1]));
  }

  cout << mod(X * Y) << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  ll N;
  cin>>N;
  string str;
  cin>>str;
  if(N%2==1){cout<<"No"<<endl;}
  else{
    ll count=0;
    for(ll i=0;i<N/2;i++){
      if(str.at(i)==str.at(i+N/2)){count++;}
    }
    if(count==N/2){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
  }
}


Measured memory_bytes: 256