akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  Competitive
//
//  Created by Ashutosh Tiwari on 16/05/20.
//  Copyright © 2020 Ashutosh Tiwari. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <climits>
#include <functional>
#include <unordered_map>
#include <tuple>
#include <iterator>
#include <unordered_set>
#include <chrono>
#include <regex>

using namespace std;
using vi = vector<int>;

int mod = 1e9 + 7;
int N = 1e3 + 5;

int main()
{
    ios_base::sync_with_stdio(false);
//    freopen("../in.txt", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);

    vector<string> v(n);
    vector<vector<int> > dp(n, vector<int>(m, 0));
    for (int i = 0; i < n; i ++) {
        cin >> v[i];
    }
    dp[0][0] = 1;
    for (int i = 0; i < m; i ++ ) {
        if (v[0][i] == '.') dp[0][i] = 1;
        else break;
    }

    for (int i = 0; i < n; i ++ ) {
        if (v[i][0] == '.') dp[i][0] = 1;
        else break;
    }
    for (int i = 1; i < n; i ++)
        for (int j = 1; j < m; j ++) {
            if (v[i][j] == '.') dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % mod;
            dp[i][j] %= mod;
        }
//    for (auto i: v) {
////        for (auto j: i)
////            cout << j << " ";
//
//        cout << i << endl;
//    }
//    for (auto i: dp) {
//        for (auto j: i)
//            cout << j << " ";
//        cout << endl;
//    }
    printf("%d\n", dp[n - 1][m - 1] % mod);
    return 0;
}


Measured memory_bytes: 5760
def chmin(i):
    if i < k:
        a = k-i
        list_before_compare = [dp_table[i-kk] + abs(h[i]-h[i-kk]) for kk in range(1,k+1-a)]
    else:
        list_before_compare = [dp_table[i-kk] + abs(h[i]-h[i-kk]) for kk in range(1,k+1)]
    
    list_before_compare.append(dp_table[i])

    return min(list_before_compare)



n,k = map(int,input().split())
h = list(map(int,input().split()))

dp_table  = [float("inf")] * n

dp_table[0] = 0

for i in range(1,n):
    dp_table[i] = chmin(i)

print(dp_table[-1])

Measured memory_bytes: 55904
from collections import Counter
n, m = map(int, input().split())
py = []
for i in range(m):
    t = list(map(int, input().split()))
    py.append(t+[i])

c = Counter([])
py.sort(key=lambda x: x[1])

ans = []
for p, y, i in py:
    c[p]+=1
    ans.append((i, str(p).zfill(6)+str(c[p]).zfill(6)))
ans.sort()
for i, a in ans:
    print(a)

Measured memory_bytes: 45284
<?php
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
  while ($line = fgets(STDIN)) {
      list($a, $b, $c) = explode(' ', $line);
      $a = (int)$a;
      $b = (int)$b;
      $c = (int)$c;
      echo $a < $b && $b < $c ? 'Yes' : 'No';
  }
}
?>

Measured memory_bytes: 15304
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m;
	cin >> n >> m;
	if(m % n == 0){
		cout << m/n;
		return 0;
	}
	vector<ll> fac;
	for(ll i{2};i*i < m;i++){
		if(m % i == 0){
			fac.push_back(i);
			if(i >= n){
				cout << m/i;
				return 0;
			}
		}
	}
	int p = fac.size()-1;
	for(int i = p;i >= 0;i--){
		if(m / fac[i] >= n){
			cout << fac[i];
			return 0;
		}
	}
	cout << 1;
	return 0;
}





Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
 int n, m, c, a, b = 0;
 scanf("%d %d", &n, &m);
 for(c = 0; c < m; c++) {
  scanf("%d", &a);
  b = b + a;
 }
 if(n >= b) {
  printf("%d", n - b);
 } else {
  printf("-1");
 }
 return 0;
}

Measured memory_bytes: 1724
//include
//------------------------------------------
#include <bits/stdc++.h> // only for GCC

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

