akhauriyash/Code-Regression huggingface dataset:
import queue


def megalomania(N: int, tasks: list)->bool:
    que = queue.PriorityQueue()

    for a, b in tasks:
        que.put((b, a))

    time = 0
    while not que.empty():
        b, a = que.get()
        time += a
        if time > b:
            return False

    return True


if __name__ == "__main__":
    N = int(input())
    tasks = [tuple(int(s) for s in input().split()) for _ in range(N)]

    yes = megalomania(N, tasks)
    print('Yes' if yes else 'No')


Measured memory_bytes: 102612
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    char[] charN = String.valueOf(n).toCharArray();

    String ans = "";
    for (char num : charN) {
      ans += (num == '1') ? "9" : "1";
    }

    System.out.println(ans);

  }

}


Measured memory_bytes: 23252
a=input()
b=input()
flg=0
if len(a) > len(b):
    print("GREATER")
elif len(a) < len(b):
    print("LESS")
else:
    for i in range(len(a)):
        if ord(a[i]) > ord(b[i]):
            print("GREATER")
            flg=1
            break
        elif ord(a[i]) < ord(b[i]):
            print("LESS")
            flg=1
            break
    if(flg==0):
        print("EQUAL")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <array>
using namespace std;

struct Dice
{
    array<int, 6> roll;
    void toNorth()
    {
        array<int, 6> t = roll;
        roll[4] = t[0];
        roll[0] = t[1];
        roll[5] = t[4];
        roll[1] = t[5];
    }
    void toSouth()
    {
        array<int, 6> t = roll;
        roll[1] = t[0];
        roll[5] = t[1];
        roll[0] = t[4];
        roll[4] = t[5];
    }
    void toWest()
    {
        array<int, 6> t = roll;
        roll[3] = t[0];
        roll[0] = t[2];
        roll[5] = t[3];
        roll[2] = t[5];
    }
    void toEast()
    {
        array<int, 6> t = roll;
        roll[2] = t[0];
        roll[5] = t[2];
        roll[0] = t[3];
        roll[3] = t[5];
    }
};

int main()
{
    int num;
    string commands;
    Dice dice;
    for (int i=0; i<6; i++) {
        cin >> dice.roll[i];
    }
    cin >> commands;
    size_t size = commands.size();
    for (size_t i=0; i<=size; i++ ) {
        if (commands[i]=='N')
            dice.toNorth();
        else if (commands[i]=='S')
            dice.toSouth();
        else if (commands[i]=='E')
            dice.toEast();
        else if (commands[i]=='W')
            dice.toWest();
    }
    cout << dice.roll[0] << endl;
    
    return 0;
}


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

