akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace ITP1_1_A
{
    class Program
    {

        static private int midterm_Examination;
        static private int final_Examination;
        static private int makeup_Examination;
        static private bool Finish = false;

        static void Main(string[] args)
        {
            while (true)
            {
                input_Score();
                if (Finish) return;
                Console.WriteLine(Gradeing());
            }
        }

        static void input_Score()
        {
            string[] score = Console.ReadLine().Split();
            if (int.Parse(score[0]) == -1 && int.Parse(score[1]) == -1 && int.Parse(score[2]) == -1)
            {
                Finish = true;
                return;
            }
            midterm_Examination = int.Parse(score[0]);
            final_Examination = int.Parse(score[1]);
            makeup_Examination = int.Parse(score[2]);
        }
        static string Gradeing()
        {
            if (midterm_Examination == -1 || final_Examination == -1)
            {
                return "F";
            }
            if (80 <= midterm_Examination + final_Examination)
            {
                return "A";
            }
            if (65 <= midterm_Examination + final_Examination && midterm_Examination + final_Examination < 80)
            {
                return "B";
            }
            if (50 <= midterm_Examination + final_Examination && midterm_Examination + final_Examination < 65)
            {
                return "C";
            }
            if (30 <= midterm_Examination + final_Examination && midterm_Examination + final_Examination < 50)
            {
                if (50 <= makeup_Examination)
                {
                    return "C";
                }
                else
                {
                    return "D";
                }
            }
            if (midterm_Examination + final_Examination < 30)
            {
                return "F";
            }
            return "ERROR";
        }
    }
}



Measured memory_bytes: 7856
h, w, k = map(int, input().split())

c = []
for i in range(h):
    c.append(input())
ans = 0


#print(c)

'''
入力例1

2 3 2
..#
###

に対して
print(c)
を実行すると
['..#', '###']
と出力される
'''
for i in range(pow(2, h)):
    for j in range(pow(2, w)):
        count = 0
        for p in range(h):
            for q in range(w):
                if ((i & (1 << p)) == 0 and (j & (1 << q)) == 0 and c[p][q] == '#'):
                    count += 1
        
        if (k == count):
            ans += 1

print(ans)
        


Measured memory_bytes: 9216
import java.util.Scanner;

class Main{

  public static void main(String[] args){

    Scanner scan = new Scanner(System.in);
   
  	int a = scan.nextInt();
  	int b = scan.nextInt();
	int c = scan.nextInt();
  	int i = 0;
  	
  	if(a > b){
  		i = a;
  		a = b;
  		b = i;
  	}
  	if(b > c){
  		i = b;
  		b = c;
  		c = i;
	}
  	if(a > b){
  		i = a;
  		a = b;
  		b = i;
 	}
  	  	System.out.println(a + " " + b + " " + c);
  }
}

Measured memory_bytes: 26260
import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

x = line_to_list()
print(x.index(0)+1)

Measured memory_bytes: 8988
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<string> b(a);
  rep(i,a)
    cin>>b[i];
  bool c=1;
  rep(i,a-1){
  if(b[i][b[i].size()-1]!=b[i+1][0])
    c=0;
  }
  sort(all(b));
  rep(i,a-1){
  if(b[i]==b[i+1])
    c=0;
  }
  YesNo(c);
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 405;
ll c[N];
ll dp[N][N];
ll inf = 1e17;

