akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,n;
    cin>>h>>w>>n;
    vector<int>a(n);
    REP(i,n) cin>>a[i];
    int cnt=0,k=0;
    int s[h][w];
    REP(i,h){
        if(i%2==0){
            for(int j=0;j<w;j++){
                //cout<<i<<":"<<j<<" "<<k<<endl;
                cnt++;
                s[i][j]=(k+1);
                if(cnt>=a[k]){
                    //cout<<cnt<<":"<<a[k]<<endl;
                    //cout<<i<<":"<<j<<" "<<k<<endl;
                    cnt=0;
                    k++;
                }
            }
        }
        else{
            for(int j=w-1;j>=0;j--){
                cnt++;
                s[i][j]=(k+1);
                if(cnt>=a[k]){
                    cnt=0;
                    k++;
                }
            }
        }
    }
    REP(i,h){
        REP(j,w){
            cout<<s[i][j]<<" ";
        }
        cout<<endl;
    }
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{                  
    int s,t;
    while(1)
   {
        scanf("%d %d",&s,&t);
        if((s==t) && (s==0)) break;
        else if(s>t){
         printf("%d %d\n",t,s);}
        else
         printf("%d %d\n",s,t);
    }
    return 0;
            
}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;

using ll = long long;
const int limit = 100010;
//行き先と費用を持つ構造体
using edge = struct {int to; ll cost;};
//行き先と費用を持った木構造の配列
vector<edge> tree[limit];
//kからの距離記録
ll depth[limit];

