akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int h, w;
string s[20];
int ans;
bool bl[25][25];
int d[25][25];
int cnt;

void dfs(int x, int y) {
	if (x < 0 || y < 0 || h <= x || w <= y || (bl[x][y] & d[x][y] <= cnt) || s[x][y] == '#')return;
	bl[x][y] = true;
	d[x][y] = min(d[x][y], cnt);
	cnt++;
	dfs(x + 1, y);
	dfs(x - 1, y);
	dfs(x, y + 1);
	dfs(x, y - 1);
	cnt--;
	return;
}

signed main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++)cin >> s[i];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int k = 0; k < 25; k++) {
				for (int l = 0; l < 25; l++) {
					bl[k][l] = false;
					d[k][l] = INF;
				}
			}
			cnt = 0;
			dfs(i, j);
			for (int k = 0; k < h; k++) {
				for (int l = 0; l < w; l++) {
					if (d[k][l] != INF)ans = max(ans, d[k][l]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
   COMinit();
long long N,M;
long long counter=1;
cin>>N>>M;
queue<long long>vec;
   for (long long a = 2; a * a <= M; ++a) {
        if (M % a != 0) continue;
        long long ex = 0;
        while (M % a == 0) {
            ++ex;
            M /= a;
        }
        vec.push(ex);}
  if (M != 1) vec.push(1);
  while(vec.size()>0) {
  long long z=vec.front();
  vec.pop();
  counter=(counter*COM((z+N-1),z))%MOD;}
cout<<counter<<endl;}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  int N,C;
  cin>>N>>C;
  vector<int>s(N),t(N),c(N);
  for(int i=0;i<N;i++)cin>>s[i]>>t[i]>>c[i];
  for(int i=0;i<N;i++)c[i]--;
  vector<vector<int>>dp(200002,vector<int>(C,0));
  for(int i=0;i<N;i++){
    dp[2*s[i]-1][c[i]]=1;
    dp[2*t[i]][c[i]]=-1;
  }
  for(int i=1;i<=200001;i++){
    for(int j=0;j<C;j++){
      dp[i][j]+=dp[i-1][j];
    }
  }
  vector<int>ans(200002,0);
  for(int i=0;i<=200001;i++){
    for(int j=0;j<C;j++){
      ans[i]+=(dp[i][j]>0);
    }
  }
  ll res=0;
  for(int i=0;i<=200001;i++)res=max(res,ans[i]);
  cout<<res<<endl;
  return 0;
}


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

const int64_t MAX = 1000000000001; // 10^12+1
int64_t pow(int64_t a, int64_t b) {
	int tmp = a;
	int64_t ret = 1;
	while (b) {
		if (ret >= MAX || ret < 0) return MAX;
		if (b & 1) ret *= a;
		a *= a;
		b >>= 1;
	}
	return ret;
}

int64_t gcd(int64_t a, int64_t b) {
	int64_t swap;
	while(b) {
		swap = a;
		a = b;
		b = swap % b;
	}
	return a;
}
int main() {
	int64_t N, P;
	cin >> N >> P;
	if (N == 1) cout << P;
	else if (N >= 40) cout << 1; // 2^40 > 10^12なので
	else {
		int64_t ans = 1;
		for (int64_t i = 1, j = 1;(j = pow(i, N)) <= P;++ i) if (P % j == 0) ans = i;
		cout << ans;
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

逆に最大公約数を考える
するとその数をN乗した値がPの約数かで判定できる
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x,y;
    cin>>x>>y;
    ll d = x/y;
       d = x - (y*d);
    ll ans = abs(d-y);
    if(ans<=d) cout<<ans<<endl;
    else cout<<d<<endl;


return 0;
}


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

int main(){
	long long a;
	cin>>a;
	long long ar[a];
	for(int i=0;i<a;i++){
		cin>>ar[i];
	}
	long long sum=0;
	for(int i=0;i<a;i++){
		for(int j=i+1;j<a;j++){
			sum+=(ar[i]*ar[j]);
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[]A = new int[N];
		int[]B = new int[N];
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			int a1 = int.Parse(str2[0])-1;
			string s1 = str2[1];
			if(s1=="WA" && B[a1] == 0){
				A[a1]++;
			} else if(s1=="AC"){
				B[a1] = 1;
			}
		}
		int ans1 = 0;
		int ans2 = 0;
		for(var i=0;i<N;i++){
			if(B[i]==1){
				ans1++;
				ans2 += A[i];
			}
		}
		Console.WriteLine(ans1+" "+ans2);
	}
}

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

int main()
{
	string s;
	cin >> s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string op;
		cin >> op;
		if (op == "print")
		{
			int start, e;
			cin >> start >> e;
			for (int j = start; j <= e; j++)
			{
				cout << s[j];
			}
			cout << endl;
		}
		if (op == "replace")
		{
			int start, end;
			cin >> start >> end;
			string rep;
			cin >> rep;
			for (int i = start,j = 0; i <=end; i++)
			{
				s[i] = rep[j++];
			}
		}
		if (op == "reverse")
		{
			int start, end;
			cin >> start >> end;

			string subs = s.substr(start, end + 1 - start);
			
			for (int i = start,j = subs.size() - 1; j != -1; i++,j--)
			{
				s[i] = subs[j];
			}

		}
	}
	return 0;
}

Measured memory_bytes: 3220
dict = {"A":1,"C":2,"G":3,"T":4}
def a2n(a):
	ans = 0
	for i in range(len(a)):
		ans += dict[a[i]]*4**i
	return ans
	
n = int(raw_input())
ls = [0 for i in range(6710886)]
for i in range(n):
    inp = raw_input()
    if inp[0] == "i":
        ls[a2n(inp[7:])] = 1
    else:
        print "yes" if ls[a2n(inp[5:])] else "no"
            

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

int main() {
  long long n;
  cin >> n;
  vector<char> c;

  while ( n > 0 ) {
    long long r = n%26;
    n /= 26;
    r--;
    if ( r == -1 ) {
      n--;
      r = 25;
    }
    c.push_back('a'+r);
  }

  for ( int i = c.size()-1; i >= 0; i-- ) {
    cout << c[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k=nxt();
    ll test=0;
    for(int i=1;i<=k;i++)
        for(int j=1;j<=k;j++)
            for(int x=1;x<=k;x++)
                test+=__gcd(__gcd(i,j),x);
        cout<<test<<endl;
    
    return 0;   
}




 
 


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication51
{
    class Program
    {
        static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int s = 0;
            for(int c = 0; c < a; c++)
            {
                int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray();
                b += d[0] - d[1];
                if (b > s) s = b;
                if (b < 0) { s = 0; break; }
            }
            Console.WriteLine(s);
        }
    }
}

Measured memory_bytes: 9636
import java.util.*;

public class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String [] args){
		int a,b,c;
		a=s.nextInt();
		b=s.nextInt();
		c=s.nextInt();
		int fiv=0,sev=0;
		if(a==5)fiv++;
		if(a==7)sev++;
		if(b==5)fiv++;
		if(b==7)sev++;
		if(c==5)fiv++;
		if(c==7)sev++;
		if(fiv==2&&sev==1)System.out.println("YES");
		else System.out.println("NO");
	}
}

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