int main() {
  char b;
  cin >> b;

  if (b == 'A')
    cout << 'T' << endl;
  else if (b == 'T')
    cout << 'A' << endl;
  else if (b == 'C')
    cout << 'G' << endl;
  else if (b == 'G')
    cout << 'C' << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;

string s[1024];

int main(void)
{
    int c=0;
    string ret;
    while(cin>>s[c]){
        if(s[c][s[c].length()-1]==',' || s[c][s[c].length()-1]=='.')s[c].erase(s[c].length()-1);
            
            
            
            
            
            
            
            
            
        if(3<=s[c].length()&&s[c].length()<=6)ret+=s[c]+' ';
        c++;
    }
    ret.erase(ret.length()-1);
    cout<<ret<<endl;
    
}

Measured memory_bytes: 1200
N = int(input())
num = list(map(int, input().split()))

MAXX = 10**5 + 5
count = [0]*MAXX

sumz = sum(num)
for n in num:
    count[n] += 1

Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    sumz += count[b]*(c-b)
    #sumz -= count[b]*b
    count[c] += count[b]
    count[b] = 0

    print(sumz)








Measured memory_bytes: 83828
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int digit_sum(int x) {
	string s = to_string(x);
	int ret = 0;
	for (int i = 0; i < s.size(); i++) {
		ret += s[i] - '0';
	}
	return ret;
}

signed main() {
	int n;
	cin >> n;
	if (n % digit_sum(n) == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
if (x == 2) or (y == 2):
    print('No')
elif x in (4, 6, 9, 11) and y in (4, 6, 9, 11):
    print('Yes')
elif x in (1, 3, 5, 7, 8, 10, 12) and y in (1, 3, 5, 7, 8, 10, 12):
    print('Yes')
else:
    print('No')


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

int main()
{
	string s;
	cin>>s;
	int n=s.size(),sum=0;
	int i=0,j=n-1;
	while(i<=j)
	{
		if(s[i]!=s[j]) sum++;
		i++;j--;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
A, B = map(str, input().split())
ansCnt = 0
for i in range(int(A), int(B) + 1):
    cntB = True
    for j in range(2):
        if str(i)[j] != str(i)[-j - 1]:
            cntB = False
            break

    if cntB:
        ansCnt += 1

print(ansCnt)

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int n, m;
int fa[200009], siz[200009];

int getfa(int x) {
    if (x == fa[x])return x;
    return fa[x] = getfa(fa[x]);
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)fa[i] = i, siz[i] = 1;
    for (int i = 1; i <= m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        int faa = getfa(a), fab = getfa(b);
        if (faa != fab) {
            fa[faa] = fab;
            siz[fab] += siz[faa];
        }
    }
    cout << *max_element(siz + 1, siz + 1 + n)  << endl;
    return 0;
}


Measured memory_bytes: 5276
N = int(input())
S = input()
m = 10 ** 9 + 7
H = {}
for s in S:
  if not s in H:
    H[s] = 0
  H[s] += 1
#print(H)
ans = 1
for s, k in H.items():
  ans = (ans * (k + 1)) % m
print(ans-1)

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

const int mod = 1e9 + 7;



typedef vector<int> V;
typedef vector<V> VV;
int a[11234];
int b[11234];
VV g;
LL dp[5123][5123][2];
LL pp[5123][2];
LL latte[5123];
int sz[5123];
void dfs(int v,int p) {
	sz[v] = 1;
	dp[v][1][0] = 1;
	for (int u : g[v]) {
		if (u == p)continue;
		dfs(u, v);
		int nsz = sz[v] + sz[u];
		for (int i : range(nsz + 1))pp[i][0] = pp[i][1] = 0;
		for (int l : range(1, sz[v] + 1)) {
			pp[l][0] += dp[v][l][1] * dp[u][0][0] % mod;
			pp[l][0] += dp[v][l][0] * dp[u][0][1] % mod;
			pp[l][1] += dp[v][l][0] * dp[u][0][0] % mod;
			pp[l][1] += dp[v][l][1] * dp[u][0][1] % mod;
			for (int r : range(1, sz[u] + 1)) {
				const int lr = l + r;
				pp[lr][0] += dp[v][l][0] * dp[u][r][0] % mod;
				pp[lr][0] += dp[v][l][1] * dp[u][r][1] % mod;
				pp[lr][1] += dp[v][l][1] * dp[u][r][0] % mod;
				pp[lr][1] += dp[v][l][0] * dp[u][r][1] % mod;
			}
		}
		for (int i : range(nsz + 1)) {
			dp[v][i][0] = pp[i][0] % mod;
			dp[v][i][1] = pp[i][1] % mod;
		}
		sz[v] = nsz;
	}
	for (int i : range(1, sz[v] + 1)) {
		if (i % 2)continue;
		dp[v][0][0] += dp[v][i][0] * latte[i] % mod;
		dp[v][0][1] += dp[v][i][1] * latte[i] % mod;
	}
	dp[v][0][0] %= mod;
	dp[v][0][1] %= mod;
}
const int r = 0;
int main() {
	latte[0] = 1;
	for (int i : range(2,5123)) {
		if (i % 2)continue;
		latte[i] = latte[i - 2] * (i - 1) % mod;
	}
	int N;
	cin >> N;
	g = VV(N);
	for (int i : range(N - 1)) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	dfs(r,r);
	cout << (dp[r][0][0] + mod - dp[r][0][1]) % mod << endl;
	return 0;
}


Measured memory_bytes: 400768
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int main(){
    int a;
    vector<int> b;
    cin >> a;
    while(a != 0){
        b.push_back(abs(a%(-2)));
        if(a%(-2) == -1){
            a = a/(-2) +1;
        }else{
            a /= (-2);
        }
    }

    for(int i = b.size()-1; i >= 0; i--){
        cout << b[i];
    }
  	if(b.size() == 0){
		cout << 0;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int Bubble(int A[N], int n){

	int count = 0;
	int tmp,i,j;
	
	for(i = 0; i < n; i++){
		for(j = n-1; j > 0; j--){
			if(A[j] < A[j-1]){
				tmp = A[j];
				A[j] = A[j-1];
				A[j-1] = tmp;
				count++;
			}
		}
	}
	return count;
}

int main(){

	int A[N],n,i,count;

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

	count = Bubble(A,n);
	
	for ( i = 0; i < n; ++i){
		printf("%d",A[i]);
		if( i != n-1) printf(" ");
	}
		printf("\n%d\n",count);

	return 0;
}


Measured memory_bytes: 2140
fn main() {
    let n:i32 = read();
    let a:Vec<i32> = read_vec();
    let x_1 = a.iter().enumerate().fold(
        0,
        |s,(i,e)| if i.trailing_zeros() == 0 {s-*e} else {s+*e}
    );
    let mut ans = a.iter().scan(
        x_1,
        |p, a| {*p=2*a-*p; Some(*p)}
    );
    println!("{}",x_1);
    for i in 0..n-1 {
        println!("{}",ans.next().unwrap());
    }
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}

fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 8444
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
int a[55];
int n;
bool flag;
void swap(int i,int j)
{
	int p=a[i];a[i]=a[j];a[j]=p;
}
bool pd()
{
    for(int i=1;i<n;i++)
    {
	 if(a[i+1]<=a[i]) 
	 {
//	printf("%d %d\n",a[i],i);
	 return false;
	 }
    }
	 return true;	
}
int main()
{
	flag=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	if(pd()) {flag=1;printf("YES");}
	for(int i=1;i<n;i++)
	{
	   if(flag) break;
	   for(int j=i+1;j<=n;j++)
	   {
	   	  swap(i,j);
	   	  if(pd()) {
			 printf("YES");
			 flag=1;
	               }
	      else swap(i,j);
       }
     }
    if(!flag) printf("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o set

signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n; cin >> n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll x=n/i;
        ans+=x*i+x*(x-1)/2*i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int n;

char c[110];
void find (int x, int sp) {
	if (x == n) {
		for (int i = 1; i <= n; i ++) {
			cout << c[i];
		}
		cout << endl;
		return ;
	}
	for (int i = 1; i <= sp; i ++) {
		c[x + 1] = 'a' + i - 1;
		find (x + 1, sp);
	}
	c[x + 1] = 'a' + sp;
	find (x + 1, sp + 1);
}

int main() {
	cin >> n;	
	find (0, 0);
	return 0;
}

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

wa=(n+1)*[0]
ac=(n+1)*[0]

for i in range(m):
  a,b=input().split()
  a=int(a)
  if ac[a] ==0:
    if b=="WA":
      wa[a]+=1
    else:
      ac[a]+=1
wcon=0
accon=0
for i in range(n+1):
  if ac[i]>0:
    accon+=1
    wcon+=wa[i]
print(accon,wcon)

Measured memory_bytes: 45528
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    let n: usize = iter.next().unwrap().parse().unwrap();
    //let p: i64 = iter.next().unwrap().parse().unwrap();
    
    let mut v = Vec::new();
    
    for i in 0..n {
        let s: String = iter.next().unwrap().parse().unwrap();
        let p: i64 = iter.next().unwrap().parse().unwrap();
        v.push((s, 100 - p, i + 1));
    }
    
    v.sort();
           
    for i in 0..n{
        write!(out, "{:?}\n", v[i].2);
    }
}

Measured memory_bytes: 4352
/* ex 8_1
   unomi */

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

//スタックに格納するデータの最大数
#define SIZE 10

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    // スタックがオーバーフローしないなら
    if(stk->count < stk->size){
        stk->top--;  //topを一つ上げる
        *(stk->top) = elem;  // そこに代入
        stk->count++;  // データ数を増やす
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    // スタックがアンダーフローしないなら
    if(stk->count > 0){
        latest = *(stk->top);  // topから取り出し
        stk->top++;  // topを一つ下げる
        stk->count--; // データ数を減らす
    }
    return latest;
}

int main(void){
    // スタックの宣言
    stack stk;
    char sentence[10], trush;
    char *ptr;

    // スタックの初期化
    initialize_stack(&stk);

    // 入力の取得
    scanf("%s",sentence);

    // 入力を先頭から確認
    for(int i=0; i<strlen(sentence); i++){
        // 入力が 0 or 1 ならスタックにプッシュ
        if(sentence[i]=='0'||sentence[i]=='1')
            push(&stk, sentence[i]);
        // 入力が B ならスタックからポップ
        else
            trush = pop(&stk);
    }

    // ポインタ変数にtopのアドレスを代入
    ptr = stk.top;
    // topの位置をスタックの底まで戻す
    for(int j=0; j<stk.count-1; j++) ptr++;
    // スタックのデータ数分古い順に表示
    for(int k=0; k<stk.count; k++)
        printf("%c",*ptr--);
    printf("\n");
    return 0;
}

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

long long md(pair<long long,long long> x,pair<long long,long long> y){
    return max(x.first,y.first)-min(x.first,y.first)+max(x.second,y.second)-min(x.second,y.second);
}

int main(){
    int N;
    cin >> N;
    vector<int> enemy(N+1),hero(N);
    for(int i=0;i<N+1;i++){
        cin >> enemy[i];
    }
    for(int i=0;i<N;i++){
        cin >> hero[i];
    }
    long long ans=0;
    for(int i=0;i<N;i++){
        if(hero[i]<enemy[i]){
            ans+=hero[i];
        }
        else{
            if(enemy[i]+enemy[i+1]>=hero[i]){
                enemy[i+1]-=hero[i]-enemy[i];
                ans+=hero[i];
            }
            else{
                ans+=enemy[i]+enemy[i+1];
                enemy[i+1]=0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
  int n, k;
  scanf("%d %d", &n, &k);
  int d[200];
  int flag[200] = {0};
  int a[200][200] = {0};
  int count = 0;

  for (int i = 0; i < k; i++)
  {
    scanf("%d", &d[i]);
    for (int j = 1; j <= d[i]; j++)
    {
      scanf("%d", &a[i][j]);
    }
  }

  for (int i = 0; i < k; i++)
  {
    for (int j = 1; j <= d[i]; j++)
    {
      if (a[i][j] != 0)
      {
        flag[a[i][j]] = 1;
      }
    }
  }

  for (int i = 1; i <= n; i++)
  {
    if (flag[i] == 0)
    {
      count++;
    }
  }


  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 1864
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;int a=0;cin>>s;
  for(int i=0;i<(s.size()-s.size()%2)/2;i++){
    if(s.at(i)!=s.at(s.size()-i-1))a++;
  }
  cout << a<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int C[505][505],f[505][505],s[505][505],n,k,mods;
int upd(int x,int y){ return x+y>=mods?x+y-mods:x+y; }
int main()
{
	n=read(),k=read(),mods=read();
	for (int i=0;i<=n;i++) C[i][i]=C[i][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<i;j++) C[i][j]=upd(C[i-1][j-1],C[i-1][j]);
	for (int i=0;i<=k;i++) f[1][i]=1,s[1][i]=i+1;
	for (int i=2;i<=n+1;i++)
		for (int j=0;j<=k;j++)
		{
			for (int x=1;x<i;x++) 
				f[i][j]=upd(f[i][j],1ll*upd(s[x][k],mods-s[x][j])*f[i-x][j]%mods*C[i-2][x-1]%mods);
			s[i][j]=(!j)?0:upd(s[i][j-1],f[i][j]);
		}
	printf("%d\n",f[n+1][0]);
	return 0;
}


Measured memory_bytes: 2048
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
# n = int(input())
N, K = map(int, input().split())
V = list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res


res = 0
for k in range(K+1):
    for l in range(k+1):
        pos = 0
        neg = []
        for i in range(min(l, N)):
            if i >= N:
                break
            if V[i] >= 0:
                pos += V[i]
            else:
                neg.append(V[i])

        for i in range(min(k-l, N-l)):
            if i >= N:
                break
            v = V[N-i-1]
            if v >= 0:
                pos += v
            else:
                neg.append(v)

        # print(pos)

        for i, v in enumerate(sorted(neg)):
            if i < K-k:
                continue
            pos += v
        res = max(res, pos)

print(res)


Measured memory_bytes: 14528
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

struct UnionFind{
	////https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396
	
	//parent[i]: iの親の番号
	//例: parent[3] = 2: 3の親は2
	vector<int> parent;

	UnionFind(int N) : parent(N){
		//初期化は自分自身が親とする
		for(int i=0; i<N; i++) parent[i] = i;
	}

	int root(int x){
		if(parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}

	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		parent[rx] = ry;//rxの親をryの親にする
	}
	bool same(int x, int y){ return root(x) == root(y);}
};

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> p(N);
	for(int i=0; i<N; i++) cin >> p[i];
	for(int i=0; i<N; i++) p[i]--;
	UnionFind tree(N);
	for(int i=0; i<M; i++){
		int x, y;
		cin >> x >> y;
		x--; y--;
		tree.unite(x, y);
	}

	int ans = 0;
	for(int i=0; i<N; i++){
		if(tree.same(i, p[i])) ans++;
		else if(p[i] == i) ans++;
		// cout << " i: " << i << " p[" << i << "]: " << p[i] << " ans: " << ans << endl;
	}
	cout << ans << endl;

	return 0;
}



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

ll calc(vector<ll> &sum,int L,int R) { // [L,R]
  ll ret = sum[R];
  if( L - 1 >= 0 ) ret = ret - sum[L-1];
  return ret;
}

int main() {
  int n,k;
  cin >> n >> k;
  vector<ll> a(n),sum(n,0),psum(n,0);
  rep(i,n) cin >> a[i];
  ll p_all = 0;
  rep(i,n) {
    if( i ) {
      sum[i] = sum[i-1];
      psum[i] = psum[i-1];
    }
    sum[i] += a[i];
    if( a[i] > 0 ) psum[i] += a[i], p_all += a[i];
  }
  ll maxi = 0;
  rep(i,n-k+1) {
    ll score = p_all - calc(psum,i,i+k-1);
    maxi = max(maxi,score);
    maxi = max(maxi,score+calc(sum,i,i+k-1));
  }
  cout << maxi << endl;
  compute();
  return 0;
}


Measured memory_bytes: 2560
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<ll> L(N);
    vector<ll> cnt(3010), sum(3010);
    for(int i=0; i<N; i++) {
        cin >> L[i];
        cnt[ L[i] ]++;
        sum[ L[i] ]++;
    }
    sort(L.begin(), L.end());

    ll ans = 0;
    for(int i=1; i<3010; i++) sum[i] += sum[i-1];

    const int M = 1000;

    // 全部同じ場合
    for(int i=1; i<=M; i++) {
        ans += cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 6;
    }

    // a = b < c の場合
    for(int i=1; i<=M; i++) {
        int a = i, b = i;
        int mi = max({a-b, b-a, a-1, b-1});
        int ma = a + b - 1;
        if(mi >= ma) continue;
        ll add = (sum[ma] - sum[mi]);
        if(mi < a and a <= ma) add -= cnt[a];
        ans += add * cnt[i] * (cnt[i] - 1) / 2;
    }

    // a < b <= c の場合
    for(int i=1; i<=M; i++) {
        for(int j=i+1; j<=M; j++) {
            // a < b <= c
            // (mi, ma]
            int a = i, b = j;
            int mi = max({a-b, b-a, a-1, b-1});
            int ma = a + b - 1;

            if(mi >= ma) continue;
            ll add = (sum[ma] - sum[mi]);
            // b = c の場合
            if(mi < b and b <= ma) {
                // b を抜いたもの (unique)
                add -= cnt[b];
                ans += add * cnt[a] * cnt[b];

                // a < b = c
                ans += cnt[a] * cnt[b] * (cnt[b] - 1) / 2;
            }
            else {
                // a < b < c
                ans += add * cnt[a] * cnt[b];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        int cnt = 0;

        int n = scan.nextInt();
        int k = scan.nextInt();
        
        Map<Integer, Integer> m = new HashMap<Integer, Integer>();
        for(int i=0; i<n; i++){
            int a = scan.nextInt();
            if(m.containsKey(a)){
                int v = m.get(a);
                m.put(a, ++v);
            }else{
                m.put(a, 1);
            }
        }
        List<Integer> list = new ArrayList<>(m.values());
        Collections.sort(list);
            
        for(int i=0; i<list.size()-k; i++){
            cnt += list.get(i);
        }
        
        scan.close();
        System.out.println(cnt);
    }
}

Measured memory_bytes: 100544
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int C = sc.nextInt();
        final int X = sc.nextInt();

        int ans = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                for (int k = 0; k <= C; k++) {
                    if (X == (i * 500 + j * 100 + k * 50)) ans++;
                }
            }
        }

        System.out.println(ans);
    }
}


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

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  long x;
  if (N % (A + B) >= A) x = A;
  else x = N % (A + B);
  cout << N / (A + B) * A + x << endl;
}


Measured memory_bytes: 256
def solve(edges,values):
    stack = [1]
    visited = set()
    while stack:
        curr = stack.pop()
        if curr not in visited:
            visited.add(curr)
            for kid in edges[curr]:
                if kid not in visited:
                    values[kid-1] += values[curr-1]
                    stack.append(kid)

    for i in values:
        print(i,end = ' ')

def main():
    n,q = map(int,input().split())
    edges = {}
    for i in range(1,n+1):
        edges[i] = []

    for i in range(n-1):
        a,b = map(int,input().split())
        edges[a].append(b)
        edges[b].append(a)

    values = [0]*n

    for i in range(q):
        p,x = map(int,input().split())
        values[p-1] += x

    solve(edges,values)


main()


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N, K;

  while(cin >> N >> K){
    vector<int> count(N);

    REP(i,K){
      int d; cin >> d;
      REP(j,d){
        int a; cin >> a;
        count[a-1] += 1;
      }
    }

    int ans = 0;
    REP(i,N) if(count[i] == 0) ans++;

    pout(ans);
  }


  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	vvector<int> ans(n, vector<int>(n, 0));
	rep(i, n){
		int t;
		cin >> t;
		--t;
		int time;
		cin >> time;
		rep(j, time){
			int to;
			cin >> to;
			--to;
			ans[t][to] = 1;
		}
	}

	foreach(i, ans){
		foreach(j, i){
			output(j);
		}
		outendl();
	}
	return 0;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define N 15000001

int main()
{
   string s;
   cin>>s;
    ll n = s.size();
   s='a'+s;
   ll left[n+1],right[n+1];
   
   
   for(ll i=1;i<=n;i++)
   {
        left[i]=INT_MAX;
        right[i]=0;
        if(s[i]=='L')   left[i]=i;
        else            right[i]=i;
   }
   for(int i=n-1;i>=1;i--)
   {
        left[i]=min(left[i],left[i+1]);
   }
   for(int i=2;i<=n;i++)
   {
        right[i]=max(right[i],right[i-1]);
   }
   ll ans[n+1]={0};
  for(ll i=1;i<=n;i++)
   {
        if(s[i] == 'L')
        {
             if((i-right[i])%2)
             {
                  ans[right[i]+1]++;
             }
             else
             {
                  ans[right[i]]++;
             }
        }
        else
        {
             if((left[i]-i)%2)
             {
                  ans[left[i]-1]++;
             }
             else
             {
                  ans[left[i]]++;
             }
        }
   }
   for(ll i=1;i<=n;i++)   cout<<ans[i]<<" ";
}

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

int main()
{
	int n, x;
	
	scanf("%d", &n);
	int ans = 64;
	while (n--) {
		scanf("%d", &x);
		int tmp = 0;
		while (x % 2 == 0) {
			tmp++;
			x /= 2;
		} 
		ans = min(ans, tmp);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2]; //番兵を含めると、要素数が増える
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i=0; i<n1; i++) L[i] = A[left + i];
    for(int i=0; i<n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for(int k=left; k<right; k++){
        cnt++;
        if(L[i] <= R[j]){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right){
    if (left+1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right); //再帰された分だけ、mergeされる
    }
}

int main(){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for(i=0; i<n; i++) cin >> A[i];

    mergeSort(A, n, 0, n);

    for(i=0; i<n; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define MAXAS(x,v) x = max(x,v)

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

#define PI 3.141592653589793

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a <= c && c <= b ? "Yes" : "No") << endl;
}


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

#define for_(i,a,b) for(int i=a; i<b; ++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

int n, a[110][110];
int sum[110][110];

void solve() {
	for_(i,0,n) {
		for_(j,0,n) {
			sum[i][j] = a[i][j];
			if (i > 0) sum[i][j] += sum[i - 1][j];
			if (j > 0) sum[i][j] += sum[i][j - 1];
			if (i > 0 && j > 0) sum[i][j] -= sum[i - 1][j - 1];
		}
	}
	
	int ans = (-1) * (int)1e9;
	for_(i,0,n) for_(j,0,n) {
		ans = max(ans, sum[i][j]);		
		
		for_(k,0,i + 1) for_(l,0,j + 1) {
			int sump = sum[i][j];
			if (k < i) sump -= sum[k][j];
			if (l < j) sump -= sum[i][l];
			if (k < i && l < j) sump += sum[k][l];
			ans = max(ans, sump);
		}
	}
	
	cout << ans << endl;
}

int main() {
	cin >> n;
	for_(i,0,n) for_(j,0,n) cin >> a[i][j];
	solve();
	return 0;
}

Measured memory_bytes: 1252
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-05 21:08:19
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  int64 x, y; cin >> x >> y;

  string s1 = "Alice", s2 = "Brown";

  if (x + y <= 1) {
    cout << s2 << endl;
    return 0;
  }

  if (abs(x - y) <= 1) {
    cout << s2 << endl;
  } else {
    cout << s1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"
import "math/big"

var (
	n, x int64
)

func solve(a, b int64) int64 {
	if a == 0 || b == 0 {
		return 0
	}
	if a > b {
		return solve(a%b, b) + b*(a/b)*2
	} else {
		return solve(a, b%a) + a*(b/a)*2
	}
}

func main() {
	fmt.Scan(&n, &x)
	ret := big.NewInt(0)
	ret.GCD(nil, nil, big.NewInt(n), big.NewInt(x))
	fmt.Println(n - ret.Int64() + solve(x, n-x))
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll cnt=0;
    while(n>=25){
        n-=25;
        cnt++;
    }
    while(n>=10){
        n-=10;
        cnt++;
    }
    while(n>=5){
        n-=5;
        cnt++;
    }
    while(n>=1){
        n-=1;
        cnt++;
    }
    cout<<cnt<<endl;
}


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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    int t; 
    cin >> t;
    if(t%1000==0) cout << 0;
    else cout << (1000*((t/1000)+1))-t;
    return 0;
} 

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll A[100][100];
ll B[100][100];
ll C[100][100];
ll H, W;

ll dp[85][85][6500];

int main(){

    cin >> H >> W;
    rep1(y, H)rep1(x, W)cin >> A[y][x];
    rep1(y, H)rep1(x, W)cin >> B[y][x];
    rep1(y, H)rep1(x, W)C[y][x] = abs(A[y][x] - B[y][x]);

    dp[1][1][0] = 1;
    rep1(y, H)rep1(x, W)rep(i, 6500)if(dp[y][x][i]){
        if(i + C[y][x] < 6500)dp[y + 1][x][i + C[y][x]] = dp[y][x + 1][i + C[y][x]] = 1;
        if(i - C[y][x] < 0)dp[y + 1][x][C[y][x] - i] = dp[y][x + 1][C[y][x] - i] = 1;
        else dp[y + 1][x][i - C[y][x]] = dp[y][x + 1][i - C[y][x]] = 1;
    }
    rep(i, 6500)if(dp[H + 1][W][i]){
        cout << i << endl;
        break;
    }
    return 0;
}

Measured memory_bytes: 350592
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	a,b,c,d = map(int,input().split())
	print(max(a*b,c*d))
	

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


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

 int main() {
   int N;
   cin >> N;
   
   if(N < 1000){
     cout << "ABC" << endl;
   }else if(N >= 1000 && N <= 1998){
     cout << "ABD" << endl;
   }
   
 }

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int nNode;
int nEdge;

struct E {
  int a, b, c;
};

E es[1010];

int g[101][101];

const int INF = 1000000;

int main(void) {
  scanf("%d%d", &nNode, &nEdge);
  REP(i, nNode) REP(j, nNode) {
    g[i][j] = (i == j ? 0 : INF);
  }
  REP(i, nEdge) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a;
    --b;
    es[i] = (E){a, b, c};
    g[a][b] = g[b][a] = c;
  }
  REP(k, nNode) REP(i, nNode) REP(j, nNode)
    g[i][j] = min(g[i][k]+g[k][j], g[i][j]);
  // REP(i, nNode) {
  //   REP(j, nNode) {
  //     cerr << g[i][j] << " ";
  //   }
  //   cerr << endl;
  // }
  
  int res = nEdge;
  REP(iEdge, nEdge) {
    int a = es[iEdge].a;
    int b = es[iEdge].b;
    int c = es[iEdge].c;
    REP(i, nNode) REP(j, nNode) {
      if(g[i][j] == g[i][a]+g[j][b]+c || g[i][j] == g[j][a]+g[i][b]+c) {
        // cerr << "es[" << iEdge << "] for " << i << " to " << j << endl;
        --res;
        goto HOGE;
      }
    }
  HOGE:
    ;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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


int main(){
  ll N;cin>>N;
  vector<ll> a(N);

  rep(i,N) cin>>a[i];


  ll ans = a[0];
  rep(i,N){
    ans = gcd(a[i],ans);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, C;
  cin >> N >> C;
  vector<vector<bool>> ST(C, vector<bool>(1e5 + 1, false));
  rep(i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    --c;
    for (int j = s; j <= t; ++j) ST[c][j] = true;
  }

  int answer = 0;
  rep(t, 1e5) {
    int cnt = 0;
    rep(i, C) {
      if (ST[i][t]) ++cnt;
    }
    answer = max(answer, cnt);
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3740
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
const int MAX_V=100000;
const int INF=1000000000;
int V,E;
struct edge {int to, cost;};
typedef pair<int,int> P;
vector<edge> G[MAX_V];
int d[MAX_V];
void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P> >que;
  fill(d,d+V,INF);
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p=que.top();
    que.pop();
    //p????????????d[x]??§?????¢??§????????????????????????
    int v=p.second;
    //????????????????????§?????????????????????????????°?????????????¬?????¶????
    if(d[v] < p.first)continue;
    //G[X]???????????°?????§?§????????????????
    for(int i=0;i < G[v].size();i++){
      edge e=G[v][i];
      //d[e.to]????????¢??¨????????????????¨???¶??????????????????
      //???????????????d??????????????????????????????
      //?????????pair??§?????¢??¨??????????????¨?¨???????????????§priority_queue??????????????????
      //????????¨??????????????¶??¨????????\??????
      if(d[e.to] > d[v]+e.cost){
    d[e.to] = d[v] + e.cost;
    que.push(P(d[e.to],e.to));
      }
    }
  }
}
int main(){
  int r;
  int s,t,c;
  scanf("%d %d %d",&V,&E,&r);
  for(int i=0;i<E;i++){
    scanf("%d %d %d",&s,&t,&c);
    edge e;
    e.to=t;e.cost=c;
    G[s].push_back(e);
  }
  dijkstra(r);
  for(int i=0;i<V;i++){
    if(d[i]==INF)printf("INF\n");
    else printf("%d\n",d[i]);
  }
  return 0;
}

Measured memory_bytes: 12584
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	set<ll> a;
	for (ll i = 0; i < n; i++)
	{
		ll q, x;
		cin >> q >> x;

		switch (q)
		{
			case 0:
				a.insert(x);
				println(a.size());
				break;

			case 1:
				if (a.count(x))
				{
					println(1);
				}
				else
				{
					println(0);
				}
				break;

			case 2:
				a.erase(x);
				break;
		}
	}

}




Measured memory_bytes: 12360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e3+5;
const int mod=1e9+7;
ll dp[maxn][maxn];
struct ac
{
    ll p,v;
};
ac a[maxn];
bool cmp(ac a,ac b)
{
    return a.v>b.v;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].v;
        a[i].p=i;
    }
    sort(a+1,a+1+n,cmp);
    ll ans=-1;
    for(int la=1;la<n;la++) //已放置到第几个数
    {
        for(int s=0;s<=la;s++)
        {
            int j=n-la+s;
            int i=s+1;
            if(j+1<=n)
            dp[i][j]=max(dp[i][j],dp[i][j+1]+a[la].v*abs(j+1-a[la].p));
            if(i-1>=1)
            dp[i][j]=max(dp[i][j],dp[i-1][j]+a[la].v*abs(a[la].p-(i-1)));
        }
    }
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,dp[i][i]+a[n].v*abs(a[n].p-i));
    }
    cout<<ans<<'\n';


}


Measured memory_bytes: 26276
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

int h[100000];
int main() {
    int n, k, q, a;
    cin >> n >> k >> q;

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

    for(int i=0; i<q; i++) {
        cin >> a;
        h[a-1]++;
    }

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


Measured memory_bytes: 1024