//clear memory
// ------------------------------------------
#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
   int n;
    char c;
    while(cin>>n){
      map<int,int> t;
      int two=0,three=0,four=0,strate=0;
      t[n]++;
      rep(i,4){
         cin >> c >> n;
         t[n]++;
      }
      rep(i,14){
         if(t[i]==2) two++;
         if(t[i]==3) three++;
         if(t[i]==4) four++;
         if(t[i]==1&&t[i+1]==1&&t[i+2]==1&&t[i+3]==1&&t[i+4]==1) strate++;
      }
      if(t[1]==1&&t[10]==1&&t[11]==1&&t[12]==1&&t[13]==1) strate++;
      if(two==1){
         if(three==1) cout << "full house" << endl;
         else cout << "one pair" << endl;
      }else if(two==2) cout << "two pair" << endl;
      else if(three==1) cout << "three card" << endl;
      else if(strate==1) cout << "straight" << endl;
      else if(four==1) cout << "four card" << endl;
      else cout << "null" << endl;
    }
}

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

using namespace std;

#define endl "\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = 2e9;
const int MAX=1e7;
const int mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,h;
	while(cin>>n>>h){
		ll ans=0;
		vector<ll>v(n),v2(n);
		for(int i=0;i<n;i++)
			cin>>v[i]>>v2[i];
		sort(rall(v));
		sort(rall(v2));
		ans=(h+v[0]-1)/v[0];
		for(int i=0;i<n;i++){
			if(h<=0||v2[i]<v[0])
				break;
			h-=v2[i];
			h=max(0ll,h);
			ans=(h+v[0]-1)/v[0]+i+1;
		}
		cout<<ans<<endl;
	}

	return 0;
}


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

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

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef map<ll,ll> mpll;
typedef set<ll> setll;
typedef multiset<ll> msetll;

#define F first
#define S second
#define pb push_back
#define mp make_pair

const ll mod = 1e9 + 7;
const ll inf = 99999999999999999;
ll n;
struct node{
	ll w;
	ll s;
	ll v;
};
vector<node> v;
ll memo[1001][10001][2];

ll func(int i,ll s1,int cc){
	if(i==n-1){
		if(v[i].w<=s1 || cc==0) 
			return v[i].v;
		else return 0;
	}

	if(memo[i][s1][cc]!=-1) return memo[i][s1][cc];
	ll ma=-1;
	if(cc==1){
		if(v[i].w<=s1){
			ma = max(ma,v[i].v + func(i+1,min(s1-v[i].w,v[i].s),1));
		}
		ma = max(ma,func(i+1,s1,cc));
	}
	else
	{
		ma = max(v[i].v + func(i+1,v[i].s,1),func(i+1,s1,0));
	}
	return memo[i][s1][cc]=ma;
}


int main()
{

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
	#ifdef DEBUG_
		freopen("input.txt","r",stdin);
	#endif
	
	cout.setf(ios::fixed), cout.precision(20);

	cin >> n;
	v.resize(n);
	for(int i=0;i<n;i++){
		cin >> v[i].w >> v[i].s >> v[i].v;
	}
	auto cmp = [](node n1,node n2){
		return n1.w + n1.s > n2.w + n2.s;
	};
	sort(v.begin(),v.end(),cmp);
	// for(auto xx : v){
	// 	cout<<xx.w<<" "<<xx.s<<" "<<xx.v<<"\n";
	// }
	for(int i=0;i<=1000;i++){
		for(int j=0;j<=10000;j++)
		{
			memo[i][j][0]=-1;
			memo[i][j][1]=-1;
		}
	}
	cout<<func(0,0,0)<<"\n";

	return 0;
}



Measured memory_bytes: 156800
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int cash = 0;
		if(A >= 13) {
			cash = B;
		}else if(A <= 12 && A >= 6) {
			cash = B / 2;
		}
		System.out.println(cash);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
string s[]={"one pair","two pair","three card","straight","null"};

int str(int n){
	cout << s[n] << endl;
	return 0;
}

int main(){
	int a[5], t[14], ans, m;
	while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4]) != EOF){
		ans = -1, m = 0;
		sort(a, a+5);
		fill(t, t+14, 0);
		for(int i = 0;i < 5;i++){
			t[a[i]]++;
			if(m < t[a[i]])m = t[a[i]];
		}
		
		int flag = 0;
		if(a[0]==1&&a[1]==10&&a[2]==11&&a[3]==12&&a[4]==13){str(3);continue;}
		for(int i = 1;i < 5 && a[i-1]+1 == a[i];i++)flag = i;
		if(flag == 4){str(3);continue;}
		
		if(m == 4){cout << "four card" << endl;continue;}
		if(m == 3){
			int f = 1;
			for(int i = 1;i <= 13;i++){
				if(t[i] == 2)f = 0;
			}
			if(!f){cout << "full house" << endl;continue;}
			ans = 2;
		}
		
		for(int i = 1;i <= 13;i++){
			if(!ans && t[i] == 2)ans = 1;
			if(ans != 1 && t[i] == 2)ans = 0;
		}
		if(ans == -1)ans = 4;
		str(ans);
	}
	return 0;
}

