akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
bool B[50][50] = {};

bool bfs(int N,int a, int b) {
	queue<int> q;
	q.push(a);
	VB p(N, true);
	p[a] = false;
	while (!q.empty()) {
		int x = q.front();
		if (x == b) return true;
		q.pop();
		
		REP(i,N){
			if ((B[x][i]) && (p[i])) {
				p[i] = false;
				q.push(i);
			}
		}
	}
	return false;
}



int main() {
	int N, M;
	cin >> N >> M;
	VP R(M);
	REP(i, M) {
		cin >> R[i].first >> R[i].second;
		B[R[i].first - 1][R[i].second - 1] = B[R[i].second - 1][R[i].first - 1] = true;
	}
	int c = 0;
	REP(i, M) {
		B[R[i].first - 1][R[i].second - 1] = B[R[i].second - 1][R[i].first - 1] = false;
		REP(j, N) {
			FOR(k, j + 1, N) {
				if (!bfs(N, j, k)){
					c++;
					goto next;
				
				}
			}
		}
	next:
		B[R[i].first - 1][R[i].second - 1] = B[R[i].second - 1][R[i].first - 1] = true;
	}
	cout << c << endl;
	
	return 0;
}

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

typedef long long ll;
using namespace std;


int main(void) {
   ll N,D;
   cin>>N>>D;
   ll D2 = 2*D+1;
   if (N%D2) cout<<(N/D2)+1<<endl;
   else cout<<(N/D2)<<endl;






   return 0;
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Array.new(n, nil)
i = 0
t = 0
while b[i].nil? do
  b[i] = t
  t += 1
  i = a[i] - 1
end
head_len = b[i]
loop_len = t - head_len
#puts [head_len, loop_len].join(" ")
ans = nil
if k < head_len
  ans = b.index(k) + 1
else
  ans = b.index((k - head_len) % loop_len + head_len) + 1
end
puts ans


Measured memory_bytes: 28844
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <complex>
#define ll long long
using namespace std;

int main() {
	int a[6], k, ans;
	ans = 0;
	for (int i = 0; i < 5; i++)cin >> a[i];
	cin >> k;
	for (int i = 0; i < 5; i++)
		for (int j = 0; j < 5; j++) {
			if (i == j)continue;
			if (abs(a[i] - a[j]) > k) ans++;
		}
	if (ans > 0)cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N;
	cin >> N;
	vector<ll> SA(N+1);
	SA.at(0) = 0;
	rep(i, N) {
		ll A;
		cin >> A;

		SA.at(i + 1) = SA.at(i) + A;

	}
	map<ll, ll> Q;
	rep(i, N+1) {
		if (Q.count(SA.at(i))) {
			Q.at(SA.at(i))++;
		}
		else {
			Q[SA.at(i)] = 1;
		}
	}
	ll an = 0;
	for (auto p : Q) {
		
		auto v = p.second;
		an += v * (v - 1) / 2;
	}
	cout << an << endl;

}


Measured memory_bytes: 17012
#include  <stdio.h>

int main(void)
{     
	int x,y;     
	while(1)
	{         
	   scanf("%d %d",&x ,&y);        
	if( x == 0 && y == 0 ) 
		break;     
	if(x < y)
	{        
	printf("%d %d\n",x ,y);     
	}
	else 
	{            
		printf("%d %d\n",y ,x);     
	}     
	}
		return 0; 
}

Measured memory_bytes: 600
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    c = list(input())
    r_cnt = 0
    for i in range(n):
        if c[i] == "R":
            r_cnt+=1
    w_cnt = n-r_cnt
    change = 0
    for i in range(r_cnt):
        if c[i] != "R":
            change+=1
    ans = change
    print(ans)

Measured memory_bytes: 71756
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
    char a[1019999];
int main()
{

    scanf("%s",a);
    int len = strlen(a);
    int sum = len%2;
    //cout<<sum<<endl;
    if(!sum)
    {
        if(a[0]==a[len-1])
            printf("First\n");
        else printf("Second\n");
    }
    else
    {
        if(a[0]==a[len-1])
            printf("Second\n");
        else printf("First\n");
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    string t = "AKIHABARA";
    for (int i = 0; i < t.length(); ++i) {
        if (i >= s.length()) {
            s += t[i];
            if (t[i] != 'A') {
                cout << "NO";
                return 0;
            }
        }
        if (t[i] == 'A' && s[i] != 'A') {
            s.insert(s.begin() + i, 'A');
        }
        if (s[i] != t[i]) {
            cout << "NO";
            return 0;
        }
    }
    if (s == t) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> com(N,vector<int>(N,-1));
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        for (int j = 0; j < A; j++){
            int x,y;
            cin >> x >> y;
            com.at(i).at(x-1) = y;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < pow(2,N);i++){
        vector <int> X(N);
        int k = 0;
        int a;
        a = i;
        while (a != 0){
            X.at(k) = a%2;
            a = a/2;
            k++; 
        }
        reverse(X.begin(), X.end());
        bool ok = true;
        for (int j = 0; j< N; j++){
            if(X.at(j) == 1){
                for (int l = 0;l < N; l++){
                    if(com.at(j).at(l) == -1){
                        continue;
                    }
                    else{
                        if(com.at(j).at(l) != X.at(l)){
                            ok = false;
                        }
                    }
                }
            }
        }
        if(ok){
            int sum = 0;
            for (int m = 0; m < N; m++){
                sum += X.at(m);
            }
            ans = max(ans,sum);
        }
    }

    cout << ans << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;

int main() {
	cin >> n;
	
	cout << (n % 2 == 0 ? n : 2 * n) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n = 0;
	scanf("%d",&n);
	
	int modulo = n%10;
	int bagi = n/10;
	
	if(modulo==9 || bagi==9){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    ll N;
    cin>>N;
    unordered_map<ll, int> m;
    REP(i,N){
        ll a;
        cin>>a;
        auto it=m.find(a);
        if(it==m.end()){
            // insert
            m.insert(make_pair(a,0));
        }else{
            // delete
            m.erase(a);
        }
    }
    cout<<m.size()<<endl;
    return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,i,n,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a);
		ans+=a-1;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int n, m;
  scanf("%d %d", &n, &m);
  if (n - m < -1 || n - m > 1)
  {
    puts("0");
    return 0;
  }
  long long ans = 1;
  for (int i = 1; i <= n; ++i)
  {
    ans = (ans * i) % 1000000007;
  }
  for (int i = 1; i <= m; ++i)
  {
    ans = (ans * i) % 1000000007;
  }
  if (n == m)
  {
    ans = (ans * 2) % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include<math.h>
int main(void){
	double x1,x2,y1,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%lf\n",sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
	return 0;
}


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

int main(){
	string S;
	cin>>S;
	
	int num[26]={0};//あれば１、なければ０
	
	int count=0;
	for(int i='a';i<='z';i++){
		for(int j=0;j<S.length();j++){
			if(S[j]==i){
				num[count]=1;
				//cout<<S[j]<<endl;
			}
		}
		count++;
	}
	
	/*for(int i=0;i<25;i++){
		cout<<i<<' '<<num[i]<<endl;
	}*/
	
	for(int i=0;i<26;i++){
		if(num[i]==0){
			cout<<(char)('a'+i)<<endl;
			return 0;
		}
	}
	
	cout<<"None"<<endl;
	return 0;
	
}

Measured memory_bytes: 512
# 総価からの最小誤差を求める。
n, l = map(int, input().split())
s = []
# リンゴの味
for i in range(1, n+1):
    s.append(l+i-1)
# リンゴの最小誤差を求める絶対値です。
a = 10**19
# リンゴの最小誤差の変数です。
h = 0
for i in range(n):
    # 最小誤差を判定します。
    if a > abs(s[i]):
        a = abs(s[i])
        h = s[i]
# 総価から最小誤差を引いた味です。
print(sum(s)-h)


Measured memory_bytes: 9096
(let* ((dmax (read))
       (c (make-array '(27)))
       (s (make-array (list (1+ dmax) 27)))
       (score 0)
       (last (make-array '(27) :initial-element 0)))
  ; read
  (loop :for i :from 1 :to 26
        :do (setf (aref c i) (read)))
  (loop :for d :from 1 :to dmax
        :do (loop :for i :from 1 :to 26
                  :do (setf (aref s d i) (read))))
  ;
  (defun delta (x d)
    (- (aref s d x)
       (loop :for i :from 1 :to 26
             :sum (* (aref c i) (- d (if (= i x) d (aref last i)))))))

  ;;
  (loop :for d :from 1 :to dmax
        :do (let ((cand-c 1)
                  (cand-v (delta 1 d)))
              (loop :for i :from 2 :to 26
                    :do (let ((v (delta i d)))
                          (when (> v cand-v)
                            (setf cand-c i)
                            (setf cand-v v))))
              (setf (aref last cand-c) d)
              (incf score cand-v)
              ;(format t "SCORE: ~A~%" score)
              (format t "~A~%" cand-c)))
  ;(format t "SCORE: ~A~%" score)
  t)


Measured memory_bytes: 29672
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    int min = a;
    int max = b;
    if(a > b) {
        min = b;
        max = a;
    }
    rep(i, 0, max) { cout << min; }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    int main() {
      string S;
      cin >> S;
      if ("SUN" == S)
      {
        cout << "7" << endl;
      }
      else if ("MON" == S)
      {
        cout << "6" << endl;
      }
      else if ("TUE" == S)
      {
        cout << "5" << endl;
      }
      else if ("WED" == S)
      {
        cout << "4" << endl;
      }
      else if ("THU" == S)
      {
        cout << "3" << endl;
      }
      else if ("FRI" == S)
      {
        cout << "2" << endl;
      }
      else
      {
        cout << "1" << endl;
      }
    }

Measured memory_bytes: 3600
use rand::Rng;
fn main() {
    let start=std::time::Instant::now();
    proconio::input! {
        d: usize,
        c: [i64;26],
        s: [[i64;26];d],
    }
    let mut t=vec![0;d];
    let mut last=[0;26];
    for (i,t) in t.iter_mut().enumerate() {
        let mut m=std::i64::MIN;
        let mut k=0;
        for j in 0..26 {
            let p=last[j];
            let mut v=0;
            v+=s[i][j];
            last[j]=i+1;
            for (&c,&last) in c.iter().zip(last.iter()) {
                v-=c*(i+1-last)as i64;
            }
            if m<v {
                m=v;
                k=j;
            }
            last[j]=p;
        }
        last[k]=i+1;
        *t=k;
    }
    let mut v=vec![0;d];
    f(&c,&s,&t,0,&mut v);
    let mut rng = rand::thread_rng();
    while start.elapsed().as_secs_f64()<1.95 {
        let r: usize=rng.gen_range(0, d*26);
        let i=r/26;
        let q=r%26;
        let p=t[i];
        t[i]=q;
        let mut w=v.clone();
        f(&c,&s,&t,i,&mut w);
        if w[d-1]>v[d-1] {
            v=w;
        }
        else {
            t[i]=p;
        }
    }
    for t in t {
        println!("{}",t+1);
    }
}
fn f(c: &Vec<i64>, s: &Vec<Vec<i64>>, t: &Vec<usize>, b: usize, w: &mut Vec<i64>) -> i64 {
    let mut last=[0;26];
    let mut v=if b>0 {w[b-1]} else {0};
    for (j,(&t,w)) in t[b..].iter().zip(w[b..].iter_mut()).enumerate() {
        let i=j+b;
        v+=s[i][t];
        last[t]=i+1;
        for (&c,&last) in c.iter().zip(last.iter()) {
            v-=c*(i+1-last)as i64;
        }
        *w=v;
    }
    v
}

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str() // int to string
#define boost ios_base::sync_with_stdio(false)
#define deb(x) cout << #x" = " << x << '\n';

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n;

int main() {
//    freopen("input.in", "r", stdin);
	scanf("%d", &n);
	int re = 0;
	fr(i, 1, n+1) {
		re += i;
	}
	printf("%d\n", re);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = 1;
        while((m+1) * (m+1) <= n) {
            m++;
        }
        for(;m>=1;m--) {
            if(n % m == 0) {
                long res = m + (n / m) - 2;
                System.out.println(res);
                return;
            }
        }

    }
}


Measured memory_bytes: 23892
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
int a[MAXN];

int main() {
    int N;
    while (~scanf("%d", &N)) {
          int sum = 0, prev = 0;
          for (int i = 1; i <= N; i++) {
              scanf("%d", &a[i]);
              sum += abs(prev - a[i]);
              prev = a[i];
          }
          sum += abs(prev);
          a[N + 1] = 0;
          for (int i = 1; i <= N; i++) {
              int pre_dis = abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]);
              printf("%d\n", sum - pre_dis + abs(a[i - 1] - a[i + 1]));
          }
    }
    return 0;
}


Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
a, b, i = 0, 0, 0
while i < N-1:
  if A[i] == A[i+1]:
    if a == 0 and b == 0:
      a = max(a, A[i])
      i += 2
    elif a != 0 and b == 0:
      b = max(b, A[i])
      i += 2
    else:
      i += 1
  else:
    i += 1
print(a*b)

Measured memory_bytes: 14636
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;
#define INF 1<<20


struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
for (int i = 0;i < graph[pos].size();i++) {
	int to = graph[pos][i].to;
	int cost = graph[pos][i].cost;
	if (d[pos] + cost < d[to]) {
		d[to] = d[pos] + cost;
		q.push(Node(to, d[to]));
	}

}
	}
	cout << d[TO] << endl;
}
int partition(int A[], int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[], int n, int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >= 0) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n, int* v, int* ww) {
	int W[101][10001];
	for (int j = 0;j <= w;j++) {
		W[0][j] = 0;
	}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++) {
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n + 1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n + 1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x > 2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int gnc(int a, int b) {
	while (b%a != 0) {
		if (a > b) swap(a, b);
		else {
			b = b%a;
		}
	}
	return a;
}
int calc(int a, long long int b, long long int m) {
	if (b == 0) return 1;
	else if (b % 2 == 0) {
		long long int d = calc(a, b / 2, m);
		return (d*d) % m;
	}
	else {
		long long int d = calc(a, b -1, m);
		return (d*a) % m;
	}
}
vector<pair<int, int> > b(100000);
vector<int> src(100000);

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A*B >= C*D) {
		cout << A*B << endl;
	}
	else {
		cout << C*D << endl;
	}
	
	}




Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final String S = sc.next();
        sc.close();

        if (Character.isUpperCase(S.charAt(0))) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
        return;
    }
}

Measured memory_bytes: 35644
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	string target = "keyence";
	string s; cin >> s;
	int n = s.length(), diff = n - target.length();
	if (diff >= 0) {
		for (int i = 0; i + diff <= n; ++i) {
			string test = s.substr(0, i) + s.substr(i + diff, n);
			if (test == target) {
				cout << "YES\n";
				return 0;
			}
		}
	}
	cout << "NO\n";
}

