akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
    const int N=(int)2001;
    const int M=(int)2e6+100;
    const int inf=(int)1e9+100;
#define filename ""
    vector<pair<int,int> > v;
    int n;
    bool was[N][N];
    ll table[N][N];
ll f(int x,int y)
{
    if (x==n) re 0;
    if (was[x][y]) re table[x][y];
    was[x][y]=1;
    ll o=0;
    o=max(o,f(x+1,y+1)+(ll)v[x].fi*abs(v[x].se-y));
    o=max(o,f(x+1,y)+(ll)v[x].fi*abs(v[x].se-(n-x+y-1)));
    re table[x][y]=o;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int i,a;
    cin>>n;
    fo(i,n)
    {
        cin>>a;
        v.pb({a,i});
    }
    sort(all(v));
    reverse(all(v));
    cout<<f(0,0);
}


Measured memory_bytes: 30348
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(W<=x||H<=y||x<0||y<0||W-x<r||H-y<r)
    printf("No\n");
    else
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2048
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    var cx = 0
    var cy = 0
    var ct = 0
    repeat(n) {
        val (t, x, y) = readLine()?.split(" ")?.map(String::toInt) ?: return
        val distance = Math.abs(cx - x) + Math.abs(cy - y)
        val timeLimit = Math.abs(ct - t)
        if (distance > timeLimit) {
            println("No")
            return
        }
        if (distance % 2 != timeLimit % 2) {
            println("No")
            return
        }
        cx = x
        cy = y
        ct = t
    }
    println("Yes")
}


Measured memory_bytes: 51304
from operator import itemgetter

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

AB = [tuple(map(int, input().split())) for _ in range(M)]
AB.sort(key = itemgetter(1))

counter = 0
last_b = -1
for a, b in AB:
    if a >= last_b:
        counter += 1
        last_b = b

print(counter)


Measured memory_bytes: 18212
// abc102_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
    
    int N;
    cin >> N;
    
    if (N % 2 == 0){
        print(N);
    } else {
        print(2 * N);
    }


    return 0;
}


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

#define repi(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(v) begin(v), end(v)

using ll = long long;

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

  string S, T;
  cin >> S >> T;

  int result = numeric_limits<int>::max();
  for (int i = 0; i + T.size() <= S.size(); ++i) {
    int changes = 0;
    rep(k, T.size()) {
      if (S[i + k] != T[k]) {
        ++changes;
      }
    }

    result = min(result, changes);
  }

  cout << result << '\n';

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int x[510],a[250010],go[250010];
int main()
{
	int n,now=1;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x[i]);
		if (go[x[i]]) {puts("No");return 0;}go[x[i]]=i;
	}
	sort(x+1,x+n+1);
	for (int i=1;i<=n;i++)
	{
		if (a[x[i]]) {puts("No");return 0;}a[x[i]]=i;while (a[now]) now++;
		int w=go[x[i]]-1;
		while (w)
		{
			if (now>x[i]) {puts("No");return 0;}
			a[now]=i;w--;
			now++;while (a[now]) now++;
		}
	}
	now=1;while (a[now]) now++;
	for (int i=1;i<=n;i++)
	{
		now=max(now,x[i]+1);while (a[now]) now++;
		int w=n-go[x[i]];
		while (w)
		{
			if (now>n*n) {puts("No");return 0;}
			a[now]=i;w--;
			now++;while (a[now]) now++;
		}
	}
	puts("Yes");
	for (int i=1;i<=n*n;i++) printf("%d ",go[x[a[i]]]);
}
	
	
	
	
	
	
	
	
	


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

using namespace std;

