akhauriyash/Code-Regression huggingface dataset:
import sys;sys.setrecursionlimit(int(1e7))
from sys import stdin
from collections import deque

input = stdin.readline
N = int(input())
tree = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int,input().split())
    tree[a].append((b,c))
    tree[b].append((a,c))

Qn,K = map(int,input().split())
XY = [tuple(map(int,input().split())) for _ in range(Qn)]

depth = [None]*(N+1)
def DFS(v,p,d):
    depth[v] = d
    for e in tree[v]:
        if e[0] != p:
            DFS(e[0], v, d + e[1])
DFS(K,0,0)

for i in range(Qn):
    print(depth[XY[i][0]] + depth[XY[i][1]])

Measured memory_bytes: 145536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();//合計テストケース数
		int ｍ = sc.nextInt();//正解テストケース数
		
		if(n == ｍ) System.out.println("Yes");
		else System.out.println("No");
		
		
		sc.close();
	}

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define MX 101

using namespace std;

char mp[MX][MX];
short sx[MX][MX], sy[MX][MX];
short f[MX][MX][MX][MX];
short n, m, ex, ey;

void chmax(short& a, const short& b) {if(b > a) a = b;}

int main()
{
	scanf("%hd%hd", &n, &m);
	for(short i=1; i<=n; i++)
	{
		scanf("%s", mp[i]+1);
		for(short j=1; j<=m; j++)
		{
			if(mp[i][j] == 'o')
				sx[i][j] = sx[i-1][j] + 1,
				sy[i][j] = sy[i][j-1] + 1;
			else
				sx[i][j] = sx[i-1][j],
				sy[i][j] = sy[i][j-1];
			if(mp[i][j] == 'E') ex = i, ey = j;
		}
	}
	short ans = 0;
	f[ex][ex][ey][ey] = 0;
	for(short l=ey; l>=1; l--)
		for(short r=ey; r<=m; r++)
			for(short u=ex; u>=1; u--)
				for(short d=ex; d<=n; d++)
				{
					short dd = min(d, (short)(n-(ex-u)));
					short du = max(u, (short)(d-ex+1));
					short dl = max(l, (short)(r-ey+1));
					short dr = min(r, (short)(m-(ey-l)));
					if(dd>=du && l-1>=(r-ey+1))		chmax(f[l-1][r][u][d], f[l][r][u][d] + sx[dd][l-1] - sx[du-1][l-1]);
					if(dd>=du && r+1<=(m-(ey-l)))	chmax(f[l][r+1][u][d], f[l][r][u][d] + sx[dd][r+1] - sx[du-1][r+1]);
					if(dr>=dl && u-1>=(d-ex+1))		chmax(f[l][r][u-1][d], f[l][r][u][d] + sy[u-1][dr] - sy[u-1][dl-1]);
					if(dr>=dl && d+1<=(n-(ex-u)))	chmax(f[l][r][u][d+1], f[l][r][u][d] + sy[d+1][dr] - sy[d+1][dl-1]);
					chmax(ans, f[l][r][u][d]);
				}
	printf("%hd\n", ans);
	return 0;
}

Measured memory_bytes: 201088
def split_each(arr, number, min)
  if number == 1
    return [[arr]]
  end
  size = arr.length
  hoge = (0..(size-1)).to_a

  max = size - (number - 1) * min
  return Enumerator.new do |r|
    (min..max).each do |n|
      hoge.combination(n) do |combi|
        a = combi.map{|i|arr[i]}
        rest = (hoge-combi).map{|i|arr[i]}

        split_each(rest, number-1, min).each{|i|r << [a, *i]}
      end
    end
  end
end

def calcMP(arr, target)
  return 1000 unless arr[0]
  length = 0
  mp = -10
  arr.each do |i|
    length += i
    mp += 10
  end
  mp += (length - target).abs
  return mp
end

n,a,b,c = gets.split.map &:to_i

l = []
n.times do |i|
  l[i] = gets.to_i
end

min = 1000000
split_each(l, 4, 0).each do |splits|
  current = calcMP(splits[0], a) + calcMP(splits[1], b) + calcMP(splits[2], c)
  min = [min, current].min
end

puts min

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

int main() {	
	string s; cin>>s;
	int n=s.length();
	int f=(n-1)/2;
	int ss=(n+3)/2;
	ss--;
	string a="";
	string b="";
	for(int i=0;i<f;i++)
	{
		a+=s[i];
	}
	for(int i=ss;i<n;i++)
	{
		b+=s[i];
	}
	string y=a;string z=b;
	reverse(a.begin(),a.end());reverse(b.begin(),b.end());
	string p=s; reverse(s.begin(),s.end());
	if(a==y && z==b && s==p)
	{
		cout<<"Yes";
	}else{cout<<"No";}
}

Measured memory_bytes: 256
N = int(input())
line = list(input())

# print(line)
bottom_w = N
top = 0
count = 0
while(bottom_w > top):
    for i in reversed(range(bottom_w)):
        if(line[i]=='R'):
            bottom_w = i
            break

    if(line[-1]=='W' and bottom_w == N):
        print(0)
        exit()
    if(bottom_w <= top):
        break
    for i in range(top,N):
        if(i == N-1):
            print(count)
            exit()
        if(line[i]=='W' and bottom_w > i):
            # print("line",i,line[i])
            # print("swap",i,bottom_w)
            count += 1
            line[bottom_w] = 'W'
            top = i+1
            break
