akhauriyash/Code-Regression huggingface dataset:
N, T = map(int, input().split())
T -= 1

AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[1])
AB.sort(key = lambda x: x[0], reverse = True)

dp = [[0] * (T + 1) for _ in range(N + 1)]

ans = AB[N - 1][1]
for i in range(N - 1, 0, -1):
    for j in range(T + 1):
        if j < AB[i][0]:
            dp[i][j] = dp[i + 1][j]
        else:
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - AB[i][0]] + AB[i][1])
    tmp = dp[i][T] + AB[i - 1][1]
    ans = max(ans, tmp)
    
print (ans)
# print (AB)

# for i in dp:
#     print (dp)

Measured memory_bytes: 117080
from itertools import combinations_with_replacement as combr

N,M,Q = map(int, input().split())
a, b, c, d = [0]*Q, [0]*Q, [0]*Q, [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int, input().split())

ans = 0
# lis = list(range(1, M+1))
for pair in combr(range(1,M+1), N):
    tmp = 0
    pair = list(pair)
    for i in range(Q):
        if (pair[b[i]-1]-pair[a[i]-1]) == c[i]:
            tmp += d[i]
            
    ans=max(ans, tmp)

print(ans)


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

using namespace std;

const int lim=100005;

int m(int x){
	if(x<0) return -x; return x;
}

int h[lim];
int t[lim];

int n;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	
	cin>>h[1];
	t[0]=lim;
	
	for(int i=2;i<=n;i++){
		cin>>h[i];
		t[i]=min(t[i-1]+m(h[i-1]-h[i]),t[i-2]+m(h[i-2]-h[i]));
	}	
	
	cout<<t[n];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

const int MAXN = 105000;
const int INF = (int) 1e9;

int n;
int h[MAXN];
int dp[MAXN];

