akhauriyash/Code-Regression huggingface dataset:
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 15;
const int MAX_M = 15;

const int INF = 1 << 30;

/* typedef */

/* global variables */

int bs[MAX_N], ps[MAX_M], as[MAX_N], gs[MAX_N];

/* subroutines */

/* main */

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

  int zn = 0;
  for (int i = 0; i < n; i++) {
    cin >> bs[i];
    if (bs[i] == 0) zn++;
  }
  for (int i = 0; i < m; i++) cin >> ps[i];

  int ans = INF;
  
  for (int ib = 0; ib <= 1; ib++) {
    for (int i = 0; i < n; i++) as[i] = bs[i];

    int gzn = 0;
    for (int i = 0, k = 0, b = ib; i < m; i++, b ^= 1) {
      for (int j = 0; j < ps[i]; j++) gs[k++] = b;
      if (b == 0) gzn += ps[i];
    }
    if (zn != gzn) continue;

    //for (int i = 0; i < n; i++) printf("%d", bs[i]); putchar('\n');
    //for (int i = 0; i < n; i++) printf("%d", gs[i]); putchar('\n');

    int cnt = 0;
    for (int i = 0; i < n; i++)
      if (as[i] != gs[i]) {
	int k = i + 1;
	while (as[k] != gs[i]) k++;
	for (int j = k; j > i; j--) swap(as[j - 1], as[j]), cnt++;
      }
    if (ans > cnt) ans = cnt;
  }

  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1148
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
map<int,int>num;
typedef long long ll;
const int N=1e6+10;
const int Mod=1e9+7;
ll cal(ll x){
    if(num[x]!=0) return num[x];
    return num[x]=(cal(x/2)+cal((x-1)/2)+cal((x-2)/2))%Mod;
}
int main(){
    num[0]=1;num[1]=2;
    ll n;
    scanf("%lld",&n);
    printf("%lld\n",cal(n));
    return 0;
}

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

int main() {
	int n; cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		int l,r;cin >> l >> r;
		cnt += r - l + 1;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        v: [i32; n],
    }

    let mut V = v;
    V.sort();
    let front = V[0] as f64;
    let ans = V
        .into_iter()
        .fold(front, |acc, v| (acc + (v as f64)) / 2_f64);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#
# File    : D.rb
# Author  : Kazune Takahashi
# Created : 12/6/2018, 11:13:54 PM
# Powered by Visual Studio Code
#

s = gets.chomp
ok = true
if s[0] == s[-1]
  ok = (s.size % 2 == 0)
else
  ok = (s.size % 2 == 1)
end

if ok
  puts "First"
else
  puts "Second"
end

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    string s, ans = "keyence";
    cin >> s;
    bool ok = false;
    
    rep(i, s.size()){
        rep(j, s.size()-i){
            string tmp = s;
            tmp.erase(j, i);
            if(tmp == ans) {
                ok = true;
                break;
            }
        }
    }

    if(ok){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
    }
    let MOD = 1000_000_000+7;

    let mut dp = [[0;20];100010];
    let mut mv = [[0;13];100010];

    let n = s.len();

    for i in 0..10 {
        mv[0][i] = i%13;
    }
    for i in 1..n {
        for j in 0..10 {
            mv[i][j] = mv[i-1][j]*10%13;
        }
    }

    if s[0] != '?' {
        dp[0][mv[n-1-0][s[0] as usize - 48]] += 1;
    } else {
        for i in 0..10 {
            dp[0][mv[n-1-0][i]]+=1;
        }  
    }

    for i in 1..n {
        if s[i] != '?' {
            for j in 0..13 {
                dp[i][(j+mv[n-1-i][s[i] as usize - 48])%13] += dp[i-1][j];
                dp[i][(j+mv[n-1-i][s[i] as usize - 48])%13] %= MOD;
            }
        } else {
            for j in 0..13 {
                for k in 0..10 {
                    dp[i][ (j + mv[n-1-i][k]) %13 ] += dp[i-1][j];
                    dp[i][ (j + mv[n-1-i][k]) %13 ] %= MOD;
                } 
            }
        }
    }

     println!("{}",dp[n-1][5]);
}

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

using namespace std;

const int N = (int)4e6 + 3;

bitset < N > a;