ll solve(int i, int j)
{
    if(i == j)
        return 0;
    ll &ans = dp[i][j];
    if(ans != -1)
        return ans;
    ans = inf;
    ll have = c[j];
    if(i)
        have -= c[i - 1];
    for(int k = i; k < j; k++)
        ans = min(ans, solve(i, k) + solve(k + 1, j) + have);
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> c[i];
        if(i)
            c[i] += c[i - 1];
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(0, n - 1);
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k,sum=0,sum1=0;
    cin>>a>>b>>c;
    cin>>k;
    sum=c;
    sum1=b;
      if(c>b &&b>a)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    for(int i=1; i<=k; i++)
    {

        if(c<=b)
        {
            c*=2;
        }
        else if(b<=a)
        {
            b*=2;
        }

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


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, q, x, K;
string s, t;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	ll n, h, w;
	cin >> n >> h >> w;

	cout<<(n-h + 1)* (n-w + 1);
}


int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,mod,inv10;
char s[N];
unordered_map<int,int>vis;
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    scanf("%d%d",&n,&mod);
    inv10=qpow(10,mod-2);
    scanf("%s",s+1);
    if(mod==5)
    {
        ll ans=0;
        for(int i=1;i<=n;i++)
            if(s[i]=='5'||s[i]=='0') ans+=i;
        printf("%lld\n",ans);
        return 0;
    }
    else if(mod==2)
    {
        ll ans=0;
        for(int i=1;i<=n;i++)
            if((s[i]-'0')%2==0) ans+=i;
        printf("%lld\n",ans);
        return 0;
    }
    vis[0]++;
    int sum=0;
    ll ans=0,k=1;
    for(int i=1;i<=n;i++)
    {
        k=k*inv10%mod;
        sum=(sum+(ll)(s[i]-'0')*k%mod)%mod;
        ans+=vis[sum];
        vis[sum]++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 896
#!/usr/bin/env python


def read():
    raw_input()
    return map(int, raw_input().split())


def work(vList):
    vList.sort()

    cntDigit = 0
    cntOdd = 0
    
    idx = 0
    while idx < len(vList):
        nex = idx
        while nex < len(vList) and vList[nex] == vList[idx]:
            nex += 1

        if (nex - idx) % 2 == 0:
            cntOdd += 1
        cntDigit += 1

        idx = nex

    print cntDigit - cntOdd % 2


if __name__ == "__main__":
    work(read())


Measured memory_bytes: 11428
#include <cstdio>
#include <cstring>
#include <utility>
#include <cmath>
#include <iostream>
using namespace std;

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

  int t = 0;
  long long int sum = 0;
  while(n > sum){
    t++;
    sum+=t;
    if(n<=sum)
      break;
  }

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin>>str;
  int fi,se;
  bool b_f=false,b_s=false;
  sscanf(str.substr(0,2).c_str(),"%d",&fi);
  sscanf(str.substr(2,2).c_str(),"%d",&se);

  if(1<=fi&&fi<=12){
    b_f=true;
  }
  if(1<=se&&se<=12){
    b_s=true;
  }
  
  if(b_f){
    if(b_s){
      cout<<"AMBIGUOUS"<<endl;
    }else{
      cout<<"MMYY"<<endl;
    }
  }else if(b_s){
    cout<<"YYMM"<<endl;
  }else{
    cout<<"NA"<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable : 4996)  // VSでscanfを使う．
#endif

signed main() {
  int x, a;
  cin >> x >> a;

  if (x < a) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
s = input() # 入力文字列をsに格納
letters = '' # 出力用変数を用意

for i, letter in enumerate(s): # sを1文字ずつ、i（何文字目か）とletter（1文字）に入れる
    if i % 2 == 0: # 何文字目か　の奇数と偶数を判定；2で割って余りがあれば奇数だが、iは0から始まるので偶数のときに
        letters += letter # lettersに入れていく

print(letters)

Measured memory_bytes: 9128
N=gets.to_i

def k(n)
    Math.log10(n).floor + 1
end

min = 10
1.upto(10**5) do |i|
    r,q = N.divmod(i)
    if q == 0
        m = [k(r),k(i)].max
        min = m if m < min
    end
end

puts min

Measured memory_bytes: 1788
s = input()
t = input()
m = len(t)


def check(s, t):
    n = len(s)
    for i in range(n):
        if s[i] != '?' and s[i] != t[i]:
            return False
    return True


cands = []
for i in range(len(s) - len(t) + 1):
    if check(s[i:i + m], t):
        cands.append((s[:i] + t + s[i + m:]).replace('?', 'a'))
if cands:
    cands.sort()
    print(cands[0])
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 3005;

int pw(int x,int k,int mod)
{
	int re=1;
	for(;k;k>>=1,x=(ll)x*x%mod) if(k&1)
		re=(ll)re*x%mod;
	return re;
}
int n,phimod,mod;
int f[maxn][maxn],C[maxn][maxn];

int main()
{
	//freopen("tmp.in","r",stdin);
	//freopen("tmp.out","w",stdout);
	
	scanf("%d%d",&n,&mod); phimod=mod-1;
	C[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	for(int i=0;i<=n;i++) f[i][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++) f[i][j]=((ll)f[i-1][j]+f[i-1][j-1]+(ll)f[i-1][j]*j%mod)%mod;
	}
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		int now=0,oth=pw(2,pw(2,n-i,phimod),mod);
		for(int j=0;j<=i;j++) (now+=(ll)f[i][j]*pw(pw(2,n-i,mod),j,mod)%mod)%=mod;
		now=(ll)now*C[n][i]%mod*oth%mod;
		if(i&1) ans=(ans-now+mod)%mod;
		else ans=(ans+now)%mod;
	}
	printf("%d\n",ans);
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    for(int i =  0; i < n; i++){
        int c, a, n;
        cin >> c >> a >> n;
        int teamCount = 0;
        while(c > 0 && a > 0 && n > 0){
            c--;
            a--;
            n--;
            teamCount++;
        }
        while(c >= 2 && a > 0){
            c-=2;
            a--;
            teamCount++;
        }
        while(c >= 3){
            c-=3;
            teamCount++;
        }
        cout << teamCount << endl;
    }
    return 0;
}

Measured memory_bytes: 3112
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: usize = 1e+9 as usize + 7;

fn calc(
    depth: usize,
    upper_l: usize,
    lower_r: usize,
    l: usize,
    r: usize,
    memo: &mut Vec<Vec<Vec<usize>>>,
) -> usize {
    if memo[upper_l][lower_r][depth] != MOD {
        return memo[upper_l][lower_r][depth];
    }
    let bit = 1 << depth;
    if bit > r || (bit * 2 > r && bit <= r && lower_r == 0) {
        return 0;
    }
    let mut ret = 0;
    if bit > l || (bit * 2 > l && bit <= l && upper_l == 1) {
        ret = 1;
    }
    for i in 0..2 {
        let nlower_r = if (r & bit) > 0 {
            i == 0 || lower_r == 1
        } else {
            i == 0 && lower_r == 1
        };
        let nlower_r = if nlower_r { 1 } else { 0 };
        for j in 0..2 {
            if i == 0 && j == 1 {
                continue;
            }
            let nupper_l = if (l & bit) > 0 {
                j == 1 && upper_l == 1
            } else {
                j == 1 || upper_l == 1
            };
            let nupper_l = if nupper_l { 1 } else { 0 };
            ret = (ret + calc(depth + 1, nupper_l, nlower_r, l, r, memo)) % MOD;
        }
    }
    memo[upper_l][lower_r][depth] = ret;
    // println!("{} {} {} {} {}", depth, upper_l, lower_r, rev, ret);
    return ret;
}

fn main() {
    let l = read::<usize>();
    let r = read::<usize>();
    let mut memo = vec![vec![vec![MOD; 70]; 2]; 2];
    let ans = calc(0, 1, 1, l, r, &mut memo);
    println!("{}", ans);
}


Measured memory_bytes: 4352
/**
 * Author: Behradm
 * Created: 14-04-2020 12:00:37
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout.precision(6);
	cout << fixed;
	int n;
	cin >> n;
	ll res = 0;
	for(int i = 1; i <= n; i++){
		if(i % 3 != 0 && i % 5 != 0)
			res += i;
	}

	cout << res << '\n';
	return 0;
}



Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
    	new A().doIt();
    }
    class A{
    	ArrayList<Integer> array = new ArrayList<Integer>();
    	void eratos(int MAX){ 
    		boolean [] isprime = new boolean[MAX + 1];
    		Arrays.fill(isprime, true);
    		isprime[0] = false;
    		isprime[1] = false;
    		for(int i = 0; i * i <= MAX; i++){
    			if(isprime[i]){
    				for(int j = i * 2; j <= MAX; j+= i){
    					isprime[j] = false;
    				}
    			}
    		}
    		for(int i = 0;i < MAX;i++){
    			if(isprime[i])array.add(i);
    		}
    	}
    	void doIt(){
    		int max = (int)Math.pow(2,15);
        	eratos(max);
        	int cnt[] = new int[max+1];
        	for(int i = 0;i < array.size();i++){
        		for(int j = i;j < array.size();j++){
        			int num = array.get(i) + array.get(j);
        			if(num <= max)cnt[num]++;
        		}
        	}
        	while(true){
        		int n = sc.nextInt();
        		if(n == 0)break;
        		System.out.println(cnt[n]);
        	}
        }
    }
}

Measured memory_bytes: 26856
/***
 *          ___           ___
 *         /\  \         /\  \                                     _____
 *         \:\  \        \:\  \                                   /::\  \       ___           ___
 *          \:\  \        \:\  \                                 /:/\:\  \     /\__\         /\__\
 *      _____\:\  \   ___  \:\  \   ___     ___   ___     ___   /:/ /::\__\   /:/__/        /:/  /
 *     /::::::::\__\ /\  \  \:\__\ /\  \   /\__\ /\  \   /\__\ /:/_/:/\:|__| /::\  \       /:/__/
 *     \:\~~\~~\/__/ \:\  \ /:/  / \:\  \ /:/  / \:\  \ /:/  / \:\/:/ /:/  / \/\:\  \__   /::\  \
 *      \:\  \        \:\  /:/  /   \:\  /:/  /   \:\  /:/  /   \::/_/:/  /   ~~\:\/\__\ /:/\:\  \
 *       \:\  \        \:\/:/  /     \:\/:/  /     \:\/:/  /     \:\/:/  /       \::/  / \/__\:\  \
 *        \:\__\        \::/  /       \::/  /       \::/  /       \::/  /        /:/  /       \:\__\
 *         \/__/         \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
 *
 *      @author      : Dylan Dsouza (dsouzadyn@gmail.com)
 *      @created     : Saturday Feb 16, 2019 22:54:09 IST
 */
#include <bits/stdc++.h>

using namespace std;

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

  unordered_map<int, int> freq;
  int n, tn, m, temp;
  cin >> n >> m;
  int count = 0;
  for(int i = 0; i < n; i++) {
    cin >> tn;
    while(tn--) {
      cin >> temp;
      if(freq.find(temp) != freq.end())
	freq[temp] += 1;
      else
	freq[temp] = 1;
      if (freq[temp] == n) count = count + 1;
    }
  }
  cout << count << endl;

  return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int, int>;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
    char s[100010];
    int i, c;

    scanf("%s", s);

    i = 0;
    while (s[i])
    {
        if (s[i] == 'd')
        {
            if (s[i + 1] == 'r' && s[i + 2] == 'e' && s[i + 3] == 'a' && s[i + 4] == 'm')
                i = i + 5;
            else
                break;
        }
        else if (s[i] == 'e')
        {
            if (s[i + 1] == 'r' && s[i + 2] == 'a')
            {
                if (s[i + 3] == 's' || s[i + 4] == 'e')
                    i = i + 5;
                else
                    break;
            }
            else
            {
                if (s[i - 1] == 'm' && s[i + 1] == 'r')
                    i = i + 2;
                else
                    break;
            }
        }
        else
        {
            if ( s[i - 1] == 'e' && s[i] == 'r')
                i = i + 1;
            else
                break;
        }
    }

    if (s[i])
        printf("NO");
    else
        printf("YES");

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef int q;
typedef double shara;
typedef string s;
q main(){
    q a,b,c,d;
    cin>>d; //xxx
    a=d%10;//xx0
    b=(d/10)%10;//x0x
    c=(d/100)%10;//0xx
    if(a==9&&b==9&&c==9){a=1; b=1; c=1; cout<<c<<b<<a;}//x
    else if(a==1&&b==1&&c==1){a=9; b=9; c=9; cout<<c<<b<<a;}//x
    else if(a==1&&b==1&&c==9){a=9; b=9; c=1; cout<<c<<b<<a;}//x
    else if(a==1&&b==9&&c==9){a=9; b=1; c=1; cout<<c<<b<<a;}//x
    else if(a==9&&b==1&&c==1){a=1; b=9; c=9; cout<<c<<b<<a;}//x
    else if(a==9&&b==9&&c==1){a=1; b=1; c=9; cout<<c<<b<<a;}//x
    else if(a==9&&b==1&&c==9){a=1; b=9; c=1; cout<<c<<b<<a;}//x
    else if(a==1&&b==9&&c==1){a=9; b=1; c=9; cout<<c<<b<<a;}//x
return 0;}


Measured memory_bytes: 256
import sys
N = int(input())
b = list(map(int, input().split()))

ans = []
while len(b) > 0:
  for i in range(len(b)-1, -1, -1):
    if i+1 == b[i]:
      ans.append(b.pop(i))
      poped = True
      break
  else:
    print(-1)
    sys.exit()

for a in reversed(ans):
  print(a)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = {str(i): 0 for i in range(n+1)}
wa = {str(i): 0 for i in range(n+1)}
ok = 0
ng = 0

for _ in range(m):
    p, s = input().split()
    if ac[p] == 0:
        if s == "AC":
            ac[p] += 1
            ok += 1
            if wa[p] > 0:
                ng += wa[p]
        else:
            wa[p] += 1

print(ok, ng)


Measured memory_bytes: 31848
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, double> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i < n + 1; i++) {
		ans += i;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
D=gets.split
gets
while gets
a,b=$_.split.map{|s|D.index s}
d=[*D]
f=->x,y{x.map{|i|d[i]}.rotate(y).map.with_index{|v,i|d[x[i]]=v}}
f[rand(2)>0?[0,2,5,3]:[0,4,5,1],rand(2)>0?1:-1]until[D[a],D[b]]==d[0..1]
puts d[2]
end

Measured memory_bytes: 6140
#include <bits/stdc++.h>
using namespace std;
bool find(long long N, vector<long long>&A) {
    for (long long i = 0; i < A.size(); i++) {
        if (A.at(i) == N) return true;
    }
    return false;
}
int main() {
    long long N; cin >> N;
    vector<vector<long long>>A(N, vector<long long>(2));
    for (long long i = 0; i < N; i++) {
        cin >> A.at(i).at(0) >> A.at(i).at(1);
    }
    for (long long i = 2; i < N; i++) {
        if (!(A.at(i).at(0) - A.at(i).at(1)) && !(A.at(i - 1).at(0) - A.at(i - 1).at(1)) && !(A.at(i - 2).at(0) - A.at(i - 2).at(1)))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 3e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;
const ll LOG = (ll) 30;



int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	str s;
	cin >> s;
	ll n = s.size();
	s = s + "!!!!!";
	ll cnt = 0, ans = 0;
	for(int i = 0; i < n; i++){
		//cerr << i << " :  " << cnt << '\n';
		if(s[i] == 'A'){
			cnt ++;
		} else if(s[i] == 'B') {
			if(s[i + 1] == 'C'){
				i++;
				ans += cnt;
				//cout << cnt <<'\n';
			}
			else cnt = 0;
		} else {
			cnt = 0;
		}
	}
	cout << ans;
	return 0;
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 788
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
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 n, m;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string ans="";
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]=='0'){
            ans+='0';
        }
        else if(s[i]=='1'){
            ans+='1';
        }
        else{
            if(ans.size()>=1){
                ans.pop_back();
            }
        }
    }
    cout << ans << "\n";
}


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

