akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define itn int

int main(void){
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    for(int i = 0;i < n;i++)cin >> a[i] >> b[i] >> c[i];
    
    vector<vector<ll>> dp(n+1,vector<ll>(3,0));
    
    for(int i = 0;i < n;i++){
        dp[i+1][0] = max(dp[i][1],dp[i][2]) + a[i];
        dp[i+1][1] = max(dp[i][0],dp[i][2]) + b[i];
        dp[i+1][2] = max(dp[i][0],dp[i][1]) + c[i];
    }
    
    ll ans = 0;
    for(int i = 0;i < 3;i++)ans = max(ans,dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 9880
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP2_5_D
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] line = new int[n];
            for (int i = 0 ; i < n ; i++) { line[i] = i + 1; }
            var sb = new StringBuilder();
            foreach (var item in Perm(line))
            {
                sb.AppendLine(item);
            }
            Console.Write(sb.ToString());
        }

        static public IEnumerable<string> Perm(IEnumerable<int> items)
        {
            if (items.Count() == 1)
            {
                yield return items.First().ToString();
                yield break;
            }

            foreach (var item in items)
            {
                IEnumerable<int> unused = items.Where(x=> x != item);
                foreach (var rightside in Perm(unused))
                {
                    yield return item.ToString() + " " + rightside.ToString();
                }
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 46984
def calc_m_value(M, A, B, N, h):
    return min([M[h - A[i]]+B[i] if A[i] <= h else B[i] for i in range(N)])
 
H, N = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
 
M = [0] * (H+1)
for i in range(1, H+1):
    M[i] = calc_m_value(M, A, B, N, i)
 
print(M[H])

Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 
int h,w;
vector<string>v(30);
int call(int i,int j)
{
    queue<int>q;
    vector<int>vis(h*w+10,-1);
    vis[i*w+j]=0;
    int ans=0;
    q.push(i*w+j);

    while(q.size())
    {
        int x=q.front(); q.pop();
        int i=x/w,j=x%w;

       for(int a=0;a<4;a++)
       {
           int x=i+dx[a]; int y=j+dy[a];
           if(x<h&&x>=0&&y<w&&y>=0&&v[x][y]=='.'&&vis[x*w+y]==-1)
           {
               vis[x*w+y]=vis[i*w+j]+1; q.push(x*w+y);
           }
       }


    }
    return *(max_element(vis.begin(),vis.end()));
}

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


cin>>h>>w;



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

int ans=0;


for(int i=0;i<h;i++)
{
    for(int j=0;j<w;j++)
    {
        if(v[i][j]=='.')
        {
            int val=call(i,j); ans=max(ans,val);
        }
    }
}

cout<<ans<<"\n";

}

Measured memory_bytes: 256
#include<stdio.h>
#include <math.h>
#define N 10000

int Prime(int);

int main()
{
  int n, i, c, count1=0;
  int A[N];

  scanf("%d",&n);

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

  for(i = 0; i < n; i++){
    c = Prime(A[i]);
    if(c == 1) count1++;
  }
  
  printf("%d\n", count1);
  
  return 0;
}

int Prime(int x)
{
  int i, count;

  if(x == 2) return 1;
  else if(x < 2 || x % 2 == 0) return 2;
  else{
    i = 3;
    while(i <= sqrt(x)){
      if(x % i == 0) return 2;
      i = i + 2;
    }
  }
  return 1;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    ll maxL = 0;
    ll sumL = 0;

    REP(i, N){
        ll l;
        cin >> l;
        sumL += l;
        maxL = max(maxL, l);
    }
    if(maxL < sumL - maxL){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    if i+1 == p[i]:
        if i == N-1:
            l = p[i]
            k = p[i-1]
            p[i] = k
            p[i-1] = l
            ans +=1
        if i != N-1:
            l = p[i]
            k = p[i+1]
            p[i] = k
            p[i+1] = l
            ans +=1
print(ans)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

char maze[1010][1010];
int H,W;
int sx,sy;
int gx,gy;
int d[1010][1010];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<pair<int,int>> que;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            d[i][j]=INF;
        }
    }
    que.push(make_pair(sx,sy));
    d[sx][sy]=0;
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        if(p.first==gx && p.second==gy) break;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && maze[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(make_pair(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[gx][gy];
}

int main(){
    cin>>H>>W;
    int cnt=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>maze[i][j];
            if(maze[i][j]=='#') cnt++;
        }
    }
    sx=0,sy=0,gx=H-1,gy=W-1;
    int ans=bfs();
    if(ans==INF) cout<<-1<<endl;
    else cout<<H*W-cnt-ans-1<<endl;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>






int main(){


  int n;
  cin>>n;
  
  vector<vi> data(0,vi());
  
  rep(i,n){
    int a;
    cin>>a;
    rep(j,a){
      int x,y;
      cin>>x>>y;
      vi tmp={i+1,x,y};
      data.push_back(tmp);
    }
  }
  
  int answer=0;
  
  rep(i,(1<<n)){
    bitset<15> s(i);
    int flag=1;
    for (auto myvec:data){
      if (s.test(myvec.at(0)-1) and s.test(myvec.at(1)-1)!=myvec.at(2)){
        flag=0;
        break;
      }
    }
    
    if (flag==1){
      int count=0;
      rep(i,n){
        count+=int(s.test(i));
        answer=max(answer,count);
      }
    }
  }
  
  cout<<answer<<endl;
      
      
    
  
  
  
  
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);


    printf("ABC%ld\n", n);

    return 0;
}


Measured memory_bytes: 128
n = gets.chomp.to_i
# 昇順ショート
arr = gets.chomp.split(" ").map(&:to_i).sort_by{|a| a}

sum = 0
index = -1 
arr.each_with_index do |a, i|
  if sum * 2 >= a
    # 対象の生き物を吸収
    sum += a
  else
    # 対象の生き物を吸収できず
    # aがtmp_sumを吸収したと考えて再スタート
    sum += a
    index = i
  end
end

# indexが最後の1匹になると分かったら, indexよりあとの生き物も最後の1匹になれる
puts arr.length - index


Measured memory_bytes: 24676
#include <stdio.h>

int main()
{
    int x, a, b, c;
    int i, j, k;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);
    int count=0;
    for (i = 0; i <= a; i++)
    {
        for (j = 0; j <= b; j++)
        {
            for (k = 0; k <= c; k++)
            {
                if (i * 500 + j * 100 + k * 50 == x)
                    count++;
            }
        }
    }

    printf("%d",count);

    return 0;
}

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