Measured memory_bytes: 3124
n, t, q = gets.split.map(&:to_i)
stop = []
a = []
n.times do |i|
    x, d = gets.split.map(&:to_i)
    if d == 1
        a << x
    else
        if a.empty?
            stop << [(stop[-1] || -Float::INFINITY), x - t].max
        else
            y = a.pop
            c = (y + x) / 2
            s2 = [c, x - t].max
            s1 = [c, y + t].min
            b = [s1, s2]
            until a.empty?
                y = a.pop
                b.unshift [y + t, b[0]].min
            end
            stop += b
        end
    end
end
stop += a.map {|x| x + t}
q.times do
    p stop[gets.to_i - 1]
end


Measured memory_bytes: 154156
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define tms(x) ___ = x; while(___--)
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int ___;
vector<pii> v;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y, a, b, c, redPick, greenPick, nonePick, ans;
	redPick = greenPick = nonePick = ans = 0;
	cin>>x>>y>>a>>b>>c;
	rep(i, 0, a) v.pb(pii(next<int>(), 1));
	rep(i, 0, b) v.pb(pii(next<int>(), 2));
	rep(i, 0, c) v.pb(pii(next<int>(), 3));
	sort(v.begin(), v.end());
	for(int i = v.size()-1; i >= 0; i--)
	{
		if (redPick+greenPick+nonePick == x+y) break;
		if (v[i].second == 1 && redPick < x) redPick++, ans += v[i].first;
		else if (v[i].second == 2 && greenPick < y) greenPick++, ans += v[i].first;
		else if (v[i].second == 3) nonePick++, ans += v[i].first;
	}
	cout<<ans<<endl;
	return ~~(0-0);
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}


