akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  int k;
  cin>>s>>k;
  int n=s.size();
  int dp0[n+1][k+1];
  int dp1[n+1][k+1];
  rep(i,0,k+1) dp0[0][i]=0;
  rep(i,1,n+1) dp0[i][0]=1;
  rep(i,1,k+1) dp1[0][i]=0;
  rep(i,1,n+1) dp1[i][0]=0;
  dp1[0][0]=1;
  rep(i,0,n){
    rep(j,0,k){
      if(s.at(i)=='0'){
        dp0[i+1][j+1]=dp0[i][j+1]+dp0[i][j]*9;
        dp1[i+1][j+1]=dp1[i][j+1];
      }
      else{
        dp0[i+1][j+1]=dp0[i][j+1]+dp1[i][j+1]+dp0[i][j]*9+dp1[i][j]*(s.at(i)-'0'-1);
        dp1[i+1][j+1]=dp1[i][j];
      }
    }
  }
  cout<<dp0[n][k]+dp1[n][k]<<endl;
}


Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, dp[22][(1 << 21)];
vector <int> can[(1 << 21)];
int a[22][22];

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   return a;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   scanf ("%d", &n);
   for (int i = 1; i <= n; i ++)
      for (int j = 0; j < n; j ++)
         scanf ("%d", &a[i][j]);
   dp[0][0] = 1;
   for (int mask = 0; mask < (1 << n); mask ++)
      for (int i = 0; i < n; i ++)
         if (!(mask & (1 << i)))
            can[mask].pb (i);
   for (int i = 1; i <= n; i ++) {
      for (int mask = 0; mask < (1 << n); mask ++) {
         if (bpp (mask) != i - 1) continue;
         for (auto nxt : can[mask]) {
            if (!a[i][nxt]) continue;
            dp[i][mask | (1 << nxt)]  = add (dp[i][mask | (1 << nxt)], dp[i - 1][mask]);
         }
      }
   }
   printf ("%d", dp[n][(1 << n) - 1]);
}

int main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   //boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 364928
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      int[] alist = new int[N + 1];
      int output = 0;
      for(int i = 0; i < N; i++){
        int a = nextInt();
        alist[a] = alist[a - 1] + 1;
        output = Math.max(output, alist[a]);
      }
      myout(N - output);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 50096
main :: IO ()
main = do
  r <- readLn
  putStrLn $ solve r

solve :: Int -> String
solve r
  | r < 0 = err
  | r < 1200 = "ABC"
  | r < 2800 = "ARC"
  | r <= 4208 = "AGC"
  | r > 4208 = err
 where
  err = error $ "Invalided Rate: " ++ show r

Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;

    return 0;
}


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

int main(){
  ll N,M,S;
  cin >> N >> M >> S;
  int amax = 2501;
  if (S >= amax) S = amax;
  vector< vector< tuple<ll,int, int> > > G(N);
  REP(i,M) {
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    u--; v--;
    G[u].emplace_back( b, v, a);
    G[v].emplace_back( b, u, a);
  }
  vector<int> C(N);
  vector<ll> D(N);
  REP(i,N)  cin >> C[i] >> D[i];

  vector< vector<ll> > ti(N, vector<ll>(amax+2, 1LL << 62));
  priority_queue< tuple< ll, int, int >, vector< tuple< ll, int, int > > , greater< tuple< ll, int, int > > > q;
  q.push( {0, 0, S} );
  ti[0][S] = 0;
  while( !q.empty() ) {
    ll t; int v, co;
    tie(t,v,co) = q.top(); q.pop();
//    cout << t << " " << v << " " << co << endl;
    // 両替
    if ( co < amax ) {
      int vco = min(co + C[v], amax);
      if ( ti[v][co] + D[v] < ti[v][vco] ) {
        ti[v][vco] = ti[v][co] + D[v];
        q.emplace( ti[v][vco], v, vco );
//      cout << "  add " << ti[v][co+C[v]] << " " << v << " " << vco << endl;
      }
    }
    for ( auto nv : G[v] ) {
      ll nvt; int nvpos, nvco;
      tie(nvt, nvpos, nvco) = nv;
      // 移動
      if ( co >= nvco ) {
        if ( ti[v][co] + nvt < ti[nvpos][co-nvco] ) {
          ti[nvpos][co-nvco] = ti[v][co] + nvt;
          q.emplace( ti[nvpos][co-nvco], nvpos, co-nvco );
//        cout << "  add " << ti[nvpos][co-nvco] << " " << nvpos << " " << co-nvco << endl;
        }
      }
    }
  }
  for (int i=1; i<N; i++ ) {
    ll ans = 1LL << 62;
    REP(j, amax) {
      ans = min(ans, ti[i][j]);
    }
    cout << ans << endl;
  }

}