print(count)


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

int main(){

  int a,b;
  cin>>a>>b;
  int x=log10(b)+1;
  //cout<<x;
  int p=a*pow(10,x)+b;
  //cout<<p;
  int t=sqrt(p);
  if(t*t==p)
    cout<<"Yes";
  else
    cout<<"No";

  return 0;
}

Measured memory_bytes: 512
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    cand = set(range(N))
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        if H[A] <= H[B] and A in cand:
            cand.remove(A)
        if H[B] <= H[A] and B in cand:
            cand.remove(B)
    print(len(cand))


if __name__ == "__main__":
    main()


Measured memory_bytes: 91464
from collections import deque

def resolve():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = []
    for _ in range(H):
        S.append([s for s in input()])

    # 座標と配列番号を揃える
    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1
    # 上下左右の移動で楽する工夫
    walk = [(-1,0), (0,-1), (1,0), (0,1)]
    warp = [(-2,-2), (-2,-1), (-2,0), (-2,1), (-2,2),
        (-1,-2), (-1,-1), (-1,1), (-1,2),
        (0,-2), (0,2),
        (1,-2), (1,-1), (1,1), (1,2),
        (2,-2), (2,-1), (2,0), (2,1), (2,2)]

    # コスト格納用の盤面
    INF = 10**9
    dist = [[INF] * W for _ in range(H)]
    dist[Ch][Cw] = -1

    # dequeの定義、(h座標, w座標, コスト)のタプルを格納する
    deq = deque()
    deq.append((Ch, Cw, 0))

    while len(deq) > 0:
        (h, w, d) = deq.popleft()
        # 探索済みマスかどうか
        if dist[h][w] < d and dist[h][w] != -1:
            continue
        # コスト0の移動を検証
        for (dh, dw) in walk:
            nh = h + dh
            nw = w + dw
            # 盤面外かどうか
            if (nh < 0) or (nw < 0) or (nh >= H) or (nw >= W):
                continue
            # 道があるかどうか
            if S[nh][nw] == '#':
                continue
            # 探索済みかどうか
            if dist[nh][nw] <= d:
                continue
            dist[nh][nw] = d
            deq.appendleft((nh, nw, d))
        # コスト1の移動を検証
        for (dh, dw) in warp:
            nh = h + dh
            nw = w + dw
            # 盤面外かどうか
            if (nh < 0) or (nw < 0) or (nh >= H) or (nw >= W):
                continue
            # 道があるかどうか
            if S[nh][nw] == '#':
                continue
            # 探索済みかどうか
            if dist[nh][nw] <= d+1:
                continue
            dist[nh][nw] = d+1
            deq.append((nh, nw, d+1))
    ans = dist[Dh][Dw]
    if ans == INF:
        ans = -1
    print(ans)

if __name__ == "__main__":
    resolve()

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

int main()
{
    int n; cin >> n;
    vector<int> p(n), q(n);

    rep(i, n) cin >> p.at(i);
    rep(i, n) cin >> q.at(i);

    // reverse(p.begin(), p.end());
    // reverse(q.begin(), q.end());

    vector<int> np(n), nq(n);

    rep(i, n) np.at(i) = i+1;
    int cnt = 1, a = 0, b = 0;

    // cout << "p = ";
    // rep(i, n) cout << p.at(i);
    // cout << endl;
    // cout << "q = ";
    // rep(i, n) cout << q.at(i);
    // cout << endl;

    do {
        // cout << "np(" << cnt << ") = ";
        // rep(i, n) cout << np.at(i);
        // cout << endl;

        rep(i, n) {
            if (p.at(i) == np.at(i)) {

            } else {
                break;
            }
            if (i == n-1) {
                a = cnt;
                break;
            }
        }
        rep(i, n) {
            if (q.at(i) == np.at(i)) {

            } else {
                break;
            }
            if (i == n-1) {
                b = cnt;
                break;
            }
        }
        cnt++;
    } while (next_permutation(np.begin(), np.end()));

    cout << abs(a-b) << endl;
    // cout << cnt << endl;
}

Measured memory_bytes: 256
"use strict";

const main = (input) => {
    const spi = input.split('\n');
    const [x, n] = spi[0].split(' ').map(e => parseInt(e));
    const p = spi[1].split(' ').map(e => parseInt(e));

    let array = [];
    for (let i = -201; i <= 201; i++) {
        if (p.indexOf(i) === -1) array.push(i);
    }
    
    let minv = 210, ans = 0;
    for (let i = 0; i < array.length; i++) {
        const abx = Math.abs(x - array[i]);
        if (minv > abx) {
            minv = abx;
            ans = array[i];
        }
    }

    console.log(ans);
};

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


Measured memory_bytes: 30560
class Node:
    def __init__(self, nid, k, c):
        self.nid = nid
        self.parent = -1
        self.depth = 0
        if k == 0:
            self.type = "leaf"
        else:
            self.type = "internal node"
        self.c = c
    
    def dump(self):
        print("node {}: parent = {}, depth = {}, {}, {}".format(self.nid,self.parent,self.depth,self.type,self.c))