int main(){
        int N;
        cin >> N;
        int a[110][110]={{0}};
        for(int i=0; i<N; i++){
                int v,n;
                cin >> v;
                cin >> n;
                for(int j=0; j<n; j++){
                        int V;
                        cin >> V;
                        a[v-1][V-1]=1;
                }
        }
        for(int i=0; i<N; i++){
                for(int j=0; j<N; j++){
                        cout << a[i][j];
                        if(j<N-1)cout << " ";
                }
                cout << endl;
        }
}

Measured memory_bytes: 1216
a,b,c,d=map(int,input().split())

t=0
while 1:
    if t==0:
        c-=b
        t=1
        if c<=0:
            print("Yes")
            exit()
    else:
        a-=d
        t=0
        if a<=0:
            print("No")
            exit()

Measured memory_bytes: 9184
N=int(input())
B=[int(i) for i in input().split()]
if N>=2:
  ans=0
  for i in range(len(B)-1):
    ans+=min(B[i],B[i+1])
  ans+=B[0]+B[-1]
  print(ans)
else:
  print(2*B[0])

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define each(i,vec) for(auto i:vec)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  int n,k;
  cin>>n>>k;
  
  int res = (n-1)*(n-2)/2;
  if(k>res){
    out(-1);
    return 0;
  }

  int m=n-1+(res-k);
  VP pass;
  reps(i,n-1){
    pass.pb({1,i+1});
  }
  for(int i=2;i<=n;++i){
    if(SZ(pass)==m)break;
    for(int j=i+1;j<=n;++j){
      if(SZ(pass)==m)break;
      pass.pb({i,j});
    }
  }
  out(m);
  for(auto ans:pass)cout<<ans.fi<<" "<<ans.se<<endl;
  
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int n = N/2;
  int x[n],y[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    cin >> y[i];
  }
  int nx[100001]={0},ny[100001]={0};
  for (int i = 0; i < n; i++) {
    nx[x[i]]++;
    ny[y[i]]++;
  }

  int x1=0,x2=0,y1=0,y2=0;
  for (int i = 0; i < 100000; i++) {
    if (nx[i]>nx[x1]) {
      x2=x1;
      x1=i;
    }else if (nx[x1]>=nx[i] && nx[i]>nx[x2]) {
      x2=i;
    }

    if (ny[i]>ny[y1]) {
      y2=y1;
      y1=i;
    }else if (ny[y1]>=ny[i] && ny[i]>ny[y2]) {
      y2=i;
    }
  }

  int ans=0;

  if (nx[x2]*ny[y2] != 0) {
  if (x1 != y1) {
    ans = (n-nx[x1])+(n-ny[y1]);
  }else{
    int x1_y2 = (n-nx[x1])+(n-ny[y2]);
    int x2_y1 = (n-nx[x2])+(n-ny[y1]);
    ans = x1_y2 > x2_y1 ? x2_y1 : x1_y2;
  }
  }else{
    if (nx[x2]==0) {
      ans = n-ny[y1];
    }
    if (ny[y2]==0) {
      ans = n-nx[x1];
    }
    if (nx[x2]==ny[y2]) {
      ans == 0;
    }
    if (x1 == y1) {
      ans = n;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
import math

A, B, H, M = list(map(int,input().split()))

def rorate(x, y, theta):
    nx = x * math.cos(theta) - y * math.sin(theta)
    ny = x * math.sin(theta) + y * math.cos(theta)
    return nx, ny

hun = math.pi * M / 30
zi = math.pi * (30 * H + (M / 2)) / 180

na = rorate(0, A, zi)
nb = rorate(0, B, hun)

print(math.sqrt((na[0] - nb[0]) ** 2 + (na[1] - nb[1]) ** 2))

Measured memory_bytes: 62624
//                                               KEEP GRINDING
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>   new_data_set;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define int long long
#define ld long double
#define MOD 1000000007
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<"\n========================================\n";
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define PQ priority_queue
#define mx(a) *max_element(a)
#define mn(a) *min_element(a) 
#define LB lower_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= OUR VALUE 
#define UB upper_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > OUR VALUE 

#define fr first
#define sc second

#define MAXN 2000100
#define INF 9223372036854775807
void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	vector<int> a(n),b(m);
	f(i,0,n)	cin>>a[i];
	f(i,1,n)	a[i]+=a[i-1];
	f(i,0,m)	cin>>b[i];
	f(i,1,m)	b[i]+=b[i-1];;
	int ans=0;
	ans=max(ans,(int)( UB(all(b),k)-b.begin() ) );
	f(i,0,n){
		if(a[i]>k)break;
		ans=max(ans,i+1+(int)( UB(all(b),k-a[i])-b.begin() ) );
	}
	cout<<ans;
}
signed main(){
    fastio
    int t=1;
    for(;t--;solve());
}

Measured memory_bytes: 6372
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

char c;
int main(void){
    cin >> c;
    if(isupper(c)) cout << "A" << endl;
    else cout << "a" << endl;
    return 0;
}



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

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> A(a);
    vector<int> B(b);
    rep(i,a) cin >> A[i];
    rep(i,b) cin >> B[i];
    int A_min = *min_element(A.begin(),A.end());
    int B_min = *min_element(B.begin(),B.end());

    int mini_tmp = A_min + B_min;
    rep(i,m) {
        int x, y, c;
        cin >> x >> y >> c;
        mini_tmp = min(mini_tmp,A[x-1]+B[y-1]-c);
    }
    cout << mini_tmp << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, K; std::cin >> N >> K;
  std::vector<double> p(N);
  for (int i = 0; i < N; ++i) {
    double v; std::cin >> v;
    p[i] = (v + 1)/2;
  }

  double sum = 0;
  for (int i = 0; i < K; ++i) {
    sum += p[i];
  }
  double max_sum = sum;

  for (int i = 1; i < N-K + 1; ++i) {
    sum = sum - p[i-1] + p[i+K-1];
    max_sum = std::max(max_sum, sum);
  }
  printf("%.9f\n", max_sum);
}


