akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
	
	static PrintWriter out;
	
	final static int INF = (int) 1e9;
	final static int MOD = (int) 1e9 + 7;
	final static long LINF = (long) 1e18;
	final static double PI = (double) Math.acos(-1.0);
	final static double EPS = (double) 1e-9;
	
	void solve() {
		int n = Input.nextInt();
		final int[] x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = Input.nextInt() - 1;
		}
		TreeSet<Integer> st = new TreeSet<>();
		for (int i = 0; i < n * n; i++) {
			st.add(i);
		}
		int[] res = new int[n * n];
		for (int i = 0; i < n; i++) {
			res[x[i]] = i + 1;
			st.remove(x[i]);
		}
		ArrayList<Integer> v = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			v.add(i);
		}
		Collections.sort(v, new Comparator<Integer>() {
			public int compare(Integer i, Integer j) {
				return Integer.compare(x[i], x[j]);
			}
		});
		for (int j = 0; j < n; j++) {
			int i = v.get(j);
			int cnt = i;
			while (cnt > 0) {
				Integer k = st.first();
				if (k == null || k >= x[i]) {
					out.println("No");
					return;
				}
				res[k] = i + 1;
				cnt--;
				st.remove(k);
			}
		}
		Collections.sort(v, new Comparator<Integer>() {
			public int compare(Integer i, Integer j) {
				return Integer.compare(x[j], x[i]);
			}
		});
		for (int j = 0; j < n; j++) {
			int i = v.get(j);
			int cnt = n - i - 1;
			while (cnt > 0) {
				Integer k = st.last();
				if (k == null || k <= x[i]) {
					out.println("No");
					return;
				}
				res[k] = i + 1;
				cnt--;
				st.remove(k);
			}
		}
		out.println("Yes");
		for (int i = 0; i < n * n; i++) {
			out.printf("%d%c", res[i], " \n".charAt(i == n * n - 1 ? 1 : 0));
		}
	}
	
	public static void main(String[] args) {
		try {
			out = new PrintWriter(System.out);
			//out = new PrintWriter(new FileWriter("a.out"));
		}
		catch (Exception ex) {
		}
		long stime = System.currentTimeMillis();
		Main practice = new Main();
		practice.solve();
		if (System.getProperty("_LOCAL_") != null) {
			out.println("\nTime elapsed: " + (System.currentTimeMillis() - stime) + "ms");
		}
		out.close();
	}
	
	static class Input {
		static StringTokenizer token = null;
		static BufferedReader in;
		static {
			try {
				if (System.getProperty("_LOCAL_") != null) {
					//in = new BufferedReader(new FileReader("in.txt"));
					in = new BufferedReader(new InputStreamReader(System.in));
				}
				else {
					in = new BufferedReader(new InputStreamReader(System.in));
				}
			}
			catch (Exception ex) {
			}
		}
		static int nextInt() {
			return Integer.parseInt(nextString());
		}
		static long nextLong() {
			return Long.parseLong(nextString());
		}
		static double nextDouble() {
			return Double.parseDouble(nextString());
		}
		static String nextString() {
			try {
				while (token == null || !token.hasMoreTokens()) {
					token = new StringTokenizer(in.readLine());
				}
			}
			catch (IOException e) {
			}
			return token.nextToken();
		}
	}
}

