akhauriyash/Code-Regression huggingface dataset:
#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
  int N, M;
  while(cin >> N >> M && N >0)
    {
      pair<int, int> PD[10000];
      for(int i=0;i<N;i++)
	cin >> PD[i].second >> PD[i].first;
      sort(PD, PD+N);
      int Mcur = M;
      int sum = 0;
      for(int i=0;i<N;i++)
	sum += PD[i].first * PD[i].second;
      for(int i=N-1;i>=0;i--)
	{
	if(Mcur <= PD[i].second)
	  {
	  sum -= Mcur*PD[i].first;
	  break;
	  }
	else
	  {
	  sum -= PD[i].first*PD[i].second;
	  Mcur -= PD[i].second;
	  }
	}
      cout << sum << endl;
    }
}


Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	vector<string> Si(N);
	vector<int> Ci(4, 0);

	rep(i, N)
	{
		cin >> Si.at(i);
		if (Si.at(i) == "AC")
		{
			Ci.at(0) += 1;
		}
		else if (Si.at(i) == "WA")
		{
			Ci.at(1) += 1;
		}
		else if (Si.at(i) == "TLE")
		{
			Ci.at(2) += 1;
		}
		else
		{
			Ci.at(3) += 1;
		}
	}

	cout << "AC x " << Ci.at(0) << endl;
	cout << "WA x " << Ci.at(1) << endl;
	cout << "TLE x " << Ci.at(2) << endl;
	cout << "RE x " << Ci.at(3) << endl;

	return 0;
}

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

#define LL long long
#define lowbit(x) ((x) & -(x))

const int maxn = (int) 1e5 + 20;
const int MOD = 1e9 + 7;

LL fp(LL a, LL n, LL m = MOD)
{
    LL res = 1;
    for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m;
    return res;
}

int n, m;
int s[3333], t[3333];
int dp[3333][3333];

void work()
{
    cin >>n >>m;
    for(int i = 1; i <= n; i++) cin >>s[i];
    for(int j = 1; j <= m; j++) cin >>t[j];

    for(int i = 0; i <= n; i++) dp[i][0] = 1;
    for(int j = 0; j <= m; j++) dp[0][j] = 1;

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
            dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;

            if(s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];
            dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;

        }
    cout <<dp[n][m] <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 26752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
vector<ll> work(1);

void func(ll val,int l, int r){
	//fprintf(stderr,"l=%d, r=%d",l,r);
	if(r-l == 1){
		work[r]=val;
		return;
	}
	if(work[(l+r)/2] >= val)func(val,(l+r)/2,r);
	else func(val,l,(l+r)/2);
}

int main(void){
	int n;
	cin>>n;
	
	cin>>work[0];

	rep(i,n-1){
		ll tmp;
		cin>>tmp;
		if(work.size()==1){
			if(work[0] < tmp)work[0]=tmp;
			else work.push_back(tmp);
			continue;
		}
		if(work[work.size()-1] >= tmp)work.push_back(tmp);
		else if(work[0] < tmp)work[0]=tmp;
		else func(tmp,0,work.size()-1);
	}

	cout<<work.size()<<endl;
	return 0;
}


Measured memory_bytes: 1400
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for ap in range(a+1):
	for bp in range(b+1):
		for cp in range(c+1):
			val = 500*ap + 100*bp + 50*cp
			if val == x:
				count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  int ans = 0;
  if (N <= K) {
    ans = N * X;
  }
  else {
    ans = K * X + (N - K) * Y;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solveA();
	}

	private void solveA() {
        Scanner sc = new Scanner(System.in);
        String N = sc.nextLine();
        String[] a = N.split("");
        int sum = 0;

        for(int i=0; i < 3; i++){
        	if(Integer.parseInt(a[i]) == 1){
        		sum = sum + 1;
        	}
        }

        	System.out.println(sum);
    }

	private void solveB() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveE() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveF() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

}

Measured memory_bytes: 21844
from collections import Counter

def cal(D,M):
    C = Counter(D)
    MC = C.most_common()
    MC.sort(key = lambda x:x[0])
    n = len(MC)
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i-1]は頂点iの深さと見なせる
    for i in range(n):
        if MC[i][0] != i:
            #深さiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1 or D[0] != 0:
        #1以外の根がある又は1が根になってない
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],M)
        output %= M
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353

    ans = cal(D,M)
    print(ans)

if __name__ == "__main__":
    main()


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if(a + b > c + d){
		cout << "Left" << endl;
	}else if(a + b == c + d){
		cout << "Balanced" << endl;
	}else{
		cout << "Right" << endl;
	}
}