struct Student {
  string name;
  int no, point;
};

// a < b ならtrueを返す
bool comp(const Student& a, const Student& b) {
  if (a.name != b.name)
    return a.name < b.name; // 高い順に並べたいので演算子を逆に
  if (a.point != b.point)
    return a.point > b.point; // 同様に比較演算子を反転
  return a.no < b.no;
}

int main() {
  int n;
  int i;
  cin >> n;
  vector<Student> vec(n+1);
  for (i = 1; i <= n; i++){
    vec[i].no= i;
    cin >> vec[i].name >> vec[i].point;
  }
  sort(vec.begin(), vec.end(), comp);

  for (int i = 1; i < vec.size(); i++) {
  	printf("%d\n",vec[i].no);
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

score = 0

for i in range(0, N):
    score += B[A[i]-1]
    if i != 0 and A[i] == A[i-1] + 1:
        score += C[A[i-1]-1]

print(score)

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

void start() {
	ios::sync_with_stdio(false); cin.tie(0);
	cout<<fixed<<setprecision(10);
}

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define ii pair<int, int>
#define ll long long
#define endl '\n'
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

int main() {
	start();
	
	string s,t;
	cin>>s>>t;
	int n = s.size();
	int flag = 0;

	for (int i = 0 ; i < n ; ++i) {
		if (s[i] != t[i]) {cout<<"No"; flag = 1; break;}
	}
	if (flag == 0) cout<<"Yes";


}

// by Freyam

Measured memory_bytes: 3644
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = double(a) / double(b);
    cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
    return 0;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  string S;cin>>S;
  int cnt=0;
  rep(i,S.size()-1){
    if(S[i]!=S[i+1])cnt++;
    else if(S[i]==S[i+1])continue;
  }
  cout<<cnt<<endl;
}





Measured memory_bytes: 512
N = int(input())
As = list(map(int, input().split()))
All = sum(As)
odd = 0
for i in range(0, N+1, 2):
    odd += As[i]
iprv = (odd-All//2)*2
ans = []
ans.append(iprv)
for j in range(N-1):
    ik = (As[j]-iprv//2)*2
    iprv = ik
    ans.append(iprv)
print(*ans)

Measured memory_bytes: 14092
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Dice dice = new Dice(sc);
        if(check(dice)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
    
    public static boolean check(Dice dice) {
        char[] pat = {'N','N','E','E','E','N'};
        for(char p:pat){
            if(Arrays.equals(dice.data[0], dice.data[1])){
                return true;
            }
            dice.roll(0, p);
            for(int i = 0; i < 4; i++){
                if(Arrays.equals(dice.data[0], dice.data[1])){
                    return true;
                }
                dice.roll(0, 'Z');
            }
        }
        return false;
    }
}

class Dice {
    static int[][] data;

    public Dice(Scanner sc){
        data = new int[2][6];
        for(int i = 0; i < data.length; i++){
            for(int j = 0; j < data[i].length; j++){
            data[i][j] = sc.nextInt();
            }
        }
    }

    public static void roll(int n, char p) {
        int temp = data[n][0];
        switch(p){
            case 'E':
                data[n][0] = data[n][2];
                data[n][2] = data[n][5];
                data[n][5] = data[n][3];
                data[n][3] = temp; break;
            case 'W':
                data[n][0] = data[n][3];
                data[n][3] = data[n][5];
                data[n][5] = data[n][2];
                data[n][2] = temp; break;
            case 'S':
                data[n][0] = data[n][1];
                data[n][1] = data[n][5];
                data[n][5] = data[n][4];
                data[n][4] = temp; break;
            case 'N':
                data[n][0] = data[n][4];
                data[n][4] = data[n][5];
                data[n][5] = data[n][1];
                data[n][1] = temp; break;
            case 'Z':
                temp = data[n][1];
                data[n][1] = data[n][2];
                data[n][2] = data[n][4];
                data[n][4] = data[n][3];
                data[n][3] = temp; break;
            default:
        }
    }
}

Measured memory_bytes: 26164
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
int n;
int A[50000010];
char s[500010];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  scanf("%s",s+1);
  n=strlen(s+1);
  for(int i=1;i<=n;++i) A[n-i+1]=s[i]-'0';
  int cnt=n,t=0,tot=0;
  for(int i=1;i<=n;++i) {
    int g=(A[i]*9+t)/10;
    A[i]=(A[i]*9+t)%10;
    t=g;
    tot+=A[i];
  }
  if(t) A[++cnt]=t,tot+=t;
  for(int i=1;i<=n*9;++i) {
    t=9;
    for(int j=1;j<=cnt;++j) {
      int g=(A[j]+t)/10;
      tot-=A[j];
      A[j]=(A[j]+t)%10;
      tot+=A[j];
      t=g;
      if(!t) break;
    }
    if(t) A[++cnt]=t,tot+=t;
    if(tot<=i*9) return printf("%d\n",i),0;
  }
  return 0;
}


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

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    string ans = "APPROVED";

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

    for (int i = 0; i < n; ++i) {
        if (a[i] % 2 == 0) {
            if (a[i] % 3 == 0 || a[i] % 5 == 0) continue;
            else {
                ans = "DENIED";
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
using namespace std;

int ar[22][22];
lli dp[22][2097155];
int n;

lli func(int i,int mask)
{
    if(i==n)
    {
        if(1<<n == mask+1)
            return 1;
        else return 0;
    }
    if(dp[i][mask]!=-1)
        return dp[i][mask];
    lli ret = 0;
    for(int j=0;j<n;j++)
    {
        if(ar[i][j] && !(mask & (1<<j)))
        {
            ret += func(i+1,mask|(1<<j));
            ret %= mod;
        }
    }
    return dp[i][mask] = ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    cin >> n;

    mem(dp,-1);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            cin >> ar[i][j];
        }
    }

    lli ans = func(0,0);
    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 364100
import java.util.Scanner;
 
class Main{
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int[] x = new int[3];
     x[0] = scan.nextInt();
     x[1] = scan.nextInt();
     x[2] = scan.nextInt();
     java.util.Arrays.sort(x);
     System.out.println(x[0] + " " + x[1] + " " + x[2]);
    }
}



Measured memory_bytes: 26128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	const mod = 1000000007
	xm := make(map[int]int)
	xm[0] = 3
	ans := 1
	for i := 0; i < n; i++ {
		a := scanInt()
		ans *= xm[a]
		ans %= mod
		xm[a]--
		xm[a+1]++
	}
	fmt.Println(ans)
}


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

int main() {
  int a, b, c, d;
  cin >> a;
  d = a / 1000;
  c = (a - d * 1000) / 100;
  b = (a - d * 1000 - c * 100) / 10;
  a = a - d * 1000 - c * 100 - b * 10;


  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    i64 N, W;
    cin >> N >> W;
    vector<vector<i64>> V(4, vector<i64>(1, 0));

    i64 w1, v1; 
    cin >> w1 >> v1; 
    V[0].emplace_back(v1);
    rep(i, N-1){
        i64 w, v; cin >> w >> v;
        V[w - w1].emplace_back(v);
    } 

    rep(i, 4) sort(V[i].begin() + 1, V[i].end(), greater<i64>());
    rep(i, 4) rep(j, V[i].size() - 1) V[i][j+1] += V[i][j];

    i64 ans = 0; 
    rep(i, V[0].size()){
        rep(j, V[1].size()){
            rep(k, V[2].size()){
                rep(l, V[3].size()){
                    i64 w = w1 * i + (w1+1) * j  + (w1+2) * k + (w1+3) * l;
                    if(w > W) continue;

                    ans = max(ans, V[0][i] + V[1][j] + V[2][k] + V[3][l]);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
K=int(input())
a_i=7%K
i=1
if a_i==0:
	exit(print(1))
while True:
	i+=1
	a_i=(10*a_i+7)%K
	if a_i==0:
		print(i)
		exit()
	if i>=K:
		print(-1)
		exit()




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

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    long long br=0;
    cin >> n;
    vector<long long> v(n);
    vector<long long> g(200001,0);
    for (int i=0;i<n;i++)
    {
        cin >> v[i];
        g[v[i]]++;
    }
    for (int i=1;i<=200000;i++)
        br+=g[i]*(g[i]-1)/2;
    for (int i=0;i<n;i++)
        cout << br - g[v[i]]*(g[v[i]]-1)/2 + (g[v[i]]-1)*(g[v[i]]-2)/2 << '\n';
}


Measured memory_bytes: 5760
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const long long MOD = 1000000007;

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

long long modPow(int n, int num) {
    if (num == 0) return 1;
    long long res = modPow(n, num / 2);
    if (num % 2 == 0) res = (res * res) % MOD;
    else res = (((res * res) % MOD) * n) % MOD;
    return res;
}

int main() {
    int N; cin >> N;
    vector<long long> A(N), B(N);
    rep(i, N)cin >> A[i] >> B[i];
    // 傾きが対になっているペアを保存
    map<pair<long long, long long>, pair<int, int>> mp;

    // (0, 0)の数
    int zero = 0;
    rep(i, N) {
        if (A[i] == 0 && B[i] == 0)++zero;
        else if (A[i] == 0)++mp[make_pair(1, 0)].second;
        else if (B[i] == 0)++mp[make_pair(1, 0)].first;
        else {
            // gcdは正の数を引数に渡した方が良さそうか
            long long g = gcd(A[i], B[i]);
            A[i] /= g;
            B[i] /= g;
            if (B[i] < 0) {
                A[i] = -A[i];
                B[i] = -B[i];
            }
            if (A[i] > 0)++mp[make_pair(A[i], B[i])].first;
            else ++mp[make_pair(B[i], -A[i])].second;
        }
    }

    long long ans = 1;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
        int p1 = itr->second.first;
        int p2 = itr->second.second;
        ans *= (modPow(2, p1) - 1 + modPow(2, p2)) % MOD;
        ans %= MOD;
    }
    // すべてのイワシを選ばなかった場合を除く
    ans = (ans + zero - 1) % MOD;
    if (ans < 0)cout << ans + MOD;
    else cout << ans;
}

Measured memory_bytes: 18600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,D,X;
  cin>>N>>D>>X;
  vector<int> chocolate(D+1); //〇日目に食べるチョコレート
  for(int i=0; i<N; i++){ //生徒N人の学生
    int a;
    cin>>a;
    for(int j=0; j*a+1<=D; j++){
      chocolate.at(j*a+1)++;
    }
  } //chocolateに個数が入る
  int sum=0;
  for(int i=1; i<=D; i++){
    sum+=chocolate.at(i);
  }
  cout<<sum+X<<endl;
}


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

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	int t=1;
	long n;
	ll temp;
	ll d;
	ll p, q;

	while(t--)
	{
		long int ans=0;
		ll curr;
		cin>>n>>d;
		for(long int i = 0; i<n; i++)
		{
			cin>>p>>q;
			curr = p*p + q*q;
			
			if(curr<=d*d) ans++;

		}
		cout<<ans;
	}

	return 0;
}

Measured memory_bytes: 3648
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))

l=[v[i]-c[i] for i in range(n)]
a=0
b=0
for i in range(n):
    if l[i] >=0:
        a +=v[i]
        b +=c[i]

print(a-b)

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

int main() {
  int N;cin>>N;
  int m=0,wa=0;
  for(int i=0; i<N; i++){int a;cin>>a;wa+=a;m=max(m,a);}
  cout<<(wa-m>m? "Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    int a[(int)pow(10,5)];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int cache = 0;
    bool flag = false;
    while(!flag){
        flag = false;
        for(int i = 0; i < n - 1; i++){
            if(a[i] > a[i + 1]){
                cache = a[i];
                a[i] = a[i + 1];
                a[i + 1] = cache;
                flag = true;
            }
        }
    }
    double center = a[n - 1] / 2;
    double min_diff = 1145141919.0;
    double diff = 0.0;
    int x = 0;
    for(int i = 0; i < n - 1; i++){
        diff = fabs(a[i] - center);
        if(diff < min_diff){
            min_diff = diff;
            x = i;
        }
    }
    cout << a[n - 1] << " " << a[x];
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define toupper(S) transform(S.begin(),S.end(),S.begin(),toupper)
#define tolower(S) transform(S.begin(),S.end(),S.begin(),tolower)

int main() {
	int N;
	cin >> N;
	vector<int>D(N);
	rep(i, N) {
		cin >> D[i];
	}
	int M;
	cin >> M;
	vector<int>T(M);
	rep(i, M) {
		cin >> T[i];
	}
	sort(D);
	rep(i, M) {
		if (upper(D, T[i]) - lower(D, T[i]) == 0) {
			cout << "NO" << endl;
			return 0;
		}
		D.erase(upper(D,T[i])-1);
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def main():
	A, B = MAP()
	print(lcm(A, B))

if __name__ == '__main__':
	main()

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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll  a,b,c,s,t,i,j,k,x,y,z;
 ll A,B,C,S,T,X,Y,Z;
 ll count;
signed main(){
	
	cin>>a;

	x=100;

	for(i=0;x<a;i++){

		x=x+x/100;

	}

	cout<<i;

 return 0;
}


Measured memory_bytes: 3568
def f(n, a):
    x = list(sorted(set(a)))
    n_sub_half = n * (n + 1) // 2 // 2
    n_plus_minus = n * 2 + 1
    Li = 0
    Ri = len(x)
    while Ri > Li + 1:
        i = (Li + Ri) // 2
        xi = x[i]
        cnt_sum = [0] * n_plus_minus
        cumsum = 0
        cnt_sum[cumsum] = 1
        judge = 0
        s = 0
        for ak in a:
            if ak >= xi:
                cumsum += 1
                s += cnt_sum[cumsum] + 1
            else:
                cumsum -= 1
                s -= cnt_sum[cumsum + 1] - 1
            cnt_sum[cumsum] += 1
            judge += s
            if judge >= n_sub_half:
                Li = i
                break
        else:
            Ri = i
    print(x[Li])

n = int(input())
a = list(map(int, input().split()))
f(n, a)

Measured memory_bytes: 14608
qhsd = list(map(int, input().split()))
n = int(input()) * 4

m_qhsd = [[qhsd[3], 3], [qhsd[2] * 2, 2], [qhsd[1] * 4, 1], [qhsd[0] * 8, 0]]
qs = [1, 2, 4, 8]
m_qhsd.sort()
ans = 0
while n != 0:
    tmp = m_qhsd.pop(0)
    ans += n // qs[tmp[1]] * qhsd[tmp[1]]
    n %= qs[tmp[1]]
print(ans)

Measured memory_bytes: 3064
#
class Dice:
    def __init__(self,list):
        self.list = []
        for i in range(6):
            self.list.append(list[i])

    def rotate(self,dir):
        if dir == "N":
            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]
        elif dir == "S":
            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]
        elif dir == "W":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]
        elif dir == "E":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        elif dir == "H":
            self.list[1], self.list[2], self.list[4], self.list[3] = self.list[2], self.list[4], self.list[3], self.list[1]
        elif dir =="V":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        else:
            pass

    def show(self):
        print("D:{}".format(repr(self.list)))

    def isface(self,f):
        if f in self.list:
            return True
        else:
            return False

    def matchone(self, f):
        if self.isface(f) == False:
            return False
        if f == self.list[0]:
            pass
        elif f == self.list[1]:
            self.rotate("N")
        elif f == self.list[2]:
            self.rotate("W")
        elif f == self.list[3]:
            self.rotate("E")
        elif f == self.list[4]:
            self.rotate("S")
        else:
            self.rotate("N")
            self.rotate("N")
        return True

    def matchtwo(self, f):
        if self.isface(f) == False:
            return False
        if self.list[1] ==f:
            return True
        for i in range(3):
            self.rotate("H")
            if self.list[1] ==f:
                return True
        return False


l = [ int(x) for x in input().split()]
dice = Dice(l)
num = int(input())

for i in range(num):
    one, two = [int(x) for x in input().split()]
    dice.matchone(one)
    #dice.show()
    dice.matchtwo(two)
    #dice.show()
    print(dice.list[2])



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

void main_()
{
    int N;
    cin >> N;
    vector<tuple<string, int, int>> restaurants; //!< レストラン名、得点、番号
    for (int i = 0; i < N; i++) {
        int p;
        string s;
        cin >> s >> p;
        restaurants.emplace_back(move(s), p, i + 1);
    }
    sort(begin(restaurants), end(restaurants),
        [](auto&& r1, auto&& r2) {
            auto name1 = get<0>(r1);
            auto name2 = get<0>(r2);
            if (name1 != name2) {
                // 辞書順
                return name1 < name2;
            } else {
                // 高得点順
                auto score1 = get<1>(r1);
                auto score2 = get<1>(r2);
                return score1 > score2;
            }
        });
    for (auto&& r : restaurants) {
        cout << get<2>(r) << endl;
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
def solve():
    import sys
    file_input = sys.stdin
    
    while True:
        w, h = map(int, file_input.readline().split())
        if w == 0 and h == 0:
            break
        
        width = 2 * w + 1
        
        maze = '1' * width
        line = file_input.readline()
        maze += '1' + line.rstrip() + ' 1'
        for _ in range(h - 1):
            line = file_input.readline()
            maze += '1' + line.rstrip() + '1'
            line = file_input.readline()
            maze += '1' + line.rstrip() + ' 1'
        maze += '1' * width
        
        start = width + 1
        goal = len(maze) - width - 2
        
        from collections import deque
        forward_q = deque()
        forward_q.append(start)
        reverse_q = deque()
        reverse_q.append(goal)
        
        forward_rec = [None] * (goal + 1)
        forward_rec[start] = 1
        reverse_rec = [None] * (goal + 1)
        reverse_rec[goal] = 1
        
        adj_move = (1, -1, width, -width)
        
        while forward_q and reverse_q:
            fp = forward_q.popleft()
            fp_len = forward_rec[fp]
            rp = reverse_q.popleft()
            rp_len = reverse_rec[rp]
            
            for move in adj_move:
                wall = maze[fp + move]
                if wall == '0':
                    next_place = fp + move * 2
                    if forward_rec[next_place] == None:
                        if reverse_rec[next_place]:
                            print(fp_len + reverse_rec[next_place])
                            break
                        forward_q.append(next_place)
                        forward_rec[next_place] = fp_len + 1
                wall = maze[rp + move]
                if wall == '0':
                    next_place = rp + move * 2
                    if reverse_rec[next_place] == None:
                        if forward_rec[next_place]:
                            print(rp_len + forward_rec[next_place])
                            break
                        reverse_q.append(next_place)
                        reverse_rec[next_place] = rp_len + 1
            else:
                continue
            break
        else:
            print(0)

solve()


Measured memory_bytes: 6140
#include <iostream>
#include <set>
#include <map>
using namespace std;

int Q;
int flag[200005];
long long int a[200005], b[200005];
set<long long int> S;

map<int, long long int> val;
map<long long int, int> id;

long long int BP[500005];

void UPDATE_BP(int k, long long int v) {

	
	while (k <= Q) {
		BP[k] += v;
		k += k&(-k);
		//cout << k << endl;
	}
	//cout << "check" << endl;
}

long long int SUM_BP(int K) {
	long long int tmp = 0;

	while (K > 0) {
		tmp += BP[K];
		K -= K&(-K);
	}
	return tmp;
}

long long int BQ[500005];
void UPDATE_BQ(int k, long long int v) {
	while (k <= Q) {
		BQ[k] += v;
		k += k&(-k);
	}
}

long long int SUM_BQ(int K) {
	long long int tmp = 0;

	while (K > 0) {
		tmp += BQ[K];
		K -= K&(-K);
	}
	return tmp;
}



int BINARY_SEARCH(void) {

	int left = 0, right = Q+1;
	int med;
	while (right - left > 1) {
		med = (left + right) / 2;
		long long int D = SUM_BP(med);
		long long int U = SUM_BP(Q + 1) - D;
		//cout << "med= " << med << "D= " << D << " U= " << U << endl;
		if (D-U>=0) {
			right = med;
		}
		else {
			left = med;
		}
	}

	return right;
}

int main(void) {

	cin >> Q;
	for (int i = 1; i <= Q; i++) {
		cin >> flag[i];
		if (flag[i] == 1) { cin >> a[i] >> b[i]; 
		S.insert(a[i]);
		}
	}


	S.insert(-9999999999999);

	int q = 0;
	for (auto y : S) {
		id[y] = q;
		val[q] = y;
		q++;
	}

	long long int sum_b = 0;

	for (int i = 1; i <= Q; i++) {
		//cout << "i= " << i << endl;
		if (flag[i] == 1) {
			UPDATE_BP(id[a[i]], 1);
			UPDATE_BQ(id[a[i]], a[i]);
			sum_b += b[i];
		}
		else { // flag ==2
			int pos = BINARY_SEARCH();
			cout << val[pos] << " ";
			cout<<SUM_BQ(Q) - SUM_BQ(pos - 1) - (SUM_BP(Q) - SUM_BP(pos - 1))*val[pos]
				- SUM_BQ(pos - 1) + SUM_BP(pos - 1)*val[pos] + sum_b << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 30336
import Control.Monad
import Data.List

solve :: [Int] -> [Int] -> Int
solve ls rs = max 0 (minimum rs - maximum ls + 1)

getInts :: IO [Int]
getInts = getLine >>= mapM readIO . words

main :: IO ()
main = do
  [n, m] <- getInts
  [ls, rs] <- transpose <$> replicateM m getInts
  print $ solve ls rs


Measured memory_bytes: 64892
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define rep(x, l, r) for (x = l; x < r; x++)

const ll mod=1000000007;

void solve()
{
	ll i, j, k, l, m, n, x, y, u, v, r, p,a,b,aa,bb;
	char ch;
    cin>>ch;
    if(ch>='a' && ch<='z')cout<<'a';
    else cout<<'A';




}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3648
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
C = ["" for j in range(H)]

Step = [
    [-1, -1],
    [-1,  0],
    [-1,  1],
    [0,   1],
    [1,   1],
    [1,   0],
    [1,  -1],
    [0,  -1],
]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            C[i] += "#"
        else:
            ans = 0
            for one in Step:
                y = i + one[0]
                x = j + one[1]
                if 0 <= y and y < H and 0 <= x and x < W:
                    if S[y][x] == "#":
                        ans += 1
            C[i] += str(ans)
        
for i in range(H):
    print(C[i])


Measured memory_bytes: 3064
#include<cstdio>
#include<map>
#include<set>
using namespace std;

int main() {
  int n,t;
  while(scanf("%d", &n), n) {
    map<int,int> m;
    int ans = -1;
    for(int i=0; i<n; ++i) {
      scanf("%d", &t);
      m[t]++;
      if(m[t] > (n/2)) ans = t;
    }

    if(ans == -1) puts("NO COLOR");
    else printf("%d\n", ans);
  }
}

Measured memory_bytes: 1848
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    vector<vector<int>>chr(26);
    for(int i=0;i<s.size();i++)chr[s[i]-'a'].push_back(i);
    long long x=0;
    int p=-1;
    for(int i=0;i<t.size();i++){
        if(chr[t[i]-'a'].size()==0){
            cout<<"-1"<<endl;
            return 0;
        }
        if(p>=chr[t[i]-'a'].back()){
            x+=chr[t[i]-'a'][0]+s.size()-p;
            p=chr[t[i]-'a'][0];
        }
        else{
            x+=*upper_bound(chr[t[i]-'a'].begin(),chr[t[i]-'a'].end(),p)-p;
            p=*upper_bound(chr[t[i]-'a'].begin(),chr[t[i]-'a'].end(),p);
        }
    }
    cout<<x<<endl;
    return 0;
}

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

using namespace std;

int n;
int a[200010];
long long k;
int num[200010];
bitset<200010> vis;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    cin >> n >> k;

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

    int x = 1, cyc = 0;

    do{
        vis[x] = true;
        num[cyc++] = x;
        x = a[x];
    } while (!vis[x]);

    int last = x;
    x = 1;
    int ct = 0;

    while(x != last){
        x = a[x];
        --k;
        ++ct;

        if(k == 0) cout << x << "\n", exit(0);
    }

    for(int i = ct; i < cyc; i++) num[i - ct] = num[i];
        cyc -= ct;
    
    cout << num[k % cyc] << "\n";

    return 0;
}

Measured memory_bytes: 5180
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int deg[10000];
vector<int>G[10000];
int main(){
	int n,a,b,c[10000],m=0,d[10000];
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>a>>b;
		deg[--a]++;
		deg[--b]++;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=0;i<n;i++)
		cin>>c[i];
	sort(c,c+n);
	for(int i=0;i<n;i++){
		int mindeg=1e9,pos=-1;
		for(int j=0;j<n;j++){
			if(deg[j]<mindeg){
				mindeg=deg[j];
				pos=j;
			}
		}
		d[pos]=c[i];
		m+=c[i]*mindeg;
		for(int j=0;j<G[pos].size();j++)
			deg[G[pos][j]]--;
		deg[pos]=1e9;
	}
	cout<<m<<endl;
	for(int i=0;i<n;i++)
		cout<<d[i]<<(i+1==n?'\n':' ');
}


Measured memory_bytes: 1024
n = int(input())
array = [int(i) for i in input().split()]
last = array[n-1]
ans = "Yes"

for i in range(n-1):
  if array[i]>array[i+1] or array[i]>last:
    array[i] -= 1
    
for i in range(n-1):
  if array[i] > array[i+1]:
    ans ="No"
    
print(ans)

  

Measured memory_bytes: 14396
//互いに正方形から正方形へ、４近傍にある正方形をいくつかたどることで到達できる。
//ということは、0番の正方形とつながっている正方形が存在する。
//どれか一つの正方形の位置を(0,0)としてあげれば、(置き方は一意なので)、やるだけ。
#include<iostream>
#define int long long
using namespace std;

int n;	//1 <= n <= 200
int num[201], d[201];
int dy[4] = {0, 1, 0, -1};
int dx[4] = {-1, 0, 1, 0};

signed main()
{
	while( cin >> n )
	{
		if ( !n )
		{ 
			return 0;
		}
		
		int i, j;
		for( i = 1; i < n; i++ )
		{
			//正方形iが正方形num[i]から(dy[d[i] ], dx[d[i] ])移動したところにある。
			cin >> num[i] >> d[i];
		}
		
		bool deci[201] = {false};
		int y[201];
		int x[201];
		
		deci[0] = true;
		y[0] = 0; x[0] = 0;
		
		for( int cnt = 1; cnt < n; cnt++ ) {
			for( i = 1; i < n; i++ )
			{
				if ( deci[num[i] ] )
				{
					deci[i] = true;
					y[i] = y[num[i]] + dy[d[i]];
					x[i] = x[num[i]] + dx[d[i]];
					//cout << i << " " << y[i] << " " << x[i] << endl;
				}
			}
		}
		
		int miny = 1919810, maxy = -8332521, minx = 114514, maxx = -114514;
		for( i = 0; i < n; i++ )
		{
			miny = min(miny, y[i]);
			maxy = max(maxy, y[i]);
			minx = min(minx, x[i]);
			maxx = max(maxx, x[i]);
		}
		
		//cout << miny << " " << maxy << " " << minx << " " << maxx << endl;
		
		int h = maxy - miny + 1;
		int w = maxx - minx + 1;
		
		cout << w << " " << h << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        
        //set array
        String[] st = br.readLine().split(" ");
        int[] array = new int[n];
        for (int i = 0; i < n; i++){
            int a = Integer.parseInt(st[i]);
            array[i] = a;
        }
        
        int count = bubbleSort(array);
        printArray(array);
        System.out.println(count);
        
    }
    static void printArray(int[] arr){
        for (int i = 0; i < arr.length - 1; i++){
            System.out.print(arr[i]);
            System.out.print(" ");
        }
        System.out.println(arr[arr.length-1]);
    }
    static void printArray2(int[] arr){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length - 1; i++){
            sb.append(arr[i]);
            sb.append(" ");
        }
        sb.append(arr[arr.length - 1]);
        System.out.println(sb.toString());
    }
    static int bubbleSort(int[] arr){
        //bubble sort and count swaps
        int swapcnt = 0;
        for (int i = 0; i < arr.length; i++){
            for (int j = arr.length - 1; j > i; j--){
                if ( arr[j] < arr[j-1]){
                    swap(arr, j, j - 1);
                    swapcnt += 1;
                }
            }
        }
        return swapcnt;
    }
    static void swap(int[] arr, int i, int j){
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}

Measured memory_bytes: 17060
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans = 30000;
    char[] s = sc.next().toCharArray();
    int sl = s.length;
    char[] t = sc.next().toCharArray();
    int tl = t.length;

    for (int cnt = 0; cnt < (sl - tl + 1); cnt++) {
      int tmp = 0;
      for (int j = 0; j < tl; j++) {
        if (s[cnt + j] != t[j]) {
          tmp++;
        }
      }
      ans = Math.min(ans, tmp);
    }

    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 35644
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    print(1900 * m * 2 ** m + 100 * (n - m) * 2 ** m)


if __name__ == '__main__':
    solve()


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

using namespace std;

typedef long long ll;

ll md = 1000000007;

vector<ll> kai(100003);

int main(int, char**)
{
	ll n, ans;
	cin >> n;
	vector<int> x(n);
	list<pair<ll, ll>> p;
	for ( int i = 0; i < n; ++i)
		cin >> x[i];

	sort(x.begin(), x.end());

	int f = 1;
	int b = n-2;
	int mm = x[0];
	int mx = x[n-1];
	pair<ll, ll> k;
	while (b >= f) {
		ll y = mx - mm - x[b];
		ll z = x[f] + mx - mm;
		cerr << y << "," << z << endl;
		if (y > z) {
			k.first = mx;
			k.second = mm;
			mx -= mm;
			mm = x[f];
			f++;
		} else {
			k.first = mm;
			k.second = mx;
			mm -= mx;
			mx = x[b];
			b--;
		}

		p.push_back(k);
	}
		if (mx > mm) {
			k.first = mx;
			k.second = mm;
		} else {
			k.first = mm;
			k.second = mx;
		}
		p.push_back(k);
	cout << (k.first - k.second);
	list<pair<ll,ll>>::iterator it2 = p.begin();
	while (it2 != p.end()) {
		cout << "\n" << it2->first << " " << it2->second;
		++it2;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 7808
#include<iostream>
#include<string>
using namespace std;
int main(){
  string t,h;
  int n,pt=0,ph=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> t >> h;
    if(t==h)pt++,ph++;
    else if(t>h) pt+=3;
    else ph+=3;
  }
  cout << pt << " " << ph << endl;
}


Measured memory_bytes: 3180
/*
AizuOnline A0113
Maximum Sum Sequence
*/
#include <stdio.h>
long hijosuu;
long josuu;
int       quo[100];
long rem[100];
int js;             // junkansetu start
int je;             // junkansetu end

// write junkansetu
write_yamagata()
{  int i;
  printf("\n");
  for(i=1;i<=js-1;i++)
    printf(" ");
  for(i=0;i<je-js;i++)
    printf("^");
  printf("\n");
}
main()
{
  int i,j;
  long q,r;
  int flag;      // seisuubu 0 shousuubu 1

    while (EOF != scanf ("%ld %ld",&hijosuu,&josuu))
    {
      flag=0;
      i=0;
 
      while(1)
	{
	  q = hijosuu / josuu;
	  r= (hijosuu % josuu);
	  hijosuu = 10 * r;
	  //if(flag==1)
	  //  printf("%lld",q);
	  if(r==0)
	    {
	      printf("%ld\n",q);
	      break;
	    }
	  if(flag==0)              //print seisuubu
	    {  // printf(".");        //print comma :iranai
	      flag = 1;
	      i=0;
	      continue;
	    }
	  i++;
	  if(flag)
	    {
	      quo[i]=q;
	      rem[i]=r;
	    }
	    
	  if(i>1)
	    for(j=i-1;j>=1;j--)
	      if(quo[i]==quo[j] && rem[i]==rem[j])
		{
		  js=j;
		  je=i;
		  write_yamagata();
		  goto END_JUNKAN;
		}
	PRINT:
	  if(flag)
	    printf("%ld",q);
	}
    END_JUNKAN: ;
      // printf("\njs je=%d %d\n",js,je);
    }


return(0);
}

Measured memory_bytes: 600