//kを支点としてそれぞれの頂点がいくつ離れているかdepthに記録する。
void dfs(int v, int p, ll d){
    depth[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

int main(void){
    //入力
    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }

    int q, k;
    cin >> q >> k;
    k--;

    //距離を記録
    dfs(k, -1, 0);

    //出力
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 14336
#include<stdio.h>
int main()
{
  int a[1000], n, i, j, k, v;
  scanf("%d", &n);
  for(k = 0; k < n; k++)
    {
      scanf("%d",&a[k]);
    }
  for(k = 0; k < n-1; k++)
    {
      printf("%d ",a[k]);
    }
  printf("%d\n", a[n-1]);
  for(i = 1; i < n; i++)
    {
      v = a[i];
      j = i - 1;
      while (j >= 0 && a[j] > v)
	{
	  a[j+1] = a[j];
	  j--;
	  a[j+1] = v;
	}
      for(k = 0; k < n-1; k++)
	{
	  printf("%d ",a[k]);
	}
      printf("%d\n", a[n-1]);
    }
  return 0;
}



Measured memory_bytes: 2064
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    // int T;cin>>T;while(T--) 
    {
        int n, x, ans=0;
        cin>>n;
        ifr(i,1,n+1) {
            cin>>x;
            if((i&1) && (x&1)) ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int n;
	cin>>n;
	string s="";
	while(n!=0){
		int k=n%26;
		if(k==0){
			k=26;
			n--;
		}
		s=char(k+'a'-1)+s;
		n/=26;
	}
	cout<<s;

	return 0;
}


Measured memory_bytes: 3628
N = int(input())
A = [int(x) for x in input().split()]
buf = 0

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

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

int main(){
  int n,r,p,c;

  while(cin >> n >> r , n + r){
    vector<int> cards;

    for(int i = n ; i >= 1 ; i--){
      cards.push_back(i);
    }

    while(r--){
      cin >> p >> c;
      vector<int> tmp;
      for(int i = p-1 ; i < p+c-1 ; i++){
	tmp.push_back(cards[i]);
	cards[i] = -1;
      }
   
      for(int i = 0 ; i < cards.size() ; i++){
	if(cards[i] != -1) tmp.push_back(cards[i]);
      }

      for(int i = 0 ; i < n ; i++){
	cards[i] = tmp[i];
      }

    }
    cout << cards[0] << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
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; }
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); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n,x;
  cin >> n >> x;
  vector<int>m(n);
  int minm = INF;
  rep(i,n){
    cin >> m[i];
    x -= m[i];
    chmin(minm,m[i]);
  }
  int ans = 0;
  ans += n;
  cout << ans + (x / minm) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if(abs(x-a)<abs(x-b)){
		cout << 'A' << endl;
	}else{
		cout << 'B' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <stack>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <regex>
#include <algorithm>
#include <math.h>
#include <string>
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 ALL(obj) obj.begin(), obj.end()
#define UNIQUE(v) v.erase(unique(All(v)), v.end());
typedef long long ll;

typedef pair<int, int> P;
vector<P> vecp;
int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1};

#define N 1000
// input

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int r,d,x;
  cin >> r >> d >> x;
  REP(i, 10){
    int tmp = r * x - d;
    cout << r * x -d << endl;
    x = tmp;
  }
}

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(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}







  


int main() {
 string a,b;
 cin >> a >> b;
 ll n = max(a.size(),b.size());
 bool ok1 = false,ok2 = false;
if (a.size()>b.size()){
  cout << "GREATER" << endl;
  return 0;
}
if (a.size()<b.size()){
  cout << "LESS" << endl;
  return 0;
}
 rep (i,n){
   if (a[i] < b[i]){
     ok2 = true;
     break;
   }
   if (a[i] > b[i]){
     ok1 = true;
     break;
   }

 }
 if (ok1) cout << "GREATER" << endl;
 if (ok2) cout << "LESS" << endl;
 if (!ok1 && !ok2) cout << "EQUAL" << endl;
}





Measured memory_bytes: 3700
def game(n, m, x_list):
  if n >= m:
    return 0
  
  x_list.sort()
  interval = []
  for i in range(m - 1):
    interval.append(x_list[i + 1] - x_list[i])
  interval.sort(reverse = True)
  sum_interval = 0
  for i in range(n - 1):
    sum_interval += interval[i]
  return x_list[m - 1] - x_list[0] - sum_interval

n, m = map(int, input().split())
x = list(map(int, input().split()))

print(game(n, m, x))

Measured memory_bytes: 13968
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  if(x == 0 || y == 0)cout << 0 << endl;
  else{
    while(x!=y){
      if(x>y)x -=y;
      else y-=x;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
  int n,l;
  scanf("%d%d",&n,&l);
  char s[n][l+1];
  char temp[l+1];
  for(int i=0;i<n;i++)scanf("%s",&s[i]);
  qsort(s,n,sizeof(s[0]),strcmp);
  for(int i=0;i<n;i++)printf("%s",s[i]);
  return 0;
}

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

bool JudgeInt(char c)
{
    if (c == '+' || c == '*' || c == '.')
    {
        return false;
    }
    else
    {
        return true;
    }
}

int line;

int search(int n, int level, bool plus, vector<string> calc)
{
    int ans = (plus ? 0 : 1);
    /* if (j == n)
    {
        return ans;
    }*/
    while (line <= n && level == calc[line].size() - 1)
    {

        if (line <= n && level == calc[line].size() - 1 && JudgeInt(calc[line][level]))
        {
            if (plus)
            {
                ans += calc[line][level] - '0';
            }
            else
            {
                ans *= calc[line][level] - '0';
            }
            line++;
        }
        else if (line <= n && calc[line][level] == '+' && level == calc[line].size() - 1)
        {
            line++;
            if (plus)
                ans += search(n, level + 1, true, calc);
            else
                ans *= search(n, level + 1, true, calc);
        }
        else if (line <= n && calc[line][level] == '*' && level == calc[line].size() - 1)
        {
            line++;
            if (plus)
                ans += search(n, level + 1, false, calc);
            else
                ans *= search(n, level + 1, false, calc);
        }
    }
    return ans;
}

int main()
{
    vector<int> ANS;
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        vector<string> calc(n + 2);
        calc[n] = "";
        for (int i = 0; i < n; i++)
        {
            cin >> calc[i];
        }
        line = 0;
        int ans = 0;
        if (JudgeInt(calc[0][0]))
        {
            ans = calc[0][0] - '0';
        }
        else
        {
            ans = (calc[0] == "+" ? 0 : 1);
            while (line < n)
            {
                if (calc[0] == "+")
                {
                    ans += search(n + 1, 0, true, calc);
                }
                else
                {
                    ans *= search(n + 1, 0, false, calc);
                }
            }
        }
        ANS.push_back(ans);
    }
    for (int i = 0; i < ANS.size(); i++)
        cout << ANS[i] << endl;
}


Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {
    static int H;
    static int W;
    static Boolean [][] A;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        H = Integer.parseInt(scan.next());
        W = Integer.parseInt(scan.next());
        A = new Boolean[H][W];
        for(int h=0;h<H;h++){
            String as = scan.next();
            for(int w=0;w<W;w++){
                char a = as.charAt(w);
                if(a=='#'){
                    A[h][w] = true;
                }else{
                    A[h][w] = false;
                }

            }
        }
        scan.close();
        if(calc(0,0)){
            for(int h=0;h<H;h++){
                for(int w=0;w<W;w++){
                    if(A[h][w]){
                        System.out.print("Impossible");
                        System.exit(0);
                    }
                }
            }
            System.out.print("Possible");
        }else{
            System.out.print("Impossible");
        }
    }

    public static Boolean calc(int h,int w){

        if(h==H-1 && w==W-1){
            A[h][w] = false;
            return true;
        }
        if(A[h][w]){
            if(h<H-1) {
                if (calc(h + 1, w)) {
                    A[h][w] = false;
                    return true;
                }
            }
            if(w<W-1) {
                if (calc(h, w + 1)) {
                    A[h][w] = false;
                    return true;
                }
            }
        }else{
            return false;
        }
        return false;
    }

}

Measured memory_bytes: 9684
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    rep(i,x) cin>>a.at(i);
    rep(i,y) cin>>b.at(i);
    rep(i,z) cin>>c.at(i);
    
    vector<ll> ab;
    rep(i,x){
        rep(j,y) ab.push_back(a.at(i)+b.at(j));
    }
    sort(all(ab));
    reverse(all(ab));
    
    vector<ll> ans;
    rep(i,min(k,x*y)){
        rep(j,z) ans.push_back(ab.at(i)+c.at(j));
    }
    sort(all(ans));
    reverse(all(ans));
    
    rep(i,k) cout<<ans.at(i)<<endl;
    
}

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