Measured memory_bytes: 256
/// {{{
#include "bits/stdc++.h"
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
#define   rep(i, s, t)       for(int i = int(s); i < int(t); ++i)
using namespace std;
typedef long long i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}


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

  int cntB[200010] {};

  i64 ans = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'B') ++cntB[i];

    cntB[i] += (i-1 >= 0 ? cntB[i-1] : 0);

    if (s[i] == 'W') ans += cntB[i];
  }

  cout << ans << endl;

  return 0;
}



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

using i64 = long long;
using P = pair<i64, i64>;

i64 u = 50000;
i64 v = 25000;

void solve(long long H, long long W, std::vector<std::vector<long long>> A, std::vector<std::vector<long long>> B){
    i64 h = H, w = W;
    auto a = A;
    auto b  = B;
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(u, false)));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            i64 d = abs(a[i][j] - b[i][j]);
            if(i == 0){
                if(j == 0){
                    dp[i][j][v + d] = true;
                    dp[i][j][v - d] = true;
                }else{
                    for(int k = 0; k < u; ++k){
                        if(k - d >= 0 && dp[i][j - 1][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i][j - 1][k + d]) dp[i][j][k] = true;
                    }
                }
            }else{
                if(j == 0){
                    for(int k = 0; k < u; ++k){
                        if(k - d >= 0 && dp[i - 1][j][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i - 1][j][k + d]) dp[i][j][k] = true;
                    }
                }else{
                    for(int k = 0; k < u; ++k){
                        if(k - d >= 0 && dp[i - 1][j][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i - 1][j][k + d]) dp[i][j][k] = true;
                        if(k - d >= 0 && dp[i][j - 1][k - d]) dp[i][j][k] = true;
                        if(k + d < u && dp[i][j - 1][k + d]) dp[i][j][k] = true;
                    }
                }
            }
        }
    }
    i64 ans = 10000;
    for(i64 i = 0; i < u; ++i){
        if(dp[h - 1][w - 1][i]) ans = min(ans, abs(i - v));
    }
    cout << ans << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    std::vector<std::vector<long long>> B(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&B[i][j]);
        }
    }
    solve(H, W, std::move(A), std::move(B));
    return 0;
}


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

