akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 1e6
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
 
int max(int a, int b){
    if(a>b)
        return a;
    return b;
}
int min(int a, int b){
    if(a<b)
        return a;
    return b;
}
 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

int mod = 1e9 + 7;

int32_t main(){
	int n;
	cin>>n;
	int a[n+1];
	int pref[n+1];
	pref[0] = 0;
	a[0] = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		pref[i] = pref[i-1] + a[i];
	}
	int dp[n+1][n+1];// first index is length and other is start point
	for(int i=1;i<=n;i++){
		dp[1][i] = 0;
	}
	for(int len = 2; len <=n; len++){
		for(int left = 1; left <=n; left++){
			int right = left + len - 1;
			if(right > n)
				continue;
			int ans = 1e17;
			for(int sublen = 1; sublen < len; sublen ++){
				int right1 = left + sublen -1;
				int left2 = left + sublen;
				int len2 = right - left2 + 1;
                //if(len == 3 && left == 1)
                    //cout<<right1<<" --> "<<left2<<" "<<len2<<endl;
				ans = min(ans, dp[sublen][left] + dp[len2][left2] + pref[right] - pref[left-1]);
			}
            ///cout<<len<<" "<<left<<" "<<ans<<endl;
			dp[len][left] = ans;
		}
	}
	cout<<dp[n][1]<<endl;


	
}













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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m,k;
    cin>>n>>k;
    ll a[n];
    ll tot=0;
    vector<ll> temp;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        tot+=a[i];
    }
    for(i=1;i<=sqrt(tot);i++)
    {
        if(tot%i==0)
        {
            temp.pb(i);
            temp.pb(tot/i);
        }
    }
    ll maxi=1;
    for(auto x : temp)
    {
        ll tp[n];
        ll tot=0;
        for(i=0;i<n;i++)
        {
            tp[i]=a[i]%x;
            tot+=tp[i];
        }
        sort(tp,tp+n);
        ll pre[n+1]={0};
        ll till=0;
        for(i=1;i<=n;i++)
        {
            pre[i]=pre[i-1]+tp[i-1];
        }
        for(i=n-1;i>=0;i--)
        {
            till+=(x-tp[i]);
            if(pre[i]==till && till<=k)
            {
                maxi=max(maxi,x);
            }
        }
    }
    cout<<maxi;
    return 0;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> val(n, 0);
    rep(i, 0, n) {
        cin >> val[i];
    }
    sort(val.begin(), val.end());
    int ans = 0;
    rep(i, 0, k) {
        ans += val[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3560
import math
n, d = map(int, input().split())

x = []
for i in range(n):
    x.append(list(map(int, input().split())))
    
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k]) ** 2
        if int(math.sqrt(tmp)) ** 2 == tmp:
            ans += 1
print(ans)
            

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  string s;
  cin >> s;
  
  for(int i = 0; i < s.size(); i++) {
    if(i == 3) cout << "8";
    else cout << s[i];
  }
  cout << endl;
}

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

int main() {
  string S;
  cin >> S;
  if( S == "SUN")
   cout << 7 <<endl;
  if( S == "SAT")
   cout << 1 <<endl;
  if( S == "FRI")
   cout << 2 <<endl;
  if( S == "THU")
   cout << 3 <<endl;
  if( S == "WED")
   cout << 4 <<endl;
  if( S == "TUE")
   cout << 5 <<endl;
  if( S == "MON")
   cout << 6 <<endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>

using namespace std;

using i64 = long long;

int main() {
    
    int n, x;
    cin >> n >> x;
    
    vector<i64> a(n);
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    sort(a.rbegin(), a.rend());
    
    const i64 mod = 1000000000 + 7;

    vector<i64> inv(n + 1);
    vector<i64> fact(n + 1);

    for (i64 i = 1; i < n + 1; i++) {
        inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    }
    
    fact[0] = 1;

    for(int i = 1; i < n + 1; ++i) {
        fact[i] = fact[i - 1] * i % mod;
    }
    
    vector<vector<i64>> dp(n + 1, vector<i64>(x + 1));
    
    dp[0][x] = 1;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= x; j++) {            
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * (n - i - 1) % mod * inv[n - i] % mod) % mod;
            dp[i + 1][j % a[i]] = (dp[i + 1][j % a[i]] + dp[i][j] * inv[n - i] % mod) % mod;
        }
    }
    
    
    i64 ans = 0;
    
    for (int i = 0; i <= x; i++) {
        ans = (ans + i * dp[n][i] % mod) % mod;       
    }
    
    ans = ans * fact[n] % mod;
    
    cout << ans << endl;
}