main () {
    int n; scanf ("%d", &n);
    a[0] = 1;
    int s = 0;
    for (int i = 1; i <= n; i++) {
        int x; scanf ("%d", &x);
        s += x;
        a |= a << x;
    }
    s = (s + 1) >> 1;
    while (!a[s]) s++;
    cout << s << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
const int Mod = 1e9 + 7;
#define mst(x) memset(x, 0, sizeof(x))
typedef pair <int, int> PR;
priority_queue <PR> qua;
vector <ll> vec;
char s[maxx];
ll ans;

int main() {
	vec.clear();
	scanf("%s", s + 1);
	int l = strlen(s + 1);
	ll sum = 0;
	for(int i = 1; i <= l; i++) {
		if(s[i] == 'W') vec.push_back(sum);
		else sum++;
	}
	int sz = vec.size();
	for(int i = 0; i < sz; i++) ans += vec[i];
	cout << ans << endl;
}

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

using namespace std;

const int N=1e6+10;
long long rem,buy,bar,res;

string solve(){
        if (rem<buy) return "No";
        if (res<buy) return "No";
        if (bar>=buy-1) return "Yes";
        
        rem-=buy;
        if (rem<=bar) rem+=res;
        long long val=(rem-bar)%buy;

        res%=buy;
        long long phase=__gcd(res,buy);
        long long worst=(val+(buy-val+phase-1)/phase*phase)%buy;
        if (worst==0) worst+=phase;
        if (bar+worst>=buy) return "Yes";
        return "No";
}
int main(){
        int test;
        cin>>test;
        while (test--){
                cin>>rem>>buy>>bar>>res;
                cout<<solve()<<'\n';
        }
}


Measured memory_bytes: 256
x,y,a,b,c=map(int, input().split())
p=sorted(list(map(int, input().split())), reverse=True)[:x]
q=sorted(list(map(int, input().split())), reverse=True)[:y]
r=sorted(list(map(int, input().split())), reverse=True)[:x+y]

new=sorted(p+q+r, reverse=True)
print(sum(new[:x+y]))


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) (__gcd(a, b))
#define LCM(a, b) ((a)/GCD(a,b)*(b))
#define PI (3.14159265358979323846)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 1550555;
const int M = 5125;

