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

signed main(){
  int n;
  cin>>n;
  int arr[n];
  for(int i = 0;i<n;i++){
      cin>>arr[i];
  }
  int dp1[n];
  dp1[0] = 0;
  dp1[1] = abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++){
      dp1[i] = min(dp1[i-1]+abs(arr[i]-arr[i-1]),dp1[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout<<dp1[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;
    reverse(ALL(S));
    ll N=S.size();
    S+='#';
    ll ct=0;
    ll ans=0;
    rep(i,N){
        if(S[i]=='C'){
            if(S[i+1]=='B') ++ct,++i;
            else ct=0;
        }
        else if(S[i]=='B') ct=0;
        else if(S[i]=='A') ans+=ct;
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
                                                                                                
  
int main(){
                                                                     

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    if( abs( c - a ) <= d ){

        cout << "Yes" << endl;

        return 0;

        }

    else if( abs( b - a ) <= d && abs( c - b ) <= d ){

          cout << "Yes" << endl;

          return 0;

          }

    else cout << "No" << endl;


    return 0;

    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.141592653589793238462643383279
using namespace std;
//
int main(){
  string S;
  cin>>S;
  stack<char> ST;
  FOR(i,0,(int)S.size()){
    if(S[i]=='S'){
      ST.push('S');
    }else{
      if(!ST.empty()&&ST.top()=='S'){
        ST.pop();
      }else{
        ST.push('T');
      }
    }
  }
  cout<<ST.size()<<endl;
  return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
string S;
cin >> N >> S;
bool ans = true;
if (N % 2 != 0) ans = false;
else {
for (int i = 0;i < N/2;i++) {
if (S.at(i) != S.at(i+N/2)) ans = false;
}
}
if (ans == false) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            double[] s = new double[n];
            for (int i = 0; i < s.length; i++) {
                s[i] = sc.nextDouble();
            }
            System.out.printf("%.8f\n",Math.sqrt(variance(s)));
        }
        sc.close();
    }

    public static double sum(double[] s) {
        double sum = 0.0;
        for (int i = 0; i < s.length; i++) {
            sum += s[i];
        }
        return sum;
    }

    public static double average(double[] s) {
        return sum(s) / (double)s.length;
    }

    public static double variance(double[] s) {
        double sum = 0;
        for (int i = 0; i < s.length; i++) {
            sum += (s[i] - average(s)) * (s[i] - average(s));
        }
        return sum / (double)s.length;
    }
}


Measured memory_bytes: 39724
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
#include<iomanip>
#include<vector>
#define pi acos(-1)
using namespace std;
typedef unsigned long long int LL;
const int inf=1e9+10;
const int N=1e5+10;
int main()
{
    int x,y,sum;
    scanf("%d%d",&x,&y);
    for(int i=0;i<=x;i++)
    {
        if(i*4+(x-i)*2==y)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

bool func(vector<int>& A, int mid) {
    int size = A[mid];
    rep(i, A.size()) {
        if (i == mid) continue;

        if (size * 2 >= A[i]) {
            size += A[i];
        }
    }

    return size >= A.back();
}

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

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

    int l = -1, r = N - 1;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        (func(A, mid) ? r : l) = mid;
    }

    int ans = N - r;

    cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	map<ll, ll> m;
	for (ll i = 0; i < N; ++i)
	{
		ll a; cin >> a;
		++m[a];
	}

	string res{"No"};
	if (N%3==0)
	{
		if (m.size() == 1)
		{
			if (m.count(0) && m[0])
				res = "Yes";
		}
		else if (m.size() == 2)
		{
			if (m.count(0) && ((ll)m[0] == N/3))
			{
				res = "Yes";
			}
		}
		else if (m.size() == 3)
		{
			bool ok{true};
			ll tmp{0};
			for (auto &p : m)
			{
				tmp ^= p.first;
				if (p.second*3 != N)
					ok = false;
			}
			if (ok && !tmp)
				res = "Yes";
		}
	}
	else
	{
		if ((m.size() == 1) && m.count(0))
			res = "Yes";
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 5120
#include<stdio.h>

const int mod = 1e9 + 7;
int fact[302020], rfact[302020];

int modPow(int x, int n)
{
  if(n == 0) return (1);
  int ret = modPow(x, n / 2);
  ret = 1LL * ret * ret % mod;
  if(n % 2 == 1) {
    ret = 1LL * ret * x % mod;
  }
  return (ret);
}

int modInv(int p)
{
  return (modPow(p, mod - 2));
}

int modCombination(int p, int q)
{
  if(q < 0 || p < q) return (0);
  return (1LL * fact[p] * rfact[q] % mod * rfact[p - q] % mod);
}

void init()
{
  int i;
  fact[0] = rfact[0] = 1;
  for(i = 1; i < 302020; i++) {
    fact[i] = 1LL * fact[i - 1] * i % mod;
    rfact[i] = modInv(fact[i]);
  }
}

int main()
{
  int N, A[100000];
  int appear[100000] = {};
  int i, left, right;
  int curr = 0;

  init();

  scanf("%d", &N);
  ++N;
  for(i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    --A[i];
    ++appear[A[i]];
  }


  for(i = 0; i < N; i++) {
    if(appear[A[i]] == 2) {
      left = i;
      break;
    }
  }
  for(i = N - 1; i >= 0; i--) {
    if(appear[A[i]] == 2) {
      right = N - i - 1;
      break;
    }
  }

  for(i = 1; i <= N; i++) {
    printf("%d\n", (modCombination(N, i) + mod - modCombination(right + left, i - 1)) % mod);
  }
}

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

using namespace std;

#define INF 1e8

int W, H;
vector<string> m;
int check(int x, int y, char c) {
	int ret = 0;
	if (x < 0 || x >= W || y < 0 || y >= H) return 0;
	switch (m[y][x]) {
		case '.':
			m[y][x] = '#';
			for (int dx = -1; dx <= 1; ++dx) {
				for (int dy = -1; dy <= 1; ++dy) {
					if (dx && dy) continue;

					ret += check(x+dx, y+dy, c);
				}
			}
			return ret < 0 ? -INF : ret;

		case '#':
			return 0;

		case 'B':
		case 'W':
			if (c != m[y][x]) return -INF;
			else return 1;
	}
	return true;
}
void fill(int x, int y, char from, char to) {
	if (x < 0 || x >= W || y < 0 || y >= H) return;
	if (m[y][x] == from) {
		m[y][x] = to;
		for (int dx = -1; dx <= 1; ++dx) {
			for (int dy = -1; dy <= 1; ++dy) {
				if (dx && dy) continue;
				fill(x+dx, y+dy, from, to);
			}
		}
	}
	return;
}
int paint(int x, int y) {
	if (x < 0 || x >= W || y < 0 || y >= H) return 0;
	switch (m[y][x]) {
		case '.':
		{
			int ret = 1;
			m[y][x] = '#';
			for (int dx = -1; dx <= 1; ++dx) {
				for (int dy = -1; dy <= 1; ++dy) {
					if (dx && dy) continue;
					ret += paint(x+dx, y+dy);
				}
			}
			return ret;
		}
		case '#':
		case 'B':
		case 'W':
			return 0;
	}
	return 0;
}

int main() {
	while ( cin >> W >> H, W || H ) {
		m.clear(); m.resize(H);
		for (int y = 0; y < H; ++y) {
			cin >> m[y];
		}
		int aw = 0, ab = 0;
		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				if (m[y][x] == '.') {
					if ( check(x, y, 'B') >= 1 ) {
						fill(x, y, '#', '.');
						ab += paint(x, y);
					}
					fill(x, y, '#', '.');
					if ( check(x, y, 'W') >= 1 ) {
						fill(x, y, '#', '.');
						aw += paint(x, y);
					}
				}
			}
		}
		cout << ab << " " << aw << endl;
	}
}

Measured memory_bytes: 1416
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

struct Node
{
    int key;
    Node *right, *left, *parent;
};

Node *root,*NIL;

Node * find(Node *u, int k)
{
    while(u!=NIL&&k!=u->key){
        if(k<u->key) u=u->left;
        else u=u->right;
    }
    return u;
}
void insert(int k)
{
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *) malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key) x=x->left;
        else x=x->right;
    }

    z->parent=y;
    if(y==NIL) root=z;
    else if(z->key<y->key) y->left=z;
    else y->right=z;

}

void inorder(Node *u)
{
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node *u)
{
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main()
{
    int n,i,x;
    string com;
    cin>>n;
    for( i=0;i<n;i++){
        cin>>com;
        if(com[0]=='f'){
            cin>>x;
            Node *t=find(root,x);
            if(t!=NIL) printf("yes\n");
            else printf("no\n");
        }
        else if(com=="insert"){
            cin>>x; insert(x);
        }
        else if(com=="print"){
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
    }
    return 0;
}



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

bool isprime(int x){
    if(x==2)return true;
    else{
        for(int i=2;i<x;i++){
            if(x%i==0)return false;
        }
    }
    return true;
}

int main(){
    int x;
    cin>>x;
    while(true){
        if(isprime(x))break;
        else x++;
    }
    cout<<x<<endl;
    return 0;
}

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

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	string a="ACL";
	while(n--)
		cout<<a;
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3612
N,M=map(int,input().split())
correct=[]
penalty=[0 for i in range(N+1)]
for i in range(M):
  p,S=input().split()
  p=int(p)
  if S=="AC":correct.append(p)
  else:
    if p not in correct: penalty[p] += 1

correct = set(correct)

ans = 0
for p in correct:
  ans += penalty[p]
      
print(' '.join([str(len(correct)), str(ans)]))

Measured memory_bytes: 19572
import sys
input=sys.stdin.readline

n,m,q=map(int,input().split())
p=[[0]*(n+1) for _ in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    p[l][r]+=1
for i in range(1,n+1):
    for j in range(1,n+1):
        p[i][j]+=p[i][j-1]
for i in range(1,n+1):
    for j in range(1,n+1):
        p[i][j]+=p[i-1][j]
for i in range(q):
    l,r=map(int,input().split())
    print(p[r][r]+p[l-1][l-1]-p[l-1][r]-p[r][l-1])


Measured memory_bytes: 54876
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int kai1[12345678], kai2[12345678], kaixy[12345678];
void cominit(int n) {
	int res = 1, num = 1; kai1[0] = 1;
	for (int h = 1; h <= n + 1; h++) {
		res *= h; res %= mod; kai1[h] = res;
	}
	for (int h = n + 1; h >= 1; h--) {
		num *= h; num %= mod; kai2[h] = num;
	}
}
int modpow(int x, int y, int m = mod) {
	int res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= m; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
int aa[12345678], cost[12345678], kari[12345678];
signed main() {
	int n, m, a = 0, x = 0, y = 0, z = 0, ans = 0; cin >> n;
	cominit(n);
	for (int h = 0; h <= n; h++) {
		cin >> aa[h]; cost[aa[h]]++;
		if (cost[aa[h]] == 2) { a = aa[h]; }
	}
	for (int h = 0; h <= n; h++) {
		if (aa[h] == a) {
			if (z == 0) { x = h; z++; }
			else { y = n - h; }
		}
	}
	int num = 1;
	for (int h = x + y; h >= 1; h--) {
		num *= h; num %= mod; kaixy[h] = num;
	}
	for (int h = 1; h <= n + 1; h++) {
		z = kai2[n - h + 2] * modpow(kai1[h], (mod - 2)) % mod;
		int x1 = kaixy[x + y - (h - 1) + 1] * modpow(kai1[h - 1], (mod - 2)) % mod;
		if (h == 1) { cout << n << endl; continue; }
		while (z - x1 < 0) { z += mod; }
		cout << z - x1 % mod << endl;
	}
	return 0;
}

Measured memory_bytes: 11520
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  string S;
  cin >> S;
  map<char, int> m;
  for(int i = 0; S[i] != '\0'; i++){
    if(m.count(S[i])){
      m[S[i]]++;
    }else{
      m[S[i]] = 1;
    }
  }
  
  for(int j = 1; j < n; j++){
    map<char, int> ms;
    cin >> S;
    sort(S.begin(), S.end());
    for(int i = 0; S[i] != '\0'; i++){
      if(m.count(S[i])){
        if(ms.count(S[i])){
          if(m[S[i]] > ms[S[i]]) ms[S[i]]++;
        }else{
          ms[S[i]] = 1;
        }
      }
    }
    m = ms;
  }
  
  for(auto i = m.begin(); i != m.end(); i++){
    for(int j = 0; j < i->second; j++){
      cout << i->first;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define Wsize 50
#define Hsize 50

int map[Hsize+2][Wsize+2]={};//テヲツオツキ0テ」ツ??ゥツ卍クテッツシツ?

void search(int H, int W){
    //printf("テァツ渉セテ・ツ慊ィテ・ツ慊ーW%d H%d\n",W, H);
    int needlH[8]={-1,-1,0,1,1,1,0,-1};
    int needlW[8]={0,1,1,1,0,-1,-1,-1};
    int i;
    map[H][W] = 0;
    for(i=0;i<8;i++){
        //printf("%d %dテ」ツつ津ィツヲツ凝」ツつ欺n",H + needlH[i],W + needlW[i]);
        if(map[H + needlH[i]][W + needlW[i]]){
            //printf("ifin\n");
            search((H + needlH[i]), (W + needlW[i]));
        }
    }
    return;
}

    
int main (void){
    int w,h;
    int i,j;
    int count;
    
    while(1){
        count = 0;
        
        //テ・ツ?・テ・ツ?コテ・ツ環?
        scanf("%d %d",&w ,&h);
        if(!w && !h)
            break;
        
        for(i=1; i<h+1; i++)
            for(j=1; j<w+1; j++)
                scanf("%d",&map[i][j]);
        /*
        for(i=0; i<=h+1; i++){
            for(j=0; j<=w+1; j++){
                printf("%d ",map[i][j]);
            }
            printf("\n");
        }
        */
        
        //テ・ツ?ヲテァツ青?
        for(i=1; i<h+1; i++){
            for(j=1; j<w+1; j++){
                if(map[i][j]){
                    count++;
                    search(i,j);
                }
            }
        }
        printf("%d\n",count);
        
    }
    
    return 0;
}

Measured memory_bytes: 824
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <set>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define SQR 1000000
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a,int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;


int main(){
    string s,t; cin >> s >> t;
    bool flag = false;
    
    rep(i,s.size()){
        if(s==t){
            flag = true;
            break;
        }
        s = s.back() + s.substr(0,s.size()-1);
    }
    
    if(flag) pr("Yes");
    else pr("No");
   
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a,b,c = l[i],l[j],l[k]
            if a+b>c and b+c>a and a+c>b and a!=b and b!=c and c!=a:
                ans += 1
            
print(ans)


            

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin>>n>>m;

    ans = n;
    rep(i,m){
        int ai;
        cin>>ai;
        ans -= ai;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    if(ans >= 0)cout << ans <<endl;
    else cout << -1 <<endl;

    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <iomanip>
#include <math.h>
#include <map>
#include <algorithm>
#define M_PI 3.14159265358979323846264338327950288
#define oo 998244353
#define maxN 200007
using namespace std;

map <long long, int> check;
long long f[maxN];

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
    long long n, x, m;
    cin >> n >> x >> m;
    long long res = x;
    int trace = 0;
    f[1] = res;
    check[res] = 1;
    int pos = 0;
    for (int i = 2; i <= m+10; ++i) {
        res = (res*res)%m;
        f[i] = f[i-1]+res;
        if (check[res] != 0) {
            trace = i;
            pos = check[res];
            break;
        }
        check[res] = i;
    }

    if (n <= trace) cout << f[n] << endl;
    else {
        n -= pos;
        int dist = trace-pos;
        long long a = f[pos+n%dist];
        long long b = (f[trace]-f[pos])*(n/dist);
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 6584
N = int(input())
C = list(sorted(map(int, input().split())))
mod = int(1e9 + 7)

f = [1] * (N + 1)
for i in range(1,N+1):
    f[i] = f[i-1] * 2 % mod

ans = 0
for i in range(N):
    l, r = i, N - i - 1
    res = f[r]
    if r > 0:
        res += f[r-1] * r
    res = res * f[l] % mod
    res = res * C[i] % mod
    res = res * f[N] % mod
    ans = (ans + res) % mod
print(ans)

Measured memory_bytes: 90700
x, y = map(int,input().split())
t1 = [1,3,5,7,8,10,12]
t2 = [4,6,9,11]
t3 = [2]

if x in t1 and y in t1:
    print("Yes")
elif x in t2 and y in t2:
    print("Yes")
elif x in t3 and y in t3:
    print("Yes")
else:
    print("No")

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define inf (int)(1e9)
#define INF 1.1529215e+18
#define MAXX 999999
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/
const int MAX_N=1000001;
V memo(MAX_N,MAXX);//メモ化再帰
int dfs(int d){//d円引き出すのする操作のもっとも少ない回数
    if(d==0)return 0;//0円引きさすのには0回の操作
    if(memo[d]!=MAXX)return memo[d];
    for(int i=1;i<=d;i*=6)memo[d]=min(memo[d],dfs(d-i)+1);
    for(int j=1;j<=d;j*=9)memo[d]=min(memo[d],dfs(d-j)+1);
    return memo[d];
}

int main(){
    int n;cin>>n;
    cout<<dfs(n)<<endl;
}


Measured memory_bytes: 8832
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int INF=1000000007;
int a[804],b[804],g[804],s[804][804],ss[804][804],f[804][804];
int main()
{
	int n,k,i,j,kk,ans=0;
	
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d",&n,&kk);
	n*=2;
	for(i=1;i<=kk;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		if(a[i]>b[i])
			swap(a[i],b[i]);
	}
	g[0]=1;
	for(i=2;i<=n;i+=2)
		g[i]=(long long)g[i-2]*(i-1)%INF;
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
		{
			int sum1=0,sum2=0,flag=0;
			for(k=1;k<=kk;k++)
			{
				if(a[k]>=i&&b[k]<=j)
					sum1++;
				else if(b[k]<i||a[k]>j||a[k]<i&&b[k]>j)
					sum2++;
				else
					flag=1;
			}
			if(!flag)
			{
				s[i][j]=g[j-i+1-sum1-sum1];
				ss[i][j]=g[n-(j-i+1)-sum2-sum2];
			}
			else
			{
				s[i][j]=-1;
				ss[i][j]=-1;
			}
		}
	for(j=1;j<=n;j+=2)
	{
		for(i=1;i+j<=n;i++)
		{
			if(ss[i][i+j]<0)
				continue;
			f[i][i+j]=s[i][i+j];
			for(k=i+1;k<=i+j;k+=2)
				f[i][i+j]=(f[i][i+j]-(long long)f[i][k]*s[k+1][i+j]%INF+INF)%INF;
		}
	}
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			ans=(ans+(long long)f[i][j]*ss[i][j]%INF)%INF;
	printf("%d\n",ans); 
	return 0;
}


Measured memory_bytes: 7040
#include<stdio.h>
int main(void){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  while(a>=0||c>=0){
    c=c-b;
    if(c<=0){
      printf("Yes");
      break;
    }
    a=a-d;
    if(a<=0){
      printf("No");
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1736
n = int(input())
num_list = sorted([ int(input()) for i in range(n)])
num_list_2 = []

for i in range(n):
    if i == 0:
        num_list_2.append([num_list[i]])
    else:
        if num_list[i-1] == num_list[i]:
            num_list_2[-1].append(num_list[i])
        else:
            num_list_2.append([num_list[i]])



num_list_2 = [ len(i)%2 for i in num_list_2 ]
print(sum(num_list_2))

Measured memory_bytes: 65240
# include <iostream>
# include <string>
# include <cstdlib>
using namespace std;
 
 
int main () {
    int N;
    cin >> N;
    int t[N], x[N], y[N];
    for ( int i = 0; i < N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    
    string ans = "Yes";
    for ( int i = 0; i < N; i++){
        int dt, dx, dy;
        if ( i == 0) {
            dt = t[0];
            dx = abs(x[0]);
            dy = abs(y[0]);
        } else {
            dt = t[i] - t[i-1];
            dx = abs(x[i] - x[i-1]);
            dy = abs(y[i] - y[i-1]);
            
        }
        
        if ( dt < dx + dy || (dt - dx - dy) % 2 == 1) {
            ans = "No";
            break;
        }
    }
    
    cout << ans;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include<math.h>
int sort(const void *a,const void *b){
return *(int*)b-*(int*)a;
}
int main(void)
{
int i;
int a;
int x[10];
for(i=0;i<10;i++){
scanf("%d",&x[i]);
}
qsort(x,10,sizeof(x[0]),sort);
for(i=0;i<3;i++){
printf("%d\n",x[i]);
}
return 0;
}

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

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

 int h, m, s;
 h = integer/(60*60);
 m = (integer/60)-(h*60);
 s = integer-(h*60*60)-(m*60);
 cout << h << ":" << m << ":" << s << endl;

 return 0;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:https://www.ioi-jp.org/joi/2008/2009-yo-prob_and_sol/2009-yo-t3/2009-yo-t3.html>
ñ‚ëËï∂============================================================
éüÇÃÇÊÇ§Ç»ÉQÅ[ÉÄÇ™Ç†ÇÈÅD

Ç†ÇÈÉLÉÉÉâÉNÉ^Å[Ç™èc 1 óÒÇ… N å¬ï¿ÇÒÇ≈Ç¢ÇÈÅD 
Ç±ÇÍÇÁÇÃÉLÉÉÉâÉNÉ^Å[ÇÃêFÇÕê‘ÅCê¬ÅCâ©ÇÃÇ¢Ç∏ÇÍÇ©Ç≈Ç†ÇËÅC 
èâä˙èÛë‘Ç≈ìØÇ∂êFÇÃÉLÉÉÉâÉNÉ^Å[Ç™4Ç¬à»è„òAë±ÇµÇƒï¿ÇÒÇ≈Ç¢ÇÈÇ±Ç∆ÇÕÇ»Ç¢ÅD
ÉvÉåÅ[ÉÑÅ[ÇÕÅCÇ†ÇÈà íuÇÃÉLÉÉÉâÉNÉ^Å[ÇëIÇ—ëºÇÃêFÇ…ïœçXÇ∑ÇÈÇ±Ç∆Ç™Ç≈Ç´ÇÈÅD 
Ç±ÇÃëÄçÏÇ…ÇÊÇËìØÇ∂êFÇÃÉLÉÉÉâÉNÉ^Å[Ç™4Ç¬à»è„òAë±ÇµÇƒï¿Ç‘Ç∆ÇªÇÍÇÁÇÃÉLÉÉÉâÉNÉ^Å[ÇÕè¡ñ≈Ç∑ÇÈÅD
ÉLÉÉÉâÉNÉ^Å[Ç™è¡ñ≈Ç∑ÇÈÇ±Ç∆Ç…ÇÊÇËêVÇΩÇ…ìØÇ∂êFÇÃÉLÉÉÉâÉNÉ^Å[Ç™4Ç¬à»è„òAë±ÇµÇƒï¿Ç‘Ç∆
ÇªÇÍÇÁÇÃÉLÉÉÉâÉNÉ^Å[Ç‡è¡ñ≈ÇµÅCìØÇ∂êFÇÃÉLÉÉÉâÉNÉ^Å[Ç™4Ç¬à»è„òAë±ÇµÇƒï¿ÇÒÇ≈Ç¢ÇÈâ”èäÇ™
Ç»Ç≠Ç»ÇÈÇ‹Ç≈Ç±ÇÃòAçΩÇÕë±Ç≠ÅD
Ç±ÇÃÉQÅ[ÉÄÇÃñ⁄ìIÇÕÅC è¡ñ≈ÇµÇ»Ç¢Ç≈écÇ¡ÇƒÇ¢ÇÈÉLÉÉÉâÉNÉ^Å[êîÇÇ»ÇÈÇ◊Ç≠è≠Ç»Ç≠Ç∑ÇÈÇ±Ç∆Ç≈Ç†ÇÈÅD
=================================================================
âê‡=============================================================
iî‘ñ⁄ÇÃÉLÉÉÉâÉNÉ^Å[ÇÃêFÇ™XÇ∆Ç∑ÇÈÇ∆ÅAiî‘ñ⁄ÇÃÉLÉÉÉâÉNÉ^Å[ÇXà»äOÇÃêFÇ…ïœâªÇ≥ÇπÇΩÇ∆Ç´ÅA
Ç«Ç±Ç‹Ç≈è¡ñ≈Ç≥ÇπÇÈÇ±Ç∆Ç™Ç≈Ç´ÇÈÇÃÇ©Çé¿ç€Ç…ÉVÉÖÉ~ÉåÅ[ÉVÉáÉìÇ∑ÇÍÇŒÇÊÇ¢
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N;
    while(cin >> N,N){
	vector<ll> C(N);
	for (int i = 0; i < N;i++) cin >> C[i];
	ll res = INF;
	for (int i = 0; i < N;i++) {
		ll l = i - 1, r = i + 1;
		for (int j = 1; j <= 3;j++) {
			if (j == C[i])continue;
			ll cnt = 1;
			ll nC = j;
			ll pre_l = i, pre_r = i;
			while (true) {
				if (r < N) {
					if (C[r] == nC) {
						cnt++; r++;
						continue;
					}
				}
				if (l >= 0) {
					if (C[l] == nC) {
						cnt++; l--;
						continue;
					}
				}
				if (cnt < 4)break;
				pre_l = l; pre_r = r;
				if (l < 0 || r >= N)break;
				if (C[l] != C[r])break;
				cnt = 2;
				nC = C[l];
				l--; r++;
			}
			ll temp = max(pre_l + 1, 0LL) + max(0LL, N - pre_r);
			if (pre_l == pre_r) temp--;
			res = min(res, temp);
		}
	}
	cout << res << endl;
    }
	return 0;
}



Measured memory_bytes: 3196
# include<iostream>
# include<cstdio>
# include<cmath>
# include<algorithm>
# include<cstring>
using namespace std;
const int mn = 5005;
int a[mn];
bool vis[mn];
int n,k,s;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
	  scanf("%d",&a[i]);
	  a[i]=min(a[i],k);
	  s+=a[i];
	}
	sort(a+1,a+1+n);
	vis[0]=1;
	for(int i=n;i>=0;i--)
	{
		bool flag=false;
		for(int j=k-1;j>=k-s && j>=0;j--)
		   if(vis[j]) {
		   flag=true;
		   break;
		   }
		if(!flag) 
		{
			printf("%d",i);
			return 0;
		}
		for(int j=k;j>=a[i];j--)
		   vis[j]=(vis[j] | vis[j-a[i]]);
		s-=a[i];
	}
	return 0;
}

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

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  
  vector<int> M(N);
  M[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; --i) {
    if (A[i] > M[i + 1]) M[i] = A[i];
    else M[i] = M[i + 1];
  }
  int m = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (M[i + 1] - A[i] > m) m = M[i + 1] - A[i];
  }
  int ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (M[i + 1] - A[i] == m) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

#define MAX_N 36

using namespace std;

struct Card
{
	char suit;
	char value;
};

void swap(Card &a, Card &b) {
	Card tmp = a;
	a = b;
	b = tmp;
}

void bubble_sort(Card A[], int n) {
	bool flag = true;
	int i = 0;
	while (flag) {
		flag = false;
		for (int j = n - 1; j > i; j --) {
			if (A[j].value < A[j - 1].value) {
				swap(A[j], A[j - 1]);
				flag = true;
			}
		}
		i ++;
	}
}

void selection_sort(Card A[], int n) {
	for (int i = 0; i < n - 1; i ++) {
		int minIndex = i;
		for (int j = i + 1; j < n; j ++) {
			if (A[minIndex].value > A[j].value) {
				minIndex = j;
			}
		}

		if (minIndex != i) {
			swap(A[minIndex], A[i]);
		}
	}
}

void print(Card A[], int n) {
	for (int i = 0; i < n; i ++) {
		cout << A[i].suit << A[i].value;
		if (i == n - 1) cout << endl; else cout << " ";
	}
}

int n;
Card C1[MAX_N], C2[MAX_N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++) { cin >> C1[i].suit >> C1[i].value; C2[i] = C1[i]; }
	bubble_sort(C1, n);
	selection_sort(C2, n);


	bool flag = true;
	for (int i = 0; i < n;  i ++) {
		if (C1[i].suit != C2[i].suit) {
			flag = false;
			break;
		}
	}
	print(C1, n);
	cout << "Stable" << endl;
	print(C2, n);
	if (flag) {
		cout << "Stable" << endl;
	} else {
		cout  << "Not stable" << endl;
	}
}


Measured memory_bytes: 3072
using System;

namespace ALDS1_5A_2{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var A = sr.Next<int>(N);
            var Q = sr.Next<int>();
            var M = sr.Next<int>(Q);

            var end = false;
            Func<int, int, bool> solve = null;
            solve = (i, x) =>{
                if(x == 0 || end) return end = true;
                if(i >= N || x < 0) return false;
                return solve(i + 1, x - A[i]) || solve(i + 1, x);
            };

            foreach(var m in M){
                end = false;
                Console.WriteLine(solve(0, m) ? "yes" : "no");
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 10228
#include<stdio.h>
int main()
{
	int a,b,c;
	int hw(int);
	char n[102];
	while(scanf("%d %d",&a,&b)!=EOF)
	{
		int sum=0;
		for(int i=a;i<=b;i++)
		{
			if(hw(i))
				sum++;
		}
		printf("%d\n",sum);
	}
	return 0;
}
int hw(int x)
{
    int x1=x;
	if(x<0)
		return 0;
	long long y=0;
	while(x)
	{
	    y=y*10+(x%10);
		x=x/10;
	}
	if(y==x1)
	   return 1;
	else
	   return 0;
}


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

int main() {
    string s, t; cin >> s >> t;
    vector<vector<int>> memo(s.length()+1, vector<int>(t.length()+1, 0));
    for (int i = 1; i <= s.length(); i++) {
        for (int j = 1; j <= t.length(); j++) {
            memo[i][j] = max(max(memo[i-1][j], memo[i][j-1]), memo[i-1][j-1] + (int)(s[i-1]==t[j-1]));
        }
    }
    string ans = "";
    int pi = s.length()+1, pj = t.length()+1;
    int temp = memo[s.length()][t.length()];
    for (int i = s.length(); 1 <= i; i--) {
        for (int j = t.length(); 1 <= j; j--) {
            if (i < pi && j < pj) {
                if (s[i-1] == t[j-1] && temp == memo[i][j] && memo[i][j] - memo[i-1][j-1] == 1) {
                    ans += s[i-1];
                    pi = i; pj = j;
                    temp--;
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 35584
/*
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
*/
#include <bits/stdc++.h>

#define rep(i,n)  for(int i=0; i<(n); i++)
using ll = long long;
using namespace std;

int main()
{
    int l;
    double a,b;
    cin >> l;
    a = (double)l/3;
    b = a*a*a;
    cout << std::setprecision(8) << b;
    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

string yesno[2] = {"NO", "YES"};

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

    int N;
    std::cin >> N;

    int ev = 0, od = 0;
    
    for(int i=0;i<N;++i){
        int a;
        std::cin >> a;

        if(a % 2 == 0){++ev;}
        else{++od;}
    }

    std::cout << yesno[ev == 0 || od % 2 == 0] << std::endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int h1,m1,h2,m2,t,diff;
  scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&t);
  diff=(h2*60+m2)-(h1*60+m1);
  printf("%d\n",diff-t);
  return 0;
}

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

int main() {
    long int N, X;
    long int D=0;
    
    cin >> N >> X;
    vector<long int> x(N);
    for(int i=0; i<N; i++) {
        cin >> x[i];
    }

    for(int i=0; i<N; i++) {
        x[i] = abs(X - x[i]);
    }

    for(int i=0; i<N; i++) {
        D = __gcd(x[i], D);
    }
    
    cout << D << endl;
    
    return 0;
}

Measured memory_bytes: 1024
n, w = map(int, input().split())

ws, vs = zip(*[map(int, input().split()) for _ in range(n)])

dp = [0] * (w + 1)

for i in range(n):
  for j in reversed(range(w + 1)):
    if j + ws[i] <= w:
      dp[j + ws[i]] = max(dp[j + ws[i]], dp[j] + vs[i])
      
print(dp[w])


Measured memory_bytes: 42732
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;
 
int main(){
    int a,b;cin>>a>>b;
    cout<<max(a-b*2,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

import bisect

N=int(input())
list1=divisor(N)
list1=sorted(list1)
value1=(N**0.5)//1
num=bisect.bisect_left(list1,value1)

x=list1[num]
print(int(x+N/x-2))

Measured memory_bytes: 9588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const double eps = 1e-1;

int main() {
    int n; cin >> n;
    vll x;
    rep(i,n) {
        double f; cin >> f;
        f *= inf;
        ll l = ll(f+eps);
        x.push_back(l);
    }
    vvint data(50,vint(50,0));
    vector<P> ct;
    rep(i,n) {
        int ct_2 = 0, ct_5 = 0;
        while (x[i] % 2 == 0) {
            ct_2++;
            x[i] /= 2;
        }
        while (x[i] % 5 == 0) {
            ct_5++;
            x[i] /= 5;
        }
        data[ct_2][ct_5]++;
        ct.push_back(P(ct_2,ct_5));
    }
    rep(i,50)rep(j,50) {
        if (i != 0) data[i][j] += data[i-1][j];
        if (j != 0) data[i][j] += data[i][j-1];
        if (i != 0 && j != 0) data[i][j] -= data[i-1][j-1];
    }
    ll ans = 0;
    rep(i,n) {
        int ct_2 = max(0,18 - ct[i].first);
        int ct_5 = max(0,18 - ct[i].second);
        int tmp = data[49][49];
        if (ct_5 != 0) tmp -= data[49][ct_5-1];
        if (ct_2 != 0) tmp -= data[ct_2-1][49];
        if (ct_5 != 0 && ct_2 != 0) tmp += data[ct_2-1][ct_5-1];
        if (ct_2 <= ct[i].first && ct_5 <= ct[i].second) tmp--;
        ans += tmp;
    }
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 7992
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100005

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  LL T,t,A,a,B,b,i,ans=0;
  scanf("%lld%lld%lld%lld%lld%lld",&T,&t,&A,&a,&B,&b);
  if(T*A+t*a<T*B+t*b){
    swap(&A,&B);swap(&a,&b);
  }
  if(T*A+t*a==T*B+t*b){
    printf("infinity");
    return 0;
  }
  if(T*A>=T*B){
    printf("0");
    return 0;
  }
  ans=((T*B-T*A)/(T*A+t*a-T*B-t*b))*2+1;
  if((T*B-T*A)%(T*A+t*a-T*B-t*b)==0)ans--;


  printf("%lld\n",ans);
	return 0;
}


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

struct STATE{ int x, y, d; };

bool grid[32][32][32][32];
int d[32][32];

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

int main()
{	
	int m, n;
	while (scanf("%d %d", &m, &n), n){
		memset(grid, false, sizeof(grid));
		
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m - 1; j++){
				int a;
				scanf("%d", &a);
				if (!a){
					grid[i][j][i][j + 1] = 
					grid[i][j + 1][i][j] = true;
				}
			}
			if (i == n) continue;
			for (int j = 1; j <= m; j++){
				int a;
				scanf("%d", &a);
				if (!a){
					grid[i][j][i + 1][j] = 
					grid[i + 1][j][i][j] = true;
				}
			}
		}
		
		memset(d, -1, sizeof(d));
		queue<STATE> que;
		for (que.push((STATE){1, 1, 1}); que.size(); que.pop()){
			STATE st = que.front();
			if (d[st.x][st.y] != -1) continue;
			d[st.x][st.y] = st.d;
			//printf("%d %d\n", st.x, st.y);
			
			for (int i = 0; i < 4; i++){
				if (!grid[st.x][st.y][st.x + dx[i]][st.y + dy[i]]) continue;
				if (d[st.x + dx[i]][st.y + dy[i]] != -1) continue;
				que.push((STATE){st.x + dx[i], st.y + dy[i], st.d + 1});
			}
		}
		
		if (d[n][m] == -1) puts("0");
		else printf("%d\n", d[n][m]);
	}
	
	return 0;
}

Measured memory_bytes: 2248
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long lcm = sc.nextLong();
		for (int i = 0; i < n - 1; i++) {
			long t = sc.nextLong();
			lcm = getLcm(lcm, t);
		}
		System.out.println(lcm);
		sc.close();
	}

	// 2数の最大公約数を求める
	static long getGcd(long a, long b) {
		long rem = a % b;
		if (rem == 0) {
			return b;
		}
		return getGcd(b, rem);
	}

	// 2数の最小公倍数を求める
	static long getLcm(long a, long b) {
		return a / getGcd(a, b) * b;
	}

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=16;
int dp[1<<N],a[N][N],n;
int calc(int s)
{
	int sum=0;
	for(int i=0;i<n;i++)
	{
		if(!(s&(1<<i)))
			continue;
		for(int j=i+1;j<n;j++)
			if(s&(1<<j))
				sum+=a[i][j];
	}
	return sum;
}
int dfs(int s)
{
	if(dp[s]!=-1)
		return dp[s];
	if(s==0)
		return dp[s]=0;
	dp[s]=0;
	int p;
	for(int i=0;i<n;i++)
	{
		if(s&(1<<i))
		{
			p=i;
			break;
		}
	}
	for(int t=s;t;t=s&(t-1))
	{
		int nt=t|(1<<p);
		dp[s]=max(dp[s],calc(nt)+dfs(s^nt));
	}
	return dp[s];
}
main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	memset(dp,-1,sizeof(dp));
	cout<<dfs((1<<n)-1)<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
int main()
{
    int n;cin>>n;
    int i=1;
    int sum=0;
    int reg;
    while(1){
        sum+=i;
        if(sum>=n){
            reg=i;
            break;
        }else{
            i++;
        }
    }
    int k=sum-n;
    for(int i=1;i<=reg;i++){
        if(i!=k){
            cout<<i<<endl;
        }
    }
}


Measured memory_bytes: 256
def get_input():
    N = int(input())
    AB = [tuple(map(int,input().split(" "))) for i in range(N)]
    return N,AB

def solve(N,AB):
    sortedAB = sorted(AB,key=lambda x:x[1])
    sum_of_work = 0 
    flag = True  
    for a,b in sortedAB:
        sum_of_work += a 
        if sum_of_work > b :
            flag = False 
            break
    print("Yes" if flag else "No")

#N,AB = case1()
#solve(N,AB)
#N,AB = get_input()
solve(*get_input())

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

int main(){
	ll n; cin >> n;
	vl u(n-1),v(n-1),w(n-1); 
	rep(i,n-1){
		cin >> u[i] >> v[i] >> w[i];
		--u[i]; --v[i];
	}
	vector<vector<P>> tr(n,vector<P>(0));  
	rep(i,n-1)tr[u[i]].push_back(make_pair(v[i],w[i]));
	rep(i,n-1)tr[v[i]].push_back(make_pair(u[i],w[i]));
	vl d(n); rep(i,n)d[i] = -1;
	d[0] = 0;
	queue<ll> que;
	que.push(0);
	while(!que.empty()){
		ll q = que.front();
		que.pop();
		for(auto x : tr[q]){
			if(d[x.first] != -1)continue;
			d[x.first] = (d[q] + x.second)%2;
			que.push(x.first);
		}
	}
	rep(i,n)cout << d[i] << endl;
}

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


int main() {
int H,W,count,H2,W2;
cin >>H>>W;
H2=H;
W2=W;
vector<vector<char>> table(H,vector<char>(W)); 
rep(i,H){
rep(j,W){
  cin>>table[i][j];

}

}
rep(i,H){
  count=0;
rep(j,W){
if(table[i][j]=='.'){
count++;
}
}
if(count==W){
rep(j,W){
  table[i][j]='0';

}
H2--;
}
  
}
rep(j,W){
  count=0;
rep(i,H){
  if(table[i][j]=='.'){
  count++;
  }

}
if(count==H2){
rep(i,H){
table[i][j]='0';
}
W2 = min(W2,j);
}
else{
    W2 = max(W2,j);
}
}
rep(i,H){
rep(j,W){
  if(table[i][j]=='0'){
 
  }
    
  
  else{
    cout<<table[i][j];
  if(j==min(W2,W-1)){
  cout<<endl;
  }
    
  }
}

}

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		sc.nextLine();
		for(int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list, Comparator.naturalOrder());
		int index = 0;
		for(int i = 0; i < list.size(); i++) {
			if(x < list.get(i)) {
				break;
			}
			if(i == list.size() -1 && x > list.get(i)) {
				break;
			}
			index++;
			x -= list.get(i);

		}
		System.out.println(index);
		
		
		
	}
}



Measured memory_bytes: 23252
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <numeric>
#include <list>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), rend()
#define PB pushback
#define SORT(c) sort((c).begin(),(c).end())

const LL INF = 1LL << 60;

//priority_queue<int> p;

int i, j, k, tmp, ans, cnt, N;
string s;

//scanf("%d",&N);

//printf("%d", ans);

//cout <<  << endl;


int main(void) {
	vector<int> H;
	bool flag = true;
	scanf("%d", &N);
	REP(i, N) {
		scanf("%d", &tmp);
		H.push_back(tmp);
	}
	reverse(ALL(H));

	REP(i, N - 1) {
		tmp =  H.at(i + 1) - H.at(i);
		if (tmp > 1) {
			flag = false;
			break;
		}
		else if (tmp > 0) {
			H.at(i+1)--;
		}
	}

	if (flag) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 892