akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br =
				new BufferedReader( new InputStreamReader(System.in) );

		Scanner sc = new Scanner(System.in);

//		int n = Integer.parseInt(br.readLine());
		int n = sc.nextInt();

//		String[] A = br.readLine().split(" ");
		int[] A = new int[n];
		for (int i=0; i < n; i++) {
			A[i] = sc.nextInt();
		}

		sc.close();

//		int[] A = new int[n+1]; // 1 origin array
//		for (int i=1; i <= n ; i++) {
//			A[i] = Integer.parseInt(data[i-1]);
//		}

		int k = 10_000; // Constraints

		int[] B = new int[n+1];
//		countingsort(A, B, k);

		int[] C = new int[k+1];

		for (int j=0; j < n; j++) {
//			C[ Integer.parseInt(A[j]) ]++;
			C[ A[j] ]++;
		}

		for (int i=1; i <= k; i++) {
			C[i] += C[i-1];
		}

		for (int j = n-1; 0 <= j; j--) {
//			B[  C[ Integer.parseInt(A[j]) ]  ] = Integer.parseInt(A[j]);
			B[  C[ A[j] ]  ] = A[j];
//			C[ Integer.parseInt(A[j]) ]--;
			C[ A[j] ]--;
		}

		StringBuilder sb = new StringBuilder();
		for (int i=1; i <= n-1; i++) {
			sb.append(B[i] + " ");
		}
		sb.append(B[n]);
		System.out.println(sb);
	}

	static void countingsort(int[] src, int[] dest, int range) {
		int[] counter = new int[range+1];
//		for (int i=0; i <= range; i++) {
//			counter[i] = 0;
//		}

		/** counter[i] ??? i ???????????°????¨?????????? */
		for (int j=1; j < src.length; j++) {
			counter[ src[j] ]++;
		}

		/** counter[i] ??? i ??\????????°???????????°????¨?????????? */
		for (int i=1; i <= range; i++) {
			counter[i] += counter[i-1];
		}

		for (int j = src.length - 1; 1 <= j; j--) {
			dest[  counter[ src[j] ]  ] = src[j];
			counter[ src[j] ]--;
		}
	}
}

Measured memory_bytes: 577600
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8  
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

/*******************************************************/

struct graph_t {
  int n;           // |V|, index begins with 0
  int m;           // |E|
  vector<P> edges; // E
  vector<ll> cost; // cost or distance
  vector<ll> cap;  // capacity
};

class Solve {
private:
  struct node {
    int id; bool done; vi to; vll cost; vi from; vll from_cost;
  };
  vector<node> nodes;
  int n;
public:
  bool result;
  Solve(graph_t G) {
    n = G.n;
    nodes.resize(n);
    Loop(i, n) nodes[i] = { i, false,{},{},{},{} };
    Loop(i, G.edges.size()) {
      nodes[G.edges[i].first].to.push_back(G.edges[i].second);
      nodes[G.edges[i].first].cost.push_back(G.cost[i]);
      nodes[G.edges[i].second].from.push_back(G.edges[i].first);
      nodes[G.edges[i].second].from_cost.push_back(G.cost[i]);
    }
    vll x(n, 0);
    vi roots;
    Loop(i, n) {
      bool judge = true;
      Loop(j, nodes[i].from_cost.size()) {
        if (nodes[i].from_cost[j] != 0) {
          judge = false;
          break;
        }
      }
      if (judge) roots.push_back(i);
    }
    Loop(k, roots.size()) {
      int i = roots[k];
      if (nodes[i].done) continue;
      stack<int> stk;
      stk.push(i);
      x[i] = 0;
      while (stk.size()) {
        int focus = stk.top(); stk.pop();
        if (nodes[focus].done) continue;
        nodes[focus].done = true;
        Loop(j, nodes[focus].to.size()) {
          stk.push(nodes[focus].to[j]);
          x[nodes[focus].to[j]] = x[focus] + nodes[focus].cost[j];
        }
      }
    }
    result = true;
    Loop(i, G.m) {
      if (x[G.edges[i].second] - x[G.edges[i].first] != G.cost[i]) {
        result = false;
        break;
      }
    }
    return;
  }
};

