akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n;
    cin >> n;
    vector<lint> a(n*3);
    rep(i, n*3){
        cin >> a[i];
    }
    vector<lint> f(n+1);
    priority_queue<lint, vector<lint>, greater<lint> > front;
    lint fsum = 0;
    rep(i, n){
        front.push(a[i]);
        fsum += a[i];
    }
    f[0] = fsum;
    REP(i, n, n*2){
        front.push(a[i]);
        fsum += a[i];
        fsum -= front.top();
        front.pop();
        f[i-n+1] = fsum;
    }
    vector<lint> b(n+1);
    priority_queue<lint> back;
    lint bsum = 0;
    REP(i, n*2, n*3){
        back.push(a[i]);
        bsum += a[i];
    }
    b[n] = bsum;
    for(lint i = n*2-1 ; i >= n ; i--){
        back.push(a[i]);
        bsum += a[i];
        bsum -= back.top();
        back.pop();
        b[i-n] = bsum;
    }
    lint ans = f[n] - b[n];
    rep(i, n){
        ans = max(ans, f[i] - b[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n; cin >> n;
  bool ok = true;
  for (int i = 0; i < n; i ++) {
    int t; cin >> t;
    if (t % 2 == 0) {
      if (t % 3 != 0 && t % 5 != 0) ok = false;
    }
  }

  if (ok) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
n=int(input())
# s=input()
# a,b=map(int,input().split())
# h=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))

# mod=10**9+7
# n=20
# fact=[1]
# for i in range(n):
#     fact+=fact[-1]*(i+1)%mod,
# print(fact)
# print(l)
# ほんと？
from bisect import bisect_left,bisect_right
ans=0
for i in range(n):
    for j in range(i+1,n):
        a=l[i]
        b=l[j]
        
        # print(ll)
        # abs(a-b)<c<a+bをみたすcは何個？
        ans+=bisect_left(l,a+b)-j-1 # -bisect_right(ll,b-a)
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>

int main(){

  float temp, max, min;
  max = 0;
  min = 10000000;

  while(scanf("%f", &temp) != EOF){
    if(temp > max){
      max = temp;
    }
    if(temp < min){
      min = temp;
    }
  }

  printf("%.2f\n", max - min);

  return 0;
}

Measured memory_bytes: 648
/*
	0511:Caesar Cipher
*/
#include	<iostream>
#include	<cstdio>
#include	<cstring>

using namespace std;

int main(void) {
	char str[1001];
	
	scanf("%s", str);
	
	for(int i = 0; i < (int)strlen(str); i++) {
		if(str[i] == 'C') {
			str[i] = 'Z';
		}
		else if(str[i] == 'B') {
			str[i] = 'Y';
		}
		else if(str[i] == 'A') {
			str[i] = 'X';
		}
		else {
			str[i] -= 3;
		}
	}
	
	printf("%s\n", str);
	
	return 0;
}

Measured memory_bytes: 1112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
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;
}

int n, a[100010], ta = INF, mu;

signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	cout << a[n - 1] << " ";
	double hanbun = a[n - 1] / 2.0;
	rep(i, n - 1) {
		double va = a[i];
		if (abs(hanbun - va) < ta) {
			ta = abs(hanbun - va);
			mu = a[i];
		}
	}
	cout << mu << endl;
	ggr
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

template<typename T>
using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(322);

ll const mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5 + 5;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a, b; cin >> a >> b;
    cout << max(0LL, a - 2*b);
    return 0;
}
/*

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    if(1 >= (c-a-b)){
        cout << "No" << endl;
        return 0;
    }
    ll tmp1,tmp2;
    tmp1 = 4*a*b;
    tmp2 = a*a+b*b+c*c+2*a*b-2*b*c-2*a*c;
    if(tmp1 < tmp2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/*
	Solved!
	Time: 05:23:26 PM
	Date: 05-04-2020
*/
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long  ll;
typedef vector<int>         vi;
typedef vector<ll>          vll;

#define ff                  first
#define sf                  scanf
#define pf                  printf
#define ss                  second
#define ppb                 pop_back
#define pb                  push_back
#define MP                  make_pair
#define MAXN                5000005
#define MOD                 100000007
#define inf                 0x3f3f3f3f
#define PI                  (2.0*acos(0.0))
#define INF                 0x3f3f3f3f3f3f3f3f
#define rev(v)              reverse(all(v))
#define all(v)              v.begin(), v.end()
#define __lcm(x, y)         (x * y) / __gcd(x, y)
#define FOR(i, x, y)        for(int i = x; i < y; i++)
#define RFOR(i, x, y)       for(int i = x; i >= y; i--)
#define MEM(arr, val)       memset(arr, val, sizeof(arr));
#define unq(v)              (v).resize(unique(all(v)) - v.begin())
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)
#define si(n)               scanf("%d", &n)
#define sl(n)               scanf("%lld", &n)
#define sii(a, b)           scanf("%d %d", &a, &b)
#define sll(a, b)           scanf("%lld %lld", &a, &b)
#define siii(a, b, c)       scanf("%d %d %d", &a, &b, &c)
#define slll(a, b, c)       scanf("%lld %lld %lld", &a, &b, &c)
#define siiii(a, b, c, d)   scanf("%d %d %d %d", &a, &b, &c, &d)
#define sllll(a, b, c, d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define vout(v)             for(int i = 0; i < v.size(); i++) {cout << v[i]; if(i < v.size() - 1) cout << ' '; else cout << endl;}

