akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;


int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int turn = 0;
    while(true){
        if(turn%2==0){
            c-=b;
        }
        else{
            a-=d;
        }
        if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(a<=0){
            cout<<"No"<<endl;
            return 0;
        }
        turn++;
    }
    return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;
static const long long mod = 1000000007;

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

  ll n;
  cin >> n;
  vll as(n), bs(n), cs(n);

  rep(i, n) cin >> as[i];
  rep(i, n) cin >> bs[i];
  rep(i, n) cin >> cs[i];
  Sort(as), Sort(bs), Sort(cs);

  vll pb(n), csum(n+1);
  rep(i, n) {
    pb[i] = n - Upper_bound(cs, bs[i]);
    csum[i+1] = csum[i] + pb[i];
  }
  ll yos = 0;  
  rep(i, n) {
    ll idx = Upper_bound(bs, as[i]);
    yos += csum[n] - csum[idx];
  }

  cout << yos << endl;

  return 0;
}

Measured memory_bytes: 7224
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
long lucas(int n){
    long answer = 0;
    long p = 1;
    long pp = 2;
    long tmp = 0;
    for(int i = 0; i <= n; i++){
        if (i == 0) {answer = pp;}
        else if (i == 1) {answer = p;}
        else{tmp = p + pp; pp = p; p = tmp; answer = tmp;}                   
    }
    return answer;
}
int main()
{
    int n;
    cin >> n;
    long answer = lucas(n);
    cout << answer << endl;
    return 0;
}

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

void printLine(int width) {
	for (int i = 0; i < width; i++) {
		printf("#");
	}
	printf("\n");
}

void printStrLine(int width, string s) {
	cout << "#" << s << "#" << endl;
}

int main(void) {
	int H, W;
	scanf("%d %d", &H, &W);
	string a[100];
	for (int i = 0; i < H; i++) {
		cin >> a[i];
	}
	printLine(W + 2);
	for (int i = 0; i < H; i++) {
		printStrLine(W, a[i]);
	}

	printLine(W + 2);

	return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#define M_PI acos(-1)

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << fixed << setprecision(8) << a*b*sin(M_PI / 180 * c)/2 << endl << a + b + sqrt(a*a+b*b-2*b*a*cos(M_PI/180*c)) << endl << b * sin(M_PI/180*c)<< endl;
}


Measured memory_bytes: 3500
#include<stdio.h>
int main(){
	char s[10];
  	int i,n=0,x=0;
  
	scanf("%s",s);
  
	for(i=0;i<10;i++){
	 if(s[i]=='\0') break;
 	 else{
 	if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
 	 n++;
 	if(n>x) 
 	 x=n;
 	}
	 else n=0;
 	} 
	}
           
  	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using ll = long long;
using ull = unsigned long long;


int main(){


	int N; std::cin >> N;
	std::string S; std::cin >> S;

	int ans = 0;
	int x = 0;
	rep(i, N){
		if(S[i] == 'I')x++;
		if(S[i] == 'D')x--;
		ans = std::max(ans, x);
	}

	std::cout << ans;


	return 0;
}

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


using namespace std;

int main (void)
{

  int N;
  cin >> N;

  int i, j;
  vector<int> light(N);
  // int two_cnt;

  // two_cnt = 0;
  for(i=0; i<N; i++)
  {
    cin >> light.at(i);
    // if(light.at(i) == 2)
    // {
    //   two_cnt++;
    // }
  }
  // if(two_cnt == 0)
  // {
  //   cout << -1 << endl;
  //   return 0;
  // }

  // int  count;
  int  next;
  int  tmp;
  // vector<int> trans(N);
  // bool dup;

  // count = 0;
  tmp = 1;
  for(i=1; i<N; i++)
  {

    // if(i == 0)
    // {
    //   next = light.at(0);
    // }
    // else
    // {
      next = light.at(tmp -1);
    // }
    //count += 1;

    if(next == 2)
    {
      cout << i << endl;
      break;
    }

    // 同じ要素の探索
    // ここ時間かかりすぎ？

    // for(j=0; j<count; j++)
    // {

    //   if(next == trans.at(j))
    //   {
    //     cout << -1 << endl;
    //     return 0;
    //   }

    // }
    // trans.at(i) = next;

    // dup = binary_search(trans.begin(), trans.end(), next);
    // if(dup == true)
    // {
    //   cout << -1 << endl;
    //   break;
    // }

    // trans.at(i) = next;
    // tmp         = trans.at(i);
    tmp = next;

    // sort(trans.begin(), trans.end());
    
  }

  if(i == N)
  {
    cout << -1 << endl;
  }

  return 0;

}