int main() {
  graph_t G;
  cin >> G.n >> G.m;
  Loop(i, G.m) {
    int s, t;
    ll c; cin >> s >> t >> c;
    s--;
    t--;
    G.edges.push_back({ s, t });
    G.cost.push_back(c);
  }
  Solve solve(G);
  if (solve.result) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 30180
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var H = one[0];
  var A = one[1];
  myout(Math.ceil(H / A));
}

Measured memory_bytes: 22084
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

const int INF = 1000000000;

int editDistance(const string& s1, const string& s2) {
    int len1 = s1.size();
    int len2 = s2.size();
    vector<vector<int>> dp(len1 + 1, vector<int>(len2 + 1, INF));
    for (int i = 0; i <= len2; i++) {
        dp[0][i] = i;
    }
    for (int i = 0; i < len1; i++) {
        dp[i][0] = i;
    }
    
    for (int i = 1; i <= len1; i++) {
        for (int j = 1; j <= len2; j++) {
            dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
            dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (s1[i - 1] == s2[j - 1]? 0 : 1));
        }
    }
    
    return dp[len1][len2];
    
}

int main() {
    
    string s1, s2;
    cin >> s1 >> s2;
    
    int ans = editDistance(s1, s2);
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 6788
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() { 
    int n, m; cin >> n >> m;
    vector<pii> q(m);
    rep(i, m){
        int a, b; cin >> a >> b;
        q[i] = {b, a};
    }
    sort(all(q));

    int bef = -1, res = 0;
    rep(i, m){
        int a = q[i].second, b = q[i].first;
        if(bef < a){
            bef = b - 1; res++;
        }
    }
    cout << res << ln;
}

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
a,b,c,d,e,f = map(int, input().split())
rec = 0
ans1 = 100*a
ans2 = 0
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                w = 100*a*i + 100*b*j
                s = c*k + d*l
                if w == 0:
                    break
                if s > e*(a*i+b*j):
                    break
                if w + s > f:
                    break
                if s / (w + s) > rec:
                    rec = s / (w + s)
                    ans1 = w + s
                    ans2 = s
print(str(ans1) + ' ' + str(ans2))

Measured memory_bytes: 3064
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C = sl()
    print('YES' if A[-1] == B[0] and B[-1] == C[0] else 'NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	string a;

	cin >> a;

	int b= a.size();

	for (int i = 0; i < b;i++) {
		if (a[i]=='?') {
			a[i] = 'D';
		}
	}

	cout << a<<endl;

	return 0;
}

Measured memory_bytes: 3724
use std::io;
use std::collections::HashMap;


fn main() {
    let n = read_one::<usize>();
    if n == 1 { println!("1"); return; }
    let mut xy = Vec::new();
    for _ in 0..n {
        let (x, y) = {
            let i = read::<isize>();
            (i[0], i[1])
        };
        xy.push((x, y));
    }

    let mut hm = HashMap::new();
    for i in 0..n { for j in 0..n {
        if i == j { continue; }
        *hm.entry((xy[i].0 - xy[j].0, xy[i].1 - xy[j].1)).or_insert(0) += 1;
    }}
    let ans = hm.iter().max_by_key(|v| v.1).unwrap();
    println!("{}", n - ans.1);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long ans = 0;
        for (int b = k + 1; b <= n; b++) {
            int laps = n / b;
            int extra = n % b;
            int bigger = b - k;
            ans += 1l * laps * bigger;
           ans += Math.max(0, extra - k + (k == 0 ? 0 : 1));
        }
        out.println(ans);
        out.flush();
        out.close();
    }


    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

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

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  sort(ALLR(a));
  cout << a.front()-a.back() << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <array>

using namespace std;

int main() {
	
	// 変数宣言
	int A, B, T, ans;
	
	cin >> A >> B >> T;
	
	ans = (int)((T + 0.5) / A) * B;
	
	// 出力
	printf("%d\n", ans);
	
	return 0;
	
}


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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

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

  int n; cin >> n;
  
  if (n <= 999) cout << "ABC\n";
  else cout << "ABD\n";
  
  return (0);
}

