akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {
    if(x < y) return gcd(y, x);
    while (y != 0LL) {
        ll tmp = x%y;
        x = y;
        y = tmp;
    }
    return x;
}

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

int main() {
    int n; cin >> n;
    vector<ll> t(n);
    REP(i,n) cin >> t[i];
    ll ans = 1;
    REP(i,n) ans = lcm(ans, t[i]);
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  vector<bool> hurui(100000,true);
  hurui[0]=hurui[1]=false;
  repp(i,2,100000){
    if(hurui[i]) for(int j=i+i;j<100000;j+=i) hurui[j]=false;
  }
  vector<int> prime;
  rep(i,100000) if(hurui[i]) prime.push_back(i);
  int n = prime.size();
  while(1){
    int m,a,b;
    cin >> m >> a >> b;
    if(m==0) return 0;
    int ma=0;
    int ansp,ansq;
    rep(i,n){
      if(prime[i]*prime[i]>m) break;
      int l=i,r=n,mid;
      while(r-l>1){
        mid=(l+r)/2;
        if(prime[i]*prime[mid]<=m){
          l=mid;
        }else{
          r=mid;
        }
      }
      int x = l;
      l=i,r=n;
      while(r-l>1){
        mid=(l+r)/2;
        if(a*prime[mid]<=b*prime[i]){
          l=mid;
        }else{
          r=mid;
        }
      }
      int y = l;
      int j = min(x,y);
      if(ma<prime[i]*prime[j]){
        ma=prime[i]*prime[j];
        ansp=prime[i];
        ansq=prime[j];
      }
    }
    cout << ansp SP ansq << endl;
  }
  return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}

const int Maxv=1e3+5;
bool is_prime[Maxv];
vector<int>prime;
void init(){
	for(int i=0;i<Maxv;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<Maxv;i++){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j=2*i;j<Maxv;j+=i)is_prime[j]=false;
		}
	}
}
//mii prime_factor(int n){
//	mii res;
//	for(int i=2;i*i<=n;i++){
//		while(n%i==0){
//			++res[i];
//			n/=i;
//		}
//	}
//	if(n!=1)res[n]=1;
//	return res;
//}
int n;
const int Maxn=1e6+5;
int a[Maxn];
int cnt[Maxn];

int main(){
	init();
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	bool ver1=true;
	int fac=a[1];
	for(int i=1;i<=n;i++){
		if(i>1){
			fac=__gcd(fac,a[i]);
		}
		int x=a[i];
		for(int j=0;j<SZ(prime);j++){
			int pi=prime[j];
			if(pi>x)break;
			if(x%pi==0){
				if(cnt[pi]>0){
					ver1=false;
				}
				cnt[pi]++;
				while(x%pi==0){
					x/=pi;
				}
			}
		}
		if(x!=1){
			if(cnt[x]>0){
				ver1=false;
			}
			cnt[x]++;
		}
	}
	if(fac!=1){
		printf("not coprime\n");
		return 0;
	}
	if(!ver1)printf("setwise coprime\n");
	else printf("pairwise coprime\n");
	return 0;
}

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

using namespace std;

char G[10][10];

int main () {
	string s;
	while (cin >> s, s[0] != '#') {
		s += '/';
		int h = 0, w;
		for (int i = 0; i < s.size (); ++i) {
			w = 0;
			while (s[i] != '/') {
				if (isdigit (s[i])) {
					for (int j = 0; j < s[i] - '0'; ++j)
						G[h][w++] = '.';
				} else G[h][w++] = 'b';
				++i;
			}
			++h;
		}
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		swap (G[a - 1][b - 1], G[c - 1][d - 1]);
		string ans;
		for (int i = 0; i < h; ++i) {
			if (i) ans += '/';
			int cnt = 0;
			for (int j = 0; j < w; ++j) {
				if (G[i][j] == '.') ++cnt;
				else if (cnt) ans += to_string (cnt) + "b", cnt = 0;
				else ans += 'b';
			}
			if (cnt) ans += '0' + cnt;
		}
		cout << ans << endl;
    }

	return 0;
}


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