Measured memory_bytes: 3572
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s1);
fscanf(STDIN, "%s", $s2);

$i = $p = 0;
$m = 1000000007;
while (isset($s1[$i])) {
	if ($s1[$i] == $s2[$i]) {
		if ($p == 1) {
			$x *= 2;
		} elseif (!$p) {
			$x = 3;
		}
		$p = 1;
		$i++;
	} else {
		if ($p == 1) {
			$x *= 2;
		} elseif ($p == 2) {
			$x *= 3;
		} else {
			$x = 6;
		}
		$p = 2;
		$i += 2;
	}
	$x %= $m;
}
echo $x;

Measured memory_bytes: 4728
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue(){
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b){ return a<b ? a : b;}

int main(){
	int elaps = 0, c;
	int i,q;
	P u;
	scanf("%d %d", &n, &q);
	
	for( i = 1; i <= n; i++ ){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	
	head = 1; tail = n + 1;
	
	while( head != tail ){
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if( u.t > 0 )enqueue(u);
		else{
			printf("%s %d\n",u.name, elaps);
		}
	}
	
	return 0;
}


Measured memory_bytes: 11896
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>199
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 2000001

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

void solve()
{
  li k;
  cin>>k;

  string s;
  cin>>s;

  if(size(s)<=k)
    cout<<s<<'\n';
  else
    cout<<s.substr(0,k)<<"..."<<endl;

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

    solve();
    
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
 
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(y,x%y);
}
 
ll lcm(ll x, ll y){
	return (x*y/gcd(x,y));
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int h,w;
	cin >> h >> w;
	string a[h];
	REP(i,h) cin >> a[i];
	bool bh[h],bw[w];
	memset(bh,false,sizeof(bh));
	memset(bw,false,sizeof(bw));
	REP(i,h)REP(j,w){
		if(a[i][j]=='#'){
			bh[i]=1;
			bw[j]=1;
		}
	}
	REP(i,h){
		if(bh[i]){
			REP(j,w){
				if(bw[j]) cout << a[i][j];
			}
			cout << endl;
		}
	}
/////////////////////////////////////////////
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	long double a,b;
	cin>>n;
	if (n%2==0)
	{
		cout<<setprecision(8)<<1.0/2.0<<endl;
	}
	else
	{
		cout<<setprecision(8)<<((n/2+1)*1.0)/(n*1.0)<<endl;
	}
	
}

Measured memory_bytes: 256
n,k = map(int,input().split())

s = str(input())

a = 0
if n == 1:
    print(0)
else:
    for i in range(n-1):
        if s[i] == s[i + 1]:
            a += 1
    print(min(a + 2 * k,n-1))
    

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <complex>
#include <cstdio>

using namespace std;

#define all(c) c.begin(),c.end()
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,n) loop(i,0,n)

typedef long long ll;
typedef complex<double> P;
typedef vector<P> Pol;

P NA(1e10,1e10);

P solve(Pol const& pol){
    int n=pol.size();
    if(n&1) return NA;

    P m = (pol[0]+pol[n/2])/2.;
    bool ok=true;
    rep(i,n/2){
        P t((pol[i]+pol[(i+n/2)%n])/2.);
        if(abs(m-t) > 1e-6){
            ok = false;
            break;
        }
    }
    return ok ? m : NA;
}

int main(){
    int n;
    while(cin >> n){
        Pol pol(n);
        rep(i,n){
            double x,y;cin>>x>>y;
            pol[i]=P(x,y);
        }
        P ans=solve(pol);
        if(ans == NA){
            puts("NA");
        } else {
            printf("%.10lf %.10lf\n",ans.real(),ans.imag());
        }
    }
}

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


void solve(){
    ll n;
    cin>>n;
    ll rem, num = 26;
    string str="";

        while(n != 0){
            // cout<<1<<endl;
            rem = n%26;
            if(rem == 0){
                str += 'z';
                n = n/26;
                n--;
            }
            else{
                rem--;
                n = n/26;
                char ch = 'a';
                ch += rem;
                str += ch;
            }
            
            
            // n;
        }
    reverse(str.begin(),str.end());
    cout<<str<<endl;


}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}


Measured memory_bytes: 3620
using System;

class A{
  public static void Main(){
    int n,count = 0;
    n = int.Parse(Console.ReadLine());
    int[] array = new int[n];

    string[] str = Console.ReadLine().Split(' ');
    for(int i = 0;i < n;i++){
      array[i] = int.Parse(str[i]);
    }

    for(int i = 0;i < n - 1;i++){
      for(int j = n - 1;j > i;j--){
        if(array[j].CompareTo(array[j-1]) < 0){
          Swap(ref array[j],ref array[j-1]);
          count++;
        }
      }
    }

    for(int i = 0;i < n - 1;i++){
    Console.Write(array[i] + " ");
    }
    Console.Write(array[n - 1]);
    Console.WriteLine("");

    Console.WriteLine(count);
    }