int main() {

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

  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 2; j++) {
      if (i + j < n) {
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
      }
    }
  }

  cout << dp[n - 1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
using ll =long long;

int main (void) {
  int x,y,z;
  int ans;
  cin >> x >> y >> z;
  ans=(x-z)/(y+z);
  cout << ans;
}


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

const ll INF = 1e18 + 10;
ll dp1[2010][2010];
ll dp2[2010][2010];

ll f1(int h, int t) {
	if (h >= t)
		return 0;
	ll& d = dp1[h][t];
	if (d != -1)
		return d;

	d = INF;
	if (S[h] != S[t]) {
		d = min(f1(h + 1, t) + 1, f1(h, t - 1) + 1);
	} else {
		d = f1(h + 1, t - 1);
	}
	return d;
}

ll f2(int h, int t) {
	if (h >= t)
		return 1;

	ll& d = dp2[h][t];
	if (d != -1)
		return d;

	d = 0;
	if (S[h] == S[t]) {
		d = f2(h + 1, t - 1);
	} else {
		if (dp1[h][t] == f1(h + 1, t) + 1) {
			d += f2(h + 1, t);
		}
		if (dp1[h][t] == f1(h, t - 1) + 1) {
			d += f2(h, t - 1);
		}
	}
	return d = min(INF, d);
}

int main() {
	cin >> S >> k;
	//k--;
	int N = S.size();

	memset(dp1, -1, sizeof dp1);
	memset(dp2, -1, sizeof dp2);
	int len = f1(0, N - 1);

	//cout << len << endl;

	ll sum = f2(0, N - 1);
	if (k > sum) {
		cout << "NONE" << endl;
		return 0;
	}

	string ans;
	int h = 0, t = N - 1;
	for (int i = 0; i < (N + len) / 2; i++) {
		for (char c = 'a'; c <= 'z'; c++) {
			int nh = h + (S[h] == c);
			int nt = t - (S[t] == c);
			int d = (S[h] != c) + (S[t] != c);
			if (dp1[h][t] != f1(nh, nt) + d)
				continue;
			ll num = f2(nh, nt);
			assert(num != 0);
			if (num >= k) {
				ans += c;
				h = nh, t = nt;
				break;
			} else {
				k -= num;
			}
		}
	}

	if (h == t) {
		string ss = ans;
		reverse(ss.begin(), ss.end());
		ans += S[h] + ss;
	} else {
		string ss = ans;
		reverse(ss.begin(), ss.end());
		ans += ss;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 66444
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for(int i =0;i<n;i++){
      if(minv > d[i] && color[i]!= BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(int v = 0;v<n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  int sum = 0;
  for(int i =0;i<n;i++){
    if(p[i] != -1) sum+=M[i][p[i]];
  }

  return sum;
}

int main(){
  cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e; cin >> e;
      M[i][j] = (e == -1)? INFTY : e;
    }
  }

  cout << prim() << endl;

  return 0;
}



Measured memory_bytes: 3132
import java.util.*;
import java.io.*;

class Main{
  static int n = 0;
  public static void main(String args[]){

    StringBuilder build = new StringBuilder();
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();

    int A[] = new int[n+1];

    for(int i = 1; i<n+1; i++){
      A[i]  = sc.nextInt();
    }

    buildMaxHeap(A);

    for(int i = 1; i<n+1; i++){
      System.out.print(" "+A[i]);
    }
    System.out.println("");

  }

  static void maxHeapify(int A[], int i ){
    int l =i*2;
    int r = i*2+1;
    int largest = 0;
    int tmp;

    if(l<=n && A[l] > A[i]) largest = l;
    else largest = i;

    if(r<=n && A[r] > A[largest] ) largest = r;

    if(largest != i){
      tmp = A[i];
      A[i] = A[largest];
      A[largest] = tmp;
      maxHeapify(A, largest);
    }
  }

  static void buildMaxHeap(int []A){
    for(int i = n/2; i>0; i--){
      maxHeapify(A,i);
    }
  }

}



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

map<int,int> m;
vector<int> v;
int n,x,i,ans;

int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(m[x]==0) v.push_back(x);
		m[x]++;
	}
	
	for(i=0;i<v.size();i++) 
	  if(v[i]>m[v[i]]) ans+=m[v[i]];
	  else if(v[i]<m[v[i]]) ans+=m[v[i]]-v[i];
	  
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5112
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    vector< pair<int,int> > B_C(M);
    for(int i=0;i<N;i++)cin >> A.at(i);
    for(int i=0;i<M;i++){
        cin >> B_C.at(i).second >> B_C.at(i).first;
    }
    
    sort(B_C.begin(), B_C.end(), greater< pair<int,int> >());
    vector<int> C_list(0);
    for(int i=0;i<M;i++){
        for(int j=0;j<B_C.at(i).second;j++){
            C_list.push_back( B_C.at(i).first );
            if(C_list.size() == N)break;
        }
        if(C_list.size() == N)break;
    }

    sort(A.begin(), A.end());
    sort(C_list.begin(), C_list.end(), greater<int>());
    for(int i=0;i<C_list.size();i++){
        if(A.at(i) < C_list.at(i))A.at(i) = C_list.at(i);
    }
    long sum = 0;
    for(int i=0;i<N;i++){
        sum += A.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 2044
def solve(votes):
    for start in [(1, 1), (1, 0), (0, 1), (0, 0)]:
        a = animals(start, votes)
        if a[:2] == a[-2:]:
            return a


def animals(start, votes):
    rv = [None] * len(votes)
    rv[:2] = start
    for i in range(1, len(votes) - 1):
        rv[i + 1] = rv[i - 1] ^ rv[i] ^ votes[i]
    return tuple(rv)


def parse(s):
    return tuple(int(v == "o") for v in s + s[:2])


def display(s):
    if not s:
        return "-1"
    return "".join("S" if v else "W" for v in s[:-2])


if __name__ == "__main__":
    import sys
    _n = sys.stdin.readline()
    votes = sys.stdin.readline().strip()
    votes = parse(votes)
    sol = solve(votes)
    print(display(sol))


def test_parse():
    assert parse("ooxoox") == (1, 1, 0, 1, 1, 0, 1, 1)


def test_display():
    assert display((1, 1, 0, 0, 7, 7)) == "SSWW"


def test_animals():
    p = object()  # sentinel or poison
    assert animals((1, 1), (p, 1, p)) == (1, 1, 1)
    assert animals((1, 1), (p, 0, p)) == (1, 1, 0)
    assert animals((0, 1), (p, 1, p)) == (0, 1, 0)
    assert animals((1, 0), (p, 1, p)) == (1, 0, 0)


def test_animals_lex():
    assert animals((1, 1), parse("ooo")) == (1, 1, 1, 1, 1)
    assert animals((1, 1), parse("xxx")) == (1, 1, 0, 1, 1)


def test_solve_atcoder():
    assert display(solve(parse("oox"))) == "-1"
    assert display(solve(parse("ooxoox"))) == "SSSWWS"
    assert display(solve(parse("oxooxoxoox"))) == "SSWWSSSWWS"

Measured memory_bytes: 7068
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 10;

double arr[10000], n;
double dp[3000][3000];
bool seen[3000][3000];

double solve(int i, int c)
{
	if(i == n)
	{
		if(c > n / 2) return 1;
		return 0;
	}
	if(seen[i][c])
		return dp[i][c];
	seen[i][c] = true;
	return dp[i][c] = arr[i] * solve(i + 1, c + 1) + (1 - arr[i]) * solve(i + 1, c);
}

int32_t main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		scanf(" %lf", arr + i);
	printf("%.9lf\n", solve(0, 0));
	
	return 0;
}

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

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

	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (i * j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}





Measured memory_bytes: 3604
D=int(input())
C=list(map(int,input().split()))
import numpy as np
L=np.zeros(26,dtype=np.int)
ans=[]
for d in range(D):
  L+=1
  X=L*C
  xi=X.argmax()
  S=list(map(int,input().split()))
  si=np.argmax(S)
  if si==xi:
    ans.append(si+1)
    L[si]=0
  elif S[si]-5*C[xi]>X[xi]:
    ans.append(si+1)
    L[si]=0
  else:
    ans.append(xi+1)
    L[xi]=0
for a in ans:
  print(a)

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

typedef double lf;
typedef pair<int, int> pii;

lf getDist(pii a, pii b) {
    lf dx = a.first - b.first;
    lf dy = a.second - b.second;
    return sqrt(dx*dx + dy*dy);
}

int Xs, Ys, Xt, Yt, N;
struct Info {
    int x, y, r;
};
Info info[1010];
lf adj[1010][1010];

lf f(Info a, Info b) {
    lf tmp = getDist(pii(a.x, a.y), pii(b.x, b.y));
    if(tmp + 1e-9 < a.r + b.r) return 0;
    else return tmp - (lf)(a.r + b.r);
}

int chk[1010];
lf dist[1010];

void dijkstra() {
    for(int i = 0; i < N + 2; i++) dist[i] = 1e12;
    dist[N] = 0;

    while(1) {
        int mn = 1e12, p = -1;
        for(int i = 0; i < N + 2; i++) {
            if(!chk[i] && mn > dist[i]) {
                mn = dist[i];
                p = i;
            }
        }
        if(p == -1) break;
        chk[p] = 1;

        for(int i = 0; i < N + 2; i++) {
            if(i == p) continue;
            dist[i] = min(dist[i], dist[p] + adj[p][i]);
        }
    }
}

int main() {
    scanf("%d %d %d %d %d", &Xs, &Ys, &Xt, &Yt, &N);

    for(int i = 0; i < N; i++) {
        scanf("%d %d %d", &info[i].x, &info[i].y, &info[i].r);
    }
    info[N] = {Xs, Ys, 0};
    info[N + 1] = {Xt, Yt, 0};

    for(int i = 0; i < N + 2; i++) {
        for(int j = i + 1; j < N + 2; j++) {
            adj[i][j] = f(info[i], info[j]);
            adj[j][i] = adj[i][j];
        }
    }

    dijkstra();

    cout << fixed;
    cout.precision(20);
    cout << dist[N + 1];
}


Measured memory_bytes: 8192
import sys
input = sys.stdin.readline
import numpy as np


h, w = map(int, input().split())

GRID = []
for _ in range(h):
    S = [0] + [0 if c == "#" else 1 for c in input().strip()] + [0]
    GRID.append(S)
GRID.insert(0, [0] * (w + 2))
GRID.append([0] * (w + 2))
grid = np.array(GRID)

top = np.zeros((h + 2, w + 2), dtype = np.int)
bottom = np.zeros((h + 2, w + 2), dtype = np.int)
left = np.zeros((h + 2, w + 2), dtype = np.int)
right = np.zeros((h + 2, w + 2), dtype = np.int)

for i in range(1, h + 1):
    top[i] = (top[i - 1] + 1) * grid[i]
for i in range(h, 0, -1):
    bottom[i] = (bottom[i + 1] + 1) * grid[i]
for j in range(1, w + 1):
    left[:, j] = (left[:, j - 1] + 1) * grid[:, j]
for j in range(w, 0, -1):
    right[:, j] = (right[:, j + 1] + 1) * grid[:, j]

column = (top + bottom - 1) * grid
row = (left + right - 1) * grid
lighted = (column + row - 1) * grid

ans = lighted.max()
print(ans)


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

int main(){
  int Q[12];
  for(int i=1;i<=11;i++){
    if(1<=i&&i<=6) Q[i]=i+1;
    else Q[i]=i-5;
  }

  string str;
  cin>>str;
  reverse(str.begin(),str.end());

  int sum=0,idx=0;
  for(int i=1;i<=11;i++)
    if(str[i]!='?') sum+=(str[i]-'0')*Q[i];
    else idx=i;

  if(idx==0) {
    int n=sum%11;
    if(n<=1)n=0;
    n=11-n;   
    cout<<n%11<<endl;
  }
  else {
    int ans=-1;
    for(int i=0;i<=9;i++) {
      int n=(sum+Q[idx]*i)%11;
      if(n<=1) n=0;
      n=11-n;
      if(n%11==str[0]-'0'){
	if(ans==-1)ans=i;
	else ans=-2;
      }
    }
    if(ans==-2) cout<< "MULTIPLE"<<endl;
    else cout << ans%11<<endl;
  }
  return 0;
}

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

int top = 0, a[100];

void push(int);
int pop(void);

int main(){
    int x, temp, r, l;
    char s[100];
    
    while(scanf("%s", s) != EOF){
        if(s[0] == '+'){
            temp = pop() + pop();
            push(temp);
        }
        
        else if(s[0] == '-'){
            r = pop();
            l = pop();
            temp = l - r;
            push(temp);
        }
        
        else if(s[0] == '*'){
            temp = pop() * pop();
            push(temp);
        }
        
        else{
            x = atoi(s);
            
            push(x);
        }
    }
    printf("%d\n", a[1]);
    
    return 0;
}


void push(int x){
    top++;
    a[top] = x;
}

int pop(){
    top--;
    return a[top + 1];
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;

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

signed main(){
    int n, sum = 0;
    cin >> n;
    vector<int> ans;
    for(int i = 2; i <= 30000; i++){
        if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0){
            if(ans.size() < n - 2){
                ans.push_back(i);
                sum += i;
            }
        }
    }
    int last = ans.back();
    for(int i = last + 1; i <= 30000; i++){
        if(!(i % 2 == 0 || i % 3 == 0 || i % 5 == 0)) continue;
        for(int j = i + 1; j <= 30000; j++){
            if(j % 2 == 0 || j % 3 == 0 || j % 5 == 0){
                if((i + j + sum) % 30 == 0){
                    ans.push_back(i);
                    ans.push_back(j);
                    sum += i + j;
                    j = INF; i = INF;
                }
            }
        }
    }
    int G = ans[0];
    rep(i, 1, n) G = gcd(G, ans[i]);
    assert(G == 1);
    assert(ans.size() == n);
    for(int ii = 0; ii < ans.size(); ii++){
        int tmp = gcd(ans[ii], sum - ans[ii]);
        assert(tmp != 1);
        if(ii) cout << ' ';
        cout << ans[ii];
    }
    cout << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


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

    vector<char> op(3);

    for (int bit = 0; bit < (1<<3); ++bit) {
        int tmp = abcd[0]-'0';
        rep(i, 3) {
            if (bit & (1<<i)) {
                tmp += abcd[i+1]-'0';
                op[i] = '+';
            } else {
                tmp -= abcd[i+1]-'0';
                op[i] = '-';
            }
        }
        //cout << tmp << endl;
        if(tmp == 7) break;
    }

    string ans;
    ans += abcd[0];
    rep(i, 3) {
        ans += op[i];
        ans += abcd[i+1];
    }

    ans+="=7";
    cout << ans << endl;


    return 0;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int n,a[100005][3],dp[100005][3];

int main(){
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  for(int i=1;i<n;++i){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
  }
  cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
  return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
}

Measured memory_bytes: 26196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 1e5*2+1;
int N, Q;
ll PO[MAX_N];

void solve() {
    cin >> N >> Q;
    vector<vector<int>> g(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i = 0; i < Q; ++i) {
        int p;
        ll x;
        cin >> p >> x;
        p--;
        PO[p] += x;
    }
    queue<int> q;
    q.push(0);
    vector<bool> memo(N, false);
    while(!q.empty()) {
        int par = q.front(); q.pop();
        memo[par] = true;
        int po = PO[par];
        for (int ch: g[par]) {
            if (memo[ch]) continue;
            PO[ch] += po;
            q.push(ch);
        }
    }
    for (int i = 0; i < N; ++i) {
        printf("%ld ", PO[i]);
    }
    cout << endl;
}

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

// after_contest_15 => 1 111 101


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

int main(){
	int n,c,p;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c>>p;
		if(c%p==0) cout<<p<<endl;
		else cout<<c%p<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	auto dp = make_v<bool>(n + 1, 2);
	for(int i = 0; i < n; i++) {
		if(!i) {
			dp[i + 1][0] = dp[i + 1][1] = true;
		} else {
			for(int k = 0; k < 2; k++) {
				int last = a[i - 1] - k;
				
				for(int j = 0; j < 2; j++) {
					int now = a[i] - j;
					if(last > now) continue;
					dp[i + 1][j] = dp[i + 1][j] | dp[i][k];
				}
			}
		}
	}
	
	if(dp[n][0] or dp[n][1]) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 7680
S = input()
Q = int(input())

lS = ''
for _ in range(Q):
    query = input().split()
    if query[0] == '1':
        lS, S = S, lS
    else:
        if query[1] == '1':
            lS += query[2]
        else:
            S += query[2]

print(lS[::-1] + S)

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

int main()
{
	int n;//??\?????????????????±?????°
	int count[5][4][11]={0};//4?£?3???10??¨?±?
	int b,f,r;//b?£?f??????r??????
	int v;//v???
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>b>>f>>r>>v;
		count[b][f][r]+=v;
		

	}

	for(int f=1;f<=4;f++){
		if(f>1)cout<<"####################"<<endl;
		for(int b=1;b<=3;b++){
			for(int r=1;r<=10;r++){
			cout<<" "<<count[f][b][r];



		}
			cout<<endl;

		}
		
	}
	return 0;
}

Measured memory_bytes: 3072
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAX(a,b) (a>b?a:b)
using namespace std;

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

  int jyu  = N / 10;
  int ichi = N % 10;

  if(jyu==9||ichi==9) cout << "Yes" << endl;
  else                cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N, a, b = map(int, input().split())
MOD = 10**9+7

def comb(N, a):
    x, y = 1, 1
    for i in range(a):
        x *= (N-i)
        x %= MOD
        y *= (i+1)
        y %= MOD
    return (x*pow(y, MOD-2, MOD))%MOD

ans = (pow(2, N, MOD)-1-comb(N, a)-comb(N, b))%MOD
print(ans)

Measured memory_bytes: 3064
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
discount = list(map(int, input().split()) for _ in range(M))

ans = min(a) + min(b)

for x, y, c in discount:
    tmp = a[x - 1] + b[y - 1] - c
    if tmp < ans:
        ans = tmp

print(ans)


Measured memory_bytes: 67532
#include <iostream>

using namespace std;

int main()
{
int N , c=0;
cin >> N ;
string S;
S.size()==N;
cin >> S;
for(int i=0; i<N; i++)
{
    if(S[i]==S[i+1])
        continue;
      else
        c++;
}
cout <<c ;


    return 0;
}


Measured memory_bytes: 512
N = int(input())
A = [int(e) for e in input().split()]

A_dict = {}
for i in range(1,N+1):
    A_dict[i] = A[i-1]

A_sorted = sorted(A_dict.items(), key=lambda x:x[1])
a = []
for i in A_sorted:
    a.append(int(i[0]))

print(' '.join(map(str, a)))

Measured memory_bytes: 31808
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        int K = sc.nextInt();

        Queue<Long> q = new LinkedList<>();

        for(long i = 1; i < 10; i++)
            q.offer(i);

        int count = 0;

        while(count++ < K-1) {
            long num = q.poll();

            if(num % 10 != 0) {
                q.offer(num*10 + num%10-1);
            }

            q.offer(num*10 + num%10);

            if(num % 10 != 9){
                q.offer(num*10 + num%10+1);
            }
        }

        os.println(q.poll());
    }
}

Measured memory_bytes: 37332
N, T = map(int, input().split())
A = list(map(int, input().split()))

min_a = A[0]
profit = 0
ans = 0
for a in A[1:]:
    min_a = min(min_a, a)
    if a - min_a > profit:
        profit = a - min_a
        ans = 1
    elif a - min_a == profit:
        ans += 1
print(ans)

Measured memory_bytes: 15020
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 301000
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c))	c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 998244353;
const int inv2 = 499122177;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, nn;
ll p[N], I[N], f[N];
inline void FWT(ll *a, int type) {
	for (int i = 1; i < nn; i <<= 1) {
		for (int j = 0; j < nn; j += (i << 1)) {
			for (int k = 0; k < i; ++k) {
				if (type == 1) {
					int nx = a[j + k], ny = a[i + j + k];
					a[j + k] = (nx + ny) % P;
					a[i + j + k] = (nx - ny + P) % P;
				} else {
					int nx = a[j + k], ny = a[i + j + k];
					a[j + k] = 1ll * inv2 * (nx + ny) % P;
					a[i + j + k] = 1ll * inv2 * (nx - ny + P) % P;
				}
			}
		}
	}
}
int main() {
	read(n); nn = (1 << n);
	ll tot = 0;
	for (int i = 0; i < nn; ++i)	read(p[i]), tot += p[i];
	tot = quickpow(tot % P, P - 2);
	for (int i = 0; i < nn; ++i)	p[i] = p[i] * tot % P;
	p[0] = (p[0] - 1 + P) % P;
	I[0] = nn - 1;
	for (int i = 1; i < nn; ++i)	I[i] = P - 1;
	FWT(p, 1); FWT(I, 1);
	tot = 0;
	for (int i = 1; i < nn; ++i)	f[i] = I[i] * quickpow(p[i], P - 2) % P, tot += f[i];
	f[0] = P - tot % P;
	FWT(f, -1);
	for (int i = 0; i < nn; ++i)	printf("%lld\n", f[i]);
	return 0;
}


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