Measured memory_bytes: 10604
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> l(n);
    REP(i, n){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    ll ans = 0;
    REP(bi, n - 1){
        const ll b = l.at(bi);
        ll ci = bi + 1;
        REP(ai, bi){
            const ll a = l.at(ai);
            while(ci < n && l.at(ci) < a + b){ ci++; }
            ans += ci - bi - 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
	return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
void solve() {
    int A,B,C,K;
    R(A,B,C,K);
    while(B<=A){
        B*=2;
        K--;
    }
    while(C<=B){
        C*=2;
        K--;
    }
    W(K<0?"No":"Yes");
}
int main(){
#define MULTITEST 0
#if MULTITEST    
    CASET{
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3824
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, t := ri(), ri()
	minCost := inf
	for i := 0; i < n; i++ {
		cost, tt := ri(), ri()
		if tt > t {
			continue
		}
		if cost > minCost {
			continue
		}
		minCost = cost
	}
	if minCost > 1000 {
		fmt.Println("TLE")
	} else {
		fmt.Println(minCost)
	}
}


Measured memory_bytes: 640
n,m=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
pqr = [[1,1,1],[1,1,-1],[-1,1,-1],[1,-1,-1],[-1,-1,-1],[1,-1,1],[-1,1,1],[-1,-1,1]]
res = -10**11
for p,q,r in pqr:
    l=[]
    for i in range(n):
        l.append(p*x[i][0]+q*x[i][1]+r*x[i][2])
    l.sort(reverse=True)
    res=max(res,sum(l[:m]))
print(res)

Measured memory_bytes: 40176
s=input()
n=len(s)

def circ_check(s):
    s_rev=s[::-1]
    n=len(s)
    if n%2==1:
        half_n=int((n-1)/2)
    else:
        half_n=int(n/2)
    if s_rev[0:half_n] ==s[0:half_n]:
        s_check=1
    else:
        s_check=0
    return(s_check) 


res1=circ_check(s)
res2=circ_check(s[0:int((n-1)/2)])
res3=circ_check(s[int((n-1)/2+1):len(s)])
if res1*res2*res3==1:
    print('Yes')
else:
    print('No')
    


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            List<Integer> numList = Arrays.stream(args.get(1).split(" ")).map(Integer::valueOf).collect(Collectors.toList());
            int ans = 0;
            for (int i = 1; i < numList.size() - 1; i++) {
                if (numList.get(i - 1) < numList.get(i) && numList.get(i) < numList.get(i + 1)) {
                    ans++;
                }
                if (numList.get(i - 1) > numList.get(i) && numList.get(i) > numList.get(i + 1)) {
                    ans++;
                }
            }
            System.out.println(ans);
        };
    }

}


Measured memory_bytes: 28360
n=io.read("*n","*l")
h={}
for i=1,n do
    h[i]=io.read("*n")
end
previous=h[1]-1
for i=2,n do
    if previous<h[i] then
        previous=h[i]-1
    elseif previous>h[i] then
        print("No")
        return
    end
end
print("Yes")

Measured memory_bytes: 2424
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

long long int mod=1e9+9;
const int N=100000;
int t,i,j,cs=0,n,m,a,q,b;
string s;

int main()
{
   cin>>n>>q>>s;

   int ans[n+1]={};
   for(i=1;i<n;i++){
       ans[i+1]=ans[i];
    if(s[i-1]=='A' && s[i]=='C')
        ans[i+1]++;
   }
   //for(auto it: ans) cout<<it<<" ";
   while(q--){
    cin>>a>>b;
    cout<<ans[b]-ans[a]<<endl;
   }
}






Measured memory_bytes: 1408
import java.util.*;

public class Main {
    public static void  main (String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int[] time = new int[4];
        for(int i = 0; i < 4; i++) {
            time[i] = sc.nextInt();
        }
        
        if ((time[1] <= time[2]) || (time[3] <= time[0])) {
            System.out.println(0);
        } else if (time[0] <= time[2]) {
            if (time[3] <= time[1]) {
                System.out.println(time[3] - time[2]);
            } else {
                System.out.println(time[1] - time[2]);
            }
        } else if (time[0] > time[2]) {
            if (time[3] <= time[1]) {
                System.out.println(time[3] - time[0]);
            } else {
                System.out.println(time[1] - time[0]);
            }
        }
    }
}

Measured memory_bytes: 22868
def gen_primes(N):
    from itertools import compress
    sieve = list(range(N))
    sieve[1] = 0
    for i in range(2, int(N**.5) + 1):
        sieve[i * 2::i] = [0] * len(sieve[i * 2::i])
    return sieve


if __name__ == '__main__':
    ps = gen_primes(123456 * 2 + 1)
    for e in iter(input, '0'):
        n = int(e)
        print(sum(1 for p in ps[n + 1:2 * n + 1] if p))


Measured memory_bytes: 17200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b; cin >> n >> a >> b;
	ll ans = n / (a + b) * a;
	if (n % (a + b) <= a) ans += (n % (a + b));
	else ans += a;
	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> pi;
int k,x,y,t;
pi a[200020];
pi cal(int x,int y){
	if (x>y){
		pi t=cal(y,x);
		return {t.y,t.x};
	}
	if (x<0){
		pi t=cal(-x,y);
		return {-t.x,t.y};
	}
	if (x+y>=2*k) return {x,y-k};
	if (x+y==k) return {0,0};
	int t=k-(x+y)/2;
	return {-t,y-k+x+t};
}
int main(){
	scanf("%d%d%d",&k,&x,&y);
	if (!(k&1) && (x+y)&1) return puts("-1"),0;
	a[0]={x,y};
	for (;a[t].x || a[t].y;t++) a[t+1]=cal(a[t].x,a[t].y);
	printf("%d\n",t);
	for (;t--;) printf("%d %d\n",a[t].x,a[t].y);
}

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

int main(){
  int x;

  while(cin >> x, x){
    string ans = "";

    while(x != 0){
      int rem = x % 8;
      x /= 8;

      int d;

      if(rem < 4){
        d = rem;
      }
      else if(rem < 5){
        d = rem + 1;
      }
      else{
        d = rem + 2;
      }

      ans = (char)('0' + d) + ans;
    }

    cout << ans << endl;
  }
}

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

int main() {
	string s;
	while (cin >> s, s != "0") {
		int sum = 0;
		for (char c : s)sum += c - '0';
		cout << sum << endl;
	}
}

Measured memory_bytes: 3156
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Character m[] = new Character[n];
		Integer a[] = new Integer[n];
		for(int i = 0; i < n; i++) {
			String tmp = sc.next();
			m[i] = tmp.charAt(0);
			a[i] = Integer.parseInt(tmp.substring(1));
		}
		
		ArrayList<Character> sm = new ArrayList<Character>();
		ArrayList<Character> bm = new ArrayList<Character>(Arrays.asList(m));
		ArrayList<Integer> ba = new ArrayList<Integer>(Arrays.asList(a));
		sm = BubbleSort(n, bm, ba);
		
		//SelectionSort
		for(int i = 0; i < n; i++) {
			int minj = i;
			for(int j = i; j < n; j++) {
				if(a[j] < a[minj]) {
					minj = j;
				}
			}
			int tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
			char tmpc = m[i];
			m[i] = m[minj];
			m[minj] = tmpc;
		}
		
		boolean ifstable = true;
		for(int i = 0; i < n; i++) {
			if(i != 0) System.out.print(" ");
			System.out.print(m[i]);
			System.out.print(a[i]);
			if(sm.get(i) != m[i]) ifstable = false;
		}
		if(ifstable) System.out.println("\nStable");
		else System.out.println("\nNot stable");
	}
	
	private static ArrayList<Character> BubbleSort(int n, ArrayList<Character> bm, ArrayList<Integer> ba){
		boolean flag = true;
		while(flag) {
			flag = false;
			for(int j = n-1; j > 0; j--) {
				if(ba.get(j) < ba.get(j-1)) {
					int tmp = ba.get(j);
					ba.set(j, ba.get(j-1));
					ba.set(j-1, tmp);
					char tmpc = bm.get(j);
					bm.set(j, bm.get(j-1));
					bm.set(j-1, tmpc);
					flag = true;
				}
			}
		}
		for(int i = 0; i < n; i++) {
			if(i != 0) System.out.print(" ");
			System.out.print(bm.get(i));
			System.out.print(ba.get(i));
		}
		System.out.println("\nStable");
		
		return bm;
	}
}


