akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define LEN 100010
#define STABLE 1
#define NOTSTABLE 0

typedef struct{
  char c;
  int n;
}Card;

//quick
void quicksort(Card *, int, int);
int partion(Card *, int, int);

//marge
void merge(Card *, int, int, int);
void merge_sort(Card *, int, int);


int main()
{
  int n;
  Card A[LEN], M[LEN], card;
  int p, r;

  int flag=STABLE;

  int i, j, k;
  char c;

  //read
  scanf("%d", &n);
  scanf("%c", &c);
  for(i=0; i<n; i++)
    {
      scanf("%c %d", &A[i].c, &A[i].n);
      scanf("%c", &c);
      M[i]=A[i];
      //printf("%c %d\n", A[i].c, A[i].n);
    }


  //merge sort
  merge_sort(&M[0], 0, n);

  //quick sort
  p=0;
  r=n-1;
  quicksort(&A[0], p, r);

  //is this stable?
  for(i=0; i<n-1; i++)
    {
      if(A[i].c!=M[i].c)
	{
	  flag=NOTSTABLE;
	  break;
	}
    }

  //print
  if(flag==STABLE)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0; i<n; i++)printf("%c %d\n", A[i].c, A[i].n);
  /*
  printf("\n");
  for(i=0; i<n; i++)printf("%c %d\n", M[i].c, M[i].n);
  */


  return 0;
}


//quicksort
void quicksort(Card *A, int p, int r)
{
  int q;
  if(p<r)
    {
      q = partion(A, p, r);
      quicksort(A, p, q-1);
      quicksort(A, q+1, r);
    }
}

//partion
int partion(Card *A, int p, int r)
{
  int x = A[r].n;
  int i = p-1;
  int j, n;
  Card k;

  for(j=p; j<=r-1; j++)
    {
      if(A[j].n<=x)
	{
	  i++;
	  k=A[i];
	  A[i]=A[j];
	  A[j]=k;
	}
    }

  k=A[i+1];
  A[i+1]=A[r];
  A[r]=k;
  return i+1;
}



//Merge method
void merge(Card *S, int left, int mid, int right)
{
  int i, j, k;
  int n1=mid-left;
  int n2=right-mid;
  Card L[LEN], R[LEN];

  for(i=0; i<n1; i++)L[i]=S[left+i];
  for(i=0; i<n2; i++)R[i]=S[mid+i];

  L[n1].n=1000000001;
  R[n2].n=1000000001;
  i=0;
  j=0;
  for(k=left; k<right; k++)
    {
      if(L[i].n<=R[j].n)
        {
          S[k]=L[i];
          i++;
        }
      else
        {
          S[k]=R[j];
          j++;
        }
    }
}

void merge_sort(Card *S, int left, int right)
{
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      merge_sort(S, left, mid);
      merge_sort(S, mid, right);
      merge(S, left, mid, right);
    }
}

Measured memory_bytes: 2780
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    if(n<2)out(1);
    else if(n<4)out(2);
    else if(n<8)out(4);
    else if(n<16)out(8);
    else if(n<32)out(16);
    else if(n<64)out(32);
    else out(64);
    
    return 0;
}


Measured memory_bytes: 256
<?php
class Dodecagon {
    var $r;
    
    function __construct() {
        fscanf(STDIN, "%d", $this->r);
    }

    function __invoke() {
        return 3 * pow($this->r, 2);
    }
}

$Dodecagon = new Dodecagon;
echo $Dodecagon();


Measured memory_bytes: 4856
//In The Name Of GOD
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 100*1000+1;
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
 
int ans[maxn];
 
bool prime(int x){
  for(int i=2;i<=(int)sqrt(x);i++){
    if(x%i==0){
      return false;
    }
  }
  return true;
}
 
int main(){
  IO;
  ans[1]=0;
  for(int i=3;i<=maxn;i+=2){
    if(prime(i)&&prime((i+1)/2)){
      ans[i]=ans[i-2]+1;
    }else{
      ans[i]=ans[i-2];
    }
  }
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    cout<<ans[r]-ans[max(l-2,0)]<<endl;
  }
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import Counter

def main():
    A, P = LI()
    X = P + A * 3
    ans = X // 2
    return ans

print(main())

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    double a,b,c,d,p,q;
    while(cin>>a>>b>>p>>c>>d>>q){
        double x=(b*q-d*p)/(b*c-a*d);
        double y=(a*q-c*p)/(a*d-b*c);
        if(x<=0.0&&x>-0.00001)x=0.0;
        if(y<=0.0&&y>-0.00001)y=0.0;
        printf("%.3f %.3f\n",x,y);
    }

    return 0;
}

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

