akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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();}
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(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans=0;
  cin>>N;
  ll A[N];
  map<ll,ll> M;
  REP(i,N){
    cin>>A[i];
    M[A[i]]++;
  }
  
  ll CNT[1010101];
  bool CAN[1010101];
  REP(i,1010101){
    CNT[i]=0;
    CAN[i]=false;
  }
  REP(i,N){
    CAN[A[i]]=true;
    CNT[A[i]]++;
  }
  
  FORE(v,M){
    ll AA=v.first;
    for(ll i=2; i<=1010101/AA; ++i){
      CAN[AA*i]=false;
    }
    if(CNT[AA]>=2) CAN[AA]=false;
  }
  
  REP(i,1010101){
    if(CAN[i]) ans++;
  }
  co(ans);
  return 0;
}

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

#define int long long
#define mod 1000000007

using namespace std;

int32_t main()
{
    vector <pair<int,int> > p;

    for(int i=0;i<3;i++)
    {
        int x,y;
        cin >> x >> y;
        
        p.push_back({x,y});
        p.push_back({y,x});
    }

    vector <int> v;

    for(int i=1;i<=4;i++)
        v.push_back(i);

    while(next_permutation(v.begin(),v.end()))
    {
        bool flag = true;

        for(int i=0;i<3;i++)
        {
            bool f1 = false;

            for(auto j:p)
            {
                if(j.first == v[i] && j.second == v[i+1])
                {
                    f1 = true;
                    break;
                }
            }

            if(!f1)
            {
                flag = false;
                break;
            }
        }

        if(flag)
        {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        mut s: Chars,
    }

    s.reverse();

    let mut now: u32 = 0;
    let mut ten: u32 = 1;

    let mut map: HashMap<u32, u32> = HashMap::new();
    map.insert(0, 1);

    for c in s {
        now = (c.to_digit(10).unwrap() * ten + now) % 2019;
        map.entry(now).and_modify(|v| *v += 1).or_insert(1);
        ten = (ten * 10) % 2019;
    }

    let ans: u32 = map
        .into_iter()
        .map(|(_, v)| if v >= 2 { v * (v - 1) / 2 } else { 0 })
        .sum();

    println!("{}", ans);
}


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

int main(){
	int a,b;
  	cin >> a >> b;
  	if(a>0)cout << "Positive" << endl;
  	else if(a<=0 && b>=0) cout << "Zero" << endl;
  	else{
    	if((a-b)%2==0)cout<<"Negative" << endl;
      	else cout << "Positive" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    
    if(a<b)
    {
        if(b<c)
        {
        printf("Yes\n");
        }
        else
    {
        printf("No\n");
    }
    }
    else
        {
            printf("No\n");
        }
}



Measured memory_bytes: 2040
#include <iostream>
#include <string>

int main() {
  int A = 0;
  std::cin >> A;

  std::string s;
  std::cin >> s;

  if (A >= 3200) {
    std::cout << s << std::endl;
  } else {
    std::cout << "red" << std::endl;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
	double a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f) {
	long double x = (b * f - c * e) / (b * d - a * e) * 1000.0f;
	long double y = (c * d - a * f) / (b * d - a * e) * 1000.0f;
	x = round(x) + 0.000001;
	y = round(y) + 0.000001;
	x /= 1000.0f;
	y /= 1000.0f;
	cout << fixed << setprecision(3) << x << ' ' << y << endl;
	}
	return 0;
}

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

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

		for(int i=1;i<=n;i++){
				if(i%3==0){
						cout<<' '<<i;
				}else{
						for(int x=i;x>0;x/=10){
								if(x%10==3){
										cout<<' '<<i;
										break;
								} 
						} 
				}
		}
		cout<<endl;
		return 0;
		
}

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

int main(){
  long long N,i,j;
  cin >> N;

  string res;
  switch(N % 10){
    case 0:
    case 1:
    case 6:
    case 8:
      res = "pon";
      break;
    case 3:
      res = "bon";
      break;
    default:
      res = "hon";
  	  break;
  }

  cout << res << endl;
}

Measured memory_bytes: 3572
import math
n = int(input())
a = list(map(int,input().split()))
b = sorted(a,reverse=True)

x = math.ceil(len(b)/2)
y = b[:x]
z = sum(y*2)-y[0]
if len(b)%2==1:
    print(z-y[-1])
else:
    print(z)

Measured memory_bytes: 32948
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, k;
int p[200010];
long long lSum[200010];
		
int main()
{
	scanf("%d%d", &n, &k);
	
	lSum[0] = 0;
	for (int i = 1 ; i <= n ; i++) {
		scanf("%d", &(p[i]));
		lSum[i] = lSum[i - 1] + p[i];
	}

		
	//exp = sum / n = (n + 1) / 2;
	long long maxDist = 0;
	for (int i = k ; i <= n ; i++) {
		long long curDist = lSum[i] - lSum[i - k];
		if (curDist > maxDist)
			maxDist = curDist;
	}
	
	double ans = (maxDist + k) / 2.0;
	
	printf("%.12lf\n", ans);
	
	
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#define int long long
#define inf 1145141919ll
#define oku 1000000007ll
using namespace std;
int a,b,c,d,e,f,g;
int dx[]={0,-1,0,1,0};
struct A{
	A *e;
	int temp;

};
struct B{
	A *src;
	A *dst;
	int cost;
};
struct C{
	int u;
	int v;
	int len;
	C(int x,int y,int z):u(x),v(y),len(z){}
};
int i,j,k,n;
int p[2][5001];
signed main(){
	cin>>a>>b>>c>>d;
	string s;
	for(i=0;i<c-a;i++)
		s+='R';
	for(i=0;i<d-b;i++)
		s+='U';
	for(i=0;i<c-a;i++)
		s+='L';
	for(i=0;i<d-b;i++)
		s+='D';
	s+='D';
	for(i=0;i<c-a+1;i++)
		s+='R';
	for(i=0;i<d-b+1;i++)
		s+='U';
	s+="LU";
	for(i=0;i<c-a+1;i++)
		s+='L';
	for(i=0;i<d-b+1;i++)
		s+='D';
	s+='R';
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED
    string s;
    cin>>s;
    int i,flag=0,n=s.length();
    for(i=0;i<n/2;++i)
    {
        if(s[i]!=s[n-1-i])
        {
            flag=1;
            break;
        }
    }
    for(i=0;i<(n-1)/4;++i)
    {
        if(s[i]!=s[(n-1)/2-1-i])
        {
            flag=1;
            break;
        }
    }
    for(i=(n+3)/2-1;i<n/2;++i)
    {
        if(s[i]!=s[n-1-i])
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        cout<<"No";
    else
        cout<<"Yes";
}

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


signed main(){

	int N, T;
	cin >> N >> T;
	vector<int> A(N, 0);
	rep(i, N) cin >> A[i];
	vector<int> B(N, 0);

	// iで売った場合
	int mi = A[0];
	for (int i = 1; i < N; i++){
		B[i] = A[i] - mi;
		mi = min(mi, A[i]);
	}

	sort(B.begin(), B.end(), greater<>());

	int ans = 1;
	for (int i = 1; i < N; i++){
		if (B[i] != B[0]) break;
		else ans = i+1;
	}
	cout << ans << endl;


	

	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;

inline vector<li> decom(li v) {
    vector<li> res(n);
    rin{
        res[i] = v % 4;
        v /= 4;
    }
    return res;
}

li a, b, c;
li l[11];
li len[4] = {0};

inline li calc(const vector<li>& v) {
    rep(i, 4)len[i] = 0;
    li val = 0;
    rin{
        if (len[v[i]] > 0 && v[i] < 3)val += 10;
        len[v[i]] += l[i];
    }
    if (min(len[0], min(len[1], len[2])) == 0)return INF;
    return val + abs(len[0] - a) + abs(len[1] - b) + abs(len[2] - c);
}

int main() {
    cin >> n;
    cin >> a >> b >> c;
    rin{cin >> l[i];}

    li val = 1;
    rin{val *= 4;}
    li res = INF;
    rep(i, val) {
        res = min(res, calc(decom(i)));
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n, k,cnt=0;
	cin >> n >> k;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	cout << ceil((n - k) / (double(k) - 1)) + 1 << endl;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct Edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const long double EPS = 10e-10;
const ll INF = 1LL << 50;

int main(){
    int n, m, x, y, r;
    ll t;
    char sl;
    while(scanf("%d%d", &n, &m), n){
        vector< vector<ll> > st(n, vector<ll>(n, INF)), lt(n, vector<ll>(n, INF));
        rep(n){
            st[i][i] = 0LL;
            lt[i][i] = 0LL;
        }
        rep(m){
            cin >> x >> y >> t >> sl;
            x--; y--;
            if(sl == 'S'){
                st[x][y] = st[y][x] = min(st[x][y], t);
            }else{
                lt[x][y] = lt[y][x] = min(lt[x][y], t);
            }
        }

        repp(k, n){
            repp(i, n){
                repp(j, n){
                        st[i][j] = min(st[i][j], st[i][k] + st[k][j]);
                        lt[i][j] = min(lt[i][j], lt[i][k] + lt[k][j]);
                }
            }
        }

        cin >> r;
        vector<int> z(r);
        rep(r){
            cin >> z[i];
            z[i]--;
        }

        // dp[i][j]: z[i]にいる，お船はjにあるときの最短時間
        ll dp[r][n];
        fill(dp[0], dp[r], INF);
        dp[0][z[0]] = 0LL;
        rep(r-1){
            // z[i]からkまで徒歩，kからlまで船，lからz[i+1]まで徒歩
            repp(k, n){
                if(dp[i][k] >= INF || lt[z[i]][k] >= INF) continue;
                repp(l, n){
                    dp[i+1][l] = min(dp[i+1][l], dp[i][k]+lt[z[i]][k]+st[k][l]+lt[l][z[i+1]]);
                }
                if(lt[z[i]][z[i+1]] < INF) dp[i+1][k] = min(dp[i+1][k], dp[i][k] + lt[z[i]][z[i+1]]);
            }
        }

        ll ans = INF;
        rep(n) ans = min(ans, dp[r-1][i]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 5084
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

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

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

int main(void) {
    int A, B;
    cin >> A >> B;
    if (B % A == 0) {
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }
    return 0;
}


Measured memory_bytes: 384
# 現在地x　k回d移動
from decimal import Decimal
x, k, d = map(Decimal, input().split())

def solve(x, k, d):
    if x < 0:
        x = -x

    if x > k*d:
        return x - k*d

    x, k = x - d*(x//d), k - x//d
    if k%2 == 0:
        return x
    else:
        return d - x

print(solve(x, k, d))

Measured memory_bytes: 9900
fn main() {
    let mut n = String::new();
    let mut a = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    std::io::stdin().read_line(&mut a).unwrap();
    let mut v: Vec<i32> = a.trim().split_whitespace()
        .map(|x| x.parse().unwrap()).collect();

//    println!("{}{}", n, a);
    
    let mut ans = 0;
    loop {
        let mut flag = 0;
        for x in &mut v {
//            println!("before: {}", x);
            if ( *x % 2 != 0 ) {
                flag = 1;
                break;
            }
            *x = *x / 2;
//            println!("{}", x);
        }
        if ( flag == 1 ) {
            break;
        }
        ans = ans + 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#define ll long long
#define vel vector<ll>
#define vvel vector<vel>
#define veb vector<bool>
#define pin pair<int,int>
#define ppin pair<pin,pin>
#define mkp make_pair 
const ll ze = 0;
using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b / a, c) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll l, n;
  cin >> l >> n;
  vector<ll> x(n);
  REP(i, n) cin >> x[i];

  if(n == 1) {
    cout << max(x[0], l-x[0]) << endl;
    return 0;
  }
  
  ll ans = 0;
  auto solve = [&](){
    vector<ll> a(x);
    FOR(i, 1, n) a[i] += a[i-1];
    vector<ll> b(x);
    REP(i, n) b[i] = l-b[i];
    for(ll i=n-2; i>=0; --i) b[i] += b[i+1];
    
    // 木iまで反時計回りで進んだ後交互に往復する
    REP(i, n) {
      ll dist = x[i];
      if(n-i == 1) continue;
      else {
        // [i, i+(n-i-1)/2]
        dist += (a[i+(n-i-1)/2] - (i==0?0:a[i-1])) * 2;
        if((n-i)%2) dist -= x[i+(n-i-1)/2];
        dist -= x[i];
        // [n-(n-i)/2, n-1]
        dist += b[n-(n-i)/2] * 2;
        if((n-i)%2 == 0) dist -= l - x[n-(n-i)/2];
      }
      chmax(ans, dist);
    }
  };

  solve();
  reverse(ALL(x));
  REP(i, n) x[i] = l-x[i];
  solve();

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5064
L, R = map(int, input().split())

if R - L >= 2018:
    print(0)
else:
    res = 2018
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            r = (i * j) % 2019
            res = min(res, r)
    print(res)


Measured memory_bytes: 41692
#include <bits/stdc++.h>
using namespace std;
const int Mod=1e9+7;
int n,m,fac[3010],inv[3010],f[3010][3010],g[3010][3010];
struct dsa {int l,r;}a[3010];
char S[3010];
int ksm(int aa,int bb) 
{
	int an=1;
	for (;bb;bb>>=1) {
		if (bb&1) an=1LL*an*aa%Mod;
		aa=1LL*aa*aa%Mod;
	}
	return an;
}
int C(int N,int M)
{
	if (N<M||N<0||M<0) return 0;
	return 1LL*fac[N]*inv[N-M]%Mod*inv[M]%Mod;
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",S+1);
	for (int i=1;i<=m;i++)
  	  scanf("%d%d",&a[i].l,&a[i].r);
	int nu=0,mx=0;
	for (int i=1;i<=m;i++) {
		if (mx>=a[i].r) continue;
		a[++nu].l=a[i].l;a[nu].r=a[i].r;
		mx=max(mx,a[i].r);
	}
	for (int i=1;i<=n;i++) {
		int s=0;
  	    for (int j=i;j<=n;j++) {
		    if (S[j]=='1') s++;
			g[i][j]=s;
		}
	}
	fac[0]=1;for (int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%Mod;
	inv[n]=ksm(fac[n],Mod-2);inv[0]=1;for (int i=n-1;i;i--) inv[i]=1LL*inv[i+1]*(i+1)%Mod;
	f[0][0]=1;a[nu+1].l=1e9;
	for (int i=1;i<=nu;i++) 
	  if (a[i].r<a[i+1].l) {
	  	  if (a[i-1].r<a[i].l) f[i][0]+=1LL*f[i-1][0]*C(a[i].r-a[i].l+1,g[a[i].l][a[i].r])%Mod,f[i][0]%=Mod;
			else 
 			  for (int k=0;k<=a[i-1].r-a[i].l+1;k++)
   			  	f[i][0]+=1LL*f[i-1][k]*C(a[i].r-a[i].l+1,k+g[a[i-1].r+1][a[i].r])%Mod,f[i][0]%=Mod;
	  }
	  else {
		  if (a[i-1].r<a[i].l)
			for (int j=0;j<=g[a[i].l][a[i].r];j++) 
 			  f[i][j]+=1LL*f[i-1][0]*C(a[i+1].l-a[i].l,g[a[i].l][a[i].r]-j)%Mod,f[i][j]%=Mod;
		  else 
			for (int j=0;j<=a[i].r-a[i+1].l+1;j++)				
			  for (int k=0;k<=a[i-1].r-a[i].l+1;k++)
				if (g[a[i-1].r+1][a[i].r]+k>=j) f[i][j]+=1LL*f[i-1][k]*C(a[i+1].l-a[i].l,g[a[i-1].r+1][a[i].r]+k-j)%Mod,f[i][j]%=Mod;
	  }
	cout<<f[nu][0];
	return 0;
}

Measured memory_bytes: 53504
#include <stdio.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
	int P, Q, R, ans = 0;
	scanf("%d %d %d", &P, &Q, &R);

	ans = P + Q + R - max(max(P, Q), R);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
import numpy as np
from math import factorial

n,k = map(int, input().split())

mod = pow(10, 9) + 7

def comb(n,k):
    "power_funcを用いて(nCk) mod を求める"
    if n<0 or k<0 or n<k:
        return 0
    elif n==0 or k==0:
        return 1
    a=factorial(n) % mod
    b=factorial(k) % mod
    c=factorial(n-k) % mod
    return (a*power_func(b,mod-2)*power_func(c,mod-2))% mod

def power_func(a,b):
    "a^b mod を求める"
    if b==0:
        return 1
    elif b%2==0:
        d=power_func(a,b//2)
        return d*d %mod
    elif b%2==1:
        return (a*power_func(a,b-1))%mod

for i in range(k):
    print(int(comb(k-1,i) * comb(n-k+1,i+1)) % mod)

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

int DP[45];
void init(){
    rep(i,45)DP[i]=-1;
}

int fibonaci(int n){
    if(DP[n]!=-1)return DP[n];
    if(n==0||n==1)return DP[n]=1;
    return DP[n]=fibonaci(n-1)+fibonaci(n-2);
}

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


Measured memory_bytes: 3132
from itertools import product

alphabet = 'abcdefghijklmnopqrstuvwxyz'

def decrypt(s):
    for a in range(1, 26, 2):
        if a == 13: continue
        for b in range(26):
            x = ''.join(chr(ord('a') + (a * i + b) % 26) for i in range(26))
            t = s.translate(str.maketrans(x, alphabet))
            if 'this' in t or 'that' in t:
                return t

n = int(input())
for i in range(n):
    s = input()
    print(decrypt(s))

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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; int N; cin >> N;
  US<string> t; string s;
  while(N--){
    cin >> s;
    t.INS(s);
  }
  cout<<t.size()<<endl;
}


Measured memory_bytes: 17748
H, W, D = map(int, input().split())
grid = []
memo = [[] for _ in range(H*W+1)]
for i in range(H):
    grid.append(list(map(int, input().split())))
    for j in range(len(grid[i])):
        memo[grid[i][j]].append(i)
        memo[grid[i][j]].append(j)

S = [0 for i in range(H*W+1)]

for i in range(H*W+1):
    if(i <= D):
        continue
    S[i] = S[i-D]+ abs(memo[i][0]-memo[i-D][0])+abs(memo[i][1]-memo[i-D][1])

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(S[r]-S[l])

Measured memory_bytes: 24032
fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    var res = 0
    a.forEachIndexed { index, i ->
        if (index % 2 == 0 && i % 2 == 1) {
            res += 1
        }
    }
    println(res)
}

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

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

ref = [i for i in range(1, len(p) + 1)]

res = 0
for i,v in enumerate(p):
    if ref[i] != v:
        res += 1

if res < 3:
    print('YES')
else:
    print('NO')

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

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; i++) cin >> a[i];

    int cash = 1000;
    for(int i = 1; i < n; i++) {
        int stock = 0;
        if(a[i] < a[i + 1]) stock += cash / a[i];
        cash += (a[i + 1] - a[i]) * stock;
    }

    cout << cash << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
  int n;
  int total = 0;
  cin >> n;
  for (size_t c = 1; c <= n; c++) {
    if (c % 2 == 0) {
      continue;
    }
    int count = 0;
    for (size_t i = 1; i <= n; i++) {
      if (c % i == 0) {
        count++;
      }
    }
    if (count == 8) {
      total++;
    }
  }
  cout << total;
  return 0;
}


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

int MOD;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator<(mint a, mint b) { return a.n < b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

mint modinv(mint n) {
  int a = (int)n, b = MOD;
  int s = 1, t = 0;
  while (b != 0) {
    int q = a / b;
    a -= q * b;
    s -= q * t;
    swap(a, b);
    swap(s, t);
  }
  return s >= 0 ? s : s + MOD;
}


int main() {
  int N;
  string S;
  cin >> N >> MOD >> S;
  ll ans = 0;
  if (MOD==2 || MOD==5) {
    rep(i,N) if ((S[i]-'0')%MOD == 0) ans += i+1;
  } else {
    map<mint,ll> mp;
    mp[0]++;
    mint s = 0;
    mint p = 1;
    rep(i,N) {
      s = s*10 + (S[i]-'0');
      p *= modinv(10);
      ans += mp[s*p]++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string.h>
using namespace std;

int main(){
  	int N,K;
  string s;
  cin>>N>>K;
  cin>>s;
  K--;
  if('A'<=s[K]){
   	s[K]-='A'-'a'; 
  }
  cout<<s;
 	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>

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

int limit(int lim, int exp) {
	int res = 0;
	for (int i = 0; pow(i,exp) < lim+1; i++) {
		res = i;
	}
	return res;
}

int main(void) {
	int e;
	cin >> e;

	while (e != 0) {
		int m = 0;
		int res;
		int en = e;
		int temp;
		int z = limit(en,3);

		for (int i = 0; i < 10 && !((z-i) < 0); i++) {
			m = 0;
			en = e;

			m += z-i;
			en -= pow(z-i,3);

			temp = limit(en,2);
			m += temp;
			en -= pow(temp,2);

			temp = limit(en,1);
			m += temp;

			if (i == 0) {
				res = m;
			}
			else if (m < res) {
				res = m;
			}
		}

		temp = limit(e,2);
		if (temp < res) {
			if (pow(temp,2) == e) {
				res = temp;
			}
		}
		
		cout << res << endl;
		cin >> e;
	}
	return 0;
}

Measured memory_bytes: 3132
use proconio::input;
use std::collections::BTreeSet;
use std::ops::Bound::Excluded;
use std::ops::Bound::Unbounded;
use rand::Rng;

const C:usize = 26;
const N_ITER:usize = 2000000;

fn main() {

    input!{
        d:usize,
        c:[i32;C],
        s:[[i32;C];d],
    };
    let mut t:Vec<usize> = vec![0;d];
    let mut occs = vec![BTreeSet::<i32>::new();C];
    for occ in &mut occs {
        occ.insert(-1);
    }
    let mut ans = 0;
    for (day,&ti) in t.iter().enumerate() {
        ans += s[day][ti];
        occs[ti].insert(day as i32);
        for j in 0..26 {
            let sc = (c[j] as i32) * ((day as i32) -*occs[j].iter().last().unwrap());
            ans -= sc;
        }
    }
    for occ in &mut occs {
        occ.insert(d as i32);
    }    

    let sum_lr = |l,r,n| n*(l+r)/2;
    let mut rng = rand::thread_rng();
    
    for turn in 0..N_ITER {
        let d = rng.gen::<usize>()%d;
        let q = rng.gen::<usize>()%C;
        let pre_q = t[d];
        let pre_ans = ans;
        let mut try_change = |d:usize,q:usize|{
            let pre_q = t[d];
            ans-=s[d][pre_q];
            ans+=s[d][q];
            t[d]=q;
            let d = d as i32;
            // for pre_q
            let mut calc = |q:usize,is_ins:bool| {
                if is_ins {
                    occs[q].insert(d);
                }
                else {
                    occs[q].remove(&d);
                }
                let pre_d = *occs[q].range((Unbounded,Excluded(&d))).last().unwrap();
                let nex_d = *occs[q].range((Excluded(&d),Unbounded)).next().unwrap();
                let lbig = d - pre_d;
                let rbig = nex_d - pre_d -1;
                let lsml = 0;
                let rsml = nex_d-d-1;
                let sc = sum_lr(lbig,rbig,nex_d-d)-sum_lr(lsml,rsml,nex_d-d);
                sc
            };
            
            ans -= calc(pre_q,false)*c[pre_q];
            ans += calc(q,true)*c[q];
            ans
        };
        let now_ans = try_change(d,q);
        let x = rng.gen::<usize>()%N_ITER;
        if now_ans<=pre_ans && x<=turn {
            try_change(d,pre_q);
        }
    }

    for tv in t {
        println!("{}",tv+1);
    }
}

Measured memory_bytes: 2720
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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 (b<a) { a=b; return 1; } return 0; }

ll cnt[10][10],N,ans;
string tmp;

int main(){
    cin>>N;
    repi(i,1,N+1){
        tmp = to_string(i);
        cnt[tmp[0]-'0'][tmp[tmp.size()-1]-'0']++;
    }
    rep(i,10){
        rep(j,10){
            ans+=cnt[i][j]*cnt[j][i];
        }
    }
    out(ans);
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    if (s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

const int maxn=1e3+50;
char s[maxn];
char sstd[]="AKIHABARA";

int main(){
    scanf("%s",s);
    int len=strlen(s);
    int p=0;
    for (int i=0;i<9;i++){
        if (p<len && sstd[i]==s[p]){
            p++;
        }
        else if (sstd[i]=='A'){
            
        }
        else {
            printf("NO\n");
            return 0;
        }
    }
    if (p==len) printf("YES\n");
    else printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
 
// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const int INF = 2e9;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 998244353;

int dp[N][4], n;
vector<vector<int>> in;

int solve(int day, int task)
{
    if(day == n)
        return 0;
    int &res = dp[day][task];
    if(res != -1)
        return res;
    for(int i = 0; i < 3; i++)
    {
        if(i == task)
            continue;
        res = max(solve(day + 1, i) + in[day][i], res);
    }
    return res;
}

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        in.pb({a, b, c});
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 3) << endl;
    return 0;
}

Measured memory_bytes: 40880
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 100000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

#define int int64_t

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

template<typename STL> inline void print_STL(STL c, string ab = ""){
	cout << ab << '\n';
	for(auto t : c) cout << t << ' '; cout << '\n';}

template<typename VEC> inline void import_VEC(VEC& c, int n){
	typename VEC::value_type tmp;
	for(int i = 0; i < n; ++i){	cin >> tmp; c.push_back(tmp);} }

inline int mar(int a, int b)
{
	return a <= b ? a + 100000*b : mar(b,a);
}

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

	int n,m;
	cin >> n >> m;
	vector<int> a,b;
	vector<vector<int>> d, c(n,vector<int>(n, INF));
	REP(i,0,m)
	{
		int ta, tb, tc;
		cin >> ta >> tb >> tc;
		ta--;
		tb--;
		c[ta][tb] = tc;
		c[tb][ta] = tc;
		a.push_back(ta);
		b.push_back(tb);
	}

	d = c;


	REP(k,0,n)
	{
		REP(i,0,n)
			REP(j,0,n)
			{
				int tmp = d[i][k] + d[k][j];
				if(tmp < d[i][j])
				{
					d[i][j] = tmp;
				}
			}
	}

	int ans = 0;

	REP(i, 0, m)
		if(d[a[i]][b[i]] < c[a[i]][b[i]]) ans++;

	/* for(auto t : ss) */
	/* 	cerr << t << '\n'; */

	cout << ans << '\n';

}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

int main()
{
    string str;
    cin >> str;
    vector<bool> chs(26);
    for (auto s : str) {
        //cout << (s-'a') << endl;
        chs[s - 'a'] = true;
    }
    
    for (int i = 0; i < 26; ++i)
        if (!chs[i]) {
            char c = ('a' + (char)(i));
            cout << c << endl; return 0;
        }
    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
    long long i,j,n,m,tmp;
    scanf("%lld %lld",&n,&m);
    if(n > m){tmp = n;n = m;m = tmp;}
    if(n >= 2 && m >= 2)
    {

        printf("%lld",(n - 2) * (m - 2));
    }
    else if(n == 1 && m >= 2)
    {
        printf("%lld",m - 2);
    }
    else 
    {
        printf("1");
    }
    
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int,readline().split())
vw = [(0,0)]+[tuple(map(int,readline().split())) for _ in range(n)]

A = 10
N = min(1<<A,n+1)

memo = [None for _ in range(N)]
L = 10**5+1
memo[0] = [0]*L

for i in range(1,N):
    m = memo[i>>1][:]
    v,w = vw[i]    
    for j in range(L-1,w-1,-1):
        if m[j] < m[j-w]+v:
            m[j] = m[j-w]+v
    memo[i] = m

q, = map(int,readline().split())
ans_ = [0]*q
for _ in range(q):
    u,l = map(int,readline().split())

    m = u.bit_length() - A
    if m<0: m=0
    dv = [0]*(1<<m)
    dw = [0]*(1<<m)
    for i in range(m):
        v,w = vw[u]
        for j in range(1<<i):
            dv[j+(1<<i)] = dv[j]+v
            dw[j+(1<<i)] = dw[j]+w
        u >>= 1
    
    ans = 0
    for v,w in zip(dv,dw):
        if w <= l:
            val = memo[u][l-w] + v
            if val > ans: ans = val
    ans_[_] = ans
    
print(*ans_,sep="\n")        


Measured memory_bytes: 900272
#include<bits/stdc++.h>
using namespace std;
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<int,int> P;
typedef pair<P,P> PP;
int main(void)
{
	PP PY[100000];
	int n,m;
	int p,y;
	int cnt;
	int i,j;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>p>>y;
		PY[i].ff=p; PY[i].sf=i;
		PY[i].fs=y;
	}
	sort(PY,PY+m);
	cnt=1;
	for(i=0;i<m;i++){
		if(PY[i].ff!=PY[i-1].ff){
			cnt=1;
		}
		PY[i].ss=cnt;
		cnt++;
	}
	/*for(i=0;i<m;i++){
		cout<<PY[i].sf<<" "<<PY[i].ss<<endl;
	}*/
	for(i=0;i<m;i++) swap(PY[i].ff,PY[i].sf);
	sort(PY,PY+m);
	/*for(i=0;i<m;i++){
		cout<<PY[i].ff<<" "<<PY[i].ss<<endl;
	}*///sf 前 ss 後ろ
	for(i=0;i<m;i++){
		printf("%06d%06d\n",PY[i].sf,PY[i].ss);
	}
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
  int n,sum=0,ali=0,bob=0;
  cin>>n;
  int a[100],i;
  for(i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sort(a,a+n,greater<int>());
  i=0;
  while(sum>0){
    if(i==0||i%2==0){
      sum-=a[i];
      ali+=a[i];
    }
    else{
      sum-=a[i];
      bob+=a[i];
    }
  i++;
  }

  cout<<ali-bob<<endl;
  return 0;
}


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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N,L,T;
    cin >> N >> L >> T;
    vector<ll> X(N),W(N);
    rep(i,N){
        cin >> X[i] >> W[i];
    }
    vector<ll> tmp;
    // まずはありの最終的な座標を出す
    rep(i,N){
        if(W[i]==1)tmp.push_back((X[i] + T) % L);
        else tmp.push_back((((X[i]-T)%L)+L)%L);
    }
    sort(ALL(tmp));
    // 次に原点から見て一番近い所のindexを探す
    ll cnt = 0;
    rep(i,N){
        // ありさんが原点を右から左に通過するときは cnt++;
        // 左から右に通過するときは cnt--;
        // 現在地がX[i] で T 秒間にどれだけ原点を通るかを出したい
        if(W[i]==1){
            cnt += (T+X[i])/L;
        }else{
            cnt -= (T+L-X[i]-1)/L;
        }
    }
    cnt = ((cnt%N)+N)%N;
    vector<ll> res(N);
    rep(i,N) cout << tmp[(i+cnt)%N] << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    return os << p.first << " " << p.second;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

vector<vector<ll>> G;
vector<bool> used;
vector<ll> order;
ll next_order = 0;
vector<ll> ans;
void add_ans(ll v) {
    ans.pb(v);
}
ll dfs(ll v, ll prev) {
    ll res = order[v] = next_order++;
    bool is_articulation = false;
    ll d = 0;
    EACH(to, G[v]) {
        if (to == prev) continue;
        if (order[to] >= 0) {
            res = min(res, order[to]);
        }
        else {
            ll low = dfs(to, v);
            if (prev >= 0 && low >= order[v]) {
                is_articulation = true;
            }
            res = min(res, low);
            ++d;
        }
    }
    if (prev < 0 && d >= 2) is_articulation = true;
    if (is_articulation) add_ans(v);
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m; cin >> n >> m;
    vector<ll> g(n);
    G.resize(n);
    REP(i, m) {
        ll a, b; cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }
    order.assign(n, -1);
    dfs(0, -1);
    sort(ALL(ans));
    EACH(a, ans) {
        cout << a << endl;
    }
}

Measured memory_bytes: 5532
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
	int A, B;
	cin >> A >> B;
  int count=0;
  for (int i=A; i<B+1; i++){
  if ((i/1000)%10 == (i/10)%10 && i/10000 == i %10){
    //kaibun teki nara count++ suru
    count++;
  }
  }
	cout << count<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int d, x;
	cin >> d >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	int ans = x;
	for (int i = 0; i < n; i++) {
		ans += 1 + ((d-1) / a.at(i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>

#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(long (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(long (i)=(a)-1;(i)>=(b);(i)--)
#define MOD 1000000007
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<long,long>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).begin(),(a).end(),greater<int>())
#define MP(a,b) make_pair(a,b)
#define FORE(a,b) for(auto &&a:b)

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int main(void){
	int a,b,c; cin>>a>>b>>c;
	int cnt=0;
	FOR(i,a,b+1) if(c%i==0) cnt++;
	cout<<cnt<<endl;
}

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

class Program {
    static int Main(string[] args) {
        string[] v = Console.ReadLine().Split(' ');

        long n = long.Parse(v[0]);
        long m = long.Parse(v[1]);
        long l = long.Parse(v[2]);

        long[,] A = new long[n, m];
        long[,] B = new long[m, l];
        long[,] C = new long[n, l];

        for (long i = 0; i < n; i++) {
            string[] x = Console.ReadLine().Split(' ');

            for (long k = 0; k < x.Length; k++) {
                A[i, k] = long.Parse(x[k]);
            }
        }

        for (long i = 0; i < m; i++) {
            string[] x = Console.ReadLine().Split(' ');

            for (long k = 0; k < x.Length; k++) {
                B[i, k] = long.Parse(x[k]);
            }
        }


        for (long r = 0; r < n; r++) {
            for (long c = 0; c < l; c++) {

                for (long x = 0; x < m; x++) {
                    C[r, c] += A[r, x] * B[x, c];
                }
            }
        }

        for (long r = 0; r < n; r++) {
            for (long c = 0; c < l; c++) {
                if (c > 0) { Console.Write(" "); }
                Console.Write(C[r, c]);
            }
            Console.WriteLine(string.Empty);
        }

        return 0;
    }
}


Measured memory_bytes: 17932
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def switch(n):
    if n == '1':
        return '9'
    elif n == '9':
        return '1'
    else:
        return n


def main():
    N = ns()
    ans = ''
    for n in N:
        ans += switch(n)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9048
#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 k;
  cin >> k;

  if(k%7==0) k /= 7;
  int L = 9 * k;

  int i = 0;
  int a = 10;
  int ans = 0;

  while(i<L+5){
    ans++;
    if(a%L==1){
      cout << ans << endl;
      return 0;
    }
    else{
      a %= L;
      a *= 10;
    }
    i++;
  }

  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3620