akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
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)*}};}
#[allow(unused_macros)]
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)*}};}
#[allow(unused_macros)]
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")};}

#[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()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

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

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:i64, m:i64};
    let mut a = 1i64;
    let mut b = 1i64;
    for i in 0..n {
        a *= i+1;
        a %= MOD;
    }
    for i in 0..m {
        b *= i+1;
        b %= MOD;
    }

    if (n-m).abs() > 1 {
        println!("0");
    }
    else if (n-m).abs() == 0 {
        println!("{}", (((a*b)%MOD)*2)%MOD);
    }
    else {
        println!("{}", (a*b)%MOD);
    }
}

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

int main(){
    string s;
    cin>>s;
    deque<char> deq;

    rep(i,s.size()){
        deq.push_back(s[i]);
    }
    int q;
    cin>>q;
    int f;
    bool dir=true;
    rep(i,q){
        cin>>f;
        if(f==1){
            dir=(!dir);
        }
        else{
            int qi;char c;
            cin>>qi>>c;
            if(!dir)qi=3-qi;
            if(qi==1){
                deq.push_front(c);
            }else{
                deq.push_back(c);
            }
        }
    }
    if(!dir)reverse(deq.begin(),deq.end());
    string ans;
    rep(i,deq.size())ans+=deq[i];
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  int lo=b*10;
  int hi=(b+1)*10;
  for(;lo<hi;lo++){
    int x=lo*0.08;
    if(x==a){
      cout<<lo<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class atB {
public:
    void solve(istream& in, ostream& out) {
        int n;
        in >> n;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
        }
        sort(a.begin(), a.end());
        
        int res = 0;
        long long sum = 0;
        for (int i = 0; i < n-1; ++i) {
            sum += a[i];
            ++res;
            if (2*sum < a[i+1]) {
                res = 0;
            }
        }
        out << ++res << "\n";
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	atB solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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;}

int N;

signed main(){
    cin>>N;
    for(int i=1;i<=10;++i){
        if(1000*i>=N){
            cout<<1000*i-N<<endl;
            break;
        }
    }
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){

  int a,b,list[3] = {};
  cin >> a >> b;
  list[a - 1]++;
  list[b - 1]++;
  if(list[0] == 0){cout << "1" << endl;}
  if(list[1] == 0){cout << "2" << endl;}
  if(list[2] == 0){cout << "3" << endl;}
  
return 0;
}

Measured memory_bytes: 256
def gcd(a,b)
    if a > b
      c = a
      d = b
    else
      c = b
      d = a
    end
    e = 0
    while c % d != 0
      e = c % d
      c = d
      d = e
    end
    return d
end

str = gets.split
A,B,C,D = str[0].to_i, str[1].to_i, str[2].to_i, str[3].to_i
CD = C*D
lcm = CD / gcd(C,D)
a = B/lcm - A/lcm
answer = a * (lcm - lcm/C - lcm/D + 1)
aa = A%lcm
bb = B%lcm
answer += bb-(bb/C)-(bb/D)
if aa != 0
    aa2 = aa-1
    answer -= aa2-(aa2/C)-(aa2/D)
end
puts answer

Measured memory_bytes: 1788
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int W=scanner.nextInt();
        int H=scanner.nextInt();
        int x=scanner.nextInt();
        int y=scanner.nextInt();
        int r=scanner.nextInt();
        if(x-r<0 || x+r>W){
            if(y-r<0 ||y+r>H){
                System.out.println("No");
            }else{
                System.out.println("No");
            }
        }else{
            if(y-r<0 || y+r>H){
                System.out.println("No");
            }else{
                System.out.println("Yes");
            }
        }
    }
}


Measured memory_bytes: 26360
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
long long gcd(long long a,long long b)
{
     return b?gcd(b,a%b):a;
}
long long gcd( long long a, long long b , long long c)
{
      long long temp=gcd(a, b);
      return gcd(temp, c);
}
int main()
{
      std::ios::sync_with_stdio(false);
      long long sum=0, k;
      cin >> k;
      for (int i=1; i<=k; i++)
      {
            for (int j=1; j<=k; j++)
            {
                  for (int x=1; x<=k; x++)
                  {
                        sum+=gcd(i, j, x);
                  }
            }
      }cout << sum << endl;
     return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
  int a=100000,b=0,c,n;

  scanf("%d", &n);

  for(b=0; b<n;b++){

  a=a*1.05;
  c=a%1000;
  if(c!=0)a=a-c+1000;

  }

  printf("%d\n",a);

  return 0;
}

Measured memory_bytes: 592
#include<iostream>

using namespace std;

int main()
{
  int N,i;
  cin >> N;
  long long sum=0;

  for(i=1;i<=N;i++){
    if(i%3==0 || i%5==0) continue;
    sum += i;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3580
# Problem https://atcoder.jp/contests/abc085/tasks/abc085_a
# Python 2nd Try


def solver(errorStr):
    result = '2018'
    monthDay = errorStr[4:]
    result = result + monthDay
    return result


if __name__ == "__main__":
    result = ''
    result = solver(input())
    print(result)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;


int main()
{
    ll n, w;
    cin >> n >> w;

    ll p[n], v[n];

    for(int i=0; i<n; ++i) {
        cin >> p[i] >> v[i];
    }
    
    ll dp[2][w+1];

    ll *actual = dp[0];
    ll *anterior = dp[1];

    for (ll i=n; i>=0; --i) {
        for(ll j=w; j>=0; --j ) {
            if ( i == n ) {
                actual[j] = 0;
            } else if ( j + p[i] <= w) {
                actual[j] = max( v[i] + anterior[ j+p[i] ], anterior[j] );
            } else {
                actual[j] = anterior[j];
            }
        }
        swap(actual, anterior);
    }
    cout << anterior[0] << '\n';
}

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

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

    int n;
    cin >> n;
    long long ans = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0)
            ans += i;
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 0, prev = 0; i < n; ++i) {
        int ai;
        cin >> ai;
        if(prev > ai) ans += prev - ai;
        prev = max(prev, ai);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3544
#include <stdio.h>
int main(){
    char s[4];
    scanf("%s", s);
    printf("%d\n", 700 + (s[0] == 'o' ? 100 : 0) + (s[1] == 'o' ? 100 : 0) + (s[2] == 'o' ? 100 : 0));
    return 0;
}


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

using ll = long long int;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
	ll a, b, x;
	cin >> a >> b >> x;
	
	cout <<( (x >= a && x <= (a + b)) ? "YES" : "NO" );
	return 0;
}

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

using namespace std;

#define M 1000001

int q, l, r, x, y;
bool dd[M];
vector<int> v;

int main(){
    dd[1] = true;
    for (int i = 2; i <= 100001; i++){
        if (!dd[i]){
            if(!dd[(i+1)/2]) v.push_back(i);
            int x = 2;
            while (x*i <= 100001) {
                dd[x*i] = true;
                x++; 
            }
        }
    }
    
    cin >> q;
    
    for (int i = 1; i <= q; i++){
        cin >> l >> r;
        x = lower_bound(v.begin(), v.end(), l) - v.begin();
        y = upper_bound(v.begin(), v.end(), r) - v.begin() - 1;
        cout << y - x + 1 << '\n';
    }
    
}

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

long long t,n;
const int INF=1e9+5;
int main() {

        cin >> n;
        vector<int>a(n);
        long long k;
        cin >> k;
        for (int i=0; i<n; i++) {
            cin >> a[i];
        }
        vector<int>dp(n,INF);
        dp[0]=0;
        for (int i=0; i<n; i++) {
            for (int j=i+1; j<=i+k; j++) {
                if (j<n) {
                        dp[j]=min(dp[j], dp[i]+abs(a[i]-a[j]));
                }
            }
        }
        cout << dp[n-1];

}

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

S=[0 for j in range(N+1)]
count=0
for i in range(N):
  S[A[i]]+=1
for i in range(N+1):
  count+=S[i]*(S[i]-1)//2
for i in range(N):
  print(count-(S[A[i]]-1))

Measured memory_bytes: 24748
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, t, ans = 1e9; cin >> n >> t;

    for(int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        if(y <= t) ans = min(x, ans);
    }
    if(ans == 1e9) cout << "TLE";
    else cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,L;cin >> N >> L;
  vector<string> s(N);
  rep(i,N)cin >> s[i];
  sort(all(s));
  rep(i,N)cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
  int n;
  cin>>n;
  if(n>=65 && n<91)
    cout<<"1"<<endl;
  else if(n>=97 && n<123)
    cout<<"2"<<endl;
  else
    cout<<"0"<<endl;
  return 0;
}







