akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
	llint n,K,ans=0,i,j;cin>>n>>K;
	static llint aaa[100001]={};
	for(i=1;i<=K;i++){
		aaa[i]+=i;
		for(j=i+i;j<=K;j+=i){aaa[j]-=aaa[i];}
	}
	for(i=1;i<=K;i++){
		llint gen=aaa[i],bai=K/i;
		for(int h=0;h<25;h++){
			if(n&(1<<h)){gen*=bai;gen%=mod;}
			bai*=bai;bai%=mod;
		}
		ans+=gen;ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4312
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();

        if (a+b<=2*c){
            System.out.println(a*x+b*y);
        }else{
            int i = Math.abs(x-y);
            int j;
            if (x>y){
                if (a>2*c){
                    j = 2*c*i;
                }else{
                    j = a*i;
                }
            }else if (x<y){
                if (b>2*c){
                    j = 2*c*i;
                }else{
                    j = b*i;
                }
            }else {
                j = 0;
            }
            System.out.println(Math.min(x,y)*2*c+j);

        }
    }

}

Measured memory_bytes: 21844
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;
bool com(pair<int,int> p1,pair<int,int> p2){
  return p1.second<p2.second;
}

void solve(){
  int num,m;
  cin >> num >> m;
  vector<pair<int,int>> ps(m);
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    ps[i]=make_pair(a,b);
  }
  sort(ps.begin(),ps.end(),com);
  int res=0;
  int last=-1;
  for(int i=0;i<m;i++){
    if(ps[i].first<last)continue;
    res++;
    //cout << last << endl;
    last=ps[i].second;
  }
  cout << res << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), x.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

int main(void){
  int n, k;
  string s;
  cin >> n >> k >> s;

  int score = 0;
  REP(i, n-1) if(s[i] == s[i+1]) score++;

  int ans = min(score + 2*k, n-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll a, v;
  cin >> a >> v;
  ll b, w;
  cin >> b >> w;
  ll t;
  cin >> t;
  if(b < a){
    b -= w * t;
    a -= v * t;
    if(a<= b){
      cout << "YES\n";
    }else{
      cout << "NO\n";
    }
  } else {
    b += w * t;
    a += v * t;
    if(a >= b){
      cout << "YES\n";
    }else{
      cout << "NO\n";
    }
  }
  return 0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

vector<ll> g[maxs];

void solve(){
    ll x,y;
    cin>>x>>y;
    ll A,B,C;
    cin>>A>>B>>C;
    ll a[A+1];
    ll pre_a[A+1];
    memset(pre_a,0,sizeof pre_a);
    ll b[B+1];
    ll pre_b[B+1];
    memset(pre_b,0,sizeof pre_b);
    ll c[C+1];
    ll pre_c[C+1];
    memset(pre_c,0,sizeof pre_c);
    for(ll i=1;i<=A;i++)    
        cin>>a[i];
    for(ll i=1;i<=B;i++)
        cin>>b[i];
    for(ll i=1;i<=C;i++)
        cin>>c[i];
    
    sort(a+1,a+A+1,greater<ll>());
    sort(b+1,b+B+1,greater<ll>());
    sort(c+1,c+C+1,greater<ll>());

    vector<ll> res;
    for(ll i=1;i<=x;i++){
        res.pb(a[i]);
    }
    for(ll i=1;i<=y;i++){
        res.pb(b[i]);
    }
    for(ll i=1;i<=C;i++){
        res.pb(c[i]);
    }
    sort(res.begin(),res.end(),greater<ll>());

    ll sum=0;
    for(ll i=0;i<x+y;i++)
        sum += res[i];

    cout << sum << endl;
    // pre_a[0] = 0;
    // pre_b[0] = 0;
    // pre_c[0] = 0;

    // for(ll i=1;i<=A:i++){
    //     pre_a[i] = pre_a[i-1] + a[i];
    // }
    // for(ll i=1;i<=B:i++){
    //     pre_b[i] = pre_b[i-1] + b[i];
    // }
    // for(ll i=1;i<=C:i++){
    //     pre_c[i] = pre_c[i-1] + c[i];
    // }

    // ll l=0,r=x;
    // ll MAX=0;
    // while(l<=r){
    //     ll mid = (l+r)/2;
    //     ll rem = x-mid;
    //     ll sum = pre_a[mid];
    //     ll LL = 0 , RR = y;
    //     while(LL <= RR){
    //         ll MID = (LL+RR)/2;
    //         ll REM = y - mid;
    //         ll SUM = pre_b[MID];
    //         if(rem + REM > C){
    //             LL = mid+1;
    //         }
    //         else{

    //         }
    //     }  
    // }
    
}

int main(){
    #ifdef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 34288
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	H := nextInt()
	W := nextInt()
	m := map[uint8]int{}
	for i := 0; i < H; i++ {
		s := nextString()
		for j := range s {
			m[s[j]]++
		}
	}
	counts := make([]int, 0)
	for _, v := range m {
		counts = append(counts, v)
	}
	var g4, g2, g1 int
	g4 = (H / 2) * (W / 2)
	if H%2 == 1 {
		g2 += W / 2
	}
	if W%2 == 1 {
		g2 += H / 2
	}
	if H%2 == 1 && W == 1 {
		g1 = 1
	}
	for g4 > 0 {
		found := false
		for i := range counts {
			if counts[i] >= 4 {
				counts[i] -= 4
				g4--
				found = true
			}
		}
		if !found {
			fmt.Println("No")
			return
		}
	}
	for g2 > 0 {
		found := false
		for i := range counts {
			if counts[i] >= 2 {
				counts[i] -= 2
				g2--
				found = true
			}
		}
		if found == false {
			fmt.Println("No")
			return
		}
	}
	for g1 > 0 {
		found := false
		for i := range counts {
			if counts[i] >= 1 {
				counts[i]--
				g1--
				found = true
			}
		}
		if !found {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[i].b
}

var nextReader func() string

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
using namespace std;

void solve()
{
    ll n,d;
    cin >> n >> d;
    int c=0;
    while(n--)
    {
        ll x,y;
        cin >>x>>y;
        ll dx=x*x + y*y;
        if(dx<=(d*d))
            c++;
    }
    cout << c << endl;
}

int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();

    return 0;
}



Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] b = new int[n-1];
    for(int i=0; i<n-1; i++) {
      b[i] = Integer.parseInt(str[i]);
    }
    
    int aSum = 0;
    if(n>=3) {
      aSum += b[0];
      for(int i=0; i<n-1; i++) {
        if(i==n-2)
          aSum += b[i];
        else
          aSum += Math.min(b[i],b[i+1]);
      }
    }
    
    System.out.println(n==2?b[0]*2:aSum);
  }
}

