akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int c,n,m,s,d;
const int INF = 2*1e9;
vector<pair<int,int>> G[100];
ll D[100][10];

struct P
{
	int time,v,chk;
	P(int time,int v,int chk)
	{
		this->time=time;
		this->v = v;
		this->chk = chk;
	}
};

bool operator<(P a,P b)
{
	return a.time>b.time;
}

void dijkstra(int chiket)
{
	for(int i = 0;i<100;i++)
	{
		for(int j = 0;j<10;j++)
		{
			D[i][j]=INF;
		}
	}
	D[s][chiket]=0;
	priority_queue<P> PQ;
	PQ.emplace(0,s,chiket);
	while(!PQ.empty())
	{
		//cout<<PQ.size()<<endl;
		auto now = PQ.top();
		PQ.pop();
		//cout<<now.time<<endl;
		if(D[now.v][now.chk]!=now.time)continue;
		for(auto next:G[now.v])
		{
			if(D[next.first][now.chk]>now.time+next.second)
			{
				D[next.first][now.chk]=now.time+next.second;
				PQ.emplace(D[next.first][now.chk],next.first,now.chk);
			}
			if(now.chk<1)continue;
			if(D[next.first][now.chk-1]>now.time+next.second/2)
			{
				D[next.first][now.chk-1] = now.time+next.second/2;
				PQ.emplace(D[next.first][now.chk-1],next.first,now.chk-1);
			}
		}
	}
	ll mn = INF;
	for(int i = 0;i<10;i++)
	{
		mn = min(mn,D[d][i]);
	}
	cout<<mn<<endl;
}

int main()
{
	while(1)
	{
		cin >> c >> n >> m >> s >> d;
		if(c==0)break;
		for(int i = 0;i<n;i++)
		{
			G[i].clear();
		}
		s--;
		d--;
		for(int i = 0;i<m;i++)
		{
			int a,b,f;
			cin >> a >> b >> f;
			a--;
			b--;
			G[a].emplace_back(b,f);
			G[b].emplace_back(a,f);
		}
		dijkstra(c);
	}
}


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

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define pb push_back
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int MOD=1e3;
const int N=1e2+5;
const ll maxn=2e5+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
int n;
ll a[maxn], b[maxn];

void sort(ll *a, ll md)
{
    int pos = n;
    for (int i = 0; i < n; i ++)
    {
        if (pos == n && a[i] >= md)
            pos = i;
        a[i] = a[i] & (md - 1);
    }
    inplace_merge(a, a + pos, a + n);
}

bool solve(ll limit)
{
    ll ans = 0;
    int that = n - 1;
    for (int i = 0; i < n; i ++)
    {
        while (that >= 0 && a[i] + b[that] >= limit)
            that --;
        ans += n - 1 - that;
    }
    return ans & 1;
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i ++)
        scanf("%lld", &a[i]);
    for (int i = 0; i < n; i ++)
        scanf("%lld", &b[i]);
    sort(a, a + n);
    sort(b, b + n);
    ll ans = 0;
    for (int i = 61; i >= 0; i --)
    {
        sort(a, (ll)2 << i);
        sort(b, (ll)2 << i);
        ll res =
            solve((ll)1 << i) ^
            solve((ll)2 << i) ^
            solve((ll)3 << i);
        ans |= res << i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){

  ll l,r;
  cin >> l >> r;

  ll min=2019;
  for(ll i=l;i<r;i++){
    if(i%2019==0){
      min=0;
      break;
    }

    for(ll j=i+1;j<=r;j++){
      if(j%2019==0){
        min=0;
        break;
      }

      ll remainder=(i*j)%2019;
      if(min>remainder){
        min=remainder;
      }
    }

    if(min==0){
      break;
    }
  }
cout << min << endl;













  /*ll l,r;
  cin >> l >> r;
  if((r-l)>=2019){
    cout << 0 << endl;
    return 0;
  }

  int remainder,min=2019;
  for(ll i=l;i<r;i++){
    remainder=i%2019;
    if(min>remainder){
      min=remainder;
      if(min==0){
        break;
      }
    }
  }

  ll J=min+1;

  cout << min*J << endl;*/

  }


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

const vector<int> dy = {0, -1, 0, 1};
const vector<int> dx = {1, 0, -1, 0};

vector<vector<int>> dis;