Measured memory_bytes: 6220
#include <iostream>

using namespace std;


int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	if (n==1) cout << "Hello World" << endl;
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

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

int main(int argc, char* argv[]) {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  if((x-r>=0) && (y-r>=0) && (x+r<=w) && (y+r<=h)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
  
#define N 100005
#define U [N]={}
map<L,L> path U;
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,a,b,c,p,r;
char s[5];
L dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d-par[a]){
            par[d]=a;
            dep[d]=dep[a]+1;
            cst[d]=I->second;
            dfs(d);
            siz[a]+=siz[d];
            if(!hev[a]|siz[hev[a]]<siz[d])
                hev[a]=d;
        }
    }
}
    
L edgecost(L a){
    r=add[a]+add[par[a]]+cst[a];
    return r%k?r:0;
}
    
L sum(L i){
    for(r=0;i;r+=bit[i],i-=i&-i);
    return r;
}
L S(L i,L x){
    x=edgecost(x)-sum(i+1)+sum(i);
    for(i++;i<N;bit[i]+=x,i+=i&-i);
}
  
main(){
    for(cin>>n>>k;p<n-1;p++)
        cin>>a>>b>>c,
        path[a][b]=path[b][a]=c;
    dfs(0);
    
    for(c=p=0;p<n;p++)
        if(!p|hev[par[p]]-p)
        for(a=p;!c|a;a=hev[a])
            pos[a]=c++,
            hl_par[a]=p,
            S(pos[a],hev[a]);
    
    for(cin>>a;cin>>s>>a>>b;)
        if(*s&2){
            for(c=0;p=hl_par[a],n=hl_par[b],p-n;a=par[p])
                dep[p]<dep[n]?swap(p,n),swap(a,b),0:0,
                c+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<c+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }else
            add[a]+=b,
            S(pos[a],hev[a]),
            a?S(pos[a]-1,a):0;
}

Measured memory_bytes: 31988
import itertools
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    K = []
    S = [[False]*N for _ in range(M)]
    for i in range(M):
        L = list(map(int, input().split()))
        K.append(L[:1])
        for l in L[1:]:
            S[i][l-1] = True
    P = list(map(int, input().split()))
    # for s in S:
    #         print(s)

    ans = 0
    for i in range(2**N):
        C = [0]*M
        for j in range(N):
            if (i>>j) & 1:
                for k in range(M):
                    if S[k][j]:
                        C[k] += 1
        flg = True
        for j in range(M):
            if C[j]%2!=P[j]:
                flg = False
        if flg:
            ans += 1
        # print(C)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 41968
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    let n = {
        let i = read::<usize>();
        i[0]
    };

    let mut xi: Vec<isize> = Vec::new();
    let mut yi: Vec<isize> = Vec::new();
    let mut hi: Vec<isize> = Vec::new();

    for _i in 0..n {
        let vec = read::<isize>();
        let x = vec[0];
        let y = vec[1];
        let h = vec[2];

        xi.push(x);
        yi.push(y);
        hi.push(h);
    }

    for tx in 0..101 {
        for ty in 0..101 {
            let mut temph = 1;
            for i in 0..n {
                if hi[i] > 0 {
                    temph = hi[i] + (xi[i] - tx).abs() + (yi[i] - ty).abs();
                    break;
                }
            }

            let mut ansf = true;
            for i in 0..n {
                if hi[i] > 0 {
                    let h = hi[i] + (xi[i] - tx).abs() + (yi[i] - ty).abs();
                    if temph != h {
                        ansf = false;
                    }
                } else {
                    if temph - (xi[i] - tx).abs() - (yi[i] - ty).abs() > 0 {
                        ansf = false;
                    }
                }
            }

            if ansf == true {
                println!("{} {} {}", tx, ty, temph);
                return;
            }
        }
    }
}