Measured memory_bytes: 32748
#include<stdio.h>
main( )
{
  int num;
  int i = 0 ;
 
  while(1)
    {
      ++i;
       
      scanf("%d", &num);
      if( num == 0)
    break;
 
      printf("Case %d: %d\n", i, num);
 
    }
 
 
  return 0;
 
 
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int N=S.size(),a=0;
    for(int i=0;i<N;i++){
        a+=S[i]-'0';
    }
    int s=stoi(S);
    cout<<(s%a==0?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

int main(){

    int n;
    cin >> n;

    string s;
    cin >> s;

    bool isok[10][10][10];
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            for(int k = 0; k <= 9; k++){
                isok[i][j][k] = false;
            }
        }
    }    

    vector<int> cntL(10);
    vector<int> cntR(10);

    for(int i = 0; i < n; i++){
        int c = (int)(s[i] - '0');
        cntR[c] ++ ;
    }

    int c = (int)(s[0] - '0');
    cntL[c] ++;
    cntR[c] --;

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

        int c = (int)(s[i] - '0');
        cntR[c] --;
        for(int l = 0; l <= 9; l++){
            for(int r = 0; r <= 9; r++){
                if( cntL[l] >= 1 && cntR[r] >= 1 ){
                    isok[l][c][r] = true;
                }
            }
        }
        cntL[c] ++;

    }

    int ans = 0;
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            for(int k = 0; k <= 9; k++){
                if(isok[i][j][k]){
                    ans ++;
                    if(DEBUG) cout << i << j << k << endl;
                }
            }
        }
    }    
    cout << ans << endl;

}

Measured memory_bytes: 256
while True :
    x=10
    y=10
    n=int(input())
    if n==0:break
    l=[input() for _ in range(n)]
    l2=["10 10"]
    n2=int(input())
    for i in range(n2):
        a,b=map(str,input().split())
        b=int(b)
        if a=="N":
            for i in range(b):
                y+=1
                l2.append("{} {}".format(x,y))
        elif a=="W":
            for j in range(b):
                x-=1
                l2.append("{} {}".format(x,y))
        elif a=="S":
            for m in range(b):
                y-=1
                l2.append("{} {}".format(x,y))
        else:
            for n in range(b):
                x+=1
                l2.append("{} {}".format(x,y))
    s=0
    for l3 in l:
        if l2.count(l3)==0:
            print("No")
            s=1
            break
    if s==0:
        print("Yes")



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

