akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> s >> t;
    YN(s.at(0) == t.at(2) && s.at(1) == t.at(1) && s.at(2) == t.at(0))
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

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

int main(void){
  int N,Q;
  while(cin>>N>>Q,N){
    int c[100] = {};
    while(N--){
      int M;
      cin>>M;
      while(M--){
        int day;
        cin>>day;
        c[day]++;
      }
    }
    int maxm = 0;
    FOR(i,1,100)maxm = max(maxm,c[i]);
    if(maxm<Q) cout<<0<<endl;
    else{
      FOR(i,1,100){
        if(c[i]==maxm){
          cout<<i<<endl;
          break;
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
 	public static void main (String[] args) {
      Scanner sc = new Scanner (System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      
      System.out.println(a<10&&b<10 ? a*b : "-1");
      	
      	
    }
}

Measured memory_bytes: 35684
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderBeginnerContest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var g1 = new int[] { 1,3,5,7,8,10,12};
            var g2 = new int[] { 4,6,9,11};

            var xy = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            if (g1.Contains(xy[0]))
            {
                if(g1.Contains(xy[1]))
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            else if(g2.Contains(xy[0]))
            {
                if (g2.Contains(xy[1]))
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            else if(xy[0] == 2)
            {
                if (xy[1] == 2)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define VectorType string
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define YesNo(b) b?cout << "Yes" << endl: cout << "No" << endl
#define YESNO(b) b?cout << "YES" << endl: cout << "NO" << endl
#define All(x) (x).begin(),(x).end()
#define VectorSumTotal(a) accumulate(a.begin(), a.end(), 0LL)
#define VectorStringTotal(a) accumulate(a.begin(), a.end(), string())
#define VectorSumMin(a) *std::min_element(a.begin(), a.end())
#define VectorSumMax(a) *std::max_element(a.begin(), a.end())
#define SortAscending(a) sort(a.begin(), a.end())
#define SortDescending(a) sort(a.begin(), a.end(), greater<>())


vector<VectorType> VectorInput(long long int a) {
    vector<VectorType> returnVector;
    VectorType temp;
    for (int i = 0; i < a; ++i) {
        cin >> temp;
        returnVector.push_back(temp);
    }
    return returnVector;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    long int answer = 0;
    for (int i = 1; i <= N; ++i) {
        answer += i;
    }
    cout << answer << endl;
}

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

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

flg = True
for i in range(N):
    if t[i] % 2 == 1:
        flg = False
        break

print('YES' if flg else 'NO')


Measured memory_bytes: 3888
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
using graph = vector<vector<int>>;
typedef long long ll;


int main() {
	ll n,m,o;
	cin >> n;
	m = n - n % 10;
	m = m / 10;
	o = m - m % 10;
	o = o / 10;
	if (n % 10 == 7) {
		cout << "Yes" << endl;
	}
	else if (m%10 == 7) {
		cout << "Yes" << endl;
	}
	else if (o == 7) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
int main(){
  int i,j,n;
  int maxv,minv;
  int *R;

  scanf("%d",&n);
  R=malloc(n*sizeof(int));
  for(i=0;i<n;i++)
    {
      scanf("%d",&R[i]);
    }
  minv=R[0];
  maxv=R[1]-R[0];
  for(j=1;j<n;j++)
    {
      if(maxv<R[j]-minv)
	{
	  maxv = R[j]-minv;
	}
      if(minv>R[j])
	{
	  minv = R[j];
	}
    }
  printf("%d\n",maxv);
  return 0;
}
	  



Measured memory_bytes: 2532
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#define LL long long
using namespace std;
vector<int>a,b;
map<LL,int>Hash;
set<int>f[1000005];
int main(void)
{
	int i,j,k,x,y,n,found=0;
	scanf("%d",&n);
	for(i=1;i<=2*n-2;++i)
	{
		scanf("%d%d",&x,&y);
		++Hash[1LL*x*n+y];
		++Hash[1LL*y*n+x];
		f[x].insert(y);
		f[y].insert(x);
		if(Hash[1LL*x*n+y]==2)a.push_back(x),b.push_back(y);
	}
	for(i=0;i<a.size();++i)
	{
		if(Hash[1LL*a[i]*n+b[i]]==2)
		{
			++found;
			if(f[a[i]].size()<f[b[i]].size())swap(a[i],b[i]);
			while(f[b[i]].size())
			{
				j=*f[b[i]].begin();
				Hash[1LL*a[i]*n+j]+=Hash[1LL*b[i]*n+j];
				Hash[1LL*j*n+a[i]]+=Hash[1LL*b[i]*n+j];
				Hash[1LL*b[i]*n+j]=Hash[1LL*j*n+b[i]]=0;
				f[a[i]].insert(j);
				f[j].erase(b[i]);
				f[j].insert(a[i]);
				if(Hash[1LL*a[i]*n+j]==2)a.push_back(a[i]),b.push_back(j);
				f[b[i]].erase(j);
			}
		}
	}
	if(found==n-1)printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 98040
#include <cstdio>
#include <iostream>
typedef long long ll;
#define ri register int
const int N=9e5+5,mod=1e9+7;
int power[N],fac[N],ifac[N];
inline int C(ri n,ri m){
	return m<0||n<m?0:(ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
int main(){
	ri n,m,k,i,cnt,x,ans;
	scanf("%d%d%d",&n,&m,&k);
	cnt=n+m+k;
	fac[0]=power[0]=1;
	for(i=1;i<=cnt;++i)
		fac[i]=(ll)fac[i-1]*i%mod,
		power[i]=power[i-1]*3ll%mod;
	ifac[cnt]=fpow(fac[cnt],mod-2);
	for(i=cnt;i;--i)
		ifac[i-1]=(ll)ifac[i]*i%mod;
	x=1;
	ans=0;
	if(k>m) std::swap(k,m);
	for(i=0;i<=m+k;++i){
		ans=(ans+(ll)C(i+n-1,i)*power[m+k-i]%mod*x)%mod;
		if(i<k) x=x*2%mod;
		else if(i<m) x=(x*2ll-C(i,k))%mod;
		else x=(x*2ll-C(i,k)-C(i,i-m))%mod;
	}
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int c[n],in[101]={};
    stack<int>cat;
    for(int i=0;i<n;i++)cin>>c[i];
    for(int i=0;i<n;i++){
        if(c[i]>0){
            if(in[c[i]]){
                cout<<i+1<<endl;
                return 0;
            }
            in[c[i]]=1;
            cat.push(c[i]);
        }
        if(c[i]<0){
            c[i]*=-1;
            if(cat.size()==0 || cat.top()!=c[i]){
                cout<<i+1<<endl;
                return 0;
            }
            in[c[i]]=0;
            cat.pop();
        }
    }
    cout<<"OK"<<endl;
    return 0;
}


Measured memory_bytes: 3100
# python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
n = ii()
slist = []
for _ in range(n):
    slist.append(input())

print(len(set(slist)))


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

int main() {
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<4;i++) {
		if(i==0) {
			if(s[i]=='Y') {
				ans++;
			}
		}
		else if(i==1) {
			if(s[i]=='A') {
				ans++;
			}
		}
		else if(i==2) {
			if(s[i]=='K') {
				ans++;
			}
		}
		else {
			if(s[i]=='I') {
				ans++;
			}
		}
	}
	if(ans==4) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll X, ll Y, ll Z) {
  ll tmp;
  tmp = X;
  X = Y;
  Y = tmp;
  tmp = X;
  X = Z;
  Z = tmp;
  cout << X << " " << Y << " " << Z << endl;
}

int main() {
  ll X;
  scanf("%lld", &X);
  ll Y;
  scanf("%lld", &Y);
  ll Z;
  scanf("%lld", &Z);
  solve(X, Y, Z);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n,a[maxn],ans=0;
map<int,int> m;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> a[i];
	rep(n){
		if(i>0) m[a[i-1]+(i-1)]++;
		ans+=m[i-a[i]];
	}
	print1(ans);
	return 0;
}

Measured memory_bytes: 27912
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();

    vvl v(26);
    rep(i, n) {
        v[s[i] - 'a'].pb(i);
    } 
    rep(i, n) {
        v[s[i] - 'a'].pb(i+n);
    }

    ll p = 0;
    ll ans = 0;
    rep(i, m) {
        ll c = t[i] - 'a';
        if(v[c].size() == 0) {
            out(-1);
            re0;
        }
        p = *lower_bound(all(v[c]), p) + 1;
        if(p >= n) {
            p -= n;
            ans += n;
        }
    }
    
    ans += p;

    out(ans);
    re0;
}

Measured memory_bytes: 2800
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int n, m;
	cin >> n >> m;
	vector<queue<int>> ab(m + 1);
	priority_queue<int> q;
	int a, b;
	REP(i, n) {
		cin >> a >> b;
		if(a <= m)
			ab[a].push(b);
	}
	int ans = 0;
	for (int i = 1; i <= m; i++){
		for (int j = 0; !ab[i].empty(); j++) {
			q.push(ab[i].front());
			ab[i].pop();
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans;
}

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

int main(){
  int k;
  string s;
  cin >> k;
  cin >> s;
  if(s.length() <= k) cout << s << endl;
  else {
    string t = s.substr(0, k) + "...";
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
typedef pair<int,p> P;

int w,h,used[1<<10][20][20],bt[20][20];;
char c[20][20];
int d[5]={-1,0,1,0,-1};
int sx,sy,n;

int bfs(){
  memset(used,0,sizeof(used));
  queue<P> q;
  q.push(P(0,p(sx,sy)));
  while(!q.empty()){
    int s=q.front().first,x=q.front().second.first,y=q.front().second.second;
    q.pop();
    if(s==n-1)return used[s][y][x];
    for(int i=0;i<4;i++){
      int nx=x+d[i],ny=y+d[i+1];
      if(nx<0||w<=nx||ny<0||h<=ny||c[ny][nx]=='x')continue;
      int ns=s|bt[ny][nx];
      if(!used[ns][ny][nx])
	q.push(P(ns,p(nx,ny))),used[ns][ny][nx]=used[s][y][x]+1;
    }
  }
  return -1;
}

int ans(){
  memset(used,0,sizeof(used));
  memset(bt,0,sizeof(bt));
  n=1;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      cin>>c[i][j];
      if(c[i][j]=='o')sx=j,sy=i;
      if(c[i][j]=='*')bt[i][j]=n,n*=2;
    }
  return bfs();
}

int main(){
  while(cin>>w>>h,w)cout<<ans()<<endl;
  return 0;
}

Measured memory_bytes: 4828
n, k, q = map(int, input().split())
ls_a = [int(input()) for _ in range(q)]

ls_p = [k] * n
ls_c = [0] * n

for i in range(q):
    ls_c[ls_a[i] - 1] += 1

for j in range(n):
    ls_p[j] += ls_c[j] - q

for l in range(n):
    if ls_p[l] > 0:
        print("Yes")
    elif ls_p[l] <= 0:
        print("No")

Measured memory_bytes: 12568
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, K: int, A: "List[int]"):
    #フェルマーの小定理を最後に使って逆元を求めてもいい
    p = MOD
    a = N

    fac = [1]*(a+1)
    inv = [1]*(a+1)
    finv = [1]*(a+1)

    for i in range(2, a+1):
        fac[i] = fac[i-1] * i % p
        inv[i] = p - (inv[p%i] * (p//i) )% p #拡張ユークリッドの互除法を応用し、逆元をO(1)で求める
        finv[i] = finv[i-1] * inv[i] % p

    def cmb(a, b):
        if a < b or a < 0 or b < 0:
            return 0
        return fac[a] * (finv[b] * finv[a - b] % p) % p

    ans = 0
    A.sort()
    n = A[N-1]
    b = 0
    c = 0
    for i in range(N-1, -1, -1):
        if A[i] == n:
            c += 1
            continue
        else:
            ans = (ans + n * (cmb(N-b, K) - cmb(N-b-c, K)))% MOD
            b += c
            n = A[i]
            c = 1

    ans = (ans + n * (cmb(N-b, K) - cmb(N-b-c, K)))% MOD
    ans_m = 0
    n = A[0]
    b = 0
    c = 0
    for i in range(N):
        if A[i] == n:
            c += 1
            continue
        else:
            ans_m = (ans_m + n * (cmb(N-b, K) - cmb(N-b-c, K)))% MOD
            b += c
            n = A[i]
            c = 1
    ans_m = (ans_m + n * (cmb(N-b, K) - cmb(N-b-c, K)))% MOD
    ans -= ans_m
    if ans < 0:
        ans += MOD
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27568
#include <iostream>

using namespace std;

int main(void){
	int a,b;
	int sum;
	
	cin >> a >> b ;

	sum = a * b;

	if( sum % 2 == 0 ) {
		cout << "Even" << endl;
		return 0;
	}

	cout << "Odd" << endl;
	return 0;
}
	

Measured memory_bytes: 256
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)

bool = false

while bool == false
  bool = true if a[0].to_s.split("").map(&:to_i).select{|t| b.include?(t)}.size == 0
  a[0]+=1
end
p a[0]-1


Measured memory_bytes: 2044
#include<stdio.h>

int main()
{
  int i,n[4],one=0,seven=0,nine=0,four=0;
  for(i=0;i<4;i++)
  {
    scanf("%d",&n[i]);
  }
  
  for(i=0;i<4;i++)
  {
    switch(n[i])
    {
      case 1:one++;
        break;
      case 9:nine++;
        break;
      case 7:seven++;
        break;
      case 4:four++;
       		 break;
      default:break;
    }
  }
    
  if(one==1&&nine==1&&seven==1&&four==1)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
//vector<int> g1;
//g1.push_back(i);

using namespace std;

int main()
{
	string inp;
	cin >> inp;
	if (inp == "SUN") cout << 7;
	if (inp == "MON") cout << 6;
	if (inp == "TUE") cout << 5;
	if (inp == "WED") cout << 4;
	if (inp == "THU") cout << 3;
	if (inp == "FRI") cout << 2;
	if (inp == "SAT") cout << 1;
	return 0;
}



Measured memory_bytes: 256
N = int(input())
lis = [0,26]
num = 26
n = 1
while lis[-1]<N:
    num *= 26
    lis.append(lis[-1]+num)
    n += 1
c = N-lis[-2]-1
ans = ''
for i in range(n):
    ans = chr(c%26+ord('a')) + ans
    c //= 26
print(ans)

Measured memory_bytes: 61860
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000
	
long long gcd(long long a, long long b){
	if (b == 0) return a;
	return gcd(b, a % b);
}
 
long long lcm(long long a, long long b){
	if (b > a) swap(a, b);
	return a / gcd(a, b) * b;
}

int main(){
	
	long long A,B;
	cin>>A>>B;
	
	cout<<lcm(A,B)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
    int n;cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    map<int,int> m;
    for(int i=0;i<n;i++)m[v[i]]++;
    int ans=0;
    for(auto it=m.begin();it!=m.end();it++)ans++;
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main( void )
{
	string in;
	while(getline(cin, in), in[0] != '.') {
		stack<char> st;
		bool hit = true;
		int len = in.size();
		for(int i=0; i < len; ++i) {
			if(in[i] == '(' || in[i] == '[') {
				st.push(in[i]);
			}
			else if(in[i] == ')') {
				if(st.empty()) {
					hit = false;
				}
				else {
					if(st.top() != '(') hit = false;
					st.pop();
				}
			}
			else if(in[i] == ']') {
				if(st.empty()) {
					hit = false;
				}
				else {
					if(st.top() != '[') hit = false;
					st.pop();
				}
			}
		}
		if(st.size() == 0 && hit)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}

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

int main() {
  int h,w,x,y,r;
  bool flag = true;
  cin >> w >> h >> x >> y >> r;
  if(x-r < 0||y-r < 0) flag = false;
  if(r+x > w||r+y > h) flag = false;
  if(flag){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define pb push_back
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0){putchar('-');x = -x;}
	if(x >= 10) out(x / 10);
	putchar('0' + x % 10);
}

int N,sum[2][MAXN];
char s[MAXN];
void Solve() {
	read(N);
	scanf("%s",s + 1);
	for(int i = 1 ; i <= N ; ++i) {
		sum[0][i] = sum[0][i - 1];sum[1][i] = sum[1][i - 1];
		if(s[i] == 'E') sum[0][i]++;
		else sum[1][i]++;
	}
	int ans = N;
	for(int i = 1 ; i <= N ; ++i) {
		ans = min(i - 1 - sum[0][i - 1] + (N - i - (sum[1][N] - sum[1][i])),ans);
	}
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int dp[] = new int[(int)Math.pow(2, n)];
		int INF = 1_000_000_000;
		Arrays.fill(dp, INF);
		dp[0] = 0;
		for(int i = 0; i < m; i++){
			int price = sc.nextInt();
			int b = sc.nextInt();

			int pattern = 0;
			for(int j = 0; j < b; j++){
				int c = sc.nextInt();
				pattern += Math.pow(2, c - 1);
			}

//			System.out.println(pattern);

			for(int j = 0; j < dp.length; j++){
				if((pattern | j) == pattern){
					dp[j] = Math.min(dp[j], price);
				}
				else {
					dp[pattern|j] = Math.min(dp[pattern|j], dp[j] + price);
				}
			}
		}
		if(dp[dp.length - 1] < INF){
			System.out.println(dp[dp.length - 1]);
		}
		else {
			System.out.println(-1);
		}
	}

}


Measured memory_bytes: 40540
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    public static void Main()
    {
        long N = NextLong();
        long[] s = new long[5];
        for (int i = 0; i < 5; i++) s[i] = NextLong();
        long x = s[0];
        for (int i = 0; i < 5; i++)
        {
            x = Math.Min(x, s[i]);
        }
        long ans = N / x;
        if (N % x != 0) ans += 1;
        Console.WriteLine(ans + 4);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13268
N = int(input())
from collections import deque

tree = [{} for _ in range(N)]

color = [-1]*N
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1][v-1] = w
    tree[v-1][u-1] = w

queue = deque()
queue.append((0, 0))

while queue:
    v, w = queue.pop()
    color[v] = w%2
    for i in tree[v].keys():
        if color[i]==-1:
            queue.append((i, w+tree[v][i]))

for c in color:
    print(c)

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long A, long long B) {
    cout << A * B << endl;
}

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;

int gcd(int x, int y)
{
	return x == 0 ? y : gcd(y % x, x);
}

vector<int> merge(const vector<int> &a, const vector<int> &b)
{
	vector<int> ret;
	int i = 0, j = 0;
	while(i < a.size() && j < b.size())
		ret.push_back(a[i] > b[j] ? a[i++] : b[j++]);
	while(i < a.size())
		ret.push_back(a[i++]);
	while(j < b.size())
		ret.push_back(b[j++]);
	return ret;
}

int n, s[MAXN];
vector<int> ans;
vector<int> edg[MAXN];
bool vis[MAXN];

vector<int> dfs(int x, int fa)
{
	vector<int> ret;
	vis[x] = true;
	for(int i = 0; i < edg[x].size(); i++)
		if(edg[x][i] != fa)
		{
			int y = edg[x][i];
			// cerr << x << ' ' << y << endl;
			if(!vis[y])
				ret = merge(ret, dfs(y, x));
		}
	ret.insert(ret.begin(), s[x]);
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> s[i];
	sort(s + 1, s + n + 1);
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			if(gcd(s[i], s[j]) > 1)
				edg[i].push_back(j), edg[j].push_back(i);

	ans.clear();
	for(int i = 1; i <= n; i++)
		if(!vis[i])
			ans = merge(ans, dfs(i, 0));
	for(int i = 1; i <= n; i++)
		cout << ans[i - 1] << ' ';
	cout << endl;

	return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll N = (ll)1e6 + 5;
const ll MOD = (ll)1e9 + 7;
const ll inf = (ll)1e18 + 5;

template <class T>
bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T>
bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll add(ll x, ll y)
{
	x += y;
	if (x >= MOD)
		return x - MOD;
	return x;
}

ll sub(ll x, ll y)
{
	x -= y;
	if (x < 0)
		return x + MOD;
	return x;
}

ll mult(ll x, ll y)
{
	return (x * y) % MOD;
}

ll bin_pow(ll x, ll p)
{
	if (p == 0)
		return 1;
	if (p & 1)
		return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

ll rev(ll x)
{
	return bin_pow(x, MOD - 2);
}

int main()
{

	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
#ifdef LOCAL_DEFINE
	freopen("input.txt", "rt", stdin);
#endif
	ll n, k;
	cin >> n >> k;
	// cout << n % k << " " << n - (n % k) << "\n";
	cout << min(n % k, k - (n % k)) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
int x[n];
for (int i = 0; i < n; ++i) cin >> x[i];
ans = 0;
int flag = 1;
while (flag) {
        for (int i = 0; i < n; ++i) {
                if (x[i] % 2 != 0) {
                        flag = 0;
                        break;
                }
                else x[i] /= 2;
        }
        if (flag) ++ans;
}
cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: "List[int]"):
    print(max(A) - min(A))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [ int(next(tokens)) for _ in range(3) ]  # type: "List[int]"
    solve(A)

if __name__ == '__main__':
    main()


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

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

constexpr int MAX_N = 24;
constexpr int MAX_C = 4;

int n;
int x[MAX_N], y[MAX_N], r[MAX_N], c[MAX_N];

int ans;
int over[MAX_N];
bool visited[1 << MAX_N];
array<vector<int>, MAX_C> circles;
int shift[MAX_N + 1];

inline void init() {
	for(int i = 0; i <= MAX_N; ++i) {
		shift[i] = 1 << i;
	}
}

inline int square(int value) {
	return value * value;
}

inline bool intersect(int x1, int y1, int r1, int x2, int y2, int r2) {
	return square(x1 - x2) + square(y1 - y2) < square(r1 + r2);
}

void dfs(int rest, int cnt = 0) {
	chmax(ans, cnt);
	visited[rest] = true;

	for(const auto &S : circles) {
		for(int i = 1; i < S.size(); ++i) {
			if((rest & shift[S[i]]) == 0 || (over[S[i]] & rest)) continue;

			for(int j = 0; j < i; ++j) {
				if((rest & shift[S[j]]) == 0 || (over[S[j]] & rest)) continue;
				const int next_rest = rest ^ (shift[S[i]] | shift[S[j]]);
				if(!visited[next_rest]) dfs(next_rest, cnt + 2);
			}
		}
	}
}

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

	init();

	while(cin >> n && n) {
		fill_n(over, n, 0);
		for(auto &S : circles) {
			S.clear();
		}

		for(int i = 0; i < n; ++i) {
			cin >> x[i] >> y[i] >> r[i] >> c[i];
			--c[i];

			circles[c[i]].emplace_back(i);

			for(int j = 0; j < i; ++j) {
				if(intersect(x[i], y[i], r[i], x[j], y[j], r[j])) {
					over[i] |= shift[j];
				}
			}
		}

		fill_n(visited, 1 << n, false);
		ans = 0;
		dfs(shift[n] - 1);
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 17596
MOD = 10 ** 9 + 7

N = int(input())

ans = pow(10, N, MOD)
ans -= 2 * pow(9, N, MOD)
ans += pow(8, N, MOD)
ans %= MOD # 最後にMODを取り忘れないように気をつけましょう

print(ans)

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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,h;
    cin >> n >> h;
    
    vector<pair<int, int>> arr(n);
    
    int maxa = 0;
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        
        maxa = max(maxa,a);
        arr[i].first = b;
        arr[i].second = a;
    }
    
    sort(arr.begin(), arr.end());
    reverse(arr.begin(), arr.end());
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(arr[i].first >= maxa) {
            ans++;
            h -= arr[i].first;
            if(h <= 0){
                cout << i + 1 << endl;
                return 0;
            }
        } else break;
    }
    
    ans += (h - 1) / maxa + 1;
    cout << ans << endl;
}
 



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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}
//--------------------------------------------------//
const int MOD = 1e9 + 7;
inline ll add(ll a, ll b) { return (a + b) % MOD; }
inline ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll pow_mod(ll x, ll n) {
  ll ret = 1;
  for (; n; n >>= 1, x = mul(x, x))
    if (n & 1) ret = mul(ret, x);
  return ret;
}
inline ll inv_mod(ll x) { return pow_mod(x, MOD - 2); }

int main() {
  use_cio();
  int n, m, k;
  cin >> n >> m >> k;

  ll val = 1,
     ans = 0;
  rep(i, k - 2) {
    val = mul(val, n * m - 2 - i);
    val = mul(val, inv_mod(i + 1));
  }
  repp(i, 1, n) ans += mul(mul(m, m), mul(i, n - i));
  repp(i, 1, m) ans += mul(mul(n, n), mul(i, m - i));

  cout << mul(ans, val) << endl;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }

/**
 *  約数を列挙する
 */
template<typename T>
std::vector<T> divisor(T n, bool sort = true) {
    std::vector<T> ret;
    for(T i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    if(sort) std::sort(ret.begin(), ret.end());
    return ret;
}

bool IsPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for(ll i = 3; i <= sqrtNum; i += 2) {
        if(num % i == 0) {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

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

    ll A, B;
    std::cin >> A >> B;

    auto A_div = divisor(A);
    auto B_div = divisor(B);

    vector<ll> dupl;
    std::set_intersection(ALL(A_div), ALL(B_div), std::back_inserter(dupl));
    int ans = dupl[0] == 1 ? 1 : 0;
    REP(i, dupl.size()) {
        if(IsPrime(dupl[i])) ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 512
N,K=map(int,input().split())
if K==1:
    ans =N**3
elif K%2 ==0:
    a =N//(K//2)
    b =a//2
    a -=b
    ans =a**3+b**3
else:
    a =N//K
    ans =a**3
print(ans)

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

/*
再帰的に配列を操作していく．
1.配列に0が含まれているとき->0を含まないように配列を分割し，2を実行．
2.配列に0が含まれていないとき->その配列の要素の中で最小の値を減算し，1を実行．要素数が1で返された値と最小の値を加算して返す．
3.配列の要素数が1つのみのとき，その値を返す．
*/


int watering(vector<int> d);
bool zeroCheck(vector<int> d);
int getMin(vector<int> d);

int main() {
  //input
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i=0;i<N;i++)
    cin >> h.at(i);

  //calculation
  int num = watering(h);  
  
  //output
  cout << num << endl;
}

int watering(vector<int> d){
  int sum = 0;

  //要素数が1つだけの場合，その値を返す
  if(d.size() == 1){
    return d.front();
  }

  if(zeroCheck(d)){
    //0が配列dに含まれている場合
    //配列を0を境にして分割する
    //Ex. [0,4,5,1,3] -> [4,5,1,3]
    //Ex. [10,9,3,0,5,6] -> [10,9,3],[5,6]
    
    if(d.front() == 0){
      //0が先頭の場合
      d.erase(d.begin());//配列の先頭を削除
      sum += watering(d);
    }
    else if(d.back() == 0){
      //0が末尾の場合
      d.erase(d.end() - 1);//配列の末尾を削除. .end()では配列の末尾の要素の次の位置を示すため，1を引く．
      sum += watering(d);
    }
    else{
      //0が真ん中にある場合
      vector<int> v1,v2; int i;
      for(i=0;i<d.size();i++){//前半の配列
        if(d.at(i) != 0)
          v1.push_back(d.at(i));
        else
          break;
      }
      for(int j=i+1;j<d.size();j++)//後半の配列
        v2.push_back(d.at(j));

      sum += watering(v1) + watering(v2);
    }

  }else{
    //0が配列dに含まれていない場合
    int min = getMin(d);
    sum += min;

    //配列の最小値を全ての要素から減算する
    for(int i=0;i<d.size();i++)
      d.at(i) -= min;
    
    //もう一度水やりを行う
    sum += watering(d);
  }

  return sum;
}

bool zeroCheck(vector<int> d){
  //cout << "zeroCheck" << endl;
  sort(d.begin(),d.end());
  if(d.at(0) == 0)
    return true;
  else
    return false;
}

int getMin(vector<int> d){
  //cout << "getMin" << endl;
  sort(d.begin(),d.end());
  return d.at(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,A,B,D;
    cin >> N >> A >> B;
    A--,B--;
    map<int,set<P<int,int>>> mps,mms;
    map<int,vec<P<int,int>>> mpv,mmv;
    vec<int> X(N),Y(N);
    for(int i=0;i<N;i++){
        int x,y;
        cin >> x >> y;
        X[i] = x,Y[i] = y;
        mps[x+y].insert({x,i});
        mms[x-y].insert({x,i});
        mpv[x+y].push_back({x,i});
        mmv[x-y].push_back({x,i});
    }
    D = abs(X[A]-X[B])+abs(Y[A]-Y[B]);
    for(auto& v:mpv) sort(v.second.begin(),v.second.end());
    for(auto& v:mmv) sort(v.second.begin(),v.second.end());
    queue<int> Q;
    ll ans = 0;
    const int inf = 1e9+7;
    Q.push(A),Q.push(B);
    struct point{
        int x,y;
    };

    vec<int> vis(N,0);
    auto ne = [&](int s,int t,set<P<int,int>>& st){
        if(st.empty()) return ;
        set<P<int,int>>::iterator it = st.upper_bound({s,-1});
        while(it!=st.end()){
            P<int,int> p = *it;
            if(t<p.first) break;
            if(!vis[p.second]){
                Q.push(p.second);
                vis[p.second] = 1;
            }
            it = st.erase(it);
        }
    };

    auto calc = [&](int s,int t,vec<P<int,int>>& v,ll& cnt){
        if(v.empty()) return ;
        int l = lower_bound(v.begin(),v.end(),P<int,int>(s,-1))-v.begin();
        int r = lower_bound(v.begin(),v.end(),P<int,int>(t,inf))-v.begin();
//        cerr << l << " " << r << " " << v.size() << endl;
        ans += r-l;
        r--;
        if(l>r) return ;
        if(s==v[l].first || (r>=0 && s==v[r].first)) cnt++;
        if(t==v[l].first || (r>=0 && t==v[r].first)) cnt++;
    };

    vis[A] = vis[B] = 1;
    while(!Q.empty()){
        int cur = Q.front(); Q.pop();
        point u = {X[cur],Y[cur]+D},d = {X[cur],Y[cur]-D};
        point l = {X[cur]-D,Y[cur]},r = {X[cur]+D,Y[cur]};
        ll c = 0;
        if(mpv.count(X[cur]+Y[cur]+D)){
            ne(u.x,r.x,mps[X[cur]+Y[cur]+D]);
            calc(u.x,r.x,mpv[X[cur]+Y[cur]+D],c);
        }
        if(mpv.count(X[cur]+Y[cur]-D)){
            ne(l.x,d.x,mps[X[cur]+Y[cur]-D]);
            calc(l.x,d.x,mpv[X[cur]+Y[cur]-D],c);
        }
        if(mmv.count(X[cur]-Y[cur]-D)){
            ne(l.x,u.x,mms[X[cur]-Y[cur]-D]);
            calc(l.x,u.x,mmv[X[cur]-Y[cur]-D],c);
        }
        if(mmv.count(X[cur]-Y[cur]+D)){
            ne(d.x,r.x,mms[X[cur]-Y[cur]+D]);
            calc(d.x,r.x,mmv[X[cur]-Y[cur]+D],c);
        }
//        cerr << cur << " " << c << endl;
        ans -= c/2;
    }
    cout << ans/2 << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

pair <int, int> p[N];

int dp[N];

int main () {
    to_pray();

    int n, t;
    cin >> n >> t;
    for (int i = 1; i <= n; ++ i) {
    	int x, y;
    	cin >> x >> y;
    	p[i].first = x;
    	p[i].second = y;
    }
    
    sort(p + 1, p + 1 + n);
    
    for (int i = 1; i <= n; ++ i) {
    	for (int j = t - 1; j >= 0; -- j) {
    		dp[min(j + p[i].first, t + 1)] = max(dp[min(j + p[i].first, t + 1)], dp[j] + p[i].second);
    	}
    }
    int mx = 0;
    for (int i = 1; i <= t + 1; ++ i)
    	mx = max(mx, dp[i]);
    cout << mx;
    
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}

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

int main() {

  int N;
  cin >> N;
  
  int x = 1;
  vector<int> m(N);
  
  for (int i = 0; i < N; i++) {
    cin >> m.at(i);
  }
  
  sort(m.begin(), m.end());
  
  for (int i = 0; i < N - 1; i++) {
    if (m.at(i) != m.at(i + 1)) {
      x++;
    }
  }

  cout << x <<endl;
  
}

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

int main(){
  string st;//入力文字の格納場所
  cin >> st;//入力した文字の格納
  
  if (st[0] == 'R'&&st[1] == 'R'&&st[2] == 'R'){
    cout << 3 << endl;
  }else if ((st[0] == 'R'&&st[1] == 'S')||(st[0] == 'S'&&st[1] == 'R'&&st[2] == 'S')
        ||(st[1] == 'S'&&st[2] == 'R')){
    cout << 1 << endl;
  }else if ((st[0] == 'R'&&st[1] == 'R'&&st[2] == 'S')
            ||(st[0] == 'S'&&st[1] == 'R'&&st[2] == 'R')){
  	cout << 2 << endl;
  }else{
  	cout << 0 << endl;
  }
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>

using namespace std;

int main(void){
    string S;
    cin >> S;

    if(S == "Sunny")
        cout << "Cloudy" << endl;

    if(S == "Cloudy")
        cout << "Rainy" << endl;

    if(S == "Rainy" )
        cout << "Sunny" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 10000
#define Q 500
int linearSearch();
int i,j,n,q,S[N],T[Q],c=0;
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&T[i]);
 printf("%d\n",linearSearch());
  return 0;
}

int linearSearch(){

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(T[i]==S[j]){
	c++;
      break;
      }
    }
  }
  return c;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long x;
  cin>>x;
  long long a=x%11;
  if(a==0){
    cout<<x/11*2<<endl;
  }
  else if(a<=6){
    cout<<x/11*2+1<<endl;
  }
  else{
    cout<<x/11*2+2<<endl;
  }
  return(0);
}
 


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

int main() {
  int n;
  cin >> n;
  cout << (n+999)/1000*1000 - n << endl;
}


Measured memory_bytes: 3580
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int):
    if K > (N-1)*(N-2)//2:
        print(-1)
        return

    # スター型
    M = N-1
    addition = (N-1)*(N-2)//2 - K
    print(M+addition)
    for i in range(2, N+1):     # N-1本
        print(1, i)

    from_ = 2
    to_ = 3
    for i in range(addition):
        print(from_, to_)
        if to_ < N:
            to_ += 1
        else:
            from_ += 1
            to_ = from_ + 1
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3608
$N, $A, $B, $C = gets.chomp.split.map(&:to_i)
$l = []
$N.times { $l << gets.chomp.to_i }

# 三本の長さがa,b,cになったとき
# 合体後にabs(a - A) + abs(b - B) + abc(c - C) をたしたものコストになる

# a, b, cはそれぞれの長さ
def dfs(i, a, b, c)
  if i == $N
    # 一本も使っていないときは大きな数字を返す
    return 10**10 if i == 0 || b == 0 || c == 0

    return ($A-a).abs + ($B-b).abs + ($C-c).abs
  end

  y_i = a == 0 ? 0 : 1
  z_i = b == 0 ? 0 : 1
  w_i = c == 0 ? 0 : 1

  x = dfs(i+1, a, b, c)
  y = dfs(i+1, a + $l[i], b, c ) + 10*y_i
  z = dfs(i+1, a, b + $l[i], c ) + 10*z_i
  w = dfs(i+1, a, b, c + $l[i]) + 10*w_i

  return [x, y, z, w].min
end

p dfs(0, 0, 0, 0)



Measured memory_bytes: 1788