akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 2e5+5;
const int MOD = 1e9+7;


int arr[MSIZE];
int dp[MSIZE];

int main(){
    FIO
    int n; cin>>n;
    f(i,0,n-1)  cin>>arr[i];
    dp[0] = 0;
    dp[1] = abs(arr[0]-arr[1]);
    f(i,2,n-1) {
        dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]),
                    dp[i-2] + abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;

}
    


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

int main(){
    int S;
    cin >> S;
    int h=0 , m = 0, s = 0;
    h = S / 3600;
    S = S - h*3600;
    m = S / 60;
    S = S - m*60;
    s = S;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   string s;
   cin>>s;
   unordered_map<char,int>mp;
   for(auto c:s){
      mp[c]++;
   }
   for(auto it:mp){
      if(it.second!=2){
         cout<<"No"<<endl;
         return 0;
      }
   }
   if(mp.size()==2){
      cout<<"Yes"<<endl;
   }else{
      cout<<"No"<<endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};

int main() {
    int x;
    cin >> x;
    if (x==3 || x==5 || x==7) 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 < (int)(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;

int n;
string t;

int main() {
  cin >> n;
  int ans=0;
  while(n){
    ans+=n%10; n/=10;
  }
  cout << (ans==1?10:ans) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }

ll C(ll n,ll m)
{
    ll sum=1; 
    for(ll i=1,j=n;i<=m;i++,j--)
    {
        sum=sum*j/i;
    }
    return sum;
}
int main(){
	// in;
	// out;
	ll n,m;
	cin>>n>>m;
	cout<<C(n,2)+C(m,2)<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;


/**
 * ABC155
 */
public class Main {

	public static void main(String[] args) throws Exception {
		Main main = new Main();

		try (Scanner scan = new Scanner(System.in)) {
			main.poor(scan);
		}
	}

	private void poor(Scanner scan) {
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if (a == b) {
			if (b == c){
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		} else if (a == c) {
			System.out.println("Yes");
		} else if (b == c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	@SuppressWarnings("unused")
	private static class Pair<T1, T2> {

		private T1 left;
		private T2 right;

		public Pair(T1 left, T2 right) {
			this.left = left;
			this.right = right;
		}

		public T1 left() {
			return left;
		}

		public T2 right() {
			return right;
		}
	}


	@SuppressWarnings("unused")
	private static class UnionFindTree {
		private List<Integer> parents;

		public static UnionFindTree initialize(int n) {
			return new UnionFindTree(n);
		}

		public UnionFindTree(int n) {
			parents = IntStream.range(0, n).boxed().collect(Collectors.toCollection(() -> new ArrayList<>()));
		}

		public int find(int index) {
			if (index == parents.get(index)) {
				return index;
			}
			// 自分の親の親は自分の親とできるため経路圧縮
			parents.set(index, find(parents.get(index)));
			return parents.get(index);
		}

		public void union(int x, int y) {
			int xParent = find(x);
			int yParent = find(y);
			parents.set(yParent, xParent);
		}

		public long size() {
			return parents.stream().map(i -> find(i)).distinct().count();
		}
	}

}


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

int main(){
  int S;
  cin >> S;
  int Sf=S/100;
  int Sb=S%100;
  if (Sf<=12 && Sf>0){
    if (Sb<=12 && Sb>0){
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "MMYY" << endl;
    }
  } else {
    if (Sb<=12 && Sb>0){
        cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

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

	vector<string> X;

	for (int h = 0;h < N;h++) {
		string S;
		cin >> S;
		X.push_back(S);
	}

	for (int h = 0;h < N;h++) {
		string T = X[h];

		for (int i = 0;i < M;i++) {//T[i]についてみている
			for (int j = 0;j <= i;j++) {
				if (T[i - j] == 'c') {
					if (i+1 == M) {
						cout << j << endl;
						break;
					}
					if (i != M) {
						cout << j << " ";
						break;
					}
				}
				else if (i - j == 0) {
					if (i + 1 == M) {
						cout << -1 << endl;
						break;
					}
					if (i != M) {
						cout << -1 << " ";
						break;
					}
				}

			}
		}
	}
	return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin>>n;
	int ans =0;
	if(n%2==0) ans = n;
	else ans = n*2;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	//iはループ変数、indexは添字、input_xとinput_yは入力値を格納
	int i, index;
	int input_x[10000], input_y[10000];

	//初期値は0
	index = 0;

	while(1){
		scanf("%d %d", &input_x[index], &input_y[index]);

		//入力値が両方ともに0ならばループを抜ける
		if(input_x[index] == 0 && input_y[index] == 0){
			break;
		}
		index++;
	}

	//入力した回数だけ出力する
	for(i = 0; i < index; i++){
		//入力値を昇順に出力する
		if(input_x[i] < input_y[i]){
			printf("%d %d\n", input_x[i], input_y[i]);
		}
		else{
			printf("%d %d\n", input_y[i], input_x[i]);
		}
	}

	return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	string s;
	char c;
	string abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string abc2 = "abcdefghijklmnopqrstuvwxyz";
	while (cin >> s >> c) {
		if (c == 'X') {
			break;
		}
		vector<string> ss;
		if (s.find("_") != string::npos) {
			string sa = "";
			for (int i = 0; i < s.size(); i++) {
				if (s[i] == '_') {
					ss.push_back(sa);
					sa = "";
				} else {
					sa += s[i];
				}
			}
			ss.push_back(sa);
		} else {
			bool h = false;
			for (int i = 0; i < 26; i++) {
				if (s[0] == abc[i]) {
					h = true;
					break;
				}
			}
			if (h) {
				string sb = "";
				for (int i = 0; i < s.size(); i++) {
					bool h2 = false;
					for (int j = 0; j < 26; j++) {
						if (s[i] == abc[j]) {
							h2 = true;
							if (sb == "") {
							} else {
								ss.push_back(sb);
							}
							sb = "";
							sb += abc2[j];
							break;
						}
					}
					if (!h2) {
						sb += s[i];
					}
				}
				ss.push_back(sb);
			} else {
				string sc = "";
				for (int i = 0; i < s.size(); i++) {
					bool h2 = false;
					for (int j = 0; j < 26; j++) {
						if (s[i] == abc[j]) {
							h2 = true;
							ss.push_back(sc);
							sc = "";
							sc += abc2[j];
							break;
						}
					}
					if (!h2) {
						sc += s[i];
					}
				}
				ss.push_back(sc);
			}
		}
		string s2 = "";
		if (c == 'U') {
			for (int i = 0; i < ss.size(); i++) {
				for (int j = 0; j < 26; j++) {
					if (ss[i][0] == abc2[j]) {
						ss[i][0] = abc[j];
						break;
					}
				}
				s2 += ss[i];
			}
		} else if (c == 'L') {
			s2 += ss[0];
			for (int i = 1; i < ss.size(); i++) {
				for (int j = 0; j < 26; j++) {
					if (ss[i][0] == abc2[j]) {
						ss[i][0] = abc[j];
						break;
					}
				}
				s2 += ss[i];
			}
		} else {
			for (int i = 0; i < ss.size(); i++) {
				if (s2 != "") {
					s2 += "_";
				} 
				s2 += ss[i];
			}
		}
		cout << s2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
N = int(input())
if N == 1:
  print(input())
else:
  A = 0
  B = 0
  a = list(map(int,input().split()))
  a.sort()
  a.reverse()
  for i in range(N):
    if i % 2 == 0:
      A += a[i]
    else:
      B += a[i]
  print(A - B)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string result = "No";
  int S = 0, N = 0; cin >> N;
  int n = N, m = 0;

  while (n >= 1) {
    S += n % 10;
    n /= 10;
  }

  if (N%S==0)
    result = "Yes";

  cout << result << endl;
}

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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007LL
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  ll T1, T2;
  cin >> T1 >> T2;
  ll A1, A2, B1, B2;
  cin >> A1 >> A2 >> B1 >> B2;
  ll one_gap = (A1 - B1) * T1;
  ll two_gap = (A2 - B2) * T2;
  if (one_gap == 0 || two_gap == 0 || ((one_gap > 0) ^ (two_gap < 0))) {
    cout << 0 << endl;
  } else if (one_gap + two_gap == 0) {
    cout << "infinity" << endl;
  } else {
    if (one_gap > 0) {
      one_gap *= -1;
      two_gap *= -1;
    }
    ll ans;
    ans = (abs(one_gap) + (one_gap + two_gap) - 1) / (one_gap + two_gap) * 2;
    if (abs(one_gap) % (one_gap + two_gap) != 0) ans--;
    cout << max(0LL, ans) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;

typedef long long ll;
const int N = 305;

int read(){
	int x = 0 , f = 1 ; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}

int n , k , Mod;
ll s[N][N] , f[N][N] , C[N][N];

int main(){
	n = read(); k = read(); Mod = read();
	C[0][0] = 1;
	for(int i = 1 ; i <= n ; i++){
		C[i][0] = 1;
		for(int j = 1 ; j <= i ; j++)
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;
	}
	for(int i = 0 ; i <= k ; i++) f[1][i] = 1 , s[1][i] = k - i + 1;
	for(int i = 2 ; i <= n + 1 ; i++){
		for(int j = 0 ; j <= k ; j++)
			for(int l = 1 ; l < i ; l++)
				(f[i][j] += f[i - l][j] * s[l][j + 1] % Mod * C[i - 2][l - 1] % Mod) %= Mod;
		for(int j = k ; j >= 0 ; j--) s[i][j] = (s[i][j + 1] + f[i][j]) % Mod;
	}
	printf("%lld\n",f[n + 1][0]);
	return 0;
}

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

int main() {
	unsigned long long int la, lb, lc;
	int n;

	la = 2;
	lb = 1;

	cin >> n;

	if (n == 0) {
		cout << la;
	}

	else if (n == 1) {
		cout << lb;
	}
	else {
		for (int i = 1; i < n; i++) {
			lc = la + lb;
			la = lb;
			lb = lc;
		}

		cout << lc;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long n = scan.nextLong();
    String[] a = new String[]{"z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    ArrayList<String> g = new ArrayList<String>();
    while (n>0){
      long t1 = (long) n%26;
      int t = (int) t1;
      g.add(a[t]);
      if (t == 0){
        t = 26;
      }
      n -= t;
      n = (long) n/26;
    }
    for (int p = g.size()-1;p>=0;p--){
      System.out.print(g.get(p));
    }
    System.out.println("");
  }
}


Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
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; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N, 0);

    REP(i, K){
        ll d;
        cin >> d;
        REP(j, d){
            ll tmp;
            cin >> tmp;
            tmp--;
            A[tmp]++;
        }
    }

    ll res = 0;
    REP(i, N) if(A[i]==0) res++;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3596
# include <bits/stdc++.h>
# define rep(i,n) for (int i = 0; i < n; i++)
# define sort(v) sort(v.begin(),v.end())
# define rsort(v) reverse(v.begin(),v.end())
# define all(v) v.begin() ,v.end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;

ll X;

bool is_prime(ll n)
{
  if(n == 1){
    return false;
  }
  int k = ceil(sqrt(n));
  rep(i,k){
    if(i == 0 || i == 1){

    }
    else if(n % i == 0){
      return false;
    }
  }
  return true;
}

int main()
{
  cin >> X;
  if(X == 2 || X == 3 || X == 5){
    cout << X << endl;
  }
  else if(is_prime(X)){
    cout << X << endl;
  }else{
    while(true){
      X += 1;
      if(is_prime(X)){
        cout << X << endl;
        return 0;
      }
    }
  }
  return 0;
}

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

int main()
{
    string t;
    int n,i;
    cin>>t;
    n=(int)(t.length());
    for (i = 0; i < n; i++)
    {
        if (t[i]=='?') t[i]='D';
    }
    cout<<t<<endl;
}

Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
#include<cstring>

int r, c, res = 0;
int data[11][10001], buf[11][10001];

void reverse(int *ose){
	for (int i = 0; i < c; i++){
		ose[i] = (ose[i] + 1) % 2;
	}
}

int main(){
	while (std::cin >> r >> c, r || c){

		for (int i = 0; i < r; i++){
			for (int j = 0; j < c; j++){
				std::cin >> data[i][j];
			}
		}

		int rev = (1 << 10);
		for (int i = 0; i < rev; i++){
			memcpy(buf, data, sizeof(buf));
			int ans = 0;

			for (int j = 0; j < r; j++){
				if ((i >> j) & 1)reverse(buf[j]);
			}

			for (int j = 0; j < c; j++){
				int count = 0;
				for (int k = 0; k < r; k++)if (buf[k][j] == 1)count++;
				ans += std::max(count, r - count);
			}

			res = std::max(res, ans);
		}

		std::cout << res << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1988
n, y = map(int, input().split())
for i in range(n + 1):
  for ii in range(n - i + 1):
    if 10000 * i + 5000 * ii + 1000 * (n - i - ii) == y:
      print('{} {} {}'.format(i, ii, n - i - ii))
      exit()
print('-1 -1 -1')

Measured memory_bytes: 2940
#include<iostream>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(){

	int x;
	int a;
	int b;

	cin >> x >> a >> b;

	if(abs(x-a)<abs(b-x)){
		cout << "A" << endl;
	}else{
		cout << "B" << endl;
	}

	return 0;

}


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

int main(){
    string x;
    while(cin>>x,x!="0"){
        int sum = 0;
        for(int i = 0; i < x.size(); i++){
            int a = x[i] - 48;
            sum += a;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main(){
  uint64_t n;
  cin>>n;
  vector<uint64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  uint64_t curr_max=0;
  uint64_t sum=0;
  for(int i=0;i<n;i++){
    if(curr_max>a[i]){
      sum+=curr_max-a[i];
    }else{
      curr_max=a[i];
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 4732
/*
  ID: ak260901
  TASK: a
  LANG: C++
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define foru(i, l, r) for(register int i = l; i <= r; i++)
#define ford(i, r, l) for(register int i = r; i >= l; i--)

int N, A, B, C;
bool a, b, c;
int tmp[1000], tot;
int l[1000], ans = 10000000;
int belong[1000];

void dfs(int);

int main() {
  //freopen("a.in", "r", stdin);
  //freopen("a.out", "w", stdout);
  scanf("%d%d%d%d", &N, &A, &B, &C);
  for(int i = 1; i <= N; i++)
    scanf("%d", &l[i]);
  belong[1] = 1; dfs(1);
  belong[1] = 2; dfs(1);
  belong[1] = 3; dfs(1);
  printf("%d\n", ans);
  return 0;
}

void dfs(int now) {
  if(now == N) {
    int tmpans = 0;

    tot = 0;
    for(int i = 1; i <= N; i++)
      if(belong[i] == 1) tmp[++tot] = i;
    if(!tot) return;
    int temp = 100000;
    for(int i = 1; i <= tot; i++)
      temp = min(temp, max(l[tmp[i]] - A, A - l[tmp[i]]));
    for(int i = 1; i < (1 << tot); i++) {
      int sum = 0, cost = 0;
      for(int j = 1; j <= tot; j++) {
        if(i & (1 << (j - 1))) {
          cost += 10; sum += l[tmp[j]];
        } else continue;
      } temp = min(temp, max(sum - A, A - sum) + cost - 10);
    } tmpans += temp;

    tot = 0;
    for(int i = 1; i <= N; i++)
      if(belong[i] == 2) tmp[++tot] = i;
    if(!tot) return;
    temp = 1000000;
    for(int i = 1; i <= tot; i++)
      temp = min(temp, max(l[tmp[i]] - B, B - l[tmp[i]]));
    for(int i = 1; i < (1 << tot); i++) {
      int sum = 0, cost = 0;
      for(int j = 1; j <= tot; j++) {
        if(i & (1 << (j - 1))) {
          cost += 10; sum += l[tmp[j]];
        } else continue;
      } temp = min(temp, max(sum - B, B - sum) + cost - 10);
    } tmpans += temp;

    tot = 0;
    for(int i = 1; i <= N; i++)
      if(belong[i] == 3) tmp[++tot] = i;
    if(!tot) return;
    temp = 1000000;
    for(int i = 1; i <= tot; i++)
      temp = min(temp, max(l[tmp[i]] - C, C - l[tmp[i]]));
    for(int i = 1; i < (1 << tot); i++) {
      int sum = 0, cost = 0;
      for(int j = 1; j <= tot; j++) {
        if(i & (1 << (j - 1))) {
          cost += 10; sum += l[tmp[j]];
        } else continue;
      } temp = min(temp, max(sum - C, C - sum) + cost - 10);
    } tmpans += temp;
    ans = min(ans, tmpans);
  } else {
    belong[now + 1] = 1; dfs(now + 1);
    belong[now + 1] = 2; dfs(now + 1);
    belong[now + 1] = 3; dfs(now + 1);
  }
}

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


int main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
      for(int k=0;k<n;k++){
      if(k>0){
        cout << " ";
      }
      cout << A[k];
    }
  cout << endl;
  for(int i=1;i<n;i++){
    int v=A[i];
    int j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(int k=0;k<n;k++){
      if(k>0){
        cout << " ";
      }
      cout << A[k];
    }
    cout <<endl;
  } 
}


Measured memory_bytes: 3104
#include<stdio.h>
int abs(int a)
{
    if(a<0) return -a;
    return a;
}
int min(int a, int b)
{
    if(a>b) return b;
    return a;
}
int main()
{
    int a[4], sum=99999;
    scanf("%d%d%d",a+1,a+2,a+3);
    int i, j, k;
    for(i=1;i<=3;i++)
        for(j=1;j<=3;j++)
        for(k=1;k<=3;k++)
    {
        if(i==j||j==k||i==k) continue;
        sum=min(sum,abs(a[j]-a[i])+abs(a[k]-a[j]));
    }

    printf("%d",sum);
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
 
using namespace std;
 
string s;
 
int main() {
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7')cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    for (int i = 1; i < n+1; i++){
        if (i % 3 == 0){
            cout << " " << i;
            continue;
        }
        int x = i;
        while (x != 0){
            if (x % 10 == 3){
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3096
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;
bool my_compare(pair<ll, ll> a, pair<ll , ll> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
         return a.first < b.first; // 昇順
        //return a.first > b.first; // 降順
    }

    // それ以外はsecondで比較
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        // どちらも同じ
        return true;
    }
}

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

    ll a,b,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str,sub;
    ll h,w;
    string str1;
    cin>>h>>w;
    string s[h];
    rep(i,h) cin>>s[i];
    //f=1;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){
                f=0;
                if(i!=0) if(s[i-1][j]=='#') f=1;
                if(j!=0) if(s[i][j-1]=='#') f=1;
                if(i+1!=h) if(s[i+1][j]=='#') f=1;
                if(j+1!=w) if(s[i][j+1]=='#') f=1;
                if(f==0){
                    No;
                    return 0;
                }
            }
        }
    }

    Yes;

    return 0;
}


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

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    long X;
    cin>>X;

    long long ans=0;
    for(int i = 0; i <= A; i++)
    {
        for(int k = 0; k <= B; k++)
        {
            for(int m = 0; m <= C; m++)
            {
                if((500*i)+(100*k)+(50*m)==X)ans++;
            }
            
        }
        
    }

    cout<<ans<<endl;
    
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int d;
    cin >> d;

    if (d == 25)
        cout << "Christmas" << endl;
    else if (d == 24)
        cout << "Christmas Eve" << endl;
    else if (d == 23)
        cout << "Christmas Eve Eve" << endl;
    else
        cout << "Christmas Eve Eve Eve" << endl;
}


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

int main() {
  int a,b; 
  cin >> a >> b;
  string as = to_string(a);
  string bs = to_string(b);
  string ans = ""; 
  if(a >= b){
    rep(i, a) ans += bs;
  }
  else{ rep(i, b) ans += as;}
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define ll long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

signed main(){
	
	int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
	int ansNoudo = 0;
	int ansWater=0,ansSuger=0;
	rep(ia,31)rep(ib,31)
	{
		int water = 100*ia*a + 100*ib*b;
		if(water > f or water == 0) continue;
		rep(ic,f/c)rep(id,f/d)
		{
			int suger = ic*c+id*d;
			
			if(water + suger > f) continue;
			if(water*e < suger*100) continue;

			if(ansWater + ansSuger ==0)
			{
				ansWater = water;
				ansSuger = suger;
			}
			
			if((ansSuger+ansWater)*suger > (suger + water) * ansSuger)
			{
				ansWater = water;
				ansSuger = suger;
			}
		}
	}
	cout << ansWater+ansSuger << " " << ansSuger << endl;
	
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int a, b;
    scanf("%d %d\n", &a, &b);
    if(a > b){
        printf("a > b\n");
    }
    else if(a < b){
        printf("a < b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  f80 a;
  while (cin >> a) {
    f80 ans = a;
    rep(i, 9) {
      if (i % 2 == 0) a *= 2; else a /= 3;
      ans += a;
    }
    cout << ans << '\n';
  }
}



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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    ll A, B;
    cin >> A >> B;

    cout << lcm(A, B) << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
INF = 10**10
N, W = map(int, input().split())

# dp[i][sum_v]:
# i-1番目までの品物から価値がsum_v以上を達成するように選んだ時の、重さの最小値
# sum_v <= max_N * max_v = 10^5
dp = [[INF]*100100 for _ in range(110)]

# 初期条件
dp[0][0] = 0

# DPループ
for i in range(N):
    weight, value = map(int, input().split())
    for sum_v in range(10**5+1):

        # i番目の品物を選ぶ場合
        if sum_v - value >= 0:
            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - value] + weight)

        # i番目の品物を選ばない場合
        dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

# 最適値の出力
res = 0
for sum_v in range(10**5+1):
    if dp[N][sum_v] <= W:
        res = sum_v
print(res)

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

typedef long long ll;

#define N 100010
#define INF 1e9

int n,K;
int A[N],l[N],r[N],kind[N],q[N][2],fa[N];
struct Edge{
 	int next,to;
 }edge[N*2];
int head[N],tot;
bool flag[N],Get;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void Addedge(int u,int v)
{
	tot++;edge[tot].next=head[u];edge[tot].to=v;head[u]=tot;
	tot++;edge[tot].next=head[v];edge[tot].to=u;head[v]=tot;
}

void DFS(int k)
{
	if(Get)
		return;
	flag[k]=true;
	for(int i=head[k];i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(flag[v])
			continue;
		fa[v]=k;
		DFS(v);
		if(kind[v]!=-1)
		{
			if(kind[k]==-1)
				kind[k]=(kind[v]^1);
			else if(kind[k]!=(kind[v]^1))
			{
				Get=true;
				return;
			}
		}
		int nowl=l[v]-1,nowr=r[v]+1;
		if(nowl>r[k]||nowr<l[k])
		{
			Get=true;
			return;
		}
		else
		{
			l[k]=max(l[k],nowl);
			r[k]=min(r[k],nowr);
		}
	}
}

void DFS1(int k,int now)
{
	for(int i=head[k];i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==fa[k])
			continue;
		if(now+1>=l[v]&&now+1<=r[v])
		{
			A[v]=now+1;
			DFS1(v,A[v]);
		}
		else
		{	
			A[v]=now-1;
			DFS1(v,A[v]);
		}
	}
}
		
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{	
		l[i]=-INF;r[i]=INF;
	}
	for(int i=1;i<=n-1;i++)
	{
		int x=read(),y=read();
		Addedge(x,y);
	}
	K=read();
	memset(kind,-1,sizeof(kind));
	for(int i=1;i<=K;i++)
	{
		int x=read();
		A[x]=read();l[x]=A[x];r[x]=A[x];
		kind[x]=A[x]%2;
	}	
	DFS(1);
	if(Get)
		puts("No");
	else 
	{
		puts("Yes");
		A[1]=l[1];
		DFS1(1,A[1]);
		for(int i=1;i<=n;i++)
			printf("%d\n",A[i]);
	}
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
 
using namespace std;
 
int main () 
{
	
	int a, b, c, s2, s3, s1, g=0;
	cin >> a >> b >> c;
	
	if (a == b && c == b && a % 2 == 0)
	{
        cout << -1 << endl;
        return 0;
    }
    	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) 
    	{
            g++;
            s1 = (b/2)+(c/2);
            s2 = (c/2)+(a/2);
            s3 = (a/2)+(b/2);
        	a=s1;
        	b=s2;
        	c=s3;
    	}
    	cout << g << endl;	
return 0;
}
 
//functions
 

Measured memory_bytes: 256
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i%2
        if i == 101 and n >= 2**20:
            def findFactorRho(N):
                def gcd(a, b):
                    while b: a, b = b, a % b
                    return a
                def f(x, c):
                    return (x * x + c) % N
                for c in range(1, 99):
                    X, d, j = [2], 1, 0
                    while d == 1:
                        j += 1
                        X.append(f(X[-1], c))
                        X.append(f(X[-1], c))
                        d = gcd(abs(X[2*j]-X[j]), N)
                    if d != N:
                        if isPrimeMR(d):
                            return d
                        elif isPrimeMR(N//d): return N//d
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    return ret

def isPrimeMR(n):
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1
    
    L = [2, 7, 61] if n < 1<<32 else [2, 13, 23, 1662803] if n < 1<<40 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    for a in L:
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False
    return True


P = 10**9+7
D = {}
N = int(input())
A = [int(a) for a in input().split()]
t = 0
for a in A:
    t += pow(a, P-2, P)
    pf = primeFactor(a)
    for p in pf:
        if p in D:
            D[p] = max(D[p], pf[p])
        else:
            D[p] = pf[p]
s = 1
for f in D:
    s = (s * pow(f, D[f], P)) % P
print(s * t % P)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    a[i]--;
  }
  int cnt = 0;
  for(int i = 0; i < n; i++){
    int j = a[i];
    if(a[j] == i) cnt++;
  }
  cout << cnt/2 << endl;
  return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n;
int a[30],b[30],c[30];


int main()
{
    cin>>n;
    for (int i=1; i<=n; ++i)
        cin >> a[i];
    for (int i=1; i<=n; ++i)
        cin >> b[i];
    for (int i=1; i<n; ++i)
        cin >> c[i];
    int ans=0;
    for (int i=1; i<=n; ++i)
    {
        ans += b[a[i]];
        if (i>=1 && a[i] == a[i-1]+1)
            ans += c[a[i-1]];
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll pow (ll x, ll n){
    ll ans = 1;
    while(n>0){
        if(n & 1 == 1){
            ans *= x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int main(){
    int n ;   cin >> n;
    vint a(n);
    rep(i,n)    cin >> a[i];
    sort(a.begin(), a.end());
    int ans = a[n-1] - a[0];

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(2*n);
  for(auto &a:A)cin>>a;
  sort(ALL(A));
  ll ans=0;
  for(int i=0;i<2*n;i+=2){
    ans+=A[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n, k = gets.strip.split.map(&:to_i)
hs = gets.strip.split.map(&:to_i)
is_yoi = Array.new(n) { true }

k.times do
  a, b = gets.strip.split.map(&:to_i)
  if hs[a - 1] >= hs[b - 1] then
    is_yoi[b - 1] = false
  end
  if hs[a - 1] <= hs[b - 1] then
    is_yoi[a - 1] = false
  end
end

is_yoi.select! { |b| b }

puts is_yoi.size()


Measured memory_bytes: 23640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct D{
    bool operator<(const D& rhs) {
        return e < rhs.e;
    }
    int s, e;
    string name;
};

int main(void){
    while (1) {
        int n, q;
        cin >> n >> q;
        if (!n && !q) break;
        
        vector<D> data(n);
        for (int i = 0; i < n; i++) {
            int a,b;
            cin >> data[i].name >> a >> b;
            data[i].s = b-a+1;
            data[i].e = b;
        }
        sort(data.begin(), data.end());
        
        for (int i = 0; i < q; i++) {
            int x;
            cin >> x;
            
            for (int j = 0; j < n; j++) {
                if (data[j].s <= x && data[j].e >= x) {
                    cout << data[j].name << " " << x - data[j].s + 1 << endl;
                    j = n;
                    break;
                }
                if (j == n-1) cout << "Unknown" << endl;
            }
        }
    }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
ll const MOD=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X;
    cin>>X;
    for(int A=0;A<=200;A++){
        for(int B=A;B>=-200;B--){
            if(A*A*A*A*A-B*B*B*B*B==X){cout<<A<<" "<<B<<endl;exit(0);}
        }
    }
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int n,s;
long long a[100005],b[100005],ans;
int main()
{
	cin>>n>>s;
	for (int i=1;i<=n;++i) cin>>a[i]>>b[i];
	int l=1,r=n;
	while (l<=r)
	{
		if (s<=a[l])
		{
			ans+=a[r]-s;
			break;
		}
		if (s>=a[r])
		{
			ans+=s-a[l];
			break;
		}
		if (b[l]>=b[r])
		{
			ans+=a[r]-a[l];
			while (l<r && b[l]>=b[r]) b[l]+=b[r--];
		}
		else
		{
			ans+=a[r]-a[l];
			while (l<r && b[l]<b[r]) b[r]+=b[l++];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	int n,m;
	int p[10010];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	int count=0;
	int temp,temp1,temp2;
	llong int max,min;
	int len;
	int sum=0;
	//データの読み込み
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n;i++){
		if(i==0){
			max=p[0];
		}else{
			max=max(max,p[i]);
		}
		sum=sum+p[i];
	}
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%d",sum-max/2);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAirplane solver = new AAirplane();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAirplane {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int p = in.nextInt();
            int q = in.nextInt();
            int r = in.nextInt();
            out.println(Math.min(Math.min(p + q, p + r), q + r));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 20948
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int s1 = 0;
      int s2 = 0;
      int s3 = 0;
      int s = 0;
      cin >> s;
      s1 = s/100;
      s2 = (s-s1*100)/10;
      s3 = ((s-s1*100)-s2*10);
      cout << s1+s2+s3 << endl;
    }

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s int
	if _, err := fmt.Scan(&s); err != nil {
		panic(err)
	}

	hours := s / 3600
	minutes := (s % 3600) / 60
	seconds := (s % 3600) % 60
	fmt.Printf("%d:%d:%d\n", hours, minutes, seconds)
}



Measured memory_bytes: 1124
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

char in[8050];
vector <int> Vu[3];

int dp[8050];
bool isValid(int x, vector <int> Vu) {
	int s = 0;
	for (auto it : Vu) s += it;
	if (s % 2 != (x + 10000) % 2) return false;

	int v = (s - x) / 2;
	if (v < 0 || v > s) return false;

	int i, j;
	for (i = 0; i <= v; i++) dp[i] = 0;
	dp[0] = 1;
	for (auto it : Vu) {
		for (i = v; i >= it; i--) if (dp[i - it]) dp[i] = 1;
	}
	if (dp[v]) return true;
	return false;
}
int main() {
	scanf("%s", in);

	int X, Y, i;
	scanf("%d %d", &X, &Y);
	int d = 2, cur = 0;
	for (i = 0; in[i] != 0; i++) {
		if (in[i] == 'T') {
			if (cur != 0) Vu[d].push_back(cur);
			cur = 0;
			if (d == 0 || d == 2) d = 1;
			else d = 0;
		}
		else cur++;
	}
	if (cur) Vu[d].push_back(cur);
	if (Vu[2].size()) X -= Vu[2][0];

	if (!isValid(X, Vu[0])) return !printf("No\n");
	if (!isValid(Y, Vu[1])) return !printf("No\n");
	return !printf("Yes\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

struct node {
  node *right,*left,*p;
  int key;
};

node *root;

void insert(int k) {
  node *y = NULL;
  node *x = root;
  node *z;

  z = (node*)malloc(sizeof(node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;

  while(x!=NULL) {
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y==NULL) root = z;
  else {
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

void preorder(node *u) {
  if (u == NULL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

void inorder(node *u) {
  if (u == NULL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}
  
int main(){
  int n; cin >> n;
  while(n--) {
    string s;
    cin >> s;
    if(s=="insert") {
      int k; cin >> k;
      insert(k);
    } else {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 26424