akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int k;
	cin >> k;
	cout << ((k + 1) / 2 * (k / 2)) << endl;
	return 0;
}
 

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

int main(){
	string s,t;
	cin>>s>>t;
	int i;
	int pns=0;
	int num=0;
	int wh=0;
	int j=0;
	int flag=-1;
	for(i=0;i<s.size();i++){
		if(s[i]==t[j]){
			j++;
		}
		else if(s[i]=='?'){
			int tem=0;
			for(int k=i;k<i+t.size();k++){
				if(s[k]==t[tem]) tem++;
				else if(s[k]=='?')	tem++;
				if(tem==t.size()){
					if(k>=pns){		
						pns=k;			
						flag=k+1-t.size();
					}

				}
			}
			j++;
		}	
		else {
			j=0;
			wh=0;
		}
		if(j==t.size()){
			if(i>=pns){	
				pns=i;
				flag=i+1-t.size();
			}

			j=0;
			wh=0;
		}
	}
	if(flag==-1) cout<<"UNRESTORABLE"<<endl;
	else{
		j=0;
		for(i=flag;i<flag+t.size();i++){
			s[i]=t[j++];
		}
		for(i=0;i<s.size();i++){
			if(s[i]=='?') cout<<'a';
			else cout<<s[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 256
N, P = map(int, input().split())
S = input()

T = [0] * (N + 1)
T[0] = 0
e = 1
for i in range(N):
  T[i + 1] = T[i] + int(S[N - i - 1]) * e
  T[i + 1] %= P
  e *= 10
  e %= P

a = {}
for i in range(N + 1):
  if T[i] in a:
    a[T[i]] += 1
  else:
    a[T[i]] = 1

num = 0
if P % 2 == 0 or P % 5 == 0:
  for i in range(N):
    if int(S[i]) % P == 0:
      num += 1 + i
else:
  for k in a:
    num += a[k] * (a[k] - 1) // 2

print(num)

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

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if( (r <= x && x <= W-r) && (r <= y && y <= H-r) ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 1160
n = int(input())
lis = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n+1):
    s = str(i)
    l = int(s[0])
    r = int(s[-1])
    lis[l][r] += 1
ans = 0
for i in range(10):
    for j in range(10):
        if i == j:
            ans += lis[i][j] ** 2
        else:
            ans += lis[i][j] * lis[j][i]
print(ans)

Measured memory_bytes: 40428
k = int(input())
if k % 10 in [0, 2, 4, 5, 6, 8]:
  print("-1")
else:
  c = 1
  r = 7 % k
  while True:
    if r == 0:
      break
    else:
      c += 1
      r = (10*r+7) % k
  print(c)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;
const int MAXN = 1000005;

int n, dp[MAXN][2];
string s;

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

	cin >> s;
	reverse(s.begin(), s.end());
	s.push_back('0');
	
	n = s.size();
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < 2; j++) {
			int x = s[i] - '0' + j;
			if (x % 10 == 0) {
				dp[i][j] = dp[i + 1][x == 10];
			}
			else {
				dp[i][j] = min(dp[i + 1][0] + x, dp[i + 1][1] + (10 - x));
			}
		}
	}
	
	cout << dp[0][0] << '\n';

	return 0;
}

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
const int mod = 1e9+9;

const int yu = 1e5+103;
int n, k;
int dp[yu];
int a[yu];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int pqr = abs(a[i]-a[i+1])+f(i+1);
	for(int j=2; j<=k; j++){
		if(i+j<n) pqr = min(pqr, abs(a[i]-a[i+j])+f(i+j));
	}
	return dp[i]=pqr;
}
int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}


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