Measured memory_bytes: 640
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  class Pair{
    int x;
    int y;

    Pair(int x, int y) {
      this.x = x;
      this.y = y;
    }

    int[][] ofs = new int[][]{
        {-1, 0},
        {0, 1},
        {1, 0},
        {0, -1}
    };
    Pair(Pair p, int d) {
      this.x = p.x + ofs[d][0];
      this.y = p.y + ofs[d][1];
    }
  }

  void run() {
    for(;;) {
      int N = ni();
      if( N == 0 ) break;


      HashMap<Integer, Pair> map = new HashMap<Integer, Pair>();

      map.put(0, new Pair(0, 0));

      for(int i = 1; i < N; ++i) {
        int n = ni();
        int d = ni();

        map.put(i, new Pair(map.get(n), d));
      }

      int minx = 1 << 28;
      int maxx = 0;
      int miny = 1 << 28;
      int maxy = 0;

      for(Integer ite: map.keySet()) {
        Pair p = map.get(ite);

        minx = Math.min(minx, p.x);
        maxx = Math.max(maxx, p.x);
        miny = Math.min(miny, p.y);
        maxy = Math.max(maxy, p.y);
      }

      int h = maxx - minx + 1;
      int w = maxy - miny + 1;

      System.out.println(h + " " + w);
    }

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

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 35492
input()
count = 0
end = 0
An = list(map(int,input().split()))
while end is not 1:
  for n in An:
    if(n % 2 is not 0):
      end = 1
  if end is not 1:
    count = count + 1
    for n in range(len(An)):
      An[n] = int(An[n]/2)
print(count)

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

#define rep(i,x) for(int i=0;i<x;i++)
#define min_3(a,b,c) min(a,min(b,c))

int main(){
	int q;
	cin>>q;
	rep(i,q){
		int c,a,n;
		cin>>c>>a>>n;
		
		int ret=0;
		
		int m=min_3(c,a,n); ret+=m; c-=m; a-=m;
		m=min(c/2,a); ret+=m; c-=m*2;
		ret+=c/3;
		
		cout<<ret<<endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 ll n,k;
	 cin>>n>>k;
	 vector<ll> v(n);
	 for(ll i=0;i<n;i++)
	 cin>>v[i];
	 
	 ll s = 0;
	 vector<ll> f;
	 for(int i = 0;i<k;i++)
	 {
		 s+=v[i];
	 }
	 f.push_back(s);
	 for(int i=k;i<n;i++)
	 {
		 s-=v[i-k];
		 s+=v[i];
		 f.push_back(s);
	 }
	 for(int i=1;i<(int)f.size();i++)
	 {
		 if(f[i]>f[i-1])
		 cout<<"Yes"<<'\n';
		 else
		 cout<<"No"<<'\n';
	 }
	 return 0;
}


Measured memory_bytes: 6884
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x)  cerr << #x << ": " << x << endl;
#define rep(i,a)  for(ll i=0; i< a; i++)
#define pb push_back
#define vl vector<ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
const ll N=3*1e5+5;ll mod=998244353;
int main()
{
	fast;
	ll t;t=1;
	while(t--)
	{
		ll n;cin>>n;ll a=(n*(n+1)*(n+2))/6;
		for(ll i=0;i<n-1;i++)
		{
			ll u,v;cin>>u>>v;if(u>v)swap(u,v);
			a-=u*(n-v+1);
		}
		cout<<a;
	}

}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

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

    vector<vector<ll>> dp(11, vector<ll>(11));
    repf(i,1,n+1) {
        int a = i%10;
        int b = i;
        while (b >= 10) {
            b /= 10;
        }
        dp[a][b]++;
    }

    ll ans = 0;
    repf(i,1,11) repf(j,1,11) {
        if (i == j) ans += dp[i][j]*dp[i][j];
        else ans += dp[i][j]*dp[j][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    K = int(input())
    A, B = map(int, input().split())

    x = A//K

    y = B//K

    for i in range(A, B+1):
        if i % K == 0:
            print('OK')
            exit()
    if A == B and A % K == 0:
        print('OK')
        exit()
    print('NG')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#import numpy as np

    
##################################################################

if __name__ == "__main__":
    Input1 = [input() for i in range(1)]
    N = int(Input1[0])
    #N = list(map(int,Input1[0].split()))

    if N % 2 == 0:
        print(0.5)
    elif N == 1:
        print(1.0)
    else:
        print((N//2+1)/N)

    #print(''.join(map(str,S[i])))
    


Measured memory_bytes: 2940
K = int(input())
# 10桁までやれば十分
runrun_table = [[0 for _ in range(10)] for _ in range(10)]
# i桁のルンルン数の種類 <= 3**(i-1)*9
for i in range(10):
    runrun_table[0][i] = 1
for keta in range(1, 10):
    for i in range(10):
        if i == 0:
            runrun_table[keta][i] = runrun_table[keta - 1][i] + \
                                    runrun_table[keta - 1][i + 1]
        elif i == 9:
            runrun_table[keta][i] = runrun_table[keta - 1][i - 1] + \
                                    runrun_table[keta - 1][i]
        else:
            runrun_table[keta][i] = runrun_table[keta - 1][i - 1] + \
                                    runrun_table[keta - 1][i] + \
                                    runrun_table[keta - 1][i + 1]

keta = 0
ans = ''
while sum(runrun_table[keta][1:]) < K:
    K -= sum(runrun_table[keta][1:])
    keta += 1

for piv in range(1, 10):
    if runrun_table[keta][piv] >= K:
        ans += str(piv)
        keta -= 1
        break
    K -= runrun_table[keta][piv]

while keta >= 0:
    if piv == 0:
        piv_range = [0, 1]
    elif piv == 9:
        piv_range = [8, 9]
    else:
        piv_range = range(piv-1, piv+2)
    for piv in piv_range:
        if runrun_table[keta][piv] >= K:
            ans += str(piv)
            keta -= 1
            break
        K -= runrun_table[keta][piv]

print(ans)


Measured memory_bytes: 9148
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string S1, S2, S3;
  cin >> S1 >> S2 >> S3;

  cout << "A" << S2[0] << "C";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{
    string s;
    cin >> s;
    int l = 0, r = s.size() - 1;
    while (s[l] != 'A') l++;
    while (s[r] != 'Z') r--;
    cout << r - l + 1 << endl;
}


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

int main(){
	
	int n,i;
	cin>>n;
	
	vector<int>arr(n);
	for(i=0;i<n;i++) cin>>arr[i];
	
	int cnt=0;
	for(i=1;i<n-1;i++){
		
		if(arr[i]>arr[i+1]  &&  arr[i]<arr[i-1]) cnt++;
		else if(arr[i]>arr[i-1] &&  arr[i]<arr[i+1]) cnt++;
		
	}
	cout<<cnt;
	
	
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int ans = 1;

  if (N == 1){
    cout << ans << endl;
    return 0;
  }
  
  for (int i = 1; i < S.size() - 1; i++){
   if (S.at(i) == S.at(i+1) && S.at(i-1) != S.at(i)){
     ans++;
   }
   else if (S.at(i) != S.at(i+1) && S.at(i-1) != S.at(i)){
     ans++;
   }
    
  }
  
  if (S.at(N-1) != S.at(N-2)){
    ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
 int64_t A,B,C;
 cin>>A>>B>>C;
 if(A%2==0||B%2==0||C%2==0){cout<<0<<endl;}
 else {cout<<min(A*B,min(A*C,B*C))<<endl;}
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define INF 100000000
#define pb push_back
#define all(x) (x).begin(),(x).end()

typedef long long ll;

int main() {
	int N; cin >> N;
	string S; cin >> S;
	int B; cin >> B;

	char t = S[B-1];
	
	REP(i, N){
		if (S[i] == t){
			cout << S[i];
		} else {
			cout << '*';
		}
	}

	cout << endl;


	return 0;
}

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

bool is_int(vector<vector<int>> X, int i, int j) {
  int d2 = 0;
  for (int k = 0; k < X[0].size(); k++) {
    d2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
  }

//  printf("d2(%d, %d) = %d\n", i, j, d2);
  
  for (int t = 1; t * t <= d2; t++) {
    if (t * t == d2) return true;
  }
  
  return false;
}

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int k = 0; k < D; k++) {
      cin >> X[i][k];
    }
  }
  
  int ans = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (is_int(X, i, j)) ans++;
    }
  } 
  
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S; cin >> S;
    int n;
    n = S.size();
    int k = 0;
    for(int i=0; i<(n-1)/2; i++){
        if(S[i] != S[n-1-i]){
            k++;
        }
    }
    int l = 0;
    if(((n-1)/2)%2 == 0){
        int p = ((n-1)/2)/2;
        for(int i=0; i<p; i++){
            if(S[i] != S[2*p-1-i]){
                l++;
            }
        }
    }
    else{
        int p = (((n-1)/2)-1)/2;
        for(int i=0; i<p; i++){
            if(S[i] != S[2*p-i]){
                l++;
            }
        }
    }
    if(k==0&&l==0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

bool month(int x) { return 0 < x and x < 13; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int f = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2, 2));
    if (month(f) and month(b))
        print("AMBIGUOUS");
    else if (month(f))
        print("MMYY");
    else if (month(b))
        print("YYMM");
    else
        print("NA");
    return 0;
}


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

int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    vector<int> B(N,K-Q);
    rep(i,Q){
        cin >> A[i];
        A[i]--;
    }
    rep(i,Q){
        B[A.back()]++;
        A.pop_back();
    }
    rep(i,N){
        if(B[i] > 0){
            puts("Yes");
        }
        else{
            puts("No");
        }
    }
    return 0;
}

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

#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl;

const int N=1e6+5;
const double eps=1e-9;
const int INF=1e18;
const int P=1e9+7;

int n;
int a[N];
int cnt[N];

int p[N];//质数数组
bool mpf[N];//vis数组
int ind[N],d[N];//最小质因子指数、因数个数
int phi[N],mu[N];//欧拉函数、莫比乌斯函数
int g[N],f[N];//最小质因子的等比数列求和、因数和

void sieve(int n)
{
    mpf[1]=1;ind[1]=1;d[1]=1;
    phi[1]=1;mu[1]=1;
    g[1]=1;f[1]=1;
    for(int i=2;i<=n;i++){
        if(!mpf[i]){
            mpf[i]=p[++p[0]]=i;ind[i]=1;d[i]=2;
            phi[i]=i-1;mu[i]=-1;
            g[i]=i+1,f[i]=i+1;
        }
        for(int j=1,k;j<=p[0]&&(k=i*p[j])<=n;j++){
            mpf[k]=p[j];
            if(!(i%p[j])){
                ind[k]=ind[i]+1;
                d[k]=d[i]/(ind[i]+1)*(ind[k]+1);
                phi[k]=phi[i]*p[j];mu[k]=0;
                g[k]=g[i]*p[j]+1;
                f[k]=f[i]/g[i]*g[k];
                break;
            }
            ind[k]=1;
            d[k]=d[i]*d[p[j]];
            phi[k]=phi[i]*(p[j]-1);
            mu[k]=-mu[i];
            g[k]=p[j]+1;
            f[k]=f[i]*f[p[j]];
        }
    }
}

void fj(int x)
{
    for(int i=1;p[i]*p[i]<=x;i++){
        if(x%p[i]==0){
            cnt[p[i]]++;
            while(x%p[i]==0){
                x/=p[i];
            }
        }
    }
    if(x!=1) cnt[x]++;
}

signed main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    cin>>n;
    sieve(1000000);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    int g=a[1];
    for(int i=2;i<=n;i++) g=__gcd(g,a[i]);
    for(int i=1;i<=n;i++){
        fj(a[i]);
    }
    int flag=1;
    for(int i=1;i<=1000000;i++){
        if(cnt[i]>=2) flag=0;
    }
    if(flag){
        puts("pairwise coprime");
    }
    else if(g==1){
        puts("setwise coprime");
    }
    else puts("not coprime");
    return 0;
}