void bfs(const vector<string>& s, int sy, int sx) {
    queue<pair<int, int>> que;
    que.emplace(sy, sx);
    dis.assign(s.size(), vector<int>(s[0].size(), -1));
    dis[sy][sx] = 0;
    while (!que.empty()) {
        int y, x;
        tie(y, x) = que.front(); que.pop();
        for (int i = 0; i < 4; ++i) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny >= 0 && ny < s.size() && nx >= 0 && nx < s[0].size() && dis[ny][nx] < 0 && s[ny][nx] == '.') {
                dis[ny][nx] = dis[y][x] + 1;
                que.emplace(ny, nx);
            }
        }
    }
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    int black = 0;
    for (int i = 0; i < H; ++i) {
        cin >> s[i];
        for (int j = 0; j < W; ++j) {
            if (s[i][j] == '#') black++;
        }
    }
    bfs(s, 0, 0);
    cout << (dis[H - 1][W - 1] < 0 ? -1 : H * W - (dis[H - 1][W - 1] + 1) - black) << endl;
}

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)

#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define STR(s) string s;cin>>s
#define MSET(arr,val)  memset(arr,val,sizeof(arr))

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  map<string, bool> mp;
  STR(a);
  int n = SZ(a), l = 1, cnt = 0; vector<int> ls(n + 1, 0);
  bool fs[n + 1]; MSET(fs, false);
  vector<vector<int>> is(26);
  REP(i, n){
    is[a[i] - 'a'].PB(i);
  }
  REP(i, 26){
    is[i].PB(n);
  }
  REP(i, n, 0){
    ls[i] = l;
    int j = a[i] - 'a';
    if (!fs[j]){
      cnt++;
      fs[j] = true;
      if (cnt == 26){
        l++;
        MSET(fs, false);
        cnt = 0;
      }
    }
  }
  string ans = "";
  int i = 0;
  REP(j, l){
    REP(k, 26){
      int nxt = *lower_bound(is[k].begin(), is[k].end(), i);
      if (j + ls[nxt] < l){
        i = nxt + 1;
        ans += 'a' + k;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2452
/*		Author : Kaustubh Gangwar
		||S||A||M||R||A||T||
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define pb push_back
#define gcd __gcd
#define vii vector<int>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
typedef long long  ll;
typedef pair<int,int> pii;

ll bpow(ll a, ll b) {
	a=a; ll res = 1;
    while(b){
        if (b & 1)
        res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main()
{	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	ll test=1;
//	cin>>test;
	while(test--)
	{
		ll n; cin>>n;
		ll a[n]; 
		f(i,0,n) cin>>a[i];
		sort(a,a+n,greater<ll>());
		ll ans=0;
		ans+=a[0];
		int j=1;
		for(int i=2;i<n;i+=2)
		{	
			ans+=a[j];
			if(i+1<n)
			ans+=a[j];
			
			j++;
		}
		cout<<ans<<nl;
		
	}
return 0;
}


Measured memory_bytes: 5164
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}




int main(){  
  int n;
  cin>>n;
  vector<int>x(n);
  vector<int>y(n);
  rep(i,n) cin>>x[i]>>y[i];
  ld ave=0;
  rep(i,n){
    rep(j,n){
      if(i!=j)ave+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
    }
  }

  ave/=n;
  cout<<fixed<<setprecision(6)<<ave<<endl;
}


Measured memory_bytes: 256
n, w = map(int, input().split())
goods = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(w + 1):
        if 0 <= j - goods[i][0]:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - goods[i][0]] + goods[i][1])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[n][w])


Measured memory_bytes: 121196
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		int A = sc.nextInt();
		 
 		if(A<1200){
		 System.out.println("ABC");
 		} else if(A<2800){
		 System.out.println("ARC");
 		} else{
		 System.out.println("AGC");
	}
}
}

Measured memory_bytes: 21844
class BIT:
    def __init__(self,n):
        self.size=n
        self.tree=[0]*-~n
    def sum(self,i):
        s=0
        while i:
            s+=self.tree[i]
            i-=i&-i
        return s
    def add(self,i,x):
        while i<=self.size:
            self.tree[i]+=x
            i+=i&-i
n,k,*a=map(int,open(0).read().split())
a=[t-k for t in a]
for i in range(1,n):
    a[i]+=a[i-1]
d={}
for i,v in enumerate(sorted(set(a+[0])),1):
    d[v]=i
for i in range(n):
    a[i]=d[a[i]]
b=BIT(max(a))
b.add(d[0],1)
c=0
for p in a:
    c+=b.sum(p)
    b.add(p,1)
print(c)

Measured memory_bytes: 113552
#include <stdio.h>

int main(void){

  char s[11];
  scanf("%s", s);
	int number;
	int min = -1;
	for (int i = 2; i < 11; i++) {
		if (s[i] < '0' || s[i] > '9') {
			break;
		}
		number = (s[i-2]-'0')*100+(s[i-1]-'0')*10+s[i]-'0';
		number -= 753;
		if (number < 0) {
			number *= -1;
		}
		if (min == -1 || number < min) {
			min = number;
		}
	}
	printf("%d\n", min);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
int main()
{
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll a=x/d,b=x%d,c;
	if(a>k)
	{
		cout<<x-k*d<<endl;
		return 0;
	}
	k=k-a;
	c=b-d;
	if(k%2) cout<<abs(c)<<endl;
	else cout<<b<<endl; 
	return  0;
}

Measured memory_bytes: 3640
def main():
    n = int(input())
    
    count = 0
    for i in range(1, n+1):
        d = 0
        if i % 2 == 0:
            continue;
        for j in range(1, int(i**(1/2))+1):
            if i % j == 0:
                d += 2
                if d > 8:
                    break
        if d == 8:
            count += 1
    print(count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
using namespace std;

int main(){
  int h,w; cin >> h >> w;
  int g[h][w+1];
  int gg[w+1] = {};
  for(int i = 0; i < h; i++){
    int add = 0;
    for(int j = 0; j < w; j++){
      cin >> g[i][j];
      add += g[i][j];
      gg[j] += g[i][j];
      gg[w] += g[i][j];
    }
    g[i][w] = add;
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w+1; j++){
      cout << g[i][j];
      if(j == w) cout << endl;
      else cout << " ";
    }
  }
  for(int i = 0; i <= w; i++){
    cout << gg[i];
    if(i == w) cout << endl;
    else cout << " ";
  }
  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int N = 100000 + 5;
struct point{
	int l,r;
}a[N];
bool cmp(point a,point b){
	return a.r < b.r;
}
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x,l1;
		cin >> x >> l1;
		a[i].l = x-l1;
		a[i].r = x+l1;
	}
	sort(a+1,a+n+1,cmp);
	int sum = n,t = a[1].r;
	for(int i = 2; i <= n; i++){
		if(a[i].l < t)
			sum--;
		else
			t = a[i].r;
	}
	cout << sum << endl;
    return 0;
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    double R;

    ist >> R;

    /* ------- 計算 ------- */

    double ans = R * 2 * M_PI;

    ost << ans << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x;
  string s;
  cin >> x; 
  cin >> s;
  REP(i, SIZE(s))
  {
    if(s[i]+x > 90)printf("%c",(s[i]+x)-26);
    else printf("%c",s[i]+x);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = pair<int, int>;
using vi = vector<int>;
using vii = vector<pi>;
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(0); cin.tie(NULL);
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x)sz(a))
#define present(t, x) (t.find(x) != t.end())
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define forall(it, a) for(decltype((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define what_is(x) cerr << #x << " is " << (x) << endl;
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
	for(long blockTime=(long)NULL;(blockTime==(long)NULL?(blockTime=clock())!=(long)NULL:false); \
	debug("%s:%.4fs\n",(d),(double)(clock()-blockTime)/CLOCKS_PER_SEC))
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1); // pi
const ld EPS = 1e-9; // epsilon
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int imin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int imax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}

//time__("program time")

void solve(){

}

int main(){

	fast_io;
	//solve();
	int n;
	cin >> n;

	if(n == 1) {
		cout << "1\n";
		return 0;
	}
	int ans = 0;

	while(n){
		ans += (n%10);
		n /= 10;
	}

	if(ans == 1) ans = 10;
	cout << ans << "\n";

return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    auto nc2 = [](ll n){return n * (n-1) / 2;};

    IOS
    int n; cin >> n;
    vector<int> v(n);
    map<int,int> mp;
    REP(i,n) {
        cin >> v[i];
        mp[v[i]]++;
    }

    ll base = 0;
    for (auto p:mp) {
        base += nc2(p.second);
    }

    REP(i,n) {
        OUT(base - nc2(mp[v[i]]) + nc2(mp[v[i]]-1))
    }

    return 0;
}

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int i=k-a-b;
    if (a>=k){
        cout << k << endl;
    }
    else if(a+b>=k){
        cout << a << endl;
    }
    else{
        cout << a-i << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using ll = long long;
int main(int argc, char ** argv)
{
  //
  int n, m;
  std::cin >> n >> m;

  int ans = -1;

  int d[] = {1, 0, 0};
  int flg[] = {0, 0, 0};

  if ((n == 1) && (m == 0)) {
    d[0] = 0;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;

    if ((n != 1) && (s == 1) && (c == 0)) {
      std::puts("-1");
      return 0;
    } else {
      if (flg[s - 1] == 0) {
        d[s - 1] = c;
        flg[s - 1] = 1;
      } else {
        if (d[s - 1] != c) {
          std::puts("-1");
          return 0;
        }
      }
    }
  }

  ans = d[0] * 100 + d[1] * 10 + d[2];

  for (int i = 0; i < 3 - n; i++) {
    ans /= 10;
  }
  std::printf("%d\n", ans);
  return 0;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n & 1 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    IOS

    int n,k;
    cin>>n>>k;
    int h[n];
  	for(int i=0;i<n;i++) 
  		cin>>h[i];
  	
  	int dp[n];
  	dp[n-1]=0;
  	dp[n-2]=dp[n-1]+abs(h[n-2]-h[n-1]);

  	for(int i=n-3;i>=0;i--)
    {
        int temp=1e9;
        for(int j=i+1;j<=min(i+k,n-1);j++)
            temp=min(temp,dp[j]+abs(h[j]-h[i]));
            
        dp[i]=temp;
    }

  	cout<<dp[0]<<endl;

    
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            if(n == 0 && x == 0) break; 

            int sum = 0;

            for(int i = 1; i <= n; i++){
                for(int j = 1; j <= n; j++){
                    for(int k = 1; k <= n; k++){
                        if(i >= j || j >= k) continue;
                        if(x == i + j + k) sum++;
                    }
                }
            }
            
            System.out.println(sum);
        }

        sc.close();
    }
}


Measured memory_bytes: 26508
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int n;
	vector <int> vec(105);
	bool flag[105];

	fill(flag, flag+105, false);

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> vec[i];
	}

	sort(vec.begin(), vec.end(), greater<int>() );

	int suma = 0, sumb = 0;

	for (i = 0; i < n; i+=2) {
		if (flag[i] == false) {
			suma += vec[i];
			flag[i] = true;
		}

		if (flag[i+1] == false) {
			sumb += vec[i + 1];
			flag[i+1] = true;
		}
		
	}

	cout << suma - sumb << endl;





	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();

        if (n%2!=0){
            System.out.println("No");
        }else {
            char[] c = sc.next().toCharArray();
            for (int i=0; i<n/2; i++){
                if (c[i]!=c[i+n/2]){
                    System.out.println("No");
                    return;
                }
            }
            System.out.println("Yes");

        }

    }
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int h, w, d; cin >> h >> w >> d;
	vector<vector<int>> col(h, vector<int>(w, -1));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int ti = i / d, tj = j / d;
			int di = i % d, dj = j % d;
			int s1 = (di + dj < d), s2 = (di > dj);
			int color = s1 * 2 + s2;
			if (ti + tj & 1) color = 3 - color;
			col[i][j] = color;
		}
	}
	char color[] = "RYGB";
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << color[col[i][j]];
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll mod=1000000007;

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

    if(S[S.size()-1] == 's') {
        S += "es";
    }
    else {
        S += 's';
    }
    cout << S << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;