Measured memory_bytes: 108544
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int main()
{
	int n,t,max=0;
	cin >> n;
	t=n;
	while(n--){
		int x;
		scanf("%d",&x);
		a[x]++;
		a[x+1]++;
		a[x-1]++;
		for(int i=x-1;i<=x+1;i++){
			if(a[i]>max)
				max=a[i];
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {

	var S string
  	var N int
	fmt.Scanf("%s\n%d\n", &S,&N)
	rev := false
	l := make([]rune, 200000)
	r := make([]rune, 300000)
	
	rs := []rune(S)
	for idx, s := range rs {
		r[idx] = s
	}

  ll, rl := 0, len(S)
	for i := 0; i < N; i ++ {
		var T int
		fmt.Scanf("%d", &T)
		if T == 1 {
			rev = !rev
			continue
		}
		var F int
		var C string
		fmt.Scanf("%d %s\n", &F, &C)
		if !rev {
			if F == 1 {
				l[ll] = []rune(C)[0]
				ll += 1
			} else {
				r[rl] = []rune(C)[0]
				rl ++
			}
		} else {
			if F == 1 {
				r[rl] = []rune(C)[0]
				rl += 1
			} else {
				l[ll] = []rune(C)[0]
				ll += 1
			}
		}
	}
  l = l[:ll]
  r = r[:rl]
  if rev {
    l, r = r, l
  }
  fmt.Println(string(append(reverse(l), r...)))
}

func reverse(rs []rune) []rune {
  s := string(rs)
    for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
        rs[i], rs[j] = rs[j], rs[i]
    }
    return rs
}


Measured memory_bytes: 7168
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M = mi()
Q = li2(M)
#Q = sorted(Q, key=lambda x:x[1])

l = [N]*N
for i in range(M):
    ind = max(0, Q[i][0]-1)
    l[ind] = min(Q[i][1]-1, l[ind])

for i in reversed(range(N-1)):
    l[i] = min(l[i], l[i+1])

cnt = 0
i = 0
#print(l)
while True:
    i = l[i]
    cnt += 1
    if l[i] == N:
        break

print(cnt)


Measured memory_bytes: 88304
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

/*
void dfs(bool pom, int sum, int cnt){
    if(pom) sum += b[cnt];
    else sum -= b[cnt];
    cnt++;
    if(cnt < 4){
        dfs(true, sum, cnt);
        dfs(false, sum, cnt);
    }
}
*/

int main(){
  int a;
  cin >> a;
  int b[5];
  rep(i, 4){
      b[3-i] = a%10;
      a /= 10;
  }
  if(b[0]+b[1]+b[2]+b[3] == 7){
      printf("%d+%d+%d+%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
  if(b[0]+b[1]+b[2]-b[3] == 7){
      printf("%d+%d+%d-%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
  if(b[0]+b[1]-b[2]+b[3] == 7){
      printf("%d+%d-%d+%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
  if(b[0]+b[1]-b[2]-b[3] == 7){
      printf("%d+%d-%d-%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
  if(b[0]-b[1]+b[2]+b[3] == 7){
      printf("%d-%d+%d+%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
  if(b[0]-b[1]+b[2]-b[3] == 7){
      printf("%d-%d+%d-%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
  if(b[0]-b[1]-b[2]+b[3] == 7){
      printf("%d-%d-%d+%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
if(b[0]-b[1]-b[2]-b[3] == 7){
      printf("%d-%d-%d-%d=7\n", b[0], b[1], b[2], b[3]);
      return 0;
  }
  
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> A;
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    if(i==0) A.push_back(a);
    else if ( A.at( A.size()-1 ) != a ) A.push_back(a);
  }
  
  vector<vector<int>> SA;
  bool fla = false;
  int res = 1;
  for (int i=0; i<A.size(); i++) {
    if (i==0) SA.push_back( {A.at(0)} );
    else {
      if ( SA.at(SA.size()-1).size() == 1 ) {
        SA.at(SA.size()-1).push_back({A.at(i)});
        if ( SA.at(SA.size()-1).at(0) < SA.at(SA.size()-1).at(1) ) fla = true;
        else fla = false;
      }
      else {
        if (fla) {  
          if ( SA.at( SA.size()-1 ).at( SA.at(SA.size()-1).size()-1 ) > A.at(i) ) {
            SA.push_back( {A.at(i)} );
          }
          else SA.at( SA.size()-1 ).push_back( {A.at(i)} );
        }
        else {
          if ( SA.at( SA.size()-1 ).at( SA.at(SA.size()-1).size()-1 ) < A.at(i) ) {
            SA.push_back( {A.at(i)} );
          }
          else SA.at( SA.size()-1 ).push_back( {A.at(i)} );
        }
      }
    }
  }

  cout << SA.size() << endl;
}

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


typedef struct{
  
  int parent , bro , degree , depth , type, height;
  int r,l;

}node_t;

vector<node_t> tree;



int Depth(int num , int d){

  int lowest=0;
  int work=0;

  tree[num].depth = d;

  if(tree[num].degree == 0){
    tree[num].height = 0;
    return 1;
  }

  if(tree[num].l!=-1)
    lowest = Depth(tree[num].l , d+1);
  if(tree[num].r!=-1)
    work = Depth(tree[num].r , d+1);

  lowest = (lowest < work)? work : lowest;
  tree[num].height = lowest;
  
  return lowest+1;

}

int main(){

  int n;
  int num;

  cin >> n;
  tree.resize(n);
  for(int i=0; i<n; i++){
    tree[i].parent = tree[i].bro = -1;
    tree[i].degree = 0;
    tree[i].type = 2;
  }


  for(int i=0; i<n; i++){
    cin >> num;
    cin >> tree[num].l >> tree[num].r;
    if(tree[num].l != -1){
      tree[num].type = 1;
      tree[ tree[num].l ].parent = num;
      tree[ tree[num].l ].bro = tree[num].r;
      tree[num].degree++;    
    }
    if(tree[num].r!=-1){
      tree[num].type = 1;
      tree[ tree[num].r ].parent = num;
      tree[ tree[num].r ].bro = tree[num].l;    
      tree[num].degree++; 
    }
 }    


  for(int i=0; i<n; i++){
    if(tree[i].parent == -1){
      tree[i].type = 0;
      tree[i].depth = 0;
      Depth(i,0);
      break;
    }
  }


  for(int i=0; i<n; i++){
    cout << "node " << i << ": parent = " << tree[i].parent << ", sibling = "
	 << tree[i].bro << ", degree = " << tree[i].degree << ", depth = "
	 << tree[i].depth << ", height = " << tree[i].height << ", ";

    if(tree[i].type == 0)cout << "root" << endl;
    else if(tree[i].type == 1)cout << "internal node" << endl;
    else cout << "leaf" << endl;
  }

  return 0;
}

Measured memory_bytes: 1200
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>
void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n,w,a,b;
	cin >> n>>w;
	vector<vector<int>>vec(n+1, vector<int>(100001,w+1));
	vec[0][0] = 0;
	for(int i=1; i<=n; i++) {
		cin >> a >> b;
		rep(j, 100001) {
			vec[i][j] = vec[i - 1][j];
			if(j>=b) vec[i][j]=min(vec[i][j],vec[i-1][j-b]+a);
		}
	}
	for (int i = 100000; i >= 0; i--) {
		if (vec[n][i] <= w) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 83160
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int W, H;
		int x, y, r;

		Scanner stdIn = new Scanner(System.in);

		W = stdIn.nextInt();
		H = stdIn.nextInt();
		x = stdIn.nextInt();
		y = stdIn.nextInt();
		r = stdIn.nextInt();

		if (0 <= (y - r) && H >= (y + r) && 0 <= (x - r) && W >= (x + r)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 26308
#include <iostream>
#include <algorithm>
using namespace	std;
int main(){

  for(int n;cin>>n&&n;){
    int a[5000],r;
    cin>>a[0];
    r=a[0];
    for(int i=1,b;i<n;i++){
      cin>>b;
      a[i]=a[i-1]+b;
      r=max({r,a[i],b});
    }
    for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) r=max(r,a[j]-a[i]);
    cout<<r<<endl;
  }
  return 0;
}

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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define rep(i, n) for(i = 0; i < n; i++)

int main(){
    ll X, t;
    cin >> X >> t;
    cout << ((X - t > 0) ? X - t : 0) << '\n';
    return 0;
}

Measured memory_bytes: 3580
// Problem : D - Xor Sum 4
// Contest : AtCoder - AtCoder Beginner Contest 147
// URL : https://atcoder.jp/contests/abc147/tasks/abc147_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    cin>>n;
    vi a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int ans = 0;
    for(int bit=0;bit<61;bit++){
        int z = 0, o = 0;
        for(int i=0;i<n;i++){
            if((a[i]>>bit)&1) o++;
            else z++;
        }
        int cur = (o*z)%mod;
        cur = (cur*((1LL<<bit)%mod))%mod;
        ans = (ans+cur)%mod;
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 5552
#include<stdio.h>

int main(){
    int n,f[131072]={0},a[131072],i,nb=1,r=0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++){scanf("%d",&a[i]);}
    while(1){
        f[nb]++;r++;
        nb=a[nb];
        if(nb == 2){printf("%d\n",r);return 0;}
        if(f[nb] > 0){printf("-1\n");return 0;}
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)
#define mp(a,b) make_pair(a, b)

typedef vector<int> vi;
typedef long long ll;
typedef complex<int> C;

char eq[128];
int idx;
bool of;

C number();
C eval1();
C eval2();
C eval3();
C eval();

void check(C v) {
	if(abs(v.real()) > 10000 || abs(v.imag()) > 10000) {
		of = true;
	}
}

C number() {
	if(eq[idx] == 'i') {
		idx++;
		return C(0, 1);
	}

	int value = 0;
	while(isdigit(eq[idx])) {
		value = value * 10 + (eq[idx] - '0');
		idx++;
		check(value);
	}
	return C(value, 0);
}

C eval3() {
	if(eq[idx] == '(') {
		idx++;
		C value = eval1();
		check(value);
	
		if(eq[idx] == ')') {
			idx++;
			return value;
		}
	}
	else {
		return number();
	}
	//cout << "Error" << endl;
	return C(0, 0);
}

C eval2() {
	C value = eval3();
	check(value);
	for(;;) {
		if(eq[idx] == '*') {
			idx++;
			value *= eval3();
		}
		else {
			break;
		}
		check(value);
	}
	check(value);
	return value;
}

C eval1() {
	C value = eval2();
	check(value);
	for(;;) {
		if(eq[idx] == '+') {
			idx++;
			value += eval2();
		} 
		else if(eq[idx] == '-') {
			idx++;
			value -= eval2();
		}
		else {
			break;
		}
		check(value);
	}
	check(value);
	return value;
}

C eval() {
	idx = 0;
	of = false;
	return eval1();
}

void print(C v) {
	if(of) {
		printf("overflow\n");
		return;
	}

	if(v.real() == 0 && v.imag() == 0) {
		printf("0\n");
		return;
	}

	if(v.real() != 0 && v.imag() == 0) {
		printf("%d\n", v.real());
		return;
	}

	if(v.real() == 0 && v.imag() != 0) {
		printf("%di\n", v.imag());
		return;
	}

	if(v.imag() > 0) {
		printf("%d+%di\n", v.real(), v.imag());
		return;
	}

	if(v.imag() < 0) {
		printf("%d%di\n", v.real(), v.imag());
		return;
	}

	cout << "unknown expression" << endl;
}

int main() {
	while(scanf("%s", eq)!=EOF) {
		C value = eval();
		print(value);
	}
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
int n;
double arr[3000];
double dp[3000][3000];

double solve(int i, int heads){
	if(i == n)
		return (heads>n/2);
	if(dp[i][heads] > -1) return dp[i][heads];

	dp[i][heads] = 0;
	dp[i][heads] += arr[i] * solve(i+1, heads+1);
	dp[i][heads] += (1-arr[i]) * solve(i+1, heads);

	return dp[i][heads];
}

int main(){
	cin>>n;
	for (int i = 0; i < n; ++i)
		cin>>arr[i];
	memset(dp, -1, sizeof dp);
	printf("%.10f\n", solve(0, 0));
	return 0;
}

Measured memory_bytes: 70784
# include "cstdio" 
# include "iostream"

using namespace std;

const int maxm=1e6+10;

int N,LH[maxm],Q[maxm],Ans;
char S[maxm],T[maxm]; 

int main(){
	register int i,j,L=1,R=0;
	register bool f=1;
	scanf("%d%s%s",&N,S+1,T+1);
	for(i=1;i<=N;i++) f&=(S[i]==T[i]);
	if(f){puts("0");return 0;}
	for(i=j=N;i;i--){
		if(T[i]==T[i-1]) continue;
		j=min(j,i);
		while(j && T[i]!=S[j]) --j;
		if(j==0){puts("-1");return 0;}
		while(L<=R){
			if(Q[L]-(R-L+1)+1>i) ++L;
			else break; 
		}
		Q[++R]=j;
		if(i!=j) Ans=max(Ans,R-L+1); 
	}
	cout<<Ans+1;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n;
  cin>>n;
  int cnt[111]={};
  int ma=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    cnt[a]++;
    ma=max(a,ma);
  }

  if(n==2){
    if(cnt[1]==2)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
  }

  if(cnt[ma]<2){
    cout<<"Impossible"<<endl;
    return 0;
  }

  if(ma%2==0&&cnt[ma/2]!=1){
    cout<<"Impossible"<<endl;
    return 0;
  }

  if(ma%2&&cnt[ma/2+1]!=2){
    cout<<"Impossible"<<endl;
    return 0;
  }
  
  int sum=cnt[ma];
  int s;
  if(ma%2==0){
    sum++;
    s=ma/2+1;
  }else{
    sum+=2;
    s=ma/2+2;
  }
  
  for(int i=s;i<ma;i++){
    if(cnt[i]<2){
	 cout<<"Impossible"<<endl;
	 return 0;
    }
    sum+=cnt[i];
  }

  if(sum==n)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    int k;
    string s;
    cin >> k >> s;
    if (s.size() > k) {
      cout << s.substr(0, k) + "...";
    } else {
      cout << s;
    }
  }
} NSPACE;
int main() {
  FPEN;
  FPEN2;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second 
//#define int   long long
#define ll   long long
#define pii pair<int, int>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main(){
    FAST
    int maxdiff = INT_MIN;
    int k, n;
    cin>>k>>n;
    vector<int> v(n);
    for(int i = 0; i<n; i++){
        cin>>v[i];
    }
    for(int i = 1; i<n; i++){
        maxdiff = max(maxdiff, v[i] - v[i-1]);
    }
    maxdiff = max(k - v[n-1] + v[0], maxdiff);
    cout<<k-maxdiff<<endl;
    return 0;
}

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

int N, E;
long a[101][101];

int INF = INT_MAX;
void warshalfloyd() {
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            if(a[i][k] == INF) continue;
            for (int j = 0; j < N; ++j) {
                if(a[k][j] == INF) continue;
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
            }
        }
    }
}

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

    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            a[k][i] = INF;
        }
    }
    for (int j = 0; j < N; ++j) {
        a[j][j] = 0;
    }
    for (int i = 0; i < E; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        a[s][t] = d;
    }

    warshalfloyd();
    for (int m = 0; m < N; ++m) {
        if(a[m][m] < 0) {
            cout << "NEGATIVE CYCLE"<< endl;
            return 0;
        }
    }
    for (int l = 0; l < N; ++l) {
        for (int i = 0; i < N; ++i) {
            if(i) cout << " ";
            if(a[l][i] == INF) {
                cout << "INF" ;
            } else
            cout << a[l][i] ;
        }
        cout << endl;
    }


    return 0;
}



Measured memory_bytes: 3168
#include<stdio.h>
#define INF 10000000

int time[101][101],cost[101][101],m;

void warshall_floyd(void);
int min(int,int);
void init(void);

int main(void){
  int i,j,n,k,a,b,cos,tim,p,q,r;

  while(scanf("%d %d",&n,&m),n,m){

    init();

    for(i=0;i<n;i++){
      scanf("%d %d %d %d",&a,&b,&cos,&tim);
      cost[a][b]=cost[b][a]=cos;
      time[a][b]=time[b][a]=tim;
    }

    warshall_floyd();

    scanf("%d",&k);
    for(i=0;i<k;i++){
      scanf("%d %d %d",&p,&q,&r);
      printf("%d\n",r?time[p][q]:cost[p][q]);
    }
  }
  
  return 0;
}

void init(void){
  int i,j;
  for(i=0;i<101;i++){
    for(j=0;j<101;j++){
      time[i][j]=cost[i][j]=INF;     
    }
    time[i][i]=cost[i][i]=0;
  }
}

void warshall_floyd(void){
  int i,j,k;
  for(k=0;k<=m;k++){
    for(i=0;i<=m;i++){
      for(j=0;j<=m;j++){
	cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
	time[i][j]=min(time[i][j],time[i][k]+time[k][j]);
      }
    }
  }
}

int min(int x,int y){
  return x<y?x:y;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
  int h, w;
  char s[50][51];

  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++)
    scanf("%s", s[i]);

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int count = 0;
      if (s[i][j] == '#') {
	putchar('#');
      }
      else {
	for (int a = i - 1; a <= i + 1; a++) {
	  for (int b = j - 1; b <= j + 1; b++) {
	    if (s[a][b] == '#')
	      count++;
	  }
	}
	printf("%d", count);
      }
    }
    putchar('\n');
  }

  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int main()
{
   int n;
   cin >> n;
   cout << 1110 - n << endl;
   return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_STN_MAX		100000									// 最大石数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 改行カット
// 戻り値：文字数
int
fCutCfLf(
	char *pcpStr				// <I> 文字列
)
{
	int i;

	for (i = 0; pcpStr[i] != '\0'; i++) {
		if (pcpStr[i] == '\n') {
			pcpStr[i] = '\0';
			break;
		}
	}

	return i;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 石取得
	char lc1Stn[D_STN_MAX + 5];
#ifdef D_TEST
	fgets(lc1Stn, sizeof(lc1Stn), szpFpT);
#else
	fgets(lc1Stn, sizeof(lc1Stn), stdin);
#endif

	// 改行カット・石数取得
	int liSCnt = fCutCfLf(lc1Stn);

	// 種類数取得
	int liCnt = 1;
	for (i = 1; i < liSCnt; i++) {
		if (lc1Stn[i] != lc1Stn[i - 1]) {		// １個前と不一致
			liCnt++;
		}
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liCnt - 1);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i = 0; i < a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
  int n;
  cin>>n;
  mint ans=mint(10).pow(n);
  ans-=mint(9).pow(n)*2;
  ans+=mint(8).pow(n);
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
function main(input) {
  const S = input.split('');
  S[0] = (S[0] === '9') ? '1' : '9';
  S[1] = (S[1] === '9') ? '1' : '9';
  S[2] = (S[2] === '9') ? '1' : '9';
  let ans = S.join('');
  console.log(ans);
}

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

Measured memory_bytes: 29552
# -*- coding: utf-8 -*-
import math

n = int(input())
counter = 0

for i in range(int(math.sqrt(n)), 0, -1):
  if n % i == 0:
    j = int(n / i)
    _keta = max(len(str(i)), len(str(j)))
    print(_keta)
    break


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   string s;
   cin >> s;
   FOR(i,0,s.length())
      cout << "x";
   cout << endl;
   return 0;
}


Measured memory_bytes: 256
n = int(input())
x = input()
a = x.count('1')
b = int(x,2)

ary = [None for i in range(200010)]
ary[0] = 0

def f(n):
  if ary[n] is not None:
    return ary[n]
  b = bin(n).count('1')
  r = 1 + f(n%b)
  ary[n] = r
  return ary[n]

a1 = a + 1
a0 = a - 1
for i in range(200010):
  f(i)

# one = [1] * 200010
# zero = [1] * 200010
# for i in range(1, 200010):
#     if a0 != 0:
#         one[i] = one[i-1] * 2 % a0
#     zero[i] = zero[i-1] * 2 % a1

c1 = b%a1
if a0 != 0:
  c0 = b%a0
for i in range(n-1, -1, -1):
  if x[n-1-i] == '0':
    # y = c1 + zero[i]
    y = c1 + pow(2,i,a1)
    y %= a1
    print (ary[y]+1)
  else:
    if a0 != 0:
      y = c0 - pow(2,i,a0)
      y %= a0
      print (ary[y]+1)
    else:
      print (0)

Measured memory_bytes: 11172
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
// use std::num;
const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
        n:usize,m:usize
    }
    let mut fact = vec![1i64; m + 1];
    for i in 2..(1 + m) {
        fact[i] = fact[i - 1] * (i as i64) % MOD;
    }
    let perm = |m, n| fact[m] * modInv(fact[m - n]) % MOD;
    let comb = |m, n| fact[m] * modInv(fact[m - n]) % MOD * modInv(fact[n]) % MOD;
    //let comb2 = |m| n * (n - 1) * modInv(2) % MOD;
    // Aを固定して、Bを考える。
    // 求めたいパターンは、全てのパターン(0個以上が同じ) - 1個以上が同じ + 2個以上が同じ - ...
    // all = m P n
    // k以上が同じケース。
    let mut ans = 0;
    for i in 0..n + 1 {
        ans += (-1i64).pow((i & 1) as u32) * comb(n, i) * perm(m - i, n - i) % MOD;
    }
    ans = ans % MOD * perm(m, n) % MOD;
    // println!("{},{}", fact[2], modInv(fact[2]));
    // println!("{}", x);
    println!("{}", (ans + MOD) % MOD);
}

fn modPow(a: i64, n: i64) -> i64 {
    let mut res = 1;
    let mut a = a;
    let mut n = n;
    while n > 0 {
        if n % 2 != 0 {
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n / 2;
    }
    return res;
}
fn modInv(a: i64) -> i64 {
    modPow(a, MOD - 2)
}


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

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

  int n,t,k,case_num = 0;
  while(cin >> n >> t >> k, n){
    case_num++;

    map<int,int> costs;
    vector< vector<pii> > tree(n);

    for(int i=0;i<n-1;i++){
      int a,b,c;
      cin >> a >> b >> c;
      a--; b--;
      tree[a].push_back(pii(c,b));
      tree[b].push_back(pii(c,a));
      costs[c]++;
    }

    vector<int> base(t), use(n,0);
    for(int i=0;i<t;i++){
      cin >> base[i];
      base[i]--;
      use[base[i]] = 1;
    }

    priority_queue<pii> q;
    for(int v : base){
      for(pii u : tree[v]){
	if(!use[u.second])q.push(u);
      }
    }

    while(q.size()){
      pii p = q.top(); q.pop();
      if(use[p.second])continue;
      use[p.second] = 1;
      costs[p.first]--;

      for(pii u : tree[p.second]){
	if(!use[u.second])q.push(u);
      }
    }

    long long res = 0;
    auto it = costs.begin();
    while(k){
      while(k && it->second){
	it->second--; k--;
	res += it->first;
      }
      it++;
    }
    cout << "Case " << case_num << ": " << res << endl;
  }
}

Measured memory_bytes: 2384
N = int(input())
A_list = list(range(0))

top1Num = 0
top2Num = 0
topCount = 0

# countが必要

for i in range(N):
    A = int(input())
    A_list.append(A)
    if A > top1Num:
        top2Num = top1Num
        top1Num = A
    elif A > top2Num:
        top2Num = A

# print(A_list)
# print(top1Num)
# print(top2Num)

topCount = A_list.count(top1Num)
# print(topCount)

# print("--------------------")

for i in range(N):
    if A_list[i] == top1Num:
        print(top2Num)
    else:
        print(top1Num)

Measured memory_bytes: 12512
#include <iostream>

using namespace std;

int main() {
  string s;
  int ans = 700;
  cin >> s;
  if(s[0] == 'o') ans += 100;
  if(s[1] == 'o') ans += 100;
  if(s[2] == 'o') ans += 100;
  cout << ans << endl;
}

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

int n,m;

void n1(){
  int p=-1; bool ok=true;
  for(int i=0;i<m&&ok;i++) {
    int s,c; cin>>s>>c; s--;
    if (s!=0 || (p != -1 && p != c)) ok=false;
    p=c;
  }
  if (p==-1) p=0;
  if (ok) cout<<p<<endl;
  else cout<<-1<<endl;
}

int main(){
  cin>>n>>m;
  if (n==1) {n1(); return 0;}

  int d[n]; fill(d, d+n, -1);
  for(int i=0;i<m;i++) {
    int s,c; cin>>s>>c; s--;
    if ((d[s] != -1 && d[s] != c) || (s == 0 && c == 0) || (s+1 > n)) return puts("-1")*0;
    else d[s]=c;
  }
  for(int i=0;i<n;i++) {
    if (d[i] != -1) cout<<d[i];
    else if (i==0) cout<<1;
    else cout<<0;
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

struct STU{
	int idx,ai;
	
	bool operator < (const STU& s) const {
		return ai<s.ai;
	}
	
}stu[100005];

int N;

int main(){
	
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&(stu[i].ai));
		stu[i].idx=i+1;
	}
	sort(stu,stu+N);
	
	for(int i=0;i<N-1;i++)
		printf("%d ",stu[i].idx);
	printf("%d\n",stu[N-1].idx);
	return 0;
}

Measured memory_bytes: 1536
/*
  AOJ 2271
  Title:KUPC
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

#define min(x,y) (((x)<(y))?(x):(y))

char line[301];
int kupc[4];
char s[4]="KUPC";
main()
{
  int i,len;
  char *p;

  scanf("%s",line);
  len=strlen(line);
  for(i=0;i<len;i++)
    if(p=strchr(s,line[i]))
      kupc[p-s]++;
  printf("%d\n",min(min(kupc[0],kupc[1]),min(kupc[2],kupc[3])));
  return(0);
}

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

typedef pair<int,int> P;

int main ()
{
    int n, w, d;
    while (cin >> n >> w >> d, n || w || d) {
        vector<P> v;
        v.push_back(P(w, d));
        int count = 1;
        while (n--) {
            int p, s;
            cin >> p >> s ;

            int x = v[p-1].first, y = v[p-1].second;
            int len = x * 2 + y * 2;
            s %= len;

            int x1, x2, y1, y2;
            if (s < x) {
                x1 = s; x2 = x - s; y1 = y2 = y;
            } else if (s < len / 2) {
                x1 = x2 = x; y1 = s - x; y2 = y - y1;
            } else if (s < len -  y) {
                x1 = s - (len / 2); x2 = x - x1; y1 = y2 = y;
            } else if (s < len) {
                x1 = x2 = x; y1 = len - s; y2 = y - y1;
            }

            if (x1 * y1 < x2 * y2) {
                v.push_back(P(x1, y1));
                v.push_back(P(x2, y2));
            } else {
                v.push_back(P(x2, y2));
                v.push_back(P(x1, y1));
            }
            count++;
            v.erase(v.begin() + (p - 1));

            v.resize(count);
        }


        vector<int> res;
        for (auto i : v) {
            res.push_back(i.first * i.second);
        }

        sort(res.begin(), res.end());

        for (int i = 0; i < res.size() - 1; i++) {
            cout << res[i] << " " ;
        } cout << res[res.size()-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1220
# -*- coding: utf-8 -*-

N = int(input())
S = input()

list_S = list(S)

new_list_S = [list_S[0]]
for i in range(1, len(list_S)):
    if list_S[i] != list_S[i - 1]:
        new_list_S.append(list_S[i])

print(len(new_list_S))

Measured memory_bytes: 4724
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, W; cin >> n >> W;
    vll w(n), v(n);
    REP(i, n) cin >> w[i] >> v[i];
    vvll dp(n+1, vll(W+1, 0));
    REP(i, n) {
        REP(j, W+1) {
            if (j-w[i]>=0) dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[n][W] << '\n';
    return 0;
}


Measured memory_bytes: 80256
/**
 *      ABC 87 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 04:45:39
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int X, A, B; cin >> X >> A >> B;
    cout << (X - A) % B << endl;

    return 0;
}

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

n = 0
import sys
if N<3:
    print(0)
    sys.exit()

for i in range(N-2):
    a = A[i]
    for j in range(i+1,N-1):
        if a == A[j]:continue
        b = A[j]
        for k in range(j+1,N):
            if (a == A[k])|(b==A[k]):continue
            c = A[k]
            if (a+b>c)&(b+c>a)&(c+a>b):
                n+=1

print(n)

Measured memory_bytes: 9208
object Main extends App {
  val input = io.Source.stdin.getLines.toSeq.head.split(' ').map(_.toInt)
  val N=input(0)
  val K=input(1)
  var i=1
  var ret=K
  while(i<N){
    ret = (ret * (K-1))
    i += 1
  } 
  println(ret)
}


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

bool cmp(const char& aa, const char& bb){
    if(tolower(aa) == tolower(bb))
        return (aa < bb);
    else
        return (tolower(aa) < tolower(bb));
}

void solve(){
    string aa = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int n;
    cin >> n;
    string s;
    cin >> s;

    for(int i= 0 ; i<s.size();i++){
        if((s[i]+n)>'Z'){
                int p = int(s[i]+n-1-'Z');
            s[i] = aa[p];
        }
        else{
            s[i] = s[i] + n;
        }
    }
    cout << s << endl;

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

    return 0;
}





Measured memory_bytes: 3640
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;
#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<" "
#define pr2(a,b)    cout<<a<<" "<<b<<" "
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void minize(ll& a,ll b){a=(a>b?b:a);};
inline void maxize(ll& a,ll b){a=(a<b?b:a);};
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll arr[MAXN+5];

ll Solves(){
	
	ll n,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESSING IN HERE
	string s;
	sc(s);
	fu(i,0,le(s)-1)arr[s[i]]++;
	
	fu(i,1,200)ans+=arr[i]*(le(s)-arr[i]);
	pr(ans/2+1);
	

	re 0;
	// Hack it if you can :)
}

int main(){
//	INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	ll test;
//	sc(test);
//	fu(T,1,test+1)
	Solves();
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u){
        cout << a-1 << ' ' << b << endl;
    }
    else{
        cout << a << ' ' << b-1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

string redbul;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> redbul;
    stack<char> rb;
    ll count = 0;
    char before_rb = redbul[0];
    rb.push(redbul[0]);
    for(int i=1;i < redbul.length();i++){
        if(before_rb != redbul[i]){
            count++;
            rb.pop();
        }else{
            rb.push(redbul[i]);
        }
        if(rb.empty()){
            i++;
            rb.push(redbul[i]);
        }
        before_rb = rb.top();
    }
    cout << count * 2 << endl;

    return 0;
}

Measured memory_bytes: 512
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn factors(n: usize) -> HashSet<usize> {
    let mut factors = HashSet::new();
    for d in 1.. {
        if d * d > n {
            break;
        }
        if n % d == 0 {
            factors.insert(d);
            factors.insert(n / d);
        }
    }
    factors
}

fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }
    let mut count = HashMap::new();
    for i in 0..n {
        *count.entry(a[i]).or_insert(0) += 1;
    }
    a.sort();
    let mut f = HashSet::new();
    let mut result = 0;
    for i in 0..n {
        if count[&a[i]] == 1 && factors(a[i]).iter().all(|&x| !f.contains(&x)) {
            result += 1;
        }
        f.insert(a[i]);
    }
    println!("{}", result);
}


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

int main () {
  string S;
  cin >> S;
  int len = 0;
  int ans = 0;
  
  while (len != S.size()) {
    len = S.size();
    for (int i=len-2; i>=0; i--) {
      if(S[i]!=S[i+1] && S[i+1]!=NULL) {
        S.erase(i,2);
        ans += 2;
      }
    }      
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int N = 350;
const int INF = 1<<30;

int a, b, s, t, sum, d[N][N], f[N][N];

inline void ck_min( int &a, int b ) { if( a > b ) a = b; }
inline void ck_max( int &a, int b ) { if( a < b ) a = b; }

inline bool check( int x, int y, int val )
{
    int res = INF;
    for( int i = 0; i <= 100; i ++ )
        for( int j = 0; j <= 100; j ++ )
            if( f[i][j] >= 0 ) ck_min( res, i*x + j*y + f[i][j] );

//  printf( "x:%d, y:%d, res:%d\n", x, y, res );
    return res == val;
}

int main()
{
    memset( f, -1, sizeof( f ) );

    scanf( "%d%d", &a, &b );
    for( int i = 1; i <= a; i ++ )
        for( int j = 1; j <= b; j ++ )
            scanf( "%d", &d[i][j] );

    s = 201, t = 202; 
    // s --> 1 --> 2 --> ... --> 100
    // t <-- 101 <-- 102 <-- ... <-- 200

    for( int i = 0; i <= 100; i ++ )
        for( int j = 0; j <= 100; j ++ )
        {
            int tmp = -INF;
            for( int _a = 1; _a <= a; _a ++ )
                for( int _b = 1; _b <= b; _b ++ )
                    ck_max( tmp, d[_a][_b] - i*_a - j*_b ); 
            f[i][j] = tmp; 
            if( f[i][j] < 0 ) break;

            sum ++;
//          printf( "i:%d, j:%d, f:%d\n", i, j, f[i][j] );
        }

    for( int i = 1; i <= a; i ++ )
        for( int j = 1; j <= b; j ++ )  
            if( !check( i, j, d[i][j] ) ) {
                printf( "Impossible\n" ); return 0;
            } 

    printf( "Possible\n" );

    printf( "%d %d\n", 202, sum+200 );
    for( int i = 1; i < 100; i ++ )
        printf( "%d %d X\n%d %d Y\n", i, i+1, i+101, i+100 );

    printf( "%d %d X\n%d %d Y\n", s, 1, 101, t );
    for( int i = 0; i <= 100; i ++ )
        for( int j = 0; j <= 100; j ++ )
            if( f[i][j] >= 0 )  printf( "%d %d %d\n", !i ? s : i, !j ? t : j+100, f[i][j] );

    printf( "%d %d\n", s, t );

    return 0;
}

Measured memory_bytes: 768