    static void Swap(ref int x,ref int y){
      int temp;
      temp = x;
      x = y;
      y = temp;
    }
}



Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
int n,a,b;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if((a%2)==0){
            if(((a%3)==0)||((a%5)==0)){}
            else{
                b++;
                break;
            }
        }
    }
    
    if(b!=0)cout<<"DENIED"<<endl;
    else cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int count_divisor(int n) {
    int count = 0;
    int N = n;
    for(int i = 2; i <= (int)sqrt(N) ; ++i) {
        if (n % i == 0) {
            count++;
            while (n % i == 0)
                n /= i;
        }
    }
    if (n != 1) count++;
    return count;
}

signed main() {
    int a, b;
    cin >> a >> b;
    int d = __gcd(a, b);
    int result = count_divisor(d) + 1;
    cout << result << "\n";
}

Measured memory_bytes: 256
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2020
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> cities(n);
    vector<int> scores(n);
    vector<int> idxes(n);
    for(int i = 0; i < n; ++i) {
        idxes[i] = i;
        cin >> cities[i] >> scores[i];
    }
    sort(idxes.begin(), idxes.end(), [&](int a, int b) {
            return cities[a] == cities[b] ? scores[a] > scores[b] : cities[a] < cities[b];});
    for(int idx : idxes) cout << idx + 1 << endl;
    return 0;
}



Measured memory_bytes: 256
N, W = gets.chomp.split(" ").map(&:to_i)
G = []
N.times{
  G << gets.chomp.split(" ").map(&:to_i)
}

T = Array.new(4).map{Array.new}
X = G[0][0]
G.each{|w, v|
  T[w - X] << v
}
T.map!{|t| tmp=0; t.sort.reverse.map{|tt| tmp += tt}.unshift(0)}

@ans = 0

def solve(idx, cnt, val, wgt)
  r = [T[idx].size-1, cnt].min
  (0..r).each{|j|
    n_v = val+T[idx][j]
    n_w = wgt+(X+idx)*j
    next if n_w > W
    if idx == 3 then
      @ans = n_v if @ans < n_v
    else
      solve(idx+1, cnt-j, n_v, n_w)
    end
  }
end

solve(0, W/X, 0, 0)

puts @ans


Measured memory_bytes: 1788
#include <iostream>

int main()
{
    int W, H, x, y, r;
    std::cin >> W >> H >> x >> y >> r;
    if ((x >= r) && (y >= r) && (x + r <= W) && (y + r <= H)) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1156
import java.util.*
class SearchInfo(val nodeNumber: Int, val visitedNodes: Set<Int>)
fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val graph = Array(N, { Array(N, { false }) })

    (1..M).forEach {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        graph[a-1][b-1] = true
        graph[b-1][a-1] = true
    }

    val queue : Queue<SearchInfo>  = ArrayDeque()

    graph[0].forEachIndexed { nodeNum, exists ->
        if (exists) {
            queue.offer(SearchInfo(nodeNum, setOf(0, nodeNum)))
        }
    }

    var count = 0
    while (queue.isNotEmpty()) {
        val searchInfo = queue.poll()
        if (searchInfo.visitedNodes.size == N) {
            count++
        } else {
            val currentNodeNum = searchInfo.nodeNumber
            graph[currentNodeNum].forEachIndexed{ node, exists ->
                if (exists && !searchInfo.visitedNodes.contains(node)) {
                    //println(searchInfo.visitedNodes.plus(node).toString())
                    queue.offer(SearchInfo(node, searchInfo.visitedNodes.plus(node)))
                }
            }
        }
    }

    println(count)
}

Measured memory_bytes: 40664
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

int arr[100010];
ll sum[100010];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		sum[0] = 0ll;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&arr[i]);
		}
		
		sort(arr+1,arr+1+n);
		
		for(int i=1;i<=n;i++)
		sum[i] = sum[i-1] + arr[i]*1ll;
		
		int mid = 0;
		for(int i=1;i<=n;i++)
		{
			if(arr[i]*1ll > 2ll*sum[i-1])
			mid = i;
		}
		int ans = n - mid + 1;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  vector<int>a(5,0);
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=="AC"){
      a.at(0)++;
    }
    if(s=="WA"){
      a.at(1)++;
    }
    if(s=="TLE"){
      a.at(2)++;
    }
    if(s=="RE"){
      a.at(3)++;
    }
  }
  cout << "AC x "<<a.at(0)<<endl;
  cout << "WA x "<<a.at(1)<<endl;
  cout << "TLE x "<<a.at(2)<<endl;
  cout << "RE x "<<a.at(3)<<endl;
}

