akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};

//--global--//



//----------//

int solve(int n, int m, vector<vector<int> > vv, int dep, vector<int> used, int v){
    used[v] = 1;
    if(dep == n-1){
        rep(i, n){
            if(used[i] == 0) return 0;
        }
        return 1;
    }
    int ans = 0;
    rep(i, vv[v].size()){
        int u = vv[v][i];
        if(used[u] == 0)
            ans += solve(n, m, vv, dep+1, used, u);
    }
    return ans;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int n, m;
    cin >> n >> m;
    vector<vector<int> > vv(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        vv[a].push_back(b);
        vv[b].push_back(a);
    }

    vector<int> used(n);
    cout << solve(n, m, vv, 0, used, 0) << endl;
    
    return 0;
}


Measured memory_bytes: 256
import itertools

class TakoyakiFestival:
    def __init__(self):
        self.N = int(input())
        self.T = list(map(int,input().split(' ')))
  #      print(self.T)
        self.souwa = 0

    def solve(self):
        takokumi = list(itertools.combinations(self.T, 2))
        for i1, i2 in takokumi:
            self.souwa += (i1 * i2)
        return self.souwa

tako = TakoyakiFestival()
ans = tako.solve()

print(ans)




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, m;
    cin >> n >> m;
    if(n % 2 == 1){
        rep(i,m){
            cout << i + 1 << ' ' << n - i << endl;
        }
    }else{
        vector<P> v;
        int x = n / 2;
        rep(i,n/2/2){
            v.push_back(P(x,n+1-x));
            x--;
        }
        rep(i,n/2/2){
            v.push_back(P(x,n+2-x));
            x--;
        }
        rep(i,m)cout << v[i].first << ' ' << v[i].second << endl;
    }
    return 0;
}




Measured memory_bytes: 4208
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
const int maxn = 2e5 + 7;

LL a[maxn],f[maxn];
int n;

bool check(LL x,LL k) {
    for(int i = 1 , j = n ; i <= n ; i++ , j--) {
        LL temp = a[i] * f[j];
        if(temp > x) {
            k -= (temp - x) / f[j];
            if((temp - x) % f[j] != 0) k--;
        }
        if(k < 0) break;
    }
    if(k >= 0) return true;
    else return false;
}