Measured memory_bytes: 4352
s = gets.chomp.chars.map(&:to_i)

s0 = 0
s1 = 0
f = 0
s.each do |n|
  if f.zero?
    s0 += 1 unless n.zero?
    s1 += 1 if n.zero?
  else
    s0 += 1 if n.zero?
    s1 += 1 unless n.zero?
  end
  f = 1 - f
end
puts [s0, s1].min

Measured memory_bytes: 7676
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

constexpr int mod = 1e9 + 7;

int dp[105][105][256];
int a[105];

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

    rep(i, n) cin >> a[i];

    dp[0][0][0] = 1;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            for (int k = 0; k <= 255; ++k) {
                (dp[i + 1][j + 1][k ^ a[i]] += dp[i][j][k]) %= mod;
                (dp[i + 1][j][k] += dp[i][j][k]) %= mod;
            }
        }
    }

    ll fact[101] = {};

    fact[0] = 1;
    for (int i = 1; i <= 100; ++i) fact[i] = (ll)i * fact[i - 1], fact[i] %= mod;

    ll ans = 0;

    for (int i = 1; i <= n; ++i) ans += (ll)dp[n][i][k] * fact[i], ans %= mod;

    cout << ans << endl;
}



Measured memory_bytes: 5888
def judge(s):
  if len(s) % 2 == 0:
    return False
  l, r = 0, len(s) - 1
  while r > l:
    if s[l] != s[r]:
      return False
    l += 1
    r -= 1
  l, r = 0, (len(s) - 1) // 2 - 1
  while r > l:
    if s[l] != s[r]:
      return False
    l += 1
    r -= 1
  l, r = (len(s) + 1) // 2, len(s) - 1
  while r > l:
    if s[l] != s[r]:
      return False
    l += 1
    r -= 1
  return True
 
import sys
input = sys.stdin.readline().rstrip()
print('Yes' if judge(input) else 'No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);

using ll = long long;
using namespace std;
using ld = long double;
const int MAXN=1e6 + 5;



int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    ll n,a ;
    cin >> a;
    n=(a*(a+1))/2;
    cout << n-a;
    return 0;
}



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

int main()
{
  int64_t a, b;
  cin >> a >> b;
  for (int i = 1; i <= b; i++)
  {
    if (a * i % b == 0)
    {
      cout << a * i << endl;
      break;
    }
  }
}


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

using namespace std;

using ll = long long;