void hello(char* p) {
    p = (char*)malloc(100);
//    strcpy(p, "hello");
//    cout << p << endl;
}

const string temp = "AKIHABARA";

int main() {
  //  freopen("in.txt", "r", stdin);
    string s, t = "";
    cin >> s;
    int n = s.length();
    for (int i = 0; i < n; i++) {
        if (i == 0 && s[i] == 'K') {
            t += 'A';
        }
        if (i && s[i - 1] == 'H' && s[i] == 'B') {
            t += 'A';
        }
        if (i && s[i - 1] == 'B' && s[i] == 'R') {
            t += 'A';
        }
        t += s[i];
    }
    if (s[n - 1] == 'R') t += 'A';
//    cout << t << endl;
    puts(t == temp ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100000
int a[maxn+5];
int main(){
	int n,x;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&x),a[x]=i;
	for(int i=1;i<=n;i++)printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=4e2+5;
const int mod=998244353;
int n,Sa,Sb,tmp,ans,a[N],b[N],fac[N],inv[N],dp[N][N][N];

inline int mul(int x,int y) {return 1ll*x*y%mod;}
inline int add(int x,int y) {x+=y;if(x>=mod) x-=mod;return x;}
inline int modpow(int x,int y,int res=1) {
	for(;y;y>>=1,x=mul(x,x)) if(y&1) res=mul(res,x);
	return res;
}
inline void inc(int&x,int y) {x=add(x,y);}
template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

int main() {
	IN(n),fac[0]=inv[0]=1;
	for(int i=1;i<=n;++i) IN(a[i]),Sa+=a[i],IN(b[i]),Sb+=b[i];
	for(int i=1;i<N;++i) fac[i]=mul(fac[i-1],i),inv[i]=modpow(fac[i],mod-2);
	dp[0][0][0]=mod-1;
	for(int i=1;i<=n;++i) for(int j=0;j<=Sa;++j) for(int k=0;k<=Sb;++k) {
		if(!dp[i-1][j][k]) continue;
		inc(dp[i][j][k],dp[i-1][j][k]),tmp=1;
		for(int c=0;c<b[i];++c,tmp=mul(tmp,a[i]))
			inc(dp[i][j+a[i]][k+c],mod-mul(tmp,mul(inv[c],dp[i-1][j][k])));
	}
	for(int i=1;i<=Sa;++i) {
		int res=modpow(i,mod-2);tmp=mul(Sa,res);
		for(int j=0;j<=Sb;++j,tmp=mul(tmp,res)) inc(ans,mul(dp[n][i][j],mul(tmp,fac[j])));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <map>

using namespace std;

typedef long long ll;

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

int main() {
    string s; cin >> s;
    ll n = 0;
    for(int i = 0; i< s.size(); i++) {
        if(i >= s.size()-1-i) {
            break;
        }
        if(s[i] != s[s.size()-1-i])
            n++;
    }
    cout << n << endl;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

ll modPow(ll a, ll b, ll mod) {
	if(b == 0){
		return 1;
	}else{
		if(b % 2 == 1){
			return a * modPow(a,b-1, mod) % mod;
		}else{
			ll temp = modPow(a,b/2, mod);
			return temp*temp%mod;
		}
	}
}

int main(){
	// ll modVal = 1000000007;
	// ll ans = modPow(10, modVal-2, modVal);
	// printf("ans %d\n",ans);
	// printf("akhir %d\n",ans*10 % modVal);
	string s;
	cin>>s;
	int i,j,n;
	n = s.size();
	int mod = 2019;
	ll bil = 0;
	int cnt[2019];
	memset(cnt, 0, sizeof cnt);
	int resMod[200001];

	for(i=0;i<n;i++){
		bil *= 10;
		bil += s[i]	- '0';
		bil %= mod;
		resMod[i] = bil;

	}
	// printf("resMod[n-1]: %d\n",resMod[n-1]);
	cnt[resMod[n-1]]++;
	int temp = 0;
	for(i=1;i<n;i++){
		temp *= 10;
		temp += s[i-1] - '0';
		temp %= mod;
		bil = temp;
		bil %= mod;
		bil *= modPow(10, n-i, mod);
		bil %= mod;
		ll ans = resMod[n-1] - bil;
		if(ans < 0){ans+=mod;}
		cnt[ans]++;

		// printf("i: %d ans: %lld\n",i, ans);
	}
	cnt[0]++; //for the end

	ll ans = 0;
	for(i=0;i<2019;i++){
		ans += ((ll)cnt[i]*(cnt[i]-1))/2LL;
	}
	printf("%lld\n",ans);
	// for(i=1;i<=9;i++){
	// 	int bil = i;
	// 	for(j=1;j<=200000;j++){
	// 		bil *= 10;
	// 		bil %= mod;
	// 		modRes[i][j] = bil;
	// 		cnt[i][bil]++;
	// 	}
	// }

	// adj.assign(11, vi());

	// for(i=1;i<=9;i++){
	// 	for(j=0;j<2019;j++){
	// 		if(cnt[i][j]){
	// 			adj[i].pb(j);
	// 		}
	// 	}
	// }

	// ll ans = 0;
	// int modString[2019];
	// memset(modString, 0, sizeof modString);
	// int bil = 0;
	// for(i=0;i<n;i++){
	// 	bil *= 10;
	// 	bil += s[i] - '0';
	// 	bil %= mod;

	// 	modString[bil]++;
	// }

	// ans += modString[0];
	// modString[0] = 0;

	// for(i=0;i<n-1;i++){
	// 	//assume num = s[i] - '0'
	// 	//try to reduce the whole sequence with num * 1e1, num * 1e2, ... , num 1e
	// }
	
	return 0;
};

Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define pii pair<int, int>
#define rep(i,n) for(int i = 0;i < n; i++)
#define Rep(i,n) for(int i = 1;i <= n; i++)
string s;
int main(){
    cin >> s;
    int l = s.size();
    string t = s.substr(0, l/2);
    if(t == s.substr(l/2+1, l/2)){
        reverse(t.begin(), t.end());
        if(t == s.substr(l/2+1, l/2)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;

  ll ans = b;
  ans += min(a + b + 1, c);
  cout << ans << endl;
}

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

long long sum(vector<int> X, int x,int N){
    long long s=0;
    for(int i=0;i<N;i++){
        s=s+((X.at(i)-x)*(X.at(i)-x));
    }
    return s;
}

int main() {
	int N;
	cin >> N;
	vector<int> X(N);
	for(int i=0;i<N;i++){
	    cin >> X.at(i);
	}
	long long dist=1000000000000000000;
	for(int x=0;x<=100;x++){
	    long long s=sum(X,x,N);
	    if(dist>s) dist=s;
	}
	cout << dist << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int N, A[201];

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

  int ans=0;
  bool flag = true;
  while(flag){
    for(int i = 0; i < N; i++){
      if(A[i] % 2 == 1) flag = false;
      else A[i] = A[i] / 2;
    }
    ans++;
  }
  ans--;
  
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def Replacing():
    N = int(input())
    A = list(map(int,input().split()))
    lis = [0 for i in range(10 ** 5)]
    res = 0
    for i in A:
        lis[i-1] += 1
        res += i
    
    Q = int(input())
    for i in range(Q):
        b, c = map(int,input().split())
        num = lis[b-1]
        res += (c - b) * num
        lis[b-1] = 0
        lis[c-1] += num
        print(res)
        
Replacing()
        

Measured memory_bytes: 21120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }

struct quattro { ll sum; int ia; int ib; int ic; };
bool operator < (const quattro& left, const quattro& right) {
    return left.sum < right.sum || (left.sum == right.sum && (left.ia > right.ia || (left.ia == right.ia && (left.ib > right.ib || (left.ib == right.ib && left.ic > right.ic)))));
}

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

    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vel A(X), B(Y), C(Z); 
    rep(i,X) cin >> A[i]; rep(i,Y) cin >> B[i]; rep(i,Z) cin >> C[i];

    sort(rall(A)); sort(rall(B)); sort(rall(C));

    priority_queue<quattro> pq;
    pq.push(quattro{A[0]+B[0]+C[0], 0, 0, 0});
    int a = -1, b = -1, c = -1;
    rep(i,K) {
        quattro p = pq.top(); pq.pop();
        while (a == p.ia && b == p.ib && c == p.ic) {
            p = pq.top(); pq.pop();
        }
        cout << p.sum << endl;
        a = p.ia; b = p.ib; c = p.ic;
        if(a+1 < X) pq.push(quattro{A[a+1]+B[b]+C[c], a+1, b, c });
        if(b+1 < Y) pq.push(quattro{A[a]+B[b+1]+C[c], a, b+1, c });
        if(c+1 < Z) pq.push(quattro{A[a]+B[b]+C[c+1], a, b, c+1 });
    }
}



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

using namespace std;
int arr[10005];
int res[1005][1005];
int main(){
    int h, w;
    cin >> h >> w;
    int n; cin >> n;
    for(int i = 0; i < n; i++) cin >> arr[i];
    int c = 0;
    for(int i = 0; i < h; i++){
        if(i % 2 == 0)
            for(int e = 0; e < w; e++){
                if(arr[c] <= 0) c++;
                res[i][e]= c;
                arr[c]--;
            }
        else
            for(int e = w-1; e >= 0; e--){
                if(arr[c] <= 0) c++;
                res[i][e]= c;
                arr[c]--;
            }
    }

    for(int i = 0; i < h; i++){
        for(int e =0; e< w; e++){
            cout << res[i][e]+1 << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
string s,t;
int p[2020202];
int main()
{
	memset(p,-1,sizeof(p));
	getline(cin,s);
	getline(cin,t);
	string x="";
	while(x.size()<s.size()+t.size())
	{
		x+=t;
	}
	string y="";
	while(y.size()<s.size()+t.size()*2)
	{
		y+=s;
	}
	int n=x.size(),j=-1;
	for(int i=0;i<n;i++)//kmp for x 
	{
		while(j>=0 && x[i]!=x[j])
		{
			j=p[j];
		}
		j++;
		p[i+1]=j;
	}
	int now=0,ans=0;
	for(int i=0;i<y.size();i++)//match the y
	{
		char c=y[i];
		while(now==n || (now>=0 && x[now]!=y[i]))
		{
			now=p[now];
		}
		now++;
		ans=max(ans,now);
	}
	if(ans>=s.size()+t.size())
	{
		ans=-1;
	}
	else
	{
		ans/=t.size();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 13512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    int N;
    int a[100];
    int min = 10000000;
    cin >> N;
    REP(i, N) cin >> a[i];
    for(int j = -100; j <= 100; j++) {
        int cost = 0;
        for(int i = 0;i < N; i++){
            cost += (a[i] - j) * (a[i] - j);
        }
        if(cost < min) min = cost;
    }
    cout << min;

    return 0;
}


Measured memory_bytes: 256
I=input;n,m=map(int,I().split());a=[I()for _ in[0]*n];b=[I()for _ in[0]*m];r=n-m+1;print('YNeos'[sum(sum(b==[t[j:j+m]for t in a[i:i+m]]for j in range(r))for i in range(r))<1::2])

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3 = x2 - y2 + y1;
    int y3 = y2 + x2 - x1;
    int x4 = x1 + x3 - x2;
    int y4 = y1 + y3 - y2;

    cout << x3 << " "
         << y3 << " "
         << x4 << " "
         << y4 ;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  map<int, int> m;
  vector<pair<int, int> > vec;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    vec.push_back(make_pair(a, b));
  }
  sort(ALL(vec));
  ll count = 0;
  REP(i, n) {
    count += vec[i].second;
    if (count >= k) {
      cout << vec[i].first << endl;
      return 0;
    }
  }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int dp[3005][3005];
int tr[3005][3005];

int main2() {
  string s, t;
  cin >> s >> t;
  const int N = s.size();
  const int M = t.size();
  CLR(dp, 0);
  CLR(tr, -1);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (s[i] == t[j]) {
        if (dp[i+1][j+1] < dp[i][j] + 1) {
          dp[i+1][j+1] = dp[i][j] + 1;
          tr[i+1][j+1] = 'b';
        }
      }
      if (dp[i+1][j+1] < dp[i][j+1]) {
        dp[i+1][j+1] = dp[i][j+1];
        tr[i+1][j+1] = 'i';
      }
      if (dp[i+1][j+1] < dp[i+1][j]) {
        dp[i+1][j+1] = dp[i+1][j];
        tr[i+1][j+1] = 'j';
      }
    }
  }

  string ans;
  int i = N;
  int j = M;
  while (tr[i][j] != -1) {
    if (tr[i][j] == 'i') {
      i--;
    } else if (tr[i][j] == 'j') {
      j--;
    } else if (tr[i][j] == 'b') {
      ans = s[i-1] + ans;
      i--;
      j--;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 70784
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Console.ReadLine();
            Console.WriteLine(N[0] == N[2] ? "Yes" : "No");
        }
    }
}


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

int main(){
  int N;
  cin>>N;
  map<int,int> S;
  for(int i=0;i<N;++i){
    int A;
    cin>>A;
    ++S[A];
    S[A] %= 2;
  }

  int S_even=0,S_odd=0;
  for(auto p:S){
    if(p.second==1) ++S_odd;
    else ++S_even;
  }

  if(S_even%2==0) cout<<S_odd+S_even<<endl;
  else cout<<S_odd+S_even-1<<endl;
}


Measured memory_bytes: 4992
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,i,j;
	cin>>n;
	ll a[n+1];
	for(i=1;i<=n;i++)
		cin>>a[i];
	a[n+1]=a[n];
	for(i=n;i>0;i--){
		if(a[i+1]<a[i])a[i]--;
	}
	for(i=1;i<=n;i++)
		if(a[i]>a[i+1]){
			cout<<"No";return 0;
		}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
    int n, m, l;
    cin >> n >> m >> l;

    //a入力
    long a[n][m],b[m][l], c[n][l];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
        
    }

    //b入力
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < l; j++)
        {
            cin >> b[i][j];
        }
        
    }
    

    //c初期化, 入力、出力
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < l; j++)
        {
            c[i][j] = 0;
            for (int k = 0; k < m; k++)
            {
                c[i][j] += a[i][k] * b[k][j];
            }
            printf("%ld",c[i][j]);
            if(j<l-1)printf(" ");
        }
        printf("\n");
        
    }
    

    return 0;
}



Measured memory_bytes: 3304
import math as mt 
  
def cal_cos(n): 
  
    accuracy = 0.00000000001
    x1, denominator, cosx, cosval = 0, 0, 0, 0
  
    # Converting degrees to radian 
    n = n * (3.14159265358979323846264338328/ 180.0) 
  
    x1 = 1
  
    # Maps the sum along the series 
    cosx = x1 
  
    # Holds the actual value of sin(n) 
    cosval = mt.cos(n) 
    i = 1
    while (accuracy <= abs(cosval - cosx)): 
  
        denominator = 2 * i * (2 * i - 1) 
        x1 = -x1 * n * n / denominator 
        cosx = cosx + x1 
        i = i + 1
  
    return cosx 
  
# Function to find third side 
def third_side(A, B, F): 
    angle = cal_cos(F) 
    return mt.sqrt((A * A) + 
                   (B * B) - 2 * A * B * angle) 
  
# Driver Code 

A, B, H, M = map(int, input().split())

I=(M/60)
F=H+I
E=(F*30)
J=(M*6)

if E > J:
      G=E-J
else:
      G=J-E

angle=G

while angle > 360:
      
      angle=angle-360

if angle > 180:
      angle=360-angle

F=angle

print(third_side(A, B, F)) 

Measured memory_bytes: 9460
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  ll n, a, b;
  cin >> n >> a >> b;
  ll mini = a * (n - 1) + b;
  ll maxi = b * (n - 1) + a;
  cout << max(maxi - mini + 1, (ll)0) << endl;
	return 0;
}