int main(){

  string n;
  cin >> n;
  
  for(int i=0; i<3; i++){
  if(n[i] == '7' ){
    cout << "Yes" << endl;
    return 0;
  }
  }
  cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
	int a[10]={};
	int i,j,temp;
	for(i=0;i<=9;i++){
	scanf("%d",&a[i]);
	}
	for(i=0;i<=9;i++){
		for(j=9;j>i;j--){
			if(a[j-1]<a[j]){
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;
			}
		}
	}
	for(i=0;i<=2;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}

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

using Int = long long;

Int const MOD = 1e9+7;
Int dp[50][1 << 20];

int main(void){
    int N, X, Y, Z; cin >> N >> X >> Y >> Z;
    int XYZbits = (1 << (X+Y+Z-1)) + (1 << (Y+Z-1)) + (1 << (Z-1));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= 10; j++) {
            for (int k = 0; k < (1 << (X+Y+Z-1)); k++) {
                int bits = (k << j) + (1 << (j - 1));
                if ((XYZbits & bits) == XYZbits) continue;
                dp[i+1][bits & ((1 << (X+Y+Z-1)) - 1)] += dp[i][k];
                dp[i+1][bits & ((1 << (X+Y+Z-1)) - 1)] %= MOD;
            }
        }
    }
    Int U = 1;
    for (int i = 0; i < N; i++) {
        U *= 10;
        U %= MOD;
    }
    Int comp = 0;
    for (int k = 0; k < (1 << (X+Y+Z-1)); k++) {
        comp += dp[N][k];
        comp %= MOD;
    } 
    
    cout << (U - comp + MOD) % MOD << endl;
}


Measured memory_bytes: 82176
#include<stdio.h>
#define N 100000

int main(void) {
  
  int i,n,A[N];
  int parent,left,right;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  
  for(i=1;i<=n;i++) {
    parent = i/2;
    left = 2*i;
    right = 2*i+1;
    
    printf("node %d: key = %d, ",i,A[i]); 
    if(i != 1)
      printf("parent key = %d, ",A[parent]);
    
    if(left <= n)
      printf("left key = %d, ",A[left]);
    
    if(right <= n)
      printf("right key = %d, ",A[right]); 
    
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
(defun answer (d n)
  (labels ((inner (k rv)
             (cond
               ((zerop (mod rv 100))
                (inner k (1+ rv)))
               ((= k n)
                rv)
               (t
                (inner (1+ k) (1+ rv))))))
    (* (inner 1 1) (expt 100 d))))


(princ (answer (read) (read)))

Measured memory_bytes: 5728
import java.util.Scanner;
public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub	
		Scanner sc=new Scanner(System.in);
		int a,b,c,d,e;
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		d=sc.nextInt();
		e=sc.nextInt();	
		int[] x={a,b,c};
		int [] y={d,e};
		for(int i=0;i<x.length/2;i++){
			for(int j=0;j<x.length;j++){
				if(x[j]<x[i]){
				int t=x[i];
				x[i]=x[j];
				x[j]=t;
				}	
			}
		}
		for(int i=0;i<y.length/2;i++){
			for(int j=0;j<y.length;j++){
				if(y[j]<y[i]){
					int s=y[i];
					y[i]=y[j];
					y[j]=s;
				}
			}
		}
		int A=x[0]+y[0]-50;
		System.out.println(A);
	}
}

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

int A[101][101];

int N;
int Func(int x, int y){
    if(x == 0 && y == 0){
        return A[0][0];
    }
    int res = A[y][x];
    if(x != 0){
        res = A[y][x] + Func(x - 1, y);
    }
    if(y != 0){
        res = max(res, A[y][x] + Func(x, y - 1));
    }
    return res;
}

int main(){
    cin >> N;

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

    cout << Func(N-1, 1) << endl;

}

Measured memory_bytes: 384
n,x,y = map(int, input().split())
b=[[] for i in range(n)]

for i in range(n-1):
    b[i].append(i+1)
    b[i+1].append(i)

b[x-1].append(y-1)
b[y-1].append(x-1)
ans=[0]*(n-1)
# グラフでのbfs
import collections
from collections import deque
def tree(s):

    INF=-10**9
    dis = [INF for i in range(n)]
    dis[s]=0
    def bfs():
        d = deque()
        d.append(s)

        while len(d):
            x = d.popleft()

            for i in range(len(b[x])):
                y=b[x][i]
                if dis[y] == INF:
                    d.append(y)
                    dis[y]=dis[x]+1
                    ans[dis[y]-1]+=1
        return dis
    return bfs()