int main()
{
    long long  n;
    cin>>n;
    long long  ans=n;
    for(long long i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ans=min(ans,i+n/i-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<int, int>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

vector<string> s;
vector<char> ans;
int a[3];
char cs[3] = { 'A','B','C' };
bool f = false;
int n;
bool func(int i, int x, int y) {
	if (a[x] == 0 && a[y] == 0) {
		f = true;
		return true;
	}
	if (a[x] > a[y]) {
		ans[i] = cs[y];
		--a[x]; ++a[y];
	}
	else if (a[y] > a[x]) {
		ans[i] = cs[x];
		--a[y]; ++a[x];
	}
	else {
		if (i == n - 1) {
			ans[i] = cs[y];
			--a[x]; ++a[y];
			return true;
		}
		return false;
	}
	return true;
}

int main(){
	cin >> n >> a[0] >> a[1] >> a[2];

	ans.resize(n);
	s.resize(n);
	for (int i = 0; i < n; i++) cin >> s[i];

	for (int i = 0; i < n; i++)
	{
		if (s[i] == "AB") {
			bool tmp = func(i, 0, 1);
			if (tmp) continue;
			if (s[i + 1] == "AB") {
				ans[i] = cs[1];
				--a[0]; ++a[1];
			}
			if (s[i + 1] == "BC") {
				ans[i] = cs[1];
				--a[0]; ++a[1];
			}
			if (s[i + 1] == "AC") {
				ans[i] = cs[0];
				--a[1]; ++a[0];
			}
		}
		if (s[i] == "AC") {
			bool tmp = func(i, 0, 2);
			if (tmp) continue;
			if (s[i + 1] == "AB") {
				ans[i] = cs[0];
				--a[2]; ++a[0];
			}
			if (s[i + 1] == "BC") {
				ans[i] = cs[2];
				--a[0]; ++a[2];
			}
			if (s[i + 1] == "AC") {
				ans[i] = cs[0];
				--a[2]; ++a[0];
			}
		}
		if (s[i] == "BC") {
			bool tmp = func(i, 1, 2);
			if (tmp) continue;
			if (s[i + 1] == "AB") {
				ans[i] = cs[1];
				--a[2]; ++a[1];
			}
			if (s[i + 1] == "BC") {
				ans[i] = cs[2];
				--a[1]; ++a[2];
			}
			if (s[i + 1] == "AC") {
				ans[i] = cs[2];
				--a[1]; ++a[2];
			}
		}
		if (f) break;
	}
	if (f) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for (int i = 0; i < n; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n,1);
    vector<bool>ok(n,false);
    ok[0]=true;
    rep(i,m){
        int x,y; cin>>x>>y;
        x--; y--;
        a[x]--; a[y]++;
        if(ok[x])ok[y]=true;
        if(a[x]==0)ok[x]=false;
    }
    int ans=0;
    rep(i,n)if(ok[i])ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3700
#include<iostream>
#include<string>
#include<vector>
#include<thread>
#include<chrono>
int main(){
    int n;
    int count=0;
    int g_flag=0,p_flag=0,w_flag=0,y_flag=0;

    std::cin>>n;
    char arare[n];

    
    for(int i=0;i<n;++i){


        std::cin>>arare[i];
    }
    
    for(int i=0;i<n;++i){

        if(g_flag==0&&arare[i]=='G'){count++;g_flag++;}
        if(p_flag==0&&arare[i]=='P'){count++;p_flag++;}
        if(w_flag==0&&arare[i]=='W'){count++;w_flag++;}
        if(y_flag==0&&arare[i]=='Y'){count++;y_flag++;}
    }
    switch(count){
        case 3:
                std::cout<<"Three"<<std::endl;
                break;
        case 4: 
                std::cout<<"Four"<<std::endl;
                break;
        default:
                break;


    }




}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll a,b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }else if(a >= 6){
        cout << b/2 << endl;
    }else{
        cout << 0 << endl;
    }
    


}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    rep(i, s.size() - 1) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }

        if (i + 2 < s.size() && s[i] == s[i + 2] && s[i] != s[i + 1]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 512
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


X=int(input())
print('Yes' if 30<=X else 'No')

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

int main(){
  int A,B,K;
  cin >>A>>B>>K;
  vector<int> n(0);
  for (int i=1;i<=min(A,B);i++){
    if(A%i==0 && B%i==0){
      n.push_back(i);
    }
  }
  reverse(n.begin(),n.end());
  cout << n.at(K-1)<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc142/tasks/abc142_a
N = read_a_int()

print(((N + 1) // 2) / N)


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

vector<ll> fac(200001); //n!(mod M)
vector<ll> ifac(200001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

vector<int> div(ll x){
    vector<int> p;
    ll P = 2;
    while(x != 1 || P <= sqrt(x)){
        for(int i = 0;;i++){
            if(x % P != 0){
                if(i != 0)p.push_back(i);
                P++;
                break;
            }else{
                x /= P;
            }
        }
    }
    return p;
}
int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0;i < 200001;i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll M,N;
    cin >> N >> M;
    ll ans = 1;
    vector<int> p = div(M);
    for(int i = 0;i < p.size();i++){
        //cout << p[i] << endl;
        ll t = comb(N+p[i]-1,p[i]);
        //cout << t << endl;
        ans *= t;
        ans %= MOD;
    }
    cout << ans << endl;
    //cin >> N;
}

Measured memory_bytes: 3328
# クラスかるほう
# 　貪欲に辺ごとにソートをしてとけばいい
W, H = map(int, input().split())
d = []
for i in range(W):
    x = int(input())
    d.append((x, "x"))

for j in range(H):
    y = int(input())
    d.append((y, "y"))
d.sort()
X = H+1
Y = W+1

ans = 0

for que in d:
    weight, pos = que
    if pos == "x":
        ans += X*weight
        Y -= 1
    else:
        ans += Y*weight
        X -= 1
print(ans)

Measured memory_bytes: 73216
#include <stdio.h>
int main(void){
  int n,a,max=0,sum=0,i;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a);
    if(a>max) max=a;
    sum+=a;
  }
  printf("%d\n",sum-max/2);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
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; }
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


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

    string S; cin >> S;

    set<string> T = {
        "AKIHABARA",

        "KIHABARA",
        "AKIHBARA",
        "AKIHABRA",
        "AKIHABAR",

        "KIHBARA",
        "KIHABRA",
        "KIHABAR",
        "AKIHBRA",
        "AKIHBAR",
        "AKIHABR",

        "KIHBRA",
        "KIHBAR",
        "KIHABR",
        "AKIHBR",

        "KIHBR",
    };

    cout << (T.count(S) == 1 ? "YES" : "NO") << '\n';

    return 0;
}


Measured memory_bytes: 3640
# B - Tap Dance
S = str(input())
ans =''
for i in range(len(S)):
    if (i+1) % 2 == 0:
        if S[i] != 'R':
            ans = 'Yes'
        else:
            ans = 'No'
            print(ans)
            exit()
    else:
        if S[i] != 'L':
            ans = 'Yes'
        else:
            ans = 'No'
            print(ans)
            exit()

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int n,a,b,c,d,m;
	while(scanf("%d",&n)!=EOF){
		m=0;
		for(a=0;a<=9;a++){
			if(n-a>=0){
				for(b=0;b<=9;b++){
					if(n-a-b>=0){
						for(c=0;c<=9;c++){
							if(n-a-b-c>=0){
								for(d=0;d<=9;d++){
									if(n==a+b+c+d)m++;}}}}}}}
		printf("%d\n",m);
	}
}

Measured memory_bytes: 0
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ga,sa,ba = map(int, input().split())
gb,sb,bb = map(int, input().split())

def sub1(n, ga, gb):
    return n - (n//ga)*ga + (n//ga)*gb
def sub2(n, ga, gb, sa, sb):
    ans = -1
    for i in range((n//sa)+1):
        val = sub1(n - (i*sa), ga, gb) + (i*sb)
        ans = max(ans, val)
    return ans
def sub3(n, ga, gb, sa, sb, ba, bb):
    ans = -1
    for i in range((n//ba)+1):
        val = sub2(n - (i*ba), ga, gb, sa, sb) + (i*bb)
        ans = max(ans, val)
    return ans

arg1 = []
arg2 = []
for a,b in [(ga,gb), (sa,sb), (ba,bb)]:
    if a<b:
        arg1.extend([a,b])
    elif a>b:
        arg2.extend([b,a])
d = {
    0: lambda n: n,
    1: sub1,
    2: sub2,
    3: sub3
}
nn = d[len(arg1)//2](n, *arg1)
nnn = d[len(arg2)//2](nn, *arg2)
print(nnn)

Measured memory_bytes: 73444
#include<iostream>
using namespace std;
int main(void)
{
	int x_1,x_2,y_1,y_2;
	cin >> x_1 >> y_1 >> x_2 >> y_2;
	
	int a=x_2-x_1;
	int b=y_2-y_1;
	
	int x_3=x_2-b;
	int y_3=y_2+a;
	int x_4=x_3-a;
	int y_4=y_3-b;
	cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    string s, t;
    cin >> s >> t;
    map<char, vector<ll>> pos;
    rep(i, sz(s)){
        if(!pos.count(s.at(i))){
            pos[s.at(i)].push_back(-1);
        }
    }
    rep(i, sz(s)){
        pos[s.at(i)].push_back(i);
    }
    rep(i, sz(t)){
        if(!pos.count(t.at(i))){
            cout << -1 << endl;
            return 0;
        }
    }
    ll p = -1;
    ll c = 0;
    rep(i, sz(s)){
        pos.at(s.at(i)).push_back(INF);
    }
    rep(i, sz(t)){
        ll l = 0;
        ll r = sz(pos.at(t.at(i))) - 1;
        // .at(l) <= p < .at(r)
        while(r-l > 1){
            ll c = (l+r) / 2;
            if(pos.at(t.at(i)).at(c) <= p){
                l = c;
            }
            else{
                r = c;
            }
        }
        if(pos.at(t.at(i)).at(r) == INF){
            c++;
            p = pos.at(t.at(i)).at(1);
        }
        else{
            p = pos.at(t.at(i)).at(r);
        }
//        cout << t.at(i) << " " << c*(sz(s)) + p << endl;
    }
    cout << c*sz(s) + p + 1 << endl;
}

Measured memory_bytes: 5708
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  string s;
  int k,n;
  cin >> k >> s;
  n = s.size();
  if (k >= n){
    cout << s << '\n';
    return 0;
  }
  for (int i = 0; i < k; i++){
    cout << s[i];
  }
  cout << "...\n";
  return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' ) {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
ll func(V & a,ll b){
	ll res=0LL;
	repi(itr,a){
		res+=abs(b+(*itr));
	}
	return res;
}
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V a(n);
	rep(i,n){
		cin>>a[i];
		a[i]-=(i+1);
		a[i]*=-1LL;
		clog<<a[i]<<endl;
	}
	//=----------------//triple tharch
	pair<ll,ll>down;
	pair<ll,ll>up;
	pair<ll,ll>pup,pdown;
	ll dis=2e10;
	down=mp(-1e10,func(a,-1e10));
	up = mp(1e10, func(a,1e10));
	while(down.F+2 < up.F){
		pup.F=down.F+2*(up.F-down.F)/3;
		pdown.F = down.F + (up.F - down.F) / 3;
		pup.S=func(a,pup.F);
		pdown.S=func(a,pdown.F);
	//	clog<<down.F<<" "<<pdown.F<<" "<<pup.F<<" "<<up.F<<endl;
	//	clog << down.S << " "<< pdown.S << " " << pup.S << " " << up.S <<endl <<endl;
		if(pdown.S <pup.S ){
			up=pup;
		}else{
			down=pdown;
		}
	}

	//----------------//
	cout<<min(up.S,min(down.S,min(pup.S,pdown.S)))<<endl;
}
/*
|a-b|:a-b or b-a

2 2 3 5 5
|2-b-1| |2-b-2| |3-b-3| |4-b-5| |5-b-5|

|1-b| |b| |b| |1-b| |b| =>2

|2-b-6| |2-b-5| |3-b-4| |4-b-3| |5-b-2| |6-b-1|

|4+b| |3+b| |1+b| |1-b| |3-b| |5-b|
|1-b| |1+b| |3-b| |3+b| |4+b| |5-d|

-4->

|1-b-1| |2-b-1| |3-b-1| |4-b-2| |5-b-3| |6-b-4|
|1-b| |1-b|  |2-b| |2-b| |2-b| |2-b|
0=>10
1=>4
2->2
3->8
*/

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

int main() {
  int N, A;
  cin >> N >> A;
    
  if ( N % 500 == 0 ) {
    cout << "Yes" << endl;
  }
  else {
    if ( N % 500 <= A ) {
      cout << "Yes" << endl;
    }
    if ( N % 500 > A ) {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef long long ll;
const int MAX_N=1000,MAX_M=1000;
int N,M,A,B;

char t[MAX_N][MAX_M+1];
string sig="<^>v";
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
	cin>>N>>M>>A>>B;
	int s=N*M/2,sa=M/2*N,sb=N/2*M;
	bool flg,flg2=false;
	if (A<=s-sb){
		if (B<=sb){
			flg=true;
		}else{
			flg=false;
		}
	}else if (A<=sa){
		if (N*M%2){
			if (A+B<=s){
				flg=true;
				if ((sa-A)%2 && A+B==s){
					flg2=true;
				}
			}else{
				flg=false;
			}
		}else{
			if (A+B<=s){
				if ((sa-A)%2 && A+B==s){
					flg=false;
				}else{
					flg=true;
				}
			}else{
				flg=false;
			}
		}
	}else{
		flg=false;
	}
	int a=0,b=0;
	if (flg){
		cout<<"YES"<<endl;
		REP(i,N)REP(j,M)t[i][j]='.';
		if (flg2){
			int n,m;
			n=N-3;
			m=M-3;
			REP(i,4){
				t[n][m]=sig[i];
				t[n+dy[i]][m+dx[i]]=sig[(i+2)%4];
				n+=dy[i]*2;
				m+=dx[i]*2;
			}
			a=b=2;
		}
		if (N%2){
			REP(i,M/2){
				if (flg2 && i==M/2-1){
					continue;
				}
				t[N-1][i*2]='<';
				t[N-1][i*2+1]='>';
				a++;
			}
		}
		if (M%2){
			REP(i,N/2){
				if (flg2 && i==N/2-1){
					continue;
				}
				t[i*2][M-1]='^';
				t[i*2+1][M-1]='v';
				b++;
			}
		}
		REP(n,N/2){
			REP(m,M/2){
				if (flg2 && n==N/2-1 && m==M/2-1){
					continue;
				}
				if (a<A){
					REP(i,2){
						t[n*2+i][m*2]='<';
						t[n*2+i][m*2+1]='>';
					}
					a+=2;
				}else{
					REP(i,2){
						t[n*2][m*2+i]='^';
						t[n*2+1][m*2+i]='v';
					}
					b+=2;
				}
			}
		}
		REP(i,N){
			REP(j,M){
				if (t[i][j]=='<' && a>A){
					t[i][j]=t[i][j+1]='.';
					a--;
				}
				if (t[i][j]=='^' && b>B){
					t[i][j]=t[i+1][j]='.';
					b--;
				}
			}
		}
		REP(i,N){
			cout<<t[i]<<endl;
		}
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

int main() {
  long long n,a,b;
  cin >> n >> a >> b;
  long long k = n/(a+b);
  long long l = n%(a+b);
  long long m;
  if(l>a)
    m = a;
  else
    m = l;
  cout << a*k+m << endl;
  
}


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

#define MAX 1000

int main(){
  int i, j, m, q, x, y, c[MAX+1][MAX+1];
  char X[MAX], Y[MAX];

  scanf("%d",&q);

  for(i=0;i<strlen(X);i++)
    c[i][0] = 0;
  for(j=0;j<strlen(Y);j++)
    c[0][j] = 0;

  for(m=0;m<q;m++){
    scanf("%s",X);
    scanf("%s",Y);
    x = strlen(X);
    y = strlen(Y);
    for(i=0;i<x;i++)
      c[i][0] = 0;
    for(j=0;j<y;j++)
      c[0][j] = 0;

    for(i=1;i<=x;i++){
      for(j=1;j<=y;j++){
	if(X[i-1] == Y[j-1])c[i][j] = c[i-1][j-1] + 1;
	else if(c[i-1][j] >= c[i][j-1])c[i][j] = c[i-1][j];
	else c[i][j] = c[i][j-1];
      }
    }
    printf("%d\n",c[x][y]);
  }

  return 0;
}

Measured memory_bytes: 4516
import java.util.*

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val size = scanner.nextInt()

    val list = mutableListOf<Int>()
    for (i in 1..size) {
        list.add(scanner.nextInt())
    }

    val max = list.max() ?: throw IllegalArgumentException()
    var shouldFill = false
    var count = 0

    for (i in 1 .. max) {
        list.forEach {
            val result = it - i
            if (result >= 0 && !shouldFill) {
                shouldFill = true
                count += 1
            } else if (result < 0) {
                shouldFill = false
            }
        }
        shouldFill = false
    }

    println(count)
}

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

#define EPS 1e-8

struct Point{double x,y,z,angle;};

double dot(Point a,Point b)
{
  return a.x*b.x + a.y*b.y + a.z*b.z;
}
double dist(Point a)
{
  return sqrt(a.x*a.x + a.y*a.y + a.z*a.z);
}
double angle(Point a,Point b)
{
  return acos(dot(a,b)/(dist(a)*dist(b)));
}


int main()
{
  int n,m,ans;
  double x,y,z,phi;
  int i,j;
  while(cin>>n,n){
    vector<Point>star(n);
    for(i=0;i<n;i++){
      cin>>x>>y>>z;
      Point s={x,y,z,0.0};
      star[i]=s;
    }
    cin>>m;
    vector<Point>tele(m);
    for(j=0;j<m;j++){
      cin>>x>>y>>z>>phi;
      Point t={x,y,z,phi};
      tele[j]=t;
    }

    ans=0;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	if(angle(star[i],tele[j])-tele[j].angle>EPS)continue;
	ans++;
	break;
      }
    }

    cout<<ans<<endl;
  }
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int left = 0;
    int right = 0;
    char l = s[0];
    char r = s[n-1];
    for(int i=1; i<n;i++){
        if(s[i]!=l){
            left++;
            l = s[i]; 
        }
        if(s[n-1-i]!=r){
            right++;
            r = s[n-1-i]; 
        }
    }
    cout << (right < left? right: left) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	sort (s.begin(),s.end());
	cout<<(s=="abc"?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int n;
int a[20];
int flg[10000000];

void dfs(int x,int sum){
  if(x==n){
    flg[sum]=1;
    return;
  }
  dfs(x+1,sum);
  dfs(x+1,sum+a[x]);
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  dfs(0,0);
  int q,key;
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if( flg[key]==1 ){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}

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

int bubbleSort(int A[], int N) {
        int sw = 0;
        bool flag = 1;
        for (int i = 0; flag; i++) {
                flag = 0;
                for (int j = N - 1; j >= i + 1; j--) {
                        if(A[j] < A[j - 1]) {
                        swap(A[j], A[j - 1]);
                        flag = 1;
                        sw++;
                        }
                }
        }
        return sw;
}

int main() {
        int A[100], N, sw;
        cin >> N;
        for(int i = 0; i < N; i++) cin >> A[i];
        sw = bubbleSort(A, N);
        for(int i = 0; i < N; i++) {
                if (i) cout << " ";
                cout << A[i];
        }
        cout << endl;
        cout << sw << endl;
        return 0;
}

Measured memory_bytes: 3060
N, M = list(map(int, input().split()))

td = [[0 for i in range(2)] for j in range(N)]

for n in range(N):
    A, B = list(map(int, input().split()))
    td[n][0] = A
    td[n][1] = B

td = sorted(td, key=lambda x: x[0])

m = M
kin = 0
for t in range(len(td)):  
    kosu = min(m, td[t][1])
    kin += td[t][0] * kosu
    m -= kosu

print(kin)

Measured memory_bytes: 23588
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int D, N;
    cin >> D >> N;
    int seq1 = 0, seq2 = 0, ans1, ans2;
    if (D == 0) {
        int ans = N;
        if (N == 100)
            ans += 1;
        cout << ans << endl;
        return 0;
    } else if (D == 1) {
        int ans = N * 100;
        if (N == 100)
            ans += 100;
        cout << ans << endl;
        return 0;
    } else {
        int ans = N * 10000;
        if (N == 100)
            ans += 10000;
        cout << ans << endl;
        return 0;
    }
}

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

#include<vector>
#include<map>
#include<math.h>
#include<stack>
#include<unordered_map>

using namespace std;
const int N = 100010;
long long a[N], w[N];
const int M = 107;
long long dp[M][N];
int main() {

    long long n, weight; cin >> n >> weight;
    for (int i = 1; i <= n; i ++) cin >> a[i] >> w[i];
    memset(dp, 0, sizeof(dp));
//    for (int i = 1; i <= n; i ++) {
//        for (int j = 1; j <= weight; j ++)
//            if (j >= a[i]) dp[i][j] = max(w[i], dp[i - 1][j]);
//            else dp[i][j] = max(dp[i][j], dp[i - 1][j]);
//    }

    for (int i = 1; i <=n; i ++) {
        for (int j = 1; j <= weight; j ++) {
            if (j - a[i] >= 0)
                dp[i][j] = max(dp[i - 1][j], w[i] + dp[i - 1][j - a[i]]);
            else dp[i][j] = dp[i - 1][j];
        }
    }
//    for (int i = 1; i <= n; i ++) {
//        for (int j = 1; j <= weight; j ++) {
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }

    cout << dp[n][weight];
    return 0;
}

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

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n,p;
  scanf("%ld %ld", &n, &p);
  char s[n+1];
  scanf("%s", s);
  long sum = 0;
  long num;
  if (p == 2) {
    for (long i = 0; i < n; i++) {
      num = s[i]-'0';
      if (num%2 == 0) {
        sum += i+1;
      }
    }
  } else if (p == 5) {
    for (long i = 0; i < n; i++) {
      num = s[i]-'0';
      if (num%5 == 0) {
        sum += i+1;
      }
    }
  } else {
    long mod_list[n];
    mod_list[0] = s[n-1]-'0';
    mod_list[0] %= p;
    long unit = 1;
    for (long i = 1; i < n; i++) {
      num = s[n-1-i]-'0';
      unit = (unit*10)%p;
      mod_list[i] = mod_list[i-1];
      mod_list[i] += num*unit;
      mod_list[i] %= p;
    }
    qsort(mod_list, n, sizeof(long), cmpnum);
    long count = 0;
    for (long i = 0; i < n-1; i++) {
      count++;
      if (mod_list[i] != mod_list[i+1]) {
        sum += count*(count-1)/2;
        count = 0;
      }
    }
    count++;
    sum += count*(count-1)/2;
    count = 0;
    for (long i = 0; i < n; i++) {
      if (mod_list[i] == 0) {
        count++;
      } else {
        break;
      }
    }
    sum += count;
  }
  printf("%ld\n", sum);

  return 0;
}

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

int main(){
    int X, Y, Z;
    int K;
    cin >> X >> Y >> Z;
    cin >> K;
    vector<ll> A(X), B(Y), C(Z);

    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    sort(B.begin(), B.end());
    reverse(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());

    
    vector<ll> ABC;
    for (int a = 0; a < X; a++) {
        for (int b = 0; b < Y; b++) {
            if ((a + 1) * (b + 1) > K) break;
            for (int c = 0; c < Z; c++) {
                if ((a + 1) * (b + 1) * (c + 1) > K) break;
                ABC.push_back(A[a] + B[b] + C[c]);
            }
        }
    }

    sort(ABC.begin(), ABC.end());
    reverse(ABC.begin(), ABC.end());

    for (int i = 0; i < K; i++) {
        cout << ABC[i] << '\n';
    }
}


Measured memory_bytes: 1404
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n = int(sys.stdin.readline())
    s = (n * (n + 1)) // 2
    # print(s)
    three = (n // 3)
    s -= 3*((three*(three+1))//2)
    five = (n // 5)
    s -= 5 * ((five * (five + 1)) // 2)
    fif = (n // 15)
    s += 15*((fif*(fif+1))//2)
    print(s)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 61944
S = list(map(str, input()))
S_reverse = list(reversed(S))
index_1 = 0
index_2 = 0
index_3 = 0

for i in range(0, len(S)):
    if S[i] != S_reverse[i]:
        index_1 = 1
        break

left = int((len(S) - 1) / 2)
S_left = S[0:left]
S_left_reverse = list(reversed(S_left))
right = int((len(S) + 3) / 2) - 1
S_right = S[right:len(S)]
S_right_reverse = list(reversed(S_right))


for i in range(0, len(S_left)):
    if S_left[i] != S_left_reverse[i]:
        index_2 = 1
        break

for i in range(0, len(S_right)):
    if S_right[i] != S_right_reverse[i]:
        index_3 = 1
        break

index = index_1 + index_2 + index_3
if index == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();
		boolean flag=true;

		char s[][]=new char[h+2][w+2];

		for(int i=0;i<h+2;i++){
            for(int j=0;j<w+2;j++) s[i][j]='.';
        }

		for(int i=1;i<=h;i++){
			String str=sc.next();
			for(int j=1;j<=w;j++){
				s[i][j]=str.charAt(j-1);
			}
		} 

		int[] x={1,0,-1,0};
		int[] y={0,1,0,-1};

		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(s[i][j]=='#') {
					boolean ifor=false;
					for(int k=0;k<4;k++){
                        if(s[i+x[k]][j+y[k]]=='#'){
                        	ifor=true;
                        }
                    }
                    if(!ifor){
                    	flag=false;
                    }
				}
			}
		}
		if(flag) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 21844
A, B, C = tuple(map(int, input().split()))
if A == B:
    if A != C:
        print("Yes")
    else:
        print("No")
elif A == C:
    if A != B:
        print("Yes")
    else:
        print("No")
elif B == C:
    if A != B:
        print("Yes")
    else:
        print("No")
else:
    print("No")
    

Measured memory_bytes: 38256
#include<math.h>
#include<iostream>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)

using namespace std;

int cost[200][200], tim[200][200],dist[200];
int x[200][200];
bool vis[200];
int M,N;

void dij(int p, int q, int r){
	int i,j,k,l,m,n,mn;
	rep(i,M)rep(j,M)x[i][j]= ((r==0)?(cost[i][j]):(tim[i][j]));
	rep(i,M)vis[i]=false,dist[i]=INF;
	dist[p-1]=0;
	for(;;){
		k=-1,mn=INF;
		rep(i,M)if(!vis[i]&&dist[i]<mn){mn=dist[i],k=i;}
		if(k==-1 || mn>=INF) break;
		if(k==q-1)break;
		vis[k]=true;
		rep(i,M)if(!vis[i])dist[i]=min(dist[i],dist[k]+x[k][i]);
	}
	cout<<dist[q-1]<<endl;
}

int main(){
	int i,j,k,l,m,n;
	
	while(cin>>N>>M){
		if((N|M)==0) break;

		rep(i,M){
			dist[i]=INF; 
		    rep(j,M){
			  if(i==j) {cost[i][j]=tim[i][j]=0; continue;}
			  cost[i][j]=tim[i][j]=INF;
			}
		}
		rep(i,N){
			int a,b,c,t;
			cin>>a>>b>>c>>t;
			a--; b--;
			cost[a][b]=cost[b][a]=c; tim[a][b]=tim[b][a]=t;
		}
		cin>>k;
		rep(i,k){
			int p,q,r;
			cin>>p>>q>>r;
			dij(p,q,r);
		}
	}
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a==1 && b==2)
        cout << 3 << endl;
        else if(a==2 && b==1)
        cout << 3 << endl;
        else if(a==1 && b==3)
        cout << 2 << endl;
        else if(a==3 && b==1)
        cout << 2 << endl;
        else if(a==2 && b==3)
        cout << 1 << endl;
        else if(a==3 && b==2)
        cout << 1 << endl;       
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M, Q = map(int, input().split())

mat = [[0]*(N+1) for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, input().split())
    mat[a][b] += 1


def solve():

    for i in range(N+1):
        for j in range(1, N+1):
            mat[i][j] += mat[i][j-1]

    ans = []

    for _ in range(Q):
        ql, qr = map(int, input().split())
        tmp = 0
        for i in range(ql, qr+1):
            tmp += mat[i][qr] - mat[i][ql-1]
        ans.append(tmp)

    for a in ans:
        print(a)


def solve2():

    for i in range(1, N+1):
        for j in range(1, N+1):
            mat[i][j] += mat[i-1][j] + \
                mat[i][j-1] - mat[i-1][j-1]

    ans = [0]*Q
    for i in range(Q):
        ql, qr = map(int, input().split())
        t = mat[qr][qr] - mat[ql-1][qr] - mat[qr][ql-1] + mat[ql-1][ql-1]
        ans[i] = t

    for a in ans:
        print(a)


solve2()


Measured memory_bytes: 17532
#include <stdio.h>
int main(void){
    // Your code here!
    char str[3];
    int i,j=0;
    gets(str);
    for(i=0;i<3;i++){
        if(str[i]=='7'){
            j++;
        }
    }
    if(j>0){
        printf("Yes\n");
    }
//    printf("%d",j);
    if(j==0){
        printf("No\n");
    }
    return 0;
}

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

int main()
{
    int k,n,mx=-1;
    cin >> k >> n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for(int i=2;i<=n;i++)
    {
        mx = max(mx,a[i]-a[i-1]);
    }
    mx = max(mx,k-a[n]+a[1]); // handles crossing northmost point
    cout << k-mx << endl;
}

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

long long n, m, q;
const long long Q = 55;
vector<long long> A(Q), B(Q), C(Q), D(Q);

long long ans = 0;

void dfs(long long lastNum, vector<long long> numList){
    if((long long)numList.size() == n){
        long long t = 0;
        for(long long i = 0; i < q; i++){
            if(numList[B[i]] - numList[A[i]] == C[i]){
                t += D[i];
            }
        }
        ans = max(ans, t);
        return;
    }else{
        for(long long i = lastNum; i <= m; i++){
            vector<long long> tmp = numList;
            tmp.push_back(i);
            dfs(i, tmp);
        }
    }
}

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

    cin >> n >> m >> q;
    for(long long i = 0; i < q; i++){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;
        B[i]--;
    }

    dfs(1, {});

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n;
vector<P> contests;
Int l, r;
Int ans;
multiset<Int> rs;

Int calc(Int l1, Int r1, Int l2, Int r2, Int newr){
    return max(max(min(r1,newr)-l1+1,0LL) + max(r2-l2+1, 0LL),
               max(r1-l1+1,0LL) + max(min(newr,r2)-l2+1, 0LL));
}

int main(){
    cin >> n;
    Int lmax = 0, lmaxcnt = 0;
    Int rmin = LINF;
    
    for(int i = 0;i < n;i++){
        cin >> l >> r;
        rmin = min(rmin, r);
        rs.insert(r);
        contests.push_back(P(l, r));
        if(lmax < l){
            lmax = l;
            lmaxcnt = 1;
        }
        else if(lmax == l){
            lmaxcnt++;
        }
    }
    if(lmaxcnt > 1){
        Int lmaxrmax =0;
        for(auto p: contests){
            Int l = p.first, r =p.second;
            if(l == lmax)lmaxrmax = max(lmaxrmax, r);
        }
        ans = max(ans, max(0LL, rmin - lmax+1) + max(0LL,lmaxrmax - lmax+1));
    }
    
    sort(contests.rbegin(), contests.rend());
    Int lmaxrmax = LINF;
    for(auto p: contests){
        Int l = p.first, r = p.second;
        if(lmaxrmax != LINF){
            ans = max(ans, calc(lmax, lmaxrmax, l, r, *rs.begin())); 
        }
        lmaxrmax = min(lmaxrmax, r);
        rs.erase(rs.find(r));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7012
import java.util.*;
public class Main {

	final int MAX = 999999;

	private boolean isPrime(int n){
		for(int i=2; i * i <= n; i++){
			if(n % i == 0){
				return false;
			}
		}
		return true;
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		boolean [] prime = new boolean[MAX + 1];
		for(int i=2; i < prime.length; i++){
			prime[i] = true;
		}
		for(int i=2; i * i < MAX; i++){
			if(isPrime(i)){
				for(int j = i + i; j <= MAX; j += i){
					prime[j] = false;
				}
			}
		}

		while(sc.hasNext()){
			int n = sc.nextInt();
			int count = 0;
			for(int i = 2; i <= n; i++){
				if(prime[i]){
					count++;
				}
			}
			System.out.println(count);
		}

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

	}

}

Measured memory_bytes: 13000
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))


def solve():
    N, X, M = it()
    if N == 1:
        return X % M
    value = defaultdict(int)
    history = defaultdict(int)
    cur = 0
    cnt = 0
    for i in range(N):
        if X in history:
            break
        value[X] = cur
        history[X] = i
        cnt += 1
        cur += X
        X = X * X % M
    period = i - history[X]
    cur += (N - cnt) // period * (cur - value[X])
    for i in range((N - cnt) % period):
        cur += X
        X = X * X % M
    return cur

if __name__ == '__main__':
    print(solve())

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

const ll MOD=LLONG_MAX;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int cnt[200];
int main(){
	int n,K;cin>>n>>K;
	rep(i,K){
		int d;cin>>d;
		rep(j,d){
			int x;cin>>x;x--;
			cnt[x]++;
		}
	}
	int ans=0;
	rep(i,n){
		if(!cnt[i])ans++;
	}
	cout<<ans<<endl;
}

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

int main() {
  string s;
  cin >> s;
  
  int out = 0;
  
  for (int i = 0; i < s.size(); i++){
    if (s[i] == '1'){
      out += 1;
    }
  }
  
  cout << out << endl;
}

Measured memory_bytes: 256
a,b =map(str,input().split())

if a == "H" and b == "H":
	print("H")
	
if a == "D" and b == "H":
	print("D")
	
if a == "H" and b == "D":
	print("D")

if a == "D" and b == "D":
	print("H")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
char s[20];
int n,ans,p[maxn];
signed main()
{
	scanf("%lld",&n);
	for(register int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		int len=strlen(s+1);
		sort(s+1,s+len+1);
		for(register int j=1;j<=len;j++)
			p[i]=(p[i]*13331+s[j]-96);
	}
	sort(p+1,p+n+1);
	int pre=-1,cnt=0;
	for(register int i=1;i<=n;i++)
		if(p[i]==pre)
			cnt++;
		else
		{
			ans+=cnt*(cnt-1)/2;
			cnt=1;
			pre=p[i];
		}
	ans+=cnt*(cnt-1)/2;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;

int main() {
	long L, R, ans = 0;
	cin >> L >> R;
	if (673 > R - L) {
		ans = LONG_MAX;
		for (long i = L; i < R; ++i) {
			for (long j = 1 + L; j <= R; ++j) ans = min(ans, i * j % 2019);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
/*  ex4_1
    B30095    */
#include <stdio.h>
#include <math.h>
 
int main(void){
    int TreesNum, d;
    scanf("%d %d", &TreesNum, &d);

    int visibleTreesNum = 2 * d + 1;  // number of visible trees
    int inspectorNum = ceil((double)TreesNum / visibleTreesNum);  // number of inspectors needed
    
    printf("%d", inspectorNum);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
	int n, i, j, min, k=0, m;
	scanf("%d", &n);
	int a[n];
	for(i = 0; i < n; i++)scanf("%d", &a[i]);
	
	for(i = 0; i < n; i++){
		min = i;
		for(j = i; j < n; j++){
			if(a[j] < a[min])min = j;
		}
		if(i != min){
			m = a[i];
			a[i] = a[min];
			a[min] = m;
			k++;
		}
	}
	
	for(i =0; i < n; i++){
		if(i!=n-1)printf("%d ", a[i]);
		else printf("%d\n", a[i]);
	}
	printf("%d\n", k);
	
	return 0;
}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, step;
char s[200005];

int pos = 1, toggled;

void print_string(int p, int q){
	FI(i, p, n){
		if(toggled) printf("%c", (int)'A' + 'B' - s[i]);
		else printf("%c", s[i]);
	}
	FI(i, 1, p - 1){
		if(toggled) printf("%c", (int)'A' + 'B' - s[i]);
		else printf("%c", s[i]);
	}
	printf("\n");
	exit(0);
}
int main(){
	scanf("%d %d %s", &n, &step, s + 1);
	FI(i, 1, step){
		if((s[pos] == 'A') ^ toggled){
			s[pos] = 'A' + 'B' - s[pos];
		}
		else{
			pos++;
			toggled ^= 1;
			if(pos == n + 1){
				step -= i;
				pos = 1;
				goto gg;
			}
		}
//		printf("%d: %s [p = %d, tog %d]\n", i, s + 1, pos, toggled);
	}
	
	step = 0;
	
	gg:;
	step %= (n + n);
	
	FI(i, 1, step){
		if((s[pos] == 'A') ^ toggled){
			s[pos] = 'A' + 'B' - s[pos];
		}
		else{
			pos++;
			toggled ^= 1;
			if(pos == n + 1) pos = 1;
		}
	}
	
	print_string(pos, toggled);
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] v = new int[n];
    int[] c = new int[n];
    for(int i = 0;i<n;i++){
      v[i] = sc.nextInt();
    }
    for(int i = 0;i<n;i++){
      c[i] = sc.nextInt();
    }
    int total = 0;
    for(int i=0;i<n;i++){
      if(v[i]-c[i]>0){
        total+=v[i]-c[i];
      }
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 35876