void solve() {
    int n;
    cin >> n;

    int ans = 0;
    for (int i = 1; i <= n; i++){
        ll x;
        cin >> x;
        if (x % 2 && i % 2) ans++;
    }

    cout << ans;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <array>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define INF 0x3f3f3f3f
#define UINF 0x3f3f3f3f3f3f3f3f
#define CLEAR(a) a = decltype(a)()
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int ,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define PI 2*acos(0.0)
#define INFILE() freopen("in.txt","r",stdin)
#define OUTFILE() freopen("out.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FIN std::ifstream cin("D:\input.txt")

ll f(ll a, ll b){
	if(a>b) swap(a,b);
	if(a==0) return 0;
	if(b%a == 0) return a*(2*(b/a)-1);
	return 2*a*(ll)(b/a) + f(a,b%a);
}

signed main(void) {
	ll N, X; cin >> N >> X;
	cout << N+f(N-X,X) << endl;
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
	fio();
	int n, m;
	cin >> n >> m;
	vi t(m), q(m);
	rep (i, m) {

		cin >> t[i] >> q[i];
	}
	rep (i, 1000) {
		string s = to_string(i);
		if (s.size() != n) continue;
		bool flag = true;
		rep (i, m) {
			if (s[t[i] - 1] != q[i] + '0') {
				flag = false;
				break;
			}
		}
		if (flag) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10)), p(n, vector<int>(11));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 11; j++)
      cin >> p[i][j];
  int ans = -1e9;
  for (int bit = 1; bit < (1 << 10); bit++)
  {
    int tmp = 0;
    for (int i = 0; i < n; i++)
    {
      int cnt = 0;
      for (int j = 0; j < 10; j++)
        if (bit & (1 << j) && f[i][j] == 1)
          cnt++;
      tmp += p[i][cnt];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
 int n,w;
char arr[100][100];
int maxx = 0;
int vx[4] = {0,0,1,-1};
int vy[4] = {1,-1,0,0};
void bfs(int i,int j)
{
     vector<vector<int>> dist(20,vector<int>(20,-1));
     queue<pii> q;
     q.push(mr(i,j));
     dist[i][j] = 0;
     auto valid = [&](int i,int j)
     {
         return i>=0&&j>=0&&i<n&&j<w&&dist[i][j]==-1&&arr[i][j]!='#';
     };
     while(!q.empty())
     {
         auto x = q.front();
         q.pop();
         auto xx = x.ff;
         auto xy = x.ss;
         for(int i=0;i<4;++i)
         {
             auto pp = xx+vx[i];
             auto qq = xy+vy[i];
             if(valid(pp,qq))
             {
                 dist[pp][qq] = dist[xx][xy]+1;
                 q.push(mr(pp,qq));
                 maxx = max(maxx,dist[pp][qq]);
             }
         }
     }
}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {

        cin>>n>>w;
        rep(i,0,n)
        rep(j,0,w)
        cin>>arr[i][j];
        for(int i=0;i<n;++i)
        {
            for(int j=0;j<w;++j)
            {
                if(arr[i][j]=='.')
                {
                   bfs(i,j);
                }
            }
        }
       cout<<maxx<<el;
    }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define print(x) for(auto& i:x) cout<<i<<" "; cout<<'\n';
#define scan(x) for(auto& i:x) cin>>i;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<" "<<b<<endl
#define d3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define d4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define d5(a,b,c,d,e) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
ll mod=1e9+7;

void solve(){
	ll x,k,d; cin>>x>>k>>d;
	if(x<0) x*=-1;
	ll st=x/d, p=x%d;
	if(st>=k) {cout<<x - k*d<<endl; return;}
	ll rem=k-st;
	if(rem&1) cout<<d-p<<endl;
	else cout<<p<<endl;
}

int main() {
	//freopen("test.txt", "r", stdin);
	FAST; int T=1;
	//cin>>T;
	while(T--) solve();
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long mypow(long long a, long long b) {
  if (b == 0) {
	  return 1LL;
	} else if (b % 2 == 1) {
	  return (a * mypow(a, b - 1)) % mod;
	}
  long long c = mypow(a, b / 2);
  return c * c % mod;
}

long long inv(long long a) {
  return mypow(a, mod - 2);
}

vector <long long> fact(200001, 1);
long long conb(long long a, long long b) {
  if (a < b) {
	  return 0LL;
	}
  long long ans = fact[a];
  ans = ans * inv(fact[b]) % mod;
  ans = ans * inv(fact[a - b]) % mod;
  return ans;
}

int main() {
  int n;
  cin >> n;
  vector <int> flg(n + 1, -1);
  int l, r;
  for (int i = 1; i <= n + 1; i++) {
	  int a;
	  cin >> a;
	  if (flg[a] != -1) {
		  l = flg[a];
		  r = i;
		} else {
		  flg[a] = i;
		}
	}
  for (long long i = 1; i <= 200000; i++) {
	  fact[i] = fact[i - 1] * i % mod;
	}
  for (int i = 1; i <= n + 1; i++) {
	  long long ans = conb(n + 1, i);
	  ans = ans - conb(l + n - r, i - 1);
	  cout << (ans + mod) % mod << endl;
	}
  return 0;
}


Measured memory_bytes: 3200
N,K = map(int,input().split())
A = list(map(int,input().split()))

s = []
# 訪れていない
visited = [-1] * (N+1)
v = 1
while visited[v] == -1: 
  visited[v] = len(s)
  s.append(v)
  # ワープさせる
  v = A[v-1]

# サイクルの長さ
c = len(s) - visited[v]
# はみ出す分の長さ
l = visited[v]

if (K < l): 
  print(s[K])
else:
  K -= l
  K %= c
  print(s[l+K])

Measured memory_bytes: 94948
//K_i == 0 0??¨1?????°??????????????????
//K_i == 1 0??¨1?????°????????¢??????
#include <bits/stdc++.h>

using namespace std;

int main()
{
  int S;
  cin >> S;
  while(S--){
    unsigned int N[9];
    for(int i = 0; i < 9; i++) scanf("%x", &N[i]);
    unsigned int K = 0U;
    for(int i = 0; i < 32; i++){
      unsigned int sum = 0U;
      for(int j = 0; j < 8; j++) sum += (N[j] ^ K);
      if(((sum >> i) & 1U) != ((N[8] >> i) & 1U)) K |= 1U << i;
    }
    printf("%x\n", K);
  }
  return 0;
}

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

int main(){
	int T[101][101];
	int r, c;
	int i, j;
	cin >> r >> c;
	for( i=0; i<r; i++ )
		for( j=0; j<c; j++ ) cin >> T[i][j];

	for( i=0; i<=r; i++ ) T[i][c] = 0;
	for( j=0; j<=c; j++ ) T[r][j] = 0;

	for( i=0; i<r; i++ ){
		for( j=0; j<c; j++ ){
			T[i][c] += T[i][j];
			T[r][j] += T[i][j];
			T[r][c] += T[i][j];
		}
	}

	for( i=0; i<=r; i++ ){
		for( j=0; j<=c; j++ ){
			if(j)cout << " ";
			cout << T[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3132
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ls = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var max = 0;
        var sum = 0;
        foreach (var l in ls)
        {
            max = Math.Max(max, l);
            sum += l;
        }
        sum -= max;
        Console.WriteLine(max < sum ? "Yes" : "No");
    }
}


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

int main() {
  int n, m; cin >> n >> m;
  int count = 0;
  
  count += (n * (n-1))/2;
  count += (m * (m-1))/2;
  
  cout << count << endl;
  
  return 0;
}

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

int main() {
  int n, a, m = 0;
  cin >> n;
  vector<int> s(100000);
  for(int i = 0; i < n; i++) {
    cin >> a;
    for(int j = -1; j < 2; j++)
      if(0 <= a + j && a + j < 100000)
        s[a + j]++;
  }
  for(int i = 0; i < 100000; i++)
    m = max(m, s[i]);
  cout << m << endl;
}

Measured memory_bytes: 640
#include <iostream>

int main() {
  int h, n, sum = 0;
  std::cin >> h >> n;
  for (int i = 0, a; i < n; ++i) {
    std::cin >> a;
    sum += a;
  }
  if (sum >= h) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	if(s=="A") puts("T");
	if(s=="T") puts("A");
	if(s=="C") puts("G");
	if(s=="G") puts("C");
}



Measured memory_bytes: 256
while 1:
    r,a=raw_input().split()
    if r=='0' and a=='0': break
    h = b = 0
    for i in xrange(4):
        if r[i]==a[i]: h+=1
    for s in r:
        for t in a:
            if s==t:
                b+=1; break;
    print h,b-h

Measured memory_bytes: 4204
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>

class Bit {
	std::vector<int>vec;
public:
	Bit(int size) : vec(size, 0){};
	int get(int position) const {
		int result = 0;
		while (position >= 0) {
			result += vec[position];
			position -= (position + 1) & ~position;
		}
		return result;
	}
	void add(int position, int value) {
		while (position < vec.size()) {
			vec[position] += value;
			position += (position + 1) & ~position;
		}
	}
	void clear() {
		std::fill(vec.begin(), vec.end(), 0);
	}
};
int main(void) {
	int height, width, min_size, p; std::cin >> height >> width >> min_size >> p;
	std::vector<std::vector<int>> for_top(height, std::vector<int>(width, 1));
	for (auto i = 0; i < p; ++i) {
		int a, b; std::cin >> a >> b;
		for_top[--a][--b] = 0;
	}
	auto for_bottom = for_top; auto for_right = for_top; auto for_left = for_top;
	for (auto i = 1; i < height; ++i) {
		for (auto j = 0; j < width; ++j) {
			if (for_top[i][j] != 0) {
				for_top[i][j] += for_top[i - 1][j];
			}
			if (for_bottom[height - i - 1][j] != 0) {
				for_bottom[height - i - 1][j] += for_bottom[height - i][j];
			}
		}
	}
	for (auto i = 0; i < height; ++i) {
		for (auto j = 1; j < width; ++j) {
			if (for_left[i][j] != 0) {
				for_left[i][j] += for_left[i][j - 1];
			}
			if (for_right[i][width - j - 1] != 0) {
				for_right[i][width - j - 1] += for_right[i][width - j];
			}
		}
	}
	std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::function<bool(std::pair<int, int>&, std::pair<int, int>&)>> history([](std::pair<int, int>& a, std::pair<int, int>& b) {return a.first > b.first; });
	Bit bit(std::min(height, width) + 1);
	long long int count = 0;
	for (int i = -width + 1; i < height; ++i) {
		const int h = std::max(i, 0);
		const int w = std::max(0, h - i);
		for (auto j = 0; h + j < height && w + j < width; ++j) {
			const auto for_next = std::min(for_bottom[h + j][w + j], for_right[h + j][w + j]);
			if (for_next >= min_size) {
				history.emplace(j + for_next - 1, j);
				bit.add(j, 1);
			}
			const auto for_prev = std::min(for_top[h + j][w + j], for_left[h + j][w + j]);
			if (for_prev >= min_size) {
				count += bit.get(j + 1 - min_size) - bit.get(j - for_prev);
			}
			while (!history.empty() && history.top().first == j) {
				bit.add(history.top().second, -1);
				history.pop();
			}
		}
	}
	std::cout << count << '\n';
}



Measured memory_bytes: 253752
#include <bits/stdc++.h> 
using namespace std;
 
int main(){
  int n;
  cin>>n;
  
  int ac=0,wa=0,tle=0,re=0;
  
  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    if(vec.at(i)=="AC"){
      ac++;
    }
    else if(vec.at(i)=="WA"){
      wa++;
    }
    else if(vec.at(i)=="TLE"){
      tle++;
    }
    else if(vec.at(i)=="RE"){
      re++;
    }
  }
  
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
  
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

int n, A, B, C, l[10] = {}, ans = 0;

int dfs(int idx, int a, int b, int c) {
    if(idx == n) {
        if(a == 0 || b == 0 || c == 0) return INF;
        else return abs(a-A)+abs(b-B)+abs(c-C);
    }
    int res = INF;
    res = min(res, dfs(idx+1, a, b, c));
    res = min(res, dfs(idx+1, a+l[idx], b, c)+(a ? 10 : 0));
    res = min(res, dfs(idx+1, a, b+l[idx], c)+(b ? 10 : 0));
    res = min(res, dfs(idx+1, a, b, c+l[idx])+(c ? 10 : 0));
    return res;
}

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

    cin >> n >> A >> B >> C;
    rep(i, n) cin >> l[i];

    cout << dfs(0, 0, 0, 0) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<unordered_map>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
const int N = 200 + 5;
const int INF = 0x3f3f3f3f;

int ans;
bool visit[10];
int mat[N][N];

void Init(){
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++) mat[i][j] = (i!=j?INF : 0);
}
void Solve(int n){
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++){
        for(int k = 1; k <= n; k++)
            mat[j][k] = min(mat[j][i] + mat[i][k], mat[j][k]);
    }
}
int a[N];
int main(){
    int n, m, r, x, y, c;
    Init();
    cin >> n >> m >> r;
    for(int i = 0; i < r; i++){
        cin >> a[i];
    }
    for(int i = 1; i <=m; i++){
        cin >> x >> y >> c;
        if(c < mat[x][y] || c < mat[y][x]) mat[x][y] = mat[y][x] = c;
    }
    Solve(n);
    sort(a, a + r);
    int ans = INF;
    do{
        int tmp = 0;
        for(int i = 0; i < r - 1; i++)
         tmp += mat[a[i]][a[i+1]];
        ans = min(ans, tmp);
    }while(next_permutation(a, a+r));
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

int mix_id(int l, int r) {
	if (l > r) {
		swap(l, r);
	}
	return l * 1000 + r;
}

bool has_cycle(const vector<vector<int>>& nodes, int id, unordered_set<int>& rec_stack, vector<bool>& visited) {
	if (rec_stack.count(id) > 0) return true;
	if (visited[id]) return false;
	visited[id] = true;
	rec_stack.insert(id);
	bool res = false;
	for (int next_id : nodes[id]) {
		if (has_cycle(nodes, next_id, rec_stack, visited)) {
			res = true;
			break;
		}
	}
	rec_stack.erase(id);
	return res;
}

int depth(const vector<vector<int>>& nodes, int id, vector<int>& depth_cache) {
	if (depth_cache[id] >= 0) return depth_cache[id];
	int max_depth = 0;
	for (int next_id : nodes[id]) {
		max_depth = max(max_depth, depth(nodes, next_id, depth_cache) + 1);
	}
	return depth_cache[id] = max_depth;
}

int main (int argc, char* argv[]) {
	int n;
	cin >> n;
	int id_count = 1000 * n + n;
	vector<vector<int>> nodes(id_count);
	vector<int> targets(n - 1);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			cin >> targets[j];
			targets[j]--;
		}
		for (int j = 0; j < n - 2; j++) {
			nodes[mix_id(i, targets[j])].push_back(mix_id(i, targets[j + 1]));
		}
	}

	unordered_set<int> rec_stack;
	vector<bool> visited(id_count);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int id = mix_id(i, j);
			if (has_cycle(nodes, id, rec_stack, visited)) {
				cout << -1 << endl;
				return 0;
			}
		}
	}

	int max_depth = 0;
	vector<int> depth_cache(id_count, -1);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			max_depth = max(max_depth, depth(nodes, mix_id(i, j), depth_cache));
		}
	}
	cout << max_depth + 1 << endl;
}