for i in range(n):
    tree(i)

for i in ans:
    print(i//2)

Measured memory_bytes: 48988
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	ll x, y;
	cin >> x >> y;
	
	int ans = 0;
	while (x <= y) x *= 2, ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
ll gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

ll lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(){
  char s[8];
  cin >> s;
  if(s[2]==s[3]&&s[4]==s[5])cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#include<stdio.h>

#define integral_end 600

int main(void){
	int d, pd;
	int i, sum;

	while(scanf("%d", &d) != EOF){
		sum = 0;
		pd = d;

		for(i = 1; i < integral_end/d; i++){
			sum += pd*pd*d;
			pd += d;
		}

		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 596
N = int(input())
A = list(map(int,input().split()))
nums = [0]*100000
ans_list=[]

for i in range(N):
  nums[A[i]] += 1

for j in range(1,99999):
  ans_list.append(nums[j-1]+nums[j]+nums[j+1])

print(max(ans_list))

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

#define MAX 200000
#define SENTINEL 2000000000
typedef  long long llong;

int L[MAX/2+2],R[MAX/2+2];

llong merge(int A[],int n,int left,int mid,int right){
	int i,j,k;
	llong cnt = 0;
	int n1 = mid-left;
	int n2 = right-mid;
	for(i=0;i<n1;i++)	L[i]=A[left+i];
	for(i=0;i<n2;i++)	R[i]=A[mid+i];
	L[n1]=R[n2]=SENTINEL;
	i=j=0;
	for(k=left;k<right;k++){
		if(L[i]<=R[j]){
			A[k]=L[i++];
		}else{
			A[k]=R[j++];
			cnt+=n1-i;
		}
	}
	return cnt;
}

llong mergeSort(int A[],int n,int left,int right){
	int mid;
	llong v1,v2,v3;
	if(left+1<right){
		mid=(left+right)/2;
		v1=mergeSort(A,n,left,mid);
		v2=mergeSort(A,n,mid,right);
		v3=merge(A,n,left,mid,right);
		
		return v1+v2+v3;
	}
	return 0;
}

int main() {
	
	int A[MAX],n,i;
	
	cin>>n;
	
	for(i=0;i<n;i++){
		cin>>A[i];
	}
	
	llong ans = mergeSort(A,n,0,n);
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 4660
#include<bits/stdc++.h>
using namespace std;
vector <long long int> arr,pref;
long long int dp[3001][3001],n=0;
long long int solve(long long int i,long long int j){
  	if(i==j){return dp[i][j] = arr[i];}
  	else if(dp[i][j]!=-1){return dp[i][j];}
  	else{
        return dp[i][j] = max(arr[i]-solve(i+1,j),arr[j] - solve(i,j-1));
      }
    
 //return dp[k] = ans;
}
int main(){
	long long int i=0,z=0,j=0,k=0,max=0,count1=0,count2=0;
  	string out;
  	cin >> n;
  	for(i=0;i<n;i++){
    	cin >> z;
      	arr.push_back(z);
    }
  	memset(dp,-1,sizeof(dp));
  	cout << solve(0,n-1)<<endl;
}

Measured memory_bytes: 70912
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
typedef long long ll;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2;
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
// vector<vector<ll>> vec(100,vector<ll>(100));

ll cnt;
ll l;
vector<ll> G;
ll vec[10000000];
void insertionSort(ll vec[],ll n,ll g){
  for(int i=g;i<n;i++){
    int v = vec[i];
    int j = i-g;
    while(j >= 0 && vec[j] > v){
      vec[j+g] = vec[j];
      j -= g;
      cnt++;
    }
    vec[j+g] = v;
  }
}
void shellSort(ll vec[],ll n){
  for(int h=1;;){
    if(h > n){
      break;
    }
    G.push_back(h);
    h = 3*h+1;
  }

  for(int i=G.size()-1;i >= 0;i--){
    insertionSort(vec,n,G[i]);
  }
}
int main(){
  ll n;
  cin >> n;
  rep(i,n){
    cin >> vec[i];
  }
  cnt = 0;
  shellSort(vec,n);
  cout << G.size() << endl;
  for(ll i = G.size()-1;i>=0;i--){
    cout << G[i];
    if(i)cout << " ";
  }
  cout << endl;
  cout << cnt << endl;
  rep(i,n){
    cout << vec[i] << endl;
  }
}



Measured memory_bytes: 10920
fn main() {
    proconio::input! {
        r : usize,
        c : usize,
        k : usize,
        item : [(usize, usize, i64); k]
    };
    let mut v = vec![vec![0; c]; r];
    for &p in &item { v[p.0-1][p.1-1] = p.2; }
    let mut dp = vec![vec![vec![0; 4]; c]; r];
    dp[0][0][1] = v[0][0];
    for i in 0..r {
        for j in 0..c {
            for k in 0..4 {
                if j+1 < c {
                    if k < 3 {
                        dp[i][j+1][k+1] = dp[i][j+1][k+1].max(dp[i][j][k] + v[i][j+1]);
                    }
                    dp[i][j+1][k] = dp[i][j+1][k].max(dp[i][j][k]);
                }
                if i+1 < r {
                    dp[i+1][j][0] = dp[i+1][j][0].max(dp[i][j][k]);
                    dp[i+1][j][1] = dp[i+1][j][1].max(dp[i][j][k] + v[i+1][j]);
                }
            }
        }
    }
    println!("{}", dp[r-1][c-1].iter().max().unwrap());
}


Measured memory_bytes: 713028
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int x, y, a, b, c;

int main() {
    fastio();

    cin >> x >> y >> a >> b >> c;
    vec<pli> l;
    int v;
    forn(i, a) {
        cin >> v;
        l.emplace_back(v, 0);
    }
    forn(i, b) {
        cin >> v;
        l.emplace_back(v, 1);
    }
    forn(i, c) {
        cin >> v;
        l.emplace_back(v, 2);
    }

    sort(all(l), greater<pli>());

    ll ans = 0;
    int k = 0;
    int cx = x, cy = y;
    for (int i = 0; i < l.size() && k < x + y; i++) {
        if (l[i].snd == 0 && cx > 0) {
            ans += l[i].fst;
            cx--;
            k++;
        }

        if (l[i].snd == 1 && cy > 0) {
            ans += l[i].fst;
            cy--;
            k++;
        }

        if (l[i].snd == 2) {
            ans += l[i].fst;
            k++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// 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("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &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 (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    vector<vi> a(N,vi(N, -1 ));
    vi b(N,0);
    set<pair<int,int> > c;
    set<pair<int,int> > d;
    Rep(i,N) Rep(k,N-1) Scd(a[i][k]) , a[i][k]--;

    Rep(i,N) {
        if( a[a[i][0]][0] == i ){
            int x = min( (int)i, a[i][0] );
            int y = max( (int)i, a[i][0] );
            c.insert( { x,y } );
        }
    }

    int ans = 0;
    int cnt = 0;

    while( c.size() ){
        ans++;
        for( auto it = c.begin(); it != c.end(); it++ ){
            cnt++;
            int f = it->first;
            int g = it->second;
            b[f]++;
            b[g]++;
            // printf ("%d,%d[%d],%d[%d]\n", ans ,f , b[f] ,g , b[g] );
            if( f >= 0 && b[f] <= N-2 ){
                int ff = a[f][b[f]];
                if( a[ff][b[ff]] == f ){
                    int x = min( f, ff );
                    int y = max( f, ff );
                    d.insert( { x,y } );
                }
            }
            if( g >= 0 && b[g] <= N-2 ){
                int gg = a[g][b[g]];
                if( a[gg][b[gg]] == g ){
                    int x = min( g, gg );
                    int y = max( g, gg );
                    d.insert( { x,y } );
                }
            }
        }
        c.clear();
        for( auto it = d.begin(); it != d.end(); it++ ){
            c.insert( { it->first, it->second } );
        }
        d.clear();
    }

    printf ("%d\n", cnt == N*(N-1)/2 ? ans : -1 );

    return 0;
}





Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  int n; cin >> n;
  vector<vector<string>> v(11);
  v[1].PB("a");

  FOR(i,2,n){
    for(auto x: v[i-1]){
      string poo;

      // poo = x;
      // char c = x[x.length()-1];
      // if(c!='a'){
      //   poo += c;
      //   v[i].PB(poo);
      // }

      // poo = x;
      // c = x[x.length()-1] + 1;
      // poo += c;
      // v[i].PB(poo);

      int lmt = -1;

      FOR(j,0,10){

        poo = x;
        char c = 'a' + j;
        bool isc = false;
        FOR(k,0,x.length()-1){
          if(lmt==-1 && x[k]==c) isc = true;
        }
        poo += c;
        v[i].PB(poo);
        if(!isc) {
          // poo = x;
          // char c = 'a' + j + 1;
          // poo += c;
          // v[i].PB(poo);
          break;
        }
        
      }
    }
  }

  SORT(v[n]);
  for(auto x: v[n]){
    cout << x << "\n";
  }
    

}


Measured memory_bytes: 11124
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<Integer> clover = new ArrayList<Integer>();
        List<Integer> spade = new ArrayList<Integer>();
        List<Integer> hart = new ArrayList<Integer>();
        List<Integer> dia = new ArrayList<Integer>();
        String cou = br.readLine();
        int count = Integer.parseInt(cou);
        int i=0;
        while(i<count) {
            String line = br.readLine();
            String[] line2 = line.split(" ");
            if(line2[0].equals("S")) {
                spade.add(new Integer(line2[1]));
            }else if(line2[0].equals("H")) {
                hart.add(new Integer(line2[1]));
            }else if(line2[0].equals("C")) {
                clover.add(new Integer(line2[1]));
            }else if(line2[0].equals("D")) {
                dia.add(new Integer(line2[1]));
            }
            i++;
        }
        List<Integer> clover_e = check(clover);
        List<Integer> spade_e = check(spade);
        List<Integer> hart_e = check(hart);
        List<Integer> dia_e = check(dia);
        print("S",spade_e);
        print("H",hart_e);
        print("C",clover_e);
        print("D",dia_e);
        
    }
    static void print(String mark,List<Integer> list) {
        for(int i=0;i<list.size();i++) {
            System.out.print(mark + " " + list.get(i));
            System.out.println();
        }
    }
    //絵柄がスペード、ハート、クラブ、ダイヤの順番で優先的に出力する。
    static List<Integer> check(List<Integer> list) {
        List<Integer> lack = new ArrayList<Integer>();
        int[] expect = {1,2,3,4,5,6,7,8,9,10,11,12,13};
        for(int i=0;i<expect.length;i++) {
            lack.add(new Integer(expect[i]));
        }
        lack.removeAll(list);
        return lack;
    }
}

Measured memory_bytes: 16940
S = input()
T = input()
d = dict()
d2 = dict()
check1 = dict()
check2 = dict()
for i in "abcdefghijklmnopqrstuvwxyz":
    check1[i] = False
    check2[i] = False
for i in range(len(S)):
    if check2[T[i]]:
        if d2[T[i]] != S[i]:print("No");exit()
    if not check1[S[i]]:
        check1[S[i]] = True
        d[S[i]] = T[i]
        check2[T[i]] = True
        d2[T[i]] = S[i]
    else:
        if d[S[i]] != T[i]:print("No");exit()
print("Yes")

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
    int i,j;
    char s[101];
    scanf("%s",s);
    for(i=0;i<100;i++){
        if(s[i]=='C'){
            for(j=i;j<100;j++){
                if(s[j]=='F'){
                    printf("Yes\n");
                    return 0;
                }
            }
        }
    }
    printf("No\n");
    return 0;
}

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

typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int index_left = 1, index_right = n - 2;
    int left = a[0], right = a[n - 1];
    ll ans = right - left;
    for (int i = 2; i < n; i++) {
        int r1 = abs(a[index_left] - left);
        int r2 = abs(a[index_left] - right);
        int r3 = abs(a[index_right] - left);
        int r4 = abs(a[index_right] - right);
        int r_max = max(max(r1, r2), max(r3, r4));
        if (r_max == r1) {
            ans += r1;
            left = a[index_left++];
        } else if (r_max == r2) {
            ans += r2;
            right = a[index_left++];
        } else if (r_max == r3) {
            ans += r3;
            left = a[index_right--];
        } else {
            ans += r4;
            right = a[index_right--];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    while(b>0){
        ll p= a%b;
        a = b;
        b=p;
    }
    return a;
}
ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return (a/g) * b;
}
int main(){
    long long  n,m;
    cin>>n>>m;
    vector<long long> v(n);
    ll l=1;
    for(int i=0; i<n; i++){
        cin>>v.at(i);
        l=lcm(l, (v.at(i)/2 ) );
        if(l>m){
            l = m+1;
        }
    }
    ll kai=0;
    ll b=v[0];
    while(b%2 ==0){
        kai++;
        b /=2;
    }
    bool ok = true;
    for(int i=1; i<n; i++){
        ll a=v.at(i);
        ll tmp=0;
        while(a%2 ==0){
            tmp++;
            a /=2;
        }
        if(kai != tmp) ok =false;
    }
    ll ans = m/l;
    cout<<(ok? (ans+1)/2 : 0)<<endl;
}

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a+b >= 10) puts("error");
	else cout << a+ b;
}


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

L = []

for i in range(N):
    tmp = list(map(int,input().split()))
    L.append(tmp)

cnt = 0
for l in L:
    if l[0] ** 2 + l[1] ** 2 <= D ** 2:
        cnt += 1

print(cnt)

Measured memory_bytes: 102344
// 0583.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, a[3];

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

	for (int i = 1; i <= 1e8; ++i) {
		bool flag = true;
		for (int j = 0; j < n; ++j) {
			if (a[j] % i != 0) {
				flag = false;
				break;
			}
		}

		if (flag == true) {
			cout << i << endl;
		}
	}

    return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	long long h, w, n;

	std::cin >> h >> w >> n;

	std::cout << int(std::ceil(1.0 * n / std::max(h, w))) << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int h,n;
	cin>>h>>n;
	int sum=0;
	int flag=0;
	for(int i=0;i<n;i++){
		int x=0;
		cin>>x;
		sum+=x;
		if(sum>=h){
			cout<<"Yes";
			flag=1;
			break;
		}
	}
	if(!flag){
		cout<<"No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
  string S;
  cin >> N >> S;
  int lw[300000] = {};
  int re[300000] = {};
  lw[0] = 0;
  for (int i = 1; i < N; i++)
  {
    lw[i] = lw[i - 1];
    if (S[i - 1] == 'W')
      lw[i]++;
  }
  re[N - 1] = 0;
  for (int i = N - 2; i >= 0; i--)
  {
    re[i] = re[i + 1];
    if (S[i + 1] == 'E')
      re[i]++;
  }
  int ans = 300000;
  for (int i = 0; i < N; i++)
  {
    if (lw[i] + re[i] < ans)
      ans = lw[i] + re[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3076
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

// UnionFind 構造体 for tree
type UnionFind struct {
	par []int
}

/*コンストラクタ*/
func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}
func (u UnionFind) unite(x int, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}

var mod int = 1000000007

type pair struct {
	fi int
	se int
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a := iScan()
	b := iScan()
	if a == 1 {
		a = 14
	}
	if b == 1 {
		b = 14
	}
	if a > b {
		fmt.Println("Alice")
	}
	if a < b {
		fmt.Println("Bob")
	}
	if a == b {
		fmt.Println("Draw")
	}
}

Measured memory_bytes: 1768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int M = (int)3e3+5;
const int Q = 401;
const int logN = 19;

ll dp[Q][Q];
int a[N];
void solve() {
    int n;
    cin>>n;
    REP(i,1,n) {
        cin>>a[i];
    }
    REPN(i,n,1) {
        dp[i][i] = 0;
        ll sum = a[i];
        REP(j,i+1,n) {
            sum += a[j];
            dp[i][j] = lim;
            REP(k,i,j-1) {
                dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+sum);
            }
        }
    }
    cout<<dp[1][n];
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))
avg = sum(As) / N

dist = 1e9
for i, a in enumerate(As):
    d = abs(a - avg)
    if d < dist:
        dist = d
        ans = i
print(ans)


Measured memory_bytes: 8356
<?php
class CircleList {
    private $vl;
    
    public function __construct() {
        $this->vl = [];
    }
    
    public function length() { return count($this->vl); }
    
    public function push($v) {
        $this->vl[] = $v;
    }
    
    public function slice($start, $size) {
        $ret = [];
        $l = $this->length();
        $index = 0;

        for ($i = 0;$i < $size; $i++) {
            if ($i >= $l) break;
            if ($start + $i >= $l) {
                $index = $start + $i - $l;
            } else {
                $index = $start + $i;
            }
            $ret[] = $this->vl[$index];
        }
        
        return $this->toString($ret);
    }
    
    private function toString($list) {
        return implode($list);
    }
}

$list = new CircleList();

$s = trim(fgets(STDIN));
$p = trim(fgets(STDIN));

$sa = str_split($s);
foreach ($sa as $v) {
    $list->push($v);
}

$sl = strlen($s);
$pl = strlen($p);

for ($i = 0;$i < $sl;$i++) {
    $tmp = $list->slice($i, $pl);
    if ($tmp == $p) {
        echo 'Yes' .PHP_EOL;
        return;
    }
}

echo 'No' .PHP_EOL;


Measured memory_bytes: 9416
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll p = 1000000007;
ll dp[101][100001];
const int N = 1000001;
using namespace std;
ll factorialNumInverse[N + 1];
ll naturalNumInverse[N + 1];
ll fact[N + 1];
void InverseofNumber(ll p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (int i = 2; i <= N; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(ll p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    for (int i = 2; i <= N; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(ll p)
{
    fact[0] = 1;
    for (int i = 1; i <= N; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}
ll Binomial(ll N, ll R)
{
    ll ans = ((fact[N] * factorialNumInverse[R])
              % p * factorialNumInverse[N - R])
             % p;
    return ans;
}
int main()
{
    InverseofNumber(p);
    InverseofFactorial(p);
    factorial(p);
    ll n,k;
    cin>>n>>k;
   memset(dp,0,sizeof(dp));
   ll a[n+1];
   for(int x=1;x<=n;x++)
    cin>>a[x];
    if(a[1]+1<=k)
    dp[1][a[1]+1]=-1;
    dp[1][0]=1;
   for(int x=2;x<=n;x++)
   for(int y=0;y<=k;y++)
   {
       dp[x][y]+=dp[x-1][y];
       dp[x][y]%=p;
       if(y+a[x]+1<=k)
       {dp[x][y+a[x]+1]+=(-dp[x-1][y]);
         dp[x][y+a[x]+1]%=p;
       }

   }
   ll ans=0;
   for(int x=0;x<=k;x++)
   {  //cout<<dp[1][x]<<" ";
       ans+=(p+dp[n][x]*Binomial(n+k-x-1,n-1))%p;
   }
   cout<<(p+ans)%p;
}


Measured memory_bytes: 102528
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 M = 0;

	cin >> N;
	cin >> M;

	SINT32 ANS = 0;
	
	for (SINT32 i = 1; i < M-N; i++) {
		ANS = ANS+i;
	}

	cout << ANS-N << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

Measured memory_bytes: 256
object Main {
    def wrap(l: List[Int]): List[(Int, Int)] = {
        if (l.isEmpty) Nil
        else {
            val (x, y) = l.span(_ == l.head)
            (x.head, x.size) :: wrap(y)
        }
    }
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.toInt).toList
        val wrapped = wrap(in.sorted)
        wrapped.filter(_._2 == wrapped.maxBy(_._2)._2).foreach(p => println(p._1))
    }
}

Measured memory_bytes: 44024
#include <iostream>
using namespace std;
int main(void){
	long long int n,a,b,c,ans=0;
	cin >> n;
	for (a=1;a<n;a++) {
		if (n%a == 0) {
			ans += int(n/a)-1;
		} else {
			ans += int(n/a);
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3632
#include<iostream>
#include<map>
using namespace std;
int main(void){

    int n;

    while(cin>>n){
        if(n==0)break;
        int a[13];
        map<int,int> b;
        int c[13];
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[a[i]]++;
        }
        int j=0;
        while(1){

            bool flg = false;
            for(int i=0;i<n;i++){
                c[i] = b[a[i]];
                if(c[i]!=a[i])flg = true;
                //cout<<c[i]<<" ";
            }
            //cout<<endl;
            if(!flg)break;
            b.clear();
            for(int k=0;k<n;k++){
                a[k] = c[k];
                b[a[k]]++;
            }
            j++;
        }
        cout<<j<<endl;
        bool f = false;
        for(int i=0;i<n;i++){
            if(f)cout<<" ";
            cout<<c[i];
            f = true;
        }
        cout<<endl;

    }

    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long int
#define INF 1000000007

signed main(){
    int n;
    cin >> n;
    int r = 1;
    for(int i = 1;i<=n;i++){
        r = r * i % INF;
    }
    cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

int64_t mod = 998244353;

std::string neg(std::string bits)
{
    for (char& c : bits) c = c=='1'?'0':'1';
    return bits;
}

int64_t pass(const std::string& bits, int k)
{
    std::string a = bits.substr(0, k);
    std::string b = neg(a);
    std::string pattern = a;
    for (int i=k;i<bits.length();i+=2*k)
    {
        pattern += b;
        pattern += a;
    }
    return pattern <= bits ? 1 : 0;
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    int n;
    std::cin >> n;
    std::string bits;
    std::cin >> bits;
    std::reverse(bits.begin(), bits.end());
    while (bits.size() < n) bits.push_back('0');
    std::reverse(bits.begin(), bits.end());

    int64_t result = 0;
    int64_t pref = 0;
    std::map<int, int64_t> S;
    for (int l=1;l<=n;++l)
    {
        pref *= 2;
        pref += bits[l-1] == '1' ? 1 : 0;
        pref %= mod;

        if (n % l == 0 && (n/l) & 1)
        {
            auto& s = S[l];
            s = (pref + pass(bits, l)) % mod;
            for (auto it : S)
            {
                int k = it.first;
                if (k < l && l % k == 0) s = (s + mod - it.second) % mod;
            }
            result = (result+2*s*l) % mod;
        }
    }

    std::cout << result;

    return 0;
}


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

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

    int min_dist = 0;
    rep(i, N) {
        int x;
        cin >> x;
        if (x < K - x) {
            min_dist += 2 * x;
        } else {
            min_dist += 2 * (K - x);
        }
    }
    cout << min_dist << endl;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main(){
	int n; scanf("%d", &n);
	ll res = 1;
	for(int i = 2; i <= n; i++) res = res * i % MOD;
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

char horizontal[2] = {'L', 'R'};
char vertical[2] = {'D', 'U'};
bool bx, by;

void print(int w, int h) {
    rep(i, w) cout << horizontal[bx];
    rep(i, h) cout << vertical[by];
    rep(i, w) cout << horizontal[!bx];
    rep(i, h) cout << vertical[!by];
}

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int w = abs(sx - tx);
    int h = abs(sy - ty);
    bx = tx > sx;
    by = ty > sy;

    rep(i, w) cout << horizontal[bx];
    rep(i, h) cout << vertical[by];
    rep(i, w) cout << horizontal[!bx];
    rep(i, h) cout << vertical[!by];
    cout << vertical[!by];
    rep(i, w+1) cout << horizontal[bx];
    rep(i, h+1) cout << vertical[by];
    cout << horizontal[!bx];
    cout << vertical[by];
    rep(i, w+1) cout << horizontal[!bx];
    rep(i, h+1) cout << vertical[!by];
    cout << horizontal[bx];
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    for(int i=0;i<b;++i) cout << a;
    cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;
ll MOD=998244353;

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


int main(){
    string S;cin>>S;
    if((S[2]==S[3])&&(S[4]==S[5])){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;

    
}

Measured memory_bytes: 256
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


def main():
    A, B, K = map(int, input().split())
    d = gcd(A, B)
    div = []
    div2 = []
    root = int(d ** 0.5)
    if root ** 2 == d:
        for i in range(1, root):
            if d % i == 0:
                div.append(i)
                div2.append(d // i)
        div.append(root)
    else:
        for i in range(1, root + 1):
            if d % i == 0:
                div.append(i)
                div2.append(d // i)
    div2.reverse()
    div = div + div2
    for _ in range(K - 1): div.pop()
    print(div[-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 63980
/************************************************************
	> File Name: a.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 19 Jan 2020 08:13:07 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <ext/rope>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
int main(void){
	int n, m;
	cin >> n >> m;
	cout << (n > m?"No":"Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,K,X=0,M=1000000007;
  cin>>N>>K;int A[N];
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++){
    long long int S=0,T=0;
    for(int j=0;j<i;j++)if(A[i]>A[j])S++;
    for(int j=i;j<N;j++)if(A[i]>A[j])T++;
    X+=K*(K+1)/2%M*T%M+K*(K-1)/2%M*S%M;X%=M;
  }
  cout<<X<<endl;
}

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

//string型文字列をint型整数にして返す
int str_to_num(string s) {return atoi(s.c_str());}
//約数の総数を返す
int count_divisor(int n){int c[n/2] = {1}; int n_half = n/2; for(int i=2;i<n_half;i++){if(n%i==0){n /= i;c[i]+=1;i--;if(n>1) continue;else break;}  }int r = 1;for(int i=2;i<n_half;i++){r *= c[i];}return r;}
//各桁の数の和を返す
int dig_num(int n){return (n<10) ? n: dig_num(n/10) + n%10;}

int dig_ord(int n){return (n<10) ? 1: dig_ord(n/10) + 1;}

int main(){
  int N; cin >> N;
  int r = 0;
  int ord = dig_ord(N);
  if(ord==1){
    r = N;
  }else if(ord==2){
    r = 9;
  }else if(ord==3){
    r = N - 90;
  }else if(ord==4){
    r = 9 + 900;
  } else if(ord==5){
    r = N - 90 - 9000;
  } else if(ord==6){
    r = 9 + 900 + 90000;
  }
  
  cout << r << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string str,str1;
   int c=0;
   cin>>str>>str1;
   for(int i=0;i<str.size();i++)
   {
       if(str[i]!=str1[i])
       {
           c++;
       }
   }
   cout<<c<<endl;
}


Measured memory_bytes: 3848