akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	private static final int LEFT = 0;
	private static final int RIGHT = 1;
	private static final int EndOfDirection = 2;
	
	private static ArrayList<Integer> a = new ArrayList<Integer>(10);
	private static ArrayList<Integer> left = new ArrayList<Integer>(10);
	private static ArrayList<Integer> right = new ArrayList<Integer>(10);
	private static ArrayList<String> result = new ArrayList<String>();
	private static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int numDataSet = sc.nextInt();
		for(int i = 0; i < numDataSet; i++){
			pushBallsToA();
			if(popBallsAscendingOrder()){
				result.add("YES");
			}
			else{
				result.add("NO");
			}
		}
		
		for(int i = 0; i < result.size(); i++){
			System.out.println(result.get(i));
		}
	}
	
	public static void setA(ArrayList<Integer> a) {
		Main.a = a;
	}
	
	public static void pushBallsToA(){
		a.clear();
		for(int i = 0; i < 10; i++){
			a.add(sc.nextInt());
		}
	}
	
	public static boolean popBallsAscendingOrder(){
		left.clear();
		right.clear();
		for(int directionBall1 = LEFT; directionBall1 < EndOfDirection; directionBall1++){
			for(int directionBall2 = LEFT; directionBall2 < EndOfDirection; directionBall2++){
				for(int directionBall3 = LEFT; directionBall3 < EndOfDirection; directionBall3++){
					for(int directionBall4 = LEFT; directionBall4 < EndOfDirection; directionBall4++){
						for(int directionBall5 = LEFT; directionBall5 < EndOfDirection; directionBall5++){
							for(int directionBall6 = LEFT; directionBall6 < EndOfDirection; directionBall6++){
								for(int directionBall7 = LEFT; directionBall7 < EndOfDirection; directionBall7++){
									for(int directionBall8 = LEFT; directionBall8 < EndOfDirection; directionBall8++){
										for(int directionBall9 = LEFT; directionBall9 < EndOfDirection; directionBall9++){
											for(int directionBall10 = LEFT; directionBall10 < EndOfDirection; directionBall10++){
												popBall(directionBall1, 0);
												popBall(directionBall2, 1);
												popBall(directionBall3, 2);
												popBall(directionBall4, 3);
												popBall(directionBall5, 4);
												popBall(directionBall6, 5);
												popBall(directionBall7, 6);
												popBall(directionBall8, 7);
												popBall(directionBall9, 8);
												popBall(directionBall10, 9);
												if(isAscendingOrder(left) && isAscendingOrder(right)){
													return true;
												}
												left.clear();
												right.clear();
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}		
		return false;
	}
	
	private static void popBall(int direction, int indexBall){
		switch(direction){
		case LEFT:
			left.add(a.get(indexBall));
			break;
		case RIGHT:
			right.add(a.get(indexBall));
			break;
		}
	}
	
	public static boolean isAscendingOrder(ArrayList<Integer> list){		
		for(int i = 0; i < list.size() - 1; i++){
			if(list.get(i) > list.get(i + 1)){
				return false;
			}
		}
		return true;
	}
}

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string S,T,U;
    int A,B;
    cin>>S>>T>>A>>B>>U;
    if(S==U) A--;
    else if(T==U) B--;
    cout<<A<<' '<<B<<'\n';
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int alice = 0, bob = 0;
    for (int i = 0; i < n; i += 2)
        alice += a[i];
    for (int i = 1; i < n; i += 2)
        bob += a[i];
    cout << alice - bob << endl;
    return 0;
}

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

using namespace std;

int main() {
  int N;
  int ans = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int in = 0;
    
    cin >> in;
    
    while (in % 2 == 0 && in != 0) {
      in /= 2;
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

// 座標圧縮 vector a の要素を圧縮して d に変換
struct Compress{
    vector<int> d, unzip;
    map<int, int> zip;        
    Compress(vector<int> a){
        vector<int> b = a;
        d.resize(a.size());
        sort(b.begin(), b.end());
        b.erase(unique(b.begin(), b.end()), b.end());
        unzip.resize(b.size());
        for(int i = 0; i < b.size(); i++){
            zip[b[i]] = i;
            unzip[i] = b[i];
        }
        for(int i = 0; i < a.size(); i++){
            d[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        }
    }
};

struct CumulativeSum2D{
    vector<vector<int> > data;
    CumulativeSum2D(int H, int W) : data(H + 1, vector<int>(W + 1, 0)) {}
    //要素(x,y)に値zを加える
    void add(int x, int y, int z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }
    void build(){
        for(int i = 1; i < data.size(); i++) {
        for(int j = 1; j < data[i].size(); j++) {
            data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }
    //左上[sy, sx], 右下(gx, gy)の矩形内の和を求める(半開区間) (0-index)
    int query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

/*
verified
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2426&lang=jp
*/

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    x.push_back(-MAX);
    y.push_back(-MAX);
    x.push_back(MAX);
    y.push_back(MAX);
    Compress cx(x), cy(y);
    CumulativeSum2D cs(n + 2, n + 2);
    for(int i = 0; i < x.size(); i++){
        if(i < n) cs.add(cx.d[i], cy.d[i], 1);
    }
    cs.build();
    for(int i = 0; i < m; i++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        x1 = lower_bound(cx.unzip.begin(), cx.unzip.end(), x1) - cx.unzip.begin();
        y1 = lower_bound(cy.unzip.begin(), cy.unzip.end(), y1) - cy.unzip.begin();
        x2 = upper_bound(cx.unzip.begin(), cx.unzip.end(), x2) - cx.unzip.begin() - 1;
        y2 = upper_bound(cy.unzip.begin(), cy.unzip.end(), y2) - cy.unzip.begin() - 1;
        if(x1 > x2 || y1 > y2){
            cout << 0 << endl;
        }else{
            cout << cs.query(x1, y1, x2 + 1, y2 + 1) << endl;
        }
    }
}


Measured memory_bytes: 101516
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


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

  vector<long long> weight(N),value(N);
  long long sum = 0;
  for(int i = 0;i < N;i++) {
    cin >> weight.at(i) >> value.at(i);
    sum += value.at(i);
  }  

  long long dp[110][sum + 1];

  for(int i = 0;i < N;i++) {
    for(int j = 0;j <= sum;j++) {
      dp[i][j] = 1LL<<60;
    }
  }

  dp[0][0] = 0;

  for(int i = 0;i < N;i++) {
    for(int j = 0;j <= sum;j++) {
      if(j >= value[i]) {
         dp[i+1][j] = min(dp[i][j],dp[i][j - value[i]] + weight[i]);
      }else{
         dp[i+1][j] = dp[i][j];
      }
    }
  }

  long long ans = 0;
  for(long long i = 0;i <= sum;i++) {
    if(dp[N][i] <= W) ans = max(ans,i);
  }

  cout << ans << endl;

}

Measured memory_bytes: 80384
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M = LI()
A = LI()

A.sort(reverse=True)
if A[M - 1] < (sum(A) / (4 * M)):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 5688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

bool used[10];
int d[10];

void func(int n, int c) {
    if (c == n) {
        for (int i = 0; i < n; i++) {
            cout << (char)('a' + d[i]);
        }
        cout << endl;
        return;
    }

    for (int i = 0; i < n; i++) {
        if (used[i]) {
            d[c] = i;
            func(n, c + 1);
        } else {
            d[c] = i;
            used[i] = true;
            func(n, c + 1);
            used[i] = false;
            break;
        }
    }
    return;
}

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

    func(n, 0);
    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
int cross(int x0, int y0, int x1, int y1) { return x0*y1-x1*y0; }

struct P {
    int i, j, p;
    P(int i, int j, int p) : i(i), j(j), p(p) {}
};
bool operator<(const P& l, const P& r) {
    const int c = cross(l.i, l.j, r.i, r.j);
    return c!=0 ? c<0 : l.p<r.p;
}

int H, W;
char f[1024][1024];

int kount(int i, int j) {
    int c = 0;
    rep(a, 2) rep(b, 2) if(f[i+a][j+b]=='#') c++;
    return c;
}

int main() {
    memset(f, '.', sizeof(f));
    scanf("%d%d", &H, &W);
    rep(i, H) rep(j, W) scanf(" %c", f[H-i]+j+1);
    vector<P> v;
    rep(i, H+1) rep(j, W+1) if(i || j) {
        const int c = kount(i, j);
        if(c==1) {
            if(f[i+1][j]=='#') v.push_back(P(i, j, 1));
            if(f[i][j+1]=='#') v.push_back(P(i, j, -1));
        }
        else if(c==2) {
            if(f[i+1][j]=='#' && f[i][j+1]=='#') {
                v.push_back(P(i, j, 1));
                v.push_back(P(i, j, -1));
            }
        }
        else if(c==3) {
            if(f[i+1][j]=='.') v.push_back(P(i, j, 1));
            if(f[i][j+1]=='.') v.push_back(P(i, j, -1));
        }
    }
    sort(v.begin(), v.end());
    int cur = 1;
    int ans = cur;
    rep(i, v.size()) {
        cur += v[i].p;
        ans = max(ans, cur);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2820
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10**9 + 1

def precompute(N, M, data):
    data = data.reshape(-1, 3)
    A, B, C = data[:N].T
    D, E, F = data[N:].T
    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B)
    D = np.searchsorted(X, D)
    C = np.searchsorted(Y, C)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F)
    return A, B, C, D, E, F, X, Y

@njit('(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8,i8)', cache=True)
def set_ng(A, B, C, D, E, F, H, W):
    ng = np.zeros((H * W, 4), np.bool_)

    for i in range(len(A)):
        for x in range(A[i], B[i]):
            v = x * W + C[i]
            ng[v][1] = 1
            ng[v - 1][0] = 1

    for i in range(len(D)):
        for y in range(E[i], F[i]):
            v = D[i] * W + y
            ng[v][3] = 1
            ng[v - W][2] = 1
    return ng

@njit('(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])', cache=True)
def solve(A, B, C, D, E, F, X, Y):
    H, W = len(X), len(Y)
    N = H * W
    DX = X[1:] - X[:-1]
    DY = Y[1:] - Y[:-1]
    ng = set_ng(A, B, C, D, E, F, H, W)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    move = (1, -1, W, -W)
    while p:
        v = pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret

N, M = map(int, readline().split())
data = np.int64(read().split())

x = solve(*precompute(N, M, data))
if x == 0:
    print('INF')
else:
    print(x)

Measured memory_bytes: 165764
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int[] p = na(n);
    Arrays.sort(p);
    p[n - 1] /= 2;
    System.out.println(Arrays.stream(p).sum());
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main(){
	int n;
	cin>>n;
	while(n--){
		int y,m,d,cnt=0;
		cin>>y>>m>>d;
		if(y % 3 == 0) {
				cnt += (21 - d);
		}
		else {
				cnt += ((m % 2 == 0 ? 20 : 21) - d);
		}
		for(int i = m + 1; i <= 10; i++) {
				if(y % 3 == 0) {
						cnt += 20;
				}
				else{
						if(i % 2 == 0) {
								cnt += 19;
						}
						else {
								cnt += 20;
						}
				}

		}
		for(int i = y + 1; i <= 999; i++) {
				if(i % 3 == 0) {
						cnt += 20 * 10;
				}
				else {
						cnt += 20 * 5 + 19 * 5;
				}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main (){
	int H,W,N,total=0,oper=0;
	scanf("%d %d %d", &H, &W, &N);
	if (H<W)
	{
		for (int i=0 ; i<H ; i++){
			if (total<N){
				total+=W;
				oper++;}
			else if (total>N){
				break;
			}
		}
	}
	else
	{
		for (int i=0 ; i<W ; i++){
			if (total<N){
				total+=H;
				oper++;}
			else if (total>N){
				break;
			}
		}
	}
	printf("%d", oper);
return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int H,W;
vector<vector<int>> A;
void input(){
    fast_io();
    cin >> H >> W;
    A.assign(H,vector<int>(W,0));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> A[i][j];
        }
        
    }
    
}

int solve(){
    vector<pair<pii,pii>> ans;
    for (int i = 0; i < H; i++)
    {
        if(i%2==0){
            for (int j = 0; j < W; j++)
            {
                if(A[i][j]%2==0) continue;
                if(j!=W-1){
                    A[i][j]--;
                    A[i][j+1]++;
                    ans.emplace_back(make_pair(i,j),make_pair(i,j+1));
                }
                else if(i!=H-1){
                    A[i][j]--;
                    A[i+1][j]++;
                    ans.emplace_back(make_pair(i,j),make_pair(i+1,j));
                }
            }
        }
        else
        {
            for (int j = W-1; j >= 0; j--)
            {
                if(A[i][j]%2==0) continue;
                if(j!=0){
                    A[i][j]--;
                    A[i][j-1]++;
                    ans.emplace_back(make_pair(i,j),make_pair(i,j-1));
                }
                else if(i!=H-1){
                    A[i][j]--;
                    A[i+1][j]++;
                    ans.emplace_back(make_pair(i,j),make_pair(i+1,j));
                }
            }
        }
    }
    cout << ans.size() << endl;
    for(auto a:ans){
        printf("%d %d %d %d\n",a.first.first+1,a.first.second+1,a.second.first+1,a.second.second+1);
    }
    
    return 0;
}   

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

Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
int k;
cin>>n>>k;
int a[10]={0};
for(int i=0;i<k;i++)
{
int x;cin>>x;a[x]=1;
}
long long ans=n;
while(1)
{
long long v=ans;
int y=1;
while(v>0)
{
if(a[v%10])
{y=0;break;}
v/=10;
}
if(y)
break;
ans++;
}
cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;

int main() {

  int N, K, Q;
  cin >> N >> K >> Q;

  int s = K-Q;

  vector<int> S(N, s);  // 先に持ち点からラウンド数減点した値で score を初期化

  vector<int> A(Q);  // who answerd
  rep(i, Q) cin >> A[i];

  // increase score who answered
  rep(i, Q) {
	S[A[i]-1]++;
  }

  rep(i, N) {
	if (S[i] > 0) cout << "Yes" << endl;
	else cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        String string = sc.next();
        boolean n = string.contains("N");
        boolean w = string.contains("W");
        boolean s = string.contains("S");
        boolean e = string.contains("E");

        System.out.println(n == s && e == w ? "Yes" : "No");
    }
}

Measured memory_bytes: 23636
#include<stdio.h>
int a[5][5];
int row[5],col[5];
int main()
{
    int i,j;
    int sum = 0;
    for(i=1;i<=3;i++)
        for(j=1;j<=3;j++){
            scanf("%d",&a[i][j]);
            row[i]+=a[i][j];
            col[j]+=a[i][j];
        }
    sum = row[1] + row[2] + row[3];
    if(sum%3)return printf("No")*0;
    int a1a2a3b1b2b3 = sum/3;
    int a1_a2 = row[1] - row[2];
    int a1_a3 = row[1] - row[3];
    int b1_b2 = col[1] - col[2];
    int b1_b3 = col[1] - col[3];
    if(a1_a2%3 + a1_a3%3 + b1_b2%3 + b1_b3%3)return printf("No")*0;
    printf("Yes");
}

Measured memory_bytes: 128
N = int(input())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
ABs = sorted(ABs, key=lambda x: x[1])

elapsed_time = 0
for AB in ABs:
    A = AB[0]
    B = AB[1]
    if elapsed_time + A > B:
        print('No')
        exit()
    elapsed_time += A

print('Yes')

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

int main() {
	string s;
	cin >> s;
	if (s[0] == '1') cout << 9; else cout << 1;
	if (s[1] == '1') cout << 9; else cout << 1;
	if (s[2] == '1') cout << 9; else cout << 1;
	cout << endl;
	return 0;
}

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

#define pb push_back
using ll = long long;

const int mx = 1e5+5;
const int inf = 1e9+9;
const int mod = 1e9+7;

ll x, y;
ll a, b, c;
ll p[mx], q[mx], r[mx];

ll min3(ll u, ll v, ll w){return min(u, min(v,w));}

int main(int argc, const char** argv) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> x >> y;
    cin >> a >> b >> c;
    
    ll val;
    vector< pair<ll, int> > v;
    
    vector<ll> tmp;
    for(int i=0; i<a; i++){
        cin >> val;
        tmp.pb(val);
    }
    sort(begin(tmp), end(tmp), greater<ll>());
    for(int i=0; i<x; i++)
        v.push_back({tmp[i], 0});

    tmp.clear();
    for(int i=0; i<b; i++){
        cin >> val;
        tmp.pb(val);
    }
    sort(begin(tmp), end(tmp), greater<ll>());
    for(int i=0; i<y; i++)
        v.push_back({tmp[i], 0});

    tmp.clear();
    for(int i=0; i<c; i++){
        cin >> val;
        tmp.pb(val);
    }

    sort(begin(v), end(v));
    reverse(begin(v), end(v));

    ll sum = 0;
    sort(begin(tmp), end(tmp), greater<ll>());
    for(int i=0; i<c; i++){
        val = tmp[i];
        if(v.size() && v.back().first<val)
            sum += val, v.pop_back();
        else break;
    }

    while(v.size())
        sum += v.back().first, v.pop_back();
    cout << sum << '\n';
    
    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int plus = n, sum = 0;
    while(plus){
        sum += plus%10;
        plus /= 10;
    }
    
    cout << (n%sum?"No":"Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
long long a,b;
int main(){
	scanf("%lld%lld",&a,&b);
	if(a==0)a=1;
	else if(a==1)a=100;
	else if(a==2)a=10000;
	if(b!=100)printf("%lld",a*b);
	else printf("%lld",a*b+a);
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int a[200000];
int main()
{
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0) ans+=i;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
    ll n, k;
    string name;
    cin >> n;
    k = n;
    while(k != 0) {
        name += 'a' + (k-1)%26;
        k = (k-1) / 26;
    }
    reverse(name.begin(), name.end());
    cout << name << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main(){
	int m, f, r, score;
	for(;;){
		cin >> m >> f >> r;
		if(m != -1 || f != -1 || r != -1){
			score = m + f;
			if(m == -1 || f == -1){
				cout << 'F' << endl;
				continue;
			}
			if(score >= 80){
				cout << 'A' << endl;
			}else if(score >= 65){
				cout << 'B' << endl;
			}else if(score >= 50){
				cout << 'C' << endl;
			}else if(score >= 30){
				if(r >= 50){
					cout << 'C' << endl;
				}else{
					cout << 'D' << endl;
				}
			}else{
				cout << 'F' << endl;
			}
			continue;
		}
		return 0;
	}
}

Measured memory_bytes: 3016
#include<stdio.h>
#define N 100
//#include<algorithm>
//using namespace std;

int main() {
  int n, p[N+1], m[N+1][N+1],i,l,j,k;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for( i=1;i<=n;i++) m[i][i]=0;
  for( l=2;l<=n;l++) {
    for( i=1;i<=n-l+1;i++){
       j=i+l-1;
      m[i][j]=(1<<21);
      for( k=i;k<=j-1;k++) {
	if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
	  m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	else m[i][j]=m[i][j];
      }
    }
  }

  printf("%d",m[1][n]);
  printf("\n");

  return 0;
}



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

using namespace std;
using ll = long long int;

#define REP(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))

int a,b,c,x,y;


int main()
{
    cin >> a >> b >> c >> x >>y;
    int p[2] = {a,b};
    bool i = x<y;
    int ans = 0;
    if(a+b < 2*c){
        cout << a*x+b*y << endl;
        return 0;
    }else{
        ans = min(x,y)*2*c;
        int k = abs(x-y);
        ans += min(p[i]*k,2*c*k);
        cout << ans << endl;
        return 0 ;
    }
}

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

#define ll long long int
void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
const ll maxk = 1e5 + 10;
ll dp[maxk];
bool go(ll n,ll k,vector<ll> &v)
{
	
	if(dp[k]!=-1)
	return dp[k];
	if(k==0)
	return dp[k]=0;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		if(k>=v[i])
			{
			
				if(	go(n,k-v[i],v)==0)
				{
					ans=1;
					break;
				}
			}
			else
			continue;
	}
	return dp[k]=ans;
}
int main()
{
	fast();
	ll n,k;
	cin>>n>>k;
	vector<ll> v(n);
	for(auto &i:v)
	cin>>i;
	memset(dp,-1,sizeof(dp));
	// dp[0]=2;
	if(go(n,k,v))
	cout<<"First\n";
	else
	cout<<"Second\n";
}

Measured memory_bytes: 5760
//ツ環ョツ青ャ
//0039
#include<stdio.h>
#include<string.h>
int exc(char c){
	switch(c){
	case 'I':
		return 1;
	case 'V':
		return 5;
	case 'X':
		return 10;
	case 'L':
		return 50;
	case 'C':
		return 100;
	case 'D':
		return 500;
	case 'M':
		return 1000;
	}
}
int main(){
	char buf[103];
	int h,i,j;
	int d[103],d2[103];
	int sum=0;
	for(;scanf("%s",buf)!=EOF;){
		sum=0;h=strlen(buf);
		for(i=0;i<h;i++)d[i]=exc(buf[i]);
		for(i=0,j=0;i<h;i++){
			if(i==0)d2[j++]=d[i];
			else{
				if(d[i]>d[i-1]){
					if(j>0)d2[j-1]-=d[i-1];
					d2[j++]=d[i]-d[i-1];
				}
				else d2[j++]=d[i];
			}
		}
		for(i=0;i<j;i++)sum+=d2[i];
		printf("%d\n",sum);
	}
	return 0;
}

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b) swap(a, b);
    if((b - a) % 2 == 0) {
        cout << (b - a) / 2 << endl;
    } else {
        cout << min(a-1+1+(b-a-1)/2, n-b+1+(b-a-1)/2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	X := ReadInt()
	ans := 1
	for b := 2; b*b <= X; b++ {
		x := b * b
		for x*b <= X {
			x *= b
		}
		ans = Max(ans, x)
	}
	fmt.Println(ans)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


Measured memory_bytes: 1840
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main() {
	int N, M, X;
	int left = 0, right = 0;
	cin >> N >> M >> X;
	vector<int> A(M);
	for(int i = 0; i < M; ++i){
		cin >> A[i];
		A[i] < X ? left++ : right++;
	}

	cout << min(left, right) << endl;

	return 0;
}

Measured memory_bytes: 256
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
typedef long double ld;
void yoinks(){
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
int main(){
    yoinks();
    char x;
    cin>>x;
    cout<<(char)(x+1);







return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


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

namespace ConsoleApp9 {
    class Program {
        static void Main(string[] args) {
            var X = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            int N = X[0];
            int M = X[1];

            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();

            A.Sort();
            A.Reverse();

            while(M > 0) {
                A[0] /= 2;
                M--;
                if (M == 0) {
                    goto warp;
                }

                for (int i = 1; i < N; i++) {
                    if (A[0] > A[i]) {
                        A.Sort();
                        A.Reverse();
                        break;
                    } else {
                        A[i] /= 2;
                        M--;
                        if (M == 0) {
                            goto warp;
                        }
                    }
                }
            }

            warp:

            //Console.WriteLine(string.Join(" ", A));

            Console.WriteLine(A.Select(d => (long)d).Sum());
        }
    }
}


Measured memory_bytes: 30044
def vacation(n, nums):
    dp = [nums[0]]
    for i in range(1, n):
        dp.append([
            nums[i][0] + max(dp[-1][1], dp[-1][2]),
            nums[i][1] + max(dp[-1][0], dp[-1][2]),
            nums[i][2] + max(dp[-1][0], dp[-1][1])
        ])
    return max(dp[-1])


n = int(input())
nums = []
for _ in range(n):
    row = [int(i) for i in input().split()]
    nums.append(row)

ans = vacation(n, nums)
print(ans)



Measured memory_bytes: 44148
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		var line0 = Console.ReadLine().Split(new char[]{' '}).Select(c => Int32.Parse(c)).ToArray();
		for(var i = 0; i < line0.Count(); i++)
		{
			if (line0[i] == 0)
			{
				Console.WriteLine($"{i + 1}");
			}
		}
	}
}


Measured memory_bytes: 19108
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
ll dd[750];
ll d[601000];
 
int main(){
  ll n,q;
  cin>>n>>q;
  vector<pair<ll,pair<ll,ll> > > vp;
  set<ll> se;
  rep(i,0,n){
    ll a,b,c;
    cin>>a>>b>>c;
    vp.pb(mp(a-c,mp(1,c)));
    vp.pb(mp(b-c,mp(-1,c)));
    se.insert(a-c);
    se.insert(b-c);
  }
  sort(all(vp));
  vector<ll> v;
  rep(i,0,q){
    ll a;
    cin>>a;
    v.pb(a);
    se.insert(a);
  }
  vector<ll> v1(all(se));
  set<ll> se1;
  ll index = 0;
  ll index2 = 0;
  rep(i,0,v1.sz){
    while(vp[index2].fi==v1[i]){
      ll b = vp[index2].se.fi;
      ll c = vp[index2].se.se;
      index2++;
      if(b==1){
        se1.insert(c);
      }
      else{
        se1.erase(c);
      }
    }
    while(v[index]==v1[i]){
      index++;
      if(se1.sz==0){
        cout << -1 << endl;
      }
      else{
        set<ll>::iterator itr = se1.begin();
        cout << (*itr) << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 55720
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    string s1, s2;
    cin >> s1 >> s2;
    R_YESNO(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]);
    return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();

            Set<Integer> remindSet = new HashSet<>();

            boolean yes = false;
            int x = A;

            while (true) {
                int rem = x % B;
                if (rem == C) {
                    yes = true;
                    break;
                }
                if (remindSet.contains(rem)) {
                    break;
                }
                remindSet.add(rem);
                x += A;
            }

            if (yes) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}


Measured memory_bytes: 23764
N = int(input())
t = []
for i in range(N):
    Xi, Li = map(int,input().split())
    t.append((Xi - Li, Xi + Li))
t.sort(key = lambda x:x[1])
# print(t)

ans = 0; x = -10**9
for i in range(N):
    if x <= t[i][0]:
        ans += 1
        x = t[i][1]
        # print(t[i]) #DB

print(ans)

Measured memory_bytes: 18256
using System;
					
public class Program
{
	public static void Main()
	{
		//ulong N = ulong.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split(' ');
		//int[] arr = new int[1000000];
		ulong A = ulong.Parse(str[0]);
		ulong B = ulong.Parse(str[1]);
			
		/*
		for(ulong i=0; i<N; i++){
			if(arr[ulong.Parse(str[i])] == 0){
				cnt++;
				arr[ulong.Parse(str[i])]=1;
			}else{
				cnt2++;
			}
		}
		*/
		
		Console.WriteLine(A*B);
		
	}
}
 
public class Sol
{
	public double Solve(ulong A, ulong B, ulong x)
	{
		double ans;
		double tmp1 = (A*x)/B;
		double tmp2 = x/B;
		
		tmp1 = Math.Truncate(tmp1);
		tmp2 = Math.Truncate(tmp2);
		
		ans = tmp1 - (A*tmp2);
		
		return ans;
	}
}

Measured memory_bytes: 17784
/* winners never quit and quitters never win.
      #swap                                 */
      
#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;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt();
    vc<ll> v(n);
    generate(all(v),nxt);
    sort(all(v),greater<ll>());
    ll ans=v[0];
    ll count=1;
    rep(a,1,n)
    {
        ll left=n-1-count;
        ll temp=min(left,2*1LL);
        ans+=temp*v[a];
        count+=temp;
    }
    cout<<ans<<endl;
	printclock;
	return 0;
}

Measured memory_bytes: 4772
import java.util.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main{
	static FastScanner fs=new FastScanner();
	static PrintWriter pw=new PrintWriter(System.out);
	static void Solve(long the){
		int n=fs.nextInt();
		int[] a=new int[n+1];
		int ans=0;
		for(int i=1;i<=n;i++){
			a[i]=fs.nextInt();
			if(i%2==1){
				if(a[i]%2==1){
					ans++;
				}
			}
		}
		pw.print(ans);



		
	}
	public static void main(String args[]){
		long t=1;
		// t=fs.nextInt();
		for(long i=1;i<=t;i++){
			Solve(i);
		}
		pw.close();
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next(){
			while((!st.hasMoreTokens()) || (st==null)){
				try{
					st=new StringTokenizer(br.readLine());
				}
				catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		int[] readArray(int n){
			int[] a=new int[n];
			for(int i=0;i<n;i++)	a[i]=nextInt();
			return a;
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String nextLine(){
			String str="";
			try{
				str=br.readLine();
			}
			catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 32844
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    REP(i,h){
        REP(j,w){
            cout<<((i<b) == (j<a));
        }
        cout<<endl;
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  bool can = false;
  ll x;
  cin >> x;
  rep(i,9){
    rep(j,9){
      if((i+1) * (j+1) == x){
        can = true;
      }
    }
  }
  if(can){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define PUTS(x) cout << (x) << endl;
#define PB push_back

struct Node {
    vector<int> adjacents;
    int len = -1;
};

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    auto nodes = vector<Node>(n);
    rep(i, n) {
        vector<int> adjacents;
        if (i > 0) {
            adjacents.PB(i - 1);
        }
        if (i < n - 1) {
            adjacents.PB(i + 1);
        }
        if (i == x) {
            adjacents.PB(y);
        }
        if (i == y) {
            adjacents.PB(x);
        }
        nodes[i].adjacents = adjacents;
    }

    auto ans = vector<int>(n);

    rep(i, n) {
        auto g = nodes;
        g[i].len = 0;
        auto q = queue<int>();
        q.push(i);
        while (q.size() > 0) {
            auto targetIndex = q.front();
            q.pop();
            auto &target = g[targetIndex];
            for (auto nextIndex : target.adjacents) {
                auto &next = g[nextIndex];
                if (next.len >= 0) continue;
                auto nextLen = target.len + 1;
                ans[nextLen]++;
                next.len = nextLen;
                q.push(nextIndex);
            }
        }
    }

    reps(i, n - 1) {
        PUTS(ans[i] / 2);
    }
}


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

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	map<int, int> count;
    for(int i = 1; i < n; i++){
    	count[i] = 0;
    }
    for(int i = 1; i < n; i++){
    	for(int j = i+1; j <= n; j++){
			count[min(abs(j-i),abs(x-i)+1+abs(y-j))]++;
        }
    }
    for(auto x: count)
    	cout<<x.second<<endl;
    return 0;
}

Measured memory_bytes: 384
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n;

int main() {
	cin >> n;
	REP(q, n) {
		int k, p;
		cin >> k >> p;
		cout << (k%p == 0 ? p : k%p) << endl;
	}
}


Measured memory_bytes: 3088