Measured memory_bytes: 3668
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'
#define INF (1ll << 60)

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int MOD = 1e9 + 7;

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

  int res = n / 1.08;
  bool flag = false;
  REP(i, 1000) {
    if (n == (int)(res * 1.08)) {
      flag = true;
      break;
    }
    res++;
  }

  if (flag) {
    cout << res << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
T = input()
MOD = 10**9+7

ans = 3
if S[0] != T[0]:
    ans *= 2
for s1,t1,s2,t2 in zip(S,T,S[1:],T[1:]):
    if s1==s2 and t1==t2: continue
    if s1==t1:
        ans *= 2
    elif s2!=t2:
        ans *= 3
print(ans%MOD)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <vector>
#include <stack>
#define Clear( x , y ) memset( x , y , sizeof(x) );
#define Qcin() std::ios::sync_with_stdio(false);
using namespace std;
typedef long long LL;
const int Maxn = 1e6 + 7;
const int Inf = 1e9 + 7;
int N , K;
int main()
{
	while( cin >> N ){
		int a = 0 , b = 0 , flag = 0;
		for( int i = 0 ; i <= 25 ; i++ ){
			if( N - 4 * i >= 0 ){
			if( ( N - 4 * i ) % 7 == 0 ){
				flag = 1;
				break;
			}
			}
		}
		if( flag )	printf("Yes\n");
		else	printf("No\n");
	}
}

Measured memory_bytes: 256
function Main(input){
    input = input.split("\n");
    k = 0;
    while(1){
        input[k] = input[k].split(' ');
        var n = parseInt(input[k][0],10);
        var m = parseInt(input[k][1],10);
        var p = parseInt(input[k++][2],10);

        if(n == 0 && m == 0 && p == 0)
            break;

        var sum = 0;var win;
        for(var i = 0;i < n;i++){
            var a = parseInt(input[k++],10);
            sum += a * 100;
            if(m - 1 == i){
                win = a;
            }
        }
        sum = sum * (100 - p) / 100;
        if(win > 0)
            console.log(Math.floor(sum / win));
        else
            console.log("0");
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

LL gcd (LL a, LL b) {
  if (b > a) {
    LL tmp = b;
    b = a;
    a = tmp;
  }
  if (a % b == 0) return b;
  else return gcd(b, a % b);
}

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

int main(){
  int n;

  scanf("%d",&n);

  LL t[n];
  REP (i, n) scanf("%lld",&t[i]);

  LL ans = t[0];
  REP (i, n) {
    ans = lcm(ans, t[i]);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long mod=1000000007;
long long fastexpo(long long a,long long n,int p) {
    if(n==0)
    return 1LL%p;
    long long u=fastexpo(a,n/2,p);
    u=(u*u)%p;
    if(n%2==1)
    u=(u*a)%p;
    return u;
}

int main() {
    long long n;
    cin>>n;
    if(n==1) {
        cout<<0;
        return 0;
    }
    
    long long ans1=fastexpo(9LL,n,mod);
    ans1=(ans1*2LL)%mod;
    long long ans2=fastexpo(8LL,n,mod);
    ans2%=mod;
    long long ans=fastexpo(10LL,n,mod);
    ans%=mod;
    ans=ans-ans1+ans2;
    ans%=mod;
    if(ans<0)
    ans+=mod;
    ans%=mod;
    cout<<ans;
}


Measured memory_bytes: 3572
import sys
#input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	s=[]
	t=[]
	for i in range(n):
		a,b=input().split()
		s.append(a)
		t.append(int(b))
	x=input()
	for i in range(n):
		if x==s[i]:
			print(sum(t[i+1:]))


if __name__ == "__main__":
	main()


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;


    ll N,K;
    ll X[100010],Y[100010];
    ll ans;
    ll prime[100010];
    ll pn;
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    prime[pn]=2;pn++;
    REP(i,55555+1){
        if(i<=2)continue;
        bool f=true;
        REP(j,pn){
            if(i%prime[j]==0){f=false;break;}
        }
        if(f){
            prime[pn]=i;
            pn++;
        }
    }

    int cnt=0;
    REP(i,55555+1){
        if(prime[i]%5==1){
            cout<<prime[i];
            cnt++;
            if(cnt==N)break;
            cout<<" ";
        }


    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  ll N; cin >> N;
  ll a, b;
  a = N / 500;
  b = (N - a * 500) / 5;

  cout << a * 1000 + b * 5 << "\n";

  return 0;
}


Measured memory_bytes: 256
n, c = map(int,input().split())
x = []
v = []
for i in range(n):
    s, t = input().split()
    x.append(int(s))
    v.append(int(t))
vl1 = [0]
vl2 = [0]
suml = 0
vr1 = [0]
vr2 = [0]
sumr = 0
for i in range(n):
    suml += v[i]
    #3項演算子ver
    vl1.append(vl1[i] if vl1[i] > suml - x[i] else suml - x[i])
    vl2.append(vl2[i] if vl2[i] > suml - x[i]*2 else suml - x[i]*2)
    #vl1.append(max(vl1[i],suml - x[i]))
    #vl2.append(max(vl2[i],suml - x[i]*2))
    sumr += v[n-1-i]
    vr1.append(vr1[i] if vr1[i] > sumr - c + x[n-1-i] else sumr - c + x[n-1-i])
    vr2.append(vr2[i] if vr2[i] > sumr - (c - x[n-1-i])*2 else sumr - (c - x[n-1-i])*2)
    #vr1.append(max(vr1[i],sumr - c + x[n-1-i]))
    #vr2.append(max(vr2[i],sumr - (c - x[n-1-i])*2))
print(max( [max(vl1[i]+vr2[n-i],vr1[i]+vl2[n-i]) for i in range(n+1)] ))

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	int count_1 = 0,count_2 = 0,count_3 = 0,count_4 = 0;
	for (int i = 0; i < n;i++) {
	    string s;
	    cin >> s;
	    if (s == "AC") {
	        count_1++;
	    }
	    if (s == "WA") {
	        count_2++;
	    }
	    if (s == "RE") {
	        count_3++;
	    }
	    if (s == "TLE") {
	        count_4++;
	    }
	}
	cout << "AC x " << count_1 << endl;
	cout << "WA x " << count_2 << endl;
	cout << "TLE x " << count_4 << endl;
	cout << "RE x " << count_3 << endl;
}


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

int main(){
    int n, cnt=0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int p; cin >> p;
        if(p != i+1) cnt++;
    }
    cout << (cnt<=2 ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
j,a['   '],z=1e6;main(i){for(;++i<z||~scanf(j="%d\n",a)&&printf(j,a[*a]);a[i]=*a+=!a[i])for(j=i*i;i<998&&!a[i]?a[j]=j<z:0;j+=i);}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::string S;
int T[4100];
int A[4100][3];

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

  std::cin >> N >> S;

  for(int i=0;i<N;++i){
      if(S[i] == 'R'){
          T[i] = 0;
      }else if(S[i] == 'G'){
          T[i] = 1;
      }else{
          T[i] = 2;
      }
  }

  for(int i=N-1;i>=0;--i){
      for(int j=0;j<3;++j){
          A[i][j] = A[i+1][j];
      }

      A[i][T[i]] += 1;
  }

  ll comp = 0;

  for(int i=0;i<N;++i){
      for(int j=i+1;j<N;++j){
          if(T[i] == T[j]){
              comp += N - j - 1;
          }else{
              comp += A[j+1][T[i]] + A[j+1][T[j]];
              
              int k = j + (j - i);
              if(k < N && T[k] != T[i] && T[k] != T[j]){
                  comp += 1;
              }
          }
      }
  }

  ll res = 1ll * N * (N - 1) * (N - 2) / 6 - comp;
  std::cout << res << std::endl;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	map<string, int>f;
	int n;
	cin >> n;
	int maxi = 0;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		f[s]++;
		maxi = max(maxi, f[s]);
	}
	for(auto i:f){
		if(i.ss == maxi) cout << i.ff <<"\n";
	}
}

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

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

    int ans = 0;
    if (a == b && b != c)
    {
        ans = 1;
    }
    else if (b == c && c != a)
    {
        ans = 1;
    }
    else if (c == a && a != b)
    {
        ans = 1;
    }

    if (ans == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;
use std::cmp::min;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    let d: i64 = read();
    if a > c {
        println!("{}", max(min(d - a, b - a), 0));
        return;
    }
    if c > a {
        println!("{}", max(min(b - c, d - c), 0));
        return;
    }
    println!("{}", min(b, d) - a);
}


Measured memory_bytes: 4352
n=int(input())
a=[int(x) for x in input().split()]
keta_0=[0]*70
keta_1=[0]*70
for shift in range(70):
    for i in range(n):
        if a[i]>>shift & 1:
            keta_1[shift]+=1
        else:
            keta_0[shift]+=1
ans=0

for i in range(70):
    ans+=2**i*keta_0[i]*keta_1[i]
    ans%=10**9+7

print(ans)

Measured memory_bytes: 124528
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		
		char count[] = new char[256];
		for(char ch:s) {
			count[ch]++;
		}
		
		if(count['R'] > count['B']) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
}


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

int N,M;
int S,G;

vector<tuple<int,int,int>> g[30];
#define mkt make_tuple
#define INF 1e9

double dist[31][31][31];

double dijkstra(){
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) for(int k=0;k<=30;k++) dist[i][j][k]=INF;
    priority_queue<tuple<double,int,int,int>> PQ;
    for(int i=0;i<g[S].size();i++){
        int nex=get<0>(g[S][i]);
        double d=get<1>(g[S][i]);
        dist[nex][S][1]=d;
        PQ.push(mkt(-d,nex,S,1));
    }

    while(!PQ.empty()){
        auto f=PQ.top();
        PQ.pop();

        double co;
        int now,pre,v;
        co=-get<0>(f);
        now=get<1>(f);
        pre=get<2>(f);
        v=get<3>(f);

        if(dist[now][pre][v]<co) continue;
        if(now==G&&v==1) return co;

        for(int i=0;i<g[now].size();i++){
            int nex=get<0>(g[now][i]);
            int lim=get<2>(g[now][i]);
            double d=get<1>(g[now][i]);

            if(nex==pre) continue;

            for(int i=-1;i<=1;i++){
                int nv=v+i;
                if(nv<=0||nv>lim) continue;
                
                double neco=d/nv;
                if(dist[nex][now][nv]<=co+neco) continue;
                dist[nex][now][nv]=co+neco;
                PQ.push(mkt(-(co+neco),nex,now,nv));
            }
        }
    }
    return -1;
}

void solve(){
    cin>>S>>G;
    S--;G--;
    for(int i=0;i<30;i++) g[i].clear();
    for(int i=0;i<M;i++){
        int x,y,c;
        double d;
        cin>>x>>y>>d>>c;
        x--;y--;
        g[x].push_back(mkt(y,d,c));
        g[y].push_back(mkt(x,d,c));
    }

    double ans;
    ans=dijkstra();
    if(ans==-1) cout<<"unreachable"<<endl;
    else cout<<fixed<<setprecision(10)<<ans<<endl;
}

int main(){
  while(1){
      cin>>N>>M;
      if(N==0&&M==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 3792
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <climits>

using namespace std;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

// using int64 = long long;
typedef long long int64;


template<typename T> class BIT {
    int n;
    vector<T> d;
public:
    BIT(int _n=0) {
      n = _n;
      d = vector<T>(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;
    }
};


int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<BIT<int>> bit(26, BIT<int>(n));
    for (int i=0; i<n; i++) {
        bit[s[i] - 'a'].add(i,1);
    }

    int q;
    cin >> q;
    for (int i=0; i<q; i++) {
        int type; cin >> type;
        switch(type) {
            case 1:
                int i;
                char c;
                cin >> i >> c;
                bit[s[i-1] - 'a'].add(i-1,-1);
                bit[c - 'a'].add(i-1,1);
                s[i-1] = c;
                break;
            case 2:
                int l,r;
                cin >> l >> r;
                int ans = 0;
                for (int i=0; i<26; i++) {
                    if (bit[i].sum(r-1) - bit[i].sum(l-2) >= 1)
                        ans++;
                }
                cout << ans << endl;
                break;
        }
    }
}


Measured memory_bytes: 53624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
#define MAX_TICK 1125899906842623
using namespace std;
using ll = long long;
vector<ll> t(51),p(51);
ll answer = 0;
void eat(ll ref_level,ll tick){
    if(tick <= 0)return;
    //cerr << ref_level;
    int level = lower_bound(t.begin(),t.end(),tick)-t.begin();
    if(t[ref_level] > tick){
        //cerr << "a";
        eat(--ref_level,--tick);
    }else if(t[ref_level] < tick){
        //cerr << "b";
        answer+=p[ref_level];
        tick-=1;
        answer++;
        tick-=t[ref_level];
        /*if(tick >= t[ref_level]){
            answer+=p[ref_level];
            return;
        }
        eat(--ref_level,tick);*/
        eat(ref_level,tick);
    }else{
        //cerr << "c";
        answer += p[ref_level];
        return;
    }
}
int main(){
    ll n,x;
    cin >> n >> x;
    t[0]=p[0]=1;
    REP(i,50){
        t[i+1] = t[i]*2+3;
        p[i+1] = p[i]*2+1;
    }

    /*int level = lower_bound(t.begin(),t.end(),x)-t.begin();
    REP(i,n){
        //cerr << t[i] << endl;
        cerr << p[i] << endl;
    }*/

    eat(n,x);

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c, k; cin >> a >> b >> c >> k;
  cout << (k%2?-1:1) * (a-b) << "\n";
  return 0;
}


Measured memory_bytes: 3588
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var broken = new bool[N + 1];
            for (var i = 0; i < M; ++i)
                broken[Sarray()[0]] = true;
            var dp = new long[N+1];
            dp[0] = 1;
            dp[1] = broken[1] ? 0 : 1;
            for (var i = 2; i <= N; ++i)
            {
                if (broken[i])
                    continue;
                dp[i] = (dp[i - 1] + dp[i - 2]) % Mod;
            }
            WriteLine(dp[N] % Mod);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 18116
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

using ll = long long;

template <typename T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}

string judge(int a, int b)
{
	if (a == b)
		return "Draw";

	if (a == 1)
		return "Alice";

	if (b == 1)
		return "Bob";

	return (a > b) ? "Alice" : "Bob";
}

int main()
{
	int a, b;
	cin >> a >> b;
	cout << judge(a, b) << endl;
}

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

int main()
{
  int n, x, y;
  cin >> n >> x >> y;

  map<int, int> m;
  for (int j = 1; j <= n; j++)
  {
    for (int i = 1; i < j; i++)
    {
      int len = min(j - i, abs(x - i) + 1 + abs(y - j));
      m[len] += 1;
    }
  }
  for (int i = 1; i <= n - 1; i++)
    cout << m[i] << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;

void solve()
{
    int n, t;
    cin >> n >> t;
    ll sum = 0;
    ll ps, pe;
    ps = -1;
    pe = -1;
    rep(i, n)
    {
        ll a;
        cin >> a;
        if (i == 0)
        {
            sum += t;
        }
        else
        {
            if (a < pe)
            {
                sum += t - abs(a - pe);
            }
            else
            {
                sum += t;
            }
        }
        ps = a;
        pe = a + t;
    }
    P(sum);
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
il1 = input().split()
il2 = input().split()

il1 = [int(i) for i in il1]
il2 = [int(i) for i in il2]

N = il1[0]
M = il1[1]

A = il2

for a in il2:
    N = N - a

if N >= 0:
    print(N)
else:
    print(-1)


Measured memory_bytes: 10056
N = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
if all([i%2==1 for i in A]):
    print('APPROVED')
else:
    even = [i for i in A if i%2==0]
    even = [0 if i%3==0 or i%5==0 else 1 for i in even]
    if max(even)==1:
        print('DENIED')
    else:
        print('APPROVED')

Measured memory_bytes: 3060
mod = 1000000007
s = input()
n = len(s)
c = [0 for i in range(n)]
d = [0 for i in range(n)]
bc = [0 for i in range(n)]
bd = [0 for i in range(n)]
dc = [0 for i in range(n)]
dd = [0 for i in range(n)]


if s[-1] == "C":
    c[-1] = 1
if s[-1] == "?":
    d[-1] = 1
for i in range(-2, -n-1, -1):
    c[i] = c[i+1]
    d[i] = d[i+1]
    bc[i] = bc[i+1]
    bd[i] = bd[i+1]
    dc[i] = dc[i+1]
    dd[i] = dd[i+1]
    if s[i] == "B":
        bc[i] += c[i+1]
        bd[i] += d[i+1]
    elif s[i] == "C":
        c[i] += 1
    elif s[i] == "?":
        d[i] += 1
        dc[i] += c[i+1]
        dd[i] += d[i+1]


if d[0] == 0:
    mul = [0, 0, 0, 1]
elif d[0] == 1:
    mul = [0, 0, 1, 3]
elif d[0] == 2:
    mul = [0, 1, 3, 9]
else:
    mul = [1, 1, 1, 1]
    for i in range(d[0]-3):
        mul[0] *= 3
        mul[0] %= mod
    for i in range(3):
        mul[i+1] = (mul[i]*3) % mod

res = 0
for i in range(n-2):
    if s[i] == "A":
        res += bc[i+1]*mul[3]+(dc[i+1]+bd[i+1])*mul[2]+dd[i+1]*mul[1]
    if s[i] == "?":
        res += bc[i+1]*mul[2]+(dc[i+1]+bd[i+1])*mul[1]+dd[i+1]*mul[0]
    res %= 1000000007
print(res)


Measured memory_bytes: 50608
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>

using namespace std;

bool is_prime[10000001];

int main(){
    int N;
    while(cin >> N){
    for(int i = 2; i <= N; i++){
        is_prime[i] = true;
    }

    for(int i = 2; i <= N; i++){
        if(!is_prime[i]){
            continue;
        }
        for(int j = 2 * i; j <= N; j += i){
            is_prime[j] = false;
        }
    }

    int ans = 0;
    for(int i = 2; i <= N; i++){
        if(is_prime[i]){
            ans++;
        }
    }
    cout << ans << endl;
    }
}


Measured memory_bytes: 4080
object Main
  extends App {
  val n                = readInt
  val source: Seq[Int] = Stream.continually(readInt).take(n)

  val answer = source.foldLeft((Integer.MAX_VALUE, Integer.MIN_VALUE))((acc, h) => (math.min(h, acc._1), math.max(acc._2, h - acc._1)))
  println(answer._2)
}


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

long long int solveKnapsack(vector <vector<long long int>> &dp,const vector <long long int > &weight,const vector <long long int> &values, long long int i, long long int w)
{
 	if(i >= weight.size())
      return 0;
  	if(dp[i][w] > -1)
      return dp[i][w];
  	long long int p1 = 0, p2 = 0;
  	if(weight[i] <= w)
      p1 = values[i] + solveKnapsack(dp, weight, values, i + 1, w - weight[i]);
  	p2 = solveKnapsack(dp, weight, values, i + 1, w);
  	dp[i][w] = max(p1, p2);
  	return dp[i][w];
}

int main()
{
  long long int n, w;
  cin >> n >> w;
  vector <long long int> weights(n, 0);
  vector <long long int> values(n, 0);
  
  for(long long int i=0; i < n; i++)
  {
    cin >> weights[i] >>  values[i];
  }
  vector< vector<long long int> > dp(n, vector<long long int> (w + 1, -1));
  cout << solveKnapsack(dp, weights, values, 0, w);
  return 0;
}

Measured memory_bytes: 79360
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let n = match buf.trim().parse() {
		Ok(m) => m,
		_ => panic!(""),
	};
	
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let mut inv:f64 = 0.0;
	let mut ret:f64 = 0.0;
	for i in 0..n {
		let j = match iter.next().unwrap().parse::<f64>() {
			Ok(k) => k,
			_ => panic!(""),
		};
		inv = inv + 1.0 / j;
	}
	ret = 1.0 / inv;
	println!("{}", ret);
}

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

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

bool cmp(pair<ii,ll> a, pair<ii,ll> b)
{
	if(a.fi.fi+a.fi.se!=b.fi.fi+b.fi.se) return a.fi.fi+a.fi.se<b.fi.fi+b.fi.se;
	return (a.se<b.se);
}

ll dp[1111][21111];
const int C = 20111;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	vector<pair<ii,ll> > vec;
	int n; cin>>n;
	vec.pb(mp(mp(-int(1e9),-1),-1));
	for(int i=0;i<n;i++)
	{
		ll w,s,v; cin>>w>>s>>v;
		vec.pb(mp(mp(w,s),v));
	}
	sort(vec.begin(),vec.end(),cmp);
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=C;j++)
		{
			//not choose vec[i]
			dp[i][j] = dp[i-1][j];
			//choose vec[i]
			if(j-vec[i].fi.fi>=0&&vec[i].fi.se>=j-vec[i].fi.fi)
			{
				dp[i][j] = max(dp[i][j], dp[i-1][j-vec[i].fi.fi]+vec[i].se);
			}
		}
	}
	ll ans=0;
	for(int j=0;j<=C;j++) ans=max(ans,dp[n][j]);
	cout<<ans<<'\n';
}


Measured memory_bytes: 166016
#include <stdio.h>

int main(){
  int a, b, c, work;
  a=b=c=work=0;
  scanf("%d%d", &a, &b);
  if(a<b){
    work=a;
    a=b;
    b=work;
  }
  c=a%b;
  while(c!=0){
    a=b;
    b=c;
    c=a%b;
  }
  printf("%d\n", b);
  return 0;
}



Measured memory_bytes: 2140
#include<stdio.h>

int main()
{
    int i,j,mt=0;

    for(i=1;i<10;i++)
    {
        for(j=1;j<10;j++)
        {
           mt = i * j;
           printf("%dx%d=%d\n",i,j,mt);
        }

    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
  
#define N 100005
#define U [N]={}
map<L,L> path[N];
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,q,a,b,c,i,p,r;
char s[5];
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
    
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
    
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
L S(L i, L x){
    x=edgecost(x)-sum(i+1)+sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
  
main(){
    for(cin>>n>>k;i<n-1;i++)
        cin>>a>>b>>c,
        path[a][b]=path[b][a]=c;
    dfs(0);
    
    for(c=i=0;i<n;i++)
        if(!i|hev[par[i]]-i)
        for(a=i;!c|a;a=hev[a])
            pos[a]=c++,
            hl_par[a]=i,
            S(pos[a],hev[a]);
    
    for(cin>>a;cin>>s>>a>>b;)
        if(*s&2){
            for(c=0;p=hl_par[a],r=hl_par[b],p-r;a=par[p])
                dep[p]<dep[r]?swap(p,r),swap(a,b),0:0,
                c+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<c+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }else
            add[a]+=b,
            S(pos[a],hev[a]),
            a?S(pos[a]-1,a):0;
}

Measured memory_bytes: 32008
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
bool used[MAX_N];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	// グラフ
	vector<VE>G(n);
	vector<P>vp;
	rep(i,n-1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b); G[b].push_back(a);
		vp.push_back(make_pair(a, b));
	}
	// 色の数
	int k = 0;
	vector<int>hennoiro(n); // その名の通り
	map<P, int>I; // 出力用map
	// 幅優先探索
	queue<int>que;
	used[0] = true;
	que.emplace(0);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		chmax(k, (int)G[v].size());
		int color = 1;
		for (int u : G[v]) {
			if (used[u])continue;
			if (color == hennoiro[v])color++;
			hennoiro[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = color++;
			used[u] = true;
			que.emplace(u);
		}
	}
	cout << k << endl;
	for (auto p : vp)cout << I[p] << endl;
	return 0;
}


Measured memory_bytes: 21488
import sys
N = int(input())
cc = [list(map(int,input().split())) for i in range(N)]
count = 0
for i,j in cc:
  if i==j:
    count+=1
  else:
    count = 0
  if count == 3:
    print('Yes')
    sys.exit()
print('No')
  

Measured memory_bytes: 9164