typedef long long ll;

using namespace std;

ll gcd(ll x, ll y)
{
    ll t;
    while (y != 0) {
        t = y;
        y = x % y;
        x = t;
    }
    return x;
}

int main()
{
  ll N, X, D;
  cin >> N >> X;
  vector<ll> x(N), y(N);
  for (int j=0; j < N; ++j) {
    cin >> x[j];
    y[j] = abs(X - x[j]);
  }
  D = y[0];
  for (int j=1; j < N; ++j) {
    D = gcd(D, y[j]);
  }
  cout << D << endl;
}

Measured memory_bytes: 1792
S = input()
sl = []
for i in range(len(S)):
    sl.append(S[i])
count = 0
memo = 0
for i in range(len(S)-1):
    if sl[i] == "B" and sl[i+1] == "W":
        count += 1+memo
        sl[i+1] = "B"
    elif sl[i] == "B" and sl[i+1] == "B":
        memo += 1

print(count)


Measured memory_bytes: 59660
S = list(map(int, list(input()[::-1])))

N = len(S)
P = 2019
C = [0] * P
B = 1
t = 0
ans = 0
for i in range(N):
    C[t] += 1
    t = (t + S[i] * B) % P
    ans += C[t]
    B = B * 10 % P
print(ans)


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

int main()
{
  int N;
  cin >> N;
  
  int ans = 0;
  int r, l;
  for(int i = 0; i < N; i++) {
    cin >> r >> l;
    ans += l-r+ 1;

  }
  cout << ans << endl;
  
}
         

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  string s1,s2;
  for(int i=0;i<a;++i)s1 = s1+(char)('0'+b);
  for(int i=0;i<b;++i)s2 = s2+(char)('0'+a);
  cout<<min(s1,s2)<<endl;
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    int k;
    cin >> n >> k;
    ll x[150000];
    for(int i = 1; i <= n; i++){
        cin >> x[i];
    }
    ll ans = 999999999999;
    for(int i = 1; i + k - 1 <= n; i++){
        ll mini = x[i];
        ll maxi = x[i + k - 1];
        ll now = 0;
        if(maxi <= 0){
            now = -mini;
            ans = min(ans, now);
            continue;
        }
        if(mini >= 0){
            now = maxi;
            ans = min(ans, now);
            continue;
        }
        now = min(-mini, maxi);
        now += (maxi - mini);
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <iomanip>
#include <fstream>
#include <array>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;

int n;

int main() {
	//freopen("test.in","r",stdin);
	scanf("%d",&n);
	int ms=2e9,Ms=-2e9;
	int md=2e9,Md=-2e9;
	REP (i,n) {
		int x,y;
		scanf("%d %d",&x,&y);
		ms=min(ms,x+y);
		Ms=max(Ms,x+y);
		md=min(md,x-y);
		Md=max(Md,x-y);
	}
	printf("%d\n",max(Ms-ms, Md-md));
	return 0;
}


Measured memory_bytes: 3792
x1,y1,x2,y2 = map(int, input().split())
x=x2-x1
y=y2-y1
x3=x2-y
y3=y2+x
x4=x3-x
y4=y3-y
print(str(x3) + ' ' + str(y3) + ' ' + str(x4)  + ' ' + str(y4) )


Measured memory_bytes: 2940
#include<cstdio>
#include<iostream>
int dir[4];
char c[1000];
int main()
{
	std::cin>>c;
	for(int i=0;i<1000;++i)
	{
		if(c[i]==0)
			break;
		switch(c[i])
		{
			case 'N':
				dir[0]=1;
				break;
			case 'W':
				dir[1]=1;
				break;
			case 'S':
				dir[2]=1;
				break;
			default:
			 	dir[3]=1;
		}
		if(dir[0]&dir[1]&dir[2]&dir[3])
		{
			puts("Yes");
			return 0;
		}
	}
	if(dir[0]==dir[2]&&dir[1]==dir[3])
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
class Node{
public:
  int location;
  int p,l,r;
  Node(){}
};
class Point {
public:
  int id,x,y;
  Point(){}
  Point(int id,int x,int y):id(id),x(x),y(y){}
  bool operator < (const Point &p)const{
    return id < p.id;
  }
  void print(){
    printf("%d\n",id);
  }
};
static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}

int makeKDTree(int l,int r,int depth){
  if(!(l<r))return NIL;
  int mid=(l+r)/2;
  int t=np++;
  if(depth%2==0)sort(P+l,P+r,lessX);
  else sort(P+l,P+r,lessY);
  T[t].location=mid;
  T[t].l=makeKDTree(l,mid,depth+1);
  T[t].r=makeKDTree(mid+1,r,depth+1);
  return t;
}
void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
  int x=P[T[v].location].x;
  int y=P[T[v].location].y;

  if(sx<=x && x<=tx && sy<=y && y<=ty)ans.push_back(P[T[v].location]);

  if(depth%2==0){
    if(T[v].l!=NIL){
      if(sx<=x)find(T[v].l,sx,tx,sy,ty,depth+1,ans);
    }
    if(T[v].r!=NIL){
      if(x<=tx)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
    }
  }
  else{
    if(T[v].l!=NIL){
      if(sy<=y)find(T[v].l,sx,tx,sy,ty,depth+1,ans);
    }
    if(T[v].r!=NIL){
      if(y<=ty)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
    }
  }
}
int main(){
  int x,y;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d %d",&x,&y);
    P[i]=Point(i,x,y);
    T[i].l=T[i].r=T[i].p=NIL;
  }
  np=0;
  int root=makeKDTree(0,N,0);

  int q;
  scanf("%d",&q);
  int sx,tx,sy,ty;
  vector<Point> ans;
  for(int i=0;i<q;i++){
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    for(int j=0;j<ans.size();j++)ans[j].print();
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 16460
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

#　素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# ここから書き始める
n = int(input())
p = list(map(int, input().split()))
q = [0] * n
for i in range(n):
    if p[i] == i + 1:
        q[i] = 1

# print("q =", q)
a = []
cnt = 0
for i in range(n):
    if q[i] == 1:
        cnt += 1
    else:
        if cnt > 0:
            a.append(cnt)
            cnt = 0
if cnt > 0:
    a.append(cnt)
# print("a =", a)
ans = 0
for i in a:
    ans += -(-i // 2)
print(ans)

Measured memory_bytes: 78776
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const ll MOD = 1000000007;
 
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
 
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
    int n;
    cin >> n;
    bool flag = false;
    REP(i, 101){
        if(n - i * 4 >= 0 && (n - i * 4) % 7 == 0){
            flag = true;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int a[101];
int main()
{
	int n,s=0;
	cin>>n;
	for(int i=1; i<=n; i++){
		int x;
		cin>>x;
		a[x]=1;
	}
	for(int i=1; i<=100; i++){
		if(a[i]==1){
			s++;
		}
	}
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define ll long long
 
int main() {
  int n;
  cin >> n;
  vector<int> A(n), B(n);
  rep(i, n){
      cin >> A[i];
      B[i]=A[i];
  }
  sort(B.begin(), B.end());
  int max=B[n-1], second=B[n-2];
  rep(i, n){
      if(A[i]==max){
          cout << second << endl;
      }
      else{
          cout << max << endl;
      }
  }
}

Measured memory_bytes: 3200
#include <stdio.h>
int main(){
  int K,n,l,min;
  scanf("%d %d",&K,&n);
  int a[n*2];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n;i++){
    a[n+i]=a[i]+K;
  }
  l=K;
  for(int i=0;i<n;i++){
    min=a[n-1+i]-a[i];
    if(min<l){
      l=min;
    }
  }
  printf("%d",l);
  return 0;
}

Measured memory_bytes: 1664
from collections import deque
n,q=list(map(int,input().split()))
graph=[[] for _ in range(n+1)]

for i in range(n-1):
  a,b=list(map(int,input().split()))
  graph[a].append(b)
  graph[b].append(a)
#print('graph:',graph)

cnt=[0] *(n+1)#q回繰り返して頂点とカウンターの値を整理
for _ in range(q):
    p,x =list(map(int, input().split()))
    cnt[p] += x
#print('cnt:',cnt)

ans = [-1] * (n+1)#ans作る
ans[1] = cnt[1]#ans初期化

que = deque()
que.append(1)#deque初期値

while que:
  v = que.popleft()
  for w in graph[v]:
    if ans[w] != -1:
      continue
    ans[w]=ans[v]+cnt[w]#ans[v]は一個上のnodeの値、cnt[w]は自分のカウンターの値
    que.append(w)
#    print('que:',que)
#    print('ans:',ans)
print(*ans[1:])

Measured memory_bytes: 70960
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
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 MAX = 300;
double dp[MAX + 2][MAX + 2][MAX + 2];

#include <iomanip>
int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<int> cnt(4, 0);
    for (int i = 0; i < N; i++) cnt[a[i]]++;

    for (int c3 = 0; c3 <= N; c3++) {
        for (int c2 = 0; c2 <= N; c2++) {
            for (int c1 = 0; c1 <= N; c1++) {
                int sm = c1 + c2 + c3;
                if (sm == 0) continue;

                dp[c1][c2][c3] = 1.0 * N / sm;
                if (c1) dp[c1][c2][c3] +=     dp[c1 - 1][c2][c3] * c1 / sm;
                if (c2) dp[c1][c2][c3] += dp[c1 + 1][c2 - 1][c3] * c2 / sm;
                if (c3) dp[c1][c2][c3] += dp[c1][c2 + 1][c3 - 1] * c3 / sm;
            }
        }
    }
    cout << fixed << setprecision(10) << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
    return 0;
}

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

int main()
{
        ll N; cin >> N;
        ll ans = 0;
        for (int i = 0; i < N; ++i) {
                ll l, r; cin >> l >> r;
                ans += (r - l + 1);
        }
        cout << ans << endl;

}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int m, k;
	cin >> m >> k;
	if (k >= (1 << m))
	{
		cout << -1;
		return 0;
	}
	if (m == 1)
	{
		if (k == 0) cout << "0 0 1 1 ";
		else cout << -1;
		return 0;
	}
	
	vector<int> all(1 << m);
	iota(ALL(all), 0);
	swap(all[k], all.back());
	
	for(auto i: all) cout << i << ' ';
	all.pop_back();
	reverse(ALL(all));
	for(auto i: all) cout << i << ' ';
	cout << k << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 2304
# coding: utf-8
N, M = map(int, input().split())
d = {}
S = ["0" for _ in range(N)]
for _ in range(M):
    s, c = map(str, input().split())
    if s not in d.keys():
        d[s] = c
        S[int(s)-1] = c
    else:
        if d[s] != c:
            print(-1)
            exit()
if N == 1:
    ans = "".join(S)
    print(ans)
    exit()
elif S[0] == "0" and "1" not in d.keys():
    S[0] = "1"
ans = "".join(S)
if ans[0] == "0":
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void)
{
 int N;
 int M;
  int ans = 0;
 cin >> N >> M;
  if(N >= 2)
  {
    ans = ans + N*(N-1)/2;
  }
    if(M >= 2)
  {
    ans = ans + M*(M-1)/2;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 3764
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int n;cin>>n;
  cout << fixed << setprecision(10);
  if(n == 1){
    cout << 1.0000000000 << endl;
  }else if(n%2==0){
    cout << 0.50000000 << endl;
  }else{
    cout << (float) (n/2+1)/n << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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() {
  int n;
  cin >> n;
  vs s(n);
  REP(i, n) cin >> s[i];
  map<string, int> mp;
  REP(i, n) mp[s[i]]++;
  cout << mp.size() << endl;

  return 0;
}

Measured memory_bytes: 25076
while query = gets
  ary = query.chomp.split("").map(&:to_i)
  9.times do
    ans = Array.new
    (ary.length - 1).times do |i|
      ans.push((ary[i] + ary[i+1]) % 10)
    end
    ary = ans
  end
  puts ary.join
end

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

#define is_uruu leapyear
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,a) for(int i=0;i<(a);++i)

ll kaij(int x){
	if(x == 1) return 1;
	else return x*kaij(x-1)%1000000007;
}

int main() {
	
	int n, m;
	ll combi;
	cin >> n >> m;
	
	if(n-m < -1 || 1 < n-m){
		combi = 0;
	} 
	else if(n-m == 0){
		combi = kaij(n)*kaij(m)*2;
	}
	else{
		combi = kaij(n)*kaij(m);
	}
	
	cout << combi%1000000007 << endl;
	
     return 0;
}

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

string S;

int main(){
	cin>>S;
	int N=0;
	for(char c:S){
		N+=c-'0';
		N%=9;
	}
	if(N==0)puts("Yes");
	else puts("No");
}


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

int main() {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  if (x + r <= w && y + r <= h && x >= r && y >= r) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)

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

   ll aar[3];
   for(int i=0;i<3;++i)
   {
       cin>>aar[i];
   }
   sort(aar,aar+3);
   cout<<(aar[1]-aar[0])+(aar[2]-aar[1]);

return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>

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

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll> s(n);
  rep(i,n)cin>>s[i];
  s.erase(unique(all(s)),s.end());
  //rep(i,s.size())cout<<s[i];
  ll l=(ll)s.size();
  vector<ll>dp(l+1);
  dp[0]=1;
  vector<ll>stock(200001);
  ll mod=1e9+7;
  rep(i,l)
  {
    dp[i+1]=dp[i];
    {
      dp[i+1]+=stock[s[i]];
      dp[i+1]%=mod;

      stock[s[i]]+=dp[i];
      stock[s[i]]%=mod;
    }
  }
  cout<<dp[l]<<endl;

  return 0;

}


Measured memory_bytes: 4992
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const ll m = 998244353;

const ll s = 1e6 + 2;
ll a[s];
ll mss(vector<ll> v){
    ll temp = 0;
    ll ans = 0;
    for(int i=0;i<v.size();i++){
        temp+=v[i];
        temp = max(temp,0ll);
        ans = max(ans,temp);
    }
    return ans;
}
int main()
{
    //shuru_krte_hai_bina_kisi_bakchodi_ke();

    /* long long yaad se daal de har jagah*/
    #define int long long

    char ch;
    cin>>ch;
    if(ch>='a'){
        cout<<'a';
    }else{
        cout<<'A';
    }
    
}

Measured memory_bytes: 3620
#include <iostream>

int main (void) {
  int second;
  std::cin >> second;
  std::cout << second / 3600 << ":";
  std::cout << (second % 3600) / 60 << ":";
  std::cout << (second % 3600) % 60 << "\n";
  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll inf=1LL<<50;

struct edge{ll from,to,cost;};

edge es[2010]; //MAX_E
ll d[1010]; //S→Gのcost //MAX_V
ll N,M;

//最短経路を求める
void bellman_ford(int s){
	for(int i=0;i<N;i++) d[i]=inf;
	d[s]=0;
	for(int i=0;i<N;i++){
		bool update=false;
		for(int j=0;j<M;j++){
			edge e=es[j];
			if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
                if(i==N-1) return;
			}
		}
	}
    return;
}

//ゴールまで負の閉路に巻き込まれずに到達可能か　bellman_fordの直後に使用
bool negative[1010]; 
void bellman_ford_sec(){
	for(int i=0;i<N;i++) negative[i]=true;
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			edge e=es[j];
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				negative[e.to]=false; //到達不能
			}
		}
	}
    return;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M;
	for(int i=0;i<M;i++){
		ll x,y,z;
		cin>>x>>y>>z;
		x--; y--; z=-z;
		es[i].from=x;
		es[i].to=y;
		es[i].cost=z;
	}
	bellman_ford(0);
	bellman_ford_sec();
	if(!negative[N-1]){
		cout<<"inf"<<endl;
	}else{
		cout<<-d[N-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll c[3][3];
    for(ll i=0;i<3;i++){
        for(ll j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    ll a=c[1][0]-c[0][0];
    ll b=c[2][0]-c[0][0];
    bool bb=true;
    for(ll i=1;i<=2;i++){
        if((c[1][i]-c[0][i])!=a){
            bb=false;
        }
        if((c[2][i]-c[0][i])!=b){
            bb=false;
        }
    }
    if(bb){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	int n;
	int cnt[26];
	vector<char> vote;
	while (cin >> n && n) {
		vote.resize(n);
		for (auto&& i : vote) {
			cin >> i;
		}
		for (int i = 0; i < 26; i++) {
			cnt[i] = 0;
		}
		bool br = true;
		char firstP = 'A', secondP = 'B';
		for (int i = 1; i <= n; i++) {
			cnt[vote[i - 1] - 'A']++;
			if (firstP != vote[i - 1] && cnt[firstP - 'A'] < cnt[vote[i - 1] - 'A']) {
				secondP = firstP;
				firstP = vote[i - 1];
			} else if (firstP != vote[i - 1] && cnt[secondP - 'A'] < cnt[vote[i - 1] - 'A']) {
				secondP = vote[i - 1];
			}
			if (cnt[firstP - 'A'] > cnt[secondP - 'A'] + n - i) {
				cout << firstP << " " << i << "\n";
				br = false;
				break;
			}
		}
		if (br) {
			cout << "TIE\n";
		}
	}
}


Measured memory_bytes: 3120
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int INF = 1000000000;
const ll BIG_NUM = 1000000000000000000;


int main() {
	int n, k;
	cin >> n >> k;
	int maxK = (n - 1) * (n - 2) / 2;
	if (maxK < k) {
	
		cout << -1 << endl;
		return 0;
	}


	int m = n - 1 + (maxK - k);

	cout << m << endl;

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

			cout << i << " " << j << endl;
			cnt++;
			if (cnt >= m) {
				return 0;
			}
		}
	}

	

}




Measured memory_bytes: 256
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
        cout << name << " : " << arg1 << endl;  
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
template <class X>
void printarr(X arr[], int n) 
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << ' ';
    cout << endl;
}
 
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
int modulo = 1e9 + 7;
 
int fpow(int a, int n) 
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = ans*a;
        a = a*a;
        n = n >> 1;
    }
    return ans;
}
 