Measured memory_bytes: 3620
#python3

class Light:
    def __init__(self, conect, condition):
        self.conect = conect 
        self.condition = condition

def main():
    n, m = map(int, input().split())
    preArray = []
    for i in range(m):
        tmp = [int(i) - 1 for i in input().split()][1:]
        preArray.append(tmp)
    ps = [int(i) for i in input().split()]


    Lights = []
    for i in range(m):
        Lights.append(Light(preArray[i], ps[i]))



    ans = 0
    for i in range(1<<n):
        swichState = [0 for _ in range(n)]
        for k in range(n):
            if (i >> k) & 1:
                swichState[k] = 1
        
        #print(swichState)

        flag = True
        for j in range(m):
            conec = Lights[j].conect
            cond = Lights[j].condition
            cnts = 0
            for k in range(len(conec)):
                if swichState[conec[k]] == 1:
                    cnts += 1 
            if cnts % 2 == cond:
                continue
            else:
                flag = False
                break
        if flag:
            ans += 1

    print(ans)
main()


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

Matches = {num: c for num, c in zip([1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 5, 5, 4, 5, 6, 3, 7, 6])}
dp = [-1 for _ in range(N + 1)]
dp[0] = 0
for a in sorted(A, reverse=True):
    c = Matches[a]
    for i in range(N - c + 1):
        if dp[i] == -1:
            continue
        dp[i+c] = max(dp[i+c], dp[i] * 10 + a)

print(dp[N])

Measured memory_bytes: 67292
def solve():
    n = int(input())
    a = list(map(int, input().split()))

    one = n*(n+1)/2

    if sum(a) % one != 0:
        print("NO")
        return
    else:
        nop = sum(a) / one

    d = [0 for i in range(n)]
    for i in range(n):
        d[i] = a[(i+1)%n] - a[i]
        d[i] = d[i] - nop

    count = 0

    for i in range(n):
        if d[i] != 0:
            if d[i] % n != 0 or d[i] > 0:
                print("NO")
                return
            count = count + (-1*d[i]) / n
            d[i] = 0
            if count > nop:
                print("NO")
                return

    if sum(d) == 0 and count == nop:
        print("YES")
    else:
        print("NO")

solve()

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

int main(){
	int A[1001];//ソートする数列を格納する配列
	int num;//数列の長さ

	//配列を0で初期化
	for(int i=0;i<1001;i++){
		A[i] = 0;
	}

	cin >>num;
	
	for(int i=0;i<num;i++){
		scanf("%d",&A[i]);
	}

	void selectionSort(int A[],int N);//プロトタイプ宣言
	selectionSort(A,num);

	return 0;
}

void selectionSort(int A[],int N){
	int minj;//minjはA[i]?A[N-1]の最小値の添え字
	int tmp;
	int cnt=0;//交換回数
	for(int i=0;i<N;i++){
		minj = i;
		for(int j=i;j<N;j++){
			if(A[j] < A[minj]){
				minj = j;
			}
		}
		if(minj != i)
			cnt++;
		tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;
	}
	//ソート完了後の状態を出力
		for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
		cout <<cnt <<endl;
}

