akhauriyash/Code-Regression huggingface dataset:
// 2014/09/11 Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		for(int i=0; i<n; i++){
			int x1, y1, z1, w1, x2, y2, z2, w2;
			cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;

			int x3 = x1*x2-y1*y2-z1*z2-w1*w2;
			int y3 = x1*y2+y1*x2+z1*w2-w1*z2;
			int z3 = x1*z2-y1*w2+z1*x2+w1*y2;
			int w3 = x1*w2+y1*z2-z1*y2+w1*x2;

			cout << x3 << ' ' << y3 << ' ' << z3 << ' ' << w3 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

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

}
int main(){
  
  ll N;
  cin>>N;
  //漸化式を立てられそうなものは基本動的計画法
  
  vector<ll>A(N);
  ll dp[N+1][2];
  dp[0][0]=0;
  dp[0][1]=-INF;
  
  
  rep(i,N){
cin>>A[i];
  }

 for(ll i=1;i<N+1;i++){//1が１反転0が無反転
 
   dp[i][0]=max(dp[i-1][0]+A[i-1],dp[i-1][1]-A[i-1]);
   dp[i][1]=max(dp[i-1][0]-A[i-1],dp[i-1][1]+A[i-1]);
  //i+1を回転させるかどうかが0,1
 }
  cout<<dp[N][0]<<endl;//Nを選んで操作できないため(i+1を回転させるため)
}

   

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	int n;

	cin >> n;

	cout << (n-1) / 2 << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int MAX_N = 100000;


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

	string ans(n.length(), '1');

	for (int i = 0; i < n.length(); i++) {
		if (n[i] == '1') {
			ans[i] = '9';
		}
	}
	cout << ans << endl;
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        int n;
        scanf("%d", &n);
        int a[n], b[n];
        rep(i, n) scanf("%d", &a[i]);
        rep(i, n) scanf("%d", &b[i]);

        int ans=MAX;
        rep(S, 1<<n)if(__builtin_popcount(S)==n/2){
                deque<pii> even, odd;
                rep(i, n){
                        int t=(i%2==(S>>i&1) ? a[i] : b[i]);
                        if(S>>i&1) odd.emplace_back(t, i);
                        else even.emplace_back(t, i);
                }
                sort(even.begin(), even.end());
                sort(odd.begin(), odd.end());
                vector<pii> p;
                rep(i, n){
                        if(i%2==0){
                                p.push_back(even.front());
                                even.pop_front();
                        }
                        else{
                                p.push_back(odd.front());
                                odd.pop_front();
                        }
                }
                bool flag=true;
                rep(i, n-1)if(p[i+1].fi<p[i].fi){
                        flag=false;
                        break;
                }
                if(flag){
                        int cnt=0;
                        rep(i, n)rep(j, i)if(p[j].se>p[i].se) ++cnt;
                        chmin(ans, cnt);
                }
        }
        printf("%d\n", ans==MAX ? -1 : ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

pair<int, int> point[3000];
bool ch[5001][5001];
int n, ans;

int main() {
	while (true) {
		cin >> n;
		if (n == 0) break;

		memset(ch, 0, sizeof(ch));
		REP(i, n) {
			int a, b;
			scanf("%d %d", &a, &b);
			point[i] = make_pair(a, b);
			ch[a][b] = true;
		}

		ans = 0;
		REP(i, n) {
			REP(j, n) {
				int x1 = point[i].first, y1 = point[i].second;
				int x2 = point[j].first, y2 = point[j].second;
				int pos = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
				if (pos < ans) continue;

				int x3 = y1 - y2 + x2, y3 = x2 - x1 + y2;
				if (x3 < 0 || x3 > 5000 || y3 < 0 || y3 > 5000 || !ch[x3][y3]) continue;

				int x4 = y1 - y2 + x1, y4 = x2 - x1 + y1;
				if (x4 < 0 || x4 > 5000 || y4 < 0 || y4 > 5000 || !ch[x4][y4]) continue;

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

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

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

#define BIG_PRIME 1000000007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF 0x3fffFFFF
#define INF_NEG (INF * -1)
#define INF_LONG 0x3fffFFFFffffFFFFL
#define INF_LONG_NEG (INF_LONG * -1L)

typedef long long ll;
typedef pair<ll, ll> lpair;
typedef char str255[256];
// char *用、strlen の ll 版
ll StrLen(char *s) { for(ll ptr = 0L;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除, 削除後の文字数を返す
ll StrDel(char *s, int n) { ll l = StrLen(s); s[l - n + 1L] = '\0'; return l - n; }
// 正の整数の桁数
ll NumDigits(ll l){ char s[30]; sprintf(s, "%lld", l); return StrLen(s); }

int isFirst = 1;
template <class T> 
void print(T t) { if (isFirst) cout << t, isFirst = 0; else cout << " " << t; }

void chmin(ll& a, ll b) { if (a > b) a = b; }
void chmax(ll& a, ll b) { if (a < b) a = b; }

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

signed main()
{
    int N, M; cin >> N >> M;
    vector<int> NG(N + 1, 0);
    rep(i, M) { int tmp; cin >> tmp; NG[tmp] = 1; }

    vector<ll> dp(N + 1, 0);
    dp[0] = dp[1] = 1; if (NG[1]) dp[1] = 0;

    for (int i = 2; i <= N; ++i){
        if (!NG[i - 1]) dp[i] = dp[i - 1];
        dp[i] %= BIG_PRIME;
        if (!NG[i - 2]) dp[i] += dp[i - 2];
        dp[i] %= BIG_PRIME;
    }
    
    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1408
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
h=sorted(lmp())
if n<=k:
    print(0)
else:   
    print(sum(h[:n-k]))

Measured memory_bytes: 109724
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {

        static void Main(string[] args)
        {
            //var N = long.Parse(Console.ReadLine());
            var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = NM[0];
            var M = NM[1];
            var ans = 1L;
            for (long i = 1; i <= (long)Sqrt(M); i++)
            {
                var pair = M / i;
                if (M%i == 0 && M/i >= N)
                {
                    ans = Max(i,ans);
                }

                if (M % i == 0 && M / pair >= N)
                {
                    ans = Max(pair,ans);
                }
            }


            Console.WriteLine(ans);
            

            
            
        }


    }


}


Measured memory_bytes: 28200
#include<stdio.h>

int main(void){
	int a,h,m,s;
	do{
		scanf("%d", &a);
	} while (a < 0 || a>86400);
	h = a / 3600;
	a %= 3600;
	m = a / 60;
	a %= 60;
	s = a;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a[::2])
a.sort()
now = 0
ans = 0
br = len(b)
for k,v in enumerate(a):
  if b[now] == v:
    if k % 2:
      ans += 1
    now += 1
  if now == br:
    break
print(ans)


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

int main(){
  int n,l;
  string s;
  vector<string> v;
  cin>>n>>l;
  for(int i=0; i<n; ++i){
    cin>>s;
    v.push_back(s);
  }
  sort(v.begin(),v.end());
  for(int i=0; i<n; ++i){
    cout<<v[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
ans = float("inf")


for ha in range(1, H):
    sa = ha * W
    h = H - ha
    
    # Case1 横日本の区切り線
    if h % 2 == 0:
        hb, hc = h // 2, h // 2
    else:
        hb, hc = h // 2, h // 2 + 1
    sb1, sc1 = hb * W, hc * W
    diff1 = max(sa, sb1, sc1) - min(sa, sb1, sc1)
    
    # Case2 横一本、縦一本区切り線
    if W % 2 == 0:
        wb, wc = W // 2, W // 2
    else:
        wb, wc = W // 2, W // 2 + 1
    sb2, sc2 = h * wb, h * wc
    diff2 = max(sa, sb2, sc2) - min(sa, sb2, sc2)
    
    tmp_min =  min(diff1, diff2)
    ans = min(ans, tmp_min)

# 縦横入れ替え
for ha in range(1, W):
    sa = ha * H
    h = W - ha
    
    # Case1 横日本の区切り線
    if h % 2 == 0:
        hb, hc = h // 2, h // 2
    else:
        hb, hc = h // 2, h // 2 + 1
    sb1, sc1 = hb * H, hc * H
    diff1 = max(sa, sb1, sc1) - min(sa, sb1, sc1)
    
    # Case2 横一本、縦一本区切り線
    if H % 2 == 0:
        wb, wc = H // 2, H // 2
    else:
        wb, wc = H // 2, H // 2 + 1
    sb2, sc2 = h * wb, h * wc
    diff2 = max(sa, sb2, sc2) - min(sa, sb2, sc2)
    
    tmp_min =  min(diff1, diff2)
    ans = min(ans, tmp_min)


print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include <vector>

using namespace std;

vector<vector<pair<int,int>>> v;
int n;

bool jedge(int bits) {
    for (int i = 0; i < n; ++i) {
        if (!(bits & (1 << i))) continue;
        for (pair<int,int> xy : v[i]) {
            int x = xy.first;
            int y = xy.second;

            if (y == 1 && !(bits & (1 << x))) return false;
            if (y == 0 && bits & (1 << x)) return false;
        }
    }
    return true;
}

int main() {
    int a;
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a;
        v[i].resize(a);
        for(int j = 0; j < a; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first;
        }
    }

    int count = 0, ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        if (jedge(i)) {
            count = __builtin_popcount(i);
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
    int N, Y, man = -1, gosen = -1, sen = -1;
    cin >> N >> Y;
    for (int i = 0; i <= N; ++i) {
        if (10000 * i > Y) break;
        for (int j = 0; i + j <= N; ++j) {
            if (10000 * i + 5000 * j > Y) break;
            if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
                man = i, gosen = j, sen = N - i - j;
            }
        }
    }
    cout << man << ' ' << gosen << ' ' << sen << endl;
    
    return 0;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	string s, t;
  int i , j;
  cin >> s >> t;
  for(int i = s.size() - 1; i >= 0; i--) {
    rep(j, t.size()) {
      if(s[i - j] != t[t.size() - 1 - j] && s[i - j] != '?') break;
      if (j + 1 == t.size()) {
        s.replace(i - j, t.size(), t);
        rep(k, s.size()) if(s[k] == '?') s[k] = 'a';
        cout << s << endl;
        return 0;
      }
    }
  }
  cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef set<ll> si;
typedef multiset<ll> msi;
typedef map<ll,ll> mii;
int main()
{
    ll i,j,k;
    ll x,y,a,b,c;
    scanf("%lld %lld %lld %lld %lld",&x,&y,&a,&b,&c);
    vector<pii> vec;
    for(i=0;i<a;i++){
        scanf("%lld",&j);
        vec.pb({j,0});
    }
    for(i=0;i<b;i++){
        scanf("%lld",&j);
        vec.pb({j,1});
    }
    for(i=0;i<c;i++){
        scanf("%lld",&j);
        vec.pb({j,2});
    }
    sort(vec.begin(),vec.end(),greater<pii>());
    ll mx=0;
    ll cnt=x+y;
    for(i=0;i<a+b+c && cnt;i++){
        if((vec[i].se==0 && x==0) || (vec[i].se==1 && y==0))
            continue;
        //printf("%lld %lld\n",vec[i].fi,vec[i].se);
        if(vec[i].se==0){
            x--;
            mx+=vec[i].fi;
        }
        else if(vec[i].se==1){
            y--;
            mx+=vec[i].fi;
        }
        else {
            mx+=vec[i].fi;
        }
        cnt--;
    }
    printf("%lld\n",mx);
}


Measured memory_bytes: 10604
ans = 'Yes'
C = []
for i in range(0, 3):
	C.append(list(map(int, input().split())))
a1ma2 = C[0][0] - C[1][0]
if a1ma2 != C[0][1] - C[1][1] or a1ma2 != C[0][2] - C[1][2]:
	ans = 'No'
a1ma3 = C[0][0] - C[2][0]
if a1ma3 != C[0][1] - C[2][1] or a1ma3 != C[0][2] - C[2][2]:
	ans = 'No'
a2ma3 = C[1][0] - C[2][0]
if a2ma3 != C[1][1] - C[2][1] or a2ma3 != C[1][2] - C[2][2]:
	ans = 'No'
b1mb2 = C[0][0] - C[0][1]
if b1mb2 != C[1][0] - C[1][1] or b1mb2 != C[2][0] - C[2][1]:
	ans = 'No'
b1mb3 = C[0][0] - C[0][2]
if b1mb3 != C[1][0] - C[1][2] or b1mb3 != C[2][0] - C[2][2]:
	ans = 'No'
b2mb3 = C[0][1] - C[0][2]
if b2mb3 != C[1][1] - C[1][2] or b2mb3 != C[2][1] - C[2][2]:
	ans = 'No'
print(ans)

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

int main(){
  long long n;  cin >> n;
  long long ans = 0;
  long long count = 0;
  for(long long a = 1;a<n;a++){
    for(long long b = a;;b++){
      if(a*b < n){
        ans++;
        if(a == b)  count++;
      }
      else  break;
    }
  }
  cout << ans*2 - count << endl;
}


Measured memory_bytes: 3648
lines = STDIN.read.split("\n")
loop do
    size = lines.shift.to_f
    break if size == 0
    nums = lines.shift.split.map(&:to_i)
    mean = nums.reduce(0){|sum, n| sum + n} / size
    a = (nums.reduce(0){|sum, n| sum + (n - mean) ** 2} / size) ** 0.5
    puts "%.8f" % a
end

Measured memory_bytes: 8844
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 100000001
#define inf 1000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define int ll
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
 
signed main() {
	fast;
	ll n,m;
	cin>>n>>m;
	ll l=1, r=n;
	for(int i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		l=max(a,l);
		r=min(b,r);
	}
	ll ans=r-l+1;
	ans=max(0LL,ans);
	cout<<ans;
}

Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1000000007
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}

ll acc(ll n){
    return n * (n+1) / 2;
}

int main(){
    int n = nxt(), k = nxt();
    ll count = 0;
    for(int i = k; i <= n+1; i++){
        count += acc(n) - acc(n-i) - acc(i-1) + 1;
        // count = ((count%mod) + (seg%mod))%mod;   
        count %= mod;
    }
    printf("%lld\n", count);
    return 0;
}



Measured memory_bytes: 3788
#include <iostream>
#include <string>
#define MAXN 100005
using namespace std;

int n;
string s;
bool dp[MAXN];

int main() {
    cin >> s;
    n = s.length();

    dp[n] = 1;
    for(int i = n - 1; i >= 0; --i) {
        dp[i] |= (i + 5 <= n && s.substr(i, 5) == "dream" && dp[i + 5]);
        dp[i] |= (i + 7 <= n && s.substr(i, 7) == "dreamer" && dp[i + 7]);
        dp[i] |= (i + 5 <= n && s.substr(i, 5) == "erase" && dp[i + 5]);
        dp[i] |= (i + 6 <= n && s.substr(i, 6) == "eraser" && dp[i + 6]); 
    }

    printf("%s\n", dp[0] ? "YES" : "NO");

    return 0;
}

Measured memory_bytes: 512
import heapq
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int,input().split()))
cal = []
heapq.heapify(cal)
minus = 0
zero = False
for i in a:
    if i == 0:
        zero = True
    if i < 0:
        minus += 1
    heapq.heappush(cal,abs(i))

if minus % 2 == 0 or zero:
    print(sum(cal))
else:
    adjust = heapq.heappop(cal)
    print(sum(cal)-adjust)


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

int main(){
    int n, d; cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d));
    rep(i,n) rep(j,d) cin >> x[i][j];
    int ans = 0;
    rep(i,n){
        for(int j = i+1; j < n; j++){
            int sql = 0;
            rep(k,d) sql += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            int l = sqrt(sql);
            if(l*l == sql) ans++;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int r, D, x[11];
  cin >> r >> D >> x[0];
   
  for(int i=0;i<10;++i){
    x[i+1] = r*x[i] - D;
    cout << x[i+1] << endl;
  }
  
  
}

Measured memory_bytes: 256
rolls = []
for _ in range(int(input())):
    rolls.append(list(map(int, input().split())))

current = 0
found = False
for i in range(len(rolls)):
    if rolls[i][1] == rolls[i][0]:
        current += 1
    else:
        current = 0
    if current == 3:
        found = True

if found:
    print("Yes")
else:
    print("No")



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

using namespace std;

int main(void) {
	int flag, A, B;
	cin >> flag;
	if(flag == 1) {
		cout << "Hello World\n";
	} else {
		cin >> A >> B;
		cout << (A + B) << '\n';
	}
	return 0;
}



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

int main(void) {
    string t;
    cin >> t;
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == '?') {
            if (t[i-1] == 'P') {
                t[i] = 'D';
            } else if (t[i+1] == 'D') {
                t[i] = 'P';
            } else if (t[i+1] == 'P') {
                t[i] = 'D';
            } else {
                if (t[i+1] == '?') {
                    if (t[i+2] == 'D') {
                        t[i] = 'D';
                        t[i+1] = 'P';
                    } else {
                        t[i] = 'P';
                        t[i+1] = 'D';
                    }
                } else {
                    t[i] = 'D';
                }
            }
        }
    }
    cout << t << endl;
}

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


Measured memory_bytes: 2040
#include <stdio.h>

int main( void ) {
  int i, max = 0;
  char ch[ 81 ];
  int ans[ 100 ] = { 0 };

  while( scanf( "%s", ch ) == 1 ) {
    for( i = 0; ch[ i ]; i++ ) ;

    for( i--; i >= 0; i-- )
      if( '0' <= ch[ i ] && ch[ i ] <= '9' ) {
        int j = 0;

        ans[ j ] += ch[ i ] - '0';

        for( i--, j++; i >= 0 && '0' <= ch[ i ] && ch[ i ] <= '9'; i--, j++ )
          ans[ j ] += ch[ i ] - '0';

        if( max < j )
          max = j;

        for( j = 0; j < max; j++ ) {
          ans[ j + 1 ] += ans[ j ] / 10;
          ans[ j ] %= 10;
        }
      }
  }

  for( i = max - 1; i >= 0; i-- )
    printf( "%d", ans[ i ] );
  printf( "\n" );

  return ( 0 );
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
   int H,W;
   cin >> H >> W;
   while(!(H==0 && W==0)){
      for(int i=1; i<=H; i++){
         for(int j=1; j<=W; j++){
            if((i>1 && i<H) && (j>1 && j<W)){
               printf(".");
            }
            else{
               printf("#");
            }
         }
         printf("\n");
      }
   printf("\n");
   cin >> H >> W;
   }

   return 0;
}



Measured memory_bytes: 3112
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[] a = new int[n];
		int[] ans = new int[n + 1];

		for (int i = 1; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
			ans[a[i]]++;
		}

		for (int i = 1; i < n + 1; i++) {
			System.out.println(ans[i]);
		}
	}

}


Measured memory_bytes: 59208
#include<bits/stdc++.h>
using namespace std;
int n,m,k,ans=1e9,sum[12];
char c[12][1010];
bool vis[1010]; 
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=0;i<(1<<(n-1));i++)
	{
		int cnt=0;
		vector<int>v;
		for(int j=1;j<n;j++)
		{
			int x=j-1;
			if((i>>x)&1==1)
			{
				v.push_back(j); 
			}
		}
		cnt=v.size();
		v.push_back(n);
		bool oo=true;
		memset(vis,false,sizeof(vis));
		for(int j=0;j<11;j++)
		{
			sum[j]=0;
		}
		for(int j=0;j<m;j++)
		{
			for(int kk=0;kk<v.size();kk++)
			{
				int l,r;
				if(kk==0)
				{
					l=0;
					r=v[kk]-1;
				}
				else
				{
					l=v[kk-1];
					r=v[kk]-1;
				}
				for(int x=l;x<=r;x++)
				{
					if(c[x][j]=='1')
					{
						sum[kk]++;
					}
				}
			}
			bool nd=false;
			for(int kk=0;kk<v.size();kk++)
			{
				if(sum[kk]>k)
				{
					nd=true;
					break;
				}
			}
			if(nd)
			{
				if(j==0)
				{
					oo=false;
					break;
				}
				else
				{
					cnt++;
					for(int kk=0;kk<v.size();kk++)
					{
						sum[kk]=0;
						int l,r;
						if(kk==0)
						{
							l=0;
							r=v[kk]-1;
						}
						else
						{
							l=v[kk-1];
							r=v[kk]-1;
						}
						for(int x=l;x<=r;x++)
						{
							if(c[x][j]=='1')
							{
								sum[kk]++;
							}
						}
						if(sum[kk]>k)
						{
							oo=false;
							break;
						}
					}
				}
			}
		}
		for(int j=0;j<m;j++)
		{
			if(vis[j])
			{
				cnt++;
			}
		}
		if(oo==true)
		{
			ans=min(ans,cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    reverse(S.begin(),S.end());
    S += '0';
    int N = S.size();
    vvec<int> dp(N+1,vec<int>(2,1e9));
    dp[0][0] = 0;
    for(int i=0;i<N;i++) for(int j=0;j<2;j++){
        int n = S[i]-'0';
        n += j;
        for(int a=0;a<10;a++){
            int nj = 0;
            int b = a-n;
            if(b<0){
                nj = 1;
                b += 10;
            }
            dp[i+1][nj] = min(dp[i+1][nj],dp[i][j]+a+b);
        }
    }
    cout << dp[N][0] << "\n";
}

Measured memory_bytes: 55964
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[0]+list(map(int,input().split()))
count=0
for i in range(N):
    a=A[i]-1
    count+=B[a]
    if  i!=0 and A[i-1]+1==A[i]:
        count+=C[a]
print(count)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int n,b,f,r,v,i,j,k;
    int arr[4][3][10]={0};

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d%d%d",&b,&f,&r,&v);
        arr[b-1][f-1][r-1]=arr[b-1][f-1][r-1]+v;
    }
    for(i=0;i<4;i++)
    {
        for(j=0;j<3;j++)
        {
            for(k=0;k<10;k++)
            {
                printf(" %d",arr[i][j][k]);
            }
            printf("\n");
        }
        if(i>=0&&i<3)
        {
            printf("####################\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2044
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


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

main(){
  string in[12];
  int n;
  cin>>n;
  while(n--){
    rep(i,12)cin>>in[i];

    int ans=0;

    while(true){
      bool end=true;

      rep(i,12)rep(j,6){
        if(in[i][j]=='.' || in[i][j]=='O')continue;
        queue<PI> Q;
        Q.push(mp(i,j));
        set<PI> dis;
        dis.insert(mp(i,j));
        //cout<<i<<" "<<j<<endl;
        int dou=0;
        while(!Q.empty()){
          int cx=Q.front().F,cy=Q.front().S;Q.pop();
          ++dou;
          rep(i,4){
            int nx=cx+dx[i],ny=cy+dy[i];
            if(dis.count(mp(nx,ny)) || nx<0 || nx>=12 || ny<0 || ny>=6 || (in[nx][ny]!='O' && in[nx][ny]!=in[cx][cy]))continue;
            if(in[nx][ny]!='O')Q.push(mp(nx,ny));
            dis.insert(mp(nx,ny));
          }
        }

        if(dou>3){
          end=false;
          FOR(siter,dis){
            int tx=siter->first,ty=siter->second;
            in[tx][ty]='.';
          }
        }
      }

      if(end)break;
      ++ans;

      for(int i=11;i>=0;i--){
        rep(j,6){
          if(in[i][j]!='.'){
            int ti=i;
            while(ti<11 && in[ti+1][j]=='.'){
              in[ti+1][j]=in[ti][j];
              in[ti][j]='.';
              ++ti;
            }
          }
        }
      }
      //rep(i,12)cout<<in[i]<<endl;
      //cout<<endl;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
console.log(function(args){
  const map = args.trim().split('\n');
  const [H,W] = map.shift().split(' ').map( v=>v|0 );
  const dp = Array(H).fill(0).map( r=>Array(W).fill(0) );
  dp[0][0] = 1;
  for ( let h = 0; h < H; h++ ) {
    for ( let w = 0; w < W; w++ ) {
      if ( map[h][w] === '#' ) continue;
      if ( h > 0 ) dp[h][w] = (dp[h][w] + dp[h-1][w]) % (1e9+7);
      if ( w > 0 ) dp[h][w] = (dp[h][w] + dp[h][w-1]) % (1e9+7);
    }
  }
  return dp[H-1][W-1].toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m; cin>>n>>m;
    if (n>m) swap(n,m);
    if (n==1 && m==1){
        cout<<"1\n";
        return 0;
    }
    if (n==1){
        cout<<m-2<<"\n";
        return 0;
    }
    cout<<(m-2)*(n-2)<<endl;
    return 0;
}


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

int main() {
    string a;
    cin >> a;
    string b = "sbc";
    char s = b[0];
    int len = a.size();
    int len2 = len - 1;
    char c0 = a[len2];
    if (c0 == s) {
        cout << a << "es\n";
    }
    if (c0 != s) {
        cout << a << "s\n"; 
    }

    return 0;
}

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

using namespace std;

int main() {
    int n, k, q;
    cin >> n >> k >> q;

    vector<int> myvs(n, k);
    int pos;
    for(int i = 0; i < q; i++) {
        cin >> pos;
        myvs[pos-1]++;
    }
    for(int i = 0; i < n; i++) {
        if (myvs[i]-q > 0) {
            cout << "Yes" << '\n';
        }
        else {
            cout << "No" << '\n';
        }
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;

ll calc(ll x) {
  if (x == 1LL) {
    return 1LL;
  }
  return 1LL + 2LL * calc(x / 2LL);
}
int main() {
  ll n;
  cin >> n;
  cout << calc(n) << endl;
}

Measured memory_bytes: 256
from statistics import mean
import math

n = int(input())
a = list(map(int,input().split()))
m = mean(a)
u = math.ceil(m)
l = math.floor(m)
ans = 0
can = 0
for i in a:
  ans += (i-u)**2
  can += (i-l)**2
  
print(min(ans,can))  

Measured memory_bytes: 5084
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin >> a >> b;
    if(a < b) cout<<"a < b"<<endl;
    else if(a > b) cout<<"a > b"<<endl;
    else cout<<"a == b"<<endl;
    return 0;
}


Measured memory_bytes: 3120
import sys
input = sys.stdin.readline
import itertools

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for n in range(M)]
branch = [[False]* N for n in range(N)]

for m in range(M):
  a = ab[m][0] - 1
  b = ab[m][1] -1 
  branch[a][b] = True
  branch[b][a] = True

ans = 0
pattern = itertools.permutations(range(1, N+1),N)
for l in pattern:
  if l[0] != 1:
    continue
  for n in range(N):
    if n == N - 1:
      ans += 1
      break
    p = l[n] -1
    np = l[n+1] -1
    if not(branch[p][np]):
      break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n; cin >> n;
	int m = n % 10;
	if (m==2||m==4||m==5||m==7||m==9) puts("hon");
	else if (m==0||m==1||m==6||m==8) puts("pon");
	else puts("bon");
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main(void) {
  int n, t, i, j;
  double max = 0;
  scanf("%d%d", &n, &t);
  for(i = 0; i < n; ++i) {
    int x, h;
    scanf("%d%d", &x, &h);
    if(max < (double)h / (double)x) max = (double)h / (double)x;
  }
  printf("%f\n", max * t);
  return 0;
}


Measured memory_bytes: 2752
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k, x; cin >> k >> x;
	if (500 * k >= x) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,mn,mx,i,j,t;
    while(cin>>n>>m)
    {
        mn=min(n,m);
        mx=max(n,m);
        for(i=1;i<=mx;i++)
        {
            cout<<mn;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<cmath>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
const unsigned int M = 1000000007;
using namespace std;
 
int main()
{
long long n,m=1; cin>>n;
for(long long i=1;i<=n;i++)
{
   m=(m*i)%M;
}
cout<<m;
return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N, K, t[55];
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> t[i];
	sort(t, t + N, greater<int>());
	int an = 0;
	for (int i = 0; i < K; i++) an += t[i];
	cout << an << endl;
}


Measured memory_bytes: 256
using System;
using static System.Console;
class E { static void Main() => new K(); }
class K
{
	public K()
	{
		var s = ReadLine();
		var i = s.IndexOf('C');
		Console.WriteLine(i >= 0 && s.IndexOf('F', i) >= 0 ? "Yes" : "No");
	}
}


Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int x,n;
  cin>>x>>n;
  set<int> p;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin>>tmp;
    p.insert(tmp);
  }
  int i=0;
  while(true)
  {
    int y=x-i;
    if(p.find(y)==p.end())
    {
      cout<<y;
      return 0;
    }
    y=x+i;
    if(p.find(y)==p.end())
    {
      cout<<y;
      return 0;
    }
    i++;
  }

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
4
WWRR

RRWWにする必要がある
*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N, ans = 0;
  cin >> N;
  string S;
  cin >> S;
  ll i=0, j=S.size()-1;
  while (S[i]){
    if (S[i] == 'W'){
      while(S[j] == 'W' && j > i){
        j--;
      }
      if (j > i){
        swap(S[i], S[j]);
        ans++;
      }
      else
        break;
    }
    i++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3728
s = input()

a=s[0]
b=s[1]
c=s[2]
d=s[3]

ops = ['+','-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            equation = "".join([a,op1,b,op2,c,op3,d])
            solution = eval(equation)
            if solution ==7:
                answer = equation + "=7"

#7にしたい

print(answer)


Measured memory_bytes: 3064
# Author: cr4zjh0bp
# Created: Mon Mar  2 00:21:30 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N = ni()
dp = [inf for _ in range(N + 1)]
dp[0] = 0

for i in range(1, N + 1):
    t = 1
    while t <= i:
        dp[i] = min(dp[i], dp[i - t] + 1)
        t *= 6
    t = 1
    while t <= i:
        dp[i] = min(dp[i], dp[i - t] + 1)
        t *= 9

print(dp[N])

Measured memory_bytes: 3992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		final long M = 1000000007;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(tokens[i]);
		long sum = 0;
		for (int i = 1; i < n; i++) {
			sum += a[i];
		}
		long ans = (a[0]*(sum%M))%M;
		for (int i = 1; i < n-1; i++) {
			sum -= a[i];
			ans = ((a[i]*(sum%M))%M+ans)%M;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 55700
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string S,T;
  cin>>S>>T;
  cout<<T<<S<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

using namespace std;

#define MOD 1000000007
#define INF 100000000000000000
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ALL(x) ((x).begin(), (x).end())
#define sync(); ios_base::sync_with_stdio(0);

inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


ll ex_euclid(ll a, ll b, ll &x, ll &y){
  ll xx,yy;
  x = yy = 1;
  xx = y = 0;
  while(b){
    ll m = a / b;
    ll t = xx;
    xx = x - m * xx;
    x = t;
    t = yy;
    yy = y - m * yy;
    y = t;
    t = b;
    b = a % b;
    a = t;
  }

  return a;
}

ll inverse(ll a){
  pair<ll,ll> p {MOD,a};
  pair<pair<ll,ll>,pair<ll,ll>> k {{1,0}, {0,1}};
  while(1){
    if(p.second == 1){
      return k.second.second;
    }
    ll temp = p.second;
    pair<ll,ll> tempp = k.second;
    k.second.first = k.first.first - (p.first / p.second) * k.second.first;
    k.second.second = k.first.second - (p.first / p.second) * k.second.second;
    p.second = p.first % p.second;
    p.first = temp;
    k.first = tempp;
  }
}

ll pw(ll a, ll b){
  ll ans = 1;
  ll mul = a;
  
  while(b){
    if((b & 1ll) == 1){
      ans *= mul;
      ans %= MOD;
    }
    mul = mul * mul;
    mul %= MOD;
    b = (b >> 1);
  }
  return ans;
}



int main(){
  sync();
  ll n;
  cin >> n;
  cout << n << ":";
  while(n > 1){
    ll i = 2;
    
    while(1){
      if(n % i == 0){
	n = n / i;
	cout << ' ' << i;
	break;
      }
      
      i++;
      if(i * i > n){
	cout << ' ' << n << endl;
	return 0;
      }
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int N, M;
bool G[8][8]; // 2<= N <= 8

int main()
{
    cin >> N >> M;
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a][b] = G[b][a] = true;
    }

    vector<int> P(N);
    rep(i, N)
    {
        P[i] = i;
    }
    int ans = 0;

    // 順列の全探索
    do
    {
        if (P[0] != 0)
        {
            break; // 1始点じゃないとダメ
        }

        bool ok = true;
        rep(i, N - 1)
        {
            int from = P[i];
            int to = P[i + 1];
            if (!G[from][to])
            {
                ok = false;
            }
        }
        if (ok)
        {
            ans++;
        }
    } while (next_permutation(P.begin(), P.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long lint;

int dp[1111][1111];

void chmax(int& x, const int y) {
    x = max(x, y);
}

int main() {
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
        string X, Y;
        cin >> X >> Y;
        const int N = X.size(), M = Y.size();
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= M; j++) {
                dp[i][j] = 0;
            }
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= M; j++) {
                chmax(dp[i][j], dp[i-1][j]);
                chmax(dp[i][j], dp[i][j-1]);
                if (X[i-1] == Y[j-1]) chmax(dp[i][j], dp[i-1][j-1] + 1);
            }
        }
        cout << dp[N][M] << endl;
    }
    return 0;
}


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

template<class T>
class Queue{
private:
  T* data;
  int size;
  int rp=0;//次に入れる
  int fp=0;//次に出す
public:
  Queue(int x){data=new T[x+1];size=x+1;}
  void enqueue(T x){
    data[rp]=x;
    rp++;
    if(rp==size)rp=0;
  }
  T front(){return data[fp];}
  void dequeue(){
    fp++;
    if(fp==size)fp=0;
  }
  bool isFull(){
    if(fp==0)return rp==size-1;
    else return fp-1==rp;
  }
  bool isEmpty(){
    return rp==fp;
  }
};

int main(){
  int n,q;
  cin>>n>>q;
  Queue<string> p_name(n);
  Queue<int> p_time(n);

  string tmp1;
  int tmp2;
  for(int i=0;i<n;i++){
    cin>>tmp1>>tmp2;
    p_name.enqueue(tmp1);
    p_time.enqueue(tmp2);
  }

  int turn_around_time=0;int not_completed=n;
  while(not_completed){
    if(p_time.front()>q){
      string tmp_s=p_name.front();
      p_name.dequeue();
      p_name.enqueue(tmp_s);
      int tmp_i=p_time.front()-q;
      p_time.dequeue();
      p_time.enqueue(tmp_i);
      turn_around_time+=q;
    }
    else{
      turn_around_time+=p_time.front();
      p_time.dequeue();
      cout<<p_name.front()<<' '<<turn_around_time<<endl;
      p_name.dequeue();
      not_completed--;
    }
  }
}



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

int main(void){
    ll N;
    cin>>N;
    int min = 1e6;
    for (ll i=1;i*i<=N;i++){
        if (N%i==0){
            string A = to_string(i);
            string B = to_string(N/i);
            int F = max(A.size(),B.size());
            if (min>F) min = F;
        }
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
l = list(map(int,input().split()))
l_ans = [0,abs(l[1]-l[0])]+[0]*(n-2)
for i in range(2,n):
    tmp1=float("inf")
    for j in range(1,min(i+1,k+1)):
        tmp2=l_ans[i-j]+abs(l[i]-l[i-j])
        if tmp1>tmp2:tmp1=tmp2
    l_ans[i]=tmp1
print(l_ans[::-1][0])

Measured memory_bytes: 53216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int x,n;
  cin >> x >> n;
  if(n == 0){
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  rep(i,n){
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  p.push_back(0);
  int count = 0;
  int diff = 1000;
  int ans = -1;
  rep(i,103){
    if(i == p.at(count)){
      count++;
      continue;
    }
    if(diff > abs(x-i)){
      diff = min(abs(x-i),diff);
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
 
  int n;
  cin>>n;
vector<int>s(n);
  int c=0;
  
for(int i=0;i<n;i++){
  
 cin>>s.at(i);
}
sort(s.begin(),s.end(),std::greater<>());  
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
      if(s.at(i)<s.at(j)+s.at(k)){
      c+=1;
      }
      else{break;}
  
    }
  }
  }
  cout<<c<<endl;
 }
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long N,L;
    cin>>N>>L;
    vector<long> aji(N);
    for(int i=0;i<N;i++){
        aji.at(i)=L+i;
    }
    
    
    long sute=INF,sum=0;
    for(int i=0;i<N;i++){
        sum+=aji.at(i);
        if(abs(aji.at(i))<abs(sute)) sute=aji.at(i);
    }
    
    cout<<sum-sute<<endl;
}

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

bool bad(const pair<int, int>& p1, const pair<int, int>& p2) {
    return p1.first > p2.first;
}

void solve() {
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> row(H, 0);
    vector<int> col(W, 0);
    set<pair<int, int>> st;
    for (int i = 0; i < M; ++i) {
        int h, w; cin >> h >> w; h--; w--;
        row[h]++;
        col[w]++;
        st.insert({h, w});
    }
    set<pair<int, int>, greater<pair<int, int>>> st1;
    set<pair<int, int>, greater<pair<int, int>>> st2;
    for (int i = 0; i < H; ++i) {
        if (row[i] == 0) continue;
        st1.emplace(row[i], i);
    }
    for (int i = 0; i < W; ++i) {
        if (col[i] == 0) continue;
        st2.emplace(col[i], i);
    }

    int ans = 0;
    for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) {
        if (bad(*st1.begin(), *it1)) break;
        for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) {
            if (bad(*st2.begin(), *it2)) break;
            int temp = it1->first + it2->first;
            if (st.count({it1->second, it2->second})) { temp--; }
            if (ans > temp) {
                cout << ans << endl;
                return;
            }
            ans = max(ans, temp);
        }
    }
    cout << ans << endl;
}

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

    int t = 1;
    while(t--) {
        solve();
    }
}


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

int d, g;
pair<int,int> p[11];
int ans = 100000000;

void rec(int u, bool c[]){
  if ( u > d ){
    int point = 0, cnt = 0;
    for ( int i = 1; i <= d; i++){
      if ( c[i] ){
        int sum = p[i].second + (p[i].first * i * 100);
        point += sum;
        cnt += p[i].first;
      }
    }
    int i = d;
    int pcnt = 0;
    while(1){
      if ( point >= g){
        ans = min(ans, cnt);
        break;
      }
      if ( i == 0)break;
      if ( !c[i] && p[i].first > pcnt){
        point += i * 100;
        cnt ++;
        pcnt++ ;
      } else {
        i--;
        pcnt = 0;
      }
    }
    return;
  }
  c[u] = true;
  rec(u+1, c);
  c[u] = false;
  rec(u+1, c);
}

int main(){
  cin >> d >> g;
  int a, b;
  bool c[d+1];
  for ( int i = 1; i <= d; i++){
    cin >> a >> b;
    p[i] = make_pair(a, b);
    c[i] = false;
  }

  rec(1, c);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int max = -1000000,min = 1000000,n,i,a;
    long long sum = 0;
    scanf("%d",&n);
    
    for(i = 0;i < n;i++){
        scanf("%d",&a);
        if(max < a) max = a;
        if(min > a) min = a;
        sum += a;
    }
    
    printf("%d %d %lld\n",min,max,sum);
    
    return 0;
}


Measured memory_bytes: 2112