Measured memory_bytes: 158592
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n, m;
  cin >> n >> m;
  string ans = "No";
  if (n == m) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

k, n = MAP()
a = LIST()

b = []

for x in range(0, n - 1):
    b.append(a[x + 1] - a[x])

b.append(k - a[n - 1] + a[0])

print(k - max(b))

Measured memory_bytes: 25164
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let l:Vec<u32> = (0..n).map(|_| read()).collect();

    let mx = l.iter().max().unwrap();
    //debug!(mx);
    println!("{}", if l.iter().sum::<u32>() - mx > *mx {"Yes"} else {"No"});
    
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
    using namespace std;
    int main(){

        int n,x,y,c=0,j;
        bool r=false;
        scanf("%d",&n);
        scanf("%d",&x);
        y=x;
        n--;
        j=n;
        while(n--){
            scanf("%d",&x);
            if(r)y--;

            if(x>=y)c++;
            else c=0;

            if(x==y)r=false;
            else r=true;
            y=x;

        }
        if(c==j||c==j-1)printf("Yes");
        else printf("No");
        return 0;
    }

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)

/*
bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
}
int gcd(int a, int b) 
{ 
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    if (a == b) 
        return a; 
   
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
void dfs(int x,int y){
		if(x == n+1){
			int tmp = 0;
			FOR(i,0,k){
				if(tmp1[mortyy[i]]-tmp1[morty[i]] == mortyyy[i])tmp+=mortyyyy[i];
			}
			rick = max(rick,tmp);
			return ;
		}
		int i;
		for(i = y;i<=n1;i++){
			tmp1[x] = i;
			dfs(x+1,i);
		}
	}
*/


//3111111111111111111111111111111




	void solve(){

		ini(n);
		ini(k);
		int morty[310];
		FOR(i,0,n)morty[i] = 0;
		FOR(i,0,k){
			ini(x);
			FOR(i1,0,x){
				ini(x1);
				x1--;
				morty[x1] = 1;
			}
		}
		int rick = 0;
		FOR(i,0,n){if(morty[i] == 0)rick++;}
		out(rick);





	}









































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    lol x;
    cin >> x;
    cout << (x/500) * 1000 + ((x%500) /5) * 5 << '\n'; 
    return 0;
} 


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  if(N==M) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3600
#pragma target("avx")
#pragma target("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
        int n;
        scanf("%d", &n);
        V a(n);
        scan(a);
        rep(i, 0, n) a[i] -= i+1;
        std::sort(be(a));
        int b = a[n/2];
        ll ans = 0;
        rep(i, 0, n) ans += llabs(a[i]-b);
        printf("%ld\n", ans);
        return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
// dp[i日目まで][行動jを取った] <- 最大値
int dp[100100][3],v[100100][3];
int main(){
  int n;
  cin >> n;
  rep(i,n)cin >> v[i][0] >> v[i][1] >> v[i][2];
  // dp[0][0] = v[0][0],dp[0][1] = v[0][1],dp[0][2] = v[0][2];
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(j == k)continue;
        dp[i + 1][j] = max(dp[i][k] + v[i][j],dp[i + 1][j]);
      }
    }
  }
  int ans = 0;
  rep(i,3)ans = max(ans,dp[n][i]);
  cout << ans << endl;
  return 0;
}


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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

void Solve()
{
	string S;
	cin >> S;
	int i = S.length() - 1;
	char c = S[i];
	if (c == 's') {
		S += "es";
	} else {
		S += "s";
	}

	cout << S << endl;
}

// メインs
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

bool go() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    if (x % 2 == 1) continue;
    if (x % 3 == 0 || x % 5 == 0) continue;
    return false;
  }
}