def ope(i, j):
    return abs(i - j)

appeared = set()

if n > k:
    c = n // k
    n -= k * c

while True:
    result = ope(n, k)
    if result in appeared:
        print(min(appeared))
        exit(0)
    else:
        appeared.add(result)
        n = result


Measured memory_bytes: 2940
import sys
def I(): return int(sys.stdin.readline().rstrip())

N,s = I(),I()


def digit_sum(b,n):  # nのb進法での桁和
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res


M = int(N**.5)+1
for b in range(2,M+1):
    if digit_sum(b,N) == s:
        print(b)
        break
else:  # N = b*q + r と除算して考える(b > M より 0 <= q,r < b)
    ans = 10**12
    for q in range(1,M):
        r = s-q
        if (N-r) % q == 0:
            b = (N-r)//q
            if M < b <= N and 0 <= r < b:
                ans = min(ans,b)
    if N == s:  # q = 0 の場合
        ans = min(ans,N+1)
    print(ans if ans != 10**12 else -1)


Measured memory_bytes: 73880
import sys
import math

input = sys.stdin.readline

S = input()
a = []
b = []

for num,i in enumerate(S):
  if num != 0 and num != len(S)-1:
    if i == "<":
      if S[num-1] == ">":
        b.append("".join(a))
        a = []
  elif S[-1] == "<":
    if S[num-1] == ">":
      b.append("".join(a))
      a = []
      
  a.append(i)
b.append("".join(a))

ans = 0

for j in range(len(b)):
  mx = max(b[j].count("<"),b[j].count(">"))
  mn = min(b[j].count("<"),b[j].count(">"))
  
  ans += mx * (mx + 1) // 2
  if mn >= 2:
    ans += (mn-1) * mn // 2
    
print(ans)

Measured memory_bytes: 75828
s = list(input().split())
stack = []
for i in range(len(s)):
    if s[i] == "+":
        a = stack.pop()
        b = stack.pop()
        stack.append(a+b)
    elif s[i] == "-":
        a = stack.pop()
        b = stack.pop()
        stack.append(b-a)
    elif s[i] == "*":
        a = stack.pop()
        b = stack.pop()
        stack.append(a*b)
    else:
        stack.append(int(s[i]))
print(stack[0])


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans;
    ans = "No";

    if(a == b && a != c){
        ans = "Yes";          
    }
    if(a == c && a != b){
        ans = "Yes";         
    }
    if(c == b && b != a){
        ans = "Yes";          
    }
    
    cout << ans << endl;
    

}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
class Main{
	static int[] powArr = new int[12];