// ?¨±?????????????????
#define EPS (1e-10)

int main(){
	int n;
	while(cin >> n && n != 0){
        vector<int> a(n);
        REP(i, n) cin >> a[i];
        vector<int> sum(n);
        sum[0] = a[0];
        FOR(i, 1, n) sum[i] = sum[i-1] + a[i];
        int ret = sum[0];
        FOR(i,-1, n) FOR(j,i+1, n) ret = i > -1 ? max(ret ,sum[j]-sum[i]) : max(ret ,sum[j]) ; 
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <string.h>
char s[500100],in[100010],c[5];
int main(){
	int len,i,h,t,b,q,cmd,f;
	scanf("%s",in);
	len=strlen(in);
	for(i=200010;i<200010+len;i++)s[i]=in[i-200010];
	h=200010-1,t=200010+len;
	scanf("%d",&q);
	while(q--){
		scanf("%d",&cmd);
		if(cmd==1)b=h,h=t,t=b;
		else if(cmd==2){
			scanf("%d%s",&f,c);
			if(f==1){//h
				if(h<t)s[h]=c[0],h--;
				else s[h]=c[0],h++;
			}else if(f==2){//t
				if(h<t)s[t]=c[0],t++;
				else s[t]=c[0],t--;
			}
		}
	}
	if(h>t)
		for(i=h-1;i>=t+1;i--)printf("%c",s[i]);
	else 
		for(i=h+1;i<=t-1;i++)printf("%c",s[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N, A, B; cin >> N >> A >> B;
	vector<ll> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	
	//sort(h.begin(), h.end());
	ll left = 0, right = 1e9;
	while (left < right) {
		ll mid = (left + right) / 2;
		ll cnt = 0;
		for (int i = 0; i < N; i++) {
			cnt += max((ll)0, (h[i] - B * mid + A - B - 1) / (A - B));
		}
		if (cnt > mid)left = mid + 1;
		else right = mid;
		//cout << "left=" << left << "right=" << right << endl;
		//cout << "cnt=" << cnt << " mid=" << mid << endl << endl;;
		
	}

	cout << right << endl;
}


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

int sgn(int i) {
    return i == 0 ? 0 : (i < 0 ? -1 : 1);
}

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

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

    int s = 0, r = 1;
    for (int i = 1; i < n; i++) {
        int t = sgn(a[i] - a[i - 1]);
        if (s == 0) {
            s = t;
        } else {
            if (t != 0 && s != t) {
                s = 0;
                r++;
            }
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 640
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

sum = 0
hantei = 0


for i in range(len(a)):


    if i == 0:
        sum = sum + b[a[i]-1]
        hantei = a[i]
    else:
        if a[i] == hantei + 1:
            sum = sum + b[a[i]-1] + c[a[i]-2]
            hantei = a[i]
        else:
            sum = sum + b[a[i]-1]
            hantei = a[i]
    
print(sum)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public decimal[] Sarray() { return ReadLine().Split().Select(decimal.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var AN = Sarray();
            var tmp = (AN[0] * 100) * (AN[1] * 100);
            WriteLine(Math.Floor(tmp/10000));
        }

    }
}


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

vector<int> soiunsuu(100);
void factorize(int X) {
    int i = 2;
    while (X > 1) {
        while (X % i == 0) {
            X /= i;
            soiunsuu.at(i)++;
        }
        i++;
    }
}

int main() {
    int N;
    cin >> N;
    
    for(int n = 1; n <= N; n++) {
        factorize(n);
    }
    
    int a = 0, b = 0, c = 0, d = 0, e = 0;
    for(int i = 0; i < 100; i++) {
        if(soiunsuu.at(i)>=74) a++;
        else if(soiunsuu.at(i)>=24) b++;
        else if(soiunsuu.at(i)>=14) c++;
        else if(soiunsuu.at(i)>=4) d++;
        else if(soiunsuu.at(i)>=2) e++;
    }
    
    int ans1 = a;
    
    int ans2 = (a+b)*(a+b+c+d+e-1);
    
    int ans3 = (a+b+c)*(a+b+c+d-1);
    
    int ans4 = (a+b+c+d)*(a+b+c+d-1)*(a+b+c+d+e-2)/2;
    
    cout << ans1 + ans2 + ans3 + ans4 << endl;
}


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

typedef long long ll;

int main()
{
    int h,w;
    int i,j,k;
    cin >> h >> w;
    vector<string> s(h);
    for(i = 0;i < h;++i){
        cin >> s.at(i);
    }
    vector<vector<int>> tate(h,vector<int>(w,0));
    vector<vector<int>> yoko(h,vector<int>(w,0));
    for(i = 0;i < w;++i){
        vector<int> v;
        for(j = 0;j < h;++j){
            if(s.at(j).at(i) == '#'){
                v.push_back(j);
            }
        }
        if(v.size() == 0){
            for(j = 0;j < h;++j){
                tate.at(j).at(i) = h;
            }
            continue;
        }
        for(j = 0;j < v.at(0);++j){
            tate.at(j).at(i) = v.at(0);
        }
        tate.at(v.at(0)).at(i) = 0;
        for(k = 0;k < v.size()-1;++k){
            for(j = v.at(k)+1;j < v.at(k+1);++j){
                tate.at(j).at(i) = v.at(k+1)-v.at(k)-1;
            }
            tate.at(v.at(k+1)).at(i) = 0;
        }
        for(k = v.at(v.size()-1)+1;k < h;++k){
            tate.at(k).at(i) = h-1-v.at(v.size()-1);
        }
    }
    for(i = 0;i < h;++i){
        vector<int> v;
        for(j = 0;j < w;++j){
            if(s.at(i).at(j) == '#'){
                v.push_back(j);
            }
        }
        if(v.size() == 0){
            for(j = 0;j < w;++j){
                yoko.at(i).at(j) = w;
            }
            continue;
        }
        for(j = 0;j < v.at(0);++j){
            yoko.at(i).at(j) = v.at(0);
        }
        yoko.at(i).at(v.at(0)) = 0;
        for(k = 0;k < v.size()-1;++k){
            for(j = v.at(k)+1;j < v.at(k+1);++j){
                yoko.at(i).at(j) = v.at(k+1)-v.at(k)-1;
            }
            yoko.at(i).at(v.at(k+1)) = 0;
        }
        for(k = v.at(v.size()-1)+1;k < w;++k){
            yoko.at(i).at(k) = w-1-v.at(v.size()-1);
        }
    }
    int ans = 0;
    for(i = 0;i < h;++i){
        for(j = 0;j < w;++j){
            if(ans < tate.at(i).at(j) + yoko.at(i).at(j)-1){
                ans = tate.at(i).at(j) + yoko.at(i).at(j)-1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
    IOS
    int n; cin >> n;
    vector<pii> v;
    REP(i,n) {
        int x; cin >> x;
        v.push_back(make_pair(x,i+1));
    }
    sort(ALL(v));

    REP(i,n) {
        cout << v[i].second << " ";
    }
    cout << endl;

    return 0;
}

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

using namespace std; 

int main()
{
	string s , t ; 
	cin>> s>> t;

	vector< vector<int> > dp( s.size()+1 , vector<int> (t.size()+1));

	for(int i=1 ; i<=s.size() ; i++ )
	{
		for( int j=1; j<=t.size() ; j++ )
		{
			if( s[i-1] == t[j-1] )
				dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
			else
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}

	// for( int i=0 ; i<= s.size() ; i++ )
	// 	{
	// 		for( int j=0 ; j<=t.size() ; j++ )
	// 			cout<<dp[i][j];
	// 		cout<<endl;
	// 	}

	string output = "";
	if( dp[s.size()][t.size()] > 0 )
	{
		int i=s.size(), j=t.size();
		while( i>0 && j >0)
		{
			if( dp[i][j] == dp[i][j-1] )
			{
				j--;
			}
			else if( dp[i][j] == dp[i-1][j] )
				i--;
			else
			{
				output = s[i-1]+output;
				i--,j--;
			}
		}
	}


	cout<<output<<endl;
	return 0;

}

Measured memory_bytes: 35584
num = int(input())
order = []
for i in range(1,num+1):
    order.append(i)
#print(order)

q_num = list(map(int,input().split()))
#print(q_num)
cnt = 0
for j in range(num):
    if order[j]!=q_num[j]:
        cnt = cnt+1
    else:
        pass
if cnt <=2:
    print("YES")
else:
    print("NO")
    

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int agency();
int main(){agency();}
int agency(){
	int n,m,a[50],b[50],c[50],d[50];
	long long int ans[50],sum[50],t;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		sum[i]=2000000000000;
	}
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<m;i++){
		cin>>c[i]>>d[i];
	}
	for(int i=0;i<n;i++){
		for(int i2=0;i2<m;i2++){
			t=abs(a[i]-c[i2])+abs(b[i]-d[i2]);
			if(t<sum[i]){
				ans[i]=i2+1;
				sum[i]=t;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

ll m = 998244353;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main() {
    ll mod = 998244353;
    ll N;
    cin >> N;
    ll vec[100000];
    map<ll,ll> mp;
    for (ll i = 0;i<N;i++) {
        cin >> vec[i];
        mp[vec[i]]++;
    }
    bool ok = true;

    if (vec[0] != 0) ok = false;

    ll ans = 1;

    for (ll i = 1;i<N;i++) {
      (ans*=mp[vec[i]-1])%=mod;
    }
    ans %= mod;
    if (ok) cout << ans << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 7296
N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]
nodes = [i for i in range(N)]
rank = [0]*N
diff_weight = [0]*N

def root(x):
    if nodes[x] == x:
        return x
    root_x = root(nodes[x])
    diff_weight[x] += diff_weight[nodes[x]]
    nodes[x] = root_x
    return nodes[x]

def weight(x):
    root(x)
    return diff_weight[x]

def unite(x,y,w):
    w += weight(x); w -= weight(y)
    x = root(x); y = root(y)
    if x == y:
        return
    if rank[x] >= rank[y]:
        nodes[y] = x
        diff_weight[y] = w
        if rank[x] == rank[y]:
            rank[x] += 1
    else:
        nodes[x] = y
        diff_weight[x] = -w

def same(x,y):
    return root(x) == root(y)

def diff(x,y):
    return weight(y) - weight(x)

ans = "Yes"

for L,R,D in info:
    L -= 1; R -= 1
    if same(L,R):
        if diff(L,R) != D:
            ans = "No"
            break
    else:
        unite(L,R,D)

print(ans)

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))

#define RAD(d) (PI * (d) / 180)
#define DEG(r) (180.0 * (r) / PI)

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

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

string &to_lower(string &s)
{
	REP(i, s.length()){
		if('A' <= s[i] && s[i] <= 'Z'){
			s[i] += 32;
		}
	}

	return s;
}

int main()
{
	double a, b, C;

	cin >> a >> b >> C;

	double S = 0.5 * a * b * sin(RAD(C));
	double c = sqrt(a*a + b*b - 2*a*b*cos(RAD(C)));
	double L = a + b + c;
	double h = b * sin(RAD(C));

	printf("%.8f\n", S);
	printf("%.8f\n", L);
	printf("%.8f\n", h);

	return 0;
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	int ans = 0;
	for(int i = 0; i < n - 1; i++) {
		ans += a[(i + 1) / 2];
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 5188
N = int(input())
flag = 1
t1 = 0
x1 = 0
y1 = 0
for i in range(N):
  t2, x2, y2 = map(int, input().split())
  dt = t2-t1
  dx = abs(x2-x1)
  dy = abs(y2-y1)
  if dt<(dx+dy) or dt %2 != (dx+dy) % 2:
    flag = 0
    break
  t1 = t2
  x1 = x2
  y1 = y2
print("Yes" if flag else "No")


Measured memory_bytes: 46184
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final long a = sc.nextLong();
			
			System.out.println(3 * a * a);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 20944
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int cnt = 0;
        for(int i=0; i<=a; i++){
            for(int j=0; j<=b; j++){
                int nd_c = (x - i*500 - j*100)/50;
                if(nd_c<=c && nd_c>=0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 23636
using System;

class Program
{
	static void Main(string[] args)
	{
		string[] input_1 = Console.ReadLine().Split(' ');
		string[] input_2 = Console.ReadLine().Split(' ');


		if(int.Parse(input_1[1]) == 0)
        {
			Console.WriteLine(int.Parse(input_1[0]));
        }
        else
        {
			int numX = int.Parse(input_1[0]);
			bool isOutput = false;
			bool isSame = false;

			for(int i = 0;i < 100; i++)
            {
				if (isOutput) break;

				isSame = false;
				foreach (string s in input_2)
                {
                    if ((numX - i) == int.Parse(s)){
						isSame = true;
                    }
                }

                if (!isSame)
                {
					Console.WriteLine(numX - i);
					isOutput = true;
				}

				if (isOutput) break;
				isSame = false;
				foreach (string s in input_2)
                {
                    if ((numX + i) == int.Parse(s)){
						isSame = true;
                    }
                }

                if (!isSame)
                {
					Console.WriteLine(numX + i);
					isOutput = true;
				}
			}
        }
	}
}

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

int main(){
  int n;
  cin >> n;
  int price = 100000;
  for(int i = 0; i < n; i++){
    price *= 1.05;
  if(price % 1000 != 0) 
    price = price -(price % 1000) + 1000;
  }
  cout << price << endl;
}

Measured memory_bytes: 1160
# 01010101か10101010かなのでどっちもやってみて比較
w, b = 0, 0
s = input()
for i, sv in enumerate(s):
    if i % 2 == 0:
        if sv == "0":
            b += 1
        else:
            w += 1
    else:
        if sv == "0":
            w += 1
        else:
            b += 1

print(min(w, b))


Measured memory_bytes: 39664
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
A = []
B = []

for _ in range(M):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

good_li = [True] * N
for i, a in enumerate(A):
    b = B[i]
    a -= 1
    b -= 1
    if H[a] < H[b]:
        good_li[a] = False
    elif H[a] == H[b]:
        good_li[a] = False
        good_li[b] = False
    else:
        good_li[b] = False

print(len(list(filter(lambda x: x, good_li))))


Measured memory_bytes: 22984
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main() {
	string s;
	int ans = 0;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - i - 1]) {
			ans++;
		}
	}
	cout << ans/2 << endl;
	return 0;
}

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

def main():
    N, M = [int(x) for x in input().split()]
    ab = []
    for _ in range(N):
        ab.append([int(x) for x in input().split()])
    ab.sort()

    ans = 0
    for a, b in ab:
        if b > M:
            ans += a * M
            break
        else:
            ans += a * b
            M -= b

    print(ans)


    


if __name__ == '__main__':
    main()



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

int main(){
	vector<int> vec{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int N;
  cin >> N;
  cout << vec.at(N-1) << endl;
}

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

long long power(int x, unsigned long long y) {
	if (y == 0){
		return 1;
	}
	else if (y%2 == 0){
		return power(x, y/2)*power(x, y/2);
	} else {
		return x*power(x, y/2)*power(x, y/2);
	}
}
int main() 
{ 
  long long h;
	cin >> h;
	long long l = log(h) / log(2);
	cout << power(2, l + 1) - 1;
} 


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

int main() {
    int five = 0, seven = 0;

    for (int i = 0; i < 3; i++) {
        int a;
        cin >> a;
        if (a == 5) {
            five++;
        } else if (a == 7) {
            seven++;
        }
    }
    if (five == 2 && seven == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int i,j,k,H,W;
    while(1){
    cin >>H >>W;
    if(H==0 && W==0) break;
    for (i=0; i<H; i++){
        
        
        for (j=0;j<W;j++){
            
            cout<<"#";
        }
        
        cout<<endl;
       
        
    }
    cout<<endl;
    }
    
    
    return 0;
    
}


Measured memory_bytes: 3084
import sys
write = sys.stdout.write

while True:
    entry = map(int, raw_input().split())
    H = entry[0]
    W = entry[1]
    if H == 0 and W == 0:
        break
    
    for j in range(W):
    	write("#")
    print ""
    for j in range(H - 2):
        write("#")
    	for k in range(W - 2):
    		write(".")
    	write("#")
    	print ""
    for j in range(W):
    	write("#")
    print ""
    print ""

Measured memory_bytes: 6456