int main(){
   ll n, k;
   cin >> n >> k;
   vector<ll> v(n);
   for(ll i = 0; i < n; ++i){
        cin >> v[i];
   }
   sort(v.begin(), v.end(), greater<ll>());
   cout << accumulate(v.begin(), v.begin() + k, 0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int A[3][3];
    vector<vector<bool>> field(3, vector<bool>(3));
    int n;

    REP(i, 3){
        REP(j, 3){
            cin >> A[i][j];
        }
    }
    cin >> n;
    int b[n];
    map<int, int> mp;

    REP(i, n){
        cin >> b[i];
        mp[b[i]] = 1;
    }

    REP(i, 3){
        REP(j, 3){
            if(mp[A[i][j]] != 0){
                field[i][j] = true;
            }
        }
    }

    bool flag = false;
    if(field[0][0] == true && field[1][1] == true && field[2][2] == true){
        flag = true;
    }
    if(field[0][2] == true && field[1][1] == true && field[2][0] == true){
        flag = true;
    }

    REP(i, 3){
        if(field[i][0] == true && field[i][1] == true && field[i][2] == true){
            flag = true;
        }
        if(field[0][i] == true && field[1][i] == true && field[2][i] == true){
            flag = true;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

const int N = 510;
typedef std::pair <int, int> pii;

int x[N], a[N * N];
pii p[N];

void no(){
	puts("No");
	exit(0);
}

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &x[i]);
		a[x[i]] = i;
		p[i] = {x[i], i};
	}
	std::sort(p + 1, p + n + 1);
	std::set <int> set;
	for (int i = 1; i <= n * n; ++ i){
		if (!a[i]) set.insert(i);
	}
	for (int i = 1; i <= n; ++ i){
		for (int j = 1; j < p[i].second; ++ j){
			int sit = *(set.begin());
			if (sit > p[i].first) no();
			a[sit] = p[i].second;
			set.erase(sit);
		}
	}
	for (int i = n; i >= 1; -- i){
		for (int j = p[i].second + 1; j <= n; ++ j){
			int sit = *(-- set.end());
			if (sit < p[i].first) no();
			a[sit] = p[i].second;
			set.erase(sit);
		}
	}
	puts("Yes");
	for (int i = 1; i <= n * n; ++ i){
		printf("%d%c", a[i], " \n"[i == n * n]);
	}
	return 0;
}

Measured memory_bytes: 13824
#include<bits/stdc++.h>
using namespace std;
int main() {
  char s[26],t[26];
  string S,T;
  cin>>S>>T;
  
  int count=1;
  s[0]=S[0];
  S[0]='0';
  bool flag;
  for(int i=1;i<S.size();i++){
    flag=true;
    for(int j=0;j<count;j++){
    	if(s[j]==S[i]){
          S[i]='0'+j;
          flag=false;
        }
    }
    if(flag){
      s[count]=S[i];
      S[i]='0'+count;
      count++;
    }
  }
  
  count=1;
  t[0]=T[0];
  T[0]='0';
  for(int i=1;i<T.size();i++){
    flag=true;
    for(int j=0;j<count;j++){
    	if(t[j]==T[i]){
          T[i]='0'+j;
          flag=false;
        }
    }
    if(flag){
      t[count]=T[i];
      T[i]='0'+count;
      count++;
    }
  }
  
  if(S==T){
  	cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

ll dp[100];

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) break;
        REP(i, 100) dp[i] = 0;
        dp[0] = 1;

        FOR(i, 1, n + 1){
            dp[i] += dp[i - 1];
            if(i > 1) dp[i] += dp[i - 2];
            if(i > 2) dp[i] += dp[i - 3];
        }
        cout << (dp[n] - 1) / 3650 + 1 << endl; // 1日10種類*365日=3650種類試せる
    }
}


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;int*t,n,m,d,i,s[99999];main(){for(;cin>>d>>n>>m;cout<<i<<'\n'){for(s[i=n]=d;--i;)cin>>s[i];for(sort(s,s+n);m--;t=upper_bound(s,s+n,d),i+=min(d-*--t,*t-d))cin>>d;}}

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

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

  if(n%3 == 0){
    cout << n / 3;
  }
  else{
    cout << n / 3;
  }
}


Measured memory_bytes: 3568
/*
 Templatka c++ Kacper Fis																							   																											   //
*/

#include <iostream>
#include <cstdio>
#include <limits>
#include <cstdlib>
#include <utility>
#include <iterator>
#include <bitset>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <time.h>
#include <iomanip>
#include <sstream>
#include <bits/stdc++.h>

using namespace std;

const int INF = 1000000001;
const float PI = 3.14;
typedef long long LL;

typedef vector<int> vi;
typedef list<int> li;
typedef queue<int> qi;
typedef pair<int,int> ii;
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra

list<int>::iterator it;
list<int>::iterator it1;
vector<int>::iterator it2;
vector<int>::iterator it3;
set<int>::iterator it4;
map<string, int>::iterator it5;
vector<ii>::iterator iter;

#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