int main() {
    LL k;
    while(~scanf("%d%lld",&n,&k)) {
        for(int i = 1 ; i <= n ; i++) {
            scanf("%lld",&a[i]);
        }
        for(int i = 1 ; i <= n ; i++) {
            scanf("%lld",&f[i]);
        }
        sort(a+1,a+n+1);
        sort(f+1,f+n+1);
        LL l = 0 , r = a[n]*f[n];
        LL ans = 0;
        while(l <= r) {
            LL mid = (l + r + 1LL) >> 1;
            if(check(mid,k)) {
                ans = mid;
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX=10000;
static const int INFTY=(1<<20);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n;
vector<pair<int,int> >adj[MAX];//加权有向图的邻接表示法

void dijkstra(){
    priority_queue<pair<int,int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i = 0; i < n; ++i) {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0]=0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;

    while( !PQ.empty()){
        pair<int,int> f = PQ.top();
        PQ.pop();
        int u = f.second;

        color[u] = BLACK;

        //取出最小值,如果不是最短路径则忽略
        for (int j = 0; j < adj[u].size(); ++j) {
            int v=adj[u][j].first;
            if(color[v] == BLACK) continue;
            if(d[v]>d[u]+adj[u][j].second){
                d[v]=d[u]+adj[u][j].second;
                //prority_queue priority_queue默认优先最大值,因此要乘以-1.
                PQ.push(make_pair(d[v] * (-1),v));
                color[v] = GRAY;
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        cout<<i<<" "<<(d[i]==INFTY ? -1 : d[i])<<endl;
    }
}


int main(){
    int k,u,v,c;

    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v,c));
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 8080
package main

import (
  "fmt"
  "sort"
)

func main() {
  var a, b, c int
  fmt.Scan(&a, &b, &c)
  d := []int{a, b, c} 
  res := ImmutableSort(d)
  if res[0] == 5 && res[1] == 5 && res[2] == 7 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

func ImmutableSort(slice []int) []int {
	res := make([]int, len(slice))
	copy(res, slice)
	sort.Ints(res)
	return res
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll A, B, K;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B >> K;

	ll eat = min(A, K);

	A -= eat;
	K -= eat;

	eat = min(B, K);

	B -= eat;
	K -= eat;

	printf("%lld %lld\n", A, B);
}







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

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<int, int>> AB;
  for(int i = 0; i < N; i++){
    pair<int, int> temp;
    cin >> temp.first >> temp.second;
    AB.push_back(temp);
  }
  sort(AB.begin(), AB.end());
  int ans;
  for(int i = 0; i < N; i++){
    K -= AB.at(i).second;
    if(K <= 0){
      ans = AB.at(i).first;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    rep(i,s.length()){
        int x = s[i]-'A';
        x = (x+n)%26;
        putchar(x+'A');
    }
    cout << endl;
}

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

//#define int long long
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int n, m;
    cin >> n >> m;
    vector<set<int>> graph(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].insert(b);
        graph[b].insert(a);
    }
    
    vector<int> per(n-1);
    rep(i,n-1) per[i] = i+1;
    
    int ans = 0;
    do{
        int now = 0;
        for(int next : per){
            if(!graph[now].count(next)){
                break;
            }else{
                now = next;
            }
        }
        if(now == per.back()) ans++;
    }while(next_permutation(ALL(per)));
    
    cout << ans << endl;
}

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

int main()
{
    int n[8] = {1,2,4,8,16,32,64};
    int t;
    while(cin >> t)
    {
        for(int i = 6;i >= 0;i--)
        {
            if(t >= n[i])
            {
                cout << n[i] << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    if(a <= 9 && b <= 9){
        printf("%d", a * b);
    }
    else
        printf("-1");
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

II = lambda: int(input())
MI = lambda: map(int, input().split())
DBGLOG = lambda s: sys.stderr.write(s + "\n")


def main():
    N, C = MI()
    STs_tmp = [[] for _ in range(C)]

    for i in range(N):
        s, t, c = MI()
        heapq.heappush(STs_tmp[c-1], (s, t))

    s_cnt = defaultdict(int)
    t_cnt = defaultdict(int)
    times = set()
    for c in range(C):
        ls, lt = None, None
        while STs_tmp[c]:
            s, t = heapq.heappop(STs_tmp[c])
            if ls is None:
                ls, lt = s, t
                continue
            if lt == s:
                lt = t
                continue
            else:
                s_cnt[ls-0.5] += 1
                times.add(ls-0.5)
                t_cnt[lt] += 1
                times.add(lt)
                # DBGLOG("c{} {} - {}".format(c + 1, ls, lt))
                ls, lt = s, t
        if ls is not None:
            s_cnt[ls-0.5] += 1
            times.add(ls-0.5)
            t_cnt[lt] += 1
            times.add(lt)
            # DBGLOG("c{} {} - {}".format(c + 1, ls, lt))

    ans, cnt = 0, 0
    for t in sorted(times):
        cnt += s_cnt[t] - t_cnt[t]
        ans = max(ans, cnt)
        # DBGLOG("t={}\t{}".format(t, cnt))
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 42064
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i, x, n) for (int i = x; i < n; i++)
 
int main() {
    
    string s;
    cin >> s;
    map<char, int> mp;
    for (int i = 0; i < s.size(); i++)
        mp[s[i]]++;
    for (int i = 'a'; i <= 'z'; i++)
        if (!mp[i])
            return cout << (char)i << endl, 0;
    cout << "None" << endl;
}

Measured memory_bytes: 512
# encoding: "utf-8"

from collections import defaultdict

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_del(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt   


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort(reverse=True)
    ys = defaultdict(int)
    while xs:
        key = xs[-1]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()

Measured memory_bytes: 18460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define ALL(v) (v).begin(), (v).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
//cout << std::fixed << std::setprecision(15) << y << endl;

int main(){
  ll N, K;
  cin >> N >> K;
  ll zero = 0;
  ll half = 0;
  rep(i,1,N+1){
    if(i % K == 0) zero++;
    if(K % 2 == 0 && i % K == (ll)(K/2)) half++;
  }
  ll ans = pow(zero, 3) + pow(half, 3);
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> t(N);
  rep(i, N) cin >> t[i];

  int X = 0;
  rep(i, N) {
    if (i == N-1) X += T;
    else X += min(t[i+1] - t[i], T);
  }
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 4044
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;




int main(){
   long double n, m, d;
   cin >> n >> m >> d;
   long double res = 2 * (n - d) / (n * n) * (m - 1);
   if(d == 0)res = 1 / n * (m - 1);
   cout << fixed << setprecision(10) << res << endl;
}


Measured memory_bytes: 3740
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(target)
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    m=max(b)[0] - max(target)[0] + s
    for x,y in b:
        if x>m:continue
        for u,v in target:
            if (x + u - s, y + v - t) not in b:break
        else:
            print(x - s, y - t)
            break


Measured memory_bytes: 6096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



ll dp[51][51][2501]; // dp[i][j][k] : 1～i番目までのカードのうち、j枚を使ってkを作る組み合わせの総数
					  // i : 1～N
					  // j : 0～N
					  // k : 0～50*N
int x[51];
int N, A;
void input() {
	scanf("%d%d", &N, &A);
	for (int i = 1; i <= N; i++) scanf("%d", &x[i]);
}

void solve() {
	// 初期条件 j==0
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < 50*N; k++) {
			if (k == 0) dp[i][0][k] = 1;
			else dp[i][0][k] = 0;
		}
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 0; k <= 50 * N; k++) {
				if (k >= x[i]) dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
				else dp[i][j][k] = dp[i - 1][j][k];
			}
		}
	}

	ll ans = 0;
	for (int j = 0; j <= N; j++) ans += dp[N][j][A*j];
	cout << ans << endl;
}

int main() {
	input();
	solve();

	return 0;
}

Measured memory_bytes: 50048
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   int i,a[n+1];
   for(i=0;i<n;i++)
           cin>>a[i];
   int dp[n+1];
   dp[n-1]=0;
   dp[n-2]=abs(a[n-2]-a[n-1]);
   for(i=n-3;i>=0;i--)
           dp[i]=min(abs(a[i]-a[i+1])+dp[i+1],abs(a[i]-a[i+2])+dp[i+2]);

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


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

int main() {
    ll n; cin >> n;
    vector<ll> a(n), cnt(n+1);
    for(int i=0; i<n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll sum = 0;
    for(int i=1; i<=n; i++) sum += cnt[i] * (cnt[i] - 1) / 2;
    for(int i=0; i<n; i++) {
        ll num = sum;
        num -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        cnt[a[i]]--;
        num += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        cout << num << endl;
        cnt[a[i]]++;
    }
}

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

int main(){
    int n; cin >> n;
    vector<int> t(n+1), x(n+1), y(n+1);
    t[0] = x[0] = y[0] = 0;
    rep(i,n){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }
    bool flag = true;
    rep(i,n){
        int dt = t[i+1]-t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if(dt < dist) flag = false;
        if(dt%2 != dist%2) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/

using namespace std;

int k,x;

int main()
{
    cin >> k >> x;
    cout << x-k+1;
    for (int i=x-k+2;i<=x+k-1;i++)
    {
        cout << ' ' << i;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	static final int INF = 50000000;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		int[] nums = new int[N];
		for (int i = 0; i < N; i++)
			nums[i] = sc.ni();
		int ans = 0;
		for (int i = 0; i < N; i += 2) {
			if (nums[i] % 2 == 1)
				ans++;
		}
		pw.println(ans);
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 32848
#include <bits/stdc++.h>
using namespace std;
#define rep(k,dst)    for(int i=k; i<dst;  i++)
#define rep2(k,dst)   for(int j=k; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
const double PI = acos(-1);

int main(){
    ll h, n; cin >> h >> n;
    ll AllDamage=0;
    int a;
    rep(0,n){
        cin >> a;
        AllDamage += a;
    }
    if(AllDamage >= h) cout << "Yes" << endl;
    else               cout << "No"  << endl;
    return 0;
}
/*

*/


Measured memory_bytes: 3648
S = input()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)

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

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

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

    int min_cost = INF;

    for(int x=-100; x<=100; x++){
        int cost = 0;
        for(int i=0; i<n; i++){
            cost += (a[i] - x) * (a[i] - x);
        }
        if(cost < min_cost) min_cost = cost;
    }
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto A = aryread();
    auto cnt = new long[](10 ^^ 5 + 1);
    foreach (a; A)
        cnt[a]++;
    auto s = cnt.dup; // s[x] := パワーx以上のゲストの数
    foreach_reverse (i; 0 .. (10 ^^ 5))
        s[i] += s[i + 1];
    long eval(long x)
    {
        long ret;
        foreach (a; A)
            ret += (x - a + 1 <= 10 ^^ 5) ? s[max(0, x - a + 1)] : 0;
        return ret;
    }

    long m = () {
        long ok = 0;
        long ng = M * (10 ^^ 5) * 2 + 1;
        while (1 < ng - ok)
        {
            long x = (ng + ok) / 2;
            if (M <= eval(x))
            {
                ok = x;
            }
            else
            {
                ng = x;
            }
        }
        return ok;
    }();

    A.sort!"b<a"();
    auto s2 = new long[](N + 1);
    foreach (i; 0 .. N)
        s2[i + 1] = s2[i] + A[i];

    long ans;
    foreach (a; A)
    {
        long c = (m - a + 1 <= 10 ^^ 5) ? s[max(0, m - a + 1)] : 0;
        ans += s2[c] + a * c;
    }
    writeln(ans - (eval(m) - M) * (m + 1));
}


Measured memory_bytes: 7740
# def Swap(A,B):
#     swp = A
#     A = B
#     B = swp
#     return A,B

def BubbleSort(A):
    count = 0
    for i in range(len(A)):
        for j in range(i+1,len(A))[::-1]:
            if(A[j-1] > A[j]):
                swp = A[j-1]
                A[j-1] = A[j]
                A[j] = swp
                count += 1
                # print(A)
                # print(f"count:{count}")
                # print(f"i:{i},j:{j}")
    
    return A,count

def test(a):
    return a

def outputList(A):
    if(len(A) == 1):
        print(A[0])
    else:
        for i in range(len(A)-1):
            print(f"{A[i]} ",end="")
        print(A[-1])
        

n = int(input())
numbers = list(map(int,input().split()))
ans,count = BubbleSort(numbers)
# ans = BubbleSort(numbers)
outputList(ans)
print(count)





Measured memory_bytes: 5620
#include <iostream>
using namespace std;
int main(){
  int N,A;cin>>N>>A;
  int L=A;int R=A+N-1;
  int eat;
  if (R<=0)eat=R;
  else if (L>=0)eat=L;
  else eat=0;
  int ans =(L+R)*(R-L+1)/2-eat;
  cout<<ans<<endl;
}


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

using namespace std;

const int MAX = 1e5 + 9;
const long long INF = 1e18 + 9;

bool cmp(const pair<long long, int> &a, const pair<long long, int> &b) {
	return a.first > b.first;
}

pair<long long, int> a[MAX];
int kind[MAX];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i].second >> a[i].first;
	}
	sort(a, a + n, cmp);
	/*
	for (int i = 0; i < n; i++) {
		auto sushi = a[i];
		cerr << sushi.first << ' ' << sushi.second << '\n';
	}
	cerr << '\n';
	*/
	multiset<pair<long long, int>> s, b;
	int cnt = 0;
	long long sum = 0;
	for (int i = 0; i < k; i++) {
		if (!kind[a[i].second]) {
			cnt++;
			s.insert(make_pair(INF, a[i].second));
		} else {
			s.insert(a[i]);
		}
		kind[a[i].second]++;
		sum += a[i].first * 1LL;
	}
	for (int i = k; i < n; i++) {
		b.insert(make_pair(-a[i].first, a[i].second));
	}
//	cerr << cnt << ' ' << sum << '\n';
	long long ret = cnt * cnt * 1LL + sum * 1LL;
	while (!b.empty() && (*s.begin()).first != INF) {
		if (!kind[(*b.begin()).second]) {
			sum -= (*s.begin()).first * 1LL;
			sum -= (*b.begin()).first * 1LL;
			kind[(*s.begin()).second]--;
			kind[(*b.begin()).second]++;
			s.erase(s.begin());
			cnt++;
			s.insert(make_pair(INF, (*b.begin()).second));
			ret = max(ret, cnt * cnt * 1LL + sum * 1LL) * 1LL;
			/*
			for (auto sushi : s) {
				cerr << sushi.first << ' ' << sushi.second << '\n';
			}
			cerr << '\n';
			*/
		}
		b.erase(b.begin());
	}
	//cerr << cnt << ' ' << sum << '\n';
	cout << ret << '\n';
	
	return 0;
}


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

  int n,q;
  cin>>n;

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

  cin>>q;
  for(int i=0;i<q;i++){

    int b,e;
    cin>>b>>e;

    reverse(a.begin()+b,a.begin()+e);

  }

  int i=0;
  for(int e:a) cout<<(i++?" ":"")<<e;
  cout<<endl;

  return 0;

}



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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

ll mod = 1000000007;
map<int, map<string, ll> > dp;

map<string, bool> outs;
int n;
bool ok(string s) {
  if(s[0]=='A'&&s[2]=='G'&&s[3]=='C') return false;
  if(s[0]=='A'&&s[1]=='G'&&s[3]=='C') return false;
  if (s.find("AGC")!=std::string::npos) return false;
  if (s.find("GAC")!=std::string::npos) return false;
  if (s.find("ACG")!=std::string::npos) return false;
  return true;
}

string agct = "AGCT";

ll solve(string s, int pos) {
  if (dp[pos][s]) {
    return dp[pos][s];
  }

  if (pos == n) {
    return 1;
  }

  ll ret = 0;

  for(int i=0;i<4;i++){
    if (ok(s + agct[i])) {
      ret = (ret + solve(s.substr(1, 2) + agct[i], pos+1)) % mod;
    }
  }

  dp[pos][s] = ret;

  return ret;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>n;

  string s="XXX";
  cout<<solve(s, 0)<<endl;

  return 0;
}


Measured memory_bytes: 896
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;



int main()
{
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(s[0]=='a' && s[1]=='b' && s[2]=='c')
    cout<<"Yes";
    else
    cout<<"No";

    return 0;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<sstream>
#define FOR(i,a,b) for(int i = (a),i##_end_ = (b);i<=i##_end_;i++)
#define ROF(i,a,b) for(int i = (a),i##_end_ = (b);i>=i##_end_;i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 20000005
#define INF 1000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-8
#define DEBUG_
#ifdef DEBUG_
#define DEBUG(...) fprintf(stderr,__VA_ARGS__)
#else
#define DEBUG(...)
#endif // DEBUG
using namespace std;

vector<int>e[N];
vector<pair<pair<int,int>,int> >query;
int ans[N];
int vis[N][15];
void dfs(int u,int d,int c)
{
    if(d<0)return;
    if(vis[u][d])return;
    vis[u][d] = 1;
    if(d == 0)ans[u] = c;
    dfs(u,d-1,c);
    for(auto v:e[u])dfs(v,d-1,c);
}
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        FOR(i,1,n)e[i].clear();
        FOR(i,1,m)
        {
            int x,y;
            cin>>x>>y;
            e[x].PB(y);
            e[y].PB(x);
        }
        int q;
        cin>>q;
        query.clear();
        FOR(i,1,q)
        {
            int x,y,z;
            cin>>x>>y>>z;
            query.PB(MP(MP(x,y),z));
        }
        MST(ans,0);
        MST(vis,0);
        ROF(i,q-1,0)
        {
            dfs(query[i].FT.FT,query[i].FT.SD,query[i].SD);
        }
        FOR(i,1,n)cout<<ans[i]<<endl;
    }
    return 0;
}


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

int main() {
    string s;
    cin >> s;

    int ok = true;
    string rud = "RUD";
    string lud = "LUD";
    rep(i, s.size()) {
        if (i % 2 == 0) {
            if (!lud.find(s[i])) ok = false;
        } else {
            if (!rud.find(s[i])) ok = false;
        }
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
    int m, f, b;
    cin >> m >> f >> b;

    if (m + f >= b) {
        if (m >= b) cout << 0 << endl;
        else cout << b - m << endl;
    } else {
        cout << "NA" << endl;
    }

    return 0;
}


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

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char SMAX(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
template<typename A, typename B> inline char SMIN(A &a, const B &b) {return b < a ? a = b , 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I>
inline void read(I &x) {
	int f = 0, c;
	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
	x = c & 15;
	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
	f ? x = -x : 0;
}

const int N = 300 + 7;
const int P = 998244353;

int n, m, a[N][N], b[N][N], r;

inline int fpow(int x, int y) {
	int ans = 1;
	for (; y; y >>= 1, x = (ll)x * x % P) if (y & 1) ans = (ll)ans * x % P;
	return ans;
}

int main() {
	#ifdef hzhkk
	freopen("hkk.in", "r", stdin);
	#endif
	read(n), read(m);
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) read(a[i][j]);
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= m; ++j)
			if (a[i][j])
				if (!b[j][j]) {
					for (int k = 1; k <= m; ++k) b[j][k] = a[i][k];
					++r;
					break;
				} else for (int k = 1; k <= m; ++k) a[i][k] ^= b[j][k];
	}
	printf("%lld\n", (ll)fpow(2, m - 1) * (fpow(2, n) + P - fpow(2, n - r)) % P);
}

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

using namespace std;

int main(){
    int a1, ai, aj, ak, b1, bi, bj, bk, n;
    while(cin >> n, n){
	for(int i = 0;i < n;i++){
	    cin >> a1 >> ai >> aj >> ak >> b1 >> bi >> bj >> bk;
	    cout << a1 * b1 - ai * bi - aj * bj - ak * bk << " ";
	    cout << a1 * bi + ai * b1 + aj * bk - ak * bj << " ";
	    cout << a1 * bj + aj * b1 + ak * bi - ai * bk << " ";
	    cout << ak * b1 - aj * bi + ai * bj + a1 * bk << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll d, g;
    cin >> d >> g;

    vl p(d), c(d);
    rep(i, d) {
        cin >> p[i] >> c[i];
    }

    ll ans = INF;
    rep(b, 1<<d) {  // bのiビット目が1のとき問題iを全て解く
        ll now = 0;  // いま解いた問題数
        ll point = 0;  // いまのポイント
        vl v(d);  // v[i] : bのiビット目
        rep(i, d) {
            if(b & 1<<i) {
                v[i] = 1;
            }
        }
        rep(i, d) {
            if(v[i]) {
                now += p[i];
                point += 100*(i+1)*p[i] + c[i];
            }
        }
        for(ll i = d-1; i >= 0; i--) {
            if(v[i]) {
                continue;
            }
            exrep(j, 0, p[i]-1) {
                if(point >= g) {
                    break;
                }
                point += 100*(i+1);
                now++;
            }
        }
        if(point >= g) {
            chmin(ans, now);
        }
    }
    
    out(ans);
    re0;
}

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

int main() {
	int choco, N, D, X, A[100], temp;
	cin >> N >> D >> X ;
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	choco = 0;
	for(int i=0;i<N;i++){
		++choco;
		temp = 1;
		for(int j=1;j<=D;j++){
			if(temp*A[i]+1 == j){	
				++choco;
				++temp;
			}
		}
	}
	choco += X;	
	cout << choco << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  long long N;
  cin>>N;
  long long count=0;
  rep(i,N+1){
    if(i%3==0){
      continue;
    }else if(i%5==0){
      continue;
    }else{
      count+=i;
    }
  }
  cout<<count<<endl;
}


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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define REP(i,n) for (ll i = 0; i < n; ++i)

const ll MAX = 1e5+10;
const ll MOD = 1e9+10;

ll A, B, C, D;

ll gcd(ll x, ll y) {
    if (x > y) return gcd(y, x);
    if (x == 0) return y;
    return gcd(x, y%x);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll count(ll x, ll a) {
    return x / a;
}

ll count2(ll x) {
    return count(x, C) + count(x, D) - count(x, lcm(C, D));
}

int main() {
    cin >> A >> B >> C >> D;
    ll ans = B-A - (count2(B) - count2(A-1)) + 1;
    cout << ans << endl;
}

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

int k, t;

int main()
{
    cin >> k >> t;
    priority_queue<P> que;
    rep(i, t)
    {
        int a;
        cin >> a;
        que.push(P(a, i));
    }
    int res = 0;
    int p = -1;
    while(que.size())
    {
        auto a = que.top();
        que.pop();
        if(a.second == p)
        {
            if(que.size() == 0)
            {
                res += a.first;
                break;
            }
            auto b = que.top();
            que.pop();
            p = b.second;
            b.first--;
            que.push(a);
            if(b.first) que.push(b);
        }
        else
        {
            p = a.second;
            a.first--;
            if(a.first) que.push(a);
        }
    }

    cout << res << endl;

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int64_t> a(n), b(n);
    map<int, int> m;
    for(auto& e : a){
        cin >> e;
        m[e]++;
    }
    sort(begin(a), end(a));
    partial_sum(begin(a), end(a), begin(b));
    int ans = 1;
    for(int i = n - 1; i > 0; i -= m[a[i]]){
        if(b[i-1] * 2 >= a[i]){
            if(m[a[i]] > 1){
                ans += m[a[i]];
                continue;
            }
            ans++;
        }else{
            break;
        }
    }
    if(m.size() == 1) ans = n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
<?php
fscanf(STDIN,"%d%d%d",$a,$b,$x);

$s = $x/$a;
$bu = 0;
$a2 = $a;
if($s==$a*$b){
  echo "0";
  exit;
}elseif($s<=($a*$b)/2){//三角形
    $a2 = (2*$s)/$b; 
}else{//台形
  	$bu = 2*$s/$a-$b;
}
$b2 = $b-$bu;
$tan = $b2/$a2;
$result = ((atan($tan)*180)/pi());


echo $result;


Measured memory_bytes: 16432
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>


int main(){
  int H, W, K;
  scanf("%d", &H);
  scanf("%d", &W);
  scanf("%d", &K);
  char map[10][10];
  for (int i=0; i<H; i++){
    std::string s;
    std::cin >> s;
    for (int j=0; j<W; j++){
      map[i][j] = s[j];
    }
  }
  int ans = 0;
  char check[10][10];
  for (int i=0; i<(1<<H); i++){
    for (int j=0; j<(1<<W); j++){
      for (int ii=0; ii<H; ii++){
        for (int jj=0; jj<W; jj++){
          check[ii][jj] = map[ii][jj];
        }
      }
      //printf("hoge1\n");
      for (int I=0; I<H; I++){
        if ((i&(1<<I))!=0){
          for (int jj=0; jj<W; jj++){
            check[I][jj]='r';
          }
        }   
      }
      //printf("hoge2\n");
      for (int J=0; J<W; J++){
        if ((j&(1<<J))!=0){
          //printf("J=%d\n", J);
          for (int ii=0; ii<H; ii++){
            check[ii][J]='r';
          }
        }   
      }
      //printf("hoge3\n");
      int cnt = 0;
      for (int ii=0; ii<H; ii++){
        for (int jj=0; jj<W; jj++){
          //printf("check[%d][%d]=%c\n", ii, jj, check[ii][jj]);
          if (check[ii][jj]=='#') cnt++;
        }
      }
      if (cnt==K) ans++;
      //if (cnt==K) printf("i=%d, j=%d\n", i, j);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e18;

int main() {
    int N;
    cin >> N;
    int p[N+1];
    for (int i = 1; i <= N; i++) cin >> p[i];

    int ans = 0;
    for (int i = 1; i < N; i++) {
        if (i == p[i]) {
            if (i+1 == p[i+1]) {
                ans++;
                p[i+1] = -1;
            } else {
                ans++;
            }
        }
    }

    if (N == p[N]) { // last one
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    vector<pii> v;
    rep(i,0,n){
        int a;cin>>a;
        v.push_back({a,i+1});
    }
    sort(v.begin(),v.end());
    rep(i,0,n)cout<<v[i].second<<" ";
    cout<<endl;
}


Measured memory_bytes: 1780
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long int
#define mod 1000000007
int power(int a,int b,int m)
{
	if(b==0)
	{
		return 1%m;
	}
	else
	{
		int r=power(a,b/2,m);
		if(b%2==0)
		{
			return (r*r)%m;
		}
		else
		{
			int x=(r*r)%m;
			return (a*x)%m;
		}
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m,x;
	cin>>n>>x>>m;
	if(n<=m+10)
	{
		int arr[n];
		arr[0]=x;
		int j;
		for(j=1;j<n;j++)
		{
			int val=arr[j-1];
			int temp=power(val,2,m);
			arr[j]=temp;
		}
		int answer=0;
		for(j=0;j<n;j++)
		{
			answer+=arr[j];
		}
		cout<<answer<<endl;
		exit(0);
	}
	int value[m+5];
	bool visited[m+5]={false};
	int j;
	vector<int> vec;
	for(j=0;j<=m;j++)
	{
		int here;
		if(j==0)
		{
			vec.push_back(x);
			value[j]=x;
			here=x;
		}
		else
		{
			int val=value[j-1];
			int temp=power(val,2,m);
			value[j]=temp;
			vec.push_back(value[j]);
			here=value[j];
		}
		if(visited[here])
		{
			break;
		}
		visited[here]=true;
	}
	int y=vec.size();
	int val=vec[y-1];
	for(j=y-2;j>=0;j--)
	{
		if(vec[j]==val)
		{
			break;
		}
	}
	vec.pop_back();
	y=vec.size();
	vector<int> count(y,0);
	int i;
	for(i=j-1;i>=0;i--)
	{
		count[i]=1;
	}
	for(i=j;i<y;i++)
	{
		count[i]=1;
	}
	n-=y;
	int total=n/(y-j);
	for(i=j;i<y;i++)
	{
		count[i]+=total;
	}
	int left=n%(y-j);
	int ptr=j;
	while(left!=0)
	{
		count[ptr]++;
		ptr++;
		left--;
	}
	int answer=0;
	for(i=0;i<y;i++)
	{
		int here=vec[i]*count[i];
		answer+=here;
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 4632
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<int, lld> pil;
typedef pair<pii, int> piii;
int n, m, p;
lld a[99][99];
lld c[99];
lld res = -1;
lld b[99];
int main()
{
	int i, j, k, l;
	int t = 1, tv = 0;
	while(t--)
	{
		scanf("%d %d %d", &n, &m, &p);
		res = -1;
		for (i = 0; i < n; i++) {
			scanf("%lld", &c[i]);
			for (j = 0; j < m; j++) {
				scanf("%lld", &a[i][j]);
			}
		}
		for (i = 0; i < (1 << n); i++) {
			for (j = 0; j < m; j++)b[j] = 0;
			lld cur = 0;
			for (k = 0; k < n; k++) {
				if (i & (1 << k)) {
					for (j = 0; j < m; j++) {
						b[j] += a[k][j];
					}
					cur += c[k];
				}
			}
			for (j = 0; j < m; j++) {
				if (b[j] < p)break;
			}
			if (j == m) {
				if (res < 0 || res > cur) {
					res = cur;
				}
			}
		}
		printf("%lld\n", res);
	}
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
ll dp[100001];
int main() {
   ll n,x,m;cin>>n>>x>>m;
   ll ans=0;
   ll loop=0, loop_size=0, loop_sum=0, loop_start=0;
   rep(i,200000){
      if(dp[x]==1){
         loop_size++;
         loop_sum+=x;
      }
      if(dp[x]==2){
         loop=((n-i>0)?n-i:0);
         loop_start=x;
         break;
      }
      if(i<n)ans+=x;
      dp[x]++;
      x*=x;
      x%=m;
   }
   if(loop_size>0){
      ans+=(loop/loop_size)*loop_sum;
      rep(i,loop%loop_size){
         ans+=x;
         x*=x;
         x%=m;
      }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 4304
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1154&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

#define MAXN 300005
vector<int> primes;
bool isprime[MAXN];
void init(){
    for(int i = 2; i < MAXN;i++){
        if(isprime[i]) continue;
        if(i%7 == 1 || i%7 == 6){
            primes.push_back(i);
            for(int j = 2;i*j < MAXN;j++){
                isprime[i*j] = true;
            }
        }else{
            isprime[i] = true;
        }
    }
}
int n;
void solve(){
    vector<int> ans;
    cout << n << ": ";
    for(auto p:primes){
        if(n%p == 0){
            assert(p%7 == 1 || p%7 == 6);
            ans.push_back(p);
        }
    }
    cout << ans << endl;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    init();
    while(cin >> n, n!=1){
        solve();
    }
    return 0;
}



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

int main(void){
  int n;
  vector<int> a(100);
  vector<int> c(9);
  cin >> n;
  for(int i = 0; i < n; i ++)
    cin >> a.at(i);
  
  for(int i = 0; i < n; i ++){
    if(a.at(i) < 400) c.at(0) ++;
    else if(a.at(i) < 800) c.at(1) ++;
    else if(a.at(i) < 1200) c.at(2) ++;
    else if(a.at(i) < 1600) c.at(3) ++;
    else if(a.at(i) < 2000) c.at(4) ++;
    else if(a.at(i) < 2400) c.at(5) ++;
    else if(a.at(i) < 2800) c.at(6) ++;
    else if(a.at(i) < 3200) c.at(7) ++;
    else c.at(8) ++;
  }
  int r = 0;
  for(int i = 0; i < 8; i ++){
    if(c.at(i) != 0) r ++;
  }
  
  if(r != 0){
    cout << r << " ";
    r += c.at(8);
    cout << r << endl;
  }
  else cout << "1 " << c.at(8);
  
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

#define TRUE 1
#define FALSE 0

int has3(int x) {
  while(x) {
    if(x%10 ==3) return TRUE;
    x /= 10;
  }
  return FALSE;
}

void call(int n) {
  int x;
  for(x=1;x<=n;x++) {
    if(x%3==0 || has3(x)) {
      printf(" %d",x);
    }
  }
  printf("\n");
}

int main(void) {
  int n;
  scanf("%d",&n);
  call(n);

  return 0;
}


Measured memory_bytes: 2100