int main() {

	string s;
	int total = 700;

	cin >> s;

	if (s[0] == 'o') total += 100;
	if (s[1] == 'o') total += 100;
	if (s[2] == 'o') total += 100;

	cout << total << endl;

	return 0;

}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	static Scanner scanner = new Scanner(System.in);
 
	public static void main(String[]$) {
		String[] a = new String[] {scanner.next(), scanner.next()};
		int length = a[0].length() + a[1].length();
		for (int i = 0; i < length; i++) {
			System.out.print(a[i % 2].charAt(i / 2));
		}
		System.out.println();
	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int k,t,a[10005];
int main() {
    cin>>k>>t;
    for(int i=1;i<=t;i++)cin>>a[i];
    sort(a+1,a+t+1);
    cout<<max(a[t]*2-1-k,0)<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define x first
#define y second
using namespace std;

const int N = 3e3+5;
int n, m, f[N], ans, b[N];
pair<int, int> a[N];

int main()
{
    scanf("%d%d",&n,&m); m-=1;
    for(int i=1; i<=n; ++i) scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1, a+1+n);
    for(int i=n; i>=1; --i) b[i] = max(b[i+1], a[i+1].y);
    ans = max(b[1], a[1].y);

    for(int i=1; i<=n; ++i) for(int j=m; j>=a[i].x; --j) {
        f[j] = max(f[j], f[j-a[i].x] + a[i].y);
        ans = max(ans, f[j] + b[i]);
    }
    printf("%d",ans);
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  for(int i=0; i<N-1; i++){
    if(S.at(i) != S.at(i+1)){
      ans++;
    }
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 512
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printyn(a) printf(a ? "Yes\n" : "No\n");
#define printYN(a) printf(a ? "YES\n" : "NO\n");
#define all(x) (x).begin(), (x).end()

using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
//#include <vector>

using namespace std;

int main() {

	char tmp[10];
	string s = "";
	scanf("%s", tmp);
	rep(i, strlen(tmp)) {
		if (tmp[i] == 'B') {
			if (!s.length())continue;
			else s.pop_back();
		}
		else if (tmp[i] == '0') {
			s.push_back('0');
		}
		else {
			s.push_back('1');
		}
	}
	printf("%s", s.c_str());
	return 0;
}

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

int main(){
  int n;
  int i,j;
  int num[10][10];
  int p,q;
  int ans = 0;

  scanf("%d", &n);

  for(i = 0;i <= 9;i++){
    for(j = 0;j <= 9;j++) num[i][j] = 0;
  }

  for(i = 1;i <= n;i++){
    q = i % 10;

    p = i;
    if(p >= 10){
      while(p >= 10){
        p = p/10;
      }
    }

    num[p][q]++;
  }

  for(i = 1;i <= 9;i++){
    for(j = 1;j <= 9;j++){
      ans += num[i][j]*num[j][i];
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 510000;
const int MOD = 1000000007;
typedef pair<int , int> P;
typedef long long ll;

int main () {
  ll N, K, ans, min, max;
  cin >> N >> K;
  ans = min = max = 0;
  for (ll i = 0; i < K-1; ++i) {
    min += i;
    max += N-i;
    // printf("%d %d\n", min, max);
  }
  // printf("\n");
  for (ll i = K-1; i < N+1; ++i) {
    min += i;
    max += N-i;
    ans += max-min+1;
    ans %= MOD;
    // printf("%d %d\n", min, max);
    // printf("%d\n", ans);
  }
  printf("%lld\n", ans);
  return 0;
}

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

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(k>=s.size()){
        cout << s << endl;
    }
    else{
        for(int i=0;i<k;i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//
int main(){
    int n,k; cin>>n>>k;
    string s; cin>>s;
    if(s[k-1]=='A') s[k-1]='a';
    if(s[k-1]=='B') s[k-1]='b';
    if(s[k-1]=='C') s[k-1]='c';
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 2e5+9, INF = 0x3f3f3f3f;
string s;

int main( void ) {
    ios::sync_with_stdio( false );
    int n, k;
    cin >> n >> k >> s;
    int num = 1, ans = 0;
    for( int i = 0; i < n - 1; ++i ) {
        if( s[i] != s[i + 1] ) ++num;
        else ++ans;
    }
    while( k-- ) {
        if( num >= 3 ) num -= 2, ans += 2;
        else if( num >= 2 ) {
            ans += 1;
            break;
        }
        else break;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
// 2 - Z-algorithmによる解法 O(N^2)

#include<iostream>
#include<vector>
using namespace std;

// 100%は理解できていない
vector<int> zalgo(string s){
    vector<int> prefix(s.size());
    for(int i = 1, j = 0; i < s.size(); i++){
        if(i + prefix[i-j] < j + prefix[j]){
            prefix[i] = prefix[i-j];
        }else{
            int k = max(0, j+prefix[j]-i);
            while(i + k < s.size() && s[k] == s[i+k])   k++;
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = s.size();
    return prefix;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < n; i++){
        vector<int> tmp = zalgo(s.substr(i));
        for(int j = 0; j < n-i; j++){
            if(tmp[j] <= j) ans = max(ans, tmp[j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>

using namespace std;

int main() {

    bool ans = true;
    vector<vector<int>> c(3, vector<int>(3));

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    for (int i = 0; i < 2; i++) {

        if (!(c[i][0] - c[i + 1][0] == c[i][1] - c[i + 1][1] && c[i][1] - c[i + 1][1] == c[i][2] - c[i + 1][2])) {
            ans = false;
        }
        if (!(c[0][i] - c[0][i + 1] == c[1][i] - c[1][i + 1] && c[1][i] - c[1][i + 1] == c[2][i] - c[2][i + 1])) {
            ans = false;
        }
    }

    if (ans) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n;
  cin >> n;
  int ans = 0;
  for(ll i = 1; i*i <= n-1; i++){
    if((n-1) % i != 0) continue;
    ll j = (n-1) / i;
    if(i == 1 && i == j) continue;
    if(i == 1 || i == j) ans++;
    else ans += 2;
  }
  for(ll i = 1; i*i <= n; i++){
    if(n % i != 0) continue;
    ll nn = n;
    ll j = n / i;
    while(nn % j == 0 && nn > 1) nn /= j;
    if(nn % j == 1) ans++;
    if(i == 1 || i == j) continue;
    nn = n;
    while(nn % i == 0 && nn > 1) nn /= i;
    if(nn % i == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    ll a,p;cin>>a>>p;
    ll ans=a*3+p;ans/=2;
    cout<<ans;
    
	
	
	
 return 0;
}

Measured memory_bytes: 256
#include <iostream>

int solve(const int &n, const std::string &s) {
    int ans = 0, tmp = 0;
    for (int i=0; i<n; ++i) {
        tmp += s[i] == 'I' ? 1 : -1;
        ans  = std::max(ans, tmp);
    }
    return ans;
}

int main() {
    int n;
    std::string s;

    std::cin >> n >> s;
    std::cout << solve(n, s) << std::endl;

    return 0;
}

Measured memory_bytes: 256
// ABC_156_C

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

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

	vector<int> vec(n);
	for(int i = 0; i < n; ++i) cin >> vec[i];

	int mini = pow(10, 9);
	for(int i = 1; i <=100; ++i) {
		int sum = 0;
		for(int j = 0; j < vec.size(); ++j) {
			int tmp = abs(vec[j] - i) * abs(vec[j] -i);
			sum += tmp;	
		}
		if(mini > sum) mini = sum;
		else continue;
	}

	cout << mini << "\n";

	return 0;
}                                              

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{

   int x,a,result;
   scanf("%d %d",&x,&a);
  switch(x<a)
  {
  case 1:
    printf("0");
    break;
  case 0:
    printf("10");
    break;
  }

    return 0;
}


Measured memory_bytes: 1728
n, k = map(int,input().split())
li = list(map(int,input().split()))

f_inf = float('inf')
dp = [f_inf]*(10**5+10)

# 初期値
dp[0] = 0
for i in range(1,n):
    for j in range(1,k+1):
        if (i-j>=0):
            dp[i] = min(dp[i],dp[i-j]+abs(li[i]-li[i-j]))
print(dp[n-1])

Measured memory_bytes: 55392
var lines = [];
var ans; var G;

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]); ans = Array(N).fill(0);
    lines.shift();

    G = Array(N).fill(0).map(i => i = [])
    for (var i = 0; i < N - 1; i++) {
        var t = lines[i].split(" ");
        var u = Number(t[0]); var v = Number(t[1]); var w = Number(t[2]);
        G[u - 1].push([v - 1, w]); G[v - 1].push([u - 1, w])
    }
    bfs(0, -1, 1)
    for (var i = 0; i < N; i++) { console.log(ans[i]); }
});

// vをcで塗る pはvの親
function bfs(v, p, c) {
    var q = [[v, p, c]]

    while (q.length) {
        var t = q.shift(); var v = t[0]; var p = t[1]; var c = t[2];
        ans[v] = c;

        for (var value of G[v]) {
            // 親は探索済み
            if (value[0] === p) { continue; }
            // 辺の距離が奇数なら
            if (value[1] & 1) { q.push([value[0], v, 1 - c]) }
            // 辺の距離が偶数なら
            else { q.push([value[0], v, c]) }
        }
    }
}

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

int main() {
    int n, c = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n - 2; i++)
        if(s.substr(i, 3) == "ABC")
            c++;
    cout << c << endl;
    return 0;
}


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

int main(void){
    int n, now=0;
    cin >> n;
    vector<int>a(n);
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        if (a[now]==2){
            cout << i+1 << endl;
            return 0;
        }
        now = a[now]-1;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	scanf("%d %d %d",&a,&s,&d);
	f=a-s;
	if(f<0) f*=-1;
	g=a-d;
	if(g<0) g*=-1;
	if(f>g) printf("B\n");
	else printf("A\n");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>

using namespace std;

int a[3];
int cnt[2];
int main(void){
	while(~scanf("%d,%d,%d",&a[0],&a[1],&a[2])){
		if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])cnt[0]++;
		if(a[0]==a[1])cnt[1]++;
	}
	printf("%d\n",cnt[0]);
	printf("%d\n",cnt[1]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int n,k,s;
    cin >> n >> k >> s;
    if(s < 1000000000){
        for(int i = 0; i < n; i++){
            if(i < k){
                cout << s << ' ';
            }else{
                cout << s+1 << ' ';
            }
        }
    }else{
        for(int i = 0; i < n; i++){
            if(i < k){
                cout<< s << ' '; 
            }else{
                cout << s-1 << ' ' ;
            }
        }
    }
}


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

int main() {
  int d;
  cin >> d;
  if (d == 25) {
    cout << "Christmas" << endl;
  }
  else if (d == 24) {
    cout << "Christmas Eve" << endl;
  }
  else if (d == 23) {
    cout << "Christmas Eve Eve" << endl;
  }
  else {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}


Measured memory_bytes: 256
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    A.sort(reverse=True)
    c = Counter(A)

    for b in A:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            cur = min(c[a], c[b])
        ans += cur
        c[b] -= cur
        c[a] -= cur
        # print(a, b, c, ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 56624
input = gets.split(" ").map(&:to_i)
_W = input[0]
_H = input[1]
x = input[2]
y = input[3]
r = input[4]

if (x-r < 0 || y - r < 0 || x + r > _W || y + r > _H) then
  printf("No\n")
else
  printf("Yes\n")
end

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

int main() {
  int N;
  int L;

  cin >> N >> L;

  int abs_min = abs(L);
  int min = L;
  int taste;
  int t_total = 0;

  for(int i=1;i<=N;i++) {
    taste = L+i-1;
    if(abs_min > abs(taste)) {abs_min = abs(taste); min = taste;}
    t_total += taste;
  }

  t_total = t_total - min;

  cout << t_total << endl;

  return 0;
}


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

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(long long int &x){int k;x=0;for(;;){k=gc();if(48<=k&&k<=57){x=k-48;break;}}for(;;){k=gc();if(k<48||k>57)break;x=x*10+k-48;}}

long long int N, K, b, i, r, m, n, a[20];
vector<bool> f;

int main(){
    read(N);
    read(K);
    for(i = 0; i < N; ++i){
        read(a[i]);
        if(m < a[i]){
            ++r;
            m = a[i];
        }
        f.push_back(i < K);
    }
    if(r > K){return 0&puts("0");}
    n = 1145141919810LL;
    do{
        r = 0;
        m = *a;
        for(i = 1; i < N; ++i){
            if(m >= a[i]){
                if(f[i]){
                    r += m - a[i] + 1;
                    ++m;
                }
            }else{
                m = a[i];
            }
        }
        n = min(r, n);
    }while(prev_permutation(f.begin(), f.end()));
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, ans;
vector<int> a;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    a.resize(n+1);
    erep(i, 1, n) {
        cin >> a[i];
    }
    erep(i, 1, n) {
        if (a[a[i]] == i) ans++;
    }
    printf("%d\n", ans/2);
    return 0;
}


Measured memory_bytes: 640
// 2019.9.15 bal4u
// Template for Online Contest

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef long long ll;

#define gc() getchar()
#define pc(c) putchar(c)

int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

ll inL() {  // long long 整数の入力
	ll n = 0; int c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 整数の表示
	int i; char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

void outL(ll n) { // 整数の表示
	int i; char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int ins(char *s) { // 文字列の入力
	char *p = s--;
	do *++s = gc();
	while (*s > ' ');
	*s = 0;
	return s - p;
}

void outs(char *s) {  // 文字列の表示
	while (*s) pc(*s++);
}

#define MIN(a,b)  ((a)<=(b)?(a):(b))
#define MAX(a,b)  ((a)>=(b)?(a):(b))
#define ABS(a)    ((a)>=0?(a):-(a))
inline static int chmax(int *a, int b) { if (*a < b) *a = b; }
inline static ll  chmaxL(ll *a, int b) { if (*a < b) *a = b; }
inline static int chmin(int *a, int b) { if (*a > b) *a = b; }
inline static ll  chminL(ll *a, int b) { if (*a > b) *a = b; }

int N, K, Q;
int f[100005];

int main()
{
	int i;

	N = in(), K = in(), Q = in();
	for (i = 0; i < Q; i++) f[in()]++;
	for (i = 1; i <= N; i++) puts(K-Q+f[i] <= 0? "No": "Yes");
	return 0;
}


Measured memory_bytes: 896
import itertools

i = int(input())
P = input().split()
Q = input().split()

list_to_permute = []
for each in range(1, i+1):
    list_to_permute.append(each)

list_of_all_permutes = list(itertools.permutations(list_to_permute))


# Calculatation
P = tuple(int(element) for element in P)
Q = tuple(int(element) for element in Q)
a = list_of_all_permutes.index(P) + 1
b = list_of_all_permutes.index(Q) + 1 

print(abs(a-b))

Measured memory_bytes: 8052
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double

int main(void){
  ll n;
  cin>>n;
  for(int i=1;i<10;i++){
    if(n%i==0 && n/i<=9){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
  int qtdItens, qtdItensEscolha;
  float valorFormulaPopular, totalVotos = 0, qtdItensEscolhido = 0;
  scanf("%d %d", &qtdItens, &qtdItensEscolha);

  float itensVotos[qtdItens];

  for(int i=0; i<qtdItens; i++){
    scanf("%f", &itensVotos[i]);
    totalVotos += itensVotos[i];
  }

  valorFormulaPopular = totalVotos / (4.0 * qtdItensEscolha);

  for(int i=0; i<qtdItens; i++){
    if(itensVotos[i] >= valorFormulaPopular){
      qtdItensEscolhido++;
    }
  }

  if(qtdItensEscolhido >= qtdItensEscolha){
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
list = []

def dfs(length,num):
    global list
    if len(num) == length:
        list.append(num)
        return

    for i in ['3','5','7']:
        newnum = num + i
        dfs(length,newnum)

    return


N = input()
ans = 0

for i in range(1,len(N) + 1):
    dfs(i,'')

for i in list:
    if ('3' in i) and ('5' in i) and ('7' in i):
        if int(N) >= int(i):
            ans += 1

print(ans)

Measured memory_bytes: 5144
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 2e5 + 10;
ll k;
ll flag;

void dfs(ll pos, ll val, ll dig, ll len)
{
	val = val * 10 + dig;
//	cout << pos << " " << val << " " << dig << " " << len << endl;
	if (pos == len)
	{
		k--;
		if (k == 0 && flag == 0) flag = val;
		return;
	}
//	cout << 22 << endl;
	if (dig > 0) dfs(pos + 1, val, dig - 1, len);
	if (flag) return;
	dfs(pos + 1, val, dig, len);
	if (flag) return;
	if (dig < 9) dfs(pos + 1, val, dig + 1, len);
	if (flag) return;
}

int main()
{
	cin >> k;
	
	if (k <= 9)
	{
		cout << k << endl;
		return 0;
	}
	
	k -= 9;
	for (ll i = 2; i <= 10; i++)
	{
		for (ll j = 1; j <= 9; j++)
		{
			if (j > 0) dfs(2, j, j - 1, i);
			dfs(2, j, j, i);
			if (j < 9) dfs(2, j, j + 1, i);
			if (flag) break;
		}
		if (flag) break;
	}
	
	cout << flag << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2e5 + 7;
const ll INF = 1e18;

int main() {
	int r;
	cin >> r;
	cout << (r * r) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 1e5 + 100;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int n, m;
int a[N];
int mn[N];

int main() {
    int i, j;
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; ++i) {
        scanf("%d", a + i);
        if (i == 0)
            mn[i] = a[i];
        else
            mn[i] = min(mn[i - 1], a[i]);
    }
    int mx = 0;
    for (i = 1; i < n; ++i) {
        if (mn[i - 1] < a[i]) {
            mx = max(mx, a[i] - mn[i -1]);
        }
    }
    if (mx == 0) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for (i = 1; i < n; ++i) {
        if (mx == a[i] - mn[i - 1])
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
/*
 * main.cpp
 *
 *  Created on: 2011/04/01
 *      Author: satoki
 *      11:27 ~ 11:37 Accepted
 */
#include <iostream>

using namespace std;

int main() {
  int i, j;
  for (i = 1; i < 10; i++)
    for (j = 1; j < 10; j++)
      printf("%dx%d=%d\n", i, j, i * j);
  return 0;
}

Measured memory_bytes: 0
n = input()
a = raw_input().split(' ')
b = []
for x in a:
    b.append(int(x))
b.sort()
b.reverse()
w = 0
f = 1
for x in b:
    if f == 1:
        w += x
    else:
        w -= x
    f = 1 - f
print w


Measured memory_bytes: 2568
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,M = map(int,(input().split()))
A = list(map(int,(input().split())))
s = [0]*N
s[0] = A[0] % M
for i in range(1,N):
    s[i] = s[i-1] + A[i]
    s[i] %= M
d = defaultdict(int)
for i in s:
    d[i] += 1
ans = d[0]
for k in d.keys():
    ans += d[k]*(d[k]-1)//2

print(ans)

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

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

  int ans = 0;
  if (x == 0) {
    if (0 < y) {
      ans = abs(y);
    } else {
      ans = abs(y) + 1;
    }
  } else if (y == 0) {
    if (0 < x) {
      ans = abs(x) + 1;
    } else {
      ans = abs(x);
    }
  } else if (0 < x && 0 < y) {
    if (x <= y) {
      ans = y - x;
    } else {
      ans = x - y + 2;
    }
  } else if (x < 0 && 0 < y) {
    ans = abs(x + y) + 1;
  } else if (y < 0 && 0 < x) {
    ans = abs(x + y) + 1;
  } else { // x < 0 && y < 0
    if (x <= y) {
      ans = y - x;
    } else {
      ans = x - y + 2;
    }
  }

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


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int MAX_NUM = 2000000;
int main(){
    int N;
    cin >> N;
    int elements[MAX_NUM];
    int i;
    for(i = 0; i < N; i++){
        cin >> elements[i];
    }
  
    int j;
    int count = 0;
    for(i = 0; i < N - 1; i++){
        for(j = N - 1; j >= i+1; j--){
            if(elements[j] < elements[j-1]){
                int tmp = elements[j];
                elements[j] = elements[j-1];
                elements[j-1] = tmp;
                count++;
            }
        }
    }
    for(i = 0; i < N-1; i++){
        printf("%d ", elements[i]);
    }
    printf("%d\n", elements[i]);
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 3224
import java.util.Scanner;
public class Main {
	public static void main(String arg[]) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		if(A*B*C==175) {
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}	
}

Measured memory_bytes: 19284
// mai iss duniyaa ka sbse bada chutiyaaa huu

#include<bits/stdc++.h> 
#include <chrono> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl '\n'
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono; 

template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less_equal<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
       'j','k','l','m','n','o','p','q','r','s','t','u','v',
       'w','x','y','z'};

// rectangle intersection
// x5 = max(x1, x3);
// y5 = max(y1, y3);
// x6 = min(x2, x4);
// y6 = min(y2, y4); 

// const int mx = 100005;

// char get_next(char c) {
// 	for(int i=0; i<25; i++) if(c == alphabet[i]) return alphabet[i+1];
// 	return 'a';
// }

int32_t main() {
 	fastIO;
	int tc;
	// cin >> tc;
	tc = 1;
	while(tc --) {
		int n, d;
		cin >> n >> d;
		d *= d;
		int cnt = 0;
		int x, y;
		for(int i=0; i<n; i++) {
			cin >> x >> y;
			if(x*x + y*y <= d) cnt++;
		}
		cout << cnt << endl;
	}     
}



Measured memory_bytes: 3600
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Node {
  constructor(id) {
    this.id = id;
    this.children = [];
  }
  getDepth() {
    if (this.depth === undefined) {
      this.depth = this.parent ? this.parent.getDepth() + 1 : 0;
    }
    return this.depth;
  }
  add(node) {
    node.parent = this;
    this.children.push(node);
  }
  getType() {
    if (this.getDepth() === 0) {
      return 'root';
    }
    return this.children.length ? 'internal node' : 'leaf';
  }
  toString() {
    return 'node ' + this.id + ': ' + [
      'parent = ' + (this.parent ? this.parent.id : -1),
      'depth = ' + this.getDepth(),
      this.getType(),
      '[' + this.children.map(node => node.id).join(', ') + ']',
    ].join(', ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    if (!this.map.has(id)) {
      this.map.set(id, new Node(id));
    }
    return this.map.get(id);
  }
  print() {
    for (let i = 0; i < this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Tree();
adj.forEach(([id, k, ...ck]) => {
  const parent = tree.getNode(id);
  ck.forEach(c => {
    const node = tree.getNode(c);
    parent.add(node);
  });
});

tree.print();



Measured memory_bytes: 110720
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
   int n;
   string S;
   cin >> n >> S;
   
   if(n%2 == 1){
      cout << "No" << endl;
      return 0;
   }
   string before = S.substr(0, n/2);
   string after = S.substr(n/2);
   if(before == after) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define inf 0x3fffffff
using namespace std;
const int MAXA=100010;
const int MAXB=100010;
int A,B,M;
int a[MAXA],b[MAXB];
int ans=inf;
int main()
{
//	freopen("in.txt","r",stdin);
	scanf("%d %d %d",&A,&B,&M);
	
	int mina=inf,minb=inf;
	for(int i=1;i<=A;++i){scanf("%d",&a[i]);mina=min(mina,a[i]);}
	for(int i=1;i<=B;++i){scanf("%d",&b[i]);minb=min(minb,b[i]);}
	ans=min(ans,mina+minb);
	
	int x,y,c;
	for(int i=1;i<=M;++i)
	{
		scanf("%d %d %d",&x,&y,&c);
		ans=min(ans,a[x]+b[y]-c);
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a = int(input())
print(k[a - 1])


Measured memory_bytes: 2940
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<set>
#include<algorithm>
#include<map>
#include<ctime>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int maxn = 200009;
const int inf = 100000009;
const ll mod = 1e9 + 7;
int main()
{
	int n;
	cin >> n;
	int num = 1;
	for (int i = 0; i < n; ++i) {
		int tmp;
		scanf("%d", &tmp);
		if (tmp == num)++num;
	}
	if (num == 1) cout << -1;
	else cout << n - num + 1;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
As = list(map(int, input().split()))

mem = [0]*N
mem[0] = 1
pos = 0
cic = 0
j = 0

for k in range(1,K+1):
  pos = As[pos] - 1
  if mem[pos] == 0:
    mem[pos] = 1
  else:
    j = k
    cic = pos
    break
  if k == K:
    print(pos+1)
    exit()

pos = 0
if cic == pos:
  i = 0
else:
  for l in range(1,j+1):
    pos = As[pos] - 1
    if pos == cic:
      i = l
      break

m = j - i

rlt = (K-i)%m
if rlt == 0:
  print(cic+1)
else:
  pos = cic
  for n in range(1,rlt+1):
    pos = As[pos] - 1
  print(pos+1)
  


Measured memory_bytes: 92252
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
long long i,j,t;
const int z = 1e5 + 5;
pair <long long ,long long>p[2000];
long long n,k,h[105][z];
long long req (long long r, long long c){
	long long res = 0;
	if (r==-1 || c<=0) return 0;
	if (h[r][c]!=-1) return h[r][c];
	else if (c<p[r].first) res = req(r-1, c);
	else {
		long long t1 = req(r-1,c);
		long long t2 = p[r].second + req(r-1, c - p[r].first);
		res = max(t1,t2);
	}
	h[r][c] = res;
	return res;
	
}
int main(){
	cin>>n>>k;
    memset(h,-1 ,sizeof(h));
	for (i=0; i<n; i++){
		cin>>p[i].first>>p[i].second;
	}
	cout<<req(n-1, k);
}


Measured memory_bytes: 85180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    ll q, s, h, d, n;
    cin >> q >> s >> h >> d >> n;

    vector<pair<ll, double>> cost_perf;
    cost_perf.push_back(make_pair(q*4, 0.25));
    cost_perf.push_back(make_pair(s*2, 0.50));
    cost_perf.push_back(make_pair(h, 1.0));

    sort(all(cost_perf));

    ll money = 0;
    if(n >= 2){
        if(cost_perf[0].first > double(d/2)){
            money += n/2 * d;
            n %= 2;
            money += n * cost_perf[0].first;
        }
    }
    if(money == 0){
        money += n * cost_perf[0].first;
    }

    cout << money << endl;

    return 0;
}


Measured memory_bytes: 256
INF = 10**11
from bisect import bisect

A, B, Q = map(int, input().split())
s_array = [int(input()) if i != 0 else -INF for i in range(A + 1)]
s_array.append(INF)
t_array = [int(input()) if i != 0 else -INF for i in range(B + 1)]
t_array.append(INF)
q_array = [int(input()) for i in range(Q)]

# print(s_array, t_array, q_array)

ans_array = []
for q in q_array:
    s_index = bisect(s_array, q) - 1
    t_index = bisect(t_array, q) - 1
    # print(s_index,t_index)
    method_a = q - min(s_array[s_index], t_array[t_index])
    method_b = max(s_array[s_index + 1], t_array[t_index + 1]) - q
    method_c = (q - s_array[s_index]) + (t_array[t_index + 1] - q) + min(
        (q - s_array[s_index]), (t_array[t_index + 1] - q))
    method_d = (q - t_array[t_index]) + (s_array[s_index + 1] - q) + min(
        (q - t_array[t_index]), (s_array[s_index + 1] - q))
    ans_array.append(min(method_a, method_b, method_c, method_d))

for ans in ans_array:
    print(ans)

Measured memory_bytes: 107248
N = int(input())
p = list(map(int, input().split()))
ans = 0
i = 0
while i < N:
    if p[i] == i + 1:
        ans += 1
        if i < N - 1 and p[i + 1] == i + 2:
            i += 1
    i += 1
print(ans)

Measured memory_bytes: 14008
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def low_link(nodes):
    N = len(nodes)
    visited = [False] * N
    prenum = [0] * N
    parent = [0] * N
    lowest = [0] * N
    bridges = []
    timer = 1

    def rec(cur, prev, timer):
        # curを訪問した直後の処理
        prenum[cur] = lowest[cur] = timer
        timer += 1
        visited[cur] = True
        for nxt in nodes[cur]:
            if not visited[nxt]:
                # curからvへ訪問する直前の処理
                parent[nxt] = cur
                timer = rec(nxt, cur, timer)
                # nxtの探索が終了した直後の処理
                lowest[cur] = min(lowest[cur], lowest[nxt])
                # より近い経路を含まないなら橋とする
                if lowest[nxt] == prenum[nxt]:
                    # 番号の小さい方から入れる
                    bridges.append((min(cur, nxt), max(cur, nxt)))
            elif nxt != prev:
                # cur -> nxt がback-edgeの場合の処理
                lowest[cur] = min(lowest[cur], prenum[nxt])
        return timer
    # 必要な各値の取得(非連結に対応するため全頂点から)
    for i in range(N):
        if not visited[i]:
            timer = rec(i, -1, timer)

    # 間接点
    aps = set()
    # ルートの子ノードの数
    np = 0
    for i in range(1, N):
        p = parent[i]
        if p == 0:
            np += 1
        # 条件2の確認
        elif prenum[p] <= lowest[i]:
            aps.add(p)
    # 条件1の確認
    if np > 1:
        aps.add(0)

    return aps, bridges

N, M = MAP()
nodes = [[] for i in range(N)]
for i in range(M):
    u, v = MAP()
    nodes[u].append(v)
    nodes[v].append(u)

aps, bridges = low_link(nodes)

bridges = sorted(bridges)
for x in bridges:
    print(*x)



Measured memory_bytes: 21732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int n;
  cin>>n;
  
  int ans=0;
  for(int i=1;i<=n;i+=2){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)cnt++;
}

  if(cnt==8)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


int main() {
	
	ll a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    pli p[N];
    rep(i, N){
        cin >> p[i].first;
        p[i].second = i;
    }
    sort(p, p+N);
    ll sum[N+1];
    sum[0] = 0, sum[1] = p[0].first*N;
    rep2(i, 2, N){
        sum[i] = sum[i-1]+(p[i-1].first-p[i-2].first)*(N+1-i);
    }
    ll ans[N];
    fill(ans, ans+N, 0);
    vector<int> steps;
    int now = inf;
    rep3(i, N-1, 0){
        if(i>0 && p[i-1].first == p[i].first) continue;
        if(p[i].second < now){
            steps.pb(i+1);
            now = p[i].second;
        }
    }
    steps.pb(0);
    sort(steps.begin(), steps.end());
    int n = steps.size();
    rep2(i, 1, n-1){
        int j = steps[i], k = steps[i-1];
        ans[p[j-1].second] = sum[j]-sum[k];
    }
    rep(i, N){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4728
#include<bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl '\n'
#ifndef CODE_JAM
#undef CASE_INFO
#endif
#else
#pragma GCC optimize "trapv"
#endif
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(n) for(int i = 0; i < n; i++)
#define repj(n) for(int j = 0; j < n; j++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
template<class X=int>inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int>inline X len(X s,X e){return (e-s+1);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 1e18;

void solve() {
	int n, k;
	cin >> n >> k;
	vi A(n);
	rep(n) cin >> A[i];
	function<bool(int)> good = [&](int K) -> bool {
		int ops = 0;
		for(int i = 0; i < n; i++) ops += (A[i] > K) ? (A[i] - 1)/K : 0;
		return ops <= k;
	};
	int lo = 1, hi = 1e9;
	int ans = 0;
	while(lo <= hi) {
		int mi = lo + (hi - lo)/2;
		if(good(mi)) {
			ans = mi;
			hi = mi - 1;
		}
		else
			lo = mi + 1;
	}
	hi = ans;
	if(hi > 1 and good(hi - 1)) hi = hi - 1;
	cout << hi << endl;
}

signed main() {
	clock_t start = clock();
	int T = 1;
	#ifdef TEST_CASES
	T = sc.nxtInt();
	#endif
	for(int t = 1; t <= T; t++) {
		#ifdef CASE_INFO
		cout << "Case #" << t << ": ";
		#endif
		solve();
	}
	cerr << (double)(clock() - start)/CLOCKS_PER_SEC << "\n";
	return 0;
}


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

using namespace std;

int n, m;
pair<int, int> pd[10010];

int main(){
  while(cin >> n >> m && n){
    int d, p;
    for(int i = 0 ; i < n ; i++){
      cin >> d >> p;
      pd[i] = make_pair(p, d);
    }
    sort(pd, pd+n, greater<pair<int, int> >());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (m >= pd[i].second) {
	m -= pd[i].second;
	pd[i].second = 0;
      }
      else {
	pd[i].second -= m;
	break;
      }
    }
    for(int i = 0 ; i < n ;i++){
      ans += pd[i].first * (pd[i].second);
    }
    cout << ans << '\n';
  }
}

Measured memory_bytes: 3088
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 


int main(){

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

	long long l=a/2;

	long long res=abs((a-l)*b*c-l*b*c);

	l=b/2;
	res=min(res,abs((b-l)*a*c-l*a*c));

	l=c/2;
	res=min(res,abs((c-l)*a*b-l*a*b));

	cout<<res<<endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;

    vector<int> p(M);
    vector<string> S(M);
    vector<int> corr(N,0);
    vector<int> wrong(N,0);
    vector<bool> flag(N,false);
    int ans_corr = 0;
    int ans_wrong = 0;
    for (int i = 0; i < M; i++)
    {
        cin >> p.at(i) >> S.at(i);
        if(S.at(i) == "AC"){
            corr.at(p.at(i)-1)++;
            flag.at(p.at(i)-1) = true;
        }
        else
        {
            if(!flag.at(p.at(i)-1)) wrong.at(p.at(i)-1)++;
        }
    }

    for (int i = 0; i < N; i++)
    {
        if(corr.at(i)==0) wrong.at(i)=0;
        else
        {
            ans_corr++;
            ans_wrong += wrong.at(i);
        }
        
    }

    cout << ans_corr << " ";
    cout << ans_wrong << endl;
}


Measured memory_bytes: 6912
module Point = struct

  type t = { x : float; y : float }

  let make x y = { x; y }

  let equal a b = abs_float (a.x -. b.x) < 1e-10 && abs_float (a.y -. b.y) < 1e-10

  let sum a b = { x = a.x +. b.x; y = a.y +. b.y }

  let diff a b = { x = a.x -. b.x; y = a.y -. b.y }

  let multi p k = { x = p.x *. k; y = p.y *. k }

  let div p k = { x = p.x /. k; y = p.y /. k }

  let norm p = p.x *. p.x +. p.y *. p.y

  let abs p = norm p |> sqrt

  let dot a b = a.x *. b.x +. a.y *. b.y

  let cross a b = a.x *. b.y -. a.y *. b.x

  let project p1 p2 p =
    let base = diff p2 p1 in
    dot (diff p p1) base /. norm base
    |> multi base
    |> sum p1

  let reflect p1 p2 p =
    multi (diff (project p1 p2 p) p) 2.
    |> sum p

end

open Point

let () =
  let x1, y1, x2, y2 = Scanf.scanf "%f %f %f %f " (fun a b c d -> a,b,c,d) in
  let p1 = make x1 y1 in
  let p2 = make x2 y2 in
  let q = Scanf.scanf "%d " (fun i -> i) in
  for _ = 0 to q - 1 do
    let x, y = Scanf.scanf "%f %f " (fun x y -> x,y) in
    let p = make x y |> reflect p1 p2 in
    Printf.printf "%.10f %.10f\n" p.x p.y
  done

Measured memory_bytes: 3576