Measured memory_bytes: 3116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Delivery to a Luxurious House
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		StringTokenizer st = new StringTokenizer(br.readLine());

		int N, M, T;
		N = parseInt(st.nextToken());
		M = parseInt(st.nextToken());
		T = parseInt(st.nextToken());

		int a[] = new int[N + 2];

		a[0] = -M;
		a[N + 1] = T + M;

		st = new StringTokenizer(br.readLine());

		for (int i = 0; i < N; i++) {
			a[i + 1] = parseInt(st.nextToken());
		}

		int t = 0;

		for (int i = 1; i < N + 2; i++) {
			t += a[i] - a[i - 1] > 2 * M ? a[i] - a[i - 1] - 2 * M : 0;
		}

		System.out.println(t);

	} //end main
}

Measured memory_bytes: 24464
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PAIR pair<int, int>
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
//constexpr int MOD = 10e9+7;
constexpr int INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 

  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  string S;
  int K;
  cin >> S >> K;
  int cnt = 0;
  int i = 0;
  while(S[i] == '1')
  {
    cnt ++;
    i++;
  }
  int last = S[i] -'0';
  if(K <= cnt)
  {
    cout << 1 << endl;
  }
  else {
    cout << last << endl;
  }

}

//N縺薙・荳ｭ縺九ｉ騾｣邯壹☆繧橘蛟九ｒ驕ｸ縺ｶ縺ｨ縺阪・驕ｸ縺ｳ譁ｹ縺ｯ髯舌ｌ繧峨ｌ繧九・ S T L

