akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  if (k == 1) {
    cout << 0 << '\n';
    return 0;
  }
  cout << n - k << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int cost_function(int val1,int val2){
	int val = val1-val2;
	return val*val;
}
int main() {
	int n; cin>>n;
	int a[n+2];
	bool allEq = true;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		if(!allEq) continue;
		if(i>0){
			if(a[i]!=a[i-1]) allEq = false;
		}
	}
	
	if(allEq) {
		printf("0\n"); return 0;
	}
	
	int minTotalCost = INT_MAX;
	for(int num = -100; num<=100;num++){
		int cost = 0;
		for(int i=0;i<n;i++) cost+=cost_function(num,a[i]);
		minTotalCost = min(minTotalCost, cost);
	}
	printf("%d\n", minTotalCost);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 105;
const ll LINF = 1e18 + 5;
int k;
string s;
ll dp[N][4];
ll dfs(int pos, int lead, int limit, int state) 
{
	if(pos==-1) return !state;
	if(!limit&&!lead&&~dp[pos][state]) return dp[pos][state];
	int up = limit ? s[pos]-'0' : 9;
	ll ans = 0;
	for(int i=0;i<=up;i++)
	{
		if(i&&state) ans += dfs(pos-1, 0, limit&&i==s[pos]-'0', state-1);
		else if(i==0) ans += dfs(pos-1, lead, limit&&i==s[pos]-'0', state);
	}
	if(!limit&&!lead) dp[pos][state] = ans;
	return ans;	
}
ll solve() 
{
	memset(dp, -1, sizeof(dp)); 
	reverse(all(s));
	int pos = sz(s);
	return dfs(pos-1, 1, 1, k);
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> s >> k;
 	cout << solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 100005;

int n;
vector <ii> neigh[Maxn];
int K;
int res[Maxn];

void Solve(int v, int p, int c)
{
    K = max(K, int(neigh[v].size()));
    int pnt = 1;
    for (int i = 0; i < neigh[v].size(); i++) {
        ii u = neigh[v][i];
        if (u.first == p) continue;
        if (pnt == c) pnt++;
        res[u.second] = pnt++;
        Solve(u.first, v, res[u.second]);
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(ii(b, i));
        neigh[b].push_back(ii(a, i));
    }
    Solve(1, 0, 0);
    printf("%d\n", K);
    for (int i = 0; i < n - 1; i++)
        printf("%d\n", res[i]);
    return 0;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n, k;
  string s;
  cin >> n >> s >> k;
  for (i64 i = 0; i < n; i++)
    if (s[i] != s[k - 1])
      s[i] = '*';
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
x,y,a,b,c=LI()
p=sorted(LI())[-x:]
q=sorted(LI())[-y:]
r=LI()+p+q

print(sum(sorted(r)[-x-y:]))

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

#define fi first
#define se second
#define pb push_back
#define v(T) vector<T>
#define vv(T) v(v(T))
#define sz(x) x.size()

#define times(i,n) for(int i = 0; i < n; ++i)
#define rep(i,l,r) for(auto i = l; i < r; ++i)
#define upto(i,l,r) for(auto i = l; i <= r; ++i)
#define downto(i,l,r) for(auto i = l; i >= r; --i)
#define step(i,l,r,s) for(auto i = l; i <= r; i += s)

typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef v(int) vi;
typedef vv(int) vvi;
typedef v(ll) vl;
typedef v(P) vp;
typedef v(T) vt;

template<typename T>istream& operator>>(istream& i, v(T)& v)
    {times(j, sz(v)) i >> v[j]; return i;}
template<typename T>string join(const v(T)& v, const char sep = ' ')
    {stringstream s; times(i, sz(v)) s << sep << v[i]; return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream& o, const v(T)& v)
    {if(sz(v))o << join(v); return o;}

#include <atcoder/all>
using namespace atcoder;

const ll M = 998'244'353;
const ll L = pow_mod(9, M - 2, M);

struct S {
    ll num;
    int x;
};

S op(S s1, S s2) {
    return S{(s1.num * pow_mod(10, s2.x, M) + s2.num) % M, s1.x + s2.x};
}

S e() {return S{0, 0};}

struct F {
    int n, i;
};

S mapping(F f, S s) {
    if (f.n == -1) return s;
    ll a = (pow_mod(10, s.x, M) - 1) * L % M;
    return S{a * f.n % M, s.x};
}

F composition(F f1, F f2) {return f1.i > f2.i ? f1 : f2;}

F id() {return F{-1, -1};}

int main() {
    int n, q;
    cin >> n >> q;
    v(S) a(n);
    times(i, n) a[i] = S{1, 1};
    lazy_segtree<S, op, e, F, mapping, composition, id> lseg(a);

    times(i, q) {
        int l, r, d;
        cin >> l >> r >> d;
        lseg.apply(l - 1, r, F{d, i});
        cout << lseg.all_prod().num << endl;
    }
}


Measured memory_bytes: 16724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;
using MIte = multimap<vector<char>, int>::iterator;

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

	vector<vector<int> > vvCod;
	for (int i = 0; i != N; ++i) {
		vector<int> vCod(D);
		for (int j = 0; j != D; ++j) {
			cin >> vCod[j];
		}
		vvCod.push_back(vCod);
	}

	int distmax = 40 * 40 * D;
	set<int> possibledist;
	for (int i = 1; i*i <= distmax; ++i) {
		possibledist.insert(i * i);
	}

	int cnt = 0;
	for (int i = 0; i != N-1; ++i) {
		for (int j = i; j != N; ++j) {
			int dist = 0;
			for (int k = 0; k != D; ++k) {
				dist += (vvCod[i][k] - vvCod[j][k]) * (vvCod[i][k] - vvCod[j][k]);
			}

			set<int>::iterator it = possibledist.find(dist);
			if (it != possibledist.end()) {
				++cnt;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
n,k=map(int,input().split())
a=list(map(int,input().split()))
b,c=0,0
mod=10**9+7
for i in range(n):
    for j in range(i+1,n):
        if a[i]>a[j]:
            b+=1
    for j in range(i):
        if a[i]>a[j]:
            c+=1

print((b*k*(k+1)//2+c*(k-1)*k//2)%mod)

Measured memory_bytes: 42348
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int ans = S.length();
  
  int change1 = 0;
  int change2 = 0;
  for (int i = 0; i < S.length(); i++) {
    char c1 = (i%2)==0?'0':'1';
    char c2 = (i%2)==0?'1':'0';
    if (c1!=S[i]) change1++;
    if (c2!=S[i]) change2++;
  }
  ans = min(ans, change1);
  ans = min(ans, change2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
require 'matrix'
n, m = gets.split.map(&:to_i)

a =
n.times.inject([]) do |m, o|
  m << gets.split.map(&:to_i)
end

b =
m.times.inject([]) do |m, o|
  m << gets.to_i
end

ma = Matrix[*a]
mb = Matrix.column_vector(b)

mc = ma * mb

mc.each do |e|
  puts e
end

Measured memory_bytes: 6992
def solve(a, v, b, w, t):
    return "YES" if 0 < (v-w) and abs(b-a) / (v-w) <= t else "NO"

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
print(solve(a, v, b, w, t))

Measured memory_bytes: 9180
#include <stdio.h>

int main()
{
	int takasa[10];
	int n = 10;
	int i = 0;
	int j;

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

	while(i < n-1){
		if(takasa[i] > takasa[i+1]){
			int tmp = takasa[i];
			takasa[i] = takasa[i+1];
			takasa[i+1] = tmp;
			i = 0;
		}
		else i++;
	}

	printf("%d\n",takasa[9]);
	printf("%d\n",takasa[8]);
	printf("%d\n",takasa[7]);

	return 0;
}

Measured memory_bytes: 600
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;
  
  int x, k;
  rd(x); rd(k);
  auto r=readln.split.to!(int[]);
  int q; rd(q);
  Tuple!(int, int)[] qs;
  foreach(_; 0..q){
    int t, a; rd(t, a);
    qs~=tuple(t, a);
  }

  alias Q=Tuple!(int, "t", int, "a");
  Q[] queries;
  foreach(t; r) queries~=Q(t, -1);
  foreach(e; qs) queries~=Q(e[0], e[1]);
  sort(queries);

  int l=0, u=x;
  int j=0, p=0;
  int d=0, f=-1;
  foreach(e; queries){
    int dd=(e.t-p)*f;
    u=min(x, max(0, u+dd));
    l=max(0, min(x, l+dd));
    d+=dd; p=e.t;
    if(e.a==-1){
      f*=-1;
    }else{
      int y=e.a+d;
      writeln(min(u, max(l, y)));
    }
  }


}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 6324
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    if N % K > 0:
        print(1)
    else:
        print(0)

main()



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

struct UF {
	UL N; vector<UL> V;
	void init(UL n) {
		N = n; V.resize(N);
		rep(i, N) V[i] = i;
	}
	UL root(UL a) {
		if (V[a] == a) return a;
		return V[a] = root(V[a]);
	}
	void unite(UL r, UL s) {
		V[root(s)] = root(r);
	}
};

UL N, M;
UL V[100000];
deque<UL> E[100000];
UF Q;
UL F[100000] = {};
vector<UL> dp[100000];

void unite(UL r, UL s) {
	if (E[r].size() < E[s].size()) {
		swap(E[r], E[s]);
		for (auto i = E[s].rbegin(); i != E[s].rend(); i++)
			E[r].push_front(*i);
	}
	else {
		for (auto i = E[s].begin(); i != E[s].end(); i++)
			E[r].push_back(*i);
	}
	E[s].clear();
	Q.unite(r, s);
	V[r] += V[s]; V[s] = 0;
}

bool DFS(UL p, UL pre = ~0u) {
	F[p] |= 3u;
	rep(i, E[p].size()) {
		UL e = Q.root(E[p][i]);
		if (e == pre) continue;
		if (p == e) continue;
		if (F[e] & 2u) {
			unite(e, p);
			F[p] &= ~2u;
			return true;
		}
		bool res = DFS(e, p);
		e = Q.root(e);
		if (p == e) res = false;
		if (res) {
			unite(e, p);
			F[p] &= ~2u;
			return true;
		}
	}
	F[p] &= ~2u;
	return false;
}

UL DFS2(UL p, UL pre = ~0u) {
	UL ans = 0;
	for (UL e : E[p]) if(e != pre) ans = max(ans, DFS2(e, p));
	sort(dp[p].rbegin(), dp[p].rend());
	UL tmp = (dp[p].size() >= 1) ? dp[p][0] : 0;
	tmp += V[p];
	if (pre != ~0u) dp[pre].push_back(tmp);
	tmp += (dp[p].size() >= 2) ? dp[p][1] : 0;
	return max(ans, tmp);
}

int main() {
	scanf("%u%u", &N, &M);
	rep(i, N) scanf("%u", &V[i]);
	rep(i, M) {
		UL u, v; scanf("%u%u", &u, &v); u--; v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	Q.init(N);

	DFS(0);

	rep(i, N) {
		rep(j, E[i].size()) {
			UL& e = E[i][j];
			e = Q.root(e);
			if (e == i) {
				swap(e, E[i].back());
				E[i].pop_back();
				j--;
			}
		}
		sort(E[i].begin(), E[i].end());
		E[i].erase(unique(E[i].begin(), E[i].end()), E[i].end());
	}

	UL S = 0;
	rep(i, N)if (V[i]) { S = i; break; }
	cout << DFS2(S) << endl;

	return 0;
}



Measured memory_bytes: 90680
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
	NodePointer x;
	x = nil;
	while( x->next != nil){
		if(x->next->key == key){
		return x->next;
		break;}
		x = x->next;
	}
	return NULL;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
	NodePointer x;
	x =nil->prev;
	deleteNode(x);
}

void delete(int key){
  NodePointer x;
	x = listSearch(key);
	
	if(x != NULL){
		deleteNode(x);
	}
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
	x->next = nil->next;
	x->prev =nil;
	nil->next-> prev = x;
	nil->next= x;
	


}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 32952
n = int(input())

cards = [[False for i in range(1, 14)] for j in range(4)]

for _ in range(n):
    mark, num = input().split()
    if mark == "S":
        cards[0][int(num) - 1] = True
    elif mark == "H":
        cards[1][int(num) - 1] = True
    elif mark == "C":
        cards[2][int(num) - 1] = True
    elif mark == "D":
        cards[3][int(num) - 1] = True

for i, row in enumerate(cards):
    if i == 0:
        mark = "S"
    if i == 1:
        mark = "H"
    if i == 2:
        mark = "C"
    if i == 3:
        mark = "D"
    for i, num in enumerate(row):
        if not num:
            print("{} {}".format(mark, i+1))



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,s;cin >> n >> s;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<ll> dp(s+1);
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=s-1;j>=0;j--){
            if(j+a[i]<=s){
                (dp[j+a[i]]+=dp[j])%=MOD;
            }
        }
        if(a[i]<=s){
            dp[a[i]]+=i+1;
        }
        (ans+=dp[s])%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

#define pb push_back

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N, C;
int s[100000];
int t[100000];
int c[100000];
int tt[200002];
int sm[200002];

int main(int argc, char* argv[])
{
	scanf("%d%d", &N, &C);
	for (int i = 0; i < N; i++) {
		scanf("%d%d%d", &s[i], &t[i], &c[i]);
	}

	for (int i = 1; i <= C; i++) {
		memset(tt, 0, sizeof(tt));
		for (int j = 0; j < N; j++) {
			if (c[j] != i) continue;
			tt[s[j] * 2 - 1]++;
			tt[t[j] * 2]--;
		}
		for (int j = 1; j < 200002; j++) {
			tt[j] += tt[j - 1];
		}
		for (int j = 0; j < 200002; j++) {
			sm[j] += min(1, tt[j]);
		}
	}
	int ans = 0;
	for (int i = 0; i < 200002; i++) {
		ans = max(ans, sm[i]);
	}
	printf("%d\n", ans);

	return 0;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll lr[510][510], sum[510][510];


int main(int argc, char **argv)
{
	ll N, M, Q; cin >> N >> M >> Q;
	REP(i, M)
	{
		ll l, r; cin >> l >> r;
		--l, --r;
		++lr[l][r];
	}

	REP(i, N)
	{
		for (ll j = 1; j <= N; ++j)
			sum[i][j] = sum[i][j-1] + lr[i][j-1];
	}

	REP(i, Q)
	{
		ll l, r; cin >> l >> r;
		--l, --r;
		ll res{0};
		for (ll i = l; i <= r; ++i)
			res += sum[i][r+1] - sum[i][l];
		std::cout << res << std::endl;
	}
}



Measured memory_bytes: 4864
#include<bits/stdc++.h>
     
    #define int long long
    #define ll long long
    #define F first 
    #define S second 
    #define pb push_back
    #define ld long double
     
    using namespace std ; 
     
    const int MAXN = 101 * 1001 , MOD =  1e9 + 7 ;
     
    int col[MAXN][12] ; 
     
    int d[MAXN][12] ; 
     
    vector<int> adj[MAXN] ; 
     
    int a[MAXN] , D[MAXN] , c[MAXN] ;
     
    int32_t main()
    {
    	ios::sync_with_stdio(0) ;
    	int n , m ; 
    	cin >> n >> m ;
    	for(int i = 0 ; i < m ; i ++ ) 
    	{
    		int x , y ;
    		cin >> x >> y ;
    		adj[x].pb(y) ; 
    		adj[y].pb(x) ; 
    	}
    	int q ; 
    	cin >> q ;
    	for(int i = 0 ; i < q ; i ++ ) 
    		cin >> a[i] >> D[i] >> c[i] ; 
    	for(int i = q - 1 ; i > -1 ; i -- )
    	{
    		queue<pair<int,int>> q ; 
    		q.push({a[i],D[i]}) ; 
    		while(q.size())
    		{
    			int x = q.front().F ; 
    			int y = q.front().S ; 
    			q.pop() ; 
    			for(int j = 0 ; j <= y ; j ++ ) 
    				if(!col[x][j])
    					col[x][j] = c[i] ; 
    			if(!y) continue ; 
    			for(auto u : adj[x])
    			{	
    				if(!col[u][y-1])
    				{
    					col[u][y-1] = c[i] ; 
    					q.push({u,y-1}) ; 
    				}
    			}
    		
    		}
    	}
    	for(int i = 1 ; i <= n ; i ++ ) cout << col[i][0] << '\n' ; 
    }

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

using namespace std;

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;

int grid[1005][1005], m, n, mo[2][2], dx[] = {0, 1, 1, 0}, dy[] = {0, 0, 1, 1};

inline int get(char t) {
  switch (t) {
    case 'J':
      return 1;
    case 'O':
      return 2;
    case 'I':
      return 3;
  }
}


signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> m >> n;
  for (int y = 1; y <= m; ++y) {
    string t;
    cin >> t;
    for (int x = 1; x <= n; ++x) {
      grid[x][y] = get(t[x - 1]);
    }
  }

  for (int y = 0; y < 2; ++y) {
    string t;
    cin >> t;
    for (int x = 0; x < 2; ++x) {
      mo[x][y] = get(t[x]);
    }
  }

  int base = 0, addi = 0;

  for (int y = 1; y <= m; ++y) {
    for (int x = 1; x <= n; ++x) {
      {
        bool flg = true;
        for (int j = 0; j < 4; ++j) {
          flg = flg && grid[x + dx[j]][y + dy[j]] == mo[dx[j]][dy[j]];
          if (!flg) break;
        }
        if (flg) base++;
      }

      int pre = grid[x][y], tmax = 0;
      for (int i = 1; i <= 3; ++i) {
        if (pre == i) continue;
        grid[x][y] = i;
        int temp = 0;

        for (int j = 0; j < 4; ++j) {
          bool flg = true;
          for (int k = 0; k < 4; ++k) {
            flg = flg && grid[x + dx[k] - dx[j]][y + dy[k] - dy[j]] == mo[dx[k]][dy[k]];
            if (!flg) break;
          }
          if (!flg) continue;

          temp++;
        }

        tmax = max(tmax, temp);
      }
      grid[x][y] = pre;

      addi = max(tmax, addi);
    }
  }

  cout << base + addi << endl;

  return 0;
}

Measured memory_bytes: 9068
#include <stdio.h>
 
int ketasu(int num)
{
        int a = 0;
        while(num > 0) {
                num /= 10;
                a++;
        }
        return a;
}
 
int main()
{
        int a,b;
        while(scanf("%d %d",&a,&b) != EOF) {
                printf("%d\n",ketasu(a+b));
        }
        return 0;
}

Measured memory_bytes: 596
o,x,b;
main(a){
  for(scanf("%d");~scanf("%s",&a)&&(a%=9);o=o==3?b=x=!printf("%d\n",x):o){
    for(a-8?b=b*2+1,x+=b>>3&1,b&=7:o++;a<7&&b;b/=2)x+=b&1;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int main() {
	int n;
	cin >> n;
	vector<int>A(n);
	rep(i, n) {
		cin >> A[i];
	}
	bool flag = true;
	rep(i, n) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 != 0 && A[i] % 5 != 0) {
				flag = false;
			}
		}
	}
	if (flag)puts("APPROVED");
	else puts("DENIED");
	return 0;
}


Measured memory_bytes: 256
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


H,W = map(int, input().split())
num_w = -1
srch = []
for i in range(H):
  h = list(str(sys.stdin.readline().rstrip()))
  for j in range(W):
    if h[j] == ".":
      srch.append([i+1,j+1])
      num_w += 1

Cn = [[sys.maxsize for j in range(W+2)] for i in range(H+2)]
Cn[1][1] = 0
for _ in range(num_w):
  for i,j in srch[1:]:
    Cn[i][j] = min(Cn[i-1][j],Cn[i][j-1],Cn[i+1][j],Cn[i][j+1])+1

if Cn[H][W] < sys.maxsize:
  print(num_w - Cn[H][W])
else:
  print(-1)


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

int sum_digit(string str)//??°?????????????????????????????¢??°
{
	int sum = 0;//?????????????¨?
	
	int len = str.length();
	
	for(int i = 0; i < len; i++){
		sum += str[i] - '0';
	}
	return sum;
}
int main(void)
{
	string str;
	
	while(true){
	
		getline(cin, str);//????????????????????????
		
		if(str == "0"){
			break;
		}
		
		cout << sum_digit(str) <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3136
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,a[101],sum=0;
	cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n;i>n-k;i--)sum+=a[i];
    cout<<sum<<endl;
}

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

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

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include<set>
#define ll long long 
using namespace std;

int main()
{
	ll int n,i,j,k,c=0,nr=0,ng=0,nb=0;
	string s;
	cin>>n;
	cin>>s;
	for(i=0;i<n;i++)
	{
		if (s[i]=='R')
		nr++;
		else if (s[i]=='G')
		{
			ng++;
		}
		else
		nb++;
	}
	for(i=0;i<n;i++)
	{
		
		for(j=i+1;j<n;j++)
		{
			if( (s[j]!=s[i])&&(j+j-i<n))
			{
				if ((s[j+j-i]!=s[i])&&(s[j+j-i]!=s[j]))
				{
					c++;
				}
			}
		}
		
	}
	ll int ans=ng*nb*nr;

	ans-=c;
	cout<<ans<<endl;
}


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

namespace ConsoleApp15
{
    class Class393
    {
        static void Main()
        {
            string S = Console.ReadLine();
            int c = 0;
            int max = 0;
            for (int i = 0; i < S.Length; i++)
            {
                var s = S[i];
                if (s == 'A' || s == 'C' || s == 'G' || s == 'T')
                {
                    c++;
                    max = Math.Max(max, c);
                }
                else
                {
                    c = 0;
                }
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 25812
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    int N;
    vector<ll> A;
    ll a;
    cin >> N;
    ll ct=0;
    for(int i=0;i<N;i++){
        cin >> a;
        A.push_back(a);
        if(a%2==1) ct++;
    }
    cout << (ct%2==0?"YES":"NO") << endl;

}

Measured memory_bytes: 1400
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()


    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, a - 1, -1):
                dp[j] |= dp[j - a]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)


main()


Measured memory_bytes: 39792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n,a,b;cin>>n>>a>>b;
    cout<<min(a,b)<<' '<<max(0,a+b-n)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int nen=2004,getu,hi,i,j,k,count=0;
	while(scanf("%d%d",&getu,&hi),getu){
		count=0;
	for(i=1996;i<nen;i++){
		if(i%4==0){
			for(j=1;j<=12;j++){
				if(j==1||j==3||j==5||j==7||j==8||j==10||j==12){
					for(k=1;k<=31;k++){
						count++;
					}
				}
				else if(j==2){
					for(k=1;k<=29;k++){
						count++;
					}
				}
				else{
					for(k=1;k<=30;k++){
						count++;
					}
				}
			}
		}
		else{
			for(j=1;j<=12;j++){
				if(j==1||j==3||j==5||j==7||j==8||j==10||j==12){
					for(k=1;k<=31;k++){
						count++;
					}
				}
				else if(j==2){
					for(k=1;k<=28;k++){
					  count++;
					}
				}
				else if(j==4||j==6||j==9||j==11){
					for(k=1;k<=30;k++){
						count++;
					}
				}
			}
		}
	}
	for(;i==nen;i++){
		if(i%4==0){
			for(j=1;j<getu;j++){
				if(j==1||j==3||j==5||j==7||j==8||j==10||j==12){
					for(k=1;k<=31;k++){
						count++;
					}
				}
				else if(j==2){
					for(k=1;k<=29;k++){
						count++;
					}
				}
				else{
					for(k=1;k<=30;k++){
						count++;
					}
				}
			}
		}
		else{
			for(j=1;j<getu;j++){
				if(j==1||j==3||j==5||j==7||j==8||j==10||j==12){
					for(k=1;k<=31;k++){
						count++;
					}
				}
				else if(j==2){
					for(k=1;k<=28;k++){
						count++;
					}
				}
				else{
					for(k=1;k<=30;k++){
						count++;
					}
				}
			}
		}
	}
	for(i=i-1;i==nen;i++){
		for(;j==getu;j++){
			for(k=1;k<=hi;k++){
				count++;
			}
		}
	}
	switch(count%7){
		case 0:
			puts("Sunday");
			break;
		case 1:
			puts("Monday");
			break;
		case 2:
			puts("Tuesday");
			break;
		case 3:
			puts("Wednesday");
			break;
		case 4:
			puts("Thursday");
			break;
		case 5:
			puts("Friday");
			break;
		case 6:
			puts("Saturday");
			break;
	}
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}



int main(){
  
  long long n;
  long long m;
  cin>>n>>m;
  vector<long long> a(n);
  REP(i,n){
    cin>>a[i];
  }
  sort(ALL(a));
  long long s[n];
  for(int i = n-1; i>=0; i--){
    if(i == n-1){
      s[i] = a[i];
    }else{
      s[i] = s[i+1] + a[i];
    }
  }
  long long l = -1, r = 200010;//(l,r]
  while(r - l > 1){
    long long mid = (l+r)/2;
    long long cnt = 0;
    REP(i,n){
      auto itr = lower_bound(ALL(a), mid-a[i]);
      long long lower_index = distance(a.begin(), itr);
      cnt += n - lower_index;
    }
    if(cnt > m){
      l = mid;
    }else{
      r = mid;
    }
  }
  long long ans = 0;
  long long num = 0;
  REP(i,n){
    auto itr = lower_bound(ALL(a), r-a[i]);
    long long lower_index = distance(a.begin(), itr);
    if(lower_index == n)continue;
    num += (n-lower_index);
    ans += (n - lower_index) * a[i];
    ans += s[lower_index];
  }
  //cout<<num<<endl;
  ans += l * (m - num);
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
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;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int target[n];
    for(int i = 0;i < n;i++) cin >> target[i];

    int count = 0;
    while(n > k){
        n = n - k + 1;
        count++;
    }
    cout << count+1 << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
      	int count;
      	if(s.charAt(0)=='S' &&s.charAt(1)=='S' &&s.charAt(2)=='S') count = 0;
      	else if((s.charAt(0)=='R' &&s.charAt(1)=='R' &&s.charAt(2)=='S')
                ||(s.charAt(0)=='S' &&s.charAt(1)=='R' &&s.charAt(2)=='R')) count= 2;
      	else if (s.charAt(0)=='R' &&s.charAt(1)=='R' &&s.charAt(2)=='R') count = 3;
      	else count = 1;
      	
      	System.out.println(count);
    }
}

Measured memory_bytes: 35568
#include<stdio.h>
 
int main(void){
	
	int a[5]={0},b[5]={0};
	int i,j,hit,brrow,x,flag_a,flag_b;
	
	while(1){
		flag_a=flag_b=0;
		x=0;
		hit=0;
		brrow=0;
		
		for(i=0;i<4;i++){
			if(scanf("%d",&x)==EOF){			
				flag_a=1;
				break;
			}
			a[i]=x;
		}

		for(i=0;i<4;i++){
			if(scanf("%d",&x)==EOF){			
				flag_b=1;
				break;
			}
			b[i]=x;
		}
		
		if(flag_a==1 || flag_b==1){
			break;
		}
		
		for(i=0;i<4;i++){		//hit
			if(a[i]==b[i]){
				hit++;
			}
		}
	
		for(i=0;i<4;i++){		//brrow
			for(j=0;j<4;j++){
				if(a[i]==b[j] && i!=j){
					brrow++;
				}
			}
		}	
		printf("%d %d\n",hit,brrow);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
char s[100005];
int main()
{
	scanf("%s",s);
	bool b=1;
	int ans1=0,ans2=0,i;
	for(i=0;s[i];i++)
	{
		if(s[i]-48!=b)
		ans1++;
		b=!b;
	}
	b=0;
	for(i=0;s[i];i++)
	{
		if(s[i]-48!=b)
		ans2++;
		b=!b;
	}
	printf("%d",ans1>ans2?ans2:ans1);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    int a[1100],i;
    for(i=0;i<n;++i)
    {
        scanf("%d",&a[i]);
    }
    for(i=n-1;0<=i;--i)
    {
        if(i != 0){
            printf("%d ",a[i]);
        
        }
        else{
            printf("%d",a[i]);
        }
    }
    printf("\n");
    return 0;
    
}

Measured memory_bytes: 604
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    use std::collections::BinaryHeap;
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let a: Vec<usize> = vec(n, |_| scan(tokens));
    let mut q = BinaryHeap::from(a);
    for _ in 0..m {
        let a = q.pop().unwrap();
        q.push(a >> 1);
    }
    let mut sum = 0;
    for a in q {
        sum += a;
    }
    println!("{}", sum);
}


Measured memory_bytes: 6396
### constant

DXYS = [
  [[1, 0], [1, -1], [ 0, -1], [-1, 0], [ 0, 1], [1, 1]],
  [[1, 0], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1]]
]

### main

w, h = gets.strip.split(' ').map{|s| s.to_i}

brds = h.times.map{gets.strip.split(' ').map{|s| s.to_i}}

q = []
for y in (0...h)
  if brds[y][0] == 0
    brds[y][0] = -1
    q << [0, y]
  end
  if brds[y][w - 1] == 0
    brds[y][w - 1] = -1
    q << [w - 1, y]
  end
end
for x in (0...w)
  if brds[0][x] == 0
    brds[0][x] = -1
    q << [x, 0]
  end
  if brds[h - 1][x] == 0
    brds[h - 1][x] = -1
    q << [x, h - 1]
  end
end

while ! q.empty?
  x, y = q.pop
  dxys = DXYS[y & 1]
  for i in (0...6)
    x0 = x + dxys[i][0]
    y0 = y + dxys[i][1]
    if x0 >= 0 && x0 < w && y0 >= 0 && y0 < h && brds[y0][x0] == 0
      brds[y0][x0] = -1
      q << [x0, y0]
    end
  end
end

for y in (0...h)
  for x in (0...w)
    brds[y][x] = 1 if brds[y][x] == 0
  end
end

count = 0

for y in (0...h)
  dxys = DXYS[y & 1]
  for x in (0...w)
    next if brds[y][x] != 1

    for i in (0...6)
      x0 = x + dxys[i][0]
      y0 = y + dxys[i][1]

      if x0 < 0 || x0 >= w || y0 < 0 || y0 >= h || brds[y0][x0] == -1
        count += 1
      end
    end
  end
end

puts count

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

int main() {
int A,B,ans;
cin>>A>>B;
if(A-B>0) ans=A+(A-1);
else if(B-A>0) ans=B+(B-1);
else if(A==B) ans=A+B;

cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int array[128];

int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}

int main(){

    array['A']=1,array['C']=2,array['G']=3,array['T']=4;

    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];

    char* check_table = new char[TABLE_SIZE];

    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}



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



int main() {
	int N,K;
  	cin >>N>>K;
  
  	vector<int> l(N);
      for(int i=0;i<N;i++){
      cin >>l[i];
      }
  
  sort(l.begin(),l.end());
  	int bou;
  	for(int i=0;i<K;i++){
      bou+=l[N-1-i];
    }
  
  cout<<bou<<endl;
  	
  
    }
 

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001

ll swap(ll a, ll b) {
}
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) {
    return (a*b) / gcd(a, b);
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    a--;
    ll lc = lcm(c, d);

    ll ans = 0;

    ans += (b - ((b/c) + (b/d) - (b/lc)));
    ans -= (a - ((a/c) + (a/d) - (a/lc)));

    cout << ans << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<string, int>>  a(n);
    for (auto &t : a) {
        cin >> t.first >> t.second;
    }
    string x;
    cin >> x;
    int cur = 0;
    int fl = 0;
    for (int i = 0; i < n; i++) {
        cur += fl * a[i].second;
        if (a[i].first == x) {
            fl = 1;
        }
    }
    cout << cur << endl;
}   

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] str = br.readLine().split(" ");
		int w = Integer.parseInt(str[0]);
		int h = Integer.parseInt(str[1]);
		int n = Integer.parseInt(str[2]);
		int[] x = new int[n];
		int[] y = new int[n];
		boolean[][] map = new boolean [w][h];
		for(int i = 0; i < n; i++){
			String[] str1 = br.readLine().split(" ");
			x[i] = Integer.parseInt(str1[0]);
			y[i] = Integer.parseInt(str1[1]);
			int a = Integer.parseInt(str1[2]);
			if(a==1){
				for(int j = 0; j < x[i]; j++){
					for(int k = 0; k < h; k++){
						map[j][k] = true;
					}		
				}
			}else if(a==2){
				for(int j = x[i]; j < w; j++){
					for(int k = 0; k < h; k++){
						map[j][k] = true;
					}		
				}
			}else if(a==3){
				for(int j = 0; j < w; j++){
					for(int k = 0; k < y[i]; k++){
						map[j][k] = true;
					}		
				}
			}else if(a==4){
				for(int j = 0; j < w; j++){
					for(int k = y[i]; k < h; k++){
						map[j][k] = true;
					}		
				}
			}
		}
		int cnt = w*h;
		for(int i = 0; i < w; i++){
			for(int j = 0; j < h; j++){
				if(map[i][j])
					cnt--;
			}
		}
		sb.append(cnt);
		System.out.println(sb);
	}
}

