akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
  int K;
  while(scanf("%d", &K) > 0){
    vector<bool> visited(K, false);
    int len = 1, num = 7 % K;

    while(num and !visited[num]){
      visited[num] = true;
      num = (num*10 + 7)%K;
      len++;
    }

    if(!num) printf("%d\n", len);
    else printf("-1\n");
  }
}


Measured memory_bytes: 3884
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    X=ii()

    ans = 0
    for i in range(2,10):
        if i*200 <= X <= (i+1)*200-1:
            ans = 8-i+2
    
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 61792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
n, k, q = map(int, input().split())
a = []

for i in range(n):
    a.append(k - q)

for i in range(q):
    b = int(input())
    a[b - 1] += 1

for i in range(n):
    if a[i] > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 7848
# できるだけ点数が多いほうが嬉しいので、10の倍数にならないように低い点数を引いていく
n = int(input())
arr = list(sorted([int(input()) for _ in range(n)]))
s = sum(arr)
if s % 10 != 0:
    print(s)
else:
    for a in arr:
        if a % 10 == 0:
            continue
        else:
            print(s - a)
            exit()
    print(0)


Measured memory_bytes: 38384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>

#define second S
#define first F

using namespace std;

const int N=3e6+5;
typedef long long ll;
const ll INF=1e12;
int main()
{
    int n;
    int a,l,ans;
    cin >> n;
    cin >> l;
    ans=0;
    for(int i=1;i<n;i++)
    {
        cin >> a;
        if(a==l)
        {
            a=-1;
            ans++;
        }
        l=a;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
//AtCoder ABC100 C - *3 or /2
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
ll cnt(ll v){
    ll r=0;
    while(v%2==0){
        v/=2;
        ++r;
    }
    return r;
}
int main() {
    ll N; cin>>N;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }
    ll ans=0;
    for(const auto& a:an){
        ans += cnt(a);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

const int MX = 301, md = 998244353;

char s[MX];
int dp[MX][MX][MX], f[MX][MX][MX];

void upd(int e0, int e1, int f0, int f1) {
	int& val = dp[e0][e1][f0];
	val = max(val, f1);
}

int main() {
	ignore = scanf("%s", s);
	
	int n = strlen(s);
	
	memset(dp, -1, sizeof dp);
	
	dp[0][0][0] = 0;
	for (int e0 = 0; e0 < MX; e0++)
		for (int e1 = 0; e1 < MX; e1++)
			for (int f0 = 0; f0 < MX; f0++) {
				if (dp[e0][e1][f0] == -1) continue;
				
				int f1 = dp[e0][e1][f0];
				
				// both free
				if (f0 + f1 >= 2) {
					if (f0 > 0) upd(e0 + 1, e1, f0 - 1, f1);
					if (f1 > 0) upd(e0, e1 + 1, f0, f1 - 1);
				}
				
				// both fixed
				if (e0 + e1 + f0 + f1 + 1 < n) {
					int x = s[e0 + e1 + f0 + f1] - '0';
					int y = s[e0 + e1 + f0 + f1 + 1] - '0';
					
					if (x != y) {
						upd(e0 + 1, e1, f0, f1 + 1);
						upd(e0, e1 + 1, f0 + 1, f1);
					}
					else if (x == 0) {
						upd(e0 + 1, e1, f0 + 1, f1);
					}
					else {
						upd(e0, e1 + 1, f0, f1 + 1);
					}
				}
				
				// one free, one fixed
				if (f0 + f1 > 0 && e0 + e1 + f0 + f1 < n) {
					int x = s[e0 + e1 + f0 + f1] - '0';
					
					if (x == 0) {
						upd(e0 + 1, e1, f0, f1);
						
						if (f1 > 0) upd(e0, e1 + 1, f0 + 1, f1 - 1);
					}
					else {
						upd(e0, e1 + 1, f0, f1);
						
						if (f0 > 0) upd(e0 + 1, e1, f0 - 1, f1 + 1);
					}
				}
			}
	
	int ans = 0;
	for (int e0 = 0; e0 < MX; e0++)
		for (int e1 = 0; e1 < MX; e1++) {
			int f0 = -1, f1 = -1;
			for (int x0 = 0; x0 < MX; x0++) {
				int x1 = dp[e0][e1][x0];
				if (x1 != -1 && x0 + x1 > f0 + f1) {
					f0 = x0;
					f1 = x1;
				}
			}
			
			if (f0 == -1) continue;
			
			int k = e0 + e1 + f0 + f1;
			
			f[k][f0][f1]++;
		}
	
	for (int i = 0; i < n; i++)
		for (int x = n; x >= 0; x--)
			for (int y = n; y >= 0; y--) {
				f[i + 1][x][y] += f[i][x][y];
				f[i + 1][x][y] %= md;
				
				if (s[i] == '0' && y > 0) {
					f[i][x][y - 1] += f[i][x][y];
					f[i][x][y - 1] %= md;
				}
				
				if (s[i] == '1' && x > 0) {
					f[i][x - 1][y] += f[i][x][y];
					f[i][x - 1][y] %= md;
				}
			}
	
	for (int x = n; x >= 0; x--)
		for (int y = n; y >= 0; y--) {
			if (x > 0) {
				f[n][x - 1][y] += f[n][x][y];
				f[n][x - 1][y] %= md;
			}
			
			if (y > 0) {
				f[n][x][y - 1] += f[n][x][y];
				f[n][x][y - 1] %= md;
			}
		}
	
	printf("%d\n", f[n][0][0]);
	
	return 0;
}


Measured memory_bytes: 216808
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)

int m,d;
int ans;

int cal(int i){
	int res=1;
	if(i<=9)return 0;
	else{
		res*=(i/10);
		res*=(i-10*(i/10));
		if(i/10==1)return 0;
		if((i-10*(i/10))==1)return 0;
		return res;
	}
	return 0;
}

signed main(){
	cin>>m>>d;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			if(cal(j)==i){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> adj[110];
pair<ll, ll> findans(vector<pair<ll, ll> >& considering, ll amountofzero)
{
	ll mx = 0;
	for (auto a : considering)
	{
		mx = max(mx, (ll)(adj[a.first].size() - (a.second != -1)));
	}
	if (!mx) return { (ll)1, (ll)(amountofzero + considering.size()) };
	vector<pair<ll, ll> > newconsidering;
	ll newamountofzero = 0;
	for (auto a : considering)
	{
		ll sz = adj[a.first].size() - (a.second != -1);
		if (sz < mx) newamountofzero += (mx-sz);
		for (auto ad : adj[a.first])
		{
			if (ad != a.second) newconsidering.emplace_back(ad, a.first);
		}
	}
	newamountofzero += amountofzero*mx;
	pair<ll, ll> ans = findans(newconsidering, newamountofzero);
	ans.first++;
	return ans;
}
ll u[110], v[110], n;
pair<ll, ll> ans = {(ll)(2e18), (ll)(2e18)};
int main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n-1; i++)
	{
		scanf("%lld%lld", &u[i], &v[i]);
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	for (int i = 1; i <= n; i++)
	{
		vector<pair<ll, ll> > considering;
		considering.emplace_back(i, -1);
		ans = min(ans, findans(considering, 0));
	}
	for (int i = 0; i < n-1; i++)
	{
		vector<pair<ll, ll> > considering;
		considering.emplace_back(u[i], v[i]);
		considering.emplace_back(v[i], u[i]);
		ans = min(ans, findans(considering, 0));
	}
	printf("%lld %lld\n", ans.first, ans.second);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  ll ans=0;
  for(int i=1;i<=N;i++){
    if(i%3!=0&&i%5!=0) ans+=i;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3604
/* Pain. Anger. Hatred. Ego.
                                                      Survive. Live. Win. Conquer. */

                                                          /*#Quota_Reform .
                                                        #We_Want_Safe_Roads .
                                                          #We_Want_Justice .
                                                            #Support_Us .
                                                            #Bangladesh .
                                                          */


#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ook order_of_key
#define fbk find_by_order
#define bug printf("Massacre.\n");
#define pf printf
#define sf scanf
#define pb push_back
#define r0 return 0
#define ff first
#define ss second
#define mp make_pair
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define si(a) scanf("%d" , &a)
#define sl(a) scanf("%lld" , &a)
#define sii(a,b) scanf("%d %d" , &a , &b)
#define siii(a,b,c) scanf("%d %d %d" , &a , &b, &c)
#define sll(a,b) scanf("%lld %lld" , &a , &b)
#define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c)
#define pll pair <LL, LL>
#define pii pair <int, int>
#define vi  vector <int>
#define vl  vector <LL>
#define all(x) (x).begin(), (x).end()
#define vii vector <pair <int, int> >
#define vll vector < pair <LL, LL> >
#define mod 1000000007

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

void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

void print(vector <LL> &v){
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); i++){
        pf("%lld ", v[i]);
    }
    pf("\n");
}

void print(vector <pll> &v){
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); i++){
        pf("%lld %lld\n", v[i].ff, v[i].ss);
    }
}

void print(double d){
    cout << fixed << setprecision(10) << d << endl;
}

void print(string s, double d){
    cout << s << " ";
    cout << fixed << setprecision(10) << d << endl;
}

const int N = 3000;
double dp[N][N];
bool vis[N][N];
LL n;
double a[N];
double calc(LL i, LL j){
    if(i == n){
        if(j * 2 >= n)return 1.0;
        return 0.0;
    }
    if(vis[i][j])return dp[i][j];
    vis[i][j] = 1;
    return dp[i][j] = a[i] * calc(i + 1, j + 1) + (1.0 - a[i]) * calc(i + 1, j);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    LL q, i,j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m, fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000, mn1 = 8000000000000000000;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    cout << fixed << setprecision(10) << calc(0, 0) << endl;
}


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

int main() {
    int64_t N, a = 0, b = 0, c;
    cin >> N;
  	if (N == 1) {
      cout << 1 << endl;
      return 0;
    }
    for (int i = 0; i < N + 1; i++) {
        if (i == 0) {
            a = 2;
        }
        else if (i == 1) {
            b = 1;
        }
        c = a + b;
        if (i != 0 && i != 1){
        a = b;
        b = c;
        }
    }
    cout << c << endl;
}

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

typedef long long ll;

using namespace std;

int main() {
    int x, y, z;
    cin >> x >> y >> z;

    x -= z * 2;

    int a = y + z;

    int b = x / a;

    if (x - b * (y + z) >= y) {
        cout << b + 1 << endl;
    } else {
        cout << b << endl;
    }
}

Measured memory_bytes: 3596
n = input()
for _ in xrange(n):
    y, m, d = map(int, raw_input().split())
    m -= 1

    ans = 1
    for t in xrange(y+1, 1000):
        ans += 195 if t%3 else 200
    for t in xrange(m+1, 10):
        ans += 19 if y%3 and t%2 else 20
    ans += 19-d if y%3 and m%2 else 20-d

    print ans

Measured memory_bytes: 6372
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,m,i,f,hp,a[100010],b[100010],c[100010],max=0,mi=0;
  scanf("%d %d",&n,&m);
  for(i=0;i<n-1;i++)scanf("%d %d",&a[i],&b[i]);
  a[i]=c[b[i]=0]=m;
  hp=m;//printf("a\n");
  for(i=0;f-n;i++){
    hp=c[f=mi]+max;
    max=0;
    while(hp>0){
      c[f]=hp;
      if(max<=MIN(b[f],m-hp))max=MIN(b[mi=f],m-hp);
      hp-=a[f++];//printf("%d %d %d\n",c[f-1],max,mi);
    }
  }
  printf("%d\n",i-1);
  return 0;
}

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