int main() {
  if (go()) {
    cout << "APPROVED\n";
  } else {
    cout << "DENIED\n";
  }
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vpii = vector<pii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { if (a > b) { a = b; return true; } else return false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { if (a < b) { a = b; return true; } else return false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  cin >> s;
  vb t(26);
  rep(i, s.size()) {
    if (t[s[i]]) {
      cout << "no" << endl;
      return;
    }
    t[s[i]] = true;
  }
  cout << "yes" << endl;
}


Measured memory_bytes: 256
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=185+10;

int n,m;
char a[N][N]; int s[N][N];
int dp[2][N][N][N];

int same(int lx,int ly,int rx,int ry) {
    int o=s[rx][ry]-s[lx-1][ry]-s[rx][ly-1]+s[lx-1][ly-1];
    return o==(rx-lx+1)*(ry-ly+1)||o==0;
}

int f(int o,int i,int j,int k) {
    int L=i,R=j-1,res=0;
    while (L<=R) {
        int mid=(L+R)>>1;
        res=max(res,min(dp[o][i][mid][k],dp[o][mid+1][j][k]));
        if (dp[o][i][mid][k]<dp[o][mid+1][j][k]) R=mid-1;
        else L=mid+1;
    }
    return res;
}

int main() {
    n=read(),m=read();
    for (int i=1;i<=n;++i) scanf("%s",a[i]+1);
    for (int i=1;i<=n;++i)
        for (int j=1;j<=m;++j)
            s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(a[i][j]=='#');
    if (same(1,1,n,m)) { puts("0"); return 0; }
    for (int i=1;i<=n;++i)
        for (int j=i;j<=n;++j)
            for (int k=1,t;k<=m;k=t) {
                t=k;
                while (t<=m&&same(i,k,j,t)) ++t;
                for (int p=k;p<t;++p) dp[0][i][j][p]=t-1;
                if (k==t) dp[0][i][j][k]=k-1,++t;
            }
    for (int w=1;;++w) {
        int o=w&1,p=o^1;
        for (int i=1;i<=n;++i)
            for (int j=i;j<=n;++j)
                for (int k=1;k<=m;++k) {
                    int t=dp[p][i][j][k];
                    if (t==m) dp[o][i][j][k]=m;
                    else dp[o][i][j][k]=max(dp[p][i][j][t+1],f(p,i,j,k));
                }
        if (dp[o][1][n][1]==m) { printf("%d\n",w); break; }
    }
    return 0;
}

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

using namespace std;

int main() {
    int a , b , x , t = 1 , ma , mi ;
    cin >> x >> a >> b ;
    x -= a ;
    while (t == 1 ) {
        if (x >= b) {
            x -= b ;
        }
        else {
            t = 0 ;
        }
    }
    cout << x ;
    return 0 ;
}


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



int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int ans=0;
  rep(i, n){
    if(i%2==0 && a[i]%2==1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

vint a(1000010,1);
int main(){
	a[0]=a[1]=0;
	for(int i=0;i*i<1000010;i++){
		if(a[i]){
			for(int j=i*i;j<1000010;j+=i){
				a[j]=0;
			}
		}
	}
	int b,d,n;
	while(cin>>b>>d>>n,b&&d&&n){
		while(n){
			if(a[b]) n--;
			if(!n) cout<<b<<endl;
			b+=d;
		}
	}
	return 0;
	
}

Measured memory_bytes: 4900
#define MOD 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define has(set, x) set.find(x) != set.end()
#define nohas(set, x) set.find(x) == set.end()
#define inc(mpp, x) {if(has(mpp, x)) mpp[x]++; else mpp.insert(mp(x,1));}
#define decc(mpp, x) {if(has(mpp, x)) {if(mpp[x] > 1) mpp[x]--; else mpp.erase(x);}}
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define um unordered_map
#define us unordered_set
#include <iostream>
#include <list>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <fstream>
#include <algorithm>
using namespace std;
const int INF = 1 << 29;
typedef long long ll;
typedef unsigned long long ull;
inline int two(int n) { return 1 << n; }
ll extgcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } else { int g = extgcd(b, a%b, y, x); y -= a / b * x; return g; } }
ll modpow(ll a, ll b) { ll res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1)res = res * a%MOD; a = a * a%MOD; }return res; }

ll arr[100000];
ll res[100000];

int main() {
	fast;
	ifstream in("input.txt");
	ofstream out("output.txt");
	int t, n;
	ll mx = -1e12;
	ll x;
	cin >> x;
	ll res = 0;
	res += 1000*(x / 500);
	x %= 500;
	res += 5*(x / 5);
	cout << res << endl;
	
	return 0;
}

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