	public static void main(String[] args) {
		for(int i = 0; i < powArr.length; i++) {
			powArr[i] = pow4(i);
		}

try{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int mesLength = Integer.parseInt(br.readLine());
		HashSet<Integer> hs = new HashSet<>(mesLength*2/3);
		StringBuilder sb = new StringBuilder(mesLength*4);

		for(int i = 0; i < mesLength; i++) {
			String _s = br.readLine();
			if(_s.startsWith("i")) {
				hs.add(change(_s.substring(7)));
			}else if(_s.startsWith("f")) {
				if(hs.contains(change(_s.substring(5)))) {
					sb.append("yes\n");
				}else {
					sb.append("no\n");
				}
			}
		}
		System.out.print(sb);
}catch(Exception e) {
	e.printStackTrace();
}
	}

	public static int change(String _s) {
		int sum = 0;
		char[] arr = _s.toCharArray();
		for(int i = 0; i < arr.length; i++) {
			switch(arr[i]) {
				case 'A':
					sum += 1*powArr[i];
					break;
				case 'C':
					sum += 2*powArr[i];
					break;
				case 'G':
					sum += 3*powArr[i];
					break;
				case 'T':
					sum += 4*powArr[i];
					break;
			}
		}
		return sum;
	}

	public static int pow4(int _i) {
		if(_i>0) return pow4(_i-1)*4;
		else return 1;
	}
}

Measured memory_bytes: 121604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int N, C;
vector<vector<int>> d;
vector<vector<int>> c;
map<int, int> cnt[3];