Measured memory_bytes: 43520
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

/*
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}*/

int n, C, s, t, c, mx, cnt;
bool ck[200001][30];
int main(){
	cin >> n >> C;
	lp(200001) {
		LP(30, j) {
			ck[i][j] = 0;
		}
	}
	lp(n) {
		cin >> s >> t >> c;
		for (int j = s * 2 - 1; j < t * 2; j++)
			ck[j][c - 1] = true;
	}
	mx = 0;
	lp(200001) {
		cnt = 0;
		LP(30,j) {
			if (ck[i][j])cnt++;
		}
		mx = max(mx, cnt);
	}
	cout << mx << endl;
	return 0;
}

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


public class Main {
	private	static	BufferedReader	br    = null;
	private	static	int[][]			map   = null;
	private	static	int				blank = 100;
	private	static	int				depth = 0;

	static {
		br  = new BufferedReader(new InputStreamReader(System.in));
		map = new int[10][10];
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]	aParam = null;

		while((aParam = paramParam()) != null) {
			switch(aParam[2]) {
			case 3:
				paint(aParam[0], aParam[1]-2);
				paint(aParam[0]-2, aParam[1]);
				paint(aParam[0]+2, aParam[1]);
				paint(aParam[0], aParam[1]+2);
			case 2:
				paint(aParam[0]-1, aParam[1]-1);
				paint(aParam[0]+1, aParam[1]-1);
				paint(aParam[0]-1, aParam[1]+1);
				paint(aParam[0]+1, aParam[1]+1);
			case 1:
				paint(aParam[0], aParam[1]-1);
				paint(aParam[0]-1, aParam[1]);
				paint(aParam[0], aParam[1]);
				paint(aParam[0]+1, aParam[1]);
				paint(aParam[0], aParam[1]+1);
				break;
			}
		}