Measured memory_bytes: 9288
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define pb push_back
#define vi vector<int>


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin>>n;
	
	vi v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
		
	vi dp(n);
	
	//dp[0]=v[0];
	
	//cout<<dp[0]<<" ";
	
	dp[0]=0;
    dp[1]=abs(v[0]-v[1]);
	
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-2]+abs(v[i]-v[i-2]),dp[i-1]+abs(v[i]-v[i-1]));
		
		//cout<<dp[i]<<" ";
		//cout<<dp[i+1]<<" ";
	}
	cout<<dp[n-1]<<"\n";
	
	
	
   	return 0;
}



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

int main(){
    int x , n;
    cin >> x >> n;
    vector <bool> ok(101, true);
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        ok[p] = false;
    }
    int mini = 100, ans = 0;
    for(int i = 101; i >= 0; i--){
        if(ok[i]){
            if(abs(x - i) <= mini){
                mini = abs(x - i);
                ans = i;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a); (b) <= i; i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int x1,x2,y1,y2;
  cin >> x1 >> y1 >>x2 >> y2;
  int a=x2-x1;
  int b=y2-y1;
  cout << x2-b << " " << y2+a << " " << x1-b << " " << y1+a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <climits>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
 
using namespace std;
  
int main(){
  int N;
  cin >> N;
  int X[N];
  for(int i=0;i<N;i++){
    cin >> X[i];
  }

  int ans = INT_MAX;
  int sum;
  for(int i=1;i<=100;i++){
    sum = 0;
    for(int j=0;j<N;j++){
      sum += (int)pow((X[j]-i), 2.0);
    }
    ans = min(ans, sum);
  }
  
  cout << ans << endl;
}

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

int lcs(string x, string y) {
    int _lcs = 0;
    int x_size = x.size();
    int y_size = y.size();
    int dp[x_size + 1][y_size + 1];
    for (int i=0; i <= x_size; i++) {
        dp[i][0] = 0;
    }

    for (int j=0; j <= y_size; j++) {
        dp[0][j] = 0;
    }

    for (int i=1; i <= x_size; i++) {
        for (int j=1; j <= y_size; j++) {
            if (x[i-1] == y[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max({dp[i][j-1], dp[i-1][j]});
            }
        }
    }

    return dp[x_size][y_size];
}
int main() {
    int q;
    cin >> q;
    for (int i=0; i < q; i++) {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}


Measured memory_bytes: 7128
n = int(input())
i = 0

card_S = []
card_H = []
card_C = []
card_D = []

while i < n:
	mark, num = input().split()
	if mark == "S":
		card_S.append(int(num))
	elif mark == "H":
		card_H.append(int(num))
	elif mark == "C":
		card_C.append(int(num))
	else:
		card_D.append(int(num))
	i += 1

i = 1
while i < 14:
	if not(i in card_S):
		print("S " + str(i))
	i += 1

i = 1
while i < 14:
	if not(i in card_H):
		print("H " + str(i))
	i += 1

i = 1
while i < 14:
	if not(i in card_C):
		print("C " + str(i))
	i += 1

i = 1
while i < 14:
	if not(i in card_D):
		print("D " + str(i))
	i += 1


Measured memory_bytes: 5608
use proconio::{fastout, input};

use proconio::marker::Usize1;
use std::cmp::min;
use std::cmp::Reverse;
use std::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
        n: usize, m: usize, s: usize,
    }
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        input! { u: Usize1, v: Usize1, a: usize, b: u64 }
        g[u].push((v, a, b));
        g[v].push((u, a, b));
    }
    let mut h = vec![(0, 0); n];
    for i in 0..n {
        input! { c: usize, d: u64 }
        h[i] = (c, d);
    }
    let mut q = BinaryHeap::new();
    q.push(Reverse((0, min(s, 2500), 0)));
    let mut dp = vec![vec![std::u64::MAX; 2501]; n];
    dp[0][min(s, 2500)] = 0;
    while let Some(Reverse((_, s, i))) = q.pop() {
        let (c, d) = h[i];
        if s + c < 2501 {
            if dp[i][s + c] > dp[i][s] + d {
                dp[i][s + c] = dp[i][s] + d;
                q.push(Reverse((dp[i][s + c], s + c, i)));
            }
        }
        for &(j, a, b) in g[i].iter() {
            if s >= a {
                let s1 = (s - a) as usize;
                if dp[j][s - a] > dp[i][s] + b {
                    dp[j][s - a] = dp[i][s] + b;
                    q.push(Reverse((dp[j][s - a], s1, j)));
                }
            }
        }
    }
    for i in 1..n {
        let ans = dp[i].iter().min().unwrap();
        println!("{}", ans);
    }
}


Measured memory_bytes: 4756