signed main() 
{
    fast_io();
    int a1,a2,a3; cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22)
        cout << "bust";
    else
        cout << "win";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a, b; cin >> a >> b;
	string s; cin >> s;
	rep(i,s.size()){
		if (i == a){
			if(s[i] != '-'){
				cout << "No" << endl;
				return 0;
			}
			}else {
				if (s[i]-'0' > 9 || s[i]-'0' < 0){
					cout << "No" << endl;
					return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

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

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

int main() {
  string s, t;
  cin >> s >> t;
  bool flag = true;
  vector<char> a;
  // アルファベット26通り試して、1意になるかどうか調べる
  rep(i, 26){
    a.clear();
    char c = 'a' + i;
    // s側から確認
    rep(i, s.size()){
      if (s[i] == c){
        a.push_back(t[i]);
      }
    }
    // 違う文字があるかどうかチェックする
    if (a.size() > 1) {
      rep(i, a.size()-1){
        if (a[i] != a[i+1]) {
          flag = false;
          break;
        }
      }
    }
    a.clear();
    // t側から確認
    rep(i, t.size()){
      if (t[i] == c){
        a.push_back(s[i]);
      }
    }
    // 違う文字があるかどうかチェックする
    if (a.size() > 1) {
      rep(i, a.size()-1){
        if (a[i] != a[i+1]) {
          flag = false;
          break;
        }
      }
    }
    if(!flag) break;
  }

  if (flag){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 904
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,k; cin >> n >> k;
    map<long long,long long> mp;
    for(long long i=0;i<n;++i){
        long long a,b; cin >> a >> b;
        mp[a] += b;
    }
    long long sum=0;
    for(auto itr : mp){
        sum += itr.second;
        if(sum >= k){
            cout << itr.first << endl;
            break;
        }
    }
    return 0;
    
}

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

int cost[21][21],mindist[21],cur,cur_spot;
bool used[21];

int cost_sum(int n,int x1,int x2){
  
  for(int _=1 ; _ <= 20 ; _++){
    mindist[_]=1e9;
    used[_]=false;
  }
  
  mindist[x1]=0;
  
  for(int _=0 ; _ < n ; _++){
    cur=INT_MAX;
    for(int i=1 ; i <= n ; i++){
      if( cur >= mindist[i] && used[i] == false){
	cur=mindist[i];
	cur_spot=i;
      }
    }
    used[cur_spot]=true;
    
    for(int i=1 ; i <= n ; i++){
      if(cost[cur_spot][i] != -1){
	if(mindist[i] > mindist[cur_spot] + cost[cur_spot][i]){
	  mindist[i]=mindist[cur_spot] + cost[cur_spot][i];
	}
      }
    }
    
  }
  
  return mindist[x2];
}    
int main(){
  
  int n,m,a,b,c,d,x1,x2,y1,y2;
  int cost_go,cost_back;
  char dam;
  
  cin >>n;
  cin >>m;
  
  for(int _=0 ; _ < 20 ; _++){
    for(int __=0 ; __<20 ; __++){
      cost[_][__]=-1;
    }
  }
  
  for(int _=0 ; _ < m ; _++){
    cin >>a>>dam>>b>>dam>>c>>dam>>d;
    
    cost[a][b]=c;
    cost[b][a]=d;
  }
  
  cin >>x1>>dam>>x2>>dam>>y1>>dam>>y2;
  
  cost_go=cost_sum(n,x1,x2);
  cost_back=cost_sum(n,x2,x1);
  
  cout <<y1-y2-cost_go-cost_back<<endl;
  
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <set>
#include <string>

using namespace std;


void solve()
{
	int n, k;
	while (cin >> n >> k, n || k)
	{
		vector<string> card(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> card[i];
		}
		set<string> S;
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				if (k == 2)
				{
					if (i != j)
					{
						S.insert(card[i] + card[j]);
						S.insert(card[j] + card[i]);
					}
				}
				else
				{
					if (k == 3)
					{
						for (int a = 0; a < n; ++a)
						{
							if (i != j && j != a && i != a)
							{
								S.insert(card[i] + card[j] + card[a]);
								S.insert(card[i] + card[a] + card[j]);
								S.insert(card[j] + card[i] + card[a]);
								S.insert(card[j] + card[a] + card[i]);
								S.insert(card[a] + card[i] + card[j]);
								S.insert(card[a] + card[j] + card[i]);
							}
						}
					}
					else
					{
						for (int a = 0; a < n; ++a)
						{
							for (int b = 0; b < n; ++b)
							{
								if (i != j && i != a && i != b &&
									j != a && j != b &&
									a != b)
								{
									S.insert(card[i] + card[j] + card[a] + card[b]);
									S.insert(card[i] + card[j] + card[b] + card[a]);
									S.insert(card[i] + card[a] + card[b] + card[j]);
									S.insert(card[i] + card[a] + card[j] + card[b]);
									S.insert(card[i] + card[b] + card[a] + card[j]);
									S.insert(card[i] + card[b] + card[j] + card[a]);
									
									S.insert(card[j] + card[i] + card[a] + card[b]);
									S.insert(card[j] + card[i] + card[b] + card[a]);
									S.insert(card[j] + card[a] + card[b] + card[i]);
									S.insert(card[j] + card[a] + card[i] + card[b]);
									S.insert(card[j] + card[b] + card[a] + card[i]);
									S.insert(card[j] + card[b] + card[i] + card[a]);

									S.insert(card[a] + card[i] + card[b] + card[j]);									
									S.insert(card[a] + card[i] + card[j] + card[b]);
									S.insert(card[a] + card[j] + card[b] + card[i]);
									S.insert(card[a] + card[j] + card[i] + card[b]);
									S.insert(card[a] + card[b] + card[i] + card[j]);
									S.insert(card[a] + card[b] + card[j] + card[i]);

									S.insert(card[b] + card[i] + card[a] + card[j]);
									S.insert(card[b] + card[i] + card[j] + card[a]);
									S.insert(card[b] + card[a] + card[i] + card[j]);
									S.insert(card[b] + card[a] + card[j] + card[i]);
									S.insert(card[b] + card[j] + card[a] + card[i]);
									S.insert(card[b] + card[j] + card[i] + card[a]);
								}
							}
						}
					}
				}
			}
		}
		cout << S.size() << endl;
	}
}

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

Measured memory_bytes: 1468
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main(){
        ll h,w,m,i,ht,wt,hmax=0,wmax=0,hcnt=0,wcnt=0,bcnt=0;
        cin >> h >> w >> m;
        vector<ll> bh(h);
        vector<ll> bw(w);
        vector<pair<ll,ll>> vp(m);
        for(i=0;i<m;++i){
                cin >> ht >> wt;
                --ht; --wt;
                ++bh.at(ht);
                ++bw.at(wt);
                hmax = max(hmax,bh.at(ht));
                wmax = max(wmax,bw.at(wt));
                vp.at(i) = make_pair(ht,wt);
        }
        for(i=0;i<h;++i) if(bh.at(i)==hmax) ++hcnt;
        for(i=0;i<w;++i) if(bw.at(i)==wmax) ++wcnt;
        for(i=0;i<m;++i){
                ht = vp.at(i).first;
                wt = vp.at(i).second;
                if(bh.at(ht)==hmax&&bw.at(wt)==wmax) ++bcnt;
        }
        if(hcnt*wcnt>bcnt) cout << hmax+wmax << endl;
        else cout << hmax+wmax-1 << endl;
        return 0;
}

Measured memory_bytes: 12704
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    val n, m, l = scanner.nextInt
    val a = Array.fill(n)(new Array[Long](m))
    val b = Array.fill(l)(new Array[Long](m))

    for(i <- 0 until n) {
      for(j <- 0 until m) {
        a(i)(j) = scanner.nextInt
      }
    }
    for(i <- 0 until m) {
      for(j <- 0 until l) {
        b(j)(i) = scanner.nextLong
      }
    }

    for(i <- 0 until n) {
      for(j <- 0 until l) {
        print((a(i) zip b(j)).map(t => t._1 * t._2).sum)
        if(j < l - 1) print(" ") else println()
      }
    }
  }
}



Measured memory_bytes: 225768
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int b, f, r, v;;
    int house[5][4][11];
    int i, n;
 
    for (b = 1; b <= 4; b++) {
        for (f = 1; f <= 3; f++) {
            for (r = 1; r <= 10; r++) house[b][f][r] = 0;
        }
    }
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d%d%d%d", &b, &f, &r, &v);
        house[b][f][r] += v;
    }
 
    for (b = 1; b <= 4; b++) {
        for (f = 1; f <= 3; f++) {
            for (r = 1; r <= 10; r++) printf(" %d", house[b][f][r]);
            putchar('\n');
        }
        if (b < 4) puts("####################");
    }
    return 0;
}