int partition(int A[], int p, int r){
  int x = A[r];
  int i = p - 1;
  for(int j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i+1;
}

int main(){
  int n;
  cin >> n;
  int A[100001];
  for(int i=0;i<n;i++) cin >> A[i];
  int p = partition(A, 0, n-1);
  for(int i=0;i<n;i++){
    if(i == p) cout << '[' << A[i] << ']' << " ";
    else if(i != n-1) cout << A[i] << " ";
    else cout << A[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3404
#include <stdio.h>
#include <string.h>

int heaps[2000000], h = 0;

void max_heapify(int a[], int i) {
  int largest, b;
  int l = i * 2;
  int r = i * 2 + 1;

  if (l <= h && a[l] > a[i])
    largest = l;
  else
    largest = i;
  if (r <= h && a[r] > a[largest])
    largest = r;

  if (largest != i) {
    b = a[i];
    a[i] = a[largest];
    a[largest] = b;
    max_heapify(a, largest);
  }
}

void check_maxheap(int a[], int i, int parent) {
  int b;
  while (i > 1 && a[i] > a[i / 2]) {
    b = a[i];
    a[i] = a[i / 2];
    a[i / 2] = b;
    i = i / 2;
  }
}

void insert(int a[], int key, int i) {
  int parent;
  a[i] = key;
  parent = i / 2;

  check_maxheap(a, i, parent);
}

int extract(int a[], int i) {
  int parent;
  int max = a[1];
  a[1] = a[i];
 
  return max;
}

int main(void) {
  int key;
  char order[10];

  while (1) {
    scanf("%s", order);
    if (strcmp(order, "insert") == 0) {
      scanf("%d", &key);
      h++;
      insert(heaps, key, h);
    }
    else if (strcmp(order, "extract") == 0) {
      printf("%d\n", extract(heaps, h));
      h--;
      max_heapify(heaps, 1);
    }
    else
      break;
  }

  return 0;
}



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

int main() {
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2 ;
	int x3,y3,x4,y4;
	x3 = x2 - y2 + y1;
	y3 = y2 + x2 - x1;
	x4 = x1 - y2 + y1;
	y4 = y1 + x2 - x1;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}

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

int main(){
	int n;
	bool p[N];

	for(int i = 0; i < N; i++) p[i] = 0;
	for(int i = 3; i < N; i += 2) p[i] = 1;
	p[2] = 1;
	for(int i = 0; i < N; i++){
		if(!p[i]) continue;
		for(int j = 2 * i; j < N; j += i) p[j] = 0;
	}
	
	while(cin >> n, n){
		int j = 0;
		for(int i = n + 1; i <= 2 * n; i++){
			if(p[i]) j++;	
		}	
		cout << j << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include <iostream>

#include <fstream>

#include <vector>
#include <set>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#include <algorithm>
#include <iomanip>
#include <cmath>
#include <random>
#include <cstdlib>
#include <ctime>
#include <utility>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define F first
#define S second
#define forcin(n, a) for(int i = 0; i < n; ++i) {cin >> a[i];}
#define forcout(n, a) for(int i = 0; i < n; ++i) {cout << a[i] << " ";}
#define PI acos(-1)
#define forup(st, fin) for(int i = st; i < fin; ++i)
#define fordown(st, fin) for(int i = st; i >= fin; --i)
#define reverse_all(v) reverse(v.begin(), v.end())
#define sort_all(v) sort(v.begin(), v.end())
#define sort_allr(v) sort(v.rbegin(), v.rend())

///#define cin in
///#define cout out
///#define int long long

const ll MAXL = 1e18;
const int N = 10005000;

vector<ll> add, h, d;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    int a, b;
    cin >> a >> b;
    int ans = a;
    if (b < a) ans--;
    cout << ans << "\n";
    return 0;
}
/*
 2 1 1
10 15
6 1

3 0 3
10 8
7 11
5 2
 */

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    char moji[] = s.toCharArray();
    long r = 0,g = 0,b = 0;
    for(int i = 0;i<n;i++){
      if(moji[i]=='R'){
        r++;
      }else if(moji[i]=='G'){
        g++;
      }else{
        b++;
      }
    }
    long count = r * g * b;
    for(int i = 0;i<n-2;i++){
      for(int j = i + 1;2*j - i < n;j++){
        if(moji[i] != moji[j] && moji[j] != moji[2*j-i] && moji[i] != moji[2*j-i]){
          count--;
        }
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 36296
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> Graph(n, vector<int>(0));
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }

  queue<int> que;
  vector<int> dist(n, -1);
  vector<int> res(n);
  dist[0] = 0;
  que.push(0);

  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for(int nex : Graph[v]) {
      if(dist[nex] != -1) continue;
      dist[nex] = dist[v]+1;
      res[nex] = v;
      que.push(nex);
    }
  }

  cout << "Yes" << endl;
  reps(i,1,n) cout << res[i] + 1 << endl;
  return 0;
}

Measured memory_bytes: 10648
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}
map<int , int >mp;
set<int  > st;
multiset<string> :: iterator it;
deque <char> q ;
int vis [10000000];
pair<int,int> a[2020];
int main()
{
    fast ;
    char c ;
    cin >> c;
    if(c>='A'&&c<='Z')
        {
            cout <<"A\n";
        }
    else
        {
         cout <<"a\n";
        }
}





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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
        int k = sc.nextInt();
        boolean ok = false;
        for (int mask = 0; mask < (int) Math.pow(3, k); mask++) {
            String m = Integer.toString(mask, 3);
            while (m.length() < k) m = "0" + m;
            int x = a; int y = b; int z = c;
            for (int i = 0; i < m.length(); i++) {
                if (m.charAt(i) == '0') x *= 2;
                if (m.charAt(i) == '1') y *= 2;
                if (m.charAt(i) == '2') z *= 2;
            }
            ok |= (z > y && y > x);
        }
        out.println(ok ? "Yes" : "No");
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 36988
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 998244353;
 
int main(){
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  cout << (1000 - n%1000)%1000;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
int n;
int arr[MAX_N];
int leftt[MAX_N], rightt[MAX_N];
void solve(){
    memset(leftt, -1, sizeof(leftt));
    memset(rightt, -1, sizeof(rightt));
    int i = 0;
    stack<int> s;
    s.push(0);
    for(i = 1; i < n; i++){
        if(s.empty()){
            s.push(i);
            continue;
        }
        while (!s.empty() && arr[s.top()] > arr[i]) {
            leftt[s.top()] = i;
            s.pop();
        }
        s.push(i);
    }
    while(!s.empty())
        s.pop();
    s.push(n - 1);
    for(i = n - 2; i >= 0; i--){
        if(s.empty()){
            s.push(i);
            continue;
        }
        while (!s.empty() && arr[s.top()] > arr[i]) {
            rightt[s.top()] = i;
            s.pop();
        }
        s.push(i);
    }
    long sum = 0;
    for(i = 0; i < n; i++){
        int x, y;
        if(leftt[i] == -1)
            x = n;
        else
            x = leftt[i];
        y = rightt[i];
        //cout << x << " " << y << "\n";
        long long how_many = (long long)(i - y) * (x - i);
        sum += how_many * arr[i];
    }
    cout << sum << "\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int i = 0;
    for(i = 0; i < n; i++)
        cin >> arr[i];
    solve();
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
using namespace std;
main()
{ 	int n,ans=0,x=1,a[10000],k;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int j=1;j<=n;j++)
	{
		for(k=j+1;k<=n;k++)
		{
			ans=ans+a[j]*a[k];
			
		}
	}
	cout<<ans;
}

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

using namespace std;
#define EPS 10e-12

int n, hx, hy, dx, dy;
int cx[22], cy[22];
//double c[21];
bool flag;

double dstnc(int ax, int ay, int bx, int by){
    return sqrt((double)((bx-ax)*(bx-ax) + (by-ay)*(by-ay)));
}

int dfs(int S, double t, int v){
    for(int i = 0; i < n; i++){
        if(!(S & (1<<i)) && (dstnc(cx[v],cy[v],cx[i],cy[i]) + t + EPS > dstnc(dx,dy,cx[i],cy[i]))) return 0;
    }
    int flag1 = false;
    for(int i = 0; i < n; i++){
        if(!(S & (1<<i))) flag1 = true;
    }
    if(!flag1) return 1;
    int ret = 0;
    for(int i = 0; i < n; i++){
        if(!(S & (1<<i))) ret = dfs(S | (1<<i), t + dstnc(cx[v],cy[v],cx[i],cy[i]), i);
        if(ret) return 1;
    }
    return 0;
}

int main(){
    
    while(cin >> n >> hx >> hy >> dx >> dy, n){
        for(int i = 0; i < n; i++) cin >> cx[i] >> cy[i];
        //for(int i = 0; i < n; i++) c[i] = sqrt((double)((dx-cx[i])*(dx-cx[i]) + (dy-cy[i])*(dy-cy[i])));
        cx[21] = hx;
        cy[21] = hy;
        flag = dfs(0,0,21);
        
        
        if(flag)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    
    return 0;
}

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

int main() {
string s;
cin >> s;
int s1 = stoi(s.substr(0,2));
int s2 = stoi(s.substr(2,2));
bool isM1 = false,isM2 = false;
 
 if(s1 >= 1 && s1 <= 12) isM1 = true;
if(s2 >= 1 && s2 <= 12) isM2 = true;
if(isM1 && isM2)cout << "AMBIGUOUS" << endl;
else if(isM1) cout << "MMYY" << endl;
else if(isM2) cout << "YYMM" << endl;
else cout << "NA" << endl;

}
  


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

int main(int argc, const char * argv[]) {
    char a[200];
    int i,alen;
    while(gets(a)!=NULL){
        alen=(int)strlen(a);
        for(i=0;i<alen;i++){
            if('a'<=a[i]&&a[i]<='z')
                a[i]-='a'-'A';
        }
        printf("%s\n",a);
    }
    
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<ll, int> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  REP(i, N)
  cin >> A[i];
  vector<int> B(M), C(M);
  REP(i, M)
  cin >> B[i] >> C[i];
  vector<P> card; // { first: カードの数字, second: カードの枚数 }
  REP(i, N)
  card.push_back(P(A[i], 1));
  REP(i, M)
  card.push_back(P(C[i], B[i]));
  sort(ALL(card));
  reverse(ALL(card)); // カードの数字の降順(大きい順)にソート O((N+M)log(N+M))
  int cnt = N;
  ll ans = 0;
  REP(i, card.size())
  {
    int t = min(cnt, card[i].second);
    ans += card[i].first * t;
    cnt -= t;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7664
import numpy as np
n = int(input())
a = [int(input()) for i in range(n)]
max = np.max(a)
max_pos = np.argmax(a)
b = [max]*n
b[max_pos] = np.max(a[:max_pos]+a[max_pos+1:])
for key in b:
    print(key)

Measured memory_bytes: 26168
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

inline int opposite(int self) {
	return (self + 1) % 2;
}

int main() {
	int n, k;
	cin >> n >> k;
	VI a(n);
	REP(i, n) { cin >> a[i]; }

	VI2D dp(k + 1, VI(2));

	// dp[残り石数][手番]
	REP(i, k + 1) {
		REP(j, 2) {
			if(i == 0) {
				dp[0][j] = opposite(j);
				continue;
			}
			bool win = false;
			dp[i][j] = opposite(j);
			REP(m, n) {
				if(i < a[m]) {
					continue;
				}
				win = dp[i - a[m]][opposite(j)] == j;
				if(win) {
					dp[i][j] = j;
					break;
				}
			}
		}
	}

	cout << (dp[k][0] ? "Second" : "First") << endl;

	return 0;
}


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

int main() {

  long long A, B;
  cin >> A >> B;
  
  long long saisho = 1;

  for(int i = 2; i <= min(A, B); i++) {
    if(A%i == 0 && B%i == 0) saisho = i;
  }
  
  long long ans = A*B/saisho;
  
  cout << ans << endl;
  
}

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

int main(int argc, const char * argv[]) {
    int S;
    int h,m,s;
    
    cin >> S;
    
    h = S / 3600;
    m = (S % 3600)/ 60;
    s = S % 3600 % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> p(n+1);
    int cnt = 0;
    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i];
    }
    for ( int i = 1; i <= n; ++i ) {
        if ( i == n && p[i] == i ) {
            ++cnt;
            break;
        }
        if ( p[i] == i ) {
            swap(p[i+1], p[i]);
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});
//条件式が真ならwhileの中身を回し続ける

int h,a;

int main() {
	cin >> h >> a;
	if (h % a == 0)cout << h / a << endl;
	else cout << h / a + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
const int N = 1e5 + 5 ;
const int K = 50 ;
const ll mod =  1e9+7 ;
#define pb push_back
#define ft first 
#define sd second 
ll dp[102][N];
int main(){
    int n;
    int W;
    cin >> n >> W;
    int w[n+4], v[n+4];
    for(int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=1;i<=N-1;i++) dp[0][i]= 2e18;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=N-1;j++) {
            dp[i][j] = dp[i-1][j];
            if(j >= v[i]) {
                dp[i][j] = min(dp[i][j],w[i]+dp[i-1][j-v[i]]);
            }
        }
    }
    int ans = 0;
    for(int j=0;j<=100000;j++) {
        if(dp[n][j] <= W) {
            ans = max(ans, j);
        }
    }
    cout << ans << '\n';
    return 0;   
}

Measured memory_bytes: 79104
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

const int M = (1 << 10) + 1 ; 
const int L = 1e5 + 1 ;

int dp[M][L];

void solve()
{

    int n ;
    cin >> n ;
    int V[n + 1] , W[n + 1];
    rep(i , n) cin >> V[i + 1] >> W[i + 1];

    for(int i = 1 ; i <= min(M - 2 , n) ; ++i){
        for(int l = 0 ; l < L ; ++l){
            dp[i][l] = max(dp[i][l] , dp[i/2][l]);
            if(l >= W[i]) dp[i][l] = max(dp[i][l] , dp[i/2][l - W[i]] + V[i]);
        }
    }

    int q;
    cin >> q;
    while(q--){
        int v, l;
        cin >> v >> l ;
        if(v <= (M - 2)){
            cout << dp[v][l] << '\n';
        } else {
            int u = v , ans , k;
            vector<pii> s;
            while(u > (M - 2)) s.pb({V[u] , W[u]}) , u /= 2 ;
            k = sz(s);
            ans = dp[u][l] ;
            rep(msk , 1 << k){
                int tw = 0 , tv = 0;
                rep(i , k){
                    if(msk >> i & 1){
                        tw += s[i].ss;
                        tv += s[i].ff;
                    }
                }
                if(tw <= l){
                    ans = max(ans , dp[u][l - tw] + tv);
                }
            }
            cout << ans << '\n';
        }
    }
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 806960
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,k;
	cin>>n>>k;
	int grid[2][4000][4000]={0};
	for(int i = 0; i < n; i++){
		int x,y;
		char c;
		cin>>x>>y>>c;
		x%=2*k;
		y%=2*k;
		if(c=='B'){
			grid[0][x][y]++;
			grid[0][x+2*k][y]++;
			grid[0][x][y+2*k]++;
			grid[0][x+2*k][y+2*k]++;
		}else{
			grid[1][x][y]++;
			grid[1][x+2*k][y]++;
			grid[1][x][y+2*k]++;
			grid[1][x+2*k][y+2*k]++;
		}
	}
	int sum[2][4000][4000]={0};
	for(int color = 0; color < 2; color++){
		for(int i = 0; i < 4*k; i++){
			for(int j = 0; j < 4*k; j++){
				sum[color][i][j] = (j==0?0:sum[color][i][j-1]) + grid[color][i][j];
			}
		}
		for(int i = 1; i < 4*k; i++){
			for(int j = 0; j < 4*k; j++){
				sum[color][i][j] += sum[color][i-1][j];
			}
		}
	}

	// for(int i = 0; i < 2*k; i++){
	// 	for(int j = 0; j < 2*k; j++){
	// 		cout << grid[0][i][j] << " ";
	// 	}printf("\n");
	// }
	// printf("\n\n\n");
	// for(int i = 0; i < 2*k; i++){
	// 	for(int j = 0; j < 2*k; j++){
	// 		cout << sum[0][i][j] << " ";
	// 	}printf("\n");
	// }
	int ans = 0;
	for(int i = 0; i < 2*k; i++){
		for(int j = 0; j < 2*k; j++){
			int res = sum[0][i+k][j+k] - sum[0][i][j+k] - sum[0][i+k][j] + sum[0][i][j];
			res += sum[1][i+k][j+2*k] - sum[1][i][j+2*k] - sum[1][i+k][j+k] + sum[1][i][j+k];
			res += sum[1][i+2*k][j+k] - sum[1][i+2*k][j] - sum[1][i+k][j+k] + sum[1][i+k][j];
			res += sum[0][i+2*k][j+2*k] - sum[0][i+2*k][j+k] - sum[0][i+k][j+2*k] + sum[0][i+k][j+k];
			ans = max(ans,res);
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;

inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int h, w, k;
    cin >> h >> w >> k;

    vector<string> c(h);

    rep(i,h){
        cin >> c[i];
    }

    int res = 0;

    for(int bit1 = 0; bit1 < 1 << h; ++bit1){
        for(int bit2 = 0; bit2 < 1 << w; ++bit2){
            int cnt = 0;
            rep(i,h){
                if(bit1 & 1 << i) continue;
                rep(j,w){
                    if(bit2 & 1 << j) continue;
                    cnt += (c[i][j] == '#');
                } 
            }
            res += (cnt == k);
        }
    }

    cout << res << '\n';

    return (0);
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  double xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  double x[1010], y[1010], r[1010];
  x[0] = xs, y[0] = ys, r[0] = 0;
  x[n + 1] = xt, y[n + 1] = yt, r[n + 1] = 0;
  REP1(i, n) cin >> x[i] >> y[i] >> r[i];
  double cost[1010][1010];
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= n + 1; ++j) {
      double res = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
      res -= (r[i] + r[j]);
      if (res < 0) res = 0;
      cost[i][j] = res;
    }
  }
  double d[1010];
  bool used[1010];
  for (int i = 0; i <= n + 1; ++i) {
    d[i] = 1e18;
    used[i] = false;
  }
  d[0] = 0;
  while (true) {
    int v = -1;
    for (int u = 0; u <= n + 1; ++u) {
      if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }
    if (v == -1) break;
    used[v] = true;
    for (int u = 0; u <= n + 1; ++u) {
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
  printf("%.10f\n", d[n + 1]);
  return 0;
}

Measured memory_bytes: 8192
def main():
    A, B, C, K = map(int, input().split())

    # TLE(A, B, C, K)
    f(A, B, C, K)


def f(A, B, C, K):
    """
    1: (A,B,C) = (    B  C,  A     C,  A  B   )
    2: (A,B,C) = (2A  B  C,  A 2B  C,  A  B 2C)
    3: (A,B,C) = (2A 3B 3C, 3A 2B 3C, 3A 3B 2C)
    4: (A,B,C) = (6A 5B 5C, 5A 6B 5C, 5A 5B 6C)
    """
    if A == B == C:
        print(0)
        return

    ans = int((B - A) * (-1) ** (K - 1))
    if abs(ans) > 10 ** 18:
        print("Unfair")
    else:
        print(ans)


def TLE(A, B, C, K):
    for i in range(K):
        bc = B + C
        ab = A + B
        ac = A + C
        print(A, B, C, bc, ab, ac, sep="\t")
        A = bc
        B = ac
        C = ab

    ans = A - B
    if abs(ans) > 10 ** 18:
        print("Unfair")
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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 (b < a) { a = b; return 1; } return 0; }

bool check(const vector<ll>& t) {
    ll prev = -1;
    for (const auto e : t) {
        if (prev > e) {
            return false;
        }
        prev = e;
    }
    return true;
}


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

    ll n;
    cin >> n;

    vector<ll> p(n);
    for (auto& e : p) {
        cin >> e;
    }

    if (check(p)) {
        cout << "YES" << "\n";
        return 0;
    }

    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            if (i == j) {
                continue;
            }
            vector<ll> t(n);
            copy(p.begin(), p.end(), t.begin());
            swap(t[i], t[j]);
            if (check(t)) {
                cout << "YES" << "\n";
                return 0;
            }
        }
    }

    cout << "NO" << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<sstream>
#include<cstdlib>
using namespace std;
typedef pair<int,int> P; 
void split(vector<int>& vec,string line)
{
  stringstream ss;
  ss << line;
  for(int i=0;i<ss.str().size();i++)
    {
      string s;
      if((ss >>  s).fail())
	break;
      vec.push_back((atoi)(s.c_str()));
    }  
}

bool cmp(const P& a,const P& b)
{
  if(a.second != b.second)
    return a.second > b.second;
  return a.first < b.first;

}

int main()
{
  int n;
  while(cin >> n,n)
    {
      cin.ignore();
      vector<P> info;
      for(int i=0;i<n;i++)
	{
	  string line;
	  getline(cin,line);
	  vector<int> vec;
	  split(vec,line);

	  int total,cnt;
	  total = 0,cnt = 1;
	  for(int j=1;j<vec.size();cnt++)
	    {
	     
	      if(cnt != 10)
		{
		  if(vec[j] == 10)
		    {
		      total += 10;
		      total += vec[j+1]+vec[j+2];
		      j++;
		    }
		  else 
		    {
		      if(vec[j] + vec[j+1] == 10)
			{
			  total += 10+vec[j+2];
			}
		      else 
			{
			  total += vec[j]+vec[j+1]; 
		      
			}
		      j+=2;
		    }
		}
	      else
		{
		  if(vec[j]+vec[j+1] < 10)
		    {
		      total += vec[j]+vec[j+1];
		    }
		  else 
		    {
		      total += vec[j]+vec[j+1]+vec[j+2];
		    }

		  break;
		}

	    }
	  info.push_back(P(vec[0],total)); 

	}

      sort(info.begin(),info.end(),cmp);    
      for(int i=0;i<info.size();i++)
	cout << info[i].first << " " <<info[i].second << endl;

    }
  return 0;
}

Measured memory_bytes: 1260
#include <stdio.h>

int main() {
	int a, b;
	scanf("%d\n %d", &a, &b);
	
	if (a == 1 && b == 2 || a == 2 && b == 1) {
		printf ("3");
	} else if (a == 1 && b == 3 || a == 3 && b == 1) {
		printf ("2");
	} else {
		printf ("1");
	}
	
	return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,vt[200001];

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        int x;
        scanf("%d",&x);
        vt[x]=i;
    }
}

void process()
{
    int mi=INT_MAX,dem=0;
    for (int i=1;i<=n;++i)
    {
        if (vt[i]<mi)
        {
            mi=vt[i];
            dem++;
        }
    }
    cout<<dem;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

int key[7];

void N(){
	int change = key[1];
	key[1] = key[2];
	key[2] = key[6];
	key[6] = key[5];
	key[5] = change;
}

void S(){
	int change = key[1];
	key[1] = key[5];
	key[5] = key[6];
	key[6] = key[2];
	key[2] = change;
}

void W(){
	int change = key[1];
	key[1] = key[3];
	key[3] = key[6];
	key[6] = key[4];
	key[4] = change;
}

void E(){
	int change = key[1];
	key[1] = key[4];
	key[4] = key[6];
	key[6] = key[3];
	key[3] = change;
}

int main(void){
	int i;
	char str[105];
	int math, top, flont;
	
	for(i=0;i<6;i++){
		scanf("%d", &key[i+1]);
	}
	
	scanf("%d", &math);
	
	for(i=0;i<math;i++){
		scanf("%d %d", &top, &flont);
		if(top == key[1]){
		
		}else if(top == key[2]){
			N();
		}else if(top == key[3]){
			W();
		}else if(top == key[4]){
			E();
		}else if(top == key[5]){
			S();
		}else if(top == key[6]){
			N();
			N();
		}
		
		if(flont == key[2]){
			printf("%d\n", key[3]);
		}else if(flont == key[3]){
			printf("%d\n", key[5]);
		}else if(flont == key[4]){
			printf("%d\n", key[2]);
		}else if(flont == key[5]){
			printf("%d\n", key[4]);
		}
	}
	
	return 0;
	
}


Measured memory_bytes: 2080
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
int n,m;
int s[200000],t[200000];
vector<int> v[700];
double e[700],ans,ma;
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>s[i]>>t[i];
        v[s[i]].push_back(t[i]);
    }
    for(int i=n-1;i;i--){
        for(int j=0;j<v[i].size();j++){
            e[i]+=(1.0+e[v[i][j]])/v[i].size();
        }
    }
    ans=e[1];
    for(int i=1;i<n;i++){
        if(v[i].size()==1)continue;
        ma=-1.0;
        e[i]=0.0;
        for(int j=0;j<v[i].size();j++){
            if(ma<e[v[i][j]]){
                e[i]+=(ma+1.0)/(v[i].size()-1.0);
                ma=e[v[i][j]];
            }else e[i]+=(e[v[i][j]]+1.0)/(v[i].size()-1.0);
        }
        for(int k=i-1;k;k--){
            e[k]=0.0;
            for(int j=0;j<v[k].size();j++){
                e[k]+=(1.0+e[v[k][j]])/v[k].size();
            }
        }
        ans=min(ans,e[1]);
    }
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

vector<int> dy = { 0,0,1,-1 };
vector<int> dx = { 1,-1,0,0 };

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

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

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

//Greatest Common Divisor
long long GCD(long long a, long long b) {
	return ((b == 0) ? a : GCD(b, a % b));
}

int main() {
	ll N, K; cin >> N >> K;
	cout << 3 * (N - GCD(N, K)) << endl;

	

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	set<int> s = { a, b, c, d }, ss = { 1, 9, 7, 4 };
	if (s == ss) cout << "YES\n";
	else cout << "NO\n";

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=100000;

int main(){
    
    int a;
    cin >> a;
    cout << 180*(a-2)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
using namespace std;

map<int,int> a;
int main() {
	int N;
	cin >> N;
	for (size_t i = 0; i < N; i++)
	{
		int v;
		cin >> v;
		if (a.count(v) == 0) {
			a[v] = 1;
		}
		else a[v]++;
	}

	int r = 0;
	for (std::pair<int, int> v: a)
	{
		if (v.first != v.second) {
			if (v.second >= v.first)r += v.second - v.first;
			else r += v.second;
		}
	}

	cout << r;

	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}
int n,w;
int a[105];
int v[105];
ll dp[105][100005];
ll solve(int index, int weight) {
    if (weight > w)
        return INT_MIN;
    if (index == n)
        return 0;
    if (dp[index][weight] != -1) {
        return dp[index][weight];
    }
    return dp[index][weight] = max(solve(index + 1, weight), solve(index + 1, weight + a[index]) + v[index]);
}

int main() {
    IO;
    cin >> n >> w;
    for (int i = 0; i < 100; i++)
        for (int j = 0; j < w; j++)
            dp[i][j] = -1;
    for (int i = 0; i < n; i++)
        cin >> a[i] >> v[i];
    cout << solve(0,0);
    return 0;
}


Measured memory_bytes: 80128
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> X(N);
	for(int i = 0; i < N; ++i) cin >> X[i];
	vector<int> Y = X;
	sort(ALL(Y));
	for(int i = 0; i < N; ++i) {
		if(X[i] <= Y[N / 2 - 1]) {
			cout << Y[N / 2] << endl;
		} else {
			cout << Y[N / 2 - 1] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3712
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int H,W,h,w,ans[555][555];
bool rev;
int main()
{
	get2(H,W);get2(h,w);
	if(H%h==0&&W%w==0)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	if(H%h==0)
	{
		swap(H,W),swap(h,w);
		rev=1;
	}
	int a=500*500,b=a-a*h-1;
	for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)
	{
		if(i%h)ans[i][j]=a;
		else ans[i][j]=b;
	}
	if(!rev)
	{
		for(int i=1;i<=H;i++)
		{
			for(int j=1;j<=W;j++)printf("%d ",ans[i][j]);
			puts("");
		}
	}
	else
	{
		for(int j=1;j<=W;j++)
		{
			for(int i=1;i<=H;i++)printf("%d ",ans[i][j]);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 3200