Measured memory_bytes: 1792
function Main(input) {
 var possibility;
 if(input % 2 == 0) {
   possibility = (input / 2) / input;
 } else {
   possibility = (Math.floor(input / 2) + 1 ) / input;
 }
 console.log(possibility);


}
Main(require('fs').readFileSync('/dev/stdin', 'utf-8'));


Measured memory_bytes: 7372
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <bits/stdc++.h>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct P
{
    int x,y;

    bool operator<(const P &a)const{
        //if(y!=a.y)
        //return y>a.y;

       return y<a.y;
//        return z>a.z;
    }
};
struct S
{
    int x;
    int y;
};
vector<int> v[300105];
int a,b,c,n,m,i,k,e[6666],dy[15]={0,0,-1,1,-1,1,-1,1},dx[15]={-1,1,0,0,1,1,-1,-1};
int l[20610];
long long x,y,z[620];
P u[100200],u2[100100];
int o[100011];
int j[1054];
//priority_queue<int> q,q1;
stack<int> s;
//queue<int> q[3];
//queue<char> q1;


deque<int> d;
//'1'==49;
//'A'==65;
//'a'==97;
//map<int, int > p[4];
//set<int> s;
string r,r1;
//char r[500][1010];

bool as(int c,int b)
{
     int n=0,m=0;

     return n>=m;
}