Measured memory_bytes: 2052
#include<stdio.h>
char map[10][10];
void bom(int x,int y){
	if(x<0||x>7||y<0||y>7||map[y][x]=='0')return;
	map[y][x]='0';
	bom(x,y+1);bom(x,y+2);bom(x,y+3);
	bom(x,y-1);bom(x,y-2);bom(x,y-3);
	bom(x+1,y);bom(x+2,y);bom(x+3,y);
	bom(x-1,y);bom(x-2,y);bom(x-3,y);
}

int main(){
	int i,k;
	int x,y;
	int d;
	scanf("%d",&d);
	for(k=1;k<=d;k++){
		for(i=0;i<8;i++){
			scanf("%s",map[i]);
		}

		scanf("%d %d",&x,&y);
		bom(x-1,y-1);
		printf("Data %d:\n",k);
		for(i=0;i<8;i++)
			printf("%s\n",map[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))
#define INF INT_MAX

using namespace std;
using LL=long long;

int main(){
    int n,m,i,o,res;
    cin>>n>>m;
    res=m;
    LP(x,n){
        cin>>i>>o;
        m+=i;
        m-=o;
        if(m<0){
            cout<<0<<endl;
            return 0;
        }
        res=max(res,m);
    }
    cout<<res<<endl;
    return 0;
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int> > ab(n + 1, vector<int>());
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        ab[a].push_back(b);
    }

    each(i, ab[1]) {
        each(j, ab[*i]) {
            if (*j == n) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 8576
#include<iostream>
#define REP(i,s,n) for(int i=s ; i < n ; i++) 
#define rep(i,n) REP(i,0,n)
using namespace std;
int main(){

  int N,M,x,y,l;
  int field[21][21];
  char d;

  while(1){
    
    cin >>N;
    if(N == 0)break;

    rep(i,21){
      rep(j,21){
      field[i][j]=0;
      }
    }
    
    rep(i,N){
      cin >>x>>y;
      field[y][x]=1;
    } 

    cin >>M;
    
    int cnt=0;
    x=10,y=10;

    rep(i,M){
      cin >>d>>l;
      rep(j,l){
	
	if(field[y][x] == 1){
	  cnt++;
	  field[y][x]=0;
	}
     
	if(d == 'N'){
	  y++;
	}else if(d == 'E'){
	  x++;
	}else if(d == 'S'){
	  y--;
	}else{
	  x--;
	}
	
      }

      if(field[y][x] == 1){
	cnt++;
	field[y][x]=0;
      }
      
    }

    if(cnt == N){
      cout <<"Yes"<<endl;
    }else{
      cout <<"No"<<endl;
    }
  
  }
  return 0;
}
  

Measured memory_bytes: 1152