int get_score(int c1, int c2, int c3) {
    int cs[] = {c1, c2, c3};
    int score = 0;
    
    rep(i, 3) {
        for(auto x : cnt[i]) {
            score += x.second * d[x.first][cs[i]];
        }
    }
    
    return score;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> C;
    d.resize(C);
    c.resize(N);
    int score = INT_MAX;
    
    rep(i, C) {
        d[i].resize(C);
        
        rep(ii, C) {
            cin >> d[i][ii];
        }
    }
    
    rep(i, N) {
        c[i].resize(N);
        
        rep(ii, N) {
            cin >> c[i][ii];
            c[i][ii]--;
            cnt[(i + ii) % 3][c[i][ii]]++;
        }
    }
    
    rep(i, C) {
        rep(ii, C) {
            if (i == ii) {
                continue;
            }
            
            rep(iii, C) {
                if ((i == iii) || (ii == iii)) {
                    continue;
                }
                
                score = min(score, get_score(i, ii, iii));
            }
        }
    }
    
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 1280
package main

import (
	"fmt"
)

func main() {
	var s []byte
	fmt.Scan(&s)
	fmt.Print(string(s))
	if s[len(s)-1] == 's' {
		fmt.Println("es")
	} else {
		fmt.Println("s")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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

using namespace std;

int sz[4], N, G, mod = 1e9 + 7, a[109], b[109];
vector < int > v[4];
long long s[4][109], ans;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int substract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}

int Pow (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

/*void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = Pow (fac[lim], mod - 2);for (int i=lim - 1; i>=1; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}*/

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &G);
for (int i=1; i<=N; i++)
{
    scanf ("%d %d", &a[i], &b[i]);
    int t = a[i] - a[1];
    v[t].push_back (b[i]);
}
for (int i=0; i<=3; i++)
{
    sort (v[i].rbegin (), v[i].rend ()), sz[i] = v[i].size ();
    for (int j=1; j<=sz[i]; j++)
        s[i][j] = s[i][j - 1] + v[i][j - 1];
}
for (int i0=0; i0<=sz[0]; i0++)
    for (int i1=0; i1<=sz[1]; i1++)
        for (int i2=0; i2<=sz[2]; i2++)
        {
            long long curr = 1LL * i0 * a[1] + 1LL * i1 * (a[1] + 1) + 1LL * i2 * (a[1] + 2);
            if (curr > G) continue;
            int i3 = (G - curr) / (a[1] + 3);
            if (i3 > sz[3]) i3 = sz[3];
            long long V = s[0][i0] + s[1][i1] + s[2][i2] + s[3][i3];
            //printf ("(%d, %d, %d, %d) -> %lld\n", i0, i1, i2, i3, V);
            if (V > ans) ans = V;
        }
printf ("%lld\n", ans);

return 0;
}


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

int main() {
  int n, a, b, sum = 0, aa=0,bb = 0;
  string s;
  cin >> n >> a >> b >> s;
  for (int i = 0; i < n; i++) {
    char m = s[i];
    if (m == 'a') {
      if (aa+bb+1 <= a + b) {
        cout << "Yes" << endl;
        aa++;
      } else {
        cout << "No" << endl;
      }
    }
    if (m == 'b') {
      if (aa+bb+1 <= a + b && bb+1  <= b) {
        bb++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }

    if (m == 'c') {
      cout << "No" << endl;
    }
  }
}

  

    


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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	printf("%d\n", (x - a) % b);
	return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
	"math"
)

func main() {

	var a float64

	fmt.Scan(&a)

	riding2 := math.Pow(a, 2)
	riding3 := math.Pow(a, 3)

	sum := a + riding2 + riding3

	fmt.Print(sum)
}


Measured memory_bytes: 1840
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#include <limits>

// 各点への最短経路 dijkstra
template<typename dist_t>
class Dijkstra {
    using elem_t = pair<dist_t, int>;

    int n, // 頂点数
        input_edge_num; // 辺の数

    bool directed,           // 有向グラフかどうか
         edge_length_input,  // 入力で辺の長さが与えられるかどうか(ない場合全て1に)
         zero_indexed_input; // 入力で与えられる頂点が0-indexedかどうか
    vector<elem_t> *G;

public:

    vector<int> from;

    static const dist_t INF;

    Dijkstra(int _n) : n(_n), G(new vector<elem_t>[(size_t)n]) {}

    Dijkstra(int _n, vector<elem_t>* &_G) : n(_n), G(_G) {}

    inline void add_edge(int from, int to, dist_t dist=1) {
        G[from].push_back(elem_t{dist, to});
    }

    struct result {
        result(int _n, int k) : n(_n), d(new dist_t[(size_t)_n]) {
            fill(d, d+n, INF); 
            d[k] = 0;
        }
        auto &operator[](int i) { return d[i]; } 
        auto begin() { return d; }
        auto end()   { return d + n; }
        operator dist_t*() { return d; } // dist_t* へのキャスト

        bool unreachable(int i) { return d[i] == INF; }  // 視点から到達不可能かどうか
    private:
        const int n;
        dist_t *d;
    };

    inline result operator()(int start) {
        result d(n, start);
        from.resize(n);

        priority_queue< elem_t, vector<elem_t>, greater<elem_t> > que;
        que.push(elem_t{0, start});

        while (!que.empty()) {
            elem_t p = que.top(); que.pop();
            int now = p.second;
            if (d[now] < p.first) continue;

            for (auto &g:G[now]) {
                int to = g.second;
                dist_t newd = g.first + d[now];

                if (d[to] > newd) {
                    from[to] = now;
                    d[to] = newd;
                    que.push(elem_t(d[to], to));
                }
            }
        }
        return d;
    }

    auto &operator[](int i) { return G[i]; } 
    auto begin() { return G; }
    auto end()   { return G + n; }
};

template<typename dist_t>
const dist_t Dijkstra<dist_t>::INF = numeric_limits<dist_t>::max();

/* Constructers
 *
 * Dijkstra(int _n) 
 * Dijkstra(int _n, vector<elem_t>* &_G)
 */

int main() {
    int n, m;
    cin >> n >> m;
    Dijkstra<int> dijk(n);
    for (int i=0, ai, bi; i<m; i++) {
        cin >> ai >> bi;
        ai--; bi--;
        dijk.add_edge(ai, bi);
        dijk.add_edge(bi, ai);
    }
    auto res = dijk(0);
    bool yes = true;
    for (int i=0; i<n; i++) {
        if (res.unreachable(i)) {
            yes = false;
        }
    }
    cout << (yes ? "Yes" : "No") << '\n';
    if (yes) {
        for (int i=1; i<n; i++) {
            cout << dijk.from[i] + 1 << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 13668
import java.util.Scanner;
								
public class Main{
			public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			while(sc.hasNext()) {
				int n= sc.nextInt();
				if(n==0)break;
				
				int[] power = new int[n+1];
				for(int i=0;i<n;i++) {
					power[i] = sc.nextInt();
				}
				
				int min = 1000000;
				for(int i=0;i<(1<<n);i++) {
					int a = 0;
					int b = 0;
					int s = 0;
					for(int j=0;j<n;j++) {
						if((i>>j)%2==0) a += power[s];
						else b += power[s];
						s++;
					}
					int ret = Math.abs(a-b);
					min = Math.min(ret, min);
				}
				
				System.out.println(min);
			}
	}
}



Measured memory_bytes: 28380
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long

int main() {
  int n;cin>>n;
  vector<double>a(n);
  double bunsi=1,bunbo;
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
    bunsi*=a.at(i);
  }
  for(int i=0;i<n;i++)
  {
    bunbo+=bunsi/a.at(i);
  }
  cout<<bunsi/bunbo;
}
  
    
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int m,k;
int sum;
int main(){
    cin>>m>>k;
    for(int i=1;i<=m;i++)
    {
        for(int j=22;j<=k;j++)
        {
            if(j/10>=2&&j%10>=2&&(j/10)*(j%10)==i)
            {
                sum++;
            }
        }
    }
    cout<<sum;
   return 0;
}




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

using namespace std;

const int mod = 1007050321;
const int base = 521;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int inf = 2e9;

int main() {
    ios_base :: sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n,m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2;

    return 0;
}


Measured memory_bytes: 256
x,y = map(int, input().split( ))

L = [0,300000,200000,100000]
a_x = 0
a_y = 0
if x<=3:
    a_x += L[x]
if y<=3:
    a_y += L[y]

ans = a_x + a_y

if x==1 and y==1:
    ans += 400000

print(ans)

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

int H, A[1000000];

//左の子の節点番号を求める
int left ( int i ) {
  return 2 * i;
}

//右の子の節点番号を求める
int right ( int i ) {
  return 2 * i + 1;
}


void maxHeapify ( int i ) {
  int l, r, largest;
  l = left(i);
  r = right(i);
  
 // 左の子、自分、右の子で値が最大のノードを選ぶ
  if ( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= H && A[r] > A[largest] ) largest = r;

  if ( largest != i ) { // i の子の方が値が大きい場合
    
    int tmp;      //A[i] と A[largest] を交換
    tmp  = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    
    maxHeapify(largest); // 再帰的に呼び出し

  }
}

int main() {

  cin >> H;
  
  for ( int i = 1; i <= H; i++ ) cin >> A[i];

  //配列Aをmax-ヒープに交換する
  for ( int i = H / 2; i >= 1; i-- ) maxHeapify(i);
  
  for ( int i = 1; i <= H; i++ ) cout << " " << A[i];
  cout << endl;

  return 0;
}

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

int main(){
  int N,M,T;
  int cnt=0,a,lt=0;

  cin >> N >> M >> T;

  for (int i=0;i<N;i++){
    cin >> a;
    if (lt<a-M){
      cnt+=(a-M)-lt;
    }
    lt=a+M;
  }
  if (T>lt) cnt+=T-lt;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3072
x1, y1, x2, y2 = list(map(int, input().split()))
x3 = x2 + (y1 - y2)
y3 = y2 - (x1 - x2)
x4 = x3 + (y2 - y3)
y4 = y3 - (x2 - x3)
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define ull unsigned long long
#define inf 1010000000
#define infll 1010000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod)
#define mod 998244353
#define N 305
using namespace std;

int read(); ll readll();

int n,m,a[N],b[N],f[N][N],g[N][N],h[N][N]; char s[N];
int main(){
	scanf("%s%d",s+1,&m);
	int i,j,k,len=strlen(s+1); n=1;
	for (i=1; i<=len; i++) if (s[i]=='0') n++; else a[n]++;
	for (i=1; i<=n; i++) b[i]=b[i-1]+a[i];
	f[0][0]=1;
	for (i=1; i<=n; i++){
		for (k=0; k<=b[n]; k++)
			for (j=0; j<=b[n]; j++){
				if (j) g[j][k]=(g[j-1][k]+f[j][k])%mod; else g[j][k]=f[j][k];
				if (k) h[j][k]=(h[j+1][k-1]+f[j][k])%mod; else h[j][k]=f[j][k];	
			}
		memset(f,0,sizeof(f));
		for (j=b[i]; j<=b[n]; j++)
			for (k=0; k<=b[n]; k++){
				f[j][k]=g[j-a[i]][k];
				if (k) ad(f[j][k],h[j-a[i]+1][k-1]);
				if (k>a[i]) ad(f[j][k],mod-h[j+1][k-a[i]-1]);
			}
	}
	int ans=0;
	for (i=0; i<=m && i<=b[n]; i++) ad(ans,f[b[n]][i]);
	printf("%d\n",ans);
	return 0;
}

int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}


Measured memory_bytes: 4900
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(void){
    int N,K,i=1;
    cin>>N>>K;
    while(1){
        if(pow(K,i)>N)break;
        i++;
    }
    cout<<i<<endl;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int N;
	std::cin >> N;
	for (auto x : boost::irange(1, 50000))
	{
		if (108 * x / 100 == N)
		{
			std::cout << x << std::endl;
			return;
		}
	}
	std::cout << ":(" << std::endl;
}

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }

  sort(begin(a), end(a), greater<>());
  int score_alice = 0;
  int score_bob = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      score_alice += a[i];
    } else {
      score_bob += a[i];
    }
  }
  cout << score_alice - score_bob << endl;
}


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