//Created Time  :2020/8/29 20:00:20


Measured memory_bytes: 67740
using System;
using System.Linq;

namespace yomikatawakaran
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int tasu = A[0] + A[1];
            int hiku = A[0] - A[1];
            int kakeru = A[0] * A[1];

            if (tasu >= hiku & tasu >= kakeru)
            {
                Console.WriteLine(tasu);
            }
            else if (hiku >= tasu & hiku >= kakeru)
            {
                Console.WriteLine(hiku);
            }
            else if (kakeru >= hiku & kakeru >= tasu)
            {
                Console.WriteLine(kakeru);
            }

        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
string s,s1,s2;

map<pair<string,string>,ll> calc(string t){
    map<pair<string,string>,ll> res;
    rep(bit,1<<N){
        string f,b;
        rep(i,N){
            if(bit&(1<<i)) f+=t[i];
            else b+=t[i];
        }
        res[{f,b}]++;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    cin>>s;
    
    s1=s.substr(0,N);
    s2=s.substr(N,N);
    reverse(all(s2));
    
    map<pair<string,string>,ll> fr,bk;
    fr=calc(s1);
    bk=calc(s2);
    
    ll ans=0;
    for(auto p:fr){
        ans+= p.second*bk[p.first];
    }
    cout1(ans)
}

Measured memory_bytes: 108288
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  queue<long long>a;
  long long y=9;
  for(int i=1;i<10;i++){
    a.push(i);
  } 
  while(y<=n){
   
    if(a.front()%10!=0){
      a.push(a.front()*10+a.front()%10-1);
      y++;
    }
    if(y==n)break;
    
    a.push(a.front()*10+a.front()%10);
    y++;
    if(y==n)break;
    
    if(a.front()%10==9)a.pop();
    else if(a.front()%10!=9){
      a.push(a.front()*10+a.front()%10+1);
      y++;
      a.pop();
    }
    if(y==n)break;
  }
  if(n<10) cout <<n;
  else cout <<a.back()<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if ((a*b) % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;


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

    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }

    int base = a[0];
    int unique_count = 0;
    bool ok = true;
    for(int i=1;i<N;i++){
        if(a[i] == base){
            // pass
        }else if(a[i] + 1 == base){
            unique_count++;
        }else{
            ok = false;
            break;
        }
    }
    if(ok && unique_count + min(1, N - unique_count) <= base && base <= unique_count + (N-unique_count)/2){
        cout << "Yes" << endl;
        return 0;
    }

    base = a[0] + 1;
    unique_count = 1;
    ok = true;
    for(int i=1;i<N;i++){
        if(a[i] == base){
            // pass
        }else if(a[i] + 1 == base){
            unique_count++;
        }else{
            ok = false;
            break;
        }
    }
    if(ok && unique_count + min(1, N - unique_count) <= base && base <= unique_count + (N-unique_count)/2){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
import java.lang.Math;
class Main{

  public static void main(String args[]){

    Scanner stdIn=new Scanner(System.in);
    int x=stdIn.nextInt();
    long[] a=new long[x];
    for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    }
    long minv=a[0];
    long maxv=-999999999;

    for(int i=1; i<x; i++){
        maxv=Math.max(maxv,a[i]-minv);
        minv=Math.min(minv,a[i]);
    }

    System.out.println(maxv);
  }
}



Measured memory_bytes: 102776
let tap f x = f x; x
let (n, m) = Scanf.sscanf (read_line ()) "%d %d" @@ fun n m -> (n, m)
let ab = Array.init m @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d" @@ fun a b -> (a - 1, b - 1)
let ans = Array.make n 0

let tbl = tap
  (fun tbl -> Array.iter (fun (a, b) -> Hashtbl.add tbl a b; Hashtbl.add tbl b a) ab)
  (Hashtbl.create n)

let () =
  let que = Queue.create () in
  List.iter (fun i ->
    ans.(i) <- 1;
    Queue.add i que
  ) @@ Hashtbl.find_all tbl 0;
  while not (Queue.is_empty que) do
    let t = Queue.pop que in
    List.iter (fun i ->
      if ans.(i) = 0 then begin
        ans.(i) <- t + 1;
        Queue.add i que
      end
    ) @@ Hashtbl.find_all tbl t
  done;
  print_endline "Yes";
  for i = 1 to (n - 1) do
    Printf.printf "%d\n" ans.(i)
  done

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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

template <class Itr>
Itr get_adv_itr(Itr _itr, int n) {
  Itr itr(_itr);
  advance(itr, n);
  return itr;
}

string in;
int L, temp, N;

int main() {
  while (getline(cin, in)) {
    istringstream is(in);
    is >> L;
    vector<int> cakes;
    while (is >> temp) cakes.push_back(temp);
    N = cakes.size();
    string ans = "NA";

    rep(i,N) {
      vector<int> cp_cakes(cakes);
      double cost = cp_cakes[i];
      cp_cakes.erase(get_adv_itr(cp_cakes.begin(),i));
      int last = (int)cost;
      while (cp_cakes.size()) {
        vector<int> dists;
        for (int j = 0; j < cp_cakes.size(); ++j)
          dists.push_back(pow(last - cp_cakes[j],2));
        int id = distance(dists.begin(),
                          max_element(dists.begin(), dists.end()));
        // cost += sqrt(pow(last + cp_cakes[id],2) - pow(last - cp_cakes[id],2));
        cost += 2 * sqrt(last * cp_cakes[id]);
        last = cp_cakes[id];
        cp_cakes.erase(get_adv_itr(cp_cakes.begin(), id));
      }
      cost += last;
      if (L >= cost) {
        ans = "OK";
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void) {

  long n,q,a,b,c;
  scanf("%ld", &n);
  long list[100001];
  for (long i = 0; i <= 100000; i++) {
    list[i] = 0;
  }
  long sum = 0;
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a);
    list[a]++;
    sum += a;
  }
  scanf("%ld", &q);
  long count_b;
  for (long i = 0; i < q; i++) {
    scanf("%ld %ld", &b, &c);
    count_b = list[b];
    list[b] = 0;
    sum -= b*count_b;
    sum += c*count_b;
    list[c] += count_b;
    printf("%ld\n", sum);
  }

  return 0;
}

Measured memory_bytes: 2516
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



main(){
  int q;
  cin>>q;
  while(q--){
    int a,b;
    cin>>a>>b;

    if(a==b){
      cout<<(a-1)*2<<endl;
      continue;
    } 

    int lim = a*b-1;
    int l=1,r=1LL<<31;
    while(r-l>1){
      //cout<<r<<' '<<l<<endl;
      int m=(l+r)/2;
      int mul = (m+1)/2*(m+1-(m+1)/2);
      //cout<<mul<<endl;
      if(mul>lim) r=m;
      else l=m;
    }

    cout<<l-1<<endl;
  }

}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

A,V = map(int,S().split())
B,W = map(int,S().split())
T = I()

if V > W and T*abs(V-W) >= abs(A-B):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9216
#import <iostream>

using namespace std;

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

    int sum = 0;
    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r;
        sum += r - l + 1;
    }

    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    vector<int> copy;
    int tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
        copy.push_back(tmp);
    }
    sort(copy.begin(), copy.end());
    int max = copy[n - 1];
    int max2 = copy[n - 2];
    for (int i = 0; i < n; i++)
    {
        if (a[i] == max)
        {
            cout << max2 << endl;
        }
        else
        {
            cout << max << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3436
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

// returns d = gcd(a,b); finds x,y such that d = ax + by
ll extended_euclid(ll a, ll b, ll &x, ll &y) {
  ll xx = y = 0; ll yy = x = 1;
  while (b) {
    ll q = a / b; ll t = b; b = a % b;
    a = t; t = xx; xx = x - q * xx; x = t;
    t = yy; yy = y - q * yy; y = t;
  }
  return a;
}

ll mod(ll a, ll b) {
  return ((a % b) + b) % b;
}

ll mod_inverse(ll a, ll n) {
  ll x, y;
  ll d = extended_euclid(a, n, x, y);
  if(d > 1) return -1;
  return mod(x, n);
}

void upd(ll& ans, ll x, ll y, ll a, ll n) {
  if (__gcd(x, y) != 1) return;
  ll l = mod_inverse((1ll << (a+1)) * x, y);
  if (l <= 0) return;
  ans = min(ans, l * x * (1ll << (a+1)) - 1);
  l = !l ? l : y - l;
  ans = min(ans, l * x * (1ll << (a+1)));
}

int main() {
  FIO
  ll a = 0, n, x;
  read(n);
  if (n == 1) {
    print(n); return 0;
  }
  if (n == 2) {
    print(n+1); return 0;
  }
  x = n;
  while (x % 2 == 0)
    a++, x /= 2;
  ll ans = n;
  for (ll i = 1; i * i <= x; i++)
    if (x % i == 0)
      upd(ans, i, x / i, a, n), upd(ans, x / i, i, a, x);
  print(ans);
  return 0;
}


Measured memory_bytes: 3712
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


w, a, b = MI()
if a + w < b:
    print(b - (a + w))
elif b + w < a:
    print(a - (b + w))
else:
    print(0)


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

using ll=long long;
 
constexpr long long INF64 = 1e18;

int main(){
  int n;
  cin>>n;
  int m[5]={0};
  int a[70]={0};
  for(int i=0;i<n;++i){
    cin>>a[i];
    a[i]+=2;
    m[a[i]]++;
  }
  if(m[0]%2!=0){
    if(m[1]>0){
      m[1]=1;
    }else{
      m[0]--;
      m[1]=0;
    }
  }
  else{
    m[1]=0;
  }
  cout<<m[0]+m[1]+m[4]<<endl;
  for(int i=0;i<n;++i){
    if(a[i]==0 && m[0]>0){
      cout<<i+1<<endl;
      m[0]--;
    }
    if(a[i]==1 && m[1]>0){
      cout<<i+1<<endl;
      m[1]--;
    }
    if(a[i]==4 && m[4]>0){
      cout<<i+1<<endl;
      m[4]--;
    }
  }
}


Measured memory_bytes: 3100
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N, M;
    cin >> N >> M;
    vector<ll> s(M), c(M);
    rep(i, M) cin >> s[i] >> c[i];

    vector<vector<ll>> buf(N);
    rep(i, M) {
        s[i]--;
        buf[s[i]].pb(c[i]);
    }

    rep(i, N) { buf[i].erase(unique(ALL(buf[i])), buf[i].end()); }

    // rep(i, N) {
    //     repv(buf[i]) cout << *it << " ";
    //     cout << endl;
    // }

    if (N == 1) {
        if (M == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (SZ(buf[0]) == 1) {
            cout << buf[0][0] << endl;
            return 0;
        }
    }

    string str;
    rep(i, N) {
        if (SZ(buf[i]) >= 2) {
            cout << -1 << endl;
            return 0;
        } else if (SZ(buf[i]) == 1) {
            if (buf[i][0] == 0 && i == 0) {
                cout << -1 << endl;
                return 0;
            }
            str.pb(char(buf[i][0] + '0'));
        } else if (SZ(buf[i]) == 0) {
            if (i == 0) {
                str.pb('1');
            } else {
                str.pb('0');
            }
        }
    }

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
#include<vector>
#define int long long int
#define mod  1000000007
int32_t main()
{
	 
      int n;
      cin>>n;
      int arr1[n],arr2[n];
      int j;
      for(j=0;j<n;j++)
      {
		  cin>>arr1[j];
	  }
	  for(j=0;j<n;j++)
	     cin>>arr2[j];
	  vector<int> v1(n,-1),v2(n,-1);
	  int maxval=0;
	  for(j=0;j<n;j++)
	  {
		  if(arr1[j]>maxval)
		  {
			  maxval=arr1[j];
			  v1[j]=maxval;
		  }
	  }
	  maxval=0;
	  for(j=n-1;j>=0;j--)
	  {
		  if(arr2[j]>maxval)
		  {
			  maxval=arr2[j];
			  v2[j]=maxval;
		  }
	  }
      bool result=true;
      for(j=0;j<n;j++)
      {
		  if(v1[j]!=-1&&v2[j]!=-1&&v1[j]!=v2[j])
		  {
			  result=false;
			  break;
		  }
		  if(v1[j]!=-1&&v1[j]>arr2[j])
		  {
			  result=false;
			  break;
		  }
		  if(v2[j]!=-1&&v2[j]>arr1[j])
		  {
			  result=false;
			  break;
		  }
	  }
	  if(!result)
	  {
		  cout<<0<<endl;
	  }
	  else
	  {
		  int answer=1;
		  vector<int> v(n,-1);
		  for(j=0;j<n;j++)
		  {
			  if(v1[j]!=-1)
			  {
				  v[j]=v1[j];
			  }
			  else if(v2[j]!=-1)
				 v[j]=v2[j];
		  }
		  int ptr=1;
		  while(ptr<n)
		  {
			  if(v[ptr]==-1)
              {
				  			   int value=min(arr1[ptr],arr2[ptr]);
			   answer=answer*value;
			   answer=answer%mod;
			  }
			   ptr++;
		  }
		  cout<<answer<<endl;
	  }
}


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

const int C = 26;
const int D = 365;

int d;
int c[C];
int s[D][C];

vector<int> t;

void read() {
  scanf("%d", &d);
  for (int i = 0; i < C; ++i) scanf("%d", &c[i]);
  for (int i = 0; i < d; ++i) {
    for (int j = 0; j < C; ++j) {
      scanf("%d", &s[i][j]);
    }
  }
}

int score[D];
int lst[D];
int eval(vector<int> t) {
  int cur = 0;
  for (int i = 0; i < D; ++i) lst[i] = -1;
  for (int i = 0; i < t.size(); ++i) {
    cur += s[i][t[i]];
    lst[t[i]] = i;
    for (int j = 0; j < C; ++j) {
      cur -= (i - lst[j]) * c[j];
    }

    score[i] = cur;
  }

  return cur;
}

void solve() {
  for (int i = 0; i < d; ++i) {
    t.push_back(0);
    for (int j = 1; j < C; ++j) {
      vector<int> nt = t;
      t.back() = j;

      if (eval(nt) > eval(t)) {
        t = nt;
      }
    }
  }

  for (int i = 0; i < 2000; ++i) {
    vector<int> nt = t;
    t[rand() % d] = rand() % C;
    if (eval(nt) > eval(t)) t = nt;
  }
}

void print() {
  for (int i = 0; i < d; ++i) printf("%d\n", t[i] + 1);
}

void printScore() {
  eval(t);
  for (int i = 0; i < d; ++i) printf("%d\n", score[i]);
}

int main() {
  read();
  solve();
  print();
  // cerr << eval(t) << endl;
  // printScore();
  return 0;
}


Measured memory_bytes: 3928
N = int(input())
A = list(map(int, input().split()))
A.sort()

A = [(a, 1) for a in A]
for i in range(N - 1):
    if A[i][0] * 2 >= A[i + 1][0]:
        A[i + 1] = (A[i][0] + A[i+1][0], A[i][1] + 1)
    else:
        A[i + 1] = (A[i][0] + A[i+1][0], 1)
print(A[N - 1][1])


Measured memory_bytes: 19424
#define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define DBG1(a) cerr<<#a<<" = "<<(a)<<"\n"
#define DBG2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define y1 frgrwegreg

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;

const double PI = acos(-1.0);
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 100017;

int n;
int a[200000];
LL res = 0;
int cur = 1;

int main()
{
	//freopen("C.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	FOR (i,0,n) cin >> a[i];
	FOR (i,0,n)
	{
		if (a[i] > cur)
		{
			int ct = (a[i]-1)/cur;
			res += ct;
			//a[i] -= ct*cur;
			if (1 == cur) cur++;
		}
		else
		{
			if (a[i] == cur) cur++;
		}
	}
	cout << res << endl;
	return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 1010
 
int p[MAX][MAX][3];
int t[MAX][MAX][3];
 
int solve(int m,int a,int b,int c,int d){
    return t[c][d][m]-t[a-1][d][m]-t[c][b-1][m]+t[a-1][b-1][m];
}
 
int main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    for(int i = 1 ; i <= N ; i++){
	for(int j = 1 ; j <= M ; j++){
	    char ch; cin >> ch;
	    int m = (ch == 'J' ? 0 :
		     ch == 'O' ? 1 : 2);
	    p[i][j][m]++; t[i][j][m]++;
	    for(int k = 0 ; k < 3 ; k++){
		p[i][j][k] += p[i][j-1][k];
	    }
	    for(int k = 0 ; k < 3 ; k++){
		t[i][j][k] += p[i-1][j][k];
		t[i][j][k] += p[i][j-1][k];
	    }
	}
	for(int j = 1 ; j <= M ; j++){
	    for(int k = 0 ; k < 3 ; k++){
		p[i][j][k] = t[i][j][k];
	    }
	}
    }
    int a,b,c,d;
    while(Q--){
	cin >> a >> b >> c >> d;
	cout << solve(0,a,b,c,d) << " "
	     << solve(1,a,b,c,d) << " "
	     << solve(2,a,b,c,d) << endl;
    }
    return 0;
}

Measured memory_bytes: 26532
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
sum_ = sum(A)
q = int(input())
counter = Counter(A)
for _ in range(q):
    b, c = map(int, input().split())
    x = counter[b]
    counter[c] += x
    counter[b] = 0
    sum_ += (c-b) * x
    print(sum_)

Measured memory_bytes: 24004
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum+=int(s[i])-48;
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 3744
s = readline.split(" ").map{|item| item.to_i}
n = 1
k = []
while n <= s[0] && n <= s[1]
    if s[0] % n == 0 && s[1] % n == 0
        k.push(n)
    end
    n += 1
end
puts k[0 - s[2]]

Measured memory_bytes: 3836
#include <stdio.h>
#include <string.h>

void original(int num, char s){
        int i;

        num = num % 49 +1;
        for(i=0; i<num; i++){
                putchar(s);
        }
}

int main(void){
        char s[51];
        int i,j;

while(scanf("%s",s)!=EOF){
        for(i=0; i<strlen(s); i++){
                if(s[i] == '@'){
                        original(s[i+1],s[i+2]);
                        i = i+2;
                }
                else{
                        putchar(s[i]);
                }
        }
        puts("");
        }
        return 0;
}


Measured memory_bytes: 2124
#include <stdio.h>
#include <stdlib.h>
#define N 4
 
int map[N][N];
int risou[N][N];

int x0,y0;
int lim;
bool check(void){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(map[i][j]!=risou[i][j]) return false;
        }
    }
    return true;
}

int heuris(){
	int res=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(map[i][j]!=0)res += abs(i-(map[i][j]-1)/N)+abs(j-(map[i][j]-1)%N);
		}
	}
	return res;
}
bool swapping(int x,int y,int dep){
    int temp=map[x0+x][y0+y];
    map[x0+x][y0+y]=map[x0][y0];
    map[x0][y0]=temp;
    x0+=x;
    y0+=y;
    if(check()){
        printf("%d\n",dep);
        exit(0);
        return true;
    }
    if(dep+heuris()<=lim){
        if(x!=1&&x0-1!=-1) swapping(-1,0,dep+1);
        if(x!=-1&&x0+1!=N) swapping(1,0,dep+1);
        if(y!=1&&y0-1!=-1) swapping(0,-1,dep+1);
        if(y!=-1&&y0+1!=N) swapping(0,1,dep+1);
    }
    temp=map[x0-x][y0-y];
    map[x0-x][y0-y]=map[x0][y0];
    map[x0][y0]=temp;
    x0-=x;
    y0-=y;
    return false;
}
int main(void){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
			risou[i][j]=i*N+j+1;
            scanf("%d",&map[i][j]);
            if(map[i][j]==0){
                x0=i;
                y0=j;
            }
        }
    }
	risou[N-1][N-1]=0;

    if(check()){
        printf("0\n");
        return 0;
    }
    for(lim=1;lim<46;lim++){
        if(x0-1!=-1) swapping(-1,0,1);
        if(x0+1!=N) swapping(1,0,1);
        if(y0-1!=-1) swapping(0,-1,1);
        if(y0+1!=N) swapping(0,1,1);
    }
    printf("Unsolved\n");
    return 0;
}

Measured memory_bytes: 2760
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;
// typedef complex<long double> point;

#define PI 3.14159265358979323846

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ld a,b,x;
	cin >> a >> b >> x;
	if (x > a*a*b/2){
		cout << setprecision(10) << abs(atan(ld(2)*(x/a/a-b)/a)* ld(180) / PI) << endl;
	} else {
		ld k = a*b*b;
		k /= ld(2);
		k /= x;
		cout << setprecision(10) << atan(k)* ld(180) / PI << endl;
	}
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, i;
    string s, t;
    cin >> n >> s >> t;
    int off = 0;
    int ans = 0;
    for (off = 0; off <=n; ++off) {
        bool fl = true;
        for (int i = 0; i < off; ++i) {
            fl &= (t[i] == s[n - off + i]);
        }
        if (fl)
            ans = off;
    }
    cout << 2 * n - ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int A, B;
  //入力
  scanf("%d%d", &A, &B );
  //判定
  if ( (A<= 8) && (B<= 8)) {
    printf("Yay!\n");
  } else {
    printf(":(\n");
  }
  return 0;
}

Measured memory_bytes: 128