signed main(){
	int N,K; cin>>N>>K;
	int ans=0;
	deque<int> que;
	for(int i=0;i<N;i++){
		int v; cin>>v;
		que.push_back(v);
	}
	int R=min(K,N);
	for(int l=0;l<=R;l++){
		for(int r=0;r<=R-l;r++){
			deque<int> cue=que;
			priority_queue<int,vector<int>,greater<int>> tmp;
			int TA=0;
			for(int i=0;i<l;i++){
				TA+=cue.front();
				tmp.push(cue.front());
				cue.pop_front();
			}
			for(int i=0;i<r;i++){
				TA+=cue.back();
				tmp.push(cue.back());
				cue.pop_back();
			}
			for(int i=0;i<min(K-l-r,l+r);i++){
				if(tmp.top()<0){
					TA-=tmp.top();
					tmp.pop();
				}
				else break;
			}
			ans=max(ans,TA);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
 * atcoder/abc123_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * AxBの組み合わせは1,000,000通り.
 * これを大きい順にソートO(10^6 log(10^6))して、K以降は小さいので不要.
 * AxBの最大長はK(<=3000)
 * これとCの組み合わせは3,000,1000通り.
 * 降順ソートしてKまでを出力.
 * 組み合わせ計算がボトルネックでO(N^2)
 */
int X, Y, Z, K;
vector<ll> A, B, C, AB, ABC;
void solve() {
  cin >> X >> Y >> Z >> K;
  A.resize(X); B.resize(Y); C.resize(Z);
  loop(n,0,X) cin >> A[n];
  loop(n,0,Y) cin >> B[n];
  loop(n,0,Z) cin >> C[n];
  for (auto&&a: A) for (auto&&b: B) AB.push_back(a + b);
  sort(AB.rbegin(), AB.rend());
  AB.resize(min(K, (int)AB.size()));

  for (auto&&ab: AB) for (auto&&c: C) ABC.push_back(ab + c);
  sort(ABC.rbegin(), ABC.rend());
  loop(n,0,K) cout << ABC[n] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 43240
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
typedef long long ll;
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> as(n), bs(n); repeat (i,n) cin >> as[i] >> bs[i];
    ll a = as[0];
    ll b = bs[0];
    repeat_from (i,1,n) {
        ll d = max(a / as[i], b / bs[i]);
        while (not (a <= as[i] * d and b <= bs[i] * d)) d += 1;
        a = as[i] * d;
        b = bs[i] * d;
    }
    cout << a + b << endl;
    return 0;
}

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

long long N, M;

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

  if (N == 1 && M == 1) {
    cout << 1 << endl;
  }
  else if (N == 1 && M > 1) {
    cout << M - 2 << endl;
  }
  else if (N > 1 && M == 1) {
    cout << N - 2 << endl;
  }
  else {
    cout << (N - 2)*(M - 2) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
ans = 10000000000
temp = 0

for i in range(1, max(x)+1):
    temp = 0
    for j in range(n):
        temp += (x[j] - i) ** 2
    if temp < ans:
        ans = temp

print(ans)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int main() {
	cout << setprecision(20) << fixed;
	double L;
	cin >> L;
	double ans = pow(L / 3, 3);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;

  int ans;

  int arr[1000000];


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS


    string s,t;
    cin >> s >> t;

    s += s;

    
    for(int i = 0; i < s.size(); i++)
    {
      if(s.substr(i,t.size()) == t)
      {
        cout << "Yes";
        return 0;
      }
    }


    cout << "No";
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

const int N=100005;
const ll inf=1000000000000000000ll;

int n;
ll ans,c,mx;
ll w[N],x[N],a[N],b[N],w1[N],w2[N];

int main(){
	int i;
	scanf("%d%lld",&n,&c);
	for (i=1;i<=n;i++) scanf("%lld%lld",&x[i],&w[i]);
	ans=0;
	for (i=1;i<=n;i++) w[i]+=w[i-1];
	for (i=1;i<=n;i++){
		w1[i]=w[i]-x[i];
		w2[i]=w[n]-w[i-1]-(c-x[i]);
		a[i]=w1[i]-x[i];
		b[i]=w2[i]-(c-x[i]);
		ans=max(ans,w1[i]);
		ans=max(ans,w2[i]);
	}
	mx=0;
	for (i=1;i<=n;i++){
		ans=max(ans,mx+w2[i]);
		mx=max(mx,a[i]);
	}
	mx=0;
	for (i=n;i>=1;i--){
		ans=max(ans,mx+w1[i]);
		mx=max(mx,b[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992
N,K=map(int,input().split())
P= [list(map(int,input().split())) for i in range(2*K)]
count=0
Q=[]
for t in range(1,2*K,2):
    Q.append(P[t])

R=[]
for u in range(0,len(Q)):
    for s in range(0,len(Q[u])):
        R.append(Q[u][s])

for j in range(1,N+1):
    if j not in R:
        count=count+1
    else:
        count=count
print(count)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    int K; cin >> K;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    sort(A.begin(),A.end(),greater<int>());
    int res = 0;
    for (int i=0;i<K;i++) res += A[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

#define INFL (1LL << 62)

typedef long long ll;

using namespace std;

int main() {
    ll n, w, dw, dv;
    scanf("%lld%lld", &n, &w);
    vector<ll> dp(n * 1000 + 1, INFL);
    dp.at(0) = 0;
    for (ll i = 0; i < n; ++i) {
        scanf("%lld%lld", &dw, &dv);
        for (ll j = dp.size() - 1; j >= dv; --j) dp.at(j) = min(dp.at(j), dp.at(j - dv) + dw);
    }
    for (ll i = dp.size() - 1; i >= 0; --i) if (dp.at(i) <= w) {
        printf("%lld\n", i);
        break;
    }
    return 0;
}


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

using namespace std;

#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}

#define pii pair<int, int>
#define mp make_pair

typedef long long ll;


const int N = 70;

const ll MOD = 1e9 + 7;

// 1 equal, 0 < ,2 >
ll dp[N][2][2][2][2][2][2];
ll n;

/*
0 + 0 = 00
0 + 1 = 01
1 + 0 = 01
1 + 1 = 10

0 + 0 + 1 = 01
0 + 1 + 1 = 10
1 + 0 + 1 = 10
1 + 1 + 1 = 11

u a xor b
v a + b

*/

bool valid(int u, int v, int right, int left)
{
	if (u == v)
	{
		if (right != 0)
		{
			return false;
		}
		
		if (left && u)
		{
			return false;
		}
	}
	else
	{
		if (right != 1)
		{
			return false;
		}
		
		if (u && !left)
		{
			return false;
		}
	}
		
	return true;
}


int bit(int i)
{
	return (n >> i & 1);
}

void update(ll &cur, ll add)
{
	cur = (cur + add) % MOD;
}

int main()
{
	USE_IOSTREAM;
	int i, j, u, v, right, left, bigU, bigV, uu, vv, bigU1, bigV1, r;
	cin >> n;
	
	//dp[bit][u][v][right][left][bigu][bitv]
	right = 0;
	for (u = 0; u < 2; u++)
	for (v = 0; v < 2; v++)
	{
		for (left = 0; left < 2; left++)
		{
			if (!valid(u, v, right, left))
			{
				continue;
			}
			bigU = u > bit(0);
			bigV = v > bit(0);
			dp[0][u][v][right][left][bigU][bigV] += 1;
		}	
	}
	
	for (i = 1; i <= 62; i++)
	{
		for (u = 0; u < 2; u++)
		for (v = 0; v < 2; v++)
		for (right = 0; right < 2; right++)
		for (left = 0; left < 2; left++)
		{
			if (!valid(u, v, right, left))
			{
				continue;
			}
			for (uu = 0; uu < 2; uu++)
			for (vv = 0; vv < 2; vv++)
			for (r = 0; r < 2; r++)
			for (bigU1 = 0; bigU1 < 2; bigU1++)
			for (bigV1 = 0; bigV1 < 2; bigV1++)
			{	
				bigU = u > bit(i) || (u == bit(i) && bigU1);
				bigV = v > bit(i) || (v == bit(i) && bigV1);
				update(dp[i][u][v][right][left][bigU][bigV], dp[i - 1][uu][vv][r][right][bigU1][bigV1]);
			}
		}
	}
	
	ll ans = 0;
	for (u = 0; u < 2; u++)
	for (v = 0; v < 2; v++)
	for (right = 0; right < 2; right++)
	{
		update(ans, dp[62][u][v][right][0][0][0]);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;cin>>x>>y;
  int a=0,b=x;
  bool found = false;
  while(a<=x){
    if(y==2*a+b*4)found = true;
    a++;b--;
  }
  if(found)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  int a[SIZE];

  cin >> n;

  int ans = 0;
  
  for(int i=0;i<n;i++){
    cin >> a[i];
    while(a[i] %2 == 0){
      a[i]/=2;
      ans ++;
    }
    
  }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
 
//############################ENDOFTEMPLATE############################

void solve(){
  int n,m;
  cin>>n>>m;
  vector<string> grid(n);

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

  vector<vector<int>> dp(n,vector<int>(m));

  if(grid[0][0]=='#')
    dp[0][0] = 1;

  for(int i = 1;i<n;i++){
    if(grid[i][0]=='#'){
      if(grid[i-1][0]=='#')
        dp[i][0] = dp[i-1][0];
      else
        dp[i][0] = dp[i-1][0]+1;
    }

    else{
      dp[i][0] = dp[i-1][0];
    }
  }


  for(int i = 1;i<m;i++){
    if(grid[0][i]=='#'){
      if(grid[0][i-1]=='#')
        dp[0][i] = dp[0][i-1];
      else
        dp[0][i] = dp[0][i-1]+1;
    }
    else{
      dp[0][i] = dp[0][i-1];
    }
  }

  for(int i = 1;i<n;i++){
    for(int j = 1;j<m;j++){
      if(grid[i][j]=='#'){
        dp[i][j] = min(grid[i-1][j]=='#'?dp[i-1][j]:dp[i-1][j]+1,grid[i][j-1]=='#'?dp[i][j-1]:dp[i][j-1]+1);
      }
      else{
        dp[i][j] = min(dp[i-1][j],dp[i][j-1]);
      }
    }
  }


  cout<<dp[n-1][m-1];
}
 
 
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("moobuzz.in","r",stdin);
  //freopen("moobuzz.out","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned long long H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) cout << 1 << endl;
  else if (H * W % 2 == 0) cout << H * W / 2 << endl;
  else cout << H * W / 2 + 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int isprime(int n)
{
	if(n<2)return 0;
	else for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)return 0;
	}
	return 1;
}//dfs,
void solve(int n)
{	if(isprime(n))
	{
		cout<<n<<": "<<n<<endl;//特殊情况排除
		return ;
	}
	int sum=0;
	cout<<n<<":";
	while(n>1)
	{	
		for(int i=2;i<=n;i++)
			if(isprime(i)&&(n%i==0))
				{	
					cout<<" ";//格式
					cout<<i;
					n/=i;
					sum++;
					break;
				}
	}
	cout<<endl;
}
int main()
{	
	int n;
	cin>>n;
	solve(n);
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;


int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string S,T;

    cin>>S>>T;

    for(int i=0;i<3;i++)
        if(S[i]==T[i])cnt++;

    cout<<cnt<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define pqi                priority_queue<ll>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define inf                1e18L+1
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  100005
multiset <ll> s;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll tests=1;
//    cin>>tests;
    while(tests--)
{
    ll n;
    cin>>n;
    vii v;
    rep(i,0,n)
    {
      ll a;
      cin>>a;
      v.pb({a,i+1});
    }
    sort(v.begin(),v.end());reverse(all(v));
    s.insert(0);
    s.insert(0);
    s.insert(n+1);
    s.insert(n+1);
    ll ans=0;
    rep(i,0,sz(v))
    {
        ll val=v[i].F;
        auto itr=s.lower_bound(v[i].S);
        ll itr4=*itr;
        itr++;
        ll itr3=*itr;itr--;itr--;
        ll itr2=*itr;
        itr--;
        ll itr1=*itr;
        if(itr3>itr4){
          ans+=val*(-itr4+itr3)*(v[i].S-itr2);
        //  dbg(ans);
        }
        if(itr2>itr1){
          ans+=val*(itr2-itr1)*(itr4-v[i].S);//dbg(ans);
        }
        s.insert(v[i].S);
    }
    cout<<ans<<endl;
}
    return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> h;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        h.push_back(x);
    }
    vector<int> a(n, 0);
    a[0] = 0;
    a[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        a[i] = min(a[i - 2] + abs(h[i] - h[i - 2]), a[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << a[n - 1] << endl;
}


Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int arr[5],k;
  for(int i=0;i<5;i++) cin>>arr[i];
  cin>>k;
  for(int i=0;i<5;i++) for(int j=i+1;j<5;j++) if(arr[j]-arr[i]>k) {cout<<":(\n";return 0;}
  cout<<"Yay!"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().rstrip()

    ans = ""
    n_left = 0
    n_right = 0
    for s in S:
        if s == "(":
            n_left += 1
        else:
            if n_left > 0:
                n_left -= 1
            else:
                n_right += 1

    ans = "".join(("(" * n_right, S, ")" * n_left))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8996
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#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 GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { 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() {
  GI3(N, M, R);
  GVI(r, R);
  vector<vector<int>> d(N, vector<int>(N, 1 << 28));
  FOR(i, M) {
    GI3(A, B, C);
    d[A - 1][B - 1] = C;
    d[B - 1][A - 1] = C;
  }
  sort(ALL(r));
  FOR(k, N) {
    FOR(i, N) {
      FOR(j, N) {
        if (d[i][j] > d[i][k] + d[k][j]) {
          d[i][j] = d[i][k] + d[k][j];
        }
      }
    }
  }
  int ans = 1 << 28;
  do {
    int sum = 0;
    FOR(i, R - 1) { sum += d[r[i] - 1][r[i + 1] - 1]; }
    ans = min(ans, sum);
  } while (next_permutation(ALL(r)));
  print(ans);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll f[1 << 20];
ll N, K;
ll A[21];

ll g(ll x) {
    if(x == 0) return 0;
    return (x & 1) + g(x / 2);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int bits = 0; bits < (1 << 20); bits++) {
        ll sum = 0;
        for(int i = 0; i < N; i++) {
            if(bits & (1 << i)) sum += A[i];
        }
        if(sum == K) f[bits]++;
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < (1 << N); j++) {
            if(j & (1 << i)) {
                f[j] += f[j^(1<<i)];
            }
        }
    }
    ll ans = N;
    for(int bits = 0; bits < (1 << N); bits++) {
        if(f[bits]) continue;
        chmin(ans, N - g(bits));
    }
    cout << ans << endl;
    return 0;
}



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

ll pre[100010],pre1[100010],num[100010],n,ans;
bool bo[100010];
char s[233];

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();num[1]=rd();bo[1]=true;
	for (int i=2;i<=n;i++)
	{
		scanf("%s",s+1);num[i]=rd();
		bo[i]=(s[1]=='+');
	}
	for (int i=1;i<=n;i++) pre[i]=pre[i-1]+(bo[i]?num[i]:-num[i]);
	for (int i=1;i<=n;i++) pre1[i]=pre1[i-1]+num[i];
	ans=pre[n];
	int lst=0;
	for (int i=1;i<=n;i++)
	{
		if (bo[i]) continue;
		if (!lst) { lst=i;continue; }
		ans=max(ans,pre[lst-1]-(pre1[i-1]-pre1[lst-1])+(pre1[n]-pre1[i-1]));
		lst=i;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl ans;

void dfs(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    ans[v] = G[v].size() - 1;
    if(p == -1) {
        ans[v]++;
    }
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v);
        // 帰りの処理はこのへんに書く
    }
}

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

    G.resize(n);
    exrep(i, 1, n-1) {
        ll a;
        cin >> a;
        a--;
        G[a].pb(i);
        G[i].pb(a);
    }

    const ll root = 0;
    ans.resize(n);
    dfs(root);

    rep(i, n) {
        out(ans[i]);
    }
    
    re0;
}

Measured memory_bytes: 25080
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

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

bool is_prime(long long a) {
	for (long long i = 2; i * i <= a; ++i) {
		if (a % i == 0) {
			return false;
		}
	}

	return true;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long a, b;
	cin >> a >> b;

	long long g = gcd(a, b);

	vector<long long> common;
	for (long long i = 1; i * i <= g; ++i) {
		if (g % i == 0) {
			common.push_back(i);
			long long j = g / i;
			if (j != i) {
				common.push_back(j);
			}
		}
	}

	vector<long long> coprime;
	for (int i = 0; i < (int) common.size(); ++i) {
		if (is_prime(common[i])) {
			coprime.push_back(common[i]);
		}
	}

	cout << coprime.size() << "\n";

	return 0;

}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
 char we[6];
 char *S = "Sunny";
 char *C = "Cloudy";
 int main(void){
 scanf("%s",we);
 if(strcmp(we,S)==0){
 	printf("Cloudy");
 }else if(strcmp(we,C)==0){
    printf("Rainy"); 
 }else{
    printf("Sunny");
 }
 return 0;
 }

Measured memory_bytes: 128
n, m = map(int, input().split())
a_pos = [0]*(n+1)
for i in range(m):
    a_pos[int(input())] = 1
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 0 if a_pos[1] else 1
for i in range(n-1):
    if a_pos[i+2] == 1:
        dp[i+2] = 0
    else:
        dp[i+2] = (dp[i] + dp[i+1]) % mod

print(dp[-1])

Measured memory_bytes: 44888
import java.util.Scanner;

public class Main {

  private static int x;
  private static int y;

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    for (int i = 0; i < 3000 ; i++ ) {
      x = stdIn.nextInt();
      y = stdIn.nextInt();
      if (x == 0 && y == 0) {
        break;
      } else {
        if (x <= y) {
          System.out.println(x + " " + y);
        } else {
          System.out.println(y + " " + x);
        }
      }
    }
  }
}

Measured memory_bytes: 35396
import sys, math
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline
# 文字列の場合は普通のinput()を使うか下を使う
# input = sys.stdin.readline().rstrip()

A = int(input())
B = int(input())
S = set([1,2,3])
S.discard(A)
S.discard(B)
ans = S.pop()
print(ans)

Measured memory_bytes: 38384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
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; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

	ll N;
	cin >> N;

	vector<ll> L(N);

	rep(i, N) {
		cin >> L[i];
	}

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

	ll ans = 0;

	rep(i, N - 2) {
		repl(j, i + 1, N - 1) {
			if (L[i] == L[j]) continue;
			repl(k, j +1,N){
				if (L[j] == L[k]) continue;
				if (L[i] + L[j] > L[k]) { 
					ans++;
				}
			}
		}
	}


	cout << ans;

	return 0;
}


ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

int main()
{
    int n,x,y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n+1);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int d = j-i;
            d = min(d, abs(x-i) + 1 + abs(y-j));
            ans[d]++;
        }
    }
    for(int i=1; i<n; i++) cout << ans[i] << endl;
    
    return 0;
}


Measured memory_bytes: 256
from collections import deque

N = int(input())
branch = [list(map(int, input().split())) for _ in range(N-1)]

adj = [[] for _ in range(N+1)]
for b in branch:
  adj[b[0]].append([b[1],b[2]])
  adj[b[1]].append([b[0],b[2]])

ans = [-1] * (N+1)
deq = deque()
deq.appendleft(1)
while len(deq) > 0:
  v = deq.pop()
  for u, w in adj[v]:
    if ans[u] == -1:
      deq.appendleft(u)
    if ans[v] == -1 and ans[u] == -1:
      if w % 2 == 0:
        ans[v] = 0
        ans[u] = 0
      else:
        ans[v] = 0
        ans[u] = 1
    elif ans[v] == 0:
      if w % 2 == 0:
        ans[u] = 0
      else:
        ans[u] = 1
    else:
      if w % 2 == 0:
        ans[u] = 1
      else:
        ans[u] = 0
for i in range(1,N+1):
  print(ans[i])

Measured memory_bytes: 59668
N, K = map(int, input().split())
G = [[] for n in range(N)]
for n in range(N-1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

C = [0] * N

# まず各部分木の根にカウンターを乗せる
for k in range(K):
    p, x = map(int, input().split())
    C[p - 1] += x

# 深さ優先探索で親のカウンターを子に継いでいく
V = [False]*N
Q = [0]
while Q:
    x = Q.pop()
    V[x] = True
    for y in G[x]:
        if not V[y]:
            C[y] += C[x]
            Q.append(y)
print(*C)


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = long long;
using vint = vector<int>;


void Main() {
    int n;
    cin >> n;
    vint h(n);
    for (auto& x : h)
    {
        cin >> x;
    }

    int max_value = 0;
    rep(i, n - 1) {
        max_value = max(h[i] - 1, max_value);
        if (h[i + 1] < max_value) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    ll sum = 0;
    vector<int> nums(10e5+1,0);
    REP(i,N){
        cin >> A[i];
        nums[A[i]]++;
        sum += A[i];

    }
    int Q;
    cin >> Q;
    vector<vector<int>> BC(Q, vector<int>(2));
    REP(i,Q) cin >> BC[i][0] >> BC[i][1];

    REP(i,Q){
        sum += (BC[i][1]-BC[i][0]) * nums[BC[i][0]];
        nums[BC[i][1]] += nums[BC[i][0]];
        nums[BC[i][0]] = 0;
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 12972
package main

import (
	"fmt"
	"sort"
	"bufio"
	"os"
	"strings"
	"strconv"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	a := ReadIntArray()

	counts := make([]int, 200000)

	for _, v := range a {
		counts[v-1]++
	}

	sort.Ints(counts)

	sum := 0
	for _, v := range counts[:len(counts)-k] {
		sum += v
	}

	fmt.Println(sum)
}

// reader
var size = 200000
var rdr = bufio.NewReaderSize(os.Stdin, size)

func ReadLine() string {
	buf := make([]byte, 0, size)
	for {
		line, isPrefix, err := rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func ReadArray() []string {
	s := ReadLine()
	return strings.Split(s, " ")
}

func ReadIntArray() []int {
	a := ReadArray()
	n := make([]int, 0)
	for _, v := range a {
		if i, e := strconv.Atoi(v); e == nil {
			n = append(n, i)
		}
	}
	return n
}


Measured memory_bytes: 12800
import math
mod = 10 ** 9 + 7
def combinations_count(n, r): # 組み合わせ
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())

if N < 3:
  print(0)
elif N == 3:
  print(1)
else:
  ans = 0
  num_digit = N // 3 # 項数を計算する
  for i in range(num_digit): # 可能な項数ごとに計算する 1 <= x <= num_digit, 仕切りの数は0 <= x < num_digit
    combi = combinations_count((N - (3 * (i+1)) + i), i) # 数字と項数区切りの組み合わせを計算する ex. oo|
    ans += combi
  if ans >= mod:
    print(int(ans % mod))
  else:
    print(ans)

Measured memory_bytes: 9232
def gcd(x, y):
  while y != 0:
    t = x % y
    x = y
    y = t
  return x

def lcm(x, y):
  return x * y // gcd(x, y)

n  = int(input())
xs = [int(x) for x in input().split()]
y  = 1
r  = 0
m  = 10 ** 9 + 7

for x in xs:
  y = lcm(y, x)

for x in xs:
  r += y // x

print(r % m)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define ff first
#define ss second

void setIO(string name = "") { // name is nonempty for USACO file I/O
    ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
    freopen((name+".in").c_str(), "r", stdin); // see Input & Output
    freopen((name+".out").c_str(), "w", stdout);
}
// the code that we provide requires everything above this line to compile



int main() {
	int n;cin>>n;
  	int cnt = 0;
  	for(int i = 1; i <= n; ++i){
    	int x;cin>>x;
      	cnt += ((x&1) && (i&1));
    }
  	cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;

int main() {
double a,b,h,m;
cin >> a >> b >> h >> m;
double tan,tyo;
double kaku;
tan = ((h*60.0+m)*360.0)/(12.0*60.0);
tyo = (m*360.0)/60.0;
kaku = tan-tyo;
double rad = (kaku*M_PI)/180;
//cout << tan << " " <<tyo <<" "<< kaku;
double ans;
ans = (a*a)+(b*b)-(2.0*b*a*cos(rad));
cout << fixed << setprecision(20)<< sqrt(ans) << endl;

}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define int long long

bool amin(int& x, int y) {
  bool ret = (x > y);
  if (ret) x = y;
  return ret;
}

const int inf = 1ll << 62;
signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N), y(N);
  vector<P> z;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    x[i] = a;
    y[i] = b;
    z.push_back(make_pair(a, b));
  }
  sort(begin(x), end(x));
  sort(begin(y), end(y));
  int ans = inf;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = 0; k < N; k++) {
        for (int t = k + 1; t < N; t++) {
          int tmp = 0;
          int l = x[i];
          int r = x[j];
          int d = y[k];
          int u = y[t];
          for (auto&& w : z) {
            int x0 = w.first;
            int y0 = w.second;
            if (l <= x0 && x0 <= r && d <= y0 && y0 <= u) {
              tmp++;
            }
          }
          if (tmp >= K) {
            if (amin(ans, (r - l) * (u - d))) {
              //   cout << tmp << " " << k << endl;
              //   cout << l << " " << r << " " << d << " " << u << endl;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  string s;
  cin>>s;
  for(char &x : s){
    if(x == '?')
      x = 'D';
  }
  cout<<s<<"\n";
}


Measured memory_bytes: 3768