negs = [num for num in numbers if num <= 0]
abss = []

count = 0
for num in numbers:
  if num >= 0:
    count += num
    abss.append(num)
  else:
    count -= num
    abss.append(-num)
    
if len(negs) % 2 == 0:
  print(count)
else:
  print(count - 2*min(abss))

Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
#define   vpll   vector<pll >
#define   all(x) x.begin(),x.end()
#define   present(c,x)    ((c).find(x) != (c).end())
#define   dbg(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){
  std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
#define   sz(a)  a.size()
#define   vll vector<int>
#define   pll pair<int,int>
#define   ff  first
#define   ss  second
#define   br  cout<<"\n";
#define   ld  long double
#define   int  long long int
const int  INF = 1e18+7;
const int  MAX = 1234567;
const int  MOD = 1000000007;



void solve(){
    string s ;
  	cin >> s ;
  	if ( (s[2] == s[3]) and (s[4] == s[5] )) 
      cout << "Yes";
  	else
      cout <<"No";
}
int32_t main(){
    int t;
    t=1;
    cin.sync_with_stdio(0), cin.tie(0);
    //cin>>t;
    while(t--){
        solve();
        br;
    }
    return 0;
}
 
 
 
 
 
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int r;
    cin >> r;
    cout << r * r << "\n";

    return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())