//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ REP(i,N) ruiseki[i+1] += ruiseki[i];
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

typedef vector<int> vi;

int main() {
	while (true) {
		int n, m, score[1001];
		vi v;
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		REP(i, n) scanf("%d", &score[i]);
		score[n++] = 0;

		REP(i, n) FOR(j, i, n) v.push_back(score[i] + score[j]);
		sort(v.begin(), v.end(), greater<int>());

		int ans = 0;
		REP(i, n) FOR(j, i, n) {
			vi::iterator it = upper_bound(v.begin(), v.end(), m - score[i] - score[j], greater<int>());
			if (it == v.end()) continue;
			ans = max(ans, *it + score[i] + score[j]);
		}

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

Measured memory_bytes: 5072
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    cout << n*n*n << endl;
}

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

int main(){
	double a,b,x,t,s,u;
  	cin>>a>>b>>x;
  	t=a*a*b-x;
  	if(a*a*b/2<=x){
      s=2*t/a/a;
      u=s/a;
      printf("%.10f",atan(u)*180.0/M_PI);
    }
    else{
      u=2*x/a/b;
      printf("%.10f",atan(b/u)*180.0/M_PI);
}
}

Measured memory_bytes: 256
//hello.cpp
#include <iostream>
using namespace std;

int main()
{
	int N, M;
	int A[20][20], B[20], C;
	int a;
	int f;

	cin >> N >> M >> C;
	for(int j = 0; j < M; j++) {
      cin >> B[j];
      //printf("B%d=%d\n",j+1,B[j]);
    }
	for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) {
      cin >> A[i][j];
      //printf("A%d%d=%d\n",i+1,j+1,A[i][j]);
    }
	a = 0;
    
	for(int i = 0; i < N; i++) {
		f = 0;
		for(int j = 0; j < M; j++) f += B[j]*A[i][j];
		f += C;
		if(f > 0) a++;
		//printf("f=%d\n", f);
    }
	cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
int main() {
        int N, W; cin >> N >> W;
        LL dp[N+1][W+1];
        for (int i = 0; i <= N; ++i) for (int j = 0; j <= W; ++j) dp[i][j] = 0;

        LL w, v;
        for (int i = 1; i <= N; ++i) {
                cin >> w >> v;
                for (int sum_w = 0; sum_w <= W; ++sum_w) {
                        if ((sum_w-w) >= 0) chmax(dp[i][sum_w], dp[i-1][sum_w-w]+v);
                        chmax(dp[i][sum_w], dp[i-1][sum_w]);
                        //cout << "dp[" << i << "][" << sum_w << "] = " << dp[i][sum_w] << "\n";
                }
        }
        cout << dp[N][W] << "\n";
        return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Round One
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            int ans = 1;

            if (A != 2 && B != 2)
            {
                ans = 2;
            }
            else if (A != 3 && B != 3)
            {
                ans = 3;
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
N = int(input())
a = [int(x) for x in input().split()]

X = 1

for i in range(N):
    if a[i] == 0:
        X = 0

if X == 1:
    for i in range(N):
        X = X * a[i]
        if X > 1000000000000000000:
            X = -1
            break

print(X)


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

#define ll long long
#define ar array

int n, k, p[200001];

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

	cin >> n >> k;
	for(int i=0; i<n; ++i) {
		cin >> p[i+1];
		p[i+1]+=p[i];
	}
	int ans=0;
	for(int i=k; i<=n; ++i) {
		ans=max(ans, p[i]-p[i-k]);
	}
	cout << fixed << setprecision(9) << (double)(ans+k)/2.0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 4e3 + 5;

int a[ N ];
int sum[ N ][ 5 ];
int n;

int get_sum(int l, int r, int id) {
  if (l > r) return 0;
  r = min(r, n);
  return sum[r][id] - sum[l - 1][id];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    int id = 0;
    if (s[i] == 'R') id = 1;
    if (s[i] == 'G') id = 2;
    if (s[i] == 'B') id = 3;
    a[i + 1] = id;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 3; j++) {
      sum[i][j] += sum[i - 1][j] + (a[i] == j);
    }
  }
  LL ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i] == a[j]) continue;
      int id = 6 - a[i] - a[j];
      int d = j - i;
      int idx = j + d;
      ans += get_sum(j + 1, idx - 1, id) + get_sum(idx + 1, n, id);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3716
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