int main()
{
	int n;
	long int sum = 0;
	int minx, maxx;

	cin >> n;

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

		if (i == 0) {
			minx = temp;
			maxx = temp;
		}
		else {
			minx = min(minx, temp);
			maxx = max(maxx, temp);
		}

		sum += temp;
	}

	cout << minx << " " << maxx << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 3108
# coding: utf-8
A, B, C, K = map(int,input().split())
for i in range(K % 2):
    a = A
    b = B
    c = C

    A = b + c
    B = a + c
    C = a + b

    if abs(A - B) >= 10**18:
        print('Unfair')
        exit()

print(A-B)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main()
{
    int n, a[100],x=0;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 0; i < n; i++)
    {
        for (int t = 0; t < n - 1; t++)
        {
            if (a[t + 1] < a[t])
            {
                swap(a[t], a[t + 1]);
                x++;
            }
        }
    }

    for (int i = 0; i < n; i++)
        cout << a[i] << (i < n - 1 ? " " : "\n");
    
    cout << x << "\n";
}



Measured memory_bytes: 3096
#include<iostream>
#include<string>
using namespace std;
typedef struct{
  string first;
  int second;
}SI;
int main(){
  SI pa[101];
  int k=0;
  
  while(cin >> pa[k].first >> pa[k].second){
    k++;
  }

  for(int i=0;i<k-1;i++){
    for(int j=i+1;j<k;j++){
      if(pa[i].first > pa[j].first){
	  SI temp = pa[i];
	  pa[i] = pa[j];
	  pa[j] = temp;
      } else if(pa[i].first == pa[j].first && pa[i].second > pa[j].second){
	SI temp = pa[i];
	pa[i] = pa[j];
	pa[j] = temp;
      }
    }
  }

 
  cout << pa[0].first << endl << pa[0].second;
  for(int i=1;i<k;i++){
    if(pa[i-1].first == pa[i].first) cout << ' ' << pa[i].second;
    else cout << endl << pa[i].first << endl << pa[i].second;
  }
  cout << endl;
  return (0);
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define INF 1000000009
using namespace std;

vector<int> bfs(int n,vector<vector<int> >& g,int s)
{
	vector<int> d(n,INF);
	d[s]=0;
	queue<int> q;
	q.push(s);
	while(!q.empty())
	{
		int t=q.front();q.pop();
		for(int i=0;i<g[t].size();i++) if(d[g[t][i]]>d[t]+1){
			d[g[t][i]]=d[t]+1;
			q.push(g[t][i]);
		}
	}
	
	return d;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > g(n);
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--;y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	
	vector<int> d1=bfs(n,g,0);
	vector<int> d2=bfs(n,g,n-1);
	int n1=0,n2=0;
	for(int i=0;i<n;i++) if(d1[i]<=d2[i]) n1++;else n2++;
	if(n1>n2) cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	int n,i;
	unsigned int *arr;
	scanf("%d", &n);
	arr = (unsigned int*)malloc(sizeof(unsigned int)*n);
	for (i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	if (n % 2 == 0)
	{
		for (i = 0; i < n / 2; i++)
			printf("%d ", arr[n - 1 - 2 * i]);
		for (i = 0; i < n / 2; i++)
			printf("%d ", arr[2 * i]);
	}
	else
	{
		for (i = 0; i <= n / 2; i++)
			printf("%d ", arr[n - 1 - 2 * i]);
		for (i = 0; i < n / 2; i++)
			printf("%d ", arr[2 * i+1]);
	}
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int X;
  cin>>X;
  int ans=0,time=0;
  while(time*(time+1)/2<X)time++;  
  cout<<time; 
  return 0;
}

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

mi = 1
ma = N

for _ in range(M):
	a,b = map(int,input().split())
	mi = max(a,mi)
	ma = min(b,ma)

print(max(0,ma-mi+1))

#そのままでは計算量が多く通らないので、数学的な考察が必要。

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

void _130() {
    int n, x;
    int l[100];
    cin >> n >> x;
    for (int i = 0; i < n; ++i) { 
        cin >> l[i];
    }

    int d = 0;
    for (int i = 0; i < n; ++i) {
        d = d + l[i];
        // cout << d << endl;
        if (d > x) {
            cout << i + 1 << endl;
            return;
        }
    }
    cout << n + 1 << endl;
}

void _131() {
    int n, l;
    cin >> n >> l;

    int sum = (l - 1) * n + (1 + n) * n / 2;
    // cout << sum << endl;

    int taste = 0;
    int min_taste = 100;
    for (int i = 0; i < n; ++i) {
        taste = l + (i + 1) - 1;
        // cout << "taste" << taste << endl;
        if (abs(taste) < abs(min_taste))
            min_taste = taste;
        // cout << min_taste << endl;
    }
    cout << sum - min_taste << endl;
}

void _132() {
    int n;
    cin >> n;
    int p[20];
    for (int i = 0; i < n; ++i) 
        cin >> p[i];

    int count = 0;
    int second_value = 0;
    for (int i = 0; i < n - 2; ++i) {
        if ((p[i] < p[i + 1]) && (p[i + 1] < p[i + 2])){
            // cout << "1:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
        else if ((p[i] > p[i + 1]) && (p[i + 1] > p[i + 2])){
            // cout << "2:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
    }
    cout << count << endl;
}

void _133() {
    int n, d;
    cin >> n >> d;
    int x[10][10];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }

    int count = 0;
    float distance = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            distance = 0;
            for (int k = 0; k < d; ++k) {
                distance += pow(x[i][k] - x[j][k], 2);
                // cout << x[i][k] << " " << x[j][k] << " " << distance << endl;
            }
            distance = pow(distance, 0.5);
            // cout << distance << endl;

            if (abs(distance - ceil(distance)) <= 1e-6)
                count++;
        }
    }

    cout << count << endl;
}

void _134() {
    int n, d;
    cin >> n >> d;

    cout << (n + 2 * d + 1 -1) / (2 * d + 1) << endl;
}

int main()
{
    _134();
    return 0;
}



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

void solve(){
    int h, n;
    cin >> h >> n;
    vector <int> a(n);
    int sum = 0;
    for(int i=0;i<a.size();i++) {
        cin >> a[i];
        sum +=a[i];
    }
    if(sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(0);
    // freopen("a.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int main(){

	int x1, y1, x2, y2;;

	cin >> x1 >> y1 >> x2 >> y2;

	int lenx = x2 - x1;
	int leny = y2 - y1;
	int y3 = y2 + lenx;
	int x3 = x2 - leny;

	int y4 = y3 - leny;
	int x4 = x3 - lenx;

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

	return 0;
}


Measured memory_bytes: 256
"""
素数判定

エラトステネスの篩：
x^(1/2)以下の素数が既知のとき、x^(1/2)以上x以下の素数を決定するには、x以下の整数でx^(1/2)以下の素数の倍数を全て取り除けば（=篩えば）よい
"""
x = int(input())

while True:
    prime_flag = True
    for i in range(2, int(x**0.5+1)):
        if x%i == 0:
            prime_flag = False
            break
    if prime_flag:
        break
    else:
        x += 1
        
print(x)

Measured memory_bytes: 2940
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll n;
V< V< int > > edges;

ll modpow(ll m, ll p) {
    if (p == 0) return 1;
    ll tmp = modpow(m, p / 2);
    if (p & 1) return (tmp * tmp % MOD) * m % MOD;
    else return tmp * tmp % MOD;
}

ll ans = 0;
ll dfs(int i, int p) {
    ll sum = 0;  // 子のノード数
    ll tmpa = 1;  // 余事象、初期値は全て白の場合(= 1 通り)
    for (int e: edges[i]) {
        if (e == p) continue;
        ll cn = dfs(e, i);
        ll tmp = modpow(2, cn) - 1;  // 部分木の中で黒がある場合 = 全て白の余事象
        if (tmp < 0) tmp += MOD;
        tmpa += tmp;
        if (tmpa >= MOD) tmpa -= MOD;
        sum += cn;
    }

    if (edges[i].size() == 1) return 1;  // 部分木がない場合

    // 親側が黒の時
    tmpa += modpow(2, n - sum - 1) - 1;
    if (tmpa >= MOD) tmpa -= MOD;
    // 上で求めたのは頂点 i が含まれない頂点の色の決め方の個数
    // 頂点 i が含まれるのはその余事象なので
    ll tmp = modpow(2, n - 1) - tmpa;
    if (tmp < 0) tmp += MOD;
    ans += tmp;
    if (ans >= MOD) ans -= MOD;
    return sum + 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    edges.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
    }

    dfs(0, -1);
    ans = ans * modpow(modpow(2, n), MOD - 2) % MOD;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 22272
import itertools

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

permutation_list = list(itertools.permutations(range(1,N+1),N))
a = permutation_list.index(P)
b = permutation_list.index(Q)
print(abs(a-b))

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int n;
int a[100000];
std::vector<std::pair<int, int> > res;
int dfs(int i, bool inversed) {
	int ret = 0;
	if (i == n - 2) {
		// assert((a[i] < 0) != (a[i + 1] < 0));
		if ((a[i] < a[i + 1]) ^ inversed) res.push_back({a[i + 1], a[i]});
		else res.push_back({a[i], a[i + 1]});
		ret = res.back().first - res.back().second;
	} else if ((a[i] < 0) ^ inversed) {
		int index =res.size();
		res.push_back({-1, a[i]});
		int tmp = dfs(i + 1, inversed);
		ret = tmp - a[i];
		res[index].first = tmp;
	} else {
		int index = res.size();
		res.push_back({a[i], -1});
		int tmp = dfs(i + 1, !inversed);
		ret = a[i] - tmp;
		res[index].second = tmp;
	}
	return ret;
}

int main() {
	n = ri();
	for (int i = 0; i < n; i++) a[i] = ri();
	std::sort(a, a + n);
	if (a[0] > 0) {
		std::reverse(a, a + n);
	} else if (a[n - 1] < 0) {
		
	} else {
		if (n > 2) std::swap(a[0], a[n - 2]);
	}
	dfs(0, false);
	std::reverse(res.begin(), res.end());
	std::cout << res.back().first - res.back().second << std::endl;
	for (auto &i : res) {
		std::cout << i.first << " " << i.second << std::endl;
	}
	
	return 0;
}


Measured memory_bytes: 10740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define str string
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
int main() {
    fast();
 
    ll n;
    cin >> n;
    set<ll>s;
    f(i,0,n)
    {
        ll x;
        cin >>x;
        if(s.find(x)!=s.end())
        {
            s.erase(x);
        } 
        else
            s.insert(x);
    }   

    cout<<s.size();
    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 4992
def isprime(p):
    if p <= 1:
        return False
    if p == 2:
        return True
    if p % 2 == 0:
        return False
    lim = int(p**0.5)+1
    for q in range(3, lim, 2):
        if p % q == 0:
            return False
    return True

N = int(input())
A = [int(input()) for _ in range(N)]

ans = sum(isprime(a) for a in A)
print(ans)


Measured memory_bytes: 6000
#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;
  cin >> n;
  vector<P> students(n);
  rep(i, n) {
    int a;
    cin >> a;
    students[i] = make_pair(a, i + 1);
  }
  sort(students.begin(), students.end());
  rep(i, n) {
    cout << students[i].second;
    if (i < n - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = a + b;
        int sub = a - b;
        int max = Math.max(sum,sub);
        int mul = a * b;
        max = Math.max(max,mul);
        System.out.println(max);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c; i < n; i++){
        cs.push_back(cards[i]);
      }

      for(uint32_t i= 0; i < n; i++){
        // cout << cs[i] << " ";
        cards[i] = cs[i];
      }
      // cout << endl;
    }

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

Measured memory_bytes: 3024
#include <iostream>

int main(){
    uint16_t N;
    std::cin >> N;
    if((N < 1) || (9 < N)) {
        std::cout << "invalid value!" << std::endl;
        return 1;
    }
    std::cout << (N * N * N) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define N 100010
#define mod 998244353
#define int ll
struct node{
	int x,p;
	bool operator<(node B)const{return x<B.x;}
};
node a[N],b[N];
int pa[N],pb[N];
int n;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	repeat(i,0,n)cin>>a[i].x,a[i].p=i;
	repeat(i,0,n)cin>>b[i].x,b[i].p=i;
	sort(a,a+n);
	sort(b,b+n);
	repeat(i,0,n)pa[a[i].p]=pb[b[i].p]=i;
	repeat(i,0,n)
	if(a[i].x>b[i].x){
		cout<<"No"<<endl;
		return 0;
	}
	repeat(i,0,n-1){
		if(a[i].x==a[i+1].x || b[i].x==b[i+1].x
		|| a[i+1].x<=b[i].x){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	int x=0,t;
	for(t=1;;t++){
		x=b[pa[x]].p;
		if(x==0)break;
	}
	if(t!=n)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 4992
def inverse(n, mod):
    return pow(n, mod - 2, mod)

def cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * inverse(q, mod) % mod

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
ans = pow(2, n, mod) - 1
ans -= cmb(n, a, mod)
ans -= cmb(n, b, mod)
print(ans % mod)


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    V<ll> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    set<ll> st;
    ll cnt=0;
    //st.insert(0);
    ll t=0;
    ll r,u;
    V<ll> aa;
    while(true){
        //cnt++;
        if(st.count(t)){
            r=t;
            u=t;
            break;
        }
        aa.push_back(t);
        cnt++;
        st.insert(t);
        t=a[t];
    }
    V<ll> d;
   
    
    V<ll> dd;
    t=0;
    //dd.push_back(0);
    while(true){
        if(u==t) break;
        dd.push_back(t);
        t=a[t];
        
    }
    if(k<dd.size()){
        cout<<aa[k]+1<<endl;
    }else{
        ll y=aa.size();
        y-=dd.size();
        k-=dd.size();
        ll x;
        if(y==0) x=0;
        else x=k%y;
        cout<<aa[x+dd.size()]+1<<endl;
    }
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 18708
import java.io.*;

public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      String input = new String(in.readLine());
      String[] inputArr = input.split(" ");
      int x = Integer.parseInt(inputArr[0]);
      int y = Integer.parseInt(inputArr[1]);
      if ( x > y ) {
        int tmp = x;
        x = y;
        y = tmp;
       }
       while ( x > 0 ) {
         int tmp = x;
         x = y % x;
         y = tmp;
       }
       System.out.println(y);
    } catch( IOException e ) {
    }
  }
}

Measured memory_bytes: 24452
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 100000000;
typedef pair<int, int> P;

char maze[25][25];
int N, M;
int sx, sy;
int gx, gy;
vector<vector<int>> d(25, vector<int>(25));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int bfs(int sx, int sy) {
    queue<P> que;
    rep(i,N){
        rep(j,M){
            d[i][j] = INF;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;
    while(que.size()){
        P p = que.front(); que.pop();
        for(int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if(0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' && d[nx][ny]==INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int ans = 0;
    rep(i,N){
        rep(j,M){
            if(d[i][j]!=INF)ans = max(ans, d[i][j]);
        }
    }   
    return ans;
} 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    int res = 0;
    rep(i,N){
        cin >> maze[i];
    }
    rep(i,N){
        rep(j,M) {
            if(maze[i][j] == '.') res = max(bfs(i,j), res);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
mod = 10**9+7
frac = [1]*364364
for i in range(2,364364):
    frac[i] = i * frac[i-1]%mod
fraci = [None]*364364
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -364364-1, -1):
    fraci[i] = fraci[i+1] * (364364 + i + 1) % mod
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%mod

def count(a, b):
    (r1, c1), (r2, c2) = RC[a], RC[b]
    if c2 < c1:
        return 0
    return comb(r2-r1 + c2-c1, r2-r1)

H, W, N = map(int, input().split())

RC = [list(map(int, input().split())) for _ in range(N)] + [[1, 1], [H, W]]
RC.sort()

dpe = [0]*(N+2)
dpo = [0]*(N+2)
dpe[0] += 1

for i in range(1, N+2):
    rese = 0
    reso = 0
    for k in range(i):
        t = count(k, i)
        if not t:
            continue
        rese = (rese + t*dpo[k]) % mod
        reso = (reso + t*dpe[k]) % mod
    dpe[i] = rese
    dpo[i] = reso

print((dpo[-1] - dpe[-1]) % mod)


Measured memory_bytes: 59324
#https://atcoder.jp/contests/abc109/tasks/abc109_b
import collections
N = int(input())
Word_List = []
SP = ""
for i in range(N):
    CW = str(input())
    if i == 0:
        Word_List.append(CW)
        SP = CW[-1]
    elif SP != CW[0]:
        print("No")
        break
    else:
        Word_List.append(CW)
        SP = CW[-1]
else:
    Word_List = collections.Counter(Word_List)
    if len(Word_List) != N:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 9388