int main() {
  int N,Z=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    int a;
    cin>>a;
    if(a!=i){
      Z++;
    }
  }
  
  if(Z==0||Z==2){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

#define INF -1

int d[21][21];
char M[21][21];
int h,w;

int bfs(int i,int j){
  queue<pair<int,int>> q;
  q.push({i,j});
  rep(x,21){
    rep(y,21) d[x][y]=INF;
  }
  d[i][j]=0;
  
  pair<int,int> p;
  while(!q.empty()){
    p=q.front(); q.pop();
    if(p.first>0 && M[p.first-1][p.second]=='.' &&  d[p.first-1][p.second] == INF){
      d[p.first-1][p.second]=d[p.first][p.second]+1;
      q.push({p.first-1,p.second});
    }
    if(p.first<h-1 && M[p.first+1][p.second]=='.' &&  d[p.first+1][p.second] == INF){
      d[p.first+1][p.second]=d[p.first][p.second]+1;
      q.push({p.first+1,p.second});
    }
    if(p.second>0 && M[p.first][p.second-1]=='.' &&  d[p.first][p.second-1] == INF){
      d[p.first][p.second-1]=d[p.first][p.second]+1;
      q.push({p.first,p.second-1});
    }
    if(p.second<w-1 && M[p.first][p.second+1]=='.' &&  d[p.first][p.second+1] == INF){
      d[p.first][p.second+1]=d[p.first][p.second]+1;
      q.push({p.first,p.second+1});
    }
  }
  
  int m=0;
  rep(x,h){
    rep(y,w) chmax(m,d[x][y]);
  }
   
  return m;
}

int main() {
  cin>>h>>w;
  
  rep(i,h){
    rep(j,w) cin>>M[i][j];
  }
  

  int ma=0;
  rep(i,h){
    rep(j,w){
      if(M[i][j]=='.') chmax(ma,bfs(i,j));
    }
  }
  
  cout<<ma<<endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

def calc(A):
    ans = 0
    for i in range(len(A)):
        ans += A[i] * (i + 1)

    return ans

VALUE = [0 for i in range(100000)]

for i in range(N):
    VALUE[A[i] - 1] += 1

ANS = []
ANS.append(calc(VALUE))

for i in range(Q):
    VALUE[BC[i][1] - 1] += VALUE[BC[i][0] - 1]
    ANS.append(ANS[i] + (BC[i][1] - BC[i][0]) * VALUE[BC[i][0] - 1])
    VALUE[BC[i][0] - 1] = 0

for i in range(1, Q + 1):
    print(ANS[i])


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    lli n; cin >> n;
    REP(i, 1, 100){
        if(n%2==0 && n%n==0) break;
        n=n*i;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int unsigned long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
int A, B, C ; 
signed main()
{
	A = gi(), B = gi(), C = gi() ;
	if( C <= A + B ) {
		puts("No") ; exit(0) ;
	}
	long long t = C - A - B ; 
	int sq = 1ull * t * t ;
	int q4 = 4ull * A * B ; 
	if( q4 >= sq ) {
		puts("No") ; exit(0) ; 
	}
	puts("Yes") ; 
	return 0 ;
}


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

int main(){
	int a;
  	int cnt = 0;
	cin >> a;
 	cnt += (a / 100) % 2;
  	cnt += (a / 10) % 2;
  	cnt += a % 2;
  	cout << cnt <<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    ll s, c;
    std::cin >> s >> c;
    // s型を使って可能な限り作る
    if(s * 2 > c){
        // 作れない
        std::cout << c / 2 << std::endl;
    }else{
        ll cnt = 0;
        cnt += s;
        c -= s * 2;
        cnt += c / 4;
        std::cout << cnt << std::endl;
    }
    return 0;
}


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

int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		vector<int>v;
		for (int i = 1;i <= n;i++)v.push_back(i);

		int now = 0;
		for (int i = 0;i < n - 1;i++) {
			for (int j = 0;j < m - 1;j++) {
				now++;
				now %= n-i;
			}
			v.erase(v.begin() + now);
		}
		cout << v[0] << endl;
	}
	return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    string s;
    cin >> s;
    string t=s.substr(0,3);
    print(t);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
bool comp(pair<lpair, ll> p1, pair<lpair, ll> p2){
    if(p1.first.first == p2.first.first){
        return (p1.first.second < p2.first.second);
    }
    return p1.first.first < p2.first.first;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll P[100010], Y[100010];
    cin >> N >> M;
    rep(i,0,M){
        cin >> P[i] >> Y[i];
    }
    vector< pair<lpair, ll> > lp;
    rep(i,0,M){
        lp.push_back(make_pair(make_pair(P[i], Y[i]), i));
    }
    sort(lp.begin(), lp.end(), comp);
    vector<lpair> ans(100010);
    ll rank = 1;
    rep(i,0,M){
        ll n = lp[i].second;
        ll pre_num = lp[i].first.first;
        if(i != 0){
            if(pre_num == lp[i-1].first.first){
                rank++;
            }else{
                rank = 1;
            }
        }
        ans[n].first = pre_num;
        ans[n].second = rank;
    }
    rep(i,0,M){
        cout << setfill('0') << right << setw(6) << ans[i].first;
        cout << setfill('0') << right << setw(6) << ans[i].second << endl;
    }

    // vector< pair<string, string> > ans(100010);
    // ll rank = 0;
    // ll prev_pref = lp[0].first.first;
    // rep(i,0,M){
    //     ll n = lp[i].second;
    //     ll pre_num = lp[i].first.first;
    //     if(pre_num == prev_pref){
    //         rank++;
    //     }else{
    //         rank = 1;
    //     }
    //     prev_pref = pre_num;
    //     ll keta = to_string(pre_num).size();
    //     ll zero_num = 6 - keta;
    //     ans[n].first = string(zero_num, '0') + to_string(pre_num);
    //     ll keta2 = to_string(rank).size();
    //     ll zero_num2 = 6 - keta2;
    //     ans[n].second = string(zero_num2, '0') + to_string(rank);
    // }
    // rep(i,0,M){
    //     cout << ans[i].first << ans[i].second << endl;
    // }
}


Measured memory_bytes: 7408
import java.util.Scanner;

public class Main {
	public static void initiallize(boolean b[]) {
		for (int i = 0; i < b.length; ++i) {
			b[i] = false;
		}
	}

	public static int same(int num[]) {
		int count = 0;
		for (int i = 0; i < num.length; ++i) {
			if (num[i] != 0) {
				for (int j = i + 1; j < num.length - 1; ++j) {
					if (num[i] == num[j]) {
						int tmp = research(num, num[i]);
						if (tmp != j) {
							num[j] = 0;
							num[tmp] = 0;
							++count;
							num[i] = 0;
							break;
						}
					}
				}
			}
		}
		return count;
	}

	public static void sort(int num[]) {
		for (int i = 0; i < num.length - 1; ++i) {
			for (int j = i + 1; j < num.length; ++j) {
				if (num[j] > num[i]) {
					int tmp = num[j];
					num[j] = num[i];
					num[i] = tmp;
				}
			}
		}
	}

	public static int continuous(int num[]) {
		int count = 0;
		int tmp, tmp2;
		sort(num);
		for (int i = 0; i < num.length; ++i) {
			if (num[i] != 0) {
				for (int j = 4; j > 0; --j) {
					if (j != 2) {
						tmp = research(num, num[i] - j + 2);
						if (tmp != -1) {
							if (tmp != i) {
								if (j == 3) {
									tmp2 = research(num, num[i] - j + 4);
								} else {
									tmp2 = research(num, num[i] - j + 3);
								}
								if (tmp2 != -1) {
									if (tmp2 != i) {
										++count;
										num[tmp] = 0;
										num[tmp2] = 0;
										num[i] = 0;
										break;
									}
								}
							}
						}
					}
				}
			}
		}
		return count;
	}

	public static int research(int num[], int k) {
		if (k <= 0)
			return -1;
		for (int i = num.length - 1; i >= 0; --i) {
			if (num[i] == k) {
				return i;
			}
		}
		return -1;
	}

	public static int judge(int num[], boolean b[]) {
		int count = 0;
		int j = 0;
		int number[] = new int[9];
		for (int i = 0; i < num.length; ++i) {
			if (b[i] == true) {
				number[j] = num[i];
				++j;
			}
		}
		if (number[2] == 0)
			return -1;
		// same three number
		count += same(number);
		// continuous three number
		count += continuous(number);

		return count;

	}

	public static void main(String[] args) {
		int T, num[];
		boolean R[], G[], B[];// position of R,B,G
		int count;
		String str[];
		num = new int[9];
		str = new String[9];
		R = new boolean[9];
		B = new boolean[9];
		G = new boolean[9];
		int i, j;

		Scanner sc = new Scanner(System.in);
		T = sc.nextInt();
		for (i = 0; i < T * 2; ++i) {
			for (j = 0; j < 9; ++j) {
				if (i % 2 == 0) {
					num[j] = sc.nextInt();
				} else {
					str[j] = sc.next();
					if (str[j].equals("R")) {
						R[j] = true;
					} else if (str[j].equals("B")) {
						B[j] = true;
					} else {
						G[j] = true;
					}
				}
			}

			if (i % 2 == 1) {
				count = 0;
				// Rのときに条件を満たすものを探す
				int tmp = judge(num, R);
				if (tmp != -1) {
					count += tmp;
				}
				// B
				tmp = judge(num, B);
				if (tmp != -1) {
					count += tmp;
				}
				// G
				tmp = judge(num, G);
				if (tmp != -1) {
					count += tmp;
				}
				if (count == 3) {
					System.out.println(1);
				} else {
					System.out.println(0);
				}
				initiallize(R);
				initiallize(B);
				initiallize(G);
			}
		}
		sc.close();
	}

}



Measured memory_bytes: 28684
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		String ans = "NG";	
		for (int i=a; i<=b; i++) {
			if (i % k == 0) {
				ans = "OK";
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

vvi cost;
int n;

ll prim() {

	//O(n^2)

	vi mincost(n,INF);
	mincost[0] = 0;
	ll res = 0;
	vector<bool> used(n,false);

	while (1) {
		int v = -1;
		rep(i, n) {
			if (!used[i] && (v == -1 || mincost[i] < mincost[v]))v = i;
		}
		if (v == -1)break;
		used[v] = true;
		res += mincost[v];
		rep(i, n) {
			mincost[i] = min(mincost[i], cost[v][i]);
		}
	}
	return res;
}

int main() {
	int in;
	cin >> n;
	rep(i, n) {
		vi tmp;
		rep(j, n) {
			cin >> in;
			tmp.push_back((in!=-1?in:INF));
		}
		cost.push_back(tmp);
	}
	cout << prim() << endl;
}


Measured memory_bytes: 3160
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
char str[20][70];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
bool bfs[16][64][16][64][4][4];
int to[16][64][4];
struct wolf{
	int r1,r2,c1,c2;
	int d,s;
	wolf(int a,int b,int c,int D,int e,int f){
		r1=a;c1=b;r2=c;c2=D;d=e;s=f;
	}
	wolf(){}
};
int v[16][64][4];
int main(){
	int a,b;
	while(scanf("%d%d",&b,&a),a){
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		int sr,sc;
		int gr,gc;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			if(str[i][j]=='K'){sr=i;sc=j;}
			if(str[i][j]=='M'){gr=i;gc=j;}
		}
		queue<wolf>Q;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)
			for(int k=0;k<a;k++)for(int l=0;l<b;l++)
				for(int m=0;m<4;m++)for(int n=0;n<4;n++)
					bfs[i][j][k][l][m][n]=0;
		int sd;
		for(int i=0;i<4;i++)
			if(str[sr+dx[i]][sc+dy[i]]=='.'){
				for(int j=0;j<4;j++){
				//	if(str[sr+dx[j]][sc+dy[j]]=='.')continue;
					bfs[sr][sc][sr][sc][i][j]=1;
					Q.push(wolf(sr,sc,sr,sc,i,j));
				}
				sd=i;
			}
		bool A=false;
		while(Q.size()){
			wolf at=Q.front();
			Q.pop();
			int tr=at.r1;
			int tc=at.c1;
	//	printf("%d %d %d %d %d %d\n",at.r1,at.c1,at.r2,at.c2,at.d,at.s);
			while(str[tr+dx[at.d]][tc+dy[at.d]]!='#'){
				tr+=dx[at.d];
				tc+=dy[at.d];
			}
	//		if(at.d%2==0)tr=to[tr][tc][at.d];
		//	else tc=to[tr][tc][at.d];
			for(int i=0;i<4;i++){
				if(i%2==0)continue;
				int nr=at.r2;
				int nc=at.c2;
				while(1){
					if(str[nr][nc]=='#'){
						nr+=dx[at.s];
						nc+=dy[at.s];
						break;
					}
					if(str[nr+dx[(i+at.s)%4]][nc+dy[(i+at.s)%4]]=='#'&&!bfs[tr][tc][nr][nc][(at.d+i)%4][(at.s+i)%4]){
						bfs[tr][tc][nr][nc][(at.d+i)%4][(at.s+i)%4]=1;
						Q.push(wolf(tr,tc,nr,nc,(at.d+i)%4,(at.s+i)%4));
					}
					nr-=dx[at.s];
					nc-=dy[at.s];
				}
				if(tr==gr&&tc==gc&&nr==gr&&nc==gc&&str[gr+dx[at.s]][gc+dy[at.s]]!='#')A=true;
			}	
		}
		if(A){printf("He can accomplish his mission.\n");continue;}
		bool B=false;
		queue<pair< pair<int,int> ,int> > Q2;
		Q2.push(make_pair(make_pair(sr,sc),sd));
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)for(int k=0;k<4;k++)
			v[i][j][k]=0;
		v[sr][sc][sd]=1;
		while(Q2.size()){
			int row=Q2.front().first.first;
			int col=Q2.front().first.second;
			int dir=Q2.front().second;
		//	printf("%d %d %d\n",row,col,dir);
			Q2.pop();
			while(str[row+dx[dir]][col+dy[dir]]!='#'){
				row+=dx[dir];
				col+=dy[dir];
			}
			for(int i=0;i<4;i++){
				if(i%2==0)continue;
				if(!v[row][col][(dir+i)%4]){
					v[row][col][(dir+i)%4]=1;
					Q2.push(make_pair(make_pair(row,col),(dir+i)%4));
				}
			}
		}
		for(int i=0;i<4;i++)if(v[gr][gc][i])B=true;
		if(B)printf("He cannot return to the kitchen.\n");
		else printf("He cannot bring tea to his master.\n");
	}
}

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

int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++)
    {
        cin >> s.at(i);
    }

    int M;
    cin >> M;
    vector<string> t(M);
    for (int i = 0; i < M; i++)
    {
        cin >> t.at(i);
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        // tにのみ含まれる文字列を言って、得点を負にすることはない
        // 得点の最小値は0
        // 加点対象となるsの文字列について、sとtそれぞれに幾つ含まれるかを全探索
        int p = 0;
        string chk_string = s.at(i);
        for (int j = 0; j < N; j++)
        {
            if (chk_string == s.at(j))
            {
                p++;
            }
        }
        for (int j = 0; j < M; j++)
        {
            if (chk_string == t.at(j))
            {
                p--;
            }
        }
        ans = max(ans, p);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.TreeSet
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val B = LongArray(N)
    for ((i, a) in A.withIndex()) {
        B[a - 1] = i.toLong() + 1
    }
    val S = TreeSet<Long>()
    S.add(0L)
    S.add(N.toLong() + 1)
    var ans = 0L
    for ((i, p) in B.withIndex()) {
        ans += (S.ceiling(p)!! - p) * (p - S.floor(p)!!) * (i + 1)
        S.add(p)
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

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

using namespace std;

int main()
{
    map<int,int>m;
    map<int,int>:: iterator itr;
    int n,p,k,a,sum=0;
    cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>k;
        for(int j=0;j<k;j++){
            cin>>a;
            m[a]++;
        }
    }
    for(itr=m.begin();itr!=m.end();itr++){
        if(itr->second==n){
                sum++;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3636
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp.to!(char[]);
    int[char] memo;
    foreach (c; S) {
        if (c !in memo) memo[c] = 0;
        ++memo[c];
    }
    foreach (k, v; memo) {
        if (v != 2) {
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}

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

using ll=int64_t;

int main() {
  int A,B,C; cin >>A >>B >>C;
  string ans="NO";
  rep_eq(i,1,B) {
    if((A*i)%B==C) {
      ans="YES";
      break;
    }
  }
  cout <<ans <<endl;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF P(1e16,1e16)

struct edge{
  ll to;
  P cost;
};

struct state{
  ll v;
  P cost;
};
bool operator<(const state& a,const state& b){ return a.cost > b.cost; }

ll n,M,T;
vector<edge> g[201010];
string A,B;
map<string,vector<ll> > name;
P dist[201010];

int main(){
	cin.sync_with_stdio(false);
  cin>>M>>T>>A>>B;

  // on line
  rep(i,M){
    ll num;
    vector<string> ss;
    vector<ll> ts;
    cin>>num;
    rep(j,num){
      string s;
      cin>>s;
      ss.push_back(s);
    }
    rep(j,num-1){
      ll t;
      cin>>t;
      ts.push_back(t); 
    }
    rep(j,num-1){
      g[n+j].push_back((edge){n+j+1,P(ts[j],0)});
      g[n+j+1].push_back((edge){n+j,P(ts[j],0)});
    }
    rep(j,num)name[ss[j]].push_back(n++);
  }

  // out
  for(auto it : name){
    for(int vs : it.se){
      g[n].push_back((edge){vs,P(T,1)});
      g[vs].push_back((edge){n,P(0,0)});
    }
    name[it.fi].push_back(n++);
  }

  /*
  dbg(n);
  for(auto it : name){
    dbg(it.fi);
    for(int v : it.se){
      dbg(v);
    }
  }*/

  rep(i,201010)dist[i]=INF;
  priority_queue<state> que;
  for(int vs : name[A]){
    que.push((state){vs,P(0,0)});
  }
  while(que.size()){
    ll v = que.top().v; P cost = que.top().cost; que.pop();
    if(dist[v]!=INF)continue;
    dist[v]=cost;
    for(edge e : g[v]){
      que.push((state){e.to,P(cost.fi+e.cost.fi,cost.se+e.cost.se)});
    }
  }
  P res=INF;
  for(int vs : name[B]){
    minch(res,dist[vs]);
  }
  if(res==INF)printf("-1\n");
  else printf("%lld %lld\n", res.fi,res.se);

	return 0;
}

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

using namespace std;

int bfs(int* start, int* goal, vector<vector<char> > &S, int H, int W)
{    
    queue<int> qx;
    queue<int> qy;
    queue<int> qc;

    vector<vector<bool> > attr(H, vector<bool>(W, false));

    int x = start[0];
    int y = start[1];
    int cnt = 0;
    qx.push(x);
    qy.push(y);
    qc.push(0);
    int ans;
    while(1){
        x = qx.front();
        y = qy.front();
        int c = qc.front();
        qx.pop();
        qy.pop();
        qc.pop();

        if(attr[y][x]) continue;
        attr[y][x] = true;
        if(S[y][x] == '#') continue;

       // cout << x << " " << y << "  " << c << " "<< qc.size() << endl;
        if(goal[0] == x && goal[1] == y){
            
            ans = c;
            break;
        }

        if(x > 0){
            qx.push(x-1);
            qy.push(y);
            qc.push(c+1);
        }
        if(y > 0){
            qx.push(x);
            qy.push(y-1);
            qc.push(c+1);
        }
        if(x < W-1){
            qx.push(x+1);
            qy.push(y);
            qc.push(c+1);
        }
        if(y < H - 1){
            qx.push(x);
            qy.push(y+1);
            qc.push(c+1);
        }
    }
    //cout << ans << endl;
    return ans;
}


int main(void)
{
    int H, W;
    cin >> H >> W;
    vector<vector<char> > S(H, vector<char>(W));

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> S[i][j];
        }
    }
    int max = 0;
    int length = 0;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            for(int k = 0; k < H; k++){
                for(int l = 0; l < W; l++){
                    if(S[i][j] == '#' || S[k][l] == '#') continue;
                    int start[2];
                    int goal[2];
                    start[0] = j;
                    start[1] = i;
                    goal[0] = l;
                    goal[1] = k;
                    length = bfs(start, goal, S, H, W);
                    if(length > max){
                        max = length;
                    }
                    //cout << length << endl;
                }
            }
        }
    }
    cout << max << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if (a>b){
    cout << "a > b" << endl;
  }
  if (a<b){
    cout << "a < b" << endl;
  }
  if (a==b){
    cout << "a == b" << endl;
  }
}  


Measured memory_bytes: 3112
#include <stdio.h>
#include <set>
using namespace std;
int main(){
    int n,ans=0,temp;
    set<int> s;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&temp);
        s.insert(temp);
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%d",&temp);
        if(s.count(temp))ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 2840
def get_transpose (a_grid, h, w)
	b_grid = Array.new(w){Array.new(h)}
	
	for i in 0..h-1
			for j in 0..w-1
				b_grid[j][i] = a_grid[i][j] 
			end
	end
	
	return b_grid
end

def get_lines_to_erase(a_grid)
	lines_to_erase = Array.new
	
	a_grid.each_with_index do |line, index|
		erase = 1
		line.each do |cell|
			if cell == '#'
				erase = 0
			end
		end 
		if erase == 1
			lines_to_erase.push(index)
		end 
	end
	
	return lines_to_erase
end

h, w = gets.split.map(&:to_i) 

grid = Array.new
line = Array.new

for i in 0..h-1 
		line = gets.chars.to_a
		grid.push(line)
end
	

trans_grid = get_transpose(grid, h, w)

lines = get_lines_to_erase(grid)
columns = get_lines_to_erase(trans_grid)


grid.each_with_index do |line, index_r|
	if !lines.include?(index_r)
			string = ""
			line.each_with_index do |cell, index_c|
				if !columns.include?(index_c)
					string += cell
				end
			end
			puts string
	end
end



Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m; cin >> n >> m;
    int a[n];
    int sum = 0;

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

    sort(a, a+n);
    reverse(a, a+n);

    int req = sum/(4*m);

    if(a[m-1]*4*m>=sum) cout << "Yes\n";
    else cout << "No\n";



    

}


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

using namespace std;

void go(int cx, int cy, const vector<pair<int, int>> &xy,
        vector<int> &taken, double &res) {
    double cur = sqrt(1LL * cx * cx + 1LL * cy * cy);
    res = max(res, cur);
    for (int i = 0; i < (int)xy.size(); ++i) {
        if (!taken[i]) {
            int nx = cx + xy[i].first, ny = cy + xy[i].second;
            double ncur = sqrt(1LL * nx * nx + 1LL * ny * ny);
            if (ncur > cur) {
                taken[i] = 1;
                //go(nx, ny, xy, taken, res);
                //return;
                cx = nx;
                cy = ny;
                cur = ncur;
                res = max(res, cur);
            }
        }
    }
}

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

    auto now = chrono::system_clock::now();
    auto now_ms = chrono::time_point_cast<chrono::milliseconds>(now);
    auto epoch = now_ms.time_since_epoch();
    auto value = chrono::duration_cast<chrono::milliseconds>(epoch);
    mt19937 gen(value.count());

    int N;
    cin >> N;
    vector<pair<int, int>> xy(N);
    for (int i = 0; i < N; ++i) {
        cin >> xy[i].first >> xy[i].second;
    }
    double res = 0;
    for (int r = 0; r < 2000; ++r) {
        for (int i = 0; i < N; ++i) {
            vector<int> taken(N, 0);
            taken[i] = 1;
            go(xy[i].first, xy[i].second, xy, taken, res);
        }
        shuffle(begin(xy), end(xy), gen);
    }
    cout.precision(17);
    cout << fixed << res << "\n";

    return 0;
}