VVI edge(100000);
int dist[2][100000];
int done[100000];

void dfs(int node, int d, int player){
    if(done[node]) return;
    done[node] = 1;
    dist[player][node] = d;
    for(int n : edge[node]) dfs(n, d+1, player);
}

int main(void){
    int N; cin >> N;
    REP(i,N-1){
        int a,b; cin >> a >> b;
        edge[a-1].push_back(b-1);
        edge[b-1].push_back(a-1);
    }
    REP(i,N) done[i] = 0; dfs(0, 0, 0);
    REP(i,N) done[i] = 0; dfs(N-1, 0, 1);

    int snuke=0, fennec=0;
    REP(i,N){
        if(dist[0][i] > dist[1][i]) snuke++;
        else fennec++;
    }

    cout << (fennec > snuke ? "Fennec" : "Snuke") << endl;

    return 0;
}

Measured memory_bytes: 11520
import numpy as np
from collections import Counter

n = int(input())
a = np.array(input().split(), np.int64)
S = np.zeros(n + 1, np.int64)
S[1:] = np.cumsum(a)

cnt = Counter(S)
ans = 0
# for x in cnt:
#     ans += cnt[x] * (cnt[x] - 1) // 2
ans = sum(x*(x-1)//2 for x in cnt.values())
print(ans)

Measured memory_bytes: 39376
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <sstream>

using namespace std;

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

#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

double eps = 1e-5;
const int INF = 1e9 + 7;
const li LINF = 9e18 + 7;

const int N = 1e2 + 7;

int a[2][N];
int d[2][N];

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n;
	cin >> n;


	forn(i, 2) {
		forn(j, n) {
			cin >> a[i][j];
		}
	}

	d[0][0] = a[0][0];
	forn(i, 2) {
		forn(j, n) {
			if (j > 0)
				d[i][j] = max(d[i][j],d[i][j - 1] + a[i][j]);
			if (i > 0)
				d[i][j] = max(d[i][j], d[i - 1][j] + a[i][j]);
		}
	}

	cout << d[1][n - 1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;

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

    if (X == 1) {
        cout << 1 << endl;
        return 0;
    }

    for (int n = X; n >= 1; n--) {
        for (int b = 1; b <= sqrt(n); b++) {
            for (int p = 2; p <= log2(n); p++) {
                if (n == int(pow(b, p))) {
                    cout << n << endl;
                    return 0;
                }
            }
        }
    }

}


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


int main() {

    string x, y, z;
    cin >> x >> y >> z;
    cout << x[0] << y[1] << z[2] << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [u64; n],
    };
    if a.contains(&0) {
        println!("0");
        return;
    }
    let mut ans = 1_u64;
    for &a_i in a.iter() {
        if a_i > 1_000_000_000_000_000_000_u64 / ans {
            println!("-1");
            return;
        }
        ans = ans * a_i;
    }
    println!("{}", ans);
}


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