int main(){
  int a,b,c,d,e,res = 0;
  cin >> a >> b >> c >> d >> e;
  if(a < 0) res += -a * c + d;
  res += e * min(b,b - a);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

// 1000000000000001
// 3817158266467287
// x^n(mod M)
ll mpow(ll x, ll n) {
    ll ans = 1ll;
    while(n != 0){
        if (n&1) ans = ans*x;
        x = x*x;
        n = n >> 1;
    }
    return ans;
}

int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    vector<ll> len(13);
    rep(i,13) len[i] = (mpow(26ll, i)-1)/25ll;
    // print(len);
    auto itr = upper_bound(len.begin(), len.end(), n);
    int idx = itr-len.begin()-1;
    --itr;
    n -= *itr;
    string ans(idx, 'a');
    // cout << n << '\n';
    // cout << ans << '\n';

    int cnt = 0;
    while (n > 0) {
        char c = (n%26)+'a';
        ans[cnt] = c;
        n/=26;
        ++cnt;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int a, b, c, d;

  cin >> a >> b >> c >> d;

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


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>

#define REP(i,n) for(int i = 0; i < (n); i++)

using namespace std;

double sx[500];
double sy[500];
double sz[500];
double sd[500];

bool   seen[500];

template<class T>
inline T dbl(T a){ return a * a; }
template<class T>
inline T dist2(T ax, T ay, T az, T bx, T by, T bz){
  return dbl(ax - bx) + dbl(ay - by) + dbl(az - bz);
}

int main(){
  int n;
  int m;
  while(scanf("%d", &n), n){
    REP(i, n){
      scanf("%lf%lf%lf", sx+i, sy+i, sz+i);
      seen[i] = false;
      sd[i] = dist2(0.0, 0.0, 0.0, sx[i], sy[i], sz[i]);
    }
    scanf("%d", &m);
    REP(i, m){
      double tx, ty, tz, phi;
      scanf("%lf%lf%lf%lf", &tx, &ty, &tz, &phi);
      double d = dist2(0.0, 0.0, 0.0, tx, ty, tz);

      REP(j, n) if(!seen[j]){
	double dist = dist2(tx, ty, tz, sx[j], sy[j], sz[j]);
	double coss = (d + sd[j] - dist) / (2 * sqrt(d * sd[j]));

	if(coss > cos(phi))
	  seen[j] = true;
      }
    }

    cout << count(seen, seen + n, true) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
# -*- coding:utf-8 -*-
import numpy as np

n = int(raw_input())

A_list = map(int, raw_input().split())
A_list_np = np.array(A_list)

minus_sum = np.sum(A_list_np < 0)

if(minus_sum%2 == 0):
	print np.sum(np.abs(A_list_np))
else:
	print np.sum(np.abs(A_list_np))-np.min(np.abs(A_list_np)) * 2


Measured memory_bytes: 18836
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

ll solve2(const vector<ll>& a) {
  // cout << a << endl;
  const ll n = a.size();
  vector<ll> S(n+1, 0);
  rep(i, n) S[i+1] = S[i] + a[i];
  // cout << S << endl;
  ll left = 1, right = n-2;
  ll res = S[n-1], sum = S[n-2] * 2 + (S[n] - S[n-1]) * 2;
  ll L = S[n];
  while (true) {
    chmax(res, sum - (L - S[n-left]));
    if (right > left) {
      chmax(res, sum - S[right] + S[right-left] * 2);
    }
    if (left+1 > right-1) break;
    // 右を縮める
    sum -= S[right] * 2;
    sum += S[right-(left+0)] * 2;
    sum += S[right-(left+1)] * 2;
    --right;
    // 左を伸ばす
    sum += (S[n] - S[n-(left+1)]) * 2;
    ++left;
  }
  // cout << res << endl;
  return res;
}
ll solve(vector<ll> a) {
  if (a.size() == 2) return *max_element(all(a));
  ll res = solve2(a);
  reverse(all(a));
  chmax(res, solve2(a));
  return res;
}

void solve() {
  ll L, n; cin >> L >> n;
  vector<ll> X(n); cin >> X;
  X.pb(0);
  X.pb(L);
  sort(all(X));
  ++n;
  vector<ll> a(n);
  rep(i, n) {
    a[i] = X[i+1] - X[i];
  }
  ll ans = solve(a);
  reverse(all(a));
  chmax(ans, solve(a));
  cout << ans << endl;
}


Measured memory_bytes: 7908
import re
import itertools

s=input()
k=int(input())
alphs=sorted(list(set(s)))[0:k]
candsubstrings0=map(lambda x:[s[m.start():(m.end()+k)] for m in re.finditer(x,s)],alphs)
candsubstrings1= sorted(list(set([e for  inner_list in candsubstrings0 for e in inner_list])))[0:k]

def get_all_substrings(input_string):
  length = len(input_string)
  return [input_string[i:j + 1] for i in range(length) for j in range(i,length)]

candsubstrings2 = list(map(get_all_substrings,candsubstrings1))
candsubstrings3= sorted(list(set([e for  inner_list in candsubstrings2 for e in inner_list])))[0:k]
    
print(candsubstrings3[k-1])


Measured memory_bytes: 3572
#include <bits/stdc++.h>
          using namespace std;
          #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
          #define M_PI 3.14159265358979323846
          #define data data_
          #define ff first
          #define ss second
          #define pb push_back
          #define ll long long
          #define ld long double

          int main()
          {
               tani_nachi_ke  

               int n;
               cin >> n;
               set<int> st;
               for(int i = 0; i < n; i++)
               {
                    int x;
                    cin >> x;
                    st.insert(x);
               }

               if(st.size() == n)
                cout << "YES\n";
                else
                    cout << "NO\n";



         
               return 0;
          }

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A.at(i);
  }
  for (int i = K + 1; i <= N; i++) {
    if (A.at(i) > A.at(i - K)) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}

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

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

	int res = a[0][0];
	for(int i = 0; i < n; i++) res += a[1][i];
	int tmp = res;
	for (int i = 0; i < n-1; i++)
	{
		tmp += - a[1][i] + a[0][i+1];
		res = max(res, tmp);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 6

typedef struct{
  double x;
  double y;
}Point;

void koch(int,Point,Point);
#define PI 3.141592653589793
double radian = 60 * (PI/180.0);

int main()
{
  int n,i;

  Point p1,p2;
  p1.x=0,p1.y=0,p2.x=100,p2.y=0;
  scanf("%d",&n);
  printf("%.8f %.8f\n",p1.x,p2.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);

  return 0;
}

void koch(int n,Point p1,Point p2)
{
  Point s,t,u;

  if(n==0){
    return;
  }

  s.x=(2*p1.x+p2.x)/3;
  s.y=(2*p1.y+p2.y)/3;
  t.x=(p1.x+2*p2.x)/3;
  t.y=(p1.y+2*p2.y)/3;
  u.x=(t.x-s.x)*cos(radian)-(t.y-s.y)*sin(radian)+s.x;
  u.y=(t.x-s.x)*sin(radian)+(t.y-s.y)*cos(radian)+s.y;

  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
using namespace std;

int c[29], n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		char e; cin >> e;
		c[e - 'A']++;
	}
	int cnt = 0;
	for (int i = 0; i < 26; i++) {
		if (c[i] >= 1) cnt++;
	}
	if (cnt == 3) cout << "Three" << endl;
	else cout << "Four" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
	int a, b, c, cnt = 0;
	
	scanf( "%d %d %d", &a, &b, &c );
	
	while( a <= b ){
		if( (c % a) == 0 ){
			cnt++;
		}
		a++;
	}
	
	printf("%d\n", cnt);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int i = 0;
  while (i < (int) s.size() && s[i] == '1') {
    ++i;
  }
  if (i >= k) {
    cout << 1 << '\n';
  } else {
    cout << s[i] - '0' << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    count += bisect_left(L, L[a]+L[b]) - b - 1

print(count)


Measured memory_bytes: 3188
#include<stdio.h>
#define N 100

int main(){
    int i,j,k,v,A[N];

    scanf("%d",&i);

    for(j = 0;j < i;j++){
        scanf("%d",&A[j]);
        printf("%d",A[j]);
        if(j == (i - 1)) break;
        printf(" ");
    } printf("\n");

    for(j = 1;j < i;j++){
        v = A[j];
        k = j - 1;
        while(k >= 0 && A[k] > v){
            A[k+1] = A[k];
            k--;
            A[k+1] = v;
        }
        for(k = 0;k < i;k++){
            printf("%d",A[k]);
            if(k == (i - 1)) break;
            printf(" ");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2128
import java.util.*;

public class Main{

    public static List<Integer> P;
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int K = scanner.nextInt();
        final int mod = 1000000007;
        int count = 0;
        for(int i = K; i<=N+1; i++){
            long min = (((long)i - 1) * (long)i) / 2;
            long max = ((long)(N + N-i+1) * (long)i) / 2;
            long num = max - min + 1;
            num = num % mod;
            count = (count + (int)(num))%mod;
        }
        System.out.println(count);
    }
}

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

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

using namespace std;

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

	bool odd = true;

	rep(i, S.size()) {
		if (odd) {
			if (!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')) {
				cout << "No";
				return 0;
			}
		}
		else {
			if (!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')) {
				cout << "No";
				return 0;
			}
		}
		odd = !odd;
	}
	cout << "Yes";
}



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

int h, w;

int main(void){
	cin >> h >> w;
	vector<string> c(h);
	rep(i, h) cin >> c[i];
	rep(i, 2*h){
		rep(j, w){
			cout << c[i/2][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	cin>>n;
  long int sum=0;
  for(int i=1;i<n+1;i++){
    if(i%3==0||i%5==0){
      sum-=i;
    }
   
    sum+=i;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3636
<?php
list($x, $y) = explode(" ", trim(fgets(STDIN)));
$flg = false;
for($i=0; $i<= $x; $i++){
	if(2*$i +  4*($x-$i) ==  $y){
		$flg = true;
		break;
	}
}

echo ($flg ? "Yes" : "No") . "\n";

Measured memory_bytes: 16140
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	int n;
	cin >> n;
	vector<int> p(n),c(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	copy(p.begin(), p.end(), c.begin());
	sort(c.begin(),c.end());

	for (int i = 0; i < n-1; i++) {
		for (int j = i; j < n; j++) {
			swap(p[i], p[j]);
			if (equal(p.begin(), p.end(), c.begin())) {
				cout << "YES" << endl;
				return 0;
			}
			swap(p[i], p[j]);
		}
	}
	cout << "NO" << endl;

	return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll N, K, S; cin >> N >> K >> S;
    vll A(N);
    if(S == 1e9) fill(ALL(A), 1e9-1);
    else fill(ALL(A), S+1);
    REP(i, K) A[i] = S;
    REP(i, N) cout << A[i] << " ";
    cout << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    ll ans = 0;
    rep(k, K, N + 2) {
        ll mn = (ll)k * (k - 1) / 2;
        ll mx = (ll)N * k - mn;
        ans = (ans + mx - mn + 1) % MOD;
    }
    write(ans);
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + c >= 22 ? "bust" : "win");
}


Measured memory_bytes: 3552
#include<stdio.h>
int m1[100][100] = {0};
int m2[100] = {0};
int product[100] = {0};
int main(){
int n,m;
int p = 0;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        scanf("%d",&m1[i][j]);
    }
}
for(int i=0;i<m;i++){
    scanf("%d",&m2[i]);
}
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
       product[p] +=  m1[i][j] * m2[j];
    }
    p++;
}
for(int i=0;i<n;i++){
    printf("%d\n",product[i]);
}
return 0;
}



Measured memory_bytes: 2148
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll calc(ll N, ll K) {
    ll ans = N;
    if(N >= K)
        ans = N - (K * (N / K));
    ans = min(ans, abs(ans - K));
    return ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, K;
    cin >> N >> K;
    ll ans = calc(N, K);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, M;
vector<int> adj[101010];
int deg[101010], par[101010];
int id[101010], num=1;

priority_queue<pii> PQ;

void dfs(int u){
    vector<int> E;
    id[u] = num++;
    for (int v : adj[u]) if (!id[v]) dfs(v);
    for (int v : adj[u]) if (id[v] < id[u]) E.push_back(v);
    if (par[u] & 1){
        printf("%d %d\n", u, E.back());
        E.pop_back();
    }
    while (E.size() > 1){
        printf("%d %d\n", u, E.back());
        E.pop_back();
        printf("%d %d\n", u, E.back());
        E.pop_back();
    }
    if (E.size()) {
        printf("%d %d\n", E[0], u);
        par[E[0]] = !par[E[0]];
    }
}

int main(){
    scanf("%d %d", &N, &M);
    if (M & 1){
        puts("-1");
        return 0;
    }
    for (int i=1; i<=M; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    return 0;
}


Measured memory_bytes: 18560
a=int(input())
if 400<=a and a<=599:
    print(8)
if 600<=a and a<=799:
    print(7)
if 800<=a and a<=999:
    print(6)
if 1000<=a and a<=1199:
    print(5)
if 1200<=a and a<=1399:
    print(4)
if 1400<=a and a<=1599:
    print(3)
if 1600<=a and a<=1799:
    print(2)
if 1800<=a and a<=1999:
    print(1)

Measured memory_bytes: 9132
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
int n;
int main(void) {
    cin >> n;
    cout << ((n + 110) / 111) * 111 << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int l = scanner.nextInt();
        int taste = (n * (l + l + n - 1)) / 2;
        int max = n + l - 1;

        if (l < 0 && max < 0) {
            taste -= max;
        } else if (l > 0) {
            taste -= l;
        }

        System.out.println(taste);
    }
}

Measured memory_bytes: 23892
N=int(input())
if N==2:
    print(1)
    exit()

ans=0
def f(x):
    out=set()
    for i in range(1, int(x**(1/2))+1):
        if x%i==0:
            out.add(i)
            out.add(x//i)
    out=list(out)
    out.sort()
    return out[1:]

tmp=f(N)
for K in tmp:
    x=N
    while x>=K:
        if x%K==0:
            x=x//K
        else:
            x=x%K
            
    if x==1:
        ans+=1
        
tmp=f(N-1)
ans+=len(tmp)
print(ans)

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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

ll fast(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1)
            res  = (res*x)%mod;
            
        y>>=1;
        x = (x*x)%mod;
    }
    return res;
}
 
ll inv(ll n){
    return fast(n,mod-2);
}

ll fact[maxs];
ll ifact[maxs];

void pre(){

    fact[0] = 1;
    ifact[0] = 1;

    for(ll i=1;i<maxs;i++){
        fact[i] = (fact[i-1]*i)%mod;
        ifact[i] = inv(fact[i]);
    }

}


ll ncr(ll n,ll r){
    return (fact[n]*ifact[n-r])%mod*ifact[r]%mod;
}

void solve(){
    ll n,k;
    cin >> n >> k;
    ll ans=0;
    for(ll i=0;i<=min(n-1,k);i++){
        ll z = i;
        ll rem = n-i;
        ans += ncr(n,z)*ncr(z + rem - 1 , rem-1)%mod;
        if(ans >= mod)
            ans -= mod;
    }
    cout << ans << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3456
import java.util.*;
 
public class  Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int a[] = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
    
        int max = Integer.MIN_VALUE;
        int min = a[0];
        for(int i = 1; i < N; i++){
            max = Math.max(max, a[i] - min);
            min = Math.min(min, a[i]);

        }
        System.out.println(max); 



    }   
}







Measured memory_bytes: 101396
#include <stdio.h>
//#include <stdlib.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n%k == 0) printf("0\n");
  else printf("1\n");
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int ans = 1;
    for(int i=0; i<n-1; i++){
        if(a[i+1] <= a[i]) ans++;
    }
    cout << ans << endl;
    cout << n << endl;
    return 0;
}



Measured memory_bytes: 3120
n = int(input()) 
H =  [int(x) for x in input().split()]
maxv = 0
v = H[0]
count = 0

for i in range(1,n):
    if v < H[i]:
        if maxv < count:
            maxv = count
        count = 0
    else:
        count += 1
    v = H[i]

if maxv < count:
    maxv = count

print(maxv)

Measured memory_bytes: 14252
N=int(raw_input())
A=raw_input().split(" ")
B=raw_input().split(" ")

A = map(int, A)
B = map(int, B)

maxim=0
for i in xrange(1,N+1):
	temp=sum(A[0:i]) + sum(B[i-1:N])
	if maxim < temp:
		maxim = temp
print(maxim)

Measured memory_bytes: 2568