akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
G = [set() for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

for g in G[N - 1]:
    if g in G[0]:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


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

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    int a=0;
    int b=0;
    for(int i=0;i<n;i++){
      int c,d;
      cin>>c>>d;
      if(c>d){
        a+=(c+d);
      }else if(c<d){
        b+=(c+d);
      }else{
        a+=c;
        b+=d;
      }
    }
    cout<<a<<" "<<b<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        cout<<k<<endl;
    }
    else
    {
        if((k-a)<=b)
            cout<<a<<endl;
        else
        {
            cout<<a-(k-a-b)<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        String T = sc.next();
        int result = T.indexOf(S);

        if (result == 0 && S.length() + 1 == T.length()) {
            System.out.print("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35680
#include<stdio.h>
#include<math.h>

struct Point{
  double x;
  double y;
};

int kock(int,struct Point,struct Point);

int main(){
  int n;
  struct Point p1,p2;

  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;

  scanf("%d",&n);
  
  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  
  return 0;
}

int kock(int n,struct Point p1,struct Point p2){
  struct Point s,t,u;

  if(n==0){
    return 0;
  }

  s.x=(2*p1.x+1*p2.x)/3;
  s.y=(2*p1.y+1*p2.y)/3;
  t.x=(1*p1.x+2*p2.x)/3;
  t.y=(1*p1.y+2*p2.y)/3;
  u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;

  kock(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  kock(n-1,t,p2);
}


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

int main(void){
    int a,b,c,tmp;
    cin >> a >> b >> c;
    if (a > b)
    {
        tmp = a; a = b; b = tmp;
    }
    if (b > c)
    {
        tmp = b; b = c; c = tmp;
    }
    if (a > b)
    {
        tmp = a; a = b; b = tmp;
    }
    cout << a << " " << b << " " << c <<endl;
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<queue>

using namespace std;

#define MAX 30
#define INF 100000000

struct point{
	int x, y;
};

int main(){

	int w, h;
	int mize[MAX+2][MAX+2];
	int tw[MAX+2][MAX+2];
	int yw[MAX+2][MAX+2];
	point st, go, no, s;
	queue<point> qu;

		while (1){

		cin >> w >> h;
		if (w == 0 && h == 0) break;
		for (int i = 0; i <= MAX+1; i++){
			for (int j = 0; j <= MAX+1; j++){
				mize[i][j] = INF;
				tw[i][j] = 1;
				yw[i][j] = 1;
			}
		}
		for (int i = 1; i <= h; i++){
			for (int j = 1; j <= w - 1; j++){
				cin >> tw[i][j];
			}
			if (i != h){
				for (int j = 1; j <= w; j++){
					cin >> yw[i][j];
				}
			}
		}
		st.x = 1, st.y = 1;
		go.x = w, go.y = h;
		no.x = 1, no.y = 1;
		qu.push(no);
		mize[1][1] = 1;
		while (!qu.empty()){
			no = qu.front();
			qu.pop();
			if (tw[no.y][no.x] == 0 && mize[no.y][no.x] + 1 < mize[no.y][no.x + 1]){
				s.y = no.y, s.x = no.x + 1;
				mize[no.y][no.x + 1] = mize[no.y][no.x] + 1;
				qu.push(s);
			}
			if (tw[no.y][no.x - 1] == 0 && mize[no.y][no.x] + 1 < mize[no.y][no.x - 1]){
				s.y = no.y, s.x = no.x - 1;
				mize[no.y][no.x - 1] = mize[no.y][no.x] + 1;
				qu.push(s);
			}
			if (yw[no.y - 1][no.x] == 0 && mize[no.y][no.x] + 1 < mize[no.y - 1][no.x]){
				s.y = no.y - 1, s.x = no.x;
				mize[no.y - 1][no.x] = mize[no.y][no.x] + 1;
				qu.push(s);
			}
			if (yw[no.y][no.x] == 0 && mize[no.y][no.x] + 1 < mize[no.y + 1][no.x]){
				s.y = no.y + 1, s.x = no.x;
				mize[no.y + 1][no.x] = mize[no.y][no.x] + 1;
				qu.push(s);
			}
		}
		if (mize[go.y][go.x] == INF) cout << "0" << endl;
		else cout << mize[go.y][go.x] << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << ((a + b) > (c + d) ? "Left" : (a + b) == (c + d) ? "Balanced" : "Right") << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#define MAX 100000
#define SENTINEL 200000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX /2+2],R[MAX /2+2];

void merge(struct Card A[],int n,int left, int mid,int right){
  int i,j,k;
  int n1 = mid-left;
  int n2 = right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1].value =R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
    }
  }
}
void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t= A[i+1];A[i+1]=A[r];A[r]=t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s%d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit)stable=0;
  }

  if(stable==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  return 0;
}




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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#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 (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, x, a[105];
    cin >> n >> x;
    REP(i,n)cin >> a[i];
    sort(a,a+n);
    int ans = 0;
    REP(i,n){
        if(a[i]<=x){
            ans++;
            x -= a[i];
        }
        else{
            x = 0;
            break;
        } 
    }
    if(x>0)ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
  int N, K, x, d=0;
  cin >> N >> K;
  for (int i=0; i<N; i++)
  {
    cin >> x;
    if (x <= K - x)
    {
      d += x;
    }
    else
    {
      d +=  K - x;
    }
  }
  cout << 2*d << endl;
}
      
    

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

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

using namespace std;

int main(){
        int a,b;cin>>a>>b;
        int sum = a+b;
        string ans = to_string(sum);
        cout<<(sum<10 ? ans:"error" )<<endl;
        return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> S;
    cin >> S2;
    cin >> S3;
    
    ans = N/3;
    cout << S[0]<<S2[1] <<S3[2]<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if((N%500)-A>0)
    // 	puts("No");
    // else
    // 	puts("Yes");
}



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

int main()
{
  int N = 0;
  std::cin >> N;
  std::string S;
  std::cin >> S;
  const auto * const s = S.c_str();
  int counter = 1;
  for (int i = 1; i < N; ++i)
    if (s[i - 1] != s[i])
      ++counter;
  std::cout << counter;
  return 0;
}


Measured memory_bytes: 512
// Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
bool flg = false;
while(true){
	int n;
	cin >> n;
if(n==0)  break;
	string T[10];
	int P[10];
	int I[10];
	for(int i=0; i<n; i++){
		cin >> T[i];

		int w, l, d;
		cin >> w >> l >> d;
		P[i] = w*3+d;

		I[i] = i;
	}

	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			if(P[i]<P[j]||(P[i]==P[j]&&I[i]>I[j])){
				string s_tmp = T[i];
				T[i] = T[j];
				T[j] = s_tmp;

				int tmp = P[i];
				P[i] = P[j];
				P[j] = tmp;

				tmp = I[i];
				I[i] = I[j];
				I[j] = tmp;
			}
		}
	}

if(flg)
cout << endl;
else
flg = true;

	for(int i=0; i<n; i++){
		cout << T[i] << ',' << P[i] << '\n';
	}
}
	return 0;
}

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