int main() {
	long long n, a, b; cin >> n >> a >> b;
	long long x[n];
	for(int i = 0; i < n; i++) cin >> x[i];
	long long res = 0;
	for (int i = 1; i < n; i++)
	{
		res += min((x[i] - x[i-1]) * a, b);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#include<cstring>
using namespace std;
int main(){
	long long int n;
	long long int a[100005],b[100005];
	cin>>n;
	for(int i=0;i<=n;i++){
		scanf("%lld",&b[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	long long cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]>=b[i]){
			cnt=cnt+b[i];
			a[i]=a[i]-b[i];
			//printf("%lld\n",cnt);
			b[i]=0;
			
			if(a[i]>=b[i+1]){
				
				cnt=cnt+b[i+1];
				b[i+1]=0;
			}
			else{
				b[i+1]=b[i+1]-a[i];
				cnt=cnt+a[i];
			}
		}
		else{
			cnt=cnt+a[i];
		}
	}
	printf("%lld",cnt);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<list>
#include<stack>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int inf=1e9+7;

const int maxn=1e5+10;

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll int a,b;
	
	while(cin>>a>>b)
	{
		ll int maxx=a+b;
		
		maxx=max(maxx,a-b);
		maxx=max(maxx,a*b);
		
		cout<<maxx<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define MAX_N 1000001

bool IsPrime[MAX_N];
int cnt[MAX_N];

// エラトステネスの篩
void get_primes() {
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (int i = 2; i*i <= MAX_N; i++) {
        if (IsPrime[i]) {
            for (int j = i*i; j <= MAX_N; j += i) {
                IsPrime[j]= false;
            }
        }
    }
}

int main() {
    int n;

    memset(IsPrime, 1, sizeof(IsPrime));
    get_primes();

    for (int i = 0; i <= MAX_N; i++) {
        if (IsPrime[i]) { cnt[i]++; }
    }
    for (int i = 1; i <= MAX_N; i++) {
        cnt[i] += cnt[i-1];
    }

    while (scanf("%d", &n) != EOF) {
        printf("%d\n", cnt[n]);
    }

    return 0;
}


Measured memory_bytes: 7472
var
 s:ansistring;
begin
 readln(s);
 if (s='AKIHABARA') or (s='AKIHABAR') or (s='AKIHABRA') or (s='AKIHBARA') or (s='KIHABARA') or (s='AKIHABR') or (s='AKIHBAR') or (s='KIHABAR') or (s='AKIHBRA') or (s='KIHABRA') or (s='KIHBARA') or (s='AKIHBR') or(s='KIHABR') or (s='KIHBAR') or (s='KIHBRA'
) or (s='KIHBR') then writeln('YES') else writeln('NO');
end.

Measured memory_bytes: 128
#include<cstdio>

int gcd(int a,int b){
  if(b==0)
    return a;
  else
    return gcd(b,a%b);
}

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(c%gcd(a,b)==0)
    printf("YES\n");
  else
    printf("NO\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

void disp_t (vector <vector <int> > t )
{
	int size = t.size();
	int len  = t[0].size();
	int i,j;

	for (i = 0; i < size; ++i){
		for (j = 0; j < len; ++j){
			cout << setw(3) << t[i][j];
		} // end for
		cout << endl;
	} // end for
}

void trans_diagonal (vector <int> p, vector< vector<int> >& t )
{

	int i,j,k;
	int m = (int)(sqrt(p.size() ) );
	int n = 0;

	for (k = 1; k <= m; ++k){
		for (i = 1; i <= k + 1; ++i){
			for (j = k + 1 - i; j >= 1; --j){
				if (i + j == k + 1){
					t[i][j] = p[n];
					++n;
					//cout << '(' << i << ',' << j << ") ";
				} // end if
			} // end for
		} // end for
//		cout << endl;
	} // end for
	
	for (k = m + 1; k < 2*m; ++k){
		for (i = k - (m - 1); i <= 2*m + (m - 1) - k; ++i){
			for (j = k + 1 - i; j >= i - (2*m - 1 - k); --j){
				if (i + j == k + 1){
					//cout << '(' << i << ',' << j << ") ";
					t[i][j] = p[n];
					++n;
				} // end if
			} // end for
		} // end for
//		cout << endl;
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen("testcase.rho", "r", stdin);
	string str = "";
	vector <int> p;
	int n = 0;
	while (getline (cin, str ) ){
		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		stringstream ss(str);
		while (ss >> n){
			p.push_back (n );
		} // end while
	} // end while


	int size = p.size();
	int len = (int)sqrt(size);
	vector <vector <int> > t (len+1, vector <int> ( len+1, 0 ) );
	int i,j;

	trans_diagonal (p, t );
	
//	disp_t (t );

	vector <vector <int> > dp (len+1, vector <int> ( len+1, 0 ) );
	
	dp[1][1] = t[1][1];
	for (j = 1; j <= len; ++j){
		dp[1][j] = dp[1][j-1] + t[1][j];
	} // end for
	
	for (i = 1; i <= len; ++i){
		dp[i][1] = dp[i-1][1] + t[i][1];
	} // end for

	
	for (i = 2; i <= len; ++i){
		for (j = 2; j <= len; ++j){
			dp[i][j] = max (dp[i-1][j], dp[i][j-1] ) + t[i][j];
		} // end for
	} // end for

//	disp_t (dp );

	cout << dp[len][len] << endl;
		
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int64 i = 0; i < (int64)(n); i++)

using int64 = long long;
const int64 INF = 1LL << 60;

struct SegNode
{
  int64 v;

  SegNode(int64 v) : v(v) {}

  SegNode operator*(const SegNode &r) const
  {
    return (v < r.v ? *this : r);
  }
} e(INF);

struct SegmentTree
{
  int sz;
  vector< SegNode > seg;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, e);
  }

  void update(int k, const SegNode &x)
  {
    k += sz - 1;
    seg[k] = x;
    while(k > 0) {
      k = (k - 1) >> 1;
      seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
    }
  }

  SegNode query(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (e);
    if(a <= l && r <= b) return (seg[k]);
    return (query(a, b, 2 * k + 1, l, (l + r) >> 1) * query(a, b, 2 * k + 2, (l + r) >> 1, r));
  }

  SegNode query(int a, int b)
  {
    return (query(a, b, 0, 0, sz));
  }
};

int main()
{
  int64 N, E, T, X[100001] = {};

  cin >> N >> E >> T;
  for(int i = 0; i < N; i++) {
    cin >> X[i];
  }
  X[N] = E;

  vector< int64 > dp1(N + 1, INF);
  SegmentTree seg1(N + 1), seg2(N + 1);

  auto update = [&](int idx, int64 cost)
  {
    if(dp1[idx] > cost) {
      dp1[idx] = cost;
      seg1.update(idx, dp1[idx] - X[idx] + T);
      seg2.update(idx, dp1[idx] - 3 * X[idx]);
    }
  };
  update(0, X[0]);


  int ptr = 0;

  for(int i = 1; i <= N; i++) {

    while(ptr <= N && (X[i - 1] - X[ptr]) * 2 > T) {
      ++ptr;
    }

    update(i, min(seg1.query(ptr, i).v + X[i], seg2.query(0, ptr).v + X[i] + 2 * X[i - 1]));
  }

  cout << dp1.back() << endl;

}


Measured memory_bytes: 6016
import math
N = int(input())
S = input()

r_count = 0

for x in range(N - 1):   
    a = list(S[0:x + 1])
    b = list(S[x + 1: N])
    a_u_l = list(set(a))
    b_u_l = list(set(b))
    count = 0
    for a_u in a_u_l:
        if a_u in b_u_l:
            count = count + 1
    if count >= r_count:
        r_count = count
        
print(r_count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = 100000 * 300; // (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


class Edge{
public:
	int from, to, cost;
	Edge(int from = 0, int to = 0, int cost = 0) :
			from(from), to(to), cost(cost){}

	bool operator < (const Edge &e) const{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const{
		return cost > e.cost;
	}

};

class Node{
public:
	vector<Edge> edges;
	int dist;

	Node(){
		dist = INFTY;
	}
};

class Graph{
public:
	vector<Node> nodes;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
	}
	Node& operator[](int i){
		return nodes[i];
	}
};

class Data{

public:
	int dist;
	Edge *edge;
	Data(int dist, Edge *edge) {
		this->dist = dist;
		this->edge = edge;
	}

	bool operator < (const Data &d) const{
		return dist < d.dist;
	}
	bool operator >(const Data &d) const{
		return dist > d.dist;
	}
};

Graph G(0);
int N, M, R;
int RR[8];
int D[8][8];

int dijkstra(int st, int ed){

	// initialize
	rep(i, N) G[i].dist = INFTY;

	priority_queue<Data, vector<Data>, greater<Data>> pq;
	Edge e0 = Edge(-1, st, 0);
	Data d0 = Data(0, &e0);
	pq.push(d0);

	while(!pq.empty()){
		Data d = pq.top(); pq.pop();
		Edge &e = *d.edge;
		Node &n = G[e.to];
		if(n.dist <= d.dist) continue;
		n.dist = d.dist;
		// cerr << n.dist << endl;

		for(auto &ee: n.edges){
			pq.push(Data(n.dist + ee.cost, &ee));
		}
	}

	return G[ed].dist;
}

int minimum_permuatation(){

	int ret = INFTY * 10;
	vector<int> vec; rep(i, R) vec.push_back(i);

	do {
		int r = 0;
		rep(i, R-1) { r += D[vec[i]][vec[i+1]];}
		ret = min(ret, r);
	} while( next_permutation(vec.begin(), vec.end()) );

	return ret;
}

int main() {

	// input
	cin >> N >> M >> R;
	rep(i, R) {
		cin >> RR[i]; RR[i]--;
	}
	G = Graph(N);

	rep(i, M){
		int from, to, cost;
		cin >> from >> to >> cost; from--; to--;
		G[from].edges.push_back(Edge(from, to, cost));
		G[to].edges.push_back(Edge(to, from, cost));
	}

	// dijkstra
	rep(i1, R) rep(i2, R) {D[i1][i2] = 0;}
	rep(i1, R) rep(i2, R) if(i1 < i2){
		D[i1][i2] = dijkstra(RR[i1], RR[i2]);
		D[i2][i1] = D[i1][i2];
	}

	/*
	rep(i1, R) {
		rep(i2, R) fprintf(stderr, "%d ", D[i1][i2]);
		fprintf(stderr, "\n");
	}
	*/

	// minimum permutation
	cout << minimum_permuatation() << endl;

}

Measured memory_bytes: 2604
import io.StdIn._

object Main extends App {
  val n = readInt()
  val v = readLine().split(" ").map(_.toInt).toSeq
  val c = readLine().split(" ").map(_.toInt).toSeq

  require(1 <= n && n <= 20)
  require(v.forall(i => 1 <= i && i <= 50))
  require(c.forall(i => 1 <= i && i <= 50))

  println((0 to n).flatMap(i => v.zip(c).combinations(i).map(_.map(j => j._1 - j._2).sum)).max)
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; ++i) {
        cin >> a.at(i);
    }

    vector<int> pla(n);
    for (int i=0; i<n; ++i) {
        pla.at(a.at(i)-1) = i;
    }

    set<int> st;
    ll res = 0;
    for (int i=0; i<n; ++i) {
        st.insert(pla.at(i));
        auto iter = st.find(pla.at(i));
        ll l, r;
        if (iter == st.begin()) {
            l = -1;
        } else {
            --iter;
            l = *iter;
            ++iter;
        }
        ++iter;
        if (iter == st.end()) r = n;
        else r = *iter;

        res += (ll)(i+1) * (r-pla.at(i)) * (pla.at(i)-l);
    }

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
LL gi() {
	LL w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
LL q[100001];
map<LL,LL>S;
//取了长度为a的一截，又取了长度为b的一截，如果b<a则等价于直接取长度为b的一截
//从后往前递推，记录当前位置的数在最终序列中出现了多少次
//虽然长度很长，但是我们可以把数列进行后缀差分，这样初始情况就是s[n-1]=1
//然后一个后缀差分标记在一次传递中最多被拆成两个标记

int main()
{
	int n=gi(),m=gi()+1,i;LL t;
	q[1]=n;
	for (i=2;i<=m;i++) q[i]=gi();
	t=q[m];
	S[t-1]=1;
	map<LL,LL>::iterator it;
	for (i=m-1;i;i--)
		if (q[i]<t)
			for (t=q[i];(it=--S.end())->first>=t;S.erase(it))
				if (it->second) {
					if (it->first>=t)
						S[t-1]+=it->second*(it->first/t);
					S[it->first%t]+=it->second;
				}
	for (i=n-1;i;i--)
		S[i-1]+=S[i];
	for (i=0;i<n;i++)
		printf("%lld\n",S[i]);
	return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{ 
  vector< pair<int,int> > v;
  int n,T;
  scanf("%d%d",&n,&T);
  int i,c[n],t[n];
  for(i=0;i<n;++i)
    {
        scanf("%d%d",&c[i],&t[i]);
        v.push_back(make_pair(c[i],t[i]));
         
  }
  
   sort(v.begin(),v.end());
  
  for(i=0;i<v.size();++i)
  {
    if(v[i].second<=T)
        break;
  }
  
  if(i==v.size())
      printf("TLE");
  
  else
     printf("%d",v[i].first);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    ll r=a%b;
    while(r)a=b,b=r,r=a%b;
    return b;
}
int main(){
    int h,w,c;cin>>h>>w>>c;
    int a=gcd(h,w);
    cout<<(h/a)*(w/a)*c<<endl;
    return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {    
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1;i<b;i++) {
        if((i*a)%b == c%b) {
            cout<<"YES"<<endl;
            return;
        }
    }
    cout<<"NO"<<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  B - Addition and Multiplication
//
//  Created by wenhan on 2017/10/28.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>

int main() {
    int n,k;
    std::cin>>n>>k;
    int t=1;
    for(int i=1;i<=n;i++)
    {
        if(t*2>=t+k)
            t=t+k;
        else
            t=t*2;
    }
    std::cout<<t<<std::endl;
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
if K > (N*(N-1)//2)-(N-1):
    print(-1)
    exit()
else:
    hen = [[0,0] for _ in range((N-1)+((N-1)*(N-2)//2)-K)]
    for i in range(2,N+1):
        hen[i-2] = [1,i]
    tmp = 1
    br = 0
    if hen[-1] !=[0,0]:
        print(len(hen))
        for l in hen:
            print(*l)
        exit()
    for j in range(2,N):
        for k in range(j+1,N+1):
            hen[N-2+tmp] = [j,k]
            tmp += 1
            if N-2+tmp == len(hen):
                br = 1
                break
        if br == 1:
            break
    print(len(hen))
    for l in hen:
        print(*l)

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

#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;
const int maxn=2e5+10;
int a[maxn],b[maxn];
int n;

bool check1(int x){
	for(int i=x+1;i<=n;i++){
		if(b[i-x]>=a[i])return false;
	}
	return true;
}

bool check2(int x){
	for(int i=1;i<=x;i++){
		if(a[i]>=b[i+n-x])return false;
	}
	return true;
}

int main(){
	io;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n;i++)cin>>a[i];
	int l=0,r=n,res=-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check1(mid)){ res=mid;r=mid-1; }
		else l=mid+1;
	}
	if(res==-1){ cout<<"No"<<endl;return 0; }
	int l1=0,r1=n,res1=-1;
	while(l1<=r1){
		int mid=(l1+r1)>>1;
		if(check2(mid)){ res1=mid;l1=mid+1; }
		else r1=mid-1;
	}
	if(res1==-1){ cout<<"No"<<endl;return 0; }
	if(res<=res1){
		cout<<"Yes"<<endl;
		vector<int> ve;
		for(int i=res+1;i<=n;i++)ve.pb(a[i]);
		for(int i=1;i<=res;i++)ve.pb(a[i]);
		for(int i=0;i<sz(ve);i++){
			if(i)cout<<" ";
			cout<<ve[i];
		}
		cout<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 5884
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()
B = inpl()
aa = 0
bb = 0
i = 0
for tmp in itertools.permutations(range(1,n+1)):
    i += 1
    if list(tmp) == A:
        aa = i
    if list(tmp) == B:
        bb = i
print(abs(aa - bb))

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

#define SZ(x) ((int(x.size())))

typedef long long ll;

using namespace std;

const int maxn = 200*1000+10, mod = 1000000007;
ll fac[maxn], caf[maxn], h, w, a, b, ans;

ll power (int a, ll b, int m)
{
	if (b == 0)
		return 1;
	ll hlp = power (a, b / 2, m);
	if (b & 1)
		return (((hlp * hlp) % m) * a) % m;
	return (hlp * hlp) % m;
}

inline void make_fac ()
{
	fac[0] = 1;
	for (int i = 1; i < maxn; i++)
		fac[i] = (fac[i - 1] * i) % mod;
}

inline void make_caf ()
{
	caf[maxn - 1] = power (fac[maxn - 1], mod - 2, mod);
	for (int i = maxn - 2; i >= 0; i--)
		caf[i] = (caf[i + 1] * (i + 1)) % mod;
}

ll c (int x, int y)
{
	return (((fac[x] * caf[y]) % mod) * caf[x - y]) % mod;
}

int main()
{
	make_fac ();
	make_caf ();
	cin >> h >> w >> a >> b;
	for (int i = 0; i < b; i++)
		ans = (ans + ((c (i + h - a - 1, i) * c (w - i + a - 2 , a - 1)) % mod)) % mod;
	cout << (c (h + w - 2, h - 1) - ans + mod) % mod;
	return 0;
}

Measured memory_bytes: 3328
fn main() {
    let n = read();

    // 0:C 1:S 2:F
    let vec = read_lines(n - 1);
    for i in 0..n {
        let mut t = 0;
        for j in i..n-1 {
            if t < vec[j][1] {
                t = vec[j][1];
            } else if t % vec[j][2] == 0 {
                // do nothing
            } else {
                t = t + vec[j][2] - t % vec[j][2];
            }
            t = t + vec[j][0];
        }
        println!("{}", t);
    }
}

fn read() -> usize {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_lines(n: usize) -> Vec<Vec<i32>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim()
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap())
            .collect();
        v2.push(v);
    }
    v2
}


Measured memory_bytes: 4352