		System.out.println(blank);
		System.out.println(depth);
	}

	private static void paint(int x, int y) {
		if (0 <= x && x < 10) {
			if (0 <= y && y < 10) {
				int state = map[y][x];
				if (state++ == 0) {
					blank--;
				}
				depth = Math.max(state, depth);
				map[y][x] = state;
			}
		}
	}

	private static int[] paramParam() {
		int[]	aParam = null;
		String	strIn = null;

		if ((strIn = parseStdin()) != null) {
			String[]	aN = strIn.split(",");
			aParam = new int[3];
			aParam[0] = Integer.parseInt(aN[0]);
			aParam[1] = Integer.parseInt(aN[1]);
			aParam[2] = Integer.parseInt(aN[2]);
		}
		
		return aParam;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16920
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce
from itertools import groupby, combinations
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return list(map(lambda x: x + d, A))
def ldec(A, d=1): return list(map(lambda x: x - d, A))

N = n1()
A = nn()

#MAX = 10**6
MAX = max(A)
dp = defaultdict(list)

p = 2
while p <= MAX:
    i = p
    while i <= MAX:
        dp[i].append(p)
        i += p

    p += 1
    while len(dp[p]) >= 1:
        p += 1

if max(A) == 1:
    print("pairwise coprime")
    exit(0)

dic = defaultdict(list)

for ai in A:
    fact = dp[ai]
    for x in fact:
        dic[x].append(ai)

maxlen = 0
for k, v in dic.items():
    maxlen = max(len(v), maxlen)

if maxlen == 1:
    print("pairwise coprime")
elif maxlen == N:
    print("not coprime")
else:
    print("setwise coprime")

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

int main() {
  for (int i = 0; i < 3; i++) {
    int h, m, s, H, M, S;
    cin >> h >> m >> s >> H >> M >> S;
    if (S < s) {
      M--;
      S += 60;
    }
    if (M < m) {
      H--;
      M += 60;
    }
    cout << H - h << " " << M - m << " " << S - s << "\n";
  }
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		String [] str = bufferedReader.readLine().split(" ");
		Integer a = Integer.parseInt(str[0]);
		Integer b = Integer.parseInt(str[1]);
		
		if (a < b) {
			System.out.println("a < b");
		}else if (a > b) {
			System.out.println("a > b");
		}else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 24236
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        System.out.println((n * (n - 1) + m * (m - 1)) / 2);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 25172
import sys
input = sys.stdin.readline
from collections import deque
import copy
import math
#--------Pypy3---------
#from fractions import gcd
#--------Python3---------
#from math import gcd
#----------Recursion------------
sys.setrecursionlimit(10**9)

num = 10**8
d = [(1,0),(-1,0),(0,1),(0,-1)]
H,W = map(int,input().split())
maze = [list(input()) for _ in range(H)]
visited=[[0 for _ in range(W)]for _ in range(H)]
def bfs(maze,visited,x,y):
    queue = deque()
    queue.append([0,0])
    visited[x][y] = 1
    while queue:
        x,y = queue.popleft()
        if x == H-1 and y == W-1:
            return visited[x][y]
        for dx,dy in d:
            nx,ny=x+dx,y+dy
            if 0<=nx<H and 0<=ny<W:
                if maze[nx][ny] == "." and visited[nx][ny] == 0:
                    visited[nx][ny]=visited[x][y]+1
                    queue.append([nx,ny])
    return -1
def main():
    """code here"""
    cnt = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j]==".":
                cnt+=1
    ans = bfs(maze,visited,0,0)
    if ans == -1:
        print(-1)
        exit()

    print(cnt-ans)
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 40432
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 3e5 + 5;

int n,m,s,r[N],c[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>s;
    set<pii> a;
    for(int i=1;i<=s;i++){
    	int x,y;
    	cin>>x>>y;
    	r[x]++,c[y]++;
    	a.emplace(x,y);
    }
    vector<int> R,C;
    int maR=*max_element(r+1,r+1+n);
    int maC=*max_element(c+1,c+1+m);
    for(int i=1;i<=n;i++) if(r[i]==maR) R.emplace_back(i);
    for(int i=1;i<=m;i++) if(c[i]==maC) C.emplace_back(i);
    int ans=maR+maC-1;
	for(auto x:R)
		for(auto y:C)
			if(!a.count({x,y})) {ans++;goto A;}
    A:cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 23708
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;
import java.lang.Object;
 
public class Main {
    Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        new Main(); 
    }
   
    public Main() {
        new aoj1216().doIt();
    }
    class aoj1216{	
    	int a[] = new int[101];
    	int b[] = new int[101];
    	void doIt(){
    		for(int i = 0;i < 101;i++)a[i] = i*i*i;
    		for(int i = 0;i < 101;i++)b[i] = i*(i+1)*(i+2)/6;
    		while(true){
    			int n = sc.nextInt();
    			if(n == 0)break;
    			int num = 0;
    			for(int i = 0;i < 101;i++){
    				for(int j = 0;j < 101;j++){
    					if(a[i]+b[j] <= n)num = Math.max(num,a[i]+b[j]);
    				}
    			}
    			System.out.println(num);
    		}
    	}
    }
}

Measured memory_bytes: 32200
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int solve(int n)
{
  int r = 0;
  while(n > 0){
    r += n % 10;
    n /= 10;
  }
  return r;
}

int main()
{
  int n, a, b, ans = 0; cin >> n >> a >> b;
  for(int i = 1; i <= n; i++){
    int c = solve(i);
    if(a <= c && c <= b) ans += i; 
  }
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 504
# coding: utf-8
# Your code here!
N,K = [int(i) for i in input().split()]

l = [int(input()) for j in range(N)]
l = sorted(l)
dif = 1000000000
for a in range(N-K+1):
    d = l[a+K-1] - l[a]
    #print(a)
    #print(d)
    if dif >= d:
        dif = d

print(dif)


Measured memory_bytes: 8204
import java.util.Scanner;
public class Main {
	    public static void main(String[] args){
	        Scanner sc = new Scanner(System.in);
	        int a=sc.nextInt();
	        int b=sc.nextInt();
	        int c=sc.nextInt();
	        if(a<b && b<c){
	            System.out.println("Yes");
	        }else{
	            System.out.println("No");
	        }
	        
	    }
	}


Measured memory_bytes: 26224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N, M; cin >> N >> M;
  ll ansmax = M/N;
  for(ll i = ansmax; ; i--){
    if(M%i==0){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << 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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    vector<int> res; //求めた素数を入れる配列
    vector<bool> is_prime(10000007, true);
    for (int p = 2; p <= 10000007; p++){
      if (!is_prime[p]) continue;
      // p の倍数を全て消す。
      for (int k = p * 2; k <= 10000007; k += p) is_prime[k] = false;
      res.push_back(p);
    }
    ll n;
    while (cin >> n){
      for (ll i = sz(res)-1; i > 0;i--){
        if(res[i]>n)continue;
        else{
          if(res[i]==res[i-1]+2&&res[i]==res[i-2]+6&&res[i]==res[i-3]+8){
            print(res[i]);
            break;
          }
        }
      }
    }
}


Measured memory_bytes: 7960
#include <iostream>

using namespace std;

int main(void) {
  int n = 0, array[100] = {};
  int min = 1000000000, max = 1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> array[i];
    if (max < array[i]) {
      max = array[i];
    }
    if (min > array[i]) {
      min = array[i];
    }
  }
  cout << max - min << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<int, int> P;
#define fs first
#define sc second

int main() {
    int K, N;
    cin >> K >> N;
    int a[N];
    for(int i = 0; i < N; i++) cin >> a[i];

    int mx = K - a[N - 1] + a[0];
    for(int i = 0; i < N - 1; i++) {
        mx = max(mx, a[i + 1] - a[i]);
    }

    cout << K - mx << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int gojoho(int x, int y)
{
	return x % y == 0 ? y : gojoho(y, x % y);
}
int main()
{
	cout << gojoho(in(), in()) << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	string S;
	int Q;
	
	cin >> S >> Q;

	deque<char> d;

	for (int i = 0; i < S.size(); i++) {
		d.push_back(S[i]);
	}

	bool r = false;
	for (int i = 0; i < Q; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			r = !r;
		} else {
			int F;
			char C;
			cin >> F >> C;
			if (F == 1) {
				if (r) {
					d.push_back(C);
				} else {
					d.push_front(C);
				}
			} else {
				if(r) {
					d.push_front(C);
				} else {
					d.push_back(C);
				}
			}
		}
	}

	if (r) {
		reverse(d.begin(), d.end());
	}
	for (char c : d) {
		printf("%c", c);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
typedef vector<int> vi;
int main(void){
    string s; cin >> s;

    while(s != "ABC"){
        set<char> S;

        vi match(s.size());
        bool ok = false;
        rep(i, (int)s.size()){
            if(s.substr(i, 3) == "ABC"){
                match[i] = true;
                i += 2;
                ok = true;
            }
            else {
                S.insert(s[i]);
            }
        }

        if(!ok || S.size() != 2) break;

        char c;
        rep(i, 3){
            if(S.count('A' + i) == 0) c = 'A' + i;
        }

        string next;
        rep(i, (int)s.size()){
            if(match[i]){
                next.push_back(c);
                i += 2;
            }
            else {
                next.push_back(s[i]);
            }
        }
        s = next;
    }

    cout << (s == "ABC" ? "Yes":"No") << endl;

	return 0;
}

Measured memory_bytes: 3244
import math
from fractions import Fraction
N = int(input())
ta = [list(map(int,input().split())) for _ in range(N)]
x = 1
y = 1
for i in range(N):
    if i == 0:
        x , y = ta[i][0] , ta[i][1]
    else:
        temp = int(math.ceil(max( Fraction(x ,  ta[i][0])  , Fraction(y , ta[i][1]))))
        x = temp * ta[i][0]
        y = temp * ta[i][1]
        
print(x + y)

Measured memory_bytes: 5208