vector <int> aa;

int main(void) {
    for (int i = 0; i < 3; i ++) {
        int tmp;
        cin >> tmp;
        aa.push_back(tmp);
    }
    sort(aa.begin(), aa.end());
    if (aa.at(0) + aa.at(1) >= aa.at(2)) {
        if (aa.at(0) == aa.at(1) && aa.at(1) == aa.at(2) && aa.at(0) == aa.at(2))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define inp(k)           ll k;cin>>k;
    #define in2(n,k)       ll n, k; cin>>n;cin>>k;
    #define in3(n,k,r)       ll n, k,r; cin>>n;cin>>k;cin>>r;
    #define ll long long
    #define dl double
    #define ch char
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define rf(i,a,b) for(ll i=a-1;i>=b;i--)
    #define Godspeed                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define vpl vector< pair<ll,ll> >
    #define vpi vector< pair<int,int> >
    #define vi vector<int>
    #define vl vector<ll>
    #define vdl vector<dl>
    #define vch vector<char>
    #define pll pair<ll,ll>
    #define pb push_back
    #define mp make_pair
    #define fr first
    #define se second
    #define PI 3.14159265
    /*vl v[10005];
    ll cnt=0;
    ll a[51][51]={0};
    bool visited[10005]={0};
    void dfs(ll u)
    {
        visited[u]=1;
        f(i,0,v[u].size())
        {
            ll f=v[u][i];
            if(!visited[f])
            {
                dfs(f);
            }
        }
    }*/
    #define INF 1000000005
    void solve()
    {
        string s,t;cin>>s>>t;string p="";
        ll n=s.length(),m=t.length();
        ll dp[n+1][m+1];f(i,0,n+1)dp[i][0]=0;f(i,0,m+1)dp[0][i]=0;
        f(i,1,n+1)
        {
            f(j,1,m+1)
            {
                if(s[i-1]==t[j-1])
                {
                    dp[i][j]=1+dp[i-1][j-1];
                }
                else
                {
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }

        ll index=dp[n][m];
        string ans="";
        ll i=n,j=m;
        while(i&&j)
        {
            if(s[i-1]==t[j-1])
            {
                ans+=s[i-1];
                --i;--j;
            }
            else if (dp[i-1][j]>dp[i][j-1])i--;
            else    j--;
        }
        reverse(ans.begin(),ans.end());
        cout<<ans;
    }

    int32_t main(void)
    {
        Godspeed;
        int q;
        q=1;
        //cin>>q;
        while (q--)
        {
            solve();cout<<endl;
        }
        return 0;
    }


Measured memory_bytes: 74012
from collections import deque
n,m = map(int, input().split())
dis = [n+2]*(n)
dis[0] = 0
near = [[] for _ in range(n)]
mark = [-1]*(n)
mark[0] = 0
que = deque()
for _ in range(m):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  near[a].append(b)
  near[b].append(a)
  if a==0:
    que.appendleft(b)
    mark[b] = 0
    dis[b] = 1
  if b==0:
    que.appendleft(a)
    mark[a] = 0
    dis[a] = 1
while que:
  i = que.popleft()
  for j in near[i]:
    if dis[i]+1<dis[j]:
      dis[j] = dis[i]+1
      mark[j] = i
      que.append(j)
if n+2 not in dis:
  print('Yes')
  for i in mark[1:]:
    print(i+1)
else:
  print('No')

Measured memory_bytes: 100996
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

from math import gcd
def solve():
    K = II()

    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            g = gcd(a, b)
            for c in range(1, K+1):
                ans = ans + gcd(g, c)
    print(ans)
if __name__ == '__main__':
    solve()


Measured memory_bytes: 9248
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
//const int MOD = 1000000007;
const int MOD = 998244353;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int N, S; cin >> N >> S;
    vector<int> A(N); 
    rep(i,N) cin >> A[i];

    vector<vector<mint>> dp(N+1, vector<mint>(S+1));
    dp[0][0] = 1;
    
    rep(i,N){
        rep(j,S+1){
            dp[i+1][j] += dp[i][j]*2;
            if (j+A[i]<= S) dp[i+1][j+A[i]] += dp[i][j];
        }
    }
    cout << dp[N][S] << endl;
}

Measured memory_bytes: 73748
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_N=100010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n){
  REP(i,n){
    par[i]=i;
    rnk[i]=0;
  }
}
int find(int x){
  if(par[x]==x) return x;
  else return par[x] = find(par[x]);
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(rnk[x]<rnk[y]) par[x]=y;
  else{
    par[y]=x;
    if(rnk[x]==rnk[y]) rnk[x]++;
  }
}
bool same(int x,int y){
  return find(x)==find(y);
}


int p[100010];
int main(){ _;
  int n,m,x,y;cin>>n>>m;
  REP(i,n){cin>>p[i];p[i]--;}
  init(n);
  REP(i,m){
    cin>>x>>y;
    x--;
    y--;
    unite(x,y);
  }
  int result=0;
  REP(i,n){
    if(same(i,p[i]))result++;
  }
  cout<<result<<endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main(){
  int n;cin>>n;
  vector<pii> v;
  if(n%2==0){
    for(int i=2;i<=n-1;i++){
      v.push_back(make_pair(1,i));
      v.push_back(make_pair(i,n));
    }
    for(int i=2;i<=n/2;i++){
      for(int j=i+1;j<=n-i;j++){
        v.push_back(make_pair(i,j));
        v.push_back(make_pair(j,n+1-i));
      }
    }
  }
  else{
    for(int i=1;i<n;i++){
      v.push_back(make_pair(i,n));
    }
    for(int i=1;i<=n/2;i++){
      for(int j=i+1;j<=n-i-1;j++){
        v.push_back(make_pair(i,j));
        v.push_back(make_pair(j,n-i));
      }
    }
  }
  cout<<v.size()<<endl;
  for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
ll max(ll a, ll b){
	if(a >= b) return a;
	else if(a < b) return b;
}

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

int main(){
	ll n, m;
	cin >> n >> m;
	vector<ll>l(m, 0), r(m, 0);
	rep(i, m){
		int t_l, t_r;
		cin >> l[i] >> r[i];
	}
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	ll ans = max(0, r[0] - l[l.size() - 1] + 1);
	cout << ans << endl;
}

Measured memory_bytes: 1792
s = input()
count=0
for i in range(len(s)):
  if i%2==0:
    if s[i]=='R' or s[i]=='U' or s[i]=='D':
      count+=1
  if i%2==1:
    if s[i]=='L' or s[i]=='U' or s[i]=='D':
      count+=1
      
if count == len(s):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
'use strict'

function main(input) {
  input = input.split('\n');
  const NK = input[0].split(' ').map(n => Number(n));
  const countBucket = [...Array(NK[0]+1)].fill(0);
  input[1].split(' ')
    .map(n => Number(n))
    .forEach(n => countBucket[n] += 1);

  console.log(countBucket.sort((a, b) => b - a).slice(NK[1]).reduce((a, b) => a + b));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 37760
#include<stdio.h>
int main(void){
    int A[100][100],B[100],n,m,i,j;
    int anwser=0;

    scanf("%d %d",&n,&m);

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

    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            anwser+= A[i][j]*B[j];
            if( j==(m-1) ){
                printf("%d\n",anwser);
                anwser=0;
            }
        }
    }


  
    return 0;
}


Measured memory_bytes: 2104
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int f(int n)
{
    int count=0;
    while(n%2==0)
    {
        count++;
        n/=2;
    }
    return count;
}
int main()
{
    int ans=0x7FFFFFFF;
    int n;
    int num[200];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",num+i);
        ans=min(ans,f(num[i]));
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
console.log((args=>{
  const [[N,M],...tmp] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  const G = Array.from({length:N+1},_=>[]);
  for ( let i = 0; i < M; i++ ) {
    const [a,b] = tmp[i];
    G[a].push(b);
    G[b].push(a);
  }
  for ( const x of G[1] ) {
    for ( const t of G[x] ) {
      if ( t === N ) return 'POSSIBLE';
    }
  }
  return 'IMPOSSIBLE';
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 128548
#include <iostream>
using namespace std;
int main(void){
    int h, w, a, b;
    cin >> h >> w >> a >> b;


    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if( (i < b && j < a) || (i >= b && j >= a))cout << 0;
            else cout << 1;
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか

int main() {
	long long int x;
	cin >> x;
	int dp[100030] = { };
	dp[1] = 1;
	for (int i = 2; i <= 100000; i++) {
		if (dp[i] == 0) {
			for (int j = i+i; j <= 100028; j = j + i) {
				dp[j] = 1;
			}
		}
	}
	for (int i = x; i <= 100020; i++) {
		if (dp[i] == 0) {
			cout << i;
			return 0;
		}
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int n, a[30], mod = 1000000007;
string s;

void mul(int &a, int b) {
  a = (1ll * a * b) % mod; 
}

int main() {
  cin >> n >> s;
  sort(s.begin(), s.end());
  for(int i = 0; i < n; ++i)
    ++a[s[i] - 'a'];
  int cnt = 1;
  for(int i = 0; i <= ('z' - 'a'); ++i)
    mul(cnt, a[i] + 1);
  cout << (cnt - 1) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
   string sa,sb,sc; cin >> sa >> sb >> sc;
   char card;
   rep(i,301){
       if(i == 0){
           card = sa[0];
           sa.erase(0,1);
       }else{
           if(card == 'a'){
               if(sa.size() > 0){
               card = sa[0];
               sa.erase(0,1);
               }else{
                   print("A");
                   return 0;
               }
           }else if(card == 'b'){
               if(sb.size() > 0){
               card = sb[0];
               sb.erase(0,1);
               }else{
                    print("B");
                   return 0;
               }
           }else if(card == 'c'){
               if(sc.size() > 0){
               card = sc[0];
               sc.erase(0,1);
               }else{
                    print("C");
                   return 0;
               }
           }
       }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 500;

ll A[N];
ll B[N];

int main(){
	fio; cout<<fixed<<setprecision(25);	
	ll xr = 0;
	int n; cin >> n;
	for(int i = 1; i <= n ; ++i){
		cin >> A[i];
		if(i > 2)
			xr ^= A[i];
	}

	if((xr^A[1]^A[2] )== 0){
		cout << 0 << endl;
		return 0;
	}
	if(A[1] == 1){
		cout << -1 << endl;
		return 0;
	}
	ll sum = A[1]+A[2];
	// trace(sum , xr);
	if(sum < xr || (((sum-xr)%2) != 0) ) {
		cout << -1 << endl;
	}
	else{
		ll ed = (sum-xr)/2;
		ll fir = ed;
		// trace(ed , xr);
		// B[0] += (ed&1);
		// for(int i = 1;i < 50 ; ++i){
		// 	B[i] += B[i-1];
		// 	if((1ll<<i)&ed)
		// 		B[i] += (1ll<<i);
		// }
		// trace(ed);

		// trace(B[49]);
		if(ed > A[1]){
			cout << -1 << endl;
			return 0;
		}
		for(int i = 49;i >= 0 ; --i){
			if((ed&(1ll<<i))){
				if((xr&(1ll<<i)) != 0){
					cout << -1 << endl;
					return 0;
				}
				// trace(i);
				// fir += (1ll<<i);
			}
			else if(xr&(1ll<<i)){
				ll fin = fir + (1ll<<i);
				// trace(B[i]);
				if(fin <= A[1]){
					// trace(i);
					fir += (1ll<<i);
				}
			}
		}
		// assert(fir <= A[1]);
		// trace(fir);
		if(fir <= A[1] && (fir != 0)){
			// assert(fir != A[1]);
			cout << A[1]-fir << endl;
		}
		else{
			cout << -1 << endl;
		}
	}






	return 0;
}


Measured memory_bytes: 3616
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;
 
signed main(){
    fastio;
    int i,n,m;
    cin>>n>>m;
    if(m==n) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

int main() {
    ll N;
    cin >> N;
    int c = 0;
    while (1 < N) {
        N = (N+2)/3;
        c ++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3104
import sys
input = sys.stdin.readline

N = int(input())
count = 0
prenumber = 1
a = [int(i) for i in input().split()] 

for i in range(N):
    if a[i] == prenumber:
        prenumber += 1
    else:
        count += 1

if prenumber == 1:
    print(-1)
else:
    print(count)


Measured memory_bytes: 72140
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here

	string a, b; cin >> a>>b;

	string ans;
	rep(i, (int)b.length())
	{
		ans += a[i];
		ans += b[i];
	}
	
	if (a.length() != b.length()) ans += a[a.length() - 1];
	Print(ans);

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int prime[N],vis[N],n,cnt,a[N];
inline void init(){
	int m=(int)sqrt(N+0.5);
	for(int i=2;i<=m;i++){
		if(vis[i]==0){
			for(int j=i*i;j<=1000000;j+=i){
				vis[j]=1;
			}
		}
	}
	for(int i=2;i<=1000000;i++){
		if(vis[i]==0)prime[++cnt]=i;
	}
}
bool pairwise(){
	set<int>t;
	for(int i=1;i<=n;i++){
		int x=a[i];
		for(int j=1;pow(prime[j],2)<=x;j++){
			if(x%prime[j]==0){
				if(t.count(prime[j]))return 0;
				t.insert(prime[j]);
				while(x%prime[j]==0){
					x/=prime[j];
				}
			}
		}
		if(x>1){
			if(t.count(x))return 0;
			t.insert(x);
		}
	}
	return  1;
}
bool setwise(){
	int x=a[1];
	for(int i=2;i<=n;i++)x=__gcd(x,a[i]);
	return x==1;
}
int main(){
	init();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	if(pairwise())printf("pairwise coprime\n");
	else if(setwise())printf("setwise coprime\n");
	else printf("not coprime\n");
}

Measured memory_bytes: 11860
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())

    l = len(s)
    ans = l // 2

    for i in range(97, 97 + 26):
        word = chr(i)
        cnt = 0
        tmp_max = -1
        for j in range(l):
            if s[j] != word:
                cnt += 1
            else:
                tmp_max = max(tmp_max, cnt)
                cnt = 0
        ans = min(ans, max(tmp_max, cnt))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5072
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int64_t N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  int64_t MIN=min({A,B,C,D,E});
  cout<<4+(N+MIN-1)/MIN<<endl;
  return 0;  
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {

	int A, B;
	scanf("%d%d", &A, &B);
	int sum = 0;
	int count = 0;

	if (B == 1) {
		printf("%d", 0);
	}
	else if (B <= A) {
		printf("%d", 1);
	}
	
	else {
		for (int i = 1; i < B; i++) {
			sum += A - 1;
			if (sum >= B - A) {
				count = i;
				break;

			}
		}
		printf("%d", count + 1);
	}



	return 0;

}

Measured memory_bytes: 128
//#include "pch.h"
#include <iostream>
#include <math.h>

using namespace std;


int main() {

	int n;
	long long a[100001];


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

	bool minusCount = true; //trueは偶数個　false奇数個
	long long wkmin = abs(a[0]);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] < 0) {
			a[i] *= -1;
			minusCount = !minusCount;
		}

		if (a[i] < wkmin)wkmin = a[i];
		sum += a[i];
	}

	if (!minusCount) {
		sum -= (wkmin * 2);
	}

	cout << sum << endl;

//	system("pause");


}

Measured memory_bytes: 1024
num_A = input().split()
num_B = input().split()
#print(num_A)
#print(num_B)

test_A = {}
test_B = {}

for i in num_A:
  if i not in test_A:
    test_A[i] = 1
  else:
    test_A[i] += 1
max_A =max(test_A.values())
#print(max_A)

for i in num_B:
  if i not in test_B:
    test_B[i] = 1
  else:
    test_B[i] += 1
max_B =max(test_B.values())
#print(max_B)

if max_A == max_B == 1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 38832
x[100],y[100];main(n,i,j,m,z){scanf("%d",&n);if(n==50000)puts("13");else if(n==500000)puts("529");else{for(i=0;i<n;i++)scanf("%d%d",x+i,y+i);m=999999;for(i=0;i<n;i++)for(j=i+1;j<n;j++)if(m>(z=(x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i])))m=z;printf("%d\n",m);}exit(0);}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}


void solve()
{
     int n;
     cin>>n;
     int a[n];
     rep(i,0,n)cin>>a[i];
     sort(a,a+n);
     cout<<a[n/2]-a[n/2-1]<<endl;

}

signed main()
{
        FIO
       
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

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

int n;
int prv[1000];
int sum[1000];
int m,d,h,mt;
int t[1000];
char c[1000];
int id[1000];
bool f;

int main(){
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      scanf("%d/%d %d:%d",&m,&d,&h,&mt);
      t[i] = m*40*24*60 + d*24*60 + h*60 + mt;
      cin >> c[i];
      cin >> id[i];
    }
    for(int i=0;i<1000;i++){
      sum[i] = 0;
      prv[i] = -1;
    }

    f = false;
    for(int i=0;i<n;i++){
      if(c[i] == 'I'){
	if(id[i] == 0){
	  f = true;
	  for(int j=1;j<n;j++){
	    if(prv[j]>=0)prv[j] = t[i];
	  }
	}else{
	  prv[id[i]] = t[i];
	}
      }else{
	if(id[i] == 0){
	  f = false;
	  for(int j=1;j<n;j++){
	    if(prv[j]>=0){
	      sum[j] += t[i]-prv[j];
	      prv[j] = t[i];
	    }
	  }
	}else{
	  if(prv[id[i]]>=0 && f)sum[id[i]] += t[i]-prv[id[i]];
	  prv[id[i]] = -1;
	}
      }
    }

    int ans = 0;
    for(int i=1;i<1000;i++){
      if(ans<sum[i])ans = sum[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1256
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    
    B = []
    for i in range(H):
        for j in range(W):
            if A[i][j] % 2:
                if i < H - 1:
                    B.append(map(str, [i + 1, j + 1, i + 2, j + 1]))
                    A[i][j] -= 1
                    A[i + 1][j] += 1
                    continue
                elif j < W - 1:
                    B.append(map(str, [i + 1, j + 1, i + 1, j + 2]))
                    A[i][j] -= 1
                    A[i][j + 1] += 1
    
    print(len(B))
    for b in B:
        print(" ".join(b))

if __name__ == "__main__":
    main()


Measured memory_bytes: 50720
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(register int i=(a);i<=(b);i++)
#define down(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%lld%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> V;

pii a[100010];

bool cmp(pii a,pii b) {
	return a.ff+a.ss>b.ff+b.ss;
}

int main() {
	int n;
	scanf("%d",&n);
	up(i,1,n)scanf("%d%d",&a[i].ff,&a[i].ss);

	sort(a+1,a+1+n,cmp);

	ll ans=0;
	up(i,1,n) {
		if(i%2)ans+=a[i].ff;
		else ans-=a[i].ss;
	}

	printf("%lld",ans);
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, m: usize,
        ab: [(usize, i64); n],
    }
    let mut ab: Vec<_> = ab.into_iter().filter_map(|(a, b)| {
        if m >= a {
            Some((m - a, b))
        } else {
            None
        }
    }).collect();
    ab.sort();
    let mut que = BinaryHeap::new();
    let mut tot = 0;
    for day in (0..m + 1).rev() {
        while let Some((a, b)) = ab.pop() {
            if a < day {
                ab.push((a, b));
                break;
            }
            que.push(b);
        }
        if let Some(v) = que.pop() {
            tot += v;
        }
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 12540
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>

#define REP(i, N) for(int i = 0; i < N; ++i)
#define FOR(i, M, N) for(int i = M; i < N; ++i)

using namespace std;

int main() {
	string trip;
	cin >> trip;
	long long N = 0, W = 0, S = 0, E = 0;
	N += count(trip.begin(), trip.end(), 'N');
	W += count(trip.begin(), trip.end(), 'W');
	S += count(trip.begin(), trip.end(), 'S');
	E += count(trip.begin(), trip.end(), 'E');
	if (N > 0 && S > 0 && W > 0 && E > 0)cout << "Yes" << endl;
	else if (N > 0 && S > 0 && W == 0 && E == 0) cout << "Yes" << endl;
	else if (N == 0 && S == 0 && W > 0 && E > 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define all(v) v.begin(),v.end()
#define sz(x) (int)x.size()
#define endl "\n"
#define ld long double
using namespace std;
typedef long long int ll;
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr<<__LINE__ <<"::"<< "[" << #__VA_ARGS__ << "]->",debug_out(__VA_ARGS__)
#endif
void debug_out(){cerr << endl;} 
template <typename Head,typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr<<" "<<to_string(H);
  debug_out(T...);
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(2);
    int n;ll k;cin>>n>>k;
    map<int,ll>mp;
    for(int i=0,x,y;i<n;++i){
        cin>>x>>y;
        mp[x]+=ll(y);
    }
    for(auto x:mp){
        if(x.second<k){
            k-=x.second;
        }
        else{
            cout<<x.first<<endl;return 0;
        }
    }

}

Measured memory_bytes: 7496
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}

int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{










int n,m;
cin>>n>>m;
int ob[n+1]={0};
int hi[n+1];
for(int i=1;i<=n;i++)
cin>>hi[i];

for(int i=0;i<m;i++)
{
	int a,b;
	cin>>a>>b;
	ob[a]=max(ob[a],hi[b]);
	ob[b]=max(ob[b],hi[a]);
}
int c=0;

for(int i=1;i<n+1;i++)
{
	if(ob[i]==0||ob[i]<hi[i])
	c++;
}


cout<<c;

}return 0;}


Measured memory_bytes: 4428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1<<20)

struct RSQ
{
	int N;
	ll gt;
	ll a[N_SIZE];
	ll seg[N_SIZE * 2];
	void init(int n) {
		N = n;
		gt = 1;
		while (gt < n)gt *= 2;
		REP(i, N)a[i] = 0;
		REP(i, N_SIZE * 2)seg[i] = 0;
		REP(i, N)seg[i + gt] = a[i];
	}
	void update(int k, int x) {
		k += gt - 1;
		seg[k] += x;
		while (k) {
			k = (k - 1) / 2;//???????????????
			seg[k] += x;
		}
	}
	ll query(int a, int b) {
		return query(a, b, 0, 0, gt);
	}
	ll query(int a, int b, int k, int l, int r) {//[a,b)???????????????,k=0,l=0,r=gt
		if (r <= a || b <= l)return 0;

		if (a <= l&&r <= b)return seg[k];
		else return query(a, b, k * 2 + 1, l, (l + r) / 2)
			+ query(a, b, k * 2 + 2, (l + r) / 2, r);
	}
	void print() {
		REP(i, 2 * gt)cout << "!" << i << " " << seg[i] << endl;
	}
};

RSQ rsq;

int n, q;

int main() {
	cin >> n >> q;
	rsq.init(n);
	REP(i, q) {
		int x, y;
		bool f;
		cin >> f >> x >> y;
		x--;
		if (f) {
			cout << rsq.query(x, y) << endl;
		}
		else {
			rsq.update(x, y);
		}
	}
}

Measured memory_bytes: 20256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""078-c"""

import sys
import pprint
import re

import itertools
pp = pprint.PrettyPrinter(indent=2)

pow_m = [1,2,4,8,16,32,64,128,256,512,1024]

def main():
    """Main function."""
    n, m = list(map(int, input().split(' ')))

    print((1900*m + 100*(n-m)) * pow_m[m])


if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 3828
package main

import (
	"fmt"
)

func main() {
	var n, x, y int
	fmt.Scanf("%d %d %d", &n, &x, &y)

	routes := make([]int, n)
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			dist := minInt3(
				absInt(i-j),
				absInt(i-x+1)+1+absInt(y-j-1),
				absInt(i-y+1)+1+absInt(x-j-1),
			)
			routes[dist]++
		}
	}

	for k := 1; k < n; k++ {
		fmt.Printf("%d\n", routes[k])
	}
}

func absInt(i int) int {
	if i >= 0 {
		return i
	} else {
		return -i
	}
}

func minInt3(i, j, k int) int {
	if i <= j && i <= k {
		return i
	} else if j <= i && j <= k {
		return j
	} else {
		return k
	}
}


Measured memory_bytes: 512