int main(){
    /*#ifndef ONLINE_JUDGE
        double start = clock(); READ(); WRITE();
    #endif*/
        ll n; sl(n);
        ll ans = (n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        cout << ans << endl;


   /* #ifndef ONLINE_JUDGE
        printf("\n>>Runtime: %.10fs\n", (double)(clock() - start) / CLOCKS_PER_SEC);
    #endif*/

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    ll x = 0;
    rep(i, n) {
        if(s[i] == '0') {
            x++;
        }
    }
    
    out(2*min(x, n-x));
    re0;
}

Measured memory_bytes: 512
pub mod kit {
    use std::io::{BufRead, Read};
    use std::str::{self, FromStr};

    pub struct Scanner<R> {
        reader: R,
        buff: Vec<u8>,
    }

    impl<R: BufRead> Scanner<R> {
        pub fn new(reader: R) -> Self {
            Self {
                reader,
                buff: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn read_line<T: FromStr>(&mut self) -> T
        where
            <T as FromStr>::Err: ::std::fmt::Debug,
        {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read<T: FromStr>(&mut self) -> T
        where
            <T as FromStr>::Err: ::std::fmt::Debug,
        {
            self.read_until(b' ')
        }

        #[inline]
        fn read_until<T: FromStr>(&mut self, delim: u8) -> T
        where
            <T as FromStr>::Err: ::std::fmt::Debug,
        {
            loop {
                self.buff.clear();
                match self.reader.read_until(delim, &mut self.buff).unwrap() {
                    0 => panic!("EOF read"),
                    1 if (self.buff[0] as char).is_whitespace() => (),
                    n => {
                        if (self.buff[n - 1] as char).is_whitespace() {
                            self.buff.truncate(n - 1);
                        }
                        break;
                    }
                }
            }
            str::from_utf8(&self.buff)
                .unwrap()
                .parse()
                .unwrap_or_else(|err| panic!(format!("{:?}", err)))
        }

        pub fn next<T: FromStr>(&mut self) -> T
        where
            <T as FromStr>::Err: ::std::fmt::Debug,
        {
            self.reader
                .by_ref()
                .bytes()
                .map(|b| b.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>()
                .parse::<T>()
                .unwrap()
        }
    }
}


// let cin = std::io::stdin();
// let mut sc = scanner!(cin);
#[allow(unused)]
macro_rules! scanner {
    ($stdin:expr) => {
        kit::Scanner::new($stdin.lock())
    };
}
fn main() {
    let stdin = std::io::stdin();
    let mut sc = scanner!(stdin);

    let mut buildings = [[[0i32; 10]; 3]; 4];
    let n: i64 = sc.next();

    for _ in 0..n {
        let b: usize = sc.next();
        let f: usize = sc.next();
        let r: usize = sc.next();
        let v: i32 = sc.next();

        buildings[b - 1][f - 1][r - 1] += v;
    }

    for i in 0..buildings.len() {
        let building = buildings[i];
        for j in 0..building.len() {
            let floar = building[j];
            for k in 0..floar.len() {
                print!(" {}", floar[k]);
            }
            println!();
        }
        if i != buildings.len() -1 {
            println!("####################");
        }
    }
}




Measured memory_bytes: 5032
#include <iostream>
#include <cstdint>
using namespace std;
int main()
{
	int64_t N,K;
	cin >> N >> K;
	N%=K;
	if(N<0ll) N+=K;
	if(N>K-N) cout << K-N;
	else cout << N;
	cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from bisect import bisect
def input():
	return sys.stdin.buffer.readline()[:-1]

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Get(self, i):#iを返す
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def PointAdd(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

	def SegAdd(self, l, r, x):#lからrにxを足す
		self.PointAdd(l, x)
		self.PointAdd(r+1, -x)
		return


n, d, a = map(int, input().split())
d *= 2
mo = sorted([list(map(int, input().split())) for _ in range(n)])
for i in range(n):
	mo[i][1] = (mo[i][1]-1)//a + 1
reach = []
moo = [x[0] for x in mo]
mooo = [x[1] for x in mo]
for x in moo:
	reach.append(bisect(moo, x+d)-1)
#print(reach)

bit = BIT(n)

ans = 0
for i, h in enumerate(mooo):
	gap = max(0, h - bit.Get(i+1))
	bit.SegAdd(i+1, reach[i]+1, gap)
	ans += gap

print(ans)


Measured memory_bytes: 104744
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define ll long long
using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef  long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
int main()
{

i64 n,ans=0,k;
// vi64 v;
cin>>n>>k;
vi64 v(n+1);
for1(i,n){
cin>>v[i];
}
i64 dp[100000];
dp[1]=0;
for(int i=2;i<=n;i++)
{
	dp[i]=dp[i-1]+abs(v[i]-v[i-1]);
for(int j=2;j<=k&&j<i;j++)
{
	dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
}
}
cout<<dp[n];


	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int dpd[4][2010];
inline int getint() {
	char c;
	int ret = 0;
	while ((c = getchar()) >= '0') ret = ret * 10 + c - '0';
	return ret;
}

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


	int N = getint();
	const int M = getint();

	dpd[0][0] = 1;
	auto dp0 = dpd[0];
	auto dp1 = dpd[1];
	auto dp2 = dpd[2];
	auto dp3 = dpd[3];

	rep(i, 3 * N) {
		for (int j = min(N, (i + 1) >> 1); j >= 0; j--) {
			ll tmp = dp0[j];
			dp3[j + 1] = tmp * (i + 1) * (i + 2) % M;
			dp2[j + 1] = (dp2[j + 1] + tmp * (i + 1)) % M;
			dp1[j] += tmp;
			if (dp1[j] > M) dp1[j] -= M;
		}
		dp3[0] = 0;
		swap(dp0, dp1);
		swap(dp1, dp2);
		swap(dp2, dp3);
	}

	ll kotae = 0;
	rep(i, N + 1) kotae += dp0[i];
	co(kotae % M);

	Would you please return 0;
}

Measured memory_bytes: 256
l = list(map(int,input().split()))

a=l[0]#t tai
b=l[1]#t kougeki
c=l[2]#a tai
d=l[3]#a kougeki

while True:
    c=c-b
    if c<=0:
        print("Yes")
        break
    a=a-d
    if a<=0:
        print("No")
        break


Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

char ban[128];
int sum[128];

string table;
int n;

int main(){
	while(cin >> n && n){
		rep(i,128) ban[i] = 0;
		rep(i,128) sum[i] = 0;
		table = "";
		rep(i,n){
			string s;
			cin >> s;
			if(s.size() != 1)ban[s[0]] = true;
			int w = 1 , islst = 1-2*(i == n-1);
			rep(j,s.size()){
				sum[s[s.size()-j-1]] += w * islst;
				w *= 10;
			}
			table += s;
		}
		sort(table.begin(),table.end());
		table.erase(unique(table.begin(),table.end()),table.end());
		int s = table.size();
		int ans = 0 , x[10] = {0} , bit = (1<<s)-1 , clc = 0;
		while(bit < (1<<10)){
			int p = 0;
			rep(j,10) if(bit>>j&1) x[p++] = j;
			do{
				rep(k,p) if(x[k] == 0 && ban[table[k]]) goto exit;
				clc = 0;
				rep(k,p) clc += sum[ table[k] ] * x[k];
				if(clc == 0)ans++;
				exit:;
			}while(next_permutation(x,x+p));
			int x = bit & -bit, y = bit + x;
			bit = ((bit & ~y) / x >> 1) | y;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 932
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch; int sum = 0;
	for(int i=0; cin>>ch; ++i) {
		if(ch == '\\') S1.push(i);
		else if(ch=='/' && S1.size()>0) {
			int j = S1.top(); S1.pop();
			sum += i-j; int a = i-j;
			while(S2.size()>0 && S2.top().first>j) {
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}

	vector<int> ans;
	while(S2.size() > 0) {
		ans.push_back(S2.top().second); S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl << ans.size();
	for(int i=0; i<ans.size(); ++i) cout << " " << ans[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 3168
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(auto &it:v)cin>>it;
  sort(all(v));
  int ans=0;
  v[n-1]=v[n-1]>>1;
  for(auto it:v)ans+=it;
  cout<<ans<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}


Measured memory_bytes: 256
/*
Rathin Bhargava
IIIT Bangalore

*/
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  int n;
  cin >> n;
  for(int i=0;i<=50000;i++)
  {
    // if(i== 927) cout << (int) 
    if((int)(i*1.08) == n)
    {
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] imput = new int[10];
		int sum =0;
		Scanner stdin = new Scanner(System.in);

		for(int i = 0; i < 10; i++) {
			imput[i]  = stdin.nextInt();
			sum += imput[i];
		}
		System.out.println(sum);

	}

}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i*i<=n;i++){
		if(n%i)continue;
		if(n/i-1>i)ans+=(n/i-1);
	}
	puta(ans);
	// range(i,1,30){
	// 	ll ans=0;
	// 	cout<<i<<" : ";
	// 	range(j,1,i){
	// 		if(i/j==i%j){
	// 			ans+=j;
	// 			cout<<j<<",";
	// 		}
	// 	}
	// 	puta("\t ans : ",ans);
	// }
	// puta(n);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main() {
	string s, a, b;
	cin >> s;
	while (1){
		s.erase(s.begin() + s.size() - 1);
		if (s.size() % 2 != 0) {
			continue;
		}
		a = s.substr(0, s.size() / 2);
		b = s.substr(s.size() / 2, s.size());
		if (a == b) {
			break;
		}
	}
	cout << s.size();
	return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<deque>
#include<string>
#include<map>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	long long int n, ans = 0, sum = 0; cin >> n;
	map<long long int, long long int> mp;
	mp[0] += 1;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		sum += a;
		ans += mp[sum];
		mp[sum] += 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    string s, t;
    //first problem--> works
//    cin>> s;
//    t = "";
//    for (int i = 0; i< s.length(); i++){
//        int h = s[i];
//        if (h!='B'){
//            t+= h;
//        }
//        else{
//            if (t == ""){
//                continue;
//            }
//            else{
//                string temp = t;
//                t = "";
//                for (int j = 0; j< temp.length()-1; j++){
//                    t+=temp[j];
//                }
//            }
//        }
//    }
//    cout<< t;
    //second problem
    int a, b;
//    cin>> a >> b;
//    if (a==1){
//        a = 14;
//    }
//    if (b==1){
//        b=14;
//    }
//    if (a>b){
//        cout << "Alice";
//    }
//    else if (b>a){
//        cout << "Bob";
//    }
//    else if (b==a){
//        cout<< "Draw";
//    }
    //third problem
    int input;
    bool NA = false;
    bool Ambiguous = false;
    bool YYMM = false;
    bool MMYY = false;
    
    cin>> input;
    a = input/100;
    b = input%100;

    if (0<a && a<=12){
        MMYY = true;
    }
    if (0<b && b<=12){
        YYMM = true;
    }
    if (YYMM &&MMYY){
        Ambiguous = true;
    }
    else if(!YYMM && !MMYY){
        NA = true;
    }

    //cout
    if (Ambiguous){
        cout<< "AMBIGUOUS";
    }
    else if (YYMM){
        cout<< "YYMM";
    }
    else if(MMYY){
        cout<< "MMYY";
    }
    else if (NA){
        cout<< "NA";
    }
    //fourth problem
//    cin>> a>>b;
//    int friends[b];
//    int remaining = a%b;
//    for (int i = 0; i<b; i++){
//        friends[i] = a/b;
//        if (remaining>0){
//            remaining--;
//            friends[i]++;
//        }
//    }
//    for (int i = b-1; i>=0; i--){
//        cout << friends[i] << " ";
//    }
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
import scala.collection.immutable.TreeMap

object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val m = sc.nextInt
    val map : TreeMap[Long,Int] = (1 to n).foldLeft[TreeMap[Long,Int]](TreeMap.empty)((map, _) => {
      val x = sc.nextLong
      val y = sc.nextInt
      map.updated(x, map.getOrElse(x,0) + y)
    })

    val end : (BigDecimal,Int) = map.foldLeft[(BigDecimal,Int)]((0, m)){case ((sum, toBuy),(x,y)) => {
      if(toBuy == 0) (sum,0)
      else{
        val buying = Math.min(toBuy, y)
        (sum + x*buying, toBuy - buying)
      }
    }}
    println(end._1)
  }

}

Measured memory_bytes: 116580
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N=20,P=1e9+7;

int n,m,p,a[N],f[N][1<<16|5],fac[1<<16|5],inv[1<<16|5];

inline int C(int x,int y){
  if(x<y) return 0;
  return 1LL*fac[x]*inv[y]%P*inv[x-y]%P;
}

int pw[N];

inline void add(int &x,int y){
  (x+=y)%=P;
}

int main(){
  scanf("%d%d",&n,&m);
  pw[0]=1; for(int i=1;i<=n;i++) pw[i]=pw[i-1]*2; p=pw[n];
  fac[0]=1; for(int i=1;i<=p;i++) fac[i]=1LL*fac[i-1]*i%P;
  inv[1]=1; for(int i=2;i<=p;i++) inv[i]=1LL*(P-P/i)*inv[P%i]%P;
  inv[0]=1; for(int i=1;i<=p;i++) inv[i]=1LL*inv[i]*inv[i-1]%P;
  for(int i=1;i<=m;i++) scanf("%d",&a[i]);
  sort(a+1,a+1+m); int ans=0; f[m+1][0]=1;
  for(int i=m;i;i--){
    for(int S=0;S<(1<<n);S++) f[i][S]=f[i+1][S];
    for(int S=0;S<(1<<n);S++){
      int cnt=0;
      for(int j=1;j<=n;j++)
    if(S>>(j-1)&1) cnt+=pw[j-1];
      int rst=p-a[i]-cnt;
      for(int j=1;j<=n;j++)
    if(S>>(j-1)&1);else{
      if(pw[j-1]-1>rst) continue;
      add(f[i][S|(1<<j-1)],1LL*f[i+1][S]*C(rst,pw[j-1]-1)%P*fac[pw[j-1]]%P);
    }
    }
  }
  for(int i=0;i<(1<<n);i++){
    int cur=f[1][i],cnt=0,tot=0;
    for(int j=1;j<=n;j++)
      if((i>>(j-1))&1) cnt+=pw[j-1],tot++;
    cur=1LL*cur*fac[p-cnt-1]%P;
    if(tot&1) ans=(ans-cur)%P;
    else ans=(ans+cur)%P;
  }
  ans=1LL*ans*p%P;
  printf("%d\n",(ans+P)%P);
  return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t x,int64_t y){
  int64_t a,b,r;
  if(x>y) swap(x,y);
  a=x;
  b=y;
  r=b%a;
  while(r>0){
    b=a;
    a=r;
    r=b%a;
  }
  return a;
}
int main() {
  int64_t a,b,c,d,e,ans=0;
  cin>>a>>b>>c>>d;
  e=c*d/gcd(c,d);
  ans+=(b-a+1)-((b/c-(a-1)/c)+(b/d-(a-1)/d)-(b/e-(a-1)/e));
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
  string input;
  cin >> input;

  int s0 = input[0] - '0';
  int s1 = input[1] - '0';
  int s2 = input[2] - '0';
  cout << s0 + s1 + s2 << endl;
}


Measured memory_bytes: 256
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        s = input()
        for j in range(W):
            if s[j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()
        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 85720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication79
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[3];
            a=Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(a);
            Console.WriteLine(a[0]+a[1]);
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define F first
#define S second

const int MAXN = 2e5 + 100;

int n, a[MAXN], b[MAXN], sec[MAXN], sz, xx;
int in[MAXN], out[MAXN];
vector<int> adj[MAXN];
int cc, cnt;
int inV, outV;
bool vis[MAXN];

int get(int &x){x = lower_bound(sec, sec + sz, x) - sec;}

void dfs(int v){
	vis[v] = 1;
	cnt += in[v];
	if (in[v]^out[v]){
		cc += abs(in[v] - out[v]);
		if (in[v] > out[v])
			inV = v;
		else
			outV = v;
	}

	for (int u:adj[v])
		if (!vis[u])
			dfs(u);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)	cin >> a[i], xx ^= a[i], sec[sz++] = a[i];
	sec[sz++] = xx;
	for (int i = 0; i < n; i++) cin >> b[i], sec[sz++] = b[i];
	sort(sec, sec + sz);
	sz = unique(sec, sec + sz) - sec;
	
	for (int i = 0; i < n; i++) get(a[i]);
	for (int i = 0; i < n; i++) get(b[i]);
	get(xx);

	for (int i = 0; i < n; i++)
		if (a[i]^b[i]){
			out[b[i]]++;
			in[a[i]]++;
			adj[a[i]].push_back(b[i]);
			adj[b[i]].push_back(a[i]);
		}

	int ans = 0;
	bool done = 0;
	for (int i = 0; i < sz; i++)
		if (!vis[i] && adj[i].size()){
			cc = cnt = 0;
			dfs(i);

			if (cc > 2){
				cout << "-1\n";
				return 0;
			}

			if (cc == 0)
				ans += cnt+1;
			else{
				ans += cnt;
				if (done){
					cout << "-1\n";
					return 0;
				}
				done = 1;
				if (xx != outV){
					cout << "-1\n";
					return 0;
				}
			}
		}
	
	if (!done && adj[xx].size())
		ans--;
	cout << ans << "\n";
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  if (S == "Sunny") {
    cout << "Cloudy\n";
  } else if (S == "Cloudy") {
    cout << "Rainy\n";
  } else {
    cout << "Sunny\n";
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
 
const ll MOD = 1000000007;
using namespace std;
vector<ll> fac, facInv, inv;
void facInit(int nmax)
{
    fac = facInv = inv = vector<ll>(nmax + 1, 1);
    for (ll i = 2; i <= nmax; ++i)
    {
        fac[i] = (fac[i-1]*i)%MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD/i) % MOD;
        facInv[i] = (facInv[i-1] * inv[i])%MOD;   
    }
}
ll ncr(ll n, ll r) 
{
    if (n < r || r < 0)
        return 0;           
    if (n >= (int)fac.size()) facInit(n);
    return (fac[n] * facInv[r] % MOD) * facInv[n-r] % MOD;
}
int main() {
    int n;
    ll x,y;
    cin >> x >> y;
    facInit(3e6);
    ll a = (x+y)/3;
    if (a * 3 != (x+y))
    {
        cout << "0";
    }
    else 
    {
        x -= a;
        y -= a;
        cout << ncr(a, x) << endl;
    }
    return 0;
}

Measured memory_bytes: 70528
n,m = map(int,input().split())
a = [0]*(m+1)
for i in range(n):
    b = input().split()
    for j in range(len(b)):
        b[j] = int(b[j])

    for j in range(1,b[0]+1):
        a[b[j]] += 1
t = 0
for i in range(len(a)):
    if a[i] == n:
        t += 1

print(t)

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

signed main() {
  std::vector<int> v(7);
  for(int i=0;i<7;i++)cin>>v[i];
  int a=v[1]+(v[3]/2)*2+(v[4]/2)*2+(v[0]/2)*2;
  if(v[0]%2+v[3]%2+v[4]%2==2&&v[0]*v[3]*v[4]!=0)a++;
  if(v[0]%2+v[3]%2+v[4]%2==3)a+=3;
  cout<<a<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Long> a = new ArrayList<>();
        IntStream.range(0, n).forEach(i -> a.add(sc.nextLong()));
        a.sort(Comparator.reverseOrder());
        System.out.println(Math.abs(a.get(0) - a.get(a.size() - 1)));
    }

}


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

int main(){
  int D , N ; 
  cin >> D >> N ; 
  long long P = 0 ; 
  for(int i = 1 ; i <= N ; i++){
    if(D == 1){
      P += 100 ; 
      if(P == 10000) P += 100 ; 
    }
    if(D == 2) {
      P += 100*100 ; 
      if(P == 1000000) P += 10000 ; 
    }
    if(D == 0){
      P = i ; 
      if(P == 100) P++ ;
    }
  }
  
  cout << P << endl ; 
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;
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();
  int S;
  cin >> S;
  ll ans = 0;
  for(int i = 1; i * 3 <= S; i++){
    int sum = S-i*3;
    ans += COM(i+sum-1, i-1);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15556
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int M = cin.nextint;
        var S = cin.next;
        var T = cin.next;

        var L = lcm(N, M);
        var D = new Dictionary<long, int>();
        for (int i = 0; i < N; i++)
        {
            D[i * L / N + 1] = i;
        }
        for (int j = 0; j < M; j++)
        {
            var tmp = j * L / M + 1;
            if (D.ContainsKey(tmp))
            {
                if (S[D[tmp]] != T[j])
                {
                    WriteLine(-1);
                    return;
                }
            }
        }
        WriteLine(L);
    }

    long gcd(long a, long b)
    {
        return (b != 0) ? gcd(b, a % b) : a;
    }
    long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }
    //ax + by = gcd(a, b)となるx, yを求める
    long extgcd(long a, long b, out long x, out long y)
    {
        long g = a;
        if (b != 0)
        {
            g = extgcd(b, a % b, out y, out x);
            y -= (a / b) * x;
        }
        else
        {
            x = 1;
            y = 0;
        }
        return g;
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public string join<T>(IEnumerable<T> values) { return string.Join(" ", values); }
}

Measured memory_bytes: 22496
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pi 3.141592653589
 
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power(ll b,ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,c=0,f=0;
    cin>>n;
    while(n--)
    {
        int d1,d2;
        cin>>d1>>d2;
        if(d1==d2)
            c++;
        else
            c=0;
        if(c==3)
        {
            f=1;
        }
    }
    if(f==1)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

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

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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

// 探索
vector<bool> seen, finished;
vector<int> root;
int start;
int fin;

// サイクル復元のための情報
int pos = -1; // サイクル中に含まれる頂点 pos

int64_t cnt = 0;

// 深さ優先探索
void dfs(const vector<int> &G, int v) {
    if(seen[v]) {
      fin = v;
      return;
    }
    // cout << v << endl;
    root.push_back(v);

    seen[v] = true;
    // cnt++;
    dfs(G, G[v]);
}


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

    // グラフ入力受取
    vector<int> G(N);
    for (int i = 0; i < N; ++i) {
        int b;
        cin >> b;
        --b; // 頂点番号が 1-indexed で与えられるので 0-indexed にする
        G[i] = b;
    }

    // 探索
    seen.assign(N, false);
    dfs(G, 0);

    // ループの頭
    auto itr = std::find(root.begin(), root.end(), fin);
    const int dist = std::distance(root.begin(), itr);
    const int loop = root.size()-dist;

    if(X - dist < 0) {
      cout << root.at(X)+1 << endl;
    } else {
      int64_t k = (X - dist) % loop;
      cout << root.at(dist+k)+1 << endl;
    }

}


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

int main() {
  int X,N;
  cin >> X >> N;
  vector<int> p(N);

  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  
  int dmem = 100;
  int ans = 0;
  for(int i = 0; i< 150; i++){
    int dis = abs(X - i);
    int count = 0;
    for(int j = 0; j < N; j++){
      if(i == p.at(j)){
        break;
      }
      else{
        count++;
        //cout << count << " ";
      }
      if(count == N){
        if(dis < dmem){
          ans = i;
          dmem = dis;
          //cout << i << " " << dmem << endl;
        }
        else{
          break;
          break;
        }
      }
    }
    //cout << endl;
  }
  
  if(N == 0){
    ans = X;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Formatter;

class Main{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			while(true){
				String[] nums = br.readLine().split(" ");
				int a = Integer.parseInt(nums[0]);
				int b = Integer.parseInt(nums[1]);
				int yaku = Yukurid(a,b);
				int bai = a * (b / yaku);
				System.out.println(yaku + " " + bai);
			}
		}
		catch(Exception e){
			return;
		}
	}
	
	private static int Yukurid(int a,int b){
		if(a < b){
			int temp = b;
			b = a;
			a = temp;
		}
		//double div = (double)a / b;
		int remainder = a % b;
		
		if(remainder == 0){ return b; }
		else { return Yukurid(b,remainder); }
	}

}

Measured memory_bytes: 9340
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
else:
    sortX = sorted(X)
    diffX = [sortX[i+1] - sortX[i] for i in range(M-1)]
    print(sortX[-1]-sortX[0]-sum(sorted(diffX, reverse=True)[:N-1]))

Measured memory_bytes: 13968
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

const int N = 100100;
int n;
int a[N];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		a[i]--;
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (a[a[i]] == i)
			ans++;
	printf("%d\n", ans / 2);

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

int M[N][N],n;
int d[N];

void bfs(int s){
	queue<int> q;
	q.push(s);
	for(int i=0;i<n;i++){
		d[i]=INFTY;
	}
	d[s]=0;
	int u;
	while(!q.empty()){
		u=q.front();
		q.pop();
		for(int v=0;v<n;v++){
			if(M[u][v]==0)
				continue;
			if(d[v]!=INFTY)
				continue;
			d[v]=d[u]+1;
			q.push(v);
		}
	}
	
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<((d[i]==INFTY)?(-1):d[i])<<endl;
	}
}

int main(){
	
	int k,u,v;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
			M[i][j]=0;
	}
	for(int i=0;i<n;i++){
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++){
			cin>>v;
			v--;
			M[u][v]=1;
		}
	}
	
	bfs(0);
	
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>

int main()
{
    int k,a,b;
    std::cin >> k >> a >> b;

    if(a<=b-(b%k))
    {
        std::cout << "OK" << std::endl;
    }
    else
    {
        std::cout << "NG" << std::endl;
    }
    
}

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

const int INF = 1e9;
enum {W, B};

int main() {
  int N;
  cin >> N;
  vector<int> C(2*N), A(2*N);
  for(auto i=0; i<2*N; ++i) {
    char c;
    cin >> c >> A[i];
    C[i] = (c=='W' ? W : B);
  }

  vector<vector<int>> index (N+1, vector<int>(2));
  for(auto i=0; i<2*N; ++i) index[A[i]][C[i]] = i;

  vector<vector<vector<int>>> sum(2*N+1, vector<vector<int>>(N+1, vector<int>(2)));
  for(auto i=0; i<2*N; ++i) for(auto j=0; j<A[i]; ++j) sum[i][j][C[i]] += 1;
  for(auto i=1; i<2*N; ++i) for(auto j=0; j<=N; ++j) for(auto c: {W, B}) sum[i][j][c] += sum[i-1][j][c];

  auto costw = [&](auto i, auto j) {
    auto k = index[i][W];
    return sum[k][i][W] + sum[k][j][B];
  };
  auto costb = [&](auto i, auto j) {
    auto k = index[j][B];
    return sum[k][j][B] + sum[k][i][W];
  };

  vector<vector<int>> dp(N+1, vector<int>(N+1, INF));
  dp[0][0] = 0;
  for(auto i=0; i<=N; ++i) for(auto j=0; j<=N; ++j) {
    if(i+1 <= N) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + costw(i+1, j));
    if(j+1 <= N) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + costb(i, j+1));
  }
  cout << dp[N][N] << endl;
}


Measured memory_bytes: 454016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int gm(int x, int n)
{
	if(x>n)
		x-=n;
	if(x<=0)
		x+=n;
	return x;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,x;
	cin>>n>>x;
	int z = 2*n-1;
	if(x==1||x==z)
	{
		cout<<"No\n";
		return 0;
	}
	cout<<"Yes\n";
	int st = gm(x-n+1,z);
	for(int i=0; i<z; i++)
	{
		cout<<st<<"\n";
		st=gm(st+1,z);
	}
}

Measured memory_bytes: 1536
import heapq
import sys
N = int(input())

r = [[1]*N for _ in range(N)]
g = [[]*N for _ in range(N)]
all = 0
for i in range(N):
  temp = list(map(int,(input().split())))
  g[i] = temp
  all += sum(temp)
#print(g,all)

for k in range(N):
  for i in range(N):
    for j in range(N):
      if g[i][j] > g[i][k] + g[k][j]:
        print("-1")
        sys.exit()
      elif g[i][j] == g[i][k] + g[k][j] and i != j and j != k and k != i:
        r[i][j] = 0
ans = 0
for i in range(N):
  for j in range(N):
    ans += g[i][j]*r[i][j]

ans = ans//2
print(ans)

Measured memory_bytes: 45880
#include <iostream>
using namespace std;
#define ll long long

ll a[100009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll s = 2, e = 2;
	for (int i = n - 1; i >= 0; i--) {
		ll r = ((s - 1) / a[i] + 1) * a[i];
		if (r > e) {
			cout << -1 << '\n';
			return 0;
		}
		s = r; e = (e / a[i] + 1) * a[i] - 1;
	}
	cout << s << " " << e << '\n';
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String line1 = sc.nextLine();
        String line2 = sc.nextLine();
        
        int k = Integer.parseInt(line1);
        
        String[] array = line2.split(" ");
        int a = Integer.parseInt(array[0]);
        int b = Integer.parseInt(array[1]);
        
        String result = "NG";
        for(int i = a; i <= b; i++)
        {
            if(i % k == 0)
            {
                result = "OK";
                break;
            }
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35796
n,x = map(int,input().split())

l = list(map(int,input().split()))

l2 = [0]*(n+1)

for i in range(n):
    l2[i+1] = l2[i]+l[i]
    
ans= 0
    
for i in l2:
    if i<=x:
        ans += 1
    else:
        break
    
print(ans)

Measured memory_bytes: 3060