Measured memory_bytes: 26140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
/*bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int main()
{
    ll a,b,c,t,n,k,p,q,r,y,yy,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    set<ll>st;
    char ch;
    map<ll,ll>mp;
    vector<ll>v,vv,vz;

      cin>>ch;
      p=isVowel(ch);
      if(p) cout<<"vowel"<<endl;
      else cout<<"consonant"<<endl;


}





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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;
typedef queue<pair<int, int> > que;

char city[1005][1005];
int way[1005][1005];
int di[4] = { -1, 0, 0, 1 }; int dj[4] = { 0, -1, 1, 0 };

int main()
{
	int h, w, n;
	cin >> h >> w >> n;
	REP(i, h)REP(j, w)cin >> city[i][j];
	que start;
	REP(i, h)REP(j, w){
		if (city[i][j] == 'S')start.push(make_pair(i, j));
	}
	FOR(k, 1, n + 1)
	{
		REP(i, h)REP(j, w){
			if (city[i][j]-'0'==k )
			{
				start.push(make_pair(i, j));
			}
		}
	}
	int cnt = 0;

	REP(i, n)
	{
		REP(i, 1005)REP(j, 1005)way[i][j] = INF;
		que q;
		way[start.front().first][start.front().second] = 0;
		q.push(start.front());
		start.pop();
		while (1)
		{
			int tmpi = q.front().first; int tmpj = q.front().second;
			q.pop();
			if (tmpi == start.front().first&&tmpj == start.front().second)
			{
				cnt += way[tmpi][tmpj];
				break;
			}
			else
			{
				REP(i, 4){
					if (tmpi+di[i]>=0&&tmpi+di[i]<h&&tmpj+dj[i]>=0&&tmpj+dj[i]<w&&city[tmpi+di[i]][tmpj+dj[i]]!='X'&&way[tmpi+di[i]][tmpj+ dj[i]] == INF )
					{
						way[tmpi + di[i]][tmpj + dj[i]] = way[tmpi][tmpj] + 1;
						q.push(make_pair(tmpi + di[i], tmpj + dj[i]));
					}
				}
			}
			
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int D,N;
  cin >> D >> N;
  int ans = 1;
  for(int i = 0; i < D; i++){
    ans *= 100;
  }
  if(N != 100) cout << ans * N << endl;
  else cout << ans * 101 << endl;
}


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

using namespace std;

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

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

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

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

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

  cin >> s;
  rep(i, Size(s)) { mp[s[i]] = 1; }
  for (char c = 'a'; c <= 'z'; c++) {
    if (mp[c] == 0) {
      Cout(c);
      return 0;
    }
  }
  Cout("None");

  return 0;
}

Measured memory_bytes: 3748
a=[int(input()) for _ in range(5)]
b=[]
ans=0
for j in a:
  while j%10!=0:
    j+=1
  b.append(j)
for i in range(5):
  if b[i]-a[i]>ans:
    ans=b[i]-a[i]
    
print(sum(b)-ans)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
    long a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    long ans = a*x + b*y;
    if(x>=y){
        ans = min(2*c*x,ans);
        ans = min(2*c*y+(x-y)*a,ans);
    }
    else{
        ans = min(2*c*x+(y-x)*b,ans);
        ans = min(2*c*y,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,c,d,i,j,k,l;
   while(~scanf("%lld%lld",&a,&b))
   {
       c=a/b;
       d=abs(a-b*c);
       i=abs(a-b*(c+1));
       printf("%lld\n",d>i?i:d);
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i = 0; i < N;i++){
    cin >> p.at(i);
  }
  vector<int> pd = p;
  sort(p.begin(), p.end());
  
  int disoder = 0;
  for(int i = 0;i < N;i++){
    if(p.at(i) != pd.at(i)){disoder++;}
  }
  if(disoder < 3) cout <<"YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 155-B

int main(void)
{
	int i, N, A[1000];
	int C = 0, Cdot = 0;
	scanf("%d", &N);
	C = N;
	for (i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
	}
	for (i = 0; i < N; i++)
	{
		if ((A[i] % 2 == 1) || ((A[i] % 2 == 0) && ((A[i] % 3 == 0 || A[i] % 5 == 0))))
			Cdot = Cdot + 1;
		else
			Cdot = Cdot + 0;
	}
	if (C == Cdot)
		printf("APPROVED");
	else
		printf("DENIED");
	return 0;
}

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

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N), b(N);
	for(ll i=0; i<N; i++) cin >> a[i];
	for(ll i=0; i<N; i++) cin >> b[i];

	map<ll,ll> am,bm;
	for(ll i=0; i<N; i++){
		am[a[i]]++;
		bm[b[i]]++;
	}
	for(auto&& pr:am){
		if(pr.second + bm[pr.first]> N){
			cout << "No\n";
			return 0;
		}
	}

	vector<pair<ll,ll>> ab;
	for(ll i=0; i<N; i++)ab.push_back({a[i],0});
	for(ll i=0; i<N; i++)ab.push_back({b[i],1});
	sort(ab.begin(), ab.end());

	vector<array<ll,4>> v(N);
	for(ll i=0; i<N*2; i++){
		if(i<N){
			v[i][0]=ab[i].first;
			v[i][1]=ab[i].second;
		}else{
			v[i-N][2]=ab[i].first;
			v[i-N][3]=ab[i].second;
		}
	}

	vector<pair<ll,ll>> ans;
	vector<pair<ll,ll>> tmpa, tmpb;
	for(ll i=0; i<N; i++){
		if(v[i][1]!=v[i][3]){
			if(v[i][1]>v[i][3])swap(v[i][0], v[i][2]);
			ans.push_back({v[i][0], v[i][2]});
		}else{
			if(v[i][1]==0)tmpa.push_back({v[i][0], v[i][2]});
			else tmpb.push_back({v[i][0], v[i][2]});
		}
	}

	for(ll i=0; i<(ll)tmpa.size(); i++){
		if(tmpa[i].first==tmpb[i].first || tmpa[i].second==tmpb[i].second){
			swap(tmpa[i].first, tmpa[i].second);
		}
		ans.push_back({tmpa[i].first, tmpb[i].first});
		ans.push_back({tmpa[i].second, tmpb[i].second});
	}

	sort(ans.begin(), ans.end());
	cout << "Yes\n";
	for(ll i=0; i<N; i++) cout << ans[i].second << " \n"[i==N-1];

	return 0;
}


Measured memory_bytes: 54984
#include <stdio.h>

int main(){
    long long n, d;
    long long x[200005], y[200005];

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

    //printf("%d\n", -1 * -1);

    int cnt = 0;
    for(int i = 0; i < n; ++i){
        //printf("%d %d\n", (x[i] * x[i]) + (y[i] * y[i]), (d * d));
        if(((x[i] * x[i]) + (y[i] * y[i])) <= (d * d)) cnt++;
    }

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

    return 0;
}


Measured memory_bytes: 4816
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
  ll n,res=0;
  cin>>n;
  map<ll,ll> m;
  vector<ll> v(n);
  for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    if(m.find(x)==m.end())
      m.insert({x,0});
    m[x]++;
    v[i]=x;
  }
  for(auto it=m.begin();it!=m.end();it++)
    res+=it->second*(it->second-1)/2;
  for(ll i=0;i<n;i++)
      cout<<res-m[v[i]]+1<<endl;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll q=1;
  for(ll i=1;i<=q;i++)
    solve();
}

Measured memory_bytes: 11136
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i, 0, n) cin >> l[i];

	int sum = 0;
	int mx = 0;
	for (auto& x : l) {
		mx = max(mx, x);
		sum += x;
	}

	if (mx < sum - mx) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
void merge(int [],int,int,int);
void mergeSort(int [],int,int);
int cnt;
int main(){
  int S[500000],i,n;
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
 
  mergeSort(S,0,n);

  for(i=0;i<n;i++){
    if(i==0) printf("%d",S[i]);
    else if(i==n-1)  printf(" %d\n",S[i]);
    else printf(" %d",S[i]);
  }
  printf("%d\n",cnt);

  return 0;
}

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  double *L,*R;

  n1=mid-left;
  n2=right-mid;

  L=(double*)malloc((sizeof(double))*(n1+1));
  R=(double*)malloc((sizeof(double))*(n2+1));

  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=1.0/0.0;
  R[n2]=1.0/0.0;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else {
      A[k]=R[j];
      j++;
    }

  }
  
  free(L);
  free(R);

}
void mergeSort(int A[],int left,int right){
  int mid;
  
  if(left+1<right){ mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }

}

Measured memory_bytes: 6328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,m;
  cin>>a>>b>>m;
  vector<int> ai(a);
  int ma;
  vector<int> bi(b);
  int mb;
  for(int i=0;i<a;i++){
    cin>>ai.at(i);
    ma=(i==0?ai.at(i):min(ma,ai.at(i)));
  }
  for(int i=0;i<b;i++){
    cin>>bi.at(i);
    mb=(i==0?bi.at(i):min(mb,bi.at(i)));
  }
  int ms=ma+mb;
  for(int _=0;_<m;_++){
    int x,y,c;
    cin>>x>>y>>c;
    x--;
    y--;
    ms=min(ms,ai.at(x)+bi.at(y)-c);
  }
  cout<<ms<<endl;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<int> v(3, 0);
    string s; cin >> s;
    for (auto &x: s) v[x-'a']++;
    if (max({v[0], v[1], v[2]}) - min({v[0], v[1], v[2]}) > 1) cout << "NO\n";
    else cout << "YES\n";
    return 0;
}

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

int main(void){
  int n, m, a;
  int g[1001][1001];
  while(cin >> n >> m >> a, n | m | a){
    for(int i=0; i < 1001; i++){
      for(int j=0; j < 1001; j++){
        g[i][j] = -1;
      }
    }
    for(int i=0; i < m; i++){
      int h, p, q; cin >> h >> p >> q;
      g[h][p] = q; g[h][q] = p;
    }
    for(int i=1000; i >= 0; i--){
      if(g[i][a] != -1){
        a = g[i][a];
      }
    }
    cout << a << endl;
  }


  return 0;
}

Measured memory_bytes: 5072
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<unordered_map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<memory>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a)   a.begin(),a.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    //
    ModInt operator++(int) {
        auto t = *this;
        *this += 1;
        return t;
    }

    ModInt operator--(int) {
        auto t = *this;
        *this -= 1;
        return t;
    }
    ModInt operator<<(const int n){
        return ModInt(*this)*ModInt(2).pow(n);
    }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void b(){
   ll N; cin >> N;
   unordered_map<ll,ll> D;
   rep(i,N) {
       ll t;
       cin >> t;
       D[t]++;
   }
   ll M; cin >> M;
   rep(i,M){
       ll t;
       cin >> t;
       if(!D[t]){
           cout << "NO";
           return;
       }
       D[t]--;
   }

    cout << "YES";



}


int main(){
    b();
}


Measured memory_bytes: 11368
#include <iostream>

using namespace std;

int main() {
    int n, u, k, v, a[101][101] = {};
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            a[u][v] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (j > 1)
                cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3140
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        if (n == 2) {
            if (k == 0) {
                System.out.println(1);
                System.out.println("1 2");
            } else {
                System.out.println(-1);
            }
            return;
        }
        if (k > (n - 1) * (n - 2) / 2) {
            System.out.println(-1);
            return;
        }
        System.out.println(n * (n - 1) / 2 - k);
        boolean[][] b = new boolean[n][n];
        for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
            b[i][j] = true;
        }
        for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) {
            if (k == 0) continue;
            k--;
            b[i][j] = false;
        }
        for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
            if (b[i][j]) {
                System.out.println((i + 1) + " " + (j + 1));
            }
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23764
package main

import (
	"fmt"
)

func main() {
	var S, T string
	fmt.Scan(&S, &T)

	var tableS, tableT [256]byte

	for i := 0; i < len(S); i++ {
		if tableS[S[i]] == 0 {
			tableS[S[i]] = T[i]
		} else if tableS[S[i]] != T[i] {
			fmt.Println("No")
			return
		}
	}

	for i := 0; i < len(T); i++ {
		if tableT[T[i]] == 0 {
			tableT[T[i]] = S[i]
		} else if tableT[T[i]] != S[i] {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '

const int MAXN = 4*1e5;

//ll a[MAXN], ST[MAXN * 4], LZ[MAXN*4];

/*bool perfectSquare(ll x){
    ll s = sqrt(x);
    if(s *s == x) return true;
    else return false;
}*/
typedef long double ld;

