akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
const int MAXN = 110;
const int MAXK =60;
int dp[MAXN][MAXK][5];
int arr[MAXN];
vector<int> v1;
int ans;
int dp2[MAXN][MAXK][5];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    for(int i=0;i<=n;i++){
        for(int j=i+1;j<=n+1;j++){
            vector<int> v1;
            if(i>=1){
                for(int x=1;x<=i;x++){
                    v1.push_back(arr[x]);
                    
                }
            }
            if(j<=n){
                for(int x=j;x<=n;x++){
                    v1.push_back(arr[x]);
                }
            }
            sort(v1.begin(),v1.end());
            int left =k- (v1.size());
            
            if(left<0){
                continue;
            }
            int y;
            
            for(y= 0;y<v1.size();y++){
                if(v1[y]>=0){
                    break;
                }
                if(!left){
                    
                    break;
                }
               
                left--;
                
            }
            
            int sum  = 0;
            for(y;y<v1.size();y++){
                sum+=v1[y];
                
            }
            ans = max(ans,sum);
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, m;
  cin >> n >> m;
  vll h(n), a(m), b(m);
  rep(i, n) cin >> h[i];
  rep(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
  map<ll, ll> ans;
  ll flag = 0;
  rep(i, m)
  {
    if(ans.count(a[i]))
    {
      ans[a[i]] = max(ans[a[i]], h[b[i]]);
    }
    else
    {
      ans[a[i]] = h[b[i]];
    }

    if(ans.count(b[i]))
    {
      ans[b[i]] = max(h[a[i]], ans[b[i]]);
    }
    else
    {
      ans[b[i]] = h[a[i]];
    }
  }
  rep(i, n)
  {
    if(ans.count(i))
    {
      if(ans[i] < h[i]) flag++;
    }
    else flag++;
  }
  fin(flag);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 11412
from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())

a = list(map(int, input().split(' ')))

# 最大公倍数
target_num = lcm(*a)

ans = 0
for i in range(n):
    ans += target_num//a[i]
#b = [target_num//num for num in a]

print(ans % (10**9+7))


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

int main(){
    int n,m,ans(0);
    cin >> n >> m;

    vector<int> d(m-1);
    vector<int> x(m);
    rep(i,m)    cin >> x[i];
    sort(x.begin(),x.end());

    if(n>=m){
        puts("0");
        return 0;
    }

    rep(i,m-1){
        d[i] = x[i+1] - x[i];
        ans += d[i];
    }
    sort(d.begin(),d.end(),greater<int>());

    rep(i,n-1){
        ans -= d[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<=9&&b<=9)cout<<a*b<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: usize = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let M: usize = sc.get();
    let mut adj = vec![Vec::new(); N];
    for _ in 0..M {
        let u: usize = sc.get::<usize>()-1;
        let v: usize = sc.get::<usize>()-1;
        adj[u].push(v);
    }
    let S: usize = sc.get::<usize>()-1;
    let T: usize = sc.get::<usize>()-1;
    let mut dp = vec![vec![INF; 3]; N];
    dp[S][0] = 0usize;
    let mut q = VecDeque::new();
    q.push_front((S, 0));
    while let Some((i, s)) = q.pop_back() {
        for &n in &adj[i] {
            if dp[n][(s+1) % 3] != INF {
                continue;
            }
            dp[n][(s+1) % 3] = dp[i][s] + 1;
            q.push_front((n, (s+1) % 3));
        }
    }
    if dp[T][0] == INF {
        println!("-1");
    } else {
        println!("{}", dp[T][0]/3);
    }
}


Measured memory_bytes: 18684
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  if (a > b ) cout << 0;
  else if ( n == 1 && a != b) cout << 0;
  else if ( n == 1 && a == b) cout << 1;
  else if (n == 2) cout << 1;
  else cout << b*(n-2) - a*(n-2) + 1<< endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int sheet[][] = new int[N][2];
        int ans = 0;
        for (int i = 0; N > i; i++) {
            sheet[i][0] = sc.nextInt();
            sheet[i][1] = sc.nextInt();
        }
        for (int j = 0; N > j; j++) {
            for (int t = sheet[j][0]; sheet[j][1] >= t; t++) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int hoge[] = {2,4,5,7,9};
int fuga[] = {0,1,6,8};

int main()
{
    int n;cin >> n;
    n = n%10;
    for(auto i : hoge)
    {
        if(n==i)
        {
            cout << "hon" << endl;
            return 0;
        }
    }
    for (auto i : fuga)
    {
        if(n==i)
        {
            cout << "pon" << endl;
            return 0;
        }
    }
    if(n==3)
    {
        cout << "bon" << endl;
        return 0;
    }
}

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

void CountingSort(vector<int> &A, vector<int> &B, int k) {
  vector<int> C(k+1);
  for (int  i = 0; i < k+1; i++)
    C.at(i) = 0;
  for (int i = 0; i < A.size(); i++)
    C.at(A.at(i))++;
  for (int i = 1; i < k+1; i++)
    C.at(i) += C.at(i-1);
  for (int i = A.size()-1; i >= 0; i--) {
    B.at(C.at(A.at(i))-1) = A.at(i);
    C.at(A.at(i))--;
  }
  
}
int main(void) {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  int k;
  for (int i = 0; i < n; i++) {
    if (i == 0 ) k = A.at(i);
    cin >> A.at(i);
    if (k < A.at(i)) k = A.at(i);
  }
  CountingSort(A, B, k);
  for (int i = 0; i < n; i++) {
    cout << B.at(i);
    if (i != n-1)
    cout << " ";
  }
  cout << endl;
  
}


Measured memory_bytes: 18404
// This is free and unencumbered software released into the public domain.

// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.

// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

// For more information, please refer to <http://unlicense.org>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

int main() {
  int a, b;
  cin >> a >> b;
  cout << (b % a == 0 ? a + b : b - a) << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char *argv[]){
        int a;
        scanf("%d",&a);
        if(a){
                printf("0\n");
        }else{
                printf("1\n");
        }
        return 0;
}

Measured memory_bytes: 1660
N=int(input())
*A,= map(int, input().split())

def cond(A):
    for a in A:
        if a%2==0:
            if (a%3!=0) and (a%5!=0):
                return False
    return True
            
if cond(A):
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 2940
#include<iostream>
 
using namespace std;
 
int main(){
    char S[5];
    scanf("%s", S);
    int sum=0;
    for(int i=0; i<4; i++){
        if(S[i]=='-')sum--;
        else sum++;
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
const int N=4400;
char str1[N];
long long sum;
int n,r,g,b;
int main(){
	scanf("%d%s",&n,str1+1);
	
	r=g=b=0;
	for(int i=1;i<=n;++i){
		if(str1[i]=='R')++r;
		else if(str1[i]=='G')++g;
		else ++b;
	}
	
	sum=1ll*r*g*b;
	
	for(int i=1;i<=n-2;++i){
		for(int j=i+1;j<=n-1;++j){
			int k=j+j-i;
			if(k>n)continue;
			if(str1[i]!=str1[j]&&str1[i]!=str1[k]&&str1[j]!=str1[k])sum--;
		}
	}
	
	printf("%lld\n",sum);
	
	return 0;
} 

Measured memory_bytes: 3836
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

R = {}
L = []
for i in A:
  if i not in R:
    R[i] = 1
    L.append(i)
  else:
    R[i] += 1

L.sort(reverse = True)

k = 0
t = R[L[0]]
for i in range(1, len(L)):
  k = (k + t * R[L[i]]) % MOD
  t += R[L[i]]

ans = k * ((K * (K - 1)) // 2) % MOD

k = 0
for i in range(N):
  for j in range(i):
    if A[i] < A[j]:
      k += 1
ans = (ans + k * K) % MOD

print(ans)

Measured memory_bytes: 3316
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
const ll INF = 1001001001;

int main() {
  int h,w;
  cin>>h>>w;
  int x,y;
  cin>>x>>y;
  
  cout<< h*w-x*w-y*h+y*x;
  
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int y,m,d;
  string s;
  cin >> s;
  {
    stringstream ss;
    ss << s.substr(5,2);
    ss >> m;
  }
  {
    stringstream ss;
    ss << s.substr(8,2);
    ss >> d;
  }
  if(m < 4) {
    cout << "Heisei" << endl;
  }
  else if(m > 4) {
    cout << "TBD" << endl;
  }
  else if(m <= 30) {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main()
{
    ll i,j,k,l,m,n,sum=0;
    cin>>n>>m;
    for(i=m;i<=n+1;i++)
    {
        ll a=(i*(i-1))/2;
        ll c=n-i;
        ll b=((n*(n+1)/2)-(c*(c+1)/2));
        sum+=(b-a+1);
        sum%=mod;

    }
    cout<<sum<<endl;


}


Measured memory_bytes: 3624
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10桁出力 cout << setprecision(10) << double;
#include <queue>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	string s;
	LL k;
	cin >> s >> k;
	FOR(i, 0, s.length()) {
		int t = s[i];
		if ((122-t + 1) <= k && s[i]!='a') {
			//cout << "NN"<<endl;
			s[i] = 'a';
			k -= (122-t + 1);
			//cout << "s=" << s << " , k=" << k << endl;
		}
	}

	// 残りのz消化
	//cout << "zan k = " << k << endl;
	if(k>=26)	k = k % 26;
	s[s.length() - 1] += k;
	int e = s[s.length() - 1];
	if (e > 122) {
		s[s.length() - 1] = 97 + (e - 123);
	}

	cout << s << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};


int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

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

    int count1 = 0;
    if(p[0] == 1){
        swap(p[0], p[1]);
        ++count1;
    }

    for(int i = 1;i < n; i++){
        if(p[i] == i + 1){
            swap(p[i], p[i + 1]);
            ++count1;
        }
    }

    int count2 = 0;
    if(p2[n - 1] == n){
        swap(p2[n - 1], p2[n - 2]);
        ++count2;
    }

    for(int i = n - 2;i >= 0; --i){
        if(p2[i] == i + 1){
            swap(p2[i], p2[i + 1]);
            ++count2;
        }
    }

    int ans = min(count1, count2);

    cout << ans << endl;

    return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll k, a, b;
  cin >> k >> a >> b;
  bl check = false;
  rep(i, a, b + 1) if(i % k == 0) check = true;
  cout << (check ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3620
object Main {
  def main(args: Array[String]) {

    var SEP = "####################"

    var housemap: Seq[Seq[Seq[Int]]] = Seq(
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
      Seq(Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
        Seq(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)))

    var input: List[String] = List()
    for (line <- scala.io.Source.stdin.getLines()) {
      input = input :+ line
    }
    input = input.slice(1, input.length)

    input.foreach { list =>

      var Array(b, f, r, v) = list.split(' ').map(_.toInt)
      var a1a: Seq[Seq[Seq[Int]]] = Seq()

      housemap.zipWithIndex.foreach {
        case (b1, b1idx) =>
          var a1: Seq[Seq[Int]] = Seq()

          b1.zipWithIndex.foreach {
            case (listtt, b2idx) if (b1idx == (b - 1) && b2idx == (f - 1)) => {
              a1 = a1 :+ listtt.updated(r-1, if ((listtt(r-1) + v) < 9) (listtt(r-1) + v) else 9)
            }
            case (listtt, b2idx) => { a1 = a1 :+ listtt }


          }
          a1a = a1a :+ a1
      }
      housemap = a1a
    }

    var stgs: Seq[String] = Seq()
    housemap.foreach { v =>
      var lines: Seq[String] = Seq()
      v.foreach { f =>
        lines = lines :+ " " + f.mkString(" ")
      }
      stgs = stgs :+ lines.mkString("\n")
    }
    println(stgs.mkString("\n" + SEP + "\n"))
  }

}

Measured memory_bytes: 47836
while 1 :
	m,f,r = map(int , raw_input().split())
	
	s = m + f
	
	if m == f == r == -1 :
		break
	elif m == -1 or f == -1 or s < 30 :
		print "F"
	elif s >= 80 :
		print "A"
	elif s >= 65 :	
		print "B"
	elif s >= 50 : 
		print "C"
	elif s >= 30 and r >= 50 :
		print "C"
	else :
		print "D"

Measured memory_bytes: 4212
N = int(input())
A = list(map(int, input().split()))
swap = 0
for i in range(N - 1):
    _i = i
    _min = A[i]
    for j in range(i + 1, N):
        if A[j] < _min:
            _i = j
            _min = A[j]
    if i != _i:
        swap += 1
        A[i], A[_i] = A[_i], A[i]
print(*A)
print(swap)



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

int main(){
    int N;
    cin >> N;
    vector<int> dp(N+1,1);
    for(int i=2; i<N+1; i++){
        int index = i;
        while(index <= N){
            dp.at(index) ++;
            index += i;
        }
    }
    int64_t sum = 0;
    for(int i=1; i<N+1; i++) sum += ((int64_t)i * (int64_t)dp.at(i));
    cout << sum << endl;
}

Measured memory_bytes: 42324
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if (a + b >= 24)
    {
        printf("%d\n", a + b - 24);
    }
    else
    {
        printf("%d\n", a + b);
    }
    return 0;
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N=read();
	string str;
	cin >> str;
	int left=0,right=0;
	REP(i,N){
		if(str[i]=='(') left++;
		else if(left>=1) left--;
		else right++;
	}
	
	REP(i,right){
		cout << '(';
	}
	REP(i,N){
		cout << str[i];
	}
	REP(i,left){
		cout << ')';
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int i,j,tmp,N,n;
	int a[3];
	scanf("%d",&N);
	for(n=1;n<=N;n++){
	for(i=0;i<3;i++){scanf("%d",&a[i]);}
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				tmp=a[i];
				a[i]=a[j];
				a[j]=tmp;
			}
		}
	}
		if(
			a[2]*a[2]==a[0]*a[0]+a[1]*a[1]
		){printf("YES\n");}else{printf("NO\n");}
		
		
	}
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  if(S.at(0)==S.at(1) || S.at(1)==S.at(2) || S.at(2)==S.at(3)){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good"  << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n string
	fmt.Scan(&n)

	var sum int
	for _, c := range n {
		i, _ := strconv.Atoi(string(c))
		sum += i
	}

	if sum%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


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

# 四隅のカードが裏を向くか
fc=(N==1 and M==1) # 4箇所のうち1箇所(自分自身)にのみカードがある場合
# 左端及び右端（四隅を含まない。）のカードが裏を向くか(N>=3)
fs=(N>=3 and M==1) # 6箇所のうち3箇所にのみカードがある場合
# 上端及び下端（四隅を含まない。）のカードが裏を向くか(M>=3)
fu=(M>=3 and N==1) # 同上
# 内部のカードが裏を向くか(N>=3 and M>=3)
fi=(M>=3 and N>=3) # N>1 and M>1のとき内部のカードは全て裏を向く。9箇所にカードがあるので

ans=(1 if fc else 0)+(N-2 if fs else 0)+(M-2 if fu else 0)+((M-2)*(N-2) if fi else 0)

print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s == u){
        a--;
    }else{
        b--;
    }
    cout << a << " " << b << endl;
    return(0);
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    A=sum(LI())
    if(A>N):
        print(-1)
    else:
        print(N-A)

if __name__ == '__main__':
    main()

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int ll
//#define endl '\n'

string s;

int32_t main()
{
    IOS
    cin>>s;
    int ans=inf;
    int n=s.length(),tmp=0;
    for (int i=0;i<n;i++)
    {
        tmp+=(s[i]-'0'==(i&1));
    }
    ans=min(ans,tmp);
    tmp=0;
    for (int i=0;i<n;i++)
    {
        tmp+=(s[i]-'0'==1-(i&1));
    }
    ans=min(ans,tmp);
    cout<<ans<<endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    int n,x,t;cin>>n>>x>>t;
    if(n%x==0) {
        cout<<(n/x)*t<<endl;
    } else {
        cout<<(n/x+1)*t<<endl;
    }
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(){
    int a,b;
    scanf("%d %d", &a, &b);
    if(a+b==15){
        printf("+\n");
    }
    else if(a*b==15){
        printf("*\n");
    }
    else
    {
        printf("x\n");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if (a<=c&&c<=b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);cerr<<fixed<<setprecision(5);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
/* VARIABLE DECLARATION START */
int globe[int(1e6)];
/*  FUCNTION TEMPLATE STARTS  HERE */
double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA
   int n;cin>>n;
   ll x;cin>>x;
   vector<ll> v(n);
   for(auto &x:v)cin>>x;
   ll init=accumulate(all(v),0ll);
   for(int i=1;i<sz(v);++i)
   {
     if(i==sz(v)-1)
     {
       if(v[i]+v[i-1]>x)
       {
        ll element=v[i]+v[i-1]-x;
        if(element<=v[i])
        v[i]-=element;
        else
        {
          element-=v[i];
          v[i]=0;
          v[i-1]-=element;
        }
       }
     }
     else
     {
       if(v[i]+v[i-1]>x)
       {
        ll element=v[i]+v[i-1]-x;
        if(element<=v[i])
        v[i]-=element;
        else
        {
          element-=v[i];
          v[i]=0;
          v[i-1]-=element;
        }
       }
     }

   }
   ll final=accumulate(all(v),0ll);
   cout<<init-final<<endl;


   
}



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

int sum_of_digits(int N) {
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = sum_of_digits(i);
    if (A <= sum && sum <= B) {
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    int N;
    cin >> N;
    
    double nn = N;
    
    if (N%2 == 0) {
        cout << fixed;
        cout << setprecision(8) << 0.5 << endl;
    }else{
        cout << fixed;
        cout << setprecision(8) << ((nn-1)/2+1)/nn << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  ll flag = 1;
  rep(i,0,n){
    ll a;
    cin>>a;
    if(a%2==0){
      if(a%5==0||a%3==0){

      }
      else{
        flag=0;
      }
    }
  }
  if(flag==1){
      cout << "APPROVED" << endl;
  }
  else{
      cout << "DENIED" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int A[] = new int[N];
        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        Pair bc[] = new Pair[M];
        for(int i=0; i<M; i++){
            int b = sc.nextInt();
            int c = sc.nextInt();
            bc[i] = new Pair(c,b);
        }

        Arrays.sort(bc);
        long sum = 0;
        int i=0;
            for(int j=0; j<M && i<N; j++){
                for(int k=0; k<bc[j].second && i<N;k++){
                    int c = bc[j].first;
                    if(A[i] < c){
                        sum += c;
                    } else {
                        sum += A[i];
                    }
                    i++;
                }
            }
        for(int j=i; j<N; j++) {
            sum += A[j];
        }


        System.out.println(sum);
    }
}

//import java.util.*;
//import java.util.*;

class Pair implements Comparable<Pair>{
    //firstが検索対象
    public int first;
    public int second;
    Pair(int a, int b) {
        this.first = a;
        this.second = b;
    }

    public int compareTo(Pair pair) {
        //降順なら上１，下−１
        //昇順なら上−１，下１
        if (this.first < pair.first) return 1;
        if (this.first > pair.first) return -1;
        return 0;
    }
}




Measured memory_bytes: 92444
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <vector>
#include <string>

using ll = long long;

using namespace std;

void solve() {
    ll x;
    cin >> x;
    ll f = x / 500;
    ll y = (x - f * 500) / 5;
    cout << f * 1000 + y * 5 << endl;
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
 
int main()
{
  int N, A[100000];
 
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
 
 
  auto check = [&](int size)
  {
    int left = 0, right = size - 1;
    int flag = -1;
    for(int i = 1; i < N; i++) {
      if(A[i - 1] < A[i]) {
        ++left;
        ++right;
        right = size - 1;
      } else if(A[i] < A[i - 1]) {
        left = 0;
        --right;
      }
      if(left > right) return (false);
    }
    return (true);
  };
 
  int ok = 1 << 30, ng = 0;
  while(ok - ng > 1) {
    int mid = (ok + ng) >> 1;
    if(check(mid)) ok = mid;
    else ng = mid;
  }
 
  cout << ok << endl;
}

Measured memory_bytes: 3480
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    partial_sum(A.begin(), A.end(), A.begin());
    transform(A.begin(), A.end(), A.begin(), [M](int64_t x) {return x%M;});

    int64_t ans = count(A.begin(), A.end(), 0L);
    map<int,int> mp;
    for(auto e: A) {
        mp[e]++;
    }
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        int64_t val = itr->second;
        ans += val*(val-1) / 2;
    }

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


Measured memory_bytes: 3968
n = int(input())

cnt = 0
digits = 0
for i in range(1, 12):
    cnt += pow(26, i)
    if n <= cnt:
        digits = i
        break

k = n - cnt + pow(26, digits) - 1
#digits桁の中で何番目か

alf = 'abcdefghijklmnopqrstuvwxyz'
ans = ''

for i in range(digits):
    q = k // 26
    r = k%26
    ans = alf[r] + ans
    k = q
print(ans)

Measured memory_bytes: 9152
#include <iostream>

using namespace std;

const int N = 1e5 + 5;
int n;
int a[N];
bool vis[N];
int cnt = 0 ;

int main()
{
    scanf("%d" , &n);

    for(int i = 0 ; i < n ; i++) {
        scanf("%d" , a + i);
    }

    for(int i = 0 ; i < n ; i++) {
        if(a[i] % 4 == 0) {
            vis[i] = true;
            cnt++;
        }
    }

    if(cnt >= n / 2) {
        cout << "Yes" << endl;
        return 0;
    }

    int cnt1 = 0;
    for(int i = 0 ; i < n ; i++) {
        if(vis[i] == false) {
            if(a[i] % 2 == 0) {
                cnt1++;
            }
        }
    }

    if(cnt1 >= n - 2 * cnt) {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int H = nextInt();
  int A = nextInt();
  cout << ((H+A-1)/A) << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
import math
A,B = map(int,input().split())
min_8=math.ceil(A*(100/8))
max_8=int((A+1)*(100/8))
if max_8==(A+1)*(100/8):
    max_8-=1
min_10=B*10
max_10=int((B+1)*10)-1
if max_8 < min_10:
    print("-1")
elif min_8 > max_10:
    print("-1")
elif max_8 >= min_10:
    if min_8 < min_10:
        print(min_10)
    elif min_8 >= min_10:
        print(min_8)

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(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 INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    ll n,k; cin >> n >> k; // nは街の個数,kは高橋王が移動する回数
    vector<ll> a(n); REP(i,n) {
        ll temp; cin >> temp;
        a[i] = temp - 1; // i番目の村の転送先
    }

    // 3周分だけ周りroopを見つける
    map<ll,ll> roop_finder; //通った回数をカウントする通った回数が一回であればroop外2回以上であればroopのメンバー
    vector<ll> roop; //roop担っているものを順番に入れたもの.
    vector<ll> road_to_roop; // roopに入るまでの順番を記録したもの
    // ll jun_idx = 0, road_idx = 0; // jun_idx roopのメンバーのidx road_idx roopまでのインデックス
    ll temp = 0;
    REP(i,2*n) {
        roop_finder[temp]++;
        // if (roop_finder[temp] == 1) {
        //     road_to_roop.PB(temp);
        // }
        if (roop_finder[temp] == 2) {
            roop.PB(temp);
        }
        temp = a[temp];
    }

    // cout << "roop finder ";
    // REP(i,SIZE(roop_finder)) cout << roop_finder[i] << " ";
    // cout << "\n";

    // cout << "roop ";
    // REP(i,SIZE(roop)) cout << roop[i] << " ";
    // cout << "\n";
    
    // roopに入るまでの数をカウントする.
    ll road = 0;
    // REP(i, SIZE(road_to_roop)) {
    //     if (road_to_roop[i] != roop[0]) road++;
    //     else break;
    // }
    REP(i,SIZE(roop_finder)) {
        if (roop_finder[i] == 1) road++;
    }
    // cout << road << "\n";

    ll roop_num = SIZE(roop);

    temp = k - road;
    ll idx = temp%roop_num;
    if (k < n) {
        temp = 0;
        REP(i,k) {
            temp = a[temp];
        }
        cout << temp + 1 << "\n";
    }
    else cout << roop[min(idx,temp)]+1 << "\n";

    return 0;
}


Measured memory_bytes: 18592
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

//C++17
template<typename Type>
Type GCD(Type a,Type b){ return b ? GCD(b,a%b) : a ;}
template<typename Type>
Type LCM(Type a,Type b){ return a*b / GCD(a,b) ;}

template<typename Type>//文字列の置換/Boost:replace_all()
Type replace_str(Type str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int a,b,c;cin >> a >> b >> c;
    cout << a+b+c-max({a,b,c}) << endl;
    return 0;
}


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

int main() {
    int N, P;
    cin >> N >> P;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<vector<long long>> dp(N + 1, vector<long long>(2, 0));
    dp[0][0] = 1;
    rep(i, N) {
        dp[i + 1][0] += dp[i][0];
        dp[i + 1][1] += dp[i][1];
        if (A[i] & 1) {
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += dp[i][0];
        } else {
            dp[i + 1][0] += dp[i][0];
            dp[i + 1][1] += dp[i][1];
        }
    }
    cout << dp[N][P] << endl;
    return 0;
}


Measured memory_bytes: 256
p=print
r=range
p(6484)
p(P:="+",0,1,3)
p(L:="<",2,3,3)
for x in 0,1:
	p(P,x,3,x)
	for t in r(30):p(P,v:=x+4,v,v);p(P,v,3,6),exec('p(P,6,6,6);'*(29-t));p(L,6,x,T:=x*60+9+t);p(P,v,T,v)
for t in r(60):p(P,2,2,2);[(p(P,8+t-s,69+s,5),p(L,3,5,6),p(P,2,6,2))for s in r(t)]

Measured memory_bytes: 9332
#include<iostream>
using namespace std;
int main () {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; x ++) {
    for (int y = 0; y <= K; y ++) {
      int z = S - x - y;
      if (z >= 0 && z <= K) ans ++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
  for(ll i=0;i<=n-1;i++){
    ll j=a-c*i;
    ll k=a-d*i;
    j+=d*(n-1-i);
    k+=c*(n-1-i);
    if(j>=b&&k<=b){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 256
from collections import deque
INF=10**18
h,w=map(int,input().split())
a=[input() for _ in range(h)]
d=[[INF for _ in range(w)]for _ in range(h)]
dx=[0,1,0,-1]
dy=[1,0,-1,0]
sx,sy=0,0
gx,gy=h-1,w-1
d[sx][sy]=1
q=deque([(sx,sy)])
while q:
  x,y=q.popleft()
  if (x,y)==(gx,gy):break
  for i in range(4):
    nx,ny=x+dx[i],y+dy[i]
    if 0<=nx<h and 0<=ny<w:
      if a[nx][ny]=='.' and d[nx][ny]==INF:
        d[nx][ny]=d[x][y]+1
        q.append((nx,ny))
if d[gx][gy]==INF:print(-1)
else:
  cnt=0
  for i in a:
    cnt+=i.count('.')
  print(cnt-d[gx][gy])

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

using namespace std;

int main(){
  string s,t;
  cin >>s>>t;
  bool x = true;
  rep(i, s.size()){
    if(s[i] != t[i]){
      x = false;
    }
  }
  if(x){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3620
#include <stdio.h>

int main() {
  int N;
  int x;
  int left;
  int right;
  int temp;
  long long int c = 0;

  scanf("%d %d", &N, &x);
  scanf(" %d", &left);
  for (int i = 1; i < N; i++) {
    scanf(" %d", &right);
    temp = left + right - x;
    if (temp > 0) {
      if (temp <= right) {
        right -= temp;
        c += temp;
      } else {
        right = 0;
        c += temp;
      }
    }
    left = right;
  }

  printf("%lld\n", c);

  return 0;
}

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

using namespace std;

int main(){
	long long n;
	cin>>n;
	long long cnt=0;

	for(int i=1;n>0;i++){
		cnt++;
		n-=i;
	}

	cout<<cnt<<endl;

	return 0;
}


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

using static Input;
using static Util;
class Program
{
    static int N;
//    static int[] A;
    static int[] B;
//    static int[] C;
    static void INPUT()
    {
        N = NextInt();
        //A = LineInt();
        B = LineInt();
        //C = LineInt();
    }
    static void OUTPUT()
    {
        var ans = 0;
        var prev = int.MaxValue;
        foreach (var i in B)
        {
            ans += Math.Min(prev, i);
            prev = i;
        }
        ans += prev;
        Console.WriteLine(ans);

    }

    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
        INPUT();
#else
        INPUT();
#endif
        OUTPUT();
    }

    static void TESTINPUT()
    {
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 13396