from collections import deque
n = int(input())
T = [[int(j) for j in i] for i in [input().split() for i in range(n)]]
D = {}
for i in T:
    D[i[0]] = Node(i[0],i[1],i[2:])
    
for i in range(n):
    for j in D[i].c:
        D[j].parent = D[i].nid
rootid = 0
while(True):
    if D[rootid].parent == -1:
        break
    else:
        rootid = D[rootid].parent
D[rootid].type = "root"
d = deque()
d.append(D[rootid])
while(len(d)>0):
    tmp = d.pop()
    if tmp.parent == -1:
        pass
    else:
        tmp.depth = D[tmp.parent].depth + 1
    for i in tmp.c:
        d.appendleft(D[i])
for i in range(n):
    D[i].dump()


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

int main() {
  int n,cnt=0;
  cin >> n;

  vector<int>table(n);
  for (int i = 0; i < n; i++) {
    cin >> table.at(i);
  }
  for (int i = 0; i < n; i++) {
    if ((i+1)%2==1) {
      if (table.at(i)%2==1) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3624
n, x = map(int, input().split())
a = list(map(int, input().split()))

nc = 0

for i in range(n):
    if a[i] > x:
        nc += a[i] - x
        a[i] = x

for i in range(1, n):
    if a[i - 1] + a[i] > x:
        nc += a[i - 1] + a[i] - x
        a[i] = x - a[i - 1]

print(nc)

Measured memory_bytes: 14060
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int Inf = 1e9;
const double EPS = 1e-9;



int main()
{
  int x1, x2, x3, x4, y1, y2, y3, y4 ;
  cin >> x1 >> y1 >> x2 >> y2 ;
  int X2, X3, X4, Y2, Y3, Y4 ;
  X2 = x2 - x1 ;
  Y2 = y2 - y1 ;
  
  X4 = -Y2 ;
  Y4 = X2 ;
  
  X3 = X2 + X4 ;
  Y3 = Y2 + Y4 ;
  
  x3 = X3 + x1 ;
  x4 = X4 + x1 ;
  
  y3 = Y3 + y1 ;
  y4 = Y4 + y1 ;
  
  cout <<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl ;

  return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 100005

typedef struct {
	char name[100];
    int t;
}Task;

Task Q[N];
int head,tail;
void enqueue(Task x){
    Q[tail]=x;
    tail=(tail+1)%N;
}
Task dequeue(){
    Task x=Q[head];
    head=(head+1)%N;
    return x;
}
int min(int a,int b){
	return a<b?a:b;
}
int main(void){
    int n,q,i,c,elaps=0;
    scanf("%d %d",&n,&q);
    for(i=1;i<=n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head=1;
    tail=n+1;
    while(head!=tail){ 
        Task u=dequeue();
        c=min(q,u.t);
        u.t-=c;
        elaps+=c;
        if(u.t>0)
            enqueue(u);
        else
            printf("%s %d\n",u.name,elaps);
    }
    return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int a, b, t;
    cin >> a >> b >> t;

    cout << b * (t / a) << endl;

    return 0;
}

Measured memory_bytes: 384
# [[0*10], [0*10], [0*10]]を4つ持つtableを用意
table = [[[0]*10 for i in range(3)] for k in range(4)]

n = int(input())

# tableに情報を入力
for i in range(n):
    tower, floor, number, people = map(int, input().split())
    table[tower-1][floor-1][number-1] += people
    
x = 0
for i in range(4):
    
    # 最初と最後は#*20なしに対応
    if x != 0:
        print('#'*20)
    x += 1
    
    for j in range(3):
        for k in range(10):
            # 情報出力、%dと%の組み合わせで変数として扱い出力
            print(' %d'%(table[i][j][k]), end="")
        print()


Measured memory_bytes: 5624
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll N;
    cin>>N;
    vector<ll> c(N),s(N),f(N);
    rep(i,0,N-1){
        cin>>c[i]>>s[i]>>f[i];
    }

    rep(i,0,N){
        ll pos = i, t = 0;
        while(pos < N-1){
            ll p;
            if (t < s[pos]){
                p = 0;
            }else{
                p = (t-s[pos] + f[pos]-1)/ f[pos];
            }
            ll beg = s[pos] + f[pos] * p;
            t = beg + c[pos];
            // printf("station=%d begin_time=%d arrival_time=%d\n", pos, beg, t);
            pos ++;
        }
        cout<<t<<endl;
    }
    return 0;
}


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

int main () {
    int n;
    cin >> n;
    vector<long long> b(100000, 0);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        b[a]++;
    }

    long long ans = 0;
    for (int i = 1; i < 99999; i++) {
        ans = max(ans, b[i - 1] + b[i] + b[i + 1]);
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
    int a, b, c;
    int x;
    cin >> a >> b >> c;
    x = (a == 7) + (a == 5)*10  + (b == 7) + (b == 5) * 10  + (c == 7) + (c == 5)*10;
    if (x == 21) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import heapq
K=input()

#隣接リストa
a=[[] for i in range(K)]
for i in range(K):
	a[i].append(((i+1)%K,1))
	a[i].append((i*10%K,0))

#print "# a"
#print a

#開始位置
Start=1

#初期化
d=[-1 for i in range(K)]
d[Start]=0


#優先度付きキューに[距離,頂点の番号]を格納する
#スタート地点の頂点1には距離0を入れる
q=[]
heapq.heappush(q, [0,Start])
#print "# q"
#print q

while len(q)!=0:
	#距離が最小の頂点を取り出し
	l,u=heapq.heappop(q)
	for val in a[u]:
		v=val[0]
		l_u_v=val[1]
		#print v, l_u_v
		if (d[v]>d[u]+l_u_v) or d[v]==-1:
			d[v]=d[u]+l_u_v
			heapq.heappush(q, [d[v],v])
	#print "# q,d"
	#print q
	#print "# d"
	#print d	

print d[0]+1




Measured memory_bytes: 41748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  ll left = 0, right = 0;
  rep(i, m) {
    ll a;
    cin >> a;
    if (a < x) left++;
    if (x < a) right++;
  }
  cout << min(left, right) << endl;
}

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

namespace ALDS1_2_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var v = Console.ReadLine();
            var values = v.Split(' ').Select(s => int.Parse(s)).ToList();
            SelectionSort(values, values.Count());
        }
        public static void SelectionSort(List<int>targetArray,int arrayLength)
        {
            int sw = 0;
            for(int i = 0; i < arrayLength; i++)
            {
                int minj = i;
                for(int j = i + 1; j < arrayLength; j++)
                {
                    if(targetArray[minj] > targetArray[j])
                    {
                        minj = j;
                    }
                }
                if(minj != i)
                {
                    int temp = targetArray[i];
                    targetArray[i] = targetArray[minj];
                    targetArray[minj] = temp;
                    sw++;
                }
            }
            OutputList(targetArray);
            Console.WriteLine(sw);
        }
        public static void OutputList(List<int> targetArray)
        {
            for (int i = 0; i < targetArray.Count; i++)
            {
                if (i == targetArray.Count - 1)
                {
                    Console.WriteLine(targetArray[i]);
                }
                else
                {
                    Console.Write(targetArray[i]);
                    Console.Write(' ');
                }
            }
            return;
        }
    }
}



Measured memory_bytes: 18240
#include <cstdio>
#include <algorithm>
using namespace std;

int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int H, W;
char a[100][101];

void dfs(char c, int x, int y) {
	a[y][x] = ' ';
	for (int i = 0; i < 4; i++) {
		int _x = x + dx[i], _y = y + dy[i];
		if (_x >= 0 && _x < W && _y >= 0 && _y < H && a[_y][_x] == c) {
			dfs(c, _x, _y);
		}
	}
}

int main() {
	for (;;) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0)
			break;
		for (int y = 0; y < H; y++)
			scanf("%s", a[y]);
		int ans = 0;
		for (int y = 0; y < H; y++)
			for (int x = 0; x < W; x++)
				if (a[y][x] != ' ') {
					ans++;
					dfs(a[y][x], x, y);
				}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1508
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define RREP(i,a,b) for(ll i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> p;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    ll a;
    map<ll, ll> m;
    rep(i,n){
        cin >> a;
        if(m.find(a)==m.end()) m[a] = 1;
        else m[a]++;
    }
    if(m.find(0) != m.end()){
        if(m.size() == 1) cout << "Yes" << endl;
        else{
            auto it = m.end();
            it--;
            if(m.size() == 2 && it->second == m.begin()->second * 2){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }else{
        if(m.size() != 3) cout << "No" << endl;
        else{
            ll data[3];
            ll p=0;
            ll tmp = m.begin()->second;
            for(auto it = m.begin(); it != m.end(); it++){
                if(it->second != tmp){
                    cout << "No" << endl;
                    return 0;
                }
                data[p] = it->first;
                //cout << data[p] << endl;
                p++;
            }
            if(data[2] != (data[1] ^ data[0])){
                //cout << (data[1] ^ data[2]) << endl;
                cout << "No" << endl;
            }else{
                cout << "Yes" << endl;
            }
        }
    }
}

Measured memory_bytes: 5120
#include<iostream>
#include<set>
using namespace std;
int main(){
  set<int> cmp({1,4,7,9});
  int n;
  for(int i=0;i<4;i++){
    cin>>n;
    if(cmp.find(n)==cmp.end()){
      cout<<"NO"<<endl;
      return 0;
    }
    cmp.erase(n);
  }
  cout<<"YES"<<endl;
  return 0;
}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int A, B;
    cin >> A >> B;

    if (B % A == 0) {
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<ll,ll>;
//const int 1001001001;
const int NMAX=8;
const ll MOD=1000000007;
const int dbase=80*160;

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
    //末尾の要素(i&-i)をたす→一つ上の階層なので、要素の更新の時に使える
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
     //末尾の要素(i&-i)を引く→一つ上の一つ左の階層なので、要素の総和をとる時に使える
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
	T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

mint calc(ll a, ll b, ll c, ll d){
	mint ans=0;

	mint a1=mint(2).pow(a);
	mint b1=mint(2).pow(b);
	mint c1=mint(2).pow(c);
	mint d1=mint(2).pow(d);

	ans+=(a1-1)*b1*(c1-1)*d1;
	ans+=a1*(b1-1)*c1*(d1-1);
	ans-=(a1-1)*(b1-1)*(c1-1)*(d1-1);
	ans+=a1*b1*c1*d1;

	return ans;
}
vector<bool> used(100005);
vector<ll> ans;
vector<P> g[100005];
vector<ll> x(100005);

ll dfs(ll v){
	used[v]=true;
	ll res=x[v];
	for(auto u:g[v]){
		if (used[u.first]) continue;
		if (dfs(u.first)){
			ans.emplace_back(u.second);
			res^=1;
		}
	}
	//cout<<v<<'v'<<res<<'r'<<endl;
	return res;
}

int main(){
	ll n,m;
	cin>>n>>m;
	vector<P> a(n);
	vector<P> l(m);



	rep(i,n){
		cin>>a[i].first>>a[i].second;
	}
	rep(i,m)cin>>l[i].first>>l[i].second;
	sort(a.begin(),a.end());

	x[0]=a[0].second;
	rep(i,n-1)x[i+1]=a[i+1].second^a[i].second;
	x[n]=a[n-1].second;
	rep(i,m){
		ll lft=lower_bound(a.begin(),a.end(),P(l[i].first,0))-a.begin();
		ll rt=upper_bound(a.begin(),a.end(),P(l[i].second,1))-a.begin();
		g[lft].emplace_back(P(rt,i));
		g[rt].emplace_back(P(lft,i));
	}
	rep(i,n+1){
		if (used[i])continue;
		if (dfs(i)){
			cout<<-1;
			return 0;
		}

	}
	ll cnt=ans.size();
	cout<<cnt<<endl;
	sort(ans.begin(),ans.end());
	rep(i,cnt){
		cout<<ans[i]+1<<' ';
	}

}


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

int main() {
	string number;
	cin >> number;
	if (number.at(0) == number.at(1) && number.at(1) == number.at(2)) {
		cout << "Yes" << endl;
	}
	else if (number.at(1) == number.at(2) && number.at(2) == number.at(3)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;

  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end(), greater<ll>());

  queue<ll> q;
  q.push(a[0]);

  ll ans = 0;

  reps1(i, n) {
    ans += q.front();
    q.pop();
    q.push(a[i]);
    q.push(a[i]);

  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 6412
n = int(input())
c = input()

r = []
w = []

for i in range(n):
    if c[i] == 'R':
        r.append(i)
    else:
        w.append(i)

r.sort(reverse=True)

if len(r) == 0 or len(w) == 0:
    print(0)
else:
    ans = 0
    while ans < len(r) and ans < len(w) and r[ans] > w[ans]:
        ans += 1
    print(ans)


Measured memory_bytes: 17424
#include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int n;
int d;
int e;
int f;
int g;
while(cin >>a){
cin >> b;
if(a==0){break;}
cin >> n;
int c[a][b];
d=0;
while(d<a){
g=0;
while(g<b){
c[d][g]=-1;
g=g+1;}
d=d+1;}
d=0;
while(d<n){
cin >>e;
cin >>f;
c[e-1][f-1]=0;
d=d+1;}
c[0][0]=1;
d=1;
while(d<a){
if(c[d][0]!=0){c[d][0]=c[d-1][0];}
d=d+1;}
d=1;
while(d<b){
if(c[0][d]!=0){c[0][d]=c[0][d-1];}
d=d+1;}
d=1;
while(d<a){
g=1;
while(g<b){
if(c[d][g]!=0){c[d][g]=c[d-1][g]+c[d][g-1];}
g=g+1;}
d=d+1;}
cout <<c[a-1][b-1]<<endl;}}

Measured memory_bytes: 1164
/**
 * Title: D - Teleporter
 * Url: https://atcoder.jp/contests/abc167/tasks/abc167_d
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ll n, k; cin >> n >> k;
    vector<int> a(n+1), visited(n+1, 0), times(n+1, 0);
    for(int i=1; i<=n; i++) cin >> a[i];
    ll cnt = 0;
    ll town = 1;
    while(true) {
        if(cnt==k) {
            cout << town << endl;
            return 0;
        }
        if(visited[town]==0) {
            visited[town] = 1;
            times[town] = cnt;
            cnt++;
            town = a[town];
        } else {
            break;
        }
    }
    ll r = (k-cnt)%(cnt-times[town]);
    ll target = times[town]+r;
    for(int i=1; i<=n; i++) {
        if(times[i]==target) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

int INF = 1000000007;
int n;
int x[200000], y[200000];

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		if (x[i] > y[i]) swap(x[i], y[i]);
	}
	
	int S = INF;	//全体の最小値
	int L = -INF;	//全体の最大値
	int Mx = -INF;	//min(x[i], y[i])の最大値
	int Nx = INF;	//max(x[i], y[i])の最小値
	for (i = 0; i < n; i++) S = min(S, min(x[i], y[i]));
	for (i = 0; i < n; i++) L = max(L, max(x[i], y[i]));
	for (i = 0; i < n; i++) Mx = max(Mx, min(x[i], y[i]));
	for (i = 0; i < n; i++) Nx = min(Nx, max(x[i], y[i]));
	int ans = (Mx - S) * (L - Nx);
	
	//あとは、Rmin = S, Rmax = Lとする場合を考えればよい。
	int maxX = -INF;
	int minY = INF;
	for (i = 0; i < n; i++) maxX = max(maxX, x[i]);
	for (i = 0; i < n; i++) minY = min(minY, y[i]);
	
	//簡単のためx_i≦y_iとする。次に頂点x_1,…,x_N,y_1,…,y_N (同じ値ができたら複数生成)を作り、全てのiについてx_i -> y_iと辺を張る。
	//するといい感じに考察ができる。
	//
	//Bmin…青の最小以下の好きな値, Bmax…青の最大以上の好きな値, と置き換える。
	//[Bmin, Bmax]を固定したときに正当か？を考える。Bmax≧maxX, Bmin≦minY
	//が成り立つもとで, 全てのiについて「Bmin≦x_i or Bmax≧y_i」が真⇔正当
	//
	//正当な[Bmin, Bmax]のうち, Bmax - Bminが最小のものを求めよう。とりあえずBminを固定する。
	//すると, x_i < Bminを満たすすべてのiについて、y_i≦Bmaxを満たせばよくなる。
	//そのようなBmaxの最小値は、x_i < Bminを満たすiについてのmax(y_i)と等しい。
	//x_i ≦ Bmin < x_[i+1]のときにBmaxの最小値が変化しないことから、Bminはx_i, y_iのみ想定すればよいことになる。
	//Bmax≧maxX, Bmin≦minYという条件を忘れないように注意する。
	//よって, (x_i, y_i)をx_iが小さい順にソートして、逐次max(y_i)を求めていけばよい。

	
	typedef pair<int, int> P;
	vector<P> vec;
	for (i = 0; i < n; i++) vec.push_back(P(x[i], y[i]));
	sort(vec.begin(), vec.end());
	
	int My = vec[0].second;
	int score = INF;
	for (i = 1; i < n; i++) {
		int Bmin = min(vec[i].first, minY);
		score = min(max(My, maxX) - Bmin, score);
		
		My = max(My, vec[i].second);
	}
	
	ans = min(ans, score * (L - S));
	
	cout << ans << endl;
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  for(int i = 0; i < s.length() - 1; i++) {
    if(s[i] == s[i + 1]) {
      cout << i + 1 << " " << i + 2 << "\n";
      return 0;
    }
    if(i < s.length() - 2) {
      if(s[i] == s[i + 2]) {
        cout << i + 1 << " " << i + 3 << "\n";
        return 0;
      }
    }
  }
  cout << "-1 -1"
       << "\n";
}

Measured memory_bytes: 512
Character = Struct.new(:lpt, :atk, :def, :swf)
 
@n = gets.to_i
Cs = []
(@n+1).times{ Cs << Character.new( *gets.split.map(&:to_i) ) }
 
Btl = Struct.new(:hcnt, :dmg)
 
def solve
  sum_dmg = 0
  arr = []
  (1..@n).each do |i|
    dmg = [Cs[i].atk - Cs[0].def, 0].max
    hpt = [Cs[0].atk - Cs[i].def, 0].max
    return -1 if dmg > 0 && hpt == 0
    next if hpt == 0
    hcnt = (Cs[i].lpt.to_f / hpt).ceil
    sum_dmg -= dmg if Cs[i].swf < Cs[0].swf
    arr << Btl.new(hcnt, dmg)
  end
  count = 0

  #cmp hcnt / dmg
  arr.sort{ |e0, e1| e0.hcnt * e1.dmg <=> e0.dmg * e1.hcnt }.reduce(sum_dmg) do |sum, b|
    count += b.hcnt
    res = sum + b.dmg * count
    break -1 if res >= Cs[0].lpt
    res
  end
end
 
p solve

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct State{
	int i,lap,time;
	State(){}
	State(int i,int l,int t):i(i),lap(l),time(t){}
};

int main()
{
	for(int n;cin>>n && n;){
		vi ts(n),cs(n);
		rep(i,n) cin>>ts[i]>>cs[i];
		
		queue<State> q[2]; // (index,lap,time)
		rep(i,n) q[1].emplace(i,0,0);
		
		int res=-1;
		for(;;){
			if(q[0].empty() && q[1].empty()) break;
			int cur=0,next=1;
			if(q[1].size() && (q[0].empty() || q[1].front().time<q[0].front().time))
				cur=1,next=0;
			
			int t=q[cur].front().time;
			vector<State> buf;
			while(q[cur].size() && t>=q[cur].front().time){
				State s=q[cur].front(); q[cur].pop();
				if(cur==1) s.lap++;
				if(s.lap>cs[s.i]){
					res=t;
					continue;
				}
				buf.emplace_back(s.i,s.lap,t+ts[s.i]);
			}
			
			sort(all(buf),[](State a,State b){return a.time<b.time;});
			for(auto t:buf) q[next].emplace(t);
		}
		
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1220
N, X, Y = map(int, input().split())
k = [0 for i in range(N - 1)]

for i in range(N):
  for j in range(N - i - 1):
    a = i + 1
    b = N - j
    if a <= X:
      if b >= Y:
        l = (X - a) + 1 + (b - Y)
      else:
        l = min(b - a, (X - a) + 1 + (Y - b))

    elif a > X:
      if b >= Y:
        l = min(b - a, (a - X) + 1 + (b - Y))
      else:
        l = min(b - a, (a - X) + 1 + (Y - b))
        
    k[l - 1] += 1
    
for val in k:
  print(val)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n;
  m = inf;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x < m) {
      ++ans;
      m = x;
    }
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


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

using namespace std;

vector <int> a(50),b(50),c(50),d(50);

int ans = 0;
int N,M,Q;

void dfs(vector <int> A){
    if(A.size() == N){
        int tmp = 0;
        for(int i = 0; i < Q ; ++i){
            if( A.at( b.at(i) ) - A.at( a.at(i) ) == c.at(i) )tmp += d.at(i);
        }
        ans = max(tmp,ans);
    }else{
        if(A.size() == 0){
            A.push_back(1);
        }else{
            A.push_back(A.back());
        }
        
        while(A.back() <= M){
            dfs(A);
            A.back()++;
        }
    }
    
}

int main(){
    
    cin >> N >> M >> Q;
    
    for (int i ; i < Q ; ++i){
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    
    vector <int> A;
    dfs(A);
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3624
import numpy as np
H,W,A,B = map(int, input().split())

mat = np.zeros((H,W))

for y in range(B):
    for x in range(A,W):
        mat[y][x]=1

for y in range(B,H):
    for x in range(A):
        mat[y][x]=1

for row in mat:
    row=list(map(int, row))
    print("".join(list(map(str, row))))

Measured memory_bytes: 21048
function Main(arg)
{
  var A = arg.split("\n")[0].split(" ")[0]-0;
  var B = arg.split("\n")[0].split(" ")[1]-0;
  var M = arg.split("\n")[0].split(" ")[2]-0;


  var reizouko = arg.split("\n")[1].split(" ").map(Number);
  var renzi = arg.split("\n")[2].split(" ").map(Number);
  var waribiki = arg.split("\n").slice(3);
  var min = 1000000;
  var a =  0;
  var b = 0;
  for (var i = 0; i < M; i++){
    a = waribiki[i].split(" ")[0] - 0;
    b = waribiki[i].split(" ")[1] - 0;
    var tmp = waribiki[i].split(" ")[2] - 0;
    var c = reizouko[a - 1];
    var d = renzi[b - 1];
    if (c + d - tmp < min) {
      min = c + d - tmp;
    }
  }

  var reizouko_min = reizouko.reduce((x,y)=>x<y?x:y);
  var renzi_min = renzi.reduce((x,y)=>x<y?x:y);

  console.log(Math.min(min, reizouko_min + renzi_min));

  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 61488
#include <iostream>
#include <string>
#include <string.h>
#include <strings.h>
#include <bits/stdc++.h>
using namespace std;

int main()
{
string s;
cin>>s;
if(s.at(0)==s.at(2)){
    cout<<"Yes";
}
else{
    cout<<"No";
}
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
			int ans = 0;
			for (int i = 0; i < input.Length; i++)
			{
				if (i + 1 == input[i])
				{
					ans++;
					if (i + 1 < N && i + 2 == input[i + 1]) i++;
				}
			}
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 18016
n = gets.to_i
ab = Array.new(n) { gets.split.map(&:to_i) }

takahashi = 0
aoki = 0

ab.sort_by! { |a, b| a + b }

is_takahashi = true
until ab.empty?
  a, b = ab.pop
  if is_takahashi
    takahashi += a
  else
    aoki += b
  end
  is_takahashi = !is_takahashi
end
puts(takahashi - aoki)

Measured memory_bytes: 12664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long T,i,j,n,ans=0,t;
    cin>>n;
    long long a[n+5];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
           {
               ans+=a[i]-a[i+1];
               a[i+1]+=(a[i]-a[i+1]);
           }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5212
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int x;
	std::cin >> x;
	std::cout << ((2199-x)/200) << std::endl;
	return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 105;

int w[N], v[N], dp[N][100005];


signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    	cin >> w[i] >> v[i];
    for (int i = 1; i < 100005; i++)
    	dp[0][i] = inf;
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j < 100005; j++) {
    		if (j >= v[i]) dp[i][j] = min(w[i] + dp[i-1][j-v[i]], dp[i-1][j]);
    		else dp[i][j] = dp[i-1][j];
    	}
    }
    int ans = 0;
    for (int j = 0; j < 100005; j++)
    	if (dp[n][j] <= k) ans = j;
    cout << ans;
    return 0;
}

Measured memory_bytes: 80128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		string S = GetString();
		Console.WriteLine(S.Substring(0, S.Length - 8));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

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

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

  int a, b, c;
  cin >> a >> b >> c;

  int ans;
  if (c > a+b) {
    ans = a+b + b +1;
  } else {
    ans = c + b;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int
#define nl "\n"
using namespace std;

void code()
{       
    int n,s,t;
    cin>>n>>s>>t;
    if(s*t>=n)
        cout<<"Yes"<<nl;
    else cout<<"No"<<nl;
    
        
}
signed main()

{

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
        
        FAST_IO;
        int t = 1;

        // cin>>t;

        while(t--)
        {
                code();
        }
        

#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif

        return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string Made_Model(int size, char s){
    
    string result = "";
    for(int i=0;i<size;i++){
        if(i%2 == 0){
            result += s;
        }
        else{
            if(s == '0') result += '1';
            else result += '0';
        }
    }
    return result;
}

int Diff(string s, string t){
    
    int l = s.size();
    int sum = 0;
    for(int i=0;i<l;i++){
        if(s[i] != t[i]) sum++;
    }
    
    return sum;
}
int main(){

    string S;
    cin >> S;
    int len = S.size();
    cout << min(Diff(S,Made_Model(len,'0')),Diff(S,Made_Model(len,'1'))) << endl;
}

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

XY= [list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]


red= [False for i in range(N)]
red[0]=True
balls= [1 for i in range(N)]


for x,y in XY:
    if red[x]==True:
        red[y]=True
    balls[x]-=1
    balls[y]+=1
    if balls[x]==0:
        red[x]=False
print(sum(bool(red[i] and balls[i]) for i in range(N)))


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int sum=a+b+c;
    int ma=max(a,max(b,c));
    sum-=ma;
    REP(i,k)ma*=2;
    cout << sum+ma << endl;
}


Measured memory_bytes: 256
from itertools import permutations


def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[float('inf')] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c

d = warshall_floyd(d, N)

ans = float('inf')
for p in permutations(r):
    total = 0
    for i in range(1, len(p)):
        total += d[p[i-1]-1][p[i]-1]
    ans = min(ans, total)
print(ans)


Measured memory_bytes: 59736
#include<iostream>
#include<vector>
#include<map>
#include<queue>
using namespace std;
using pii = pair<int, int>;
using piii = pair<int, pii>;

int main(){
  int n, m, r;
  std::cin >> n >> m >> r;
  vector<vector<pii> > G(n);
  vector<int> town(r);
  for (int i = 0; i < r; i++) std::cin >> town[i];
  map<int, int> pos;
  for (int i = 0; i < r; i++) pos[town[i] - 1] = i;
  
  for (int i = 0; i < m; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    a--, b--;
    G[a].push_back(pii(b, c));
    G[b].push_back(pii(a, c));
  }
  int dp[(1<<r)][n];
  for (int i = 0; i < (1<<r); i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = 1e9;
    }
  }
  for (int i = 0; i < r; i++) {
    dp[(1<<i)][town[i] - 1] = 0;
  }
  //cost, state, place
  priority_queue<piii, vector<piii>, greater<piii> > que;
  for (int i = 0; i < r; i++) 
    que.push(piii(0, pii((1<<i), town[i] - 1)));
  while(not que.empty()){
    int c = que.top().first;
    int s = que.top().second.first;
    int v = que.top().second.second;
    que.pop();
    for (int i = 0; i < G[v].size(); i++) {
      int cost = G[v][i].second, to = G[v][i].first;
      if(pos.find(to) != pos.end()){
        int x = pos[to];
        if(dp[(s|(1<<x))][to] > dp[s][v] + cost){
          dp[(s|(1<<x))][to] = dp[s][v] + cost;
          que.push(piii(dp[s][v] + cost, pii((s|(1<<x)), to)));
        }
      }else{
        if(dp[s][to] > dp[s][v] + cost){
          dp[s][to] = dp[s][v] + cost;
          que.push(piii(dp[s][v] + cost, pii(s, to)));
        }
      }
    }
  }
  int ans = 1e9;
  int s = (1<<r) - 1;
  for (int i = 0; i < n; i++) {
    ans = min(ans, dp[s][i]);
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 5236
#include <iostream>
#include <fstream>
#include <climits>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <deque>
#include <map>
using namespace std;

typedef long long ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define forn(i,n) for(int i=0; i<int(n); i++)
#define for1(i,n) for(int i=1; i<=int(n); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void no(int ex = -1) {
	cout << ex << endl;
	//cout << "NO" << endl;
	//exit(0);
}
void bl(bool win) {
	if (win) cout << "YES"; else cout << "NO";
	cout << endl;
}

const int N = 1000000;
const ll INF = LLONG_MAX;
const int mod = 998244353;

/*vector<bool> pr;
void prime() {
	int EDGE = 1000;
	pr.assign(EDGE, true);
	pr[0] = false; pr[1] = false;
	for (int i = 2; i < EDGE; i++) {
		if (pr[i])
			if (1LL * i * i < EDGE)
				for (int j = i * i; j < EDGE; j += i)
					pr[j] = false;
	}
}*/
//prime


ll T;

int main() {
	IOS;
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	int n, m, cnt = 0;
	cin >> n >> m;
	vector<int> h(n);
	vector<vector<int>> road(n);
	vector<bool> good(n, true);
	set<int> mn;
	forn(i, n) cin >> h[i];
	forn(i, m) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		mn.insert(l);
		mn.insert(r);
		if (h[l] >= h[r]) good[r] = false;
		if (h[r] >= h[l]) good[l] = false;
	}
	forn(i, n) if (good[i]) cnt++;
	cout << cnt << endl;
}

Measured memory_bytes: 9648