ll a[MAXN], n = 0;


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


int main() { 
    int a = 0, b = 0, x = 0;
    cin >> a >> b >> x;
    if(a > x){
        cout << "NO" << endl;
        return 0;
    }
    a+=b;
    if(x <= a){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    

    return 0; 
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,t,a,mii;
	double mi = INF;
	cin >> n >> t >> a;
	for(int i = 0;i < n;i++){
		double h;
		cin >> h;
		double tt = t - h * 0.006;
		if(abs(tt - a) < mi){
			mi = abs(tt - a);
			mii = i;
		}
	}
	cout << mii + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N=200000;
const double pi=acos(-1);
int n,sx,sy,tx,ty,nx;
struct point {
	int x,y,num;
}a[200005];
namespace bit {
	int t[N+10];
	int lowbit(int x) {
		return x&(-x);
	}
	void clear() {
		memset(t,0,sizeof(t));
		return;
	}
	int Query(int x) {
		int maxx=0;
		while (x>0) {
			maxx=max(maxx,t[x]);
			x-=lowbit(x);
		}
		return maxx;
	}
	void Add(int x,int va) {
		while (x<=N) {
			t[x]=max(t[x],va);
			x+=lowbit(x);
		}
	}
}
bool cmpx(point p,point q) {
	return p.x<q.x;
}
bool cmpy(point p,point q) {
	return p.y<q.y;
}
double work() {
	sort(a+1,a+n+1,cmpy);
	for (int i=1;i<=n;i++) a[i].num=i;
	sort(a+1,a+n+1,cmpx);
	int kx=0;
	bit::clear();
	for (int i=1;i<=n;i++) {
		int now=bit::Query(a[i].num-1);
		kx=max(kx,now+1);
		bit::Add(a[i].num,now+1);
	}
	double ans=100.0*(tx+ty)-(20-5*pi)*kx;
	if (kx==min(tx,ty)+1) ans+=5*pi;
	return ans;
}
int main() {
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	bool judge=1;
	if (sx>tx) {
		swap(sx,tx);
		judge^=1;
	}
	if (sy>ty) {
		swap(sy,ty);
		judge^=1;
	}
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		int nowx,nowy;
		scanf("%d%d",&nowx,&nowy);
		if (nowx<sx||nowy<sy||nowx>tx||nowy>ty) continue;
		a[++nx].x=nowx;
		if (judge) a[nx].y=nowy;else a[nx].y=sy+ty-nowy;
	}
	n=nx;
	tx-=sx;
	ty-=sy;
	for (int i=1;i<=n;i++) {
		a[i].x-=sx;
		a[i].y-=sy;
	}
	double ans=work();
	printf("%.15lf\n",ans);
	return 0;
}

Measured memory_bytes: 3328