double tab[1005];

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{ios_base::sync_with_stdio(false); cin.tie(NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int counter = 0;
	double n, m;
	cin >> n >> m;
	for(int i = 0; i < n;i++){
		cin >> tab[i];
		counter += tab[i];
	}
	
	int licznik = 0;
	for(int i = 0; i < n; i++){
		if(4*m*tab[i] >= counter){
			licznik++;
		}
	}

	
	//cout << "current licznik: " << licznik << endl;
	if(licznik >= m){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
signed main(){
  ll m,n;
  cin >> m >> n;
  cout << modpow(m,n,MOD)<<endl;
}



Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int main(void){
    int a, b, c;
    cin >> a >> b >> c;

    int count = 0;
    if(a == b){
        count++;
    }
    if(a == c){
        count++;
    }
    if(b == c){
        count++;
    }

    if(count == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

class E
{
	static long[] Read() => Console.ReadLine().Split().Select(long.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var a = Read().OrderBy(x => x).ToArray();
		var f = Read().OrderBy(x => -x).ToArray();

		Console.WriteLine(First(0, a.Last() * f[0], m => a.Zip(f, (x, y) => Math.Max(0, x - m / y)).Sum() <= h[1]));
	}

	static long First(long l, long r, Func<long, bool> f)
	{
		long m;
		while (l < r) if (f(m = l + (r - l - 1) / 2)) r = m; else l = m + 1;
		return r;
	}
}


Measured memory_bytes: 48520
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



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

	ll n, d;
	cin >> n >> d;
	vector<ll> x(n), y(n);
	ll ans = 0;
	rep(i, n)
	{
		cin >> x[i] >> y[i];
		if (x[i] * x[i] + y[i] * y[i] <= d * d)
			ans++;
	}
	cout << ans << endl;





	return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


// ABC075B - Minesweeper
int main(){
  int H, W; // 1 <= N <= 50
  cin >> H >> W;
  VECTOR_DIM2(char, data, H + 2, W + 2, 0);
  for (int i = 1; i <= H; ++i) {
    string s;
    cin >> s;
    for (int j = 1; j <= W; ++j) {
      data[i][j] = s[j-1];
    }
  }
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (data[i][j] == '#') {
        continue;
      }
      int num = 0;
      for (int ki = i-1; ki <= i+1; ki++) {
        for (int kj = j-1;kj <=j+1;kj++) {
          if (data[ki][kj] == '#') {
            ++num;
          }
        }
      }
      data[i][j] = '0' + (char)num;
    }
  }
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cout << data[i][j];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int[][] arr = input(n,n);
		long td[][] = new long[n][ (1<<22)+1]; 
		for(long[] key :td)Arrays.fill(key, -1);
		long ans = find(arr , 0 , 0 , td);
		System.out.println(ans);
	}
static long mod = 1000000007; 
	private static long find(int[][] arr, int index, int allocated , long [][] td) {
		if(index==arr.length) {
			return 1 ;
		}
		if(td[index][allocated]!=-1)return td[index][allocated];

		int n = arr.length ;
		long ans = 0 ;
		for(int i = 0 ; i < n; i++) {
			if(arr[index][i]==0 ||( (allocated & (1<<i))==(1<<i) ))continue;
			ans = ans + find(arr , index +1 , allocated | (1<<i)  , td);
			ans %=mod;
		}
		td[index][allocated] = ans%mod;
		return ans;
	}

	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

	public static int[][] input(int n, int m) throws Exception {

		int[][] arr = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {

				arr[i][j] = sc.nextInt();
			}
		}
		return arr;
	}

}


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

int main() {
  int N,Y;
  cin >> N >> Y;
  int res10000 = -1;
  int res5000 = -1;
  int res1000 = -1;
  
  for(int a = 0;a<=N;a++){
    for(int b = 0;b<=N-a;b++){
      int c = N - a - b;
      if(10000*a + 5000*b + 1000*c == Y){
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
  
}

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

int main(void){
		int n,m;
		int a[1001];

		scanf("%d",&n);
		scanf("%d",&m);

		for(int i =0;i<n;i++){
			scanf("%d",&a[i]);
		}
		int num = 0;
		for(int j =0;j<n;j++){
			num +=a[j];
		}
		int tmp = 0;
		for (int i=0; i<n; ++i) {
				for (int j=i+1; j<n; ++j) {
					if (a[i] < a[j]) {
						tmp =  a[i];
						a[i] = a[j];
						a[j] = tmp;
		}
	}
}

		int m1 = num/(4*m);
		int m2 = num%(4*m);
		if(m2 !=0){
			m1 = m1+1;
		}
		if(m1 > a[m-1]){
			puts("No");
		}
		else{
			puts("Yes");
		}

/*
		printf("%d %d %d %f %d\n",n,m,num,m1,a[m-1]);
		for(int i = 0;i<n;i++){
		printf("%d\n",a[i]);
	}
*/


		return 0;
}


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

ll gcd(ll a,ll b){
  if(a<b) return gcd(b,a);
  if(b==0) return a;
  else return gcd(a%b,b);
}

int main(){
  ll a,b;
  cin>>a>>b;
  ll x=gcd(a,b);
  cout<<a*b/x<<endl;
}



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

int digit_max_func( int num );

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

    int digit_max;
    int digit_min;

    int cnt = 0;

    for (int A = 1; A <= N; A++){
        digit_max = digit_max_func(A);
        digit_min = A % 10;

        if (digit_min != 0){
            if (digit_min * 10 + digit_max <= N){
                cnt = cnt + 1; // 間0桁

                if (digit_min * 100 + 90 + digit_max <= N){
                    cnt = cnt + 10; // 間1桁全部

                    if (digit_min * 1000 + 990 + digit_max <= N){
                        cnt = cnt + 100; // 間2桁全部

                        if (digit_min * 10000 + 9990 + digit_max <= N){
                            cnt = cnt + 1000; // 間3桁全部

                            // if (digit_max_func(N) == 1){
                                for (int i = 0; i <= 9999; i++){ //間4桁
                                    if (digit_min * 100000 + i * 10 + digit_max <= N){
                                    cnt = cnt + 1;
                                    }else{
                                        break;
                                    }
                                } 
                            // }                           
                            
                        }else{ //間3桁どこまでなら入るか探索
                            for (int i = 0; i <= 999; i++){
                                if (digit_min * 10000 + i * 10 + digit_max <= N){
                                cnt = cnt + 1;
                                }else{
                                   break;
                                }
                            }
                        }

                    }else{ //間2桁どこまでなら入るか探索
                        for (int i = 0; i <= 99; i++){
                            if (digit_min * 1000 + i * 10 + digit_max <= N){
                            cnt = cnt + 1;
                            }else{
                                break;
                            }
                        }
                    }

                }else{ //間1桁どこまでなら入るか探索
                    for (int i = 0; i <= 9; i++){
                        if (digit_min * 100 + i * 10 + digit_max <= N){
                            cnt = cnt + 1;
                        }else{
                             break;
                        }
                    }
                }
            }




        }

        if (digit_min == digit_max) cnt++; //1桁の数が有り得る

    }

    cout << cnt << endl;

    return 0;
}

int digit_max_func( int num )
{
    int count = 0;
    while( num >= 10 ) {
        num = num / 10;
    }
     return num;
}

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

int selectionSort (int A[], int n) {

    int i, j, v, count = 0, minj;

    for (i = 0; i < n; i++) {

        minj = i;

        for (j = i; j < n; j++) {

            if (A[j] < A[minj]) {

                minj = j;

            }

        }

        if (i != minj) {

            v = A[i];
            A[i] = A[minj];
            A[minj] = v;

            count += 1;

        }

    }

    return count;

}

int main () {
  
    int i, n, count, A[100];
  
    cin >> n;
  
    for (i = 0; i < n; i++) {
  
        cin >> A[i];
  
    }
 
    count = selectionSort (A, n);
 
    for (i = 0; i < n; i++) {
 
        cout << A[i];
 
        if (i < n - 1) {
 
            cout << " ";
 
        }
 
    }
 
    cout << endl;
    cout << count << endl;
 
    return 0;
 
}

Measured memory_bytes: 3100
import java.util.*;

public class Main {

    public static int sum(int n){
        return (1+n)*n/2;
    }

    public static String conv(String in){
        ArrayList<String> list
            = new ArrayList<String>();

        for (int i = 0; i < in.length(); i++) {
            if (in.charAt(i) == 'B') {
                if (!list.isEmpty()) {
                    list.remove(list.size() - 1);
                }
            } else {
                list.add(""+in.charAt(i));
            }
        }

        String result = "";
        for (String s : list) {
            result += s;
        }

        return result;
    }
    
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
		System.out.println(conv(a));
	}
}


Measured memory_bytes: 9300
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define ET cout << "\n"
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef bbq
#define debug(...) {\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}
#define DB(a,s,e) {for(int _i=s;_i<e;++_i) cerr << a[_i] << " ";cerr << "\n";}
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T,typename ...S> void _do(T &&x,S &&...t){cerr<<x<<", ";_do(t...);}
template<typename a,typename b> ostream& operator << (ostream &s,const pair<a,b> &p){return s<<"("<<p.X<<","<<p.Y<<")";}
#else
#define debug(...)
#define DB(a,s,e)
#endif

int arr[105];
vector<int> ans;

int main()
{
    IOS();
    int n,m,cnt,flag=0;
    cin >> n >> m,cnt=n&1;
    for(int i=0;i<m;++i)
        cin >> arr[i],cnt+=arr[i]&1;
    if(cnt>=3)
        return cout << "Impossible\n",0;
    if(n==1)
        return cout << "1\n1\n1\n",0;
    if(m==1)
        return cout << arr[0] << "\n2\n1 " << n-1 << "\n",0;
    for(int i=0;i<m;++i)
        if(arr[i]&1)
            if(!flag)
                flag=1,swap(arr[i],arr[0]);
            else
                swap(arr[i],arr[m-1]);
    ans.pb(arr[0]+1);
    for(int i=1;i+1<m;++i)
        ans.pb(arr[i]);
    if(arr[m-1]>1)
        ans.pb(arr[m-1]-1);
    for(int i=0;i<m;++i)
        cout << arr[i] << " \n"[i+1==m];
    cout << SZ(ans) << "\n";
    for(int i=0;i<SZ(ans);++i)
        cout << ans[i] << " \n"[i+1==SZ(ans)];
}

Measured memory_bytes: 256
x, y = map(int, input().split())
l1 = [1, 3, 5, 7, 8, 10, 12]
l2 = [4, 6, 9, 11]
if (x in l1 and y in l1) or (x in l2 and y in l2) or (x == 2 and y == 2):
  print('Yes')
else:
  print('No')

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

ll mod = 1000000007;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1
// Fact( n, modulo ) return n! % modulo {{{
// Fact(orial) = n! % mod ( natural number )
long long unsigned int Fact( long long unsigned int n, long long unsigned int modulo = mod){
    long long unsigned int Upper = 1;
    for(long long unsigned int i = 0; i < n; i++){
        Upper = Upper * (n-i) % modulo;
    }
    return Upper;
}
// }}}

int main() {

    int n;
    Scd(n);
    printf ("%d\n", Fact(n));

    return 0;
}



Measured memory_bytes: 256
import math
n = int(input())

round = lambda x:(x*1000*2+1)//2/1000

for i in range(n):
    x1,y1,x2,y2,x3,y3 = [ float(s) for s in input().split() ]
    r1 = x1*x1 + y1*y1
    r2 = x2*x2 + y2*y2
    r3 = x3*x3 + y3*y3
    x1_x2 = x1 - x2
    y1_y2 = y1 - y2
    x1_x3 = x1 - x3
    y1_y3 = y1 - y3
    r1_r2 = r1 - r2
    r1_r3 = r1 - r3
    if x1_x2 == 0:
        py = r1_r2 / (2*y1_y2)
        px = (r1_r3 - 2*y1_y3*py) / (2*x1_x3)
    else:
        py = (r1_r2 * x1_x3 - r1_r3 * x1_x2) / (2*(y1_y2 * x1_x3 - y1_y3 * x1_x2))
        px = (r1_r2 - 2*y1_y2*py) / (2*x1_x2)
    r = math.sqrt((x1-px)**2 + (y1-py)**2)
    print('{:.3f}'.format(0+px),'{:.3f}'.format(0+py),'{:.3f}'.format(0+round(r)))



Measured memory_bytes: 5700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second

typedef long long ll;

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

void solve1()
{
    ll n, x, m; cin >> n >> x >> m;
    ll tmp = x;
    ll sum = 0;
    set<ll> s;
    ll res = x;
    ll lo = 0;
    ll loc = 0;
    vector<ll> a;
    while(loc < n) {
        if(s.find(x) != s.end()) {
            res = x;
            break;
        }
        a.push_back(x);
        sum += x;
        s.insert(x);
        x *= x;
        x %= m;
        loc ++;
    }

    ll restn = n - loc;
    ll lom = 0;
    x = tmp;
    lo = sum;
    while(x != res) {
        lo -= x;
        x *= x;
        x %= m;
        lom ++;
    }

    loc -= lom;

    sum += floor(1.0*restn / loc)*lo;
    ll resm = restn%loc;
    ll by = min(lom + resm, (ll)a.size());
    for (int i = lom; i < by; i++)
    {
        sum += a[i];
    }


    cout << sum << endl;
}

int main()
{
    solve1();
}


Measured memory_bytes: 5952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n;
    cin >> n;
    ll ans = n*(n+1)*(n+2)/6;
    rep(i, n-1) {
        ll u, v;
        cin >> u >> v;
        if (u>v) swap(u, v);
        ans -= (u)*(n-v+1);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int n,k,ans,v[55];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>v[i];
	for(int i=0;i<n;i++)
		for(int j=i;j<=n;j++){
			if(i+n-j>min(n,k) )continue;
			int sum=0,x=k-(i+n-j);
			multiset<int> s;
			for(int p=0;p<i;p++){
				sum+=v[p];
				if(v[p]<0)s.insert(v[p]);
			}
			for(int p=j;p<n;p++){
				sum+=v[p];
				if(v[p]<0)s.insert(v[p]);
			}
			for(multiset<int>::iterator it=s.begin();it!=s.end() and (x--)>0;it++)
				sum-=*it;
			ans=max(ans,sum);
		}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
uses crt;
var kq,n : int64;
begin
    readln(n);
    if (n mod 2 <> 0) or (n<=4) then begin writeln(0); exit; end;
    n := n div 2;
    while(n>0) do begin
    	kq := kq + n div 5;
        n := n div 5;
    end;
    writeln(kq);
end.
    	



Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    W = [input().strip() for _ in range(N)]
    m = {}
    for i in range(N-1):
        if W[i][-1] != W[i+1][0] or W[i+1] in m:
            print("No")
            return
        m[W[i]] = True
    print("Yes")

main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a[100005][5];
int dp[100005][5];
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i][1]>>a[i][2]>>a[i][3];
        dp[i][1]=dp[i][2]=dp[i][3]=INT_MIN;
    }
    dp[1][1]=a[1][1],dp[1][2]=a[1][2],dp[1][3]=a[1][3];
    for(int i=2; i<=n; i++)
    {
        dp[i][1]=max(dp[i][1],a[i][1]+max(dp[i-1][2],dp[i-1][3]));
        dp[i][2]=max(dp[i][2],a[i][2]+max(dp[i-1][1],dp[i-1][3]));
        dp[i][3]=max(dp[i][3],a[i][3]+max(dp[i-1][1],dp[i-1][2]));
        //cout<<dp[i][1]<<" "<<dp[i][2]<<" "<<dp[i][3]<<endl;
    }
    int ans=max(dp[n][1],max(dp[n][2],dp[n][3]));
    cout<<ans<<endl;

}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s;
  ll k;
  cin >> s >> k;
  int n=s.size();
  int cnt=0;
  while(k>0){
    if(cnt==n-1){
      k %= 26;
      s[cnt] += k-26;
      if(s[cnt]<'a'){ s[cnt]+=26; }
      break;
    }
    if(s[cnt]=='a'){cnt++;continue;}
    if((26-(s[cnt]-'a'))<=k){
      k -= (int)(26-(s[cnt]-'a'));
      s[cnt] = 'a';
      cnt++;
      continue;
    }
    cnt++;
    continue;
  }
  
  
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 512
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

class UnionFind:

    def __init__(self,n):
        self.n = n
        self.root=[-1]*(n+1)
        self.rank=[0]*(n+1)

    def findRoot(self,x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.findRoot(self.root[x])
            return self.root[x]

    def unite(self,x,y):
        x=self.findRoot(x)
        y=self.findRoot(y)
        if x==y:
            return
        if self.rank[x] > self.rank[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def isSameGroup(self,x,y):
        return self.findRoot(x)==self.findRoot(y)

    def count(self,x):
        return -self.root[self.findRoot(x)]


def main():
    N,M=i_map()
    A = []
    B=[]

    for i in range(0,M):
        tmp1,tmp2 = i_map()
        A.append(tmp1-1)
        B.append(tmp2-1)

    u = UnionFind(N)

    for i in range(0,M):
        u.unite(A[i],B[i])

    max = 0
    for i in range(0,N):
        if(max<=u.count(i)):
            max = u.count(i)

    print(max)

    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 29576