Measured memory_bytes: 256
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            
            string input = Console.ReadLine();
            int n = int.Parse(input);

            int[,] kuku = new int[9,9];
            int frag = 0;
            
            
            for(int i = 0;i < 9 ;i++)
                for(int j = 0;j < 9 ;j++)
                kuku[i,j] = (i+1) * (j+1);

            for(int i = 0;i < 9 ;i++)
                for(int j = 0;j < 9 ;j++)
            {
                if(kuku[i,j] == n)
                {
                    frag = 1;
                    break;
                }
            }

            if(frag == 1)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
                
        }
    }

Measured memory_bytes: 11092
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();

    let mut ng = 0;
    let mut ok = n;
    while ok - ng > 1 {
        let mid = (ok + ng) >> 1;
        if (1..mid + 1).sum::<usize>() >= n {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    let sum = (1..ok + 1).sum::<usize>();

    for i in 1..ok + 1 {
        if sum - n == i {
            continue;
        }
        writeln!(out, "{}", i).ok();
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    string S;
    cin >> S;
    map<int, int> cnt;
    for (char c : S) {
        cnt[c]++;
    }

    if (cnt['N'] != 0 && cnt['S'] == 0) {
        cout << "No" << endl;
    } else if (cnt['S'] != 0 && cnt['N'] == 0) {
        cout << "No" << endl;
    } else if (cnt['W'] != 0 && cnt['E'] == 0) {
        cout << "No" << endl;
    } else if (cnt['E'] != 0 && cnt['W'] == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


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

int main(){
  int X, N;
  cin >> X >> N;
  vector<int> Ps;
  int p;
  while (cin >> p) Ps.push_back(p);

  vector<int> candidate;
  candidate.push_back(X);

  int count = 1;
  int sub = 1;
  while (count < N + 1){
    candidate.push_back(X - sub);
    candidate.push_back(X + sub);
    count += 2;
    sub += 1;
  }

  for (int i = 0; i < candidate.size(); i ++){
    if (find(Ps.begin(), Ps.end(), candidate[i]) == Ps.end()){
      cout << candidate[i];
      return 0;
    }
  }
}

Measured memory_bytes: 3632
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

sum_a=sum(a)
sum_b=sum(b)
if sum_a<sum_b:
    print(-1)
    exit()

lst=[]
cnt=0
ans=0
for i in range(n):
    if b[i]<=a[i]:
        lst.append(a[i]-b[i])
    else:
        cnt+=b[i]-a[i]
        ans+=1
# print(lst)
lst.sort()
# print(cnt)
# print(ans)
for i in range(len(lst))[::-1]:
    if cnt<=0:
        break
    cnt-=lst[i]
    ans+=1
print(ans)

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

int main() {
  string s;
  cin >> s;
  string acgt = "ACGT";
  int ans = 0;
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    bool find = false;
    for (int j = 0; j < acgt.size(); j++) {
      if (s.at(i) == acgt.at(j)) {
        find = true;
        break;
      }
    }
    if (find) {
      count++;
      ans = max(ans, count);
    }
    else {
      count = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// --------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int _;
  cin >> _;
  while(_--){
    int N;
    cin >> N;
    ll ans = 0;
    vector<pair<ll,ll>> L,R;
    for(int i=0; i<N; i++){
      int k,l,r;
      cin >> k >> l >> r;
      ans += min(l,r);
      if(l >= r){
        L.emplace_back(k,l-r);
      }else{
        R.emplace_back(k,r-l);
      }
    }
    sort(L.rbegin(),L.rend());
    priority_queue<ll,vector<ll>,greater<>> que;
    for(int i=1; i<=N; i++){
      while(L.size() && L.back().first == i){
        que.emplace(L.back().second);
        L.pop_back();
      }
      while(que.size() > i){
        que.pop();
      }
    }
    while(que.size()){
      ans += que.top();
      que.pop();
    }
    sort(R.begin(),R.end());
    while(R.size() && R.back().first == N) R.pop_back();
    for(int i=N; i>=1; i--){
      while(R.size() && R.back().first == i-1){
        que.emplace(R.back().second);
        R.pop_back();
      }
      while(que.size() > N-(i-1)){
        que.pop();
      }
    }
    while(que.size()){
      ans += que.top();
      que.pop();
    }
    cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 8168
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N;
  cin >> N;

  int ans = 0;
  FOR(i, 1, N){
    int j = N-i;
    if(i == j) continue;
    ans++;
  }

  cout << ans/2 << endl;

  return 0;
}

Measured memory_bytes: 256