Measured memory_bytes: 1248
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;
int n,m;
vector<int> prime;
unordered_map<int,int> prco;
bool flag2[101][101];
bool flag3[101][101][101];
void prfac(int n){
	int a=2;
	while(n>=a*a){
		if(n%a==0){
			prco[a]++;
			n/=a;
		}
		else{
			a++;
		}
	}
	prco[n]++;
}
signed main(){
	cin>>n;
	rep(i,n)prfac(i+1);
	for(auto x:prco){
		if(x.second>=74)ans++;
		for(auto y:prco){
			if(x.first==y.first || flag2[x.first][y.first])continue;
			flag2[x.first][y.first]=true;
			flag2[y.first][x.first]=true;
			if(x.second>=2&&y.second>=24)ans++;
			if(x.second>=24&&y.second>=2)ans++;
			if(x.second>=4&&y.second>=14)ans++;
			if(x.second>=14&&y.second>=4)ans++;
			for(auto z:prco){
				if(x.first==z.first || y.first==z.first || flag3[x.first][y.first][z.first])continue;
				flag3[x.first][y.first][z.first]=true;
				flag3[x.first][z.first][y.first]=true;
				flag3[y.first][x.first][z.first]=true;
				flag3[y.first][z.first][x.first]=true;
				flag3[z.first][x.first][y.first]=true;
				flag3[z.first][y.first][x.first]=true;
				if(x.second>=2&&y.second>=4&&z.second>=4)ans++;
				if(x.second>=4&&y.second>=2&&z.second>=4)ans++;
				if(x.second>=4&&y.second>=4&&z.second>=2)ans++;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    int A = abs(x - a);
    int B = abs(x - b);

    if (A < B) { cout << "A" << endl; }
    else { cout << "B" << endl; }

    return 0;
}

Measured memory_bytes: 256
k = int(input())

def dfs(now, depth):
    STACK.append(str(now))
    if depth == limit:
        LUNLUN.append(int("".join(STACK)))
    else:
        for next in range(now - 1, now + 2):
            if next == -1 or next == 10:
                continue
            dfs(next, depth + 1)
    STACK.pop()

LUNLUN = []
STACK= []
for limit in range(10):
    for i in range(1, 10):
        dfs(i, 0)

print(LUNLUN[k - 1])


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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
			pr.println("Possible");
		} else {
			pr.println("Impossible");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = (ll)(1e9) + 7;
vector<vector<int>> g;
vector<vector<ll>> dp;
int n;
//  goi dp[u][0,1] la xet cay goc u dinh u to mau (0,1)
// gia su ghep v vao
void add(ll &a,ll b){
    a += b;
    a %= Mod;
}

void mul(ll &a,ll b){
    a = ((a% Mod) * (b % Mod)) % Mod;
}
void dfs(int u,int p){
    dp[u][0] = dp[u][1] = 1;
    for (int v: g[u]){
        if (v == p) continue;
        dfs(v,u);
        mul(dp[u][0],(dp[v][1] + dp[v][0]) % Mod);
        mul(dp[u][1],dp[v][0]);
    }

    
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;

    g.resize(n);
    dp.resize(n, vector<ll> (2,0));
    for (int i = 0; i < n - 1; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }

    dfs(0,-1);
    cout << (dp[0][1] + dp[0][0]) % Mod;
    return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  long long n;
  cin >> n;
  int i;
  long long sum = 0;
  if(n==1){
    cout << 0 << "\n";
    return 0;
  }
  for(i=2;i<n;i++) sum += i;
  cout << sum+1 << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();

		ArrayDeque<Integer> a1 = new ArrayDeque<>();
		ArrayDeque<Integer> a2 = new ArrayDeque<>();
		for(int i=0; i<n; i++) {
			int d = sc.nextInt();
			a1.push(d);
			a2.add(d);
			ArrayDeque<Integer> tmp;
			tmp = a1;
			a1 = a2;
			a2 = tmp;
		}
		for(int i=0; i<n; i++) {
			if(i>0)System.out.print(" ");
			System.out.print(a2.poll());
		}
		System.out.println();
		sc.close();
	}





}


Measured memory_bytes: 81148
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
double ans,n;
void solve()
{
    cin>>n;
    cout<<fixed<<setprecision(12)<<n*n*n/27<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}

int main()
{
    IOS;
    ll n;cin>>n;
    if(n&1)cout<<0<<endl;
    else{
        n/=2;
        ll two=0,temp=n,five=0;
        while(temp>0)
        {
            temp/=5;
            five+=temp;
        }
        cout<<five<<endl;
    }

}








Measured memory_bytes: 256
#include <stdio.h>
int main (void){
        int i=-1;
        char dr[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
       char dr_[26]="DEFGHIJKLMNOPQRSTUVWXYZABC";
        char ny[1001];
while (1){
i++;
scanf ("%c",&ny[i]);
if (ny[i]==10)break;
}
for (int s=0;s<i;s++){
        for (int s_=0;s_<26;s_++){
                if (ny[s]==dr_[s_]){
                        ny[s]=dr[s_];
                        break;
                }
        }
}
for (int s=0;s<i;s++){
        printf ("%c",ny[s]);
}
printf ("\n");
return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll x;
  cin >> x;
  if(x) cout<<0<<endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 3608
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,m = li()

# graph
adj_list = [[] for _ in range(n)]

for _ in range(m):
    a,b,c = li()
    a -= 1
    b -= 1
    adj_list[a].append((c,b))

# bellman-ford
INF = -10**15
dist = [INF]*n
dist[0] = 0
for j in range(n+1):
    for i in range(n):
        updated = False
        for cost, nex in adj_list[i]:
            bef = dist[nex]
            dist[nex] = max(dist[nex], dist[i]+cost)
            if bef != dist[nex]:
                updated = True
        
    if j == n-1:
        dis_j1 = dist[n-1]
        
    if j == n:
        dis_j = dist[n-1]
        
if dis_j1 != dis_j:
    print("inf")
else:
    print(dis_j)

Measured memory_bytes: 3316
/*
ID: Aman Raj
LANG: C++
TASK: preface
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

	   //vector<ll > vten(7),vfive(7),vfifty(7),vhundred(7),vfivehundred(7),vthousand(7);

int main()
{
      ifstream fin("preface.in");
      ofstream fout("preface.out");
      ll n,tw;cin>>n>>tw;
        vector<pair<ll,ll> > v(n+1);
         v[0]=make_pair(0,0);
        //v[0].resize(n+1,{0,0});
        for(ll i=1;i<=n;i++)cin>>v[i].second>>v[i].first;
        sort(all(v));
        vector<vector<ll>> vpw(n+1);
         vpw[0].resize(n*1001,1000000001);
         vpw[0][0]=0;
        ll i=1;

        while(i<=n)
         {   vpw[i].resize(n*1001,1000000001);
             for(ll va=0;va<n*1001;va++)
             {   if(va==0)vpw[i][va]=0;
                  //if(v[i].first>w)vpw[i][w]=vpw[i-1][w];


                    if(va>=v[i].first){ vpw[i][va]=min(vpw[i-1][va],v[i].second+vpw[i-1][va-v[i].first]);}
                    else vpw[i][va]=vpw[i-1][va];


              }
              i++;
         }
        // for(ll i=0;i<=n;i++){for(ll j=0;j<=tw;j++)cout<<vpw[i][j]<<" ";cout<<endl;}

         ll ans=0;
         for(ll i=1;i<=n;i++)
         {
             for(ll j=0;j<vpw[i].size();j++)if(vpw[i][j]<=tw)ans=max(ans,j);

         }

cout<<ans;


	return 0;
}


Measured memory_bytes: 79488
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    a = list(map(int, input().split()))
    s = sum(map(lambda x, y: x * y, a, b)) + c
    if s > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
using System;

class Program
{
  public static void Main(string[] args)
  {
    while (true)
    {
      string s = Console.ReadLine();
      if (s == "-") break;
      int m = int.Parse(Console.ReadLine());
      for (int i = 0; i < m; i ++)
      {
        int h = int.Parse(Console.ReadLine());
        string s1 = s.Substring(0, h);
        string s2 = s.Substring(h);
        s = s2 + s1;
      }
      Console.WriteLine(s);
    }
  }
}



Measured memory_bytes: 18004
#include<iostream>
#include<vector>
using namespace std;
int main(){
    long long n, m;
    cin >> n >> m;
    if (n == 1 && m == 1) {
        cout << 1 << endl;
    } else if (n == 2 || m == 2) {
        cout << 0 << endl;
    } else if (n == 1) {
        cout << (m-2) << endl;
    } else if (m == 1) {
        cout << (n-2) << endl;
    } else {
        cout << (n-2)*(m-2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int N, D, X;
    cin >> N >> D >> X;
    int ans = X + N;
    for(int i=0; i<N; i++) {
        int A;
        cin >> A;
        ans += (D-1) / A;
    }
    cout << ans << endl;
    return 0;
}


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

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

#define x first
#define y second

static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
        int n, k;
        scanf("%d%d", &n, &k);
        vector<pair<long long, long long>> p;
        for (int i = 0; i < n; i ++) {
                long long x, y;
                scanf("%lld%lld", &x, &y);
                p.emplace_back(x, y);
        }
        sort(all(p));
        long long ans = INFL;
        for (int i = 0; i < n; i ++) {
                for (int j = i + 1; j < n; j ++) {
                        for (int left = 0; left < n; left ++) {
                                for (int right = left + 1; right < n; right ++) {
                                        int cnt = 0;
                                        bool swapped = false;
                                        if (p[i].y < p[j].y) { 
                                                swap(p[i].y, p[j].y);
                                                swapped = true;
                                        }
                                        for (int k = 0; k < n; k ++) {
                                                if (p[left].x <= p[k].x && p[k].x <= p[right].x && p[j].y <= p[k].y && p[k].y <= p[i].y) {
                                                        cnt ++;
                                                }
                                        }
                                        if (cnt >= k) {
                                                ans = min(ans, (p[right].x - p[left].x) * (p[i].y - p[j].y));
                                        }
                                        if (swapped) swap(p[i].y, p[j].y);
                                }
 //                       }
 //                       int left = 0;
 //                       for (int right = 0; right < n; right ++) {
 //                               int cnt = 0;
 //                               bool swapped = false;
 //                               if (p[i].y < p[j].y) { 
 //                                       swap(p[i].y, p[j].y);
 //                                       swapped = true;
 //                               }
 //                               for (int k = 0; k < n; k ++) {
 //                                       if (p[left].x <= p[k].x && p[k].x <= p[right].x && p[j].y <= p[k].y && p[k].y <= p[i].y) {
 //                                               cnt ++;
 //                                       }
 //                               }
 //                               if (cnt >= k) {
 //                                       ans = min(ans, (p[right].x - p[left].x) * (p[i].y - p[j].y));
 //                                       left ++;
 //                                       right --;
 //                               }
 //                               if (swapped) swap(p[i].y, p[j].y);
                        }
                }
        }
        printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>

// -------------8<------- start of library -------8<------------------------
struct LowestCommonAncestor {
    const int root, INF, n;
    int size, no;
    std::vector<std::vector<int>> adj;
    std::vector<int> ord, idx;
    std::vector<std::pair<int, int>> dep;

    LowestCommonAncestor(int _n, int _r = 0) :
        root(_r), INF(INT_MAX), n(_n), adj(n), ord(2 * n - 1), idx(n) {}

    void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); }

    void Dfs(int cur, int p, int d) {
        ord[no] = cur;
        idx[cur] = no;
        dep[size - 1 + no++] = std::make_pair(d, cur);
        for (int nxt : adj[cur]) {
            if (nxt == p) continue;
            Dfs(nxt, cur, d + 1);
            ord[no] = cur;
            dep[size - 1 + no++] = std::make_pair(d, cur);
        }
    }

    void Preprocessing() {
        for (size = 1; size < 2 * n - 1; ) size <<= 1;
        dep.resize(2 * size - 1);

        no = 0;
        Dfs(root, -1, 0);

        for (int i = size - 2; 0 <= i; --i) {
            if (dep[2 * i + 1] < dep[2 * i + 2]) dep[i] = dep[2 * i + 1];
            else dep[i] = dep[2 * i + 2];
        }
    }

    int rmq(int l, int r) {
        std::pair<int, int> res(INF, INF);
        l += size - 1;
        r += size - 1;
        while (l < r) {
            if ((l & 1) == 0) res = std::min(res, dep[l]);
            if ((r & 1) == 0) res = std::min(res, dep[r - 1]);
            l >>= 1;
            r = (r - 1) >> 1;
        }
        return res.second;
    }

    int query(int u, int v) {
        if (idx[v] < idx[u]) std::swap(u, v);
        return rmq(idx[u], idx[v] + 1);
    }
};
// -------------8<------- end of library ---------8-------------------------

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

    // AOJ GRL_5_C: Tree - Lowest Common Ancestor
    int n;
    std::cin >> n;

    LowestCommonAncestor lca(n, 0);
    for (int v = 0, deg, c; v < n; ++v) {
        std::cin >> deg;
        while (deg--) {
            std::cin >> c;
            lca.add_edge(v, c);
        }
    }
    lca.Preprocessing();

    int q, u, v;
    std::cin >> q;
    while (q--) {
        std::cin >> u >> v;
        std::cout << lca.query(u, v) << '\n';
    }

    return 0;
}



Measured memory_bytes: 16380
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll pp(ll n)
{
    return n*n*n*n*n;
}
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    vector<pair<ll,ll> > v;
    v.push_back({0,0});
    for(i=1;i<=200;i++)
    {
        x = pp(i);
        v.push_back({x,i});
        x = x*-1;
        v.push_back({x,-i});
    }
    cin>>n;
    for(i=0;i<v.size();i++)
    {
        for(j=0;j<v.size();j++)
        {
            if(v[i].first-v[j].first==n)
            {
                cout<<v[i].second<<" "<<v[j].second<<endl;
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int N,M,a[100000],way[100001],a_num;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> a[i];
    }
    way[0] = 1;
    way[1] = 1;
    a_num = 0;
    if(a[0] == 1){
        a_num = 1;
        way[1] = 0;
    }
    for(int i=2;i<=N;i++){
        if(a[a_num] == i){
            way[i] = 0;
            a_num ++;
        }
        else{
            way[i] = way[i-1] + way[i-2];
            way[i] %= 1000000007;
        }
    }
    cout << way[N] << endl;
}

Measured memory_bytes: 1024
"ABC 088 D Grid Repainting"

# 定数
# INF : 距離の初期値(到達済みかどうかのフラグの役割も果たす)
INF = 10e8

# 入力
H, W = gets.split.map(&:to_i)
$c = []
H.times do |i|
  $c[i] = gets.chomp
end

# bfs
# スタート$c[sy][sx]から$c[gy][gx]までの最短経路の長さを返す
def bfs(sy, sx, gy, gx, a=$c)
  # bfsに用いるキュー
  $que = []
  # 移動方向
  dx = [1, 0, -1, 0]
  dy = [0, 1, 0, -1]
  # 全ての点をINFで初期化
  d = []
  #dを2次元配列で初期化
  H.times do |i|
    d[i] = []
  end
  # dを全部INFで埋める
  H.times do |i|
    W.times do |j|
      d[i][j] = INF
    end
  end
  # スタート地点をキューに入れ、距離を0にする
  $que.push([sy, sx])
  d[sy][sx] = 0
  # キューが空でない限り続ける
  while $que.size != 0
    # puts "#{$que}"
    y, x = 0, 0
    # キューから取り出して現在位置を更新
    y, x = $que.shift
    # puts d[y][x]
    # 移動先
    ny, nx = 0, 0
    # ゴールだったら終了
    if $c[y][x] == 'g'
      return d[gy][gx]
    end
    # 各方向についてループ
    4.times do |i|
      ny = y + dy[i]
      nx = x + dx[i]
      # 移動先が$cの範囲内で壁ではなく、かつ未到達ならば
      if (0<=nx) && (nx<W) && (0<=ny) && (ny<H) && ($c[ny][nx]!='#') && (d[ny][nx]==INF)
        # 移動先に追加する
        $que.push([ny, nx])
        # 移動先の距離を現在の点までのコスト +1 して小さくなれば更新
        d[ny][nx] = [ d[y][x] + 1 , d[ny][nx] ].min
        # puts "d[#{ny}][#{nx}]=#{d[ny][nx]}"
      end
    end
  end
  return d[gy][gx]
end

# main
# 最初の状態での '#' の数を数える
cnt = 0
H.times do |i|
  W.times do |j|
    if $c[i][j] == '#'
      cnt += 1
    end
  end
end
# 最短経路の長さを求める    
min_dist = bfs(0, 0, H-1, W-1)
# たどり着けない場合は-1を出力して終了
if min_dist == INF
  puts -1
  exit
end
# 結果を出力
# min_distの+1はスタート地点も含めるため
puts H*W - cnt - (min_dist+1)

Measured memory_bytes: 1788
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
const int l[] = {4,0,3,7,5,1,2,6}, r[] = {3,2,6,7,0,1,5,4};

void rotate(set<string> &T, string S){
  string S_ = S;
  for(int i = 0; i < 4; ++i){
    for(int j = 0; j < 4; ++j){
      for(int k = 0; k < 4; ++k){
        T.insert(S);
        S_ = S;
        for(int l = 0; l < 4; ++l){
          S[l] = S_[(l+1)%4];
          S[l+4] = S_[(l+1)%4+4];
        }
      }
      S_ = S;
      for(int k = 0; k < 8; ++k) S[k] = S_[r[k]];
    }
    S_ = S;
    for(int k = 0; k < 8; ++k) S[k] = S_[l[k]];
  }
}

int main(){
  string s;
  while(cin >> s){
    map<string,int> M;
    ++M[s];
    for(int i = 1; i < 8; ++i){
      cin >> s;
      ++M[s];
    }
    vector<int> V;
    for(auto itr = M.begin(); itr != M.end(); ++itr)
      V.push_back(itr->second);
    string S;
    for(int i = 0; i < (int)V.size(); ++i)
      for(int j = 0; j < V[i]; ++j)
        S += '0' + i;
    sort(S.begin(), S.end());
    set<string> T;
    int ans = 0;
    do{
      if(T.count(S)) continue;
      ++ans;
      rotate(T,S);
    }while(next_permutation(S.begin(), S.end()));
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 6948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

    int n;
    string s;
    cin >>n;
    cin >>s;
    vector<vector<int> > num(10);

    REP(i,n){
        int m = s[i] - '0';
        num[m].push_back(i);
    }
    /*REP(i,num[1].size()){
        cout << num[1][i] << endl;
    }*/
    int ans = 0;
    bool flag[1000];
    REP(i,1000){
        flag[i] = false;
    }

    REP(i,10){
        REP(j,10){
            REP(k,10){
                if(num[i].size() != 0){
                    int ii = num[i][0];
                    if(num[j].size() != 0){
                        if(num[j][num[j].size()-1] > ii){
                            auto itrj = upper_bound(ALL(num[j]), ii);
                            int jj = *itrj;
                            if(num[k].size() != 0 && num[k][num[k].size()-1] > jj){
                                if(flag[100*i+10*j+k] == false){
                                    //cout << i<<j<<k << endl;
                                    ans++;
                                    flag[100*i+10*j+k] = true;
                                }
                            }
                        }    
                    }
                } 
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 512