akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) lower_bound(ALL(c),x)
#define UB(c,x) upper_bound(ALL(c),x)
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

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

using namespace std;

typedef pair<int,int> P;
struct edge {
  int from, to, cost;
  bool operator <(edge e) {
    return cost < e.cost;
  }
  bool operator<( const edge& e ) const {
    return cost < e.cost;
  }
};

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

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


void warshall_floyd(vector< vector<int> >& d)
{
  int N = d.size();
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}


signed main()
{
  int N; cin >> N;
  vector< vector<int> > A(N, vector<int>(N));
  rep(i, 0, N) {
    rep(j, 0, N) {
      cin >> A[i][j];
    }
  }

  vector< vector<int> > B(N, vector<int>(N));
  rep(i, 0, N) {
    rep(j, 0, N) {
      B[i][j] = A[i][j];
    }
  }

  warshall_floyd(B);
  rep(i, 0, N) {
    rep(j, 0, N) {
      if (A[i][j] > B[i][j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  int ans = 0;
  rep(i, 0, N) {
    rep(j, i+1, N) {
      bool use = true;
      rep(k, 0, N) {
        if (k == i || k == j) {
          continue;
        }
        if (B[i][j] == B[i][k] + B[k][j]) {
          use = false;
        }
      }
      if (use) {
        ans += B[i][j];
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1664
from collections import deque
import sys
sys.setrecursionlimit(10**9)


N = int(input())
to = [[] for _ in range(N)]
order = []

for _ in range(N - 1):
    a, b = list(map(lambda x:int(x) - 1, input().split()))
    to[a].append(b)
    to[b].append(a)
    order.append(b)


def solve():
    dist = [-1] * N
    # 頂点iに向かう辺をiとする
    color = [0] * N
    dist[0] = 0
    color[0] = 0
    que = deque([0])

    while que:
        v = que.popleft()
        used_color = [color[v]]
        next_color = 1
        for nv in to[v]:
            if dist[nv] == -1:
                dist[nv] = dist[v] + 1
                while next_color in used_color:
                    next_color += 1
                color[nv] = next_color
                used_color.append(next_color)
                que.append(nv)

    print(len(set(color[1:])))
    for i in range(N - 1):
        print(color[order[i]])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 98092
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n, a) for(int i = a; i < n; ++i)

int main(void) {
  int n, i, j, ans = 0;
  scanf("%d", &n);
  int a[n];
  rep(i, n) scanf("%d", &a[i]);
  int flag = 1;
  rep(i, n) {
    int minj = i, t;
    repi(j, n, i) if(a[j] < a[minj]) minj = j;
    t = a[i], a[i] = a[minj], a[minj] = t;
    if(i != minj) ++ans;
  }
  rep(i, n) {
    if(i) printf(" %d", a[i]);
    else printf("%d", a[i]);
  }
  printf("\n%d\n", ans);
  return 0;
}


Measured memory_bytes: 2708
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vvi a(3, vi(n + 1));
	erep(i, 1, 2) erep(j, 1, n) cin >> a[i][j];
	vvi dp(3, vi(n + 1, 0));
	erep(i, 1, 2) erep(j, 1, n) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i][j - 1]);
	cout << dp[2][n] << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
#define error(args...) { vector<string> _debug = split(#args, ',');err(begin(_debug), args);}

vector<string> split(const string& s, char c){
	vector<string> v;stringstream ss(s);string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a,Args... args){
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ",err(++it, args...);
}



const ll inf = 1LL << 60;
const int limit = 50;
int n,a[limit],b[limit];

bool reach[limit + 1][limit + 1];
ll dp[limit + 1][limit + 1];

bool check(int s){
	rep(i,limit+1)rep(j,limit+1) dp[i][j] = (reach[i][j]?0:inf);

	rrep(k,s+1,1){
		rrep(i,limit+1){
			rrep(j,limit+1){
				if(dp[i][j] == inf) continue;
				chmin(dp[i][j % k], dp[i][j] + (1LL<< k));
			}
		}
	}

	rep(i,n) if((dp[a[i]][b[i]] >> s) &1) return true;
	return false;
}

int main(void){
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];

	ll ans = 0LL;

	rep(i,limit+1) reach[i][i] = true;

	rrep(k,limit + 1, 1){
		if(check(k)){
			//cerr << k << endl;
			ans |= (1LL << k);
			rrep(i,limit+1)rrep(j,limit+1){
				if(reach[i][j] == false) continue;
				reach[i][j % k] = true; 
			}
		}
	}

	bool ok = true;
	rep(i,n) if(dp[a[i]][b[i]] == inf) ok = false;

	if(ok)
		cout << ans << endl;
	else
		cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    n%=10;
    if(n==3){
    	cout<<"bon";
	}
	else if(n==0||n==1||n==6||n==8) cout<<"pon";
	else cout<<"hon";
    return 0;
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    if(1<=n && n<=104)
      System.out.println(0);
    else if(105<=n && n<=134)
      System.out.println(1);
    else if(135<=n && n<=164)
      System.out.println(2);
    else if(165<=n && n<=188)
      System.out.println(3);
    else if(189<=n && n<=194)
      System.out.println(4);
    else if(195<=n && n<=200)
      System.out.println(5);
  }
}

Measured memory_bytes: 21332
use std::error::Error;
use std::io::{self, BufReader};
use std::io::prelude::*;
use std::str::{self, FromStr};

fn exec() {
    let mut sc = Scanner::new(io::stdin());
    let n: usize = sc.ne();
    let mut g = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let (u, v, c): (usize, usize, i64) = (sc.ne(), sc.ne(), sc.ne());
        let (u, v) = (u - 1, v - 1);
        g[u].push((v, c));
        g[v].push((u, c));
    }
    let (q, k): (usize, usize) = (sc.ne(), sc.ne());
    let k = k - 1;
    let inf = 1e18 as i64;
    let mut dist = vec![inf as i64; n];
    let mut que = std::collections::BinaryHeap::new();
    que.push((0, k));
    dist[k] = 0;
    while let Some((d, cur)) = que.pop() {
        if dist[cur] < d {
            continue;
        }
        for &e in &g[cur] {
            if dist[e.0] > dist[cur] + e.1 {
                dist[e.0] = dist[cur] + e.1;
                que.push((dist[e.0], e.0));
            }
        }
    }
    for _ in 0..q {
        let (x, y): (usize, usize) = (sc.ne(), sc.ne());
        println!("{}", dist[x - 1] + dist[y - 1]);
    }
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
pub struct Scanner<R> {
    bufread: BufReader<R>,
    id: usize,
    buf: Vec<u8>,
}
impl<R: Read> Scanner<R> {
    pub fn new(resource: R) -> Scanner<R> {
        Scanner {
            bufread: BufReader::new(resource),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.bufread.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    pub fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.is_empty() {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert_ne!(self.buf[l], b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!(
                    "parse error, {:?}",
                    String::from_utf8(self.buf[l..r].to_owned())
                )
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    pub fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


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

int main(){
 int n;
 cin >> n;
 for(int i=1;i<=n;++i){
  if(i%3==0) cout << " " << i;
  else{
   int x=i;
   while(x){
    if(x%10==3){
     cout << " " << i;
     break;
    }
   x/=10; 
   }
  }
 }
 cout << endl;
 return 0;
}

Measured memory_bytes: 3088
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N,M;
bool g[15][15]={0};
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",min(a+b,min(b+c,c+a)));

}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

M, D = map(int, input().split())

ans = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        d1 = d // 10
        d2 = d % 10
        if m == d1 * d2 and d1 >= 2 and d2 >= 2:
            ans += 1

print(ans)



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

int main(){
    long long n,k; 
    long long d[1000],pro[1000]={0},tot=1,a[1000]={0};
     int p,i,j;
     cin >> n >> k;
     long long ans=n;
     for(i=1;i<=k;i++){
      cin >> d[i];
      pro[d[i]]=1;
     } 
     for(i=0;i<=10;i++){
         if(pro[i]==0){
            p=i;
            break;
        } 
    }
    while(n){
       a[tot++]=n%10;
       n/=10;
     }
    for(i=tot-1; i>=1; i--){
       if(pro[a[i]]==1){
          while(pro[a[i]]==1){
            a[i]=a[i]+1;
            if(a[i]==10){
              a[i]=p;
              i = i+1;
              a[i]=a[i]+1;
            }
          if(i==tot){
             a[i]=1;
          while(pro[a[i]]==1){
             a[i]+=1;
           }
       cout << a[tot];
       for(j=tot-1; j>=1; j--)
          cout << p;
          cout << "\n";
          return 0;
     }
   }
      k=i;
      for(j=tot-1; j>=1; j--){
         if(j>=k)
           cout << a[i];
         else
           cout << p;
         if(j==1)
           return 0;
       }
     } 
   } 
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define N 100010
#define W 1000000
using namespace std;
struct NODE{
	int p, y;
	int id;
}A[N];
inline bool cmp(NODE x, NODE y){
	if(x.p ^ y.p)
		return x.p < y.p;
	else return x.y < y.y;
}
int ans[N];
int d[N];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++ i){
		scanf("%d%d", &A[i].p, &A[i].y);
		d[i] = A[i].p;
		A[i].id = i;
	}
	sort(A + 1, A + m + 1, cmp);
	int tmp = 0;
	for(int i = 1; i <= m; ++ i){
		if(A[i].p != A[i - 1].p)
			tmp = i - 1;
		ans[A[i].id] = i - tmp;
	}
	for(int i = 1; i <= m; ++ i)
		printf("%06d%06d\n", d[i], ans[i]);
	return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
#include<string.h>
int main(){
  int no,n,i,j,k,l,sw2,sw3,sw4,sw5,sw6,sa,set[20]={24,21,18,15,12,9,6,3,2,1,-1,-2,-3,-6,-9,-12,-15,-18,-21,-24};
  int sw[20];


  char a[1002],b[52],c[52];
  char A[]="yotta";
  char B[]="zetta";
  char C[]="exa";
  char D[]="peta";
  char E[]="tera";
  char F[]="giga";
  char G[]="mega";
  char H[]="kilo";
  char I[]="hecto";
  char J[]="deca";
  char K[]="deci";
  char L[]="centi";
  char M[]="milli";
  char N[]="micro";
  char O[]="nano";
  char P[]="pico";
  char Q[]="femto";
  char R[]="ato";
  char S[]="zepto";
  char T[]="yocto";


  //start
  scanf("%d",&n);
  for(i=0;i<n;i++){
    //syoki
    for(j=0;j<20;j++)sw[j]=0;
    sw2=0;
    sw3=0;
    sw4=0;
    sw5=0;
    sw6=0;
    //
    scanf("%s",a);
    scanf("%s",b);
    //hantei
    if(strcmp(A,b)==0)sw[0]=1;
    if(strcmp(B,b)==0)sw[1]=1;
    if(strcmp(C,b)==0)sw[2]=1;
    if(strcmp(D,b)==0)sw[3]=1;
    if(strcmp(E,b)==0)sw[4]=1;
    if(strcmp(F,b)==0)sw[5]=1;
    if(strcmp(G,b)==0)sw[6]=1;
    if(strcmp(H,b)==0)sw[7]=1;
    if(strcmp(I,b)==0)sw[8]=1;
    if(strcmp(J,b)==0)sw[9]=1;
    if(strcmp(K,b)==0)sw[10]=1;
    if(strcmp(L,b)==0)sw[11]=1;
    if(strcmp(M,b)==0)sw[12]=1;
    if(strcmp(N,b)==0)sw[13]=1;
    if(strcmp(O,b)==0)sw[14]=1;
    if(strcmp(P,b)==0)sw[15]=1;
    if(strcmp(Q,b)==0)sw[16]=1;
    if(strcmp(R,b)==0)sw[17]=1;
    if(strcmp(S,b)==0)sw[18]=1;
    if(strcmp(T,b)==0)sw[19]=1;
    //hantei
    for(j=0;j<20;j++){
      if(sw[j]==1)sw2=1;
    }
    if(sw2==1)scanf("%s",c);
    //in end

    for(j=0;a[j]!='\0';j++){
      if(a[j]>='1'&&a[j]<='9'){//1<a
	for(k=j+1;a[k]!='\0';k++){
	  if(a[k]=='.'){
	    sw3=1;
	    sa=k-j-1;
	    break;
	  }
	}
	if(sw3==0){
	  sa=k-j-1;
	}
	break;
      }
      if(a[j]=='.'){//1>a
	sw5=1;
	for(k=j+1;a[k]!='\0';k++){
	  if(a[k]>='1'&&a[k]<='9'){
	    sa=k-j-1;
	    sa*=-1;
	    sa--;
	    if(a[k+1]=='\0')sw4=1;
	    break;
	  }
	}
	break;
      }
    }
    //a end

    //out
    if(sw5==0){
      printf("%c.",a[0]);//atama
      for(k=1;a[k]!='\0';k++){
	if(a[k]!='.'){
	printf("%c",a[k]);
	}
      }
    }
    else{
      printf("%c",a[k]);
      if(sw4==0){
	printf(".");
	for(l=k+1;a[l]!='\0';l++){
	  if(a[l]!='.'){
	  printf("%c",a[l]);
	  }
	}
      }
    }
    printf(" * 10^");
    for(j=0;j<20;j++){
      if(sw[j]==1){
	sw6=1;
	printf("%d",set[j]+sa);
	break; 
      }
    }
    if(sw6==0){
	printf("%d",0+sa);
    }

    if(sw2==1){
      printf(" ");
      for(j=0;c[j]!='\0';j++){
	printf("%c",c[j]);
      }
    }
    else{
      printf(" ");
      for(j=0;b[j]!='\0';j++){
	printf("%c",b[j]);
      }
    }
	printf("\n");
  } 
    
  return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


// Binary Indexed Tree (Fenwick Tree)
template<typename T> // T: type of cost
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
};

mint f(int a, int b, int c, int d) {
  mint res = 0;
  vector<int> num = {a,b,c,d};
  vector<mint> o(4), ox(4);
  rep(i,4) {
    ox[i] = mint(2).pow(num[i]);
    o[i] = ox[i] - 1;
  }
  res += ox[0]*o[1]*o[2]*ox[3];
  res += o[0]*ox[1]*ox[2]*o[3];
  res -= o[0]*o[1]*o[2]*o[3];

  res += ox[0]*ox[1]*ox[2]*ox[3];
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  { // compress x
    map<int,int> mp;
    rep(i,n) mp[p[i].first] = 0;
    int j = 0;
    for (auto&& x : mp) x.second = j++;
    rep(i,n) p[i].first = mp[p[i].first];
  }
  { // compress y
    map<int,int> mp;
    rep(i,n) mp[p[i].second] = 0;
    int j = 0;
    for (auto&& x : mp) x.second = j++;
    rep(i,n) p[i].second = mp[p[i].second];
  }
  sort(p.begin(), p.end());
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  vector<int> d(n);
  rep(_,2) {
    { // calc a,b
      BIT<int> bit(n);
      rep(i,n) {
        a[i] = bit.sum(p[i].second);
        b[i] = i - a[i];
        bit.add(p[i].second);
      }
    }
    reverse(p.begin(),p.end());
    swap(a,c);
    swap(b,d);
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    reverse(c.begin(),c.end());
    reverse(d.begin(),d.end());
  }
  mint ans = 0;
  rep(i,n) {
    ans += f(a[i],b[i],c[i],d[i]);
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/	
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll power( ll a, ll n, ll m= 1000000007){
  ll ans = 1;
  while(n){
  if(n&1)
  {
  ans *= a;
  ans%=m;
  }
  a*=a;
  a%=m;
  n/=2;
  }
  return ans ;
} 


vector< int > prm ;
vector < bool > vsp ;

void prime ( int nn = 100000 ) {
	vsp = vector < bool > ( nn+1, 0 );
	int size_prime = nn;
	for( ll i =2; i*i < size_prime ; i++){
		
		if( vsp[i] == 1)
		continue;
		for(ll j = i*i; j < size_prime ;j+=i){
			
			vsp[j] =1;
			
		}
		
		
	}
	
	for( int i= 2; i < size_prime ; i++)
	if (vsp[i] == 0)
	prm.pb(i);
	
	
}


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


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...
// never forget  to recheck your predefined function in template .. 
// already defined ::  prime , power , gcd : ( ll ).. 








int Main(){
  
  
  
  int n;
  cin>>n;
  int cnt=  0 , ans  =0 ;
   for ( int i =0 ; i <n;i++){
	   int a, b;
	   cin>>a>>b;
	   if(a!= b)
	   cnt =0;
	   else{
		   cnt++;
		   }
	  if( cnt == 3)
	  {
		 ans++;
	  } 
   }
  
  
  if(ans>0 ){
	  cout<<"Yes\n";
	  
  }
  else
  cout<<"No\n";	
  
return 0;

}






int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;
}


  




Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

using ld = long double;
int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    const ld PI = 3.14159265359;
    cout << fixed << setprecision(10);
    lint a, b, x; cin >> a >> b >> x;
    lint total_vol = a * a * b;
    if (2 * x >= total_vol) {
        ld c = (ld)2 * x / (a * a) - b;
        ld y = b - c;
        cout << (ld)90 - atan2(a, y) * 180 / PI << "\n";
    } else {
        ld y = (ld)2 * x / (a * b);
        cout << atan2(b, y) * 180 / PI << "\n";
    }
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long pow(long x, long k) {
    if (k == 0) return 1;
    if (k % 2 == 0) return pow(x * x, k / 2);
    return x * pow(x, k - 1);
}

double calc(int n, int k) {
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i >= k) {
            ans += 1.0 / n;
        }
        else {

            long lo = 0;
            long hi = 20;
            long best = hi;
            while (lo <= hi) {
                long m = (lo + hi) / 2;
                if (i * pow(2, m) >= k) {
                    hi = m - 1;
                    best = min(best, m);
                }
                else {
                    lo = m + 1;
                }
            }
            assert(best != hi);

            ans += (1.0 / n) * (1.0 / pow(2, best));
        }
    }
    return ans;
}

void main() {
    auto nk = readints;
    int n = nk[0], k = nk[1];
    writefln("%.9f", calc(n, k));
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i * 100 <= n; ++i) {
    if (n - i * 100 <= i * 5) {
      puts("1");
      return 0;
    }
  }
  puts("0");
}


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

int main()
{
    int k, x;
    cin >> k >> x;

    if (500 * k >= x)
        puts("Yes");
    else
        puts("No");
}

Measured memory_bytes: 3560
#include <stdio.h>
int main()
{
  char n[7];
  int i = 0;
  while (i < 7)
  {
  	scanf("%c",&n[i]);
    i++;
  }
  if (n[0] == n[6] && n[1] == n[5] && n[2] == n[4])
    printf("YES");
  else
    printf("NO");
}

Measured memory_bytes: 128
# ABC083B - Some Sums
def main():
    n, a, b = list(map(int, input().rstrip().split()))
    ans = 0
    for i in range(1, n + 1):
        if a <= sum(map(int, list(str(i)))) <= b:
            ans += i
    print(ans)


if __name__ == "__main__":
    main()

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

const int inf = 1e9;

int n;
vector<int> t, v;

//i is parameter(0-n+1)
int fni(int i, int tm) {
  int ret;
  if (i == 0)
    ret = tm;
  else if (i == n + 1)
    ret = t[n] - tm;
  else if (tm < t[i - 1])
    ret = -(tm - t[i - 1]) + v[i];
  else if (tm > t[i])
    ret = (tm - t[i]) + v[i];
  else
    ret = v[i];
  return ret;
}

int fn(int tm) {
  int ret = fni(0, tm);
  for (int i = 1; i <= n + 1; i++) {
    ret = min(ret, fni(i, tm));
  }
  return ret;
}

int main() {
  cin >> n;
  t.resize(n + 1, 0);
  v.resize(n + 1, 0);

  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    t[i] *= 2;
  }
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    v[i] *= 2;
  }


  for (int i = 0; i < n; i++) t[i + 1] += t[i];


  double ans = 0;
  for (int i = 0; i < t[n]; i ++) {
    ans += (fn(i) + fn(i + 1));

  }
    cout << fixed << setprecision(10) << ans / 8.0 << endl;

}

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

int main() {
    cin >> s;
    cin >> k;
    ll ans = 0;
    if (k == 1) {
        int kk = (s[0] - '0');
        ans = kk;
        ll n = s.size() - 1;
        ans += 9LL * n;
        cout << ans << endl;
        return 0;
    }    

    if (s.size() < 2) {
        cout << 0 << endl;
        return 0;
    }

    if (k == 2) {
        ll l = (s[0] - '0');
        ans += (l - 1) * 9LL * (ll)(s.size() - 1);

        ll sz = s.size();
        if (s.size() > 2) {
            ans += (sz - 1) * (sz - 2) / 2 * 9 * 9;
        }

        int posb = 1;
        while (posb < sz && s[posb] == '0') posb++;
        if (posb == sz) {
            cout << ans << endl;
            return 0;
        }
        l = (s[posb] - '0');
        ans += l;
        ans += (sz - posb - 1) * 9LL;

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

    if (s.size() < 3) {
        cout << 0 << endl;
        return 0;
    }

    ll a = (s[0] - '0');
    ll sz = s.size();
    ans += (a - 1) * (sz - 1) * (sz - 2) * 9 * 9 / 2;

    if (sz > 3) {
        ans += (sz - 1) * (sz - 2) * (sz - 3) / 6 * 9 * 9 * 9;
    }

    int posb = 1;
    while (posb < sz - 1 && s[posb] == '0') posb++;
    if (posb == sz - 1) {
        cout << ans << endl;
        return 0;
    }

    ll b = (s[posb] - '0');
    ans += (b - 1) * (sz - posb - 1) * 9;

    if (sz - posb - 1 >= 2) {
        ans += (sz - posb - 1) * (sz - posb - 2) / 2 * 9 * 9;
    }

    int posc = posb + 1;
    while (posc < sz && s[posc] == '0') posc++;
    if (posc == sz) {
        cout << ans << endl;
        return 0;
    }

    ll c = (s[posc] - '0');
    ans += c;
    ans += (sz - posc - 1) * 9;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def resolve():
    A, B, K = list(map(int, input().split()))
    if B - A + 1 >= 2 * K:
        ls = [i for i in range(A, A+K)] + [i for i in range(B-K+1, B+1)]
    else:
        ls = [i for i in range(A, B+1)]

    print('\n'.join(map(str, ls)))
    return

resolve()

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


#define INF 1000000000000


signed main()
 {
   int n;
   cin>>n;
   int a[12]={1,6,36,216,1296,7776,46656,9,81,729,6561,59049};
   int dp[100001];
   rep(i,100001){
     dp[i]=INF;
   }
   dp[0]=0;
   rep(i,100001){
     rep(j,12){
       if(i-a[j]>=0){
   dp[i]=min(dp[i-a[j]]+1,dp[i]);
 }
}
}
cout<<dp[n];
 }


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#define id(i,j) (i-1)*m+j
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,m,first[30010],dep[30010],cur[30010],cnte=-1,tot;
struct edge{
	int to,next,w;
}a[200010];
inline void add(int u,int v,int w){
//	cout<<"add "<<u<<' '<<v<<' '<<w<<'\n';
	a[++cnte]=(edge){v,first[u],w};first[u]=cnte;
	a[++cnte]=(edge){u,first[v],0};first[v]=cnte;
}
bool bfs(int s,int t){
//	cout<<"bfs "<<s<<' '<<t<<'\n';
	int i,q[30010],head=0,tail=1,u,v;
	for(i=1;i<=tot;i++) dep[i]=-1,cur[i]=first[i];
	q[0]=s;dep[s]=0;
	while(head<tail){
		u=q[head++];
//			cout<<"start "<<u<<'\n';
		for(i=first[u];~i;i=a[i].next){
			v=a[i].to;if(~dep[v]||!a[i].w) continue;
//			cout<<"		from "<<u<<" to "<<v<<' '<<a[i].w<<'\n';
			dep[v]=dep[u]+1;q[tail++]=v;
		}
	}
	return ~dep[t];
}
int dfs(int u,int t,int lim){
	if(u==t||!lim) return lim;
	int i,v,f,flow=0;
	for(i=cur[u];~i;i=a[i].next){
		v=a[i].to;cur[u]=i;
		if(dep[v]==dep[u]+1&&(f=dfs(v,t,min(lim,a[i].w)))){
			flow+=f;lim-=f;
			a[i].w-=f;a[i^1].w+=f;
			if(!lim) return flow;
		}
	}
	return flow;
}
void dinic(int s,int t){
	int ans=0;
	while(bfs(s,t)) ans+=dfs(s,t,1e9);
	if(ans<=n*m) printf("%d\n",ans);
	else puts("-1");
}
int x[110][110],S,T;
int main(){
	memset(first,-1,sizeof(first));
	n=read();m=read();char s[110];int i,j;
	for(i=1;i<=n;i++){
		scanf("%s",s);
		for(j=0;j<m;j++){
			if(s[j]=='.') continue;
			x[i][j+1]=1;
			if(s[j]=='S') S=id(i,j+1); 
			if(s[j]=='T') T=id(i,j+1);
		}
	}
	tot=n*m*2;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(!x[i][j]) continue;
			add(n*m+id(i,j),tot+i,1e9);
			add(n*m+id(i,j),tot+n+j,1e9);
			add(tot+i,id(i,j),1e9);
			add(tot+n+j,id(i,j),1e9);
			if(id(i,j)!=S&&id(i,j)!=T) add(id(i,j),n*m+id(i,j),1);
		}
	}
	tot=n*m*2+n+m;
	dinic(n*m+S,T);
}


Measured memory_bytes: 1792
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

struct bangumi_t{
	int s;
	int t;
	int c;
};


int compare_channel(const void *a, const void *b) {//降順と昇順あってる？？
	struct bangumi_t *A = (struct bangumi_t *)a;
	struct bangumi_t *B = (struct bangumi_t *)b;
	if(A->c - B->c >0){
		return 1;
	}else if(A->c - B->c <0){
		return -1;
	}else{
		if(A->s - B->s >0){
			return 1;
		}else if(A->s - B->s <0){
			return -1;
		}else{
			return 0;
		}
	}
}

int compare_time(const void *a, const void *b) {//降順と昇順あってる？？
	struct bangumi_t *A = (struct bangumi_t *)a;
	struct bangumi_t *B = (struct bangumi_t *)b;
	if(A->s - B->s >0){
		return 1;
	}else if(A->s - B->s <0){
		return -1;
	}else{
		if(A->t - B->t >0){
			return 1;
		}else if(A->t - B->t <0){
			return -1;
		}else{
			return 0;
		}
	}
}

int main(void)
{
	//変数の宣言
	int n,m;
	static struct bangumi_t bangumi[100010];
	auto c = [](bangumi_t l, bangumi_t r){
		if(l.t - r.t >0){
			return true;
		}else{
          	return false;
		}
	};
	static priority_queue<bangumi_t,vector<bangumi_t>,decltype(c)> pque(c);
	struct bangumi_t b;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	char stemp[11];
	
	//データの読み込み


	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);

//	scanf("%s",&s);
//	scanf_s("%s",&s,5);


	for(i=0;i<n;i++){
		scanf("%d %d %d",&temp1,&temp2,&temp3);
//		scanf_s("%d %d %d",&temp1,&temp2,&temp3);

		bangumi[i].s=temp1;
		bangumi[i].t=temp2;
		bangumi[i].c=temp3;
	}


/*	for(i=0;i<n;i++){
//		scanf("%d",&c[i]);
		scanf_s("%d",&c[i]);
		d[i]=0;
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();

	qsort(bangumi,n,sizeof(struct bangumi_t),compare_channel);
	
	count=0;
	for(i=0;i<n;i++){
		temp=i;
		while(temp!=n-1&&bangumi[temp].c==bangumi[temp+1].c&&bangumi[temp].t==bangumi[temp+1].s){
			temp++;
		}
		bangumi[count].s=bangumi[i].s;
		bangumi[count].t=bangumi[temp].t;
		bangumi[count].c=bangumi[i].c;
		count++;
		i=temp;
	}

	n=count;
	
	qsort(bangumi,n,sizeof(struct bangumi_t),compare_time);

	for(i=0;i<n;i++){
		if(i==0){
			pque.push(bangumi[i]);
		}else{
			b=pque.top();
			if(b.t<bangumi[i].s){
				pque.pop();
				pque.push(bangumi[i]);
			}else{
				pque.push(bangumi[i]);
			}
		}
	}

//	clock_t end=clock();


	//	printf("計算部分終了\n");

	//出力

	temp1=pque.size();
	printf("%d",temp1);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
int main(){
 long long  n;
  cin>>n;
  long long sum=0;
  double m=sqrt(n);
  long long ans=ceil(m);
  for(long long i=1;i<m;i++)
  { long long r=(n-1)/i-(i-1);
   sum+=r;
     }
  cout<<sum*2-ans+1;
  return 0;}

Measured memory_bytes: 3748
# coding: utf-8

import heapq


def calc_l_score(N, a):
    scores = [None] * (N + 1)
    queue = a[:N]
    heapq.heapify(queue)
    scores[0] = sum(queue)
    for i in range(N):
        na = a[N + i]
        heapq.heappush(queue, na)
        m = heapq.heappop(queue)
        scores[i + 1] = scores[i] + na - m
    return scores


def calc_r_score(N, a):
    scores = [None] * (N + 1)
    queue = []
    for i in range(1, N + 1):
        heapq.heappush(queue, -a[-i])
    scores[-1] = - sum(queue)
    for i in range(1, N + 1):
        na = a[-N - i]
        heapq.heappush(queue, -na)
        m = - heapq.heappop(queue)
        scores[-i - 1] = scores[-i] + na - m
    return scores


def main():
    N = int(input())
    a = list(map(int, input().split()))

    ls = calc_l_score(N, a)
    rs = calc_r_score(N, a)
    return max([l - r for l, r in zip(ls, rs)])


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 37212
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e17;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int w[1010], s[1010];
ll v[1010];

ll dp[20010];

ll solve() {
    vector<P> vec(n);
    for (int i = 0; i < n; i++) vec[i] = make_pair(w[i]+s[i], i);
    sort(ALL(vec));

    for (int i = 1; i < 20010; i++) {
        dp[i] = -inf;
    }

    for (P p : vec) {
        int i = p.second;
        for (int j = s[i]; j >= 0; j--) {
            if (dp[j] < 0) continue;
            dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
        }
    }

    ll res = 0;
    for (int i = 1; i < 20010; i++) {
        res = max(res, dp[i]);
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> w[i] >> s[i] >> v[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3724
import collections

N,K,Q = [int(x) for x in input().split()]

all_result = []
for a_i in range(Q):
    all_result.append(int(input()))

c = collections.Counter(all_result)

for num in range(N):
    point = c[num + 1]
    if (K - Q + point) > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 11900
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
const LL MAX_VAL=1000000000000000000LL;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<LL> A(N);
	int i;
	LL S=0;
	for (i=0;i<N;i++){
		cin>>A[i];
		S+=A[i];
	}
	LL x=0;
	LL y=0;
	LL minY_x=MAX_VAL;
	for (i=0;i<N-1;i++){
		x+=A[i];
		y=S-x;
		LL y_x=y-x;
		if (y_x<0){
			y_x=-y_x;
		}
		if (minY_x>y_x){
			minY_x=y_x;
		}
	}

	cout<<minY_x<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

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

  int res = 9 * (N.size() - 1);
  int ps = 0;
  for (int i = 0; i < (int)N.size(); ++i) {
    if (N[i] != '0') {
      chmax(res, ps + (N[i] - '0' - 1) + 9 * (int)(N.size() - i - 1));
    }
    ps += N[i] - '0';
  }
  chmax(res, ps);

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        // 解
        string ans = string.Empty;

        // 入力
        string inp = Console.ReadLine();

        DateTime dt = DateTime.ParseExact(inp, "yyyy/MM/dd", null);

        if (dt <= new DateTime(2019, 4, 30))
        {
            ans = "Heisei";
        }
        else
        {
            ans = "TBD";
        }

        //出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11232
#include<bits/stdc++.h>
#include<cmath>
#include<string>
#include<sstream>
#include<iostream>
using namespace std;
int main()
{
	char S[4];
	cin>>S;
	int count=0;
	if(S[0]==S[1])
	{count++;}
	if(S[0]==S[2])
	{count++;}
	if(S[0]==S[3])
	{count++;}
	if(S[1]==S[2])
	{count++;}
	if(S[1]==S[3])
	{count++;}
	if(S[2]==S[3])
	{count++;}
	if(count==2)
	{
		cout<<"Yes";
	}
	if(count!=2)
	{
		cout<<"No";
	}
return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		//		String line = reader.readLine();
		//		String[] str = reader.readLine().split(" ");
		//		int[] ab = new int[str.length];
		//		for (int i = 0; i < str.length; i++) {
		//			ab[i] = Integer.parseInt(str[i]);
		//		}

		int min = 100;
		int sum = 0;
		int[] abc = new int[5];
		for (int i = 0; i < 5; i++) {
			String line = reader.readLine();
			abc[i] = Integer.parseInt(line);
			if (abc[i] %10 == 0) {
				sum += abc[i] / 10 * 10;
			}
			else {
				sum += (abc[i] / 10 + 1) * 10;
				if (abc[i] % 10 < min) {
					min = abc[i] % 10;
				}
			}
		}
		if (min == 100) {
			min = 10;
		}
		sum -= (10-min);
		System.out.println(sum);
	}
}

Measured memory_bytes: 22996
#include <stdio.h>

int main(void)
{
     int n;

     double y, v, t, u;
     
     while(0<1){
	  if(scanf("%lf", &v)==-1) break;
	  
	  t = v / 9.8;
	  y = 4.9 * t * t;
	  
	  u = (y + 5) / 5;
	  
	  if(u-(int)u>0) n = (int)u + 1;
	  else n = (int)u;
	  
	  printf("%d\n", n);
     }

     return 0;
}

Measured memory_bytes: 628
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[]) {
	int n;
	char str[101];
	scanf("%d", &n);
	scanf("%s", str);

	int res = 0;

	int i, j, k;

	int count[100] = {};


	for (i = 0; i < n-1; i++) {
		for (j = 0; j <= i; j++) {
			for (k = 0; k < j; k++) {
				if (str[j] == str[k]) {
					goto skip;
				}
			}

			for (k = i+1; k < n; k++) {
				if (str[j] == str[k]) {
					count[i]++;
					break;
				}
			}

		skip:
			continue;
		}
	}

	for (i = 0; i < n-1; i++) {
		// printf("%d\n", count[i]);
		res = res > count[i] ? res : count[i];
	}

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

	return 0;
}


Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 9)


def rec(x, n):
    # print(pos)
    if pos[x] is None:
        pos[x] = n
    else:
        if pos[x] == n:
            return True
        else:
            # print(pos[x], n)
            return False

    for nx, d in g[x]:
        if not rec(nx, n + d):
            return False
    else:
        return True

INF = 1 << 30

N, M = map(int, input().split())
g = [[] for _ in range(N)]
for _ in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    g[L].append((R, D))
    g[R].append((L, -D))

pos = [None for _ in range(N)]

for v in range(N):
    # print(pos)
    if pos[v] is None:
        if not rec(v, 0):
            print('No')
            break
else:
    print('Yes')


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

#define int long long
#define INF (int)0x3f3f3f3f*(int)0x3f3f3f3f
#define MAXN 1000005

int n,m;
int ans = INF;
int a[MAXN],f[MAXN];

bool qaq(int x) {
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		int t = x/f[i];
	//	cout<<x<<" "<<i<<" "<<t<<"\n";
		ans += max((int)0,a[n-i+1]-t);
	}
	return (ans <= m);
}

signed main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i = 1; i <= n; i ++)
		scanf("%lld",&f[i]);
	sort(f+1,f+n+1);
	int l = 0,r = (int)100000000*(int)1000000000;
	while(l+3 < r)
	{
		int mid = (l+r)>>1;
		if(qaq(mid)) r = mid;
		else l = mid;
	}
	for(int i = l; i <= r; i ++)
	if(qaq(i)) {
		cout<<i;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 5888
N = int(input())
s_list = [input() for _ in range(N)]
M = int(input())
t_list = [input() for _ in range(M)]

rev_list = []
for i in range(len(s_list)):
    a = s_list.count(s_list[i])
    b = t_list.count(s_list[i])
    if a >= b:
        ans_num = a-b
    else:
        ans_num = 0
    rev_list.append(ans_num)
    
print(max(rev_list))

Measured memory_bytes: 9144
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<String, Integer> map = new HashMap<>();
		String[] ans = new String[]{"AC", "WA", "TLE", "RE"};
		for (String s : ans) {
		    map.put(s, 0);
		}
		for (int i = 0; i < n; i++) {
		    String s = sc.next();
		    map.put(s, map.get(s) + 1);
		}
		StringBuilder sb = new StringBuilder();
		for (String s : ans) {
		    sb.append(s).append(" x ").append(map.get(s)).append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 56376
#include <bits/stdc++.h>
using namespace std;
vector <int> po;
int a,n,sum;
int main(){

    cin >> n;
    for(int i=0;i<2*n;i++){
        cin >> a;
        po.push_back(a);
    }
    std::sort(po.begin(),po.end());
    for(int i=0;i<2*n;i+=2){
        sum+=min(po[i],po[i+1]);
    }
    cout << sum << endl;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char s[11];

int main()
{	 
	int ans = 0, i;
	
	scanf("%s", s);
	for(i = 0; s[i]; i++) ans += s[i] - 48;
	if(ans == 1) ans = 10;
	printf("%d\n", ans);
		
	return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
main(){
int N;
  cin>>N;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin>>H.at(i);
  }
  int pre =-999;
  for(int i=0;i<N;i++){
    if(pre<=H[i]-1){
      pre=H[i]-1;
    }
    else if(pre<=H[i]){
      pre=H[i];
    }
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}
        

      



Measured memory_bytes: 640