Measured memory_bytes: 256
S=list(input())
N=len(S)
check=True
for i in range(N//2):
    if S[i]!=S[N-1-i]:
        check=False
        break
if check==False:
    print("No")
else:
    C=False
    for i in range((N//2)//2):
        if S[i]!=S[N//2-1-i]:#0123456
          C=True
          break
    if C==True:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 3060
from collections import Counter

n, x, y = map(int, input().split())
ans = []
for i in range(1, n+1):
    for j in range(1, n+1):
        ans.append(min(abs(j - i),
                       abs(x - i)+1+abs(j - y),
                       abs(y - i)+1+abs(j - x)))
ans_cnt = Counter(ans)
for i in range(1, n):
    print(ans_cnt[i] // 2)


Measured memory_bytes: 135144
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

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

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

using namespace std;

int main(){
	map<string, int> m;
	m["AC"] = m["TLE"] = m["RE"] = m["WA"] = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		string s;
		cin >> s;
		m[s] += 1;
	}
	cout << "AC x " << m["AC"] << '\n';
	cout << "WA x " << m["WA"] << '\n';
	cout << "TLE x " << m["TLE"] << '\n';
	cout << "RE x " << m["RE"] << '\n';
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		
		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			
			for (int i = 0; i < n; i++) {
				int m = sc.nextInt();
				int e = sc.nextInt();
				int j = sc.nextInt();
				if (m == 100 || e == 100 || j == 100) {
					System.out.println("A");
				} else if (90 <= (e + m) / 2) {
					System.out.println("A");
				} else if (80 <= (m + e + j) / 3) {
					System.out.println("A");
				} else if (70 <= (m + e + j) / 3) {
					System.out.println("B");
				} else if (50 <= (m + e + j) / 3 && (80 <= m || 80 <= e)) {
					System.out.println("B");
				} else {
					System.out.println("C");
				}
			}
		}
	}
}

Measured memory_bytes: 28272
io = STDIN
$h,$w=io.gets.chomp.split.map(&:to_i)
$board=[]
$sharp=0
$h.times do
  str = io.gets.chomp
  $sharp+=str.count("#")
  $board << str + "."
end
$board << "."*($w+1)
def parse(i,j,ct)
  return true if i==$h-1 && j==$w-1 && ct==$sharp
  [[0,1],[1,0]].each do |x,y|
    if $board[i+x][j+y]=="#"
      return true if parse(i+x,j+y,ct+1)
    end
  end
  false
end
puts parse(0,0,1) ? "Possible" : "Impossible"

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

using namespace std;

int main(void)
{
	long long int n,d;
	cin>>n>>d;
	d = d * d;
	long long int x,y,ans = 0;
	int k,t;
	for(int i = 0; i < n; i++){
		cin>>k>>t;
		if(k < 0) x = -1 * k;
		else x = k;
		if(t < 0) y = -1 * t;
		else y = t;
		if(x*x+y*y <= d) ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}
	
	




Measured memory_bytes: 3648