S=input()
old=''
count=0
data=[0]*len(S)

for i  in range(len(S)):
    if old =='A' and S[i] =='C':
        count+=1
    data[i]=count
    old=S[i]

for i in range(Q):
    L,R=map(int, input().split())
    print(abs(data[L-1]-data[R-1]))


Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1<<30;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
int main(){
  int n;  cin >> n;
  string s; cin >> s;
  vector<int> wh(n+1,0),bl(n+1,0);
  rep(i,0,n){
    wh[i+1] = wh[i] + (s[i]=='.' ? 1 : 0);
    bl[i+1] = bl[i] + (s[i]=='#' ? 1 : 0);
  }
  ll res = 1LL<<60;
  for(int left=0 ; left<=n ; left++){
    ll tmp = 0;
    tmp += bl[left];
    tmp += wh[n] - wh[left];
    chmin(res, tmp);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2180
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    
    print('ABC'+a)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#![allow(dead_code, unused_imports, deprecated)]

use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF: usize = 1_000_000_007;

#[fastout]
fn solve() {
  input!{
    n: usize, k: usize,
  };

  let res = (k..=(n + 1))
    .fold(0, |acc, i| {
      ( acc + (n + 1) * i + 1 - i * i ) % INF
    });
  println!("{}", res);
}

fn main() {
  std::thread::Builder::new()
    .name("big stack size".into())
    .stack_size(32 * 1024 * 1024)
    .spawn(|| {
      solve();
    })
    .unwrap()
    .join()
    .unwrap();
}

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

int main(){
int n;
cin >> n;
int a[n],b[n];
for(int i=0;i<n;i++){ cin >> a[i]; b[i]=a[i];}
sort(b,b+n);
for(int i=0;i<n;i++)
{
printf("%d\n", a[i]==b[n-1] ? b[n-2] : b[n-1]);

}
return 0;
}

Measured memory_bytes: 3200
n = int(input())
a = list(map(int, input().split()))
flag = True
count = 0
while 1:
    for i in range(n):
        if a[i] % 2 != 0:
            flag = False
            break
        a[i] /= 2
    if not flag:
        break
    count += 1
print(count)

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

int main() {
    int n, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        if((i < 10) || (100 <= i && i < 1000) || (10000 <= i && i < 100000)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, X, M = map(int, input().split())
flag = [False for _ in range(M)]
record = list()
record.append(X)
flag[X] = 1

An = X

for i in range(M + 1):
    An = pow(An, 2, M)
    if flag[An]:
        start = flag[An]
        cnt = i + 2 - start
        cost = record[-1] - record[start - 2] if start > 1 else record[-1]
        break

    else:
        record.append(An + record[-1])
        flag[An] = i + 2

if start >= N:
    print(record[N - 1])
else:
    print(((N - start) // cnt) * cost
                + record[(N - start) % cnt + start - 1])


Measured memory_bytes: 13624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();

        long sum = 0l;
        long currentK = k;

        currentK = k -a;
        if(currentK <=0){
            System.out.println(k);
        }else{
            currentK = currentK - b;
            if(currentK <=0){
                System.out.println(a);
            }else{
                sum = a;
                sum = sum - currentK;
                System.out.println(sum);
            }
        }

    }
    public static Double calculate(Double base, Double n) {
        return Math.pow(Math.E, Math.log(base)/n);
    }

    public static int[] toArray(List<Integer> target) {

        final int[] result = new int[target.size()];
        for (int i = 0; i < result.length; i++) {
            result[i] = target.get(i);
        }

        return result;
    }
    public static boolean isMultiple (String s, int base, int m) {
	int temp = 0;
	for (int i=0; i<s.length(); i++) {
		temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
	}
	if (temp==0) {return true;}
	return false;
}
static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 32680
#include <bits/stdc++.h>
using namespace std;
/* 角度でソートし全区間を試す */

#define rep(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define repn(i, m, n) for (int (i) = (m) ; (i) < (int)(n) ; ++(i))
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7

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

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	ll n,m;
	cin >> n >> m;
	
	ll ans = 0;
	if(n==1 && m==1){
		ans += 1;
	}else if(n==1 || m==1){
		ans += max(n,m)-2;
	}else{
		ans += max((ll)0,n-2)*max((ll)0,m-2);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), ans;
    set<int> st;
    rep(i, 0, m){
        cin >> a[i];
    }
    repb(i, m - 1, 0){
        if(!st.count(a[i])){
            st.insert(a[i]);
            ans. push_back(a[i]);
        }
    }
    rep(i, 0, ans. size()){
        cout << ans[i] << endl;
    }
    rep(i, 1, n + 1){
        if(!st.count(i)){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
long long b;
bool flag;
int main(){
	cin>>b;
	if(b%2==0 || b%5==0){
		cout<<-1;
		return 0;
	}
	long long a=0;
    for(int j=1;j<=10000000;j++){
    	a=a*10+7;
        a%=b;
        if(a==0){
        	cout<<j;
        	return 0;
		}
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool vis[105];
vector<set<int> >g;
vector< pair<int,int> >e;
void dfs( int u ){
    vis[u] = true;
    for( auto j: g[u] ){
        if( !vis[j] ){
            dfs(j);
        }
    }
}
int main(){
    cin >> n >> m;
    int s, f, c = 0;
    g.assign( n+5, set<int>() );
    for( int i = 0 ; i < m ; ++i ){
        cin >> s >> f;
        g[s].insert(f);
        g[f].insert(s);
        e.push_back({s,f});
    }
    for( auto it: e ){
        g[it.first].erase(it.second);
        g[it.second].erase(it.first);
        memset(vis, false, sizeof vis);
        dfs( it.first );
        if( !vis[it.second] ) c++;
        g[it.first].insert(it.second);
        g[it.second].insert(it.first);
    }
    cout << c << '\n';
}


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

int main() {
  long long a, b;
  cin >> a >> b;
  if (a < 0 && b > 0) {
    cout << "Zero";
  }
  else if (a < 0 && b < 0) {
    if ((a - b - 1) % 2 == 0) {
      cout << "Positive";
    }
    else {
      cout << "Negative";
    }
  }
  else {
    cout << "Positive";
  }
}

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

using namespace std;

int dp[10001];

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

    for(int i = 1; i <= W; i++)
    {
        dp[i] = -10;
    }

    dp[0] = 0;

    for(int i = 0; i < N; i++)
    {
        int v, w;
        cin >> v >> w;

        for(int j = W - w; j >= 0; j--)
        {
            if(dp[j] != -10 && j + w <= W)
            {
                dp[j + w] = max(dp[j + w], dp[j] + v);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i <= W; i++)
    {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3156