int asd(int t)
{
    if(t<10) return t;
    int u=t;
    for(;u>=10;u/=10);
    return asd(t)+u;
}

int f(int t)
{
    if(t<10) return t;
    int u=asd(t);
    t/=10;
    for(int w=t*10;w>0;w/=10,t*=10);
    return t+u;
}
//2147483647
int main()
{
    scanf("%d",&a);
    o[1]=1;
    d.push_back(1);
    for(;d.size();)
    {
        int c=d.front();
        d.pop_front();
        if(o[c*10%a]==0||o[c*10%a]>o[c])
        {
            d.push_front(c*10%a);
            o[c*10%a]=o[c];
        }
        if(o[(c+1)%a]==0||o[(c+1)%a]>o[c]+1)
        {
            d.push_back((c+1)%a);
            o[(c+1)%a]=o[c]+1;
        }
    }
    printf("%d",o[0]);
}


Measured memory_bytes: 7936
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    cnt = sum(B) - sum(A)
    acnt = 0
    bcnt = 0
    for i in range(N):
        x = B[i] - A[i]
        if x > 0:
            acnt += x//2
            if x % 2 == 1:
                acnt += 1
                bcnt += 1
        elif x < 0:
            bcnt += 1
    if acnt <= cnt and bcnt <= cnt:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll n, k, buf, city=1, cnt=0;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> flag(n,-1);
    
    REP(i,n){
        cin >> buf;
        a.at(i) = buf;
    }

    while(true){
        if(flag.at(city-1)!=-1){
            k -= flag.at(city-1);
            k %= (cnt - flag.at(city-1));
            break;
        }
        else{
            flag.at(city-1)=cnt;
            if(cnt == k){
                cout << city;
                return 0;
            }
            cnt++;
            city = a.at(city-1);
        }
    }

    REP(i,k){
        city = a.at(city-1);
    }
    cout << city;
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
int main(){
  int E,Y;
  int M=1912,T=1926,S=1989,H=2020;
  cin >> E >> Y;
  if(E ==0){
    
    if(Y<M) cout << "M" << (Y-1868)+1 << endl;
    if(Y<T && M<=Y) cout << "T" << Y-M+1 << endl;
    if(Y<S && T<=Y) cout << "S" << Y-T+1 << endl;
    if(Y<H && S<=Y) cout << "H" << Y-S+1 << endl;
  }else{
    Y = Y-1;
    if(E == 1) cout << 1868+Y << endl;
    if(E == 2) cout << M+Y << endl;
    if(E == 3) cout << T+Y << endl;
    if(E == 4) cout << S+Y << endl;
  }
  return 0;

}



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

using namespace std;

int main()
{
  int N, T;
  cin >> N >> T;
  double ret = 0;
  while(N--) {
    int X, H;
    cin >> X >> H;
    ret = max(ret, 1.0 * H / X);
  }
  cout << fixed << setprecision(10) << ret * T << endl;
}

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

int main(){
  int n;
  cin>>n;
  if(n%2==0){
    cout<<(n-2)*n/2<<endl;
    rep(i,n){
      for(int j=i+1;j<n;j++){
        if(j+i!=n-1) cout<<i+1<<" "<<j+1<<endl;
      }
    }
  }else{
    cout<<(n-1)*(n-1)/2<<endl;
    rep(i,n-1){
      for(int j=i+1;j<n-1;j++){
        if(j+i!=n-2) cout<<i+1<<" "<<j+1<<endl;
      }
      cout<<i+1<<" "<<n<<endl;
    }
  }
}

Measured memory_bytes: 256
import math 
import collections

N = int(input())
String = []
for i in range (0, N):
	S = str(input())
	S = sorted(S)
	V = str(S[0])
	for j in range (1, 10):
		V = V+str(S[j])
	String.append(V)
    
cnt = collections.Counter()
for word in String:
	cnt[word] += 1

V = cnt.most_common()

count = 0

for i in range (0, len(V)):
	count+=math.comb(V[i][1], 2)
    
print(count)

Measured memory_bytes: 29360
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=list(map(int,input().split()))
    adic={}
    for i in range(n):
        if a[i] in adic:
            adic[a[i]]+=1
        else:
            adic[a[i]]=1
    ans=0
    a=list(set(a))
    a.sort()
    maxa=max(a)
    dp=[True for i in range(maxa+1)]
    for i in a:
        if dp[i] and adic[i]==1:ans+=1
        j=i+i
        while j<=maxa:
            dp[j]=False
            j+=i
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 44372
import numpy as np

n=int(input())
E=[]
node_l=np.zeros(n)
node_l[0]=1
for i in range(n-1):
    u,v,w=map(int,input().split())
    #print(u,v,w)
    E.append((u,v,w))
#print(E,W)

def bfs(node,l):
    root=[[] for i in range(n)]
    for a,b,c in l:
        root[a-1]+=[(b-1,c)]
        root[b-1]+=[(a-1,c)]
    stack=[]
    stack.append(node-1)
    #print(root)
    dist=[-1]*n
    dist[node-1]=0
    while stack:
        #print(stack)
        buf=stack.pop(-1)
        for v,weight in root[buf]:
            if dist[v]==-1:
                dist[v]=dist[buf]+weight
                stack.append(v)
    return dist

for i in bfs(1,E):
    print(i%2,end='\n')

Measured memory_bytes: 64996
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
 
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9 + 7;
const ll MAX = 1e6+7;
const ll inf = 1e9+1;
ll a[MAX];
bool vist[MAX];
vi city;
int main() {
  fastio;
  ll ans,n,k,cont=0;
  cin>>n>>k;
  f(i,1,n+1){
    cin>>a[i];
  }
  ll pos=1;
  while(!vist[pos]){
    vist[pos]=true;
    city.pb(pos);
    pos=a[pos];
  }
  f(i,0,sz(city)){
    if(city[i]==pos) break;
    cont++;
  }
  if(k<cont) {cout<<city[k]<<endl;return 0;}
  ans = city[cont+ (k-cont)%(sz(city)-cont)];
  cout<<ans<<endl;
  return 0;
}

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

const string dict[] = {"remaerd", "resare", "esare", "maerd"};

bool exist(string S){
    for (int i = 0; i < 4; ++i){
        if (S == dict[i]) return true;
    }
    return false;
}

int main(){
    string S, T = "";
    cin >> S;
    for (size_t i = 0; i < S.size(); ++i){
        T += S[S.size() - i - 1];
        if (exist(T)) T = "";
    }

    cout << ((T.size() == 0) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}

    int len_max = 0;

    rep(i, n-1){
        int len = a[i+1] - a[i];
        len_max = max(len_max, len);
    }
    int len_last = a[0]+k-a[n-1];
    len_max = max(len_max, len_last);
    
    cout << k - len_max << endl;

}


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

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  ll res;
  if (A+1 < B && K > A) {
    res = B + ((K - A - 1) / 2) * (B - A) + (K - A - 1) % 2;
  }
  else res = K + 1;
  cout << res << endl;
}


Measured memory_bytes: 256