akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n;
    cin >> n;
    vector<long long> vec(n);
    map<ll, ll> mp;
    rep(i, n){
        cin >> vec[i];
        mp[vec[i]]++;
    }

    ll ans = 0;
    
    for(auto i: mp){
        //cout << i.first << " " << i.second <<endl;  //key
        ans += (i.second * (i.second-1) / 2);
    }
    
    rep(i,n){
        ll tmp = mp[vec[i]];
        ll mainasu = mp[vec[i]] * (mp[vec[i]] - 1) / 2;
        ll plus = (mp[vec[i]]-1) * (mp[vec[i]] - 2) / 2;
        cout << ans - mainasu + plus << endl;
    }

    //cout << ans << endl;

}

Measured memory_bytes: 11008
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int m;
    cin >> m;
    int P;
    cin >> P;
    vector<vector<pair<int,int>>> graph(n);
    vector<vector<int>> rgraph(n);
    for (int i = 0; i < m; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        w -= P;
        graph[u].emplace_back(v, w);
        rgraph[v].push_back(u);
    } 

    
    vector<int> ok(n, 0);
    
    {
        vector<int> que;
        que.emplace_back(n - 1);
        ok[n - 1] |= 1;
        for (int i = 0; i < que.size(); ++i) {
            int u = que[i];
            for (auto v : rgraph[u]) {
                if ((ok[v] & 1) == 0) {
                    ok[v] |= 1;
                    que.emplace_back(v);
                }
            }
        }
    }
    {
        vector<int> que;
        que.emplace_back(0);
        ok[0] |= 2;
        for (int i = 0; i < que.size(); ++i) {
            int u = que[i];
            for (auto& e : graph[u]) {
                int v = e.first;
                if ((ok[v] & 2) == 0) {
                    ok[v] |= 2;
                    que.emplace_back(v);
                }
            }
        }        
    }

    if (ok[n - 1] != 3) {
        cout << "-1\n";
        return 0; 
    }

    // for (int i = 0; i < n; ++i) {
    //     cout << i << " " << ok[i] << endl;
    // }

    const long long INF = 1LL << 60;

    vector<long long> dis(n, -INF);
    dis[0] = 0;

    int LIMIT = 20000;
    int t = 0;
    for (int i = 0; i < LIMIT; ++i) {
        bool changed = false;
        ++t;
        for (int u = 0; u < n; ++u) {
            if (ok[u] != 3) {
                continue;
            }
            for (auto& e : graph[u]) {
                int v = e.first;
                long long w = e.second;
                if (ok[v] != 3) {
                    continue;
                } 
                if (dis[v] < dis[u] + w) {
                    dis[v] = dis[u] + w;
                    changed = true;
                }
            }
        }
        if (!changed) {
            break;
        }
    }

    long long res = -1;
    if (t < LIMIT) {
        res = max(0LL, dis[n - 1]);
    }
    cout << res << "\n";

    return 0;
}

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

int main() {
	long n;
	cin >>n;
	vector<long> R(n);
	for(int i=0;i<n;i++){
		cin >>R[i];
	}
	long m=-1000000000;
	long k=1000000000;
	for(int i=0;i<n-1;i++){
		k=min(k,R[i]);
		m=max(m,R[i+1]-k);
	}
	cout <<m<<endl;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
#define int long long

int f(int a, int b, int N) {
    int ret = 0;
    for (int i = 1; i <= N; i++) {
        int end;
        int tmp = i;
        while (tmp){
            end = tmp, tmp /= 10;
        } 
        ret += (int)(i % 10 == b && end == a);
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            ans += f(i, j, N) * f(j, i, N);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define int long long int
main() 
{ 
	string s;
	cin>>s;
	string ans="";
	int l=s.length();
	for(int i=0;i<l;i++)
	{
	    if(s[i]=='B' && i+1<l && s[i+1]=='C')
	    {
	        ans+='D';
	        i++;
	    }
	    else
	    {
	        ans+=s[i];
	    }
	}
	int count=0;
	int res=0;
	for(int i=ans.length()-1;i>=0;i--)
	{
	    if(ans[i]=='D')
	    {
	        //cout<<"heloo"<<endl;
	        count++;
	    }
	    else if(ans[i]=='A')
	    {
	        res+=count;
	    }
	    else
	    {
	        count=0;
	    }
	}
	cout<<res<<endl;
	return 0; 
} 


Measured memory_bytes: 776
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    tou = []
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                if x == (i + j + k):
                    count += 1
                    if i == j or j == k or k == i:
                        count -= 1
                    
    print(count // 6)


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

#define sz(a) a.size()

using namespace std;

const int N = 3*1e3 + 7;

string a, b;
int f[N][N];

void tracing(int i, int j)
{
    if(!i || !j) return;
    if(a[i - 1] == b[j - 1])
    {
        tracing(i - 1, j - 1);
        cout << a[i - 1];
    }
    else if(f[i - 1][j] >= f[i][j - 1]) tracing(i - 1, j);
    else tracing(i, j - 1);
}

int main()
{
    cin >> a >> b;
    for(int i = 1; i <= sz(a); i++)
        for(int j = 1; j <= sz(b); j++)
    {
        if(a[i - 1] == b[j - 1]) f[i][j] = f[i - 1][j - 1] + 1;
        else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
    }

    tracing(sz(a), sz(b));
}


Measured memory_bytes: 35840
#include<iostream>
using namespace std;
int main(){
	int a[3],n5=2,n7=1;
	cin>>a[0]>>a[1]>>a[2];
	for(int i=0;i<3;i++){
		if(a[i]==5){
			n5--;
		}else if(a[i]==7){
			n7--;
		}
	}
	if(n5==0&&n7==0){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int A, B, ans = -1;
	vector<int> divA, divB;
	cin >> A >> B;
	for (int i = 1; i <= 1000; i++) {
		divA.push_back((int)(i * 0.08));
		divB.push_back((int)(i * 0.1));
	}
	for (int i = 0; i < 1000; i++) {
		if (divA[i] == A && divB[i] == B) {
			ans = i + 1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  /* code */
  int n ;
  int cnt = 0;
  cin >> n ;
  vector<int> l(n+1) ;
 
  for (int i = 0; i < n; i++)
  {
    cin >> l[i];
  }
  l[n] = 100000;
  sort(l.begin(),l.end());

  for (int i = 0; i < n-2; i++)
  {
    for (int j = i+1; j < n-1; j++)
    {
      int wa = l[j] + l[i];
      int sa = l[j] - l[i];

      int sa_ind = distance(l.begin(),upper_bound(l.begin(),l.end(),sa));
      int wa_ind = distance(l.begin(),lower_bound(l.begin(),l.end(),wa));

    //  std::cout << i << j << sa_ind << wa_ind << "\n";

      if (wa_ind > j)
      {
        if (sa_ind <= j)
        {
        sa_ind = j+1;
        }
        if (wa_ind - sa_ind >0)
        {
          cnt += wa_ind - sa_ind ;
        }
        
      }
      
      
    }
  }
  
  std::cout << cnt << "\n" ;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int ans = 0;
	int n, t; cin >> n >> t;
	vi a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	
	vector<vi> dp(n + 1, vi(t));
	rep(i, n){
		dp[i + 1] = dp[i];
		rep(j, t - a[i]) dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + b[i]);
	}
	reverse(all(a)); reverse(all(b));
	vector<vi> dp2(n + 1, vi(t));
	rep(i, n){
		rep(j, t) ans = max(ans, dp2[i][j] + b[i] + dp[n - 1 - i][t - 1 - j]);
		dp2[i + 1] = dp2[i];
		rep(j, t - a[i]) dp2[i + 1][j + a[i]] = max(dp2[i + 1][j + a[i]], dp2[i][j] + b[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70912
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

class dijkstra{
public:
struct edge{int to,cost;};
const int MAX_V = 100001;
vector< vector<edge> > G;
int d[100001];
int V = 0;
priority_queue < pair<int,int>,vector< pair<int,int> >,greater< pair<int,int> > > que;
const int Inf = 1 << 30;

    dijkstra(int v){
        fill_n(d,v,Inf);
        //d.resize(v,Inf);
        G.resize(v);
        V = v;
    };

    void input(int r){
        for(int i = 0;i < r;i++){
            int x,y,z;
            cin >> x >> y >> z;
            edge e;
            e.to = y; e.cost = z;
            G[x].push_back(e);
            //printf("(x,y,z) =(%d,%d,%d)\n",x,y,z);
        }
    }
    void discover(int s){
        d[s] = 0;
        que.push({0,s});
        while(!que.empty()){
            pair<int,int> p = que.top();que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (int i=0;i < G[v].size();i++){
                edge e=G[v][i];
                if (d[e.to] > d[v]+ e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push({d[e.to],e.to});
                }
            }
        }
        for (int j=0;j < V;j++){
            if (d[j] == Inf) cout << "INF" << endl;
            else cout << d[j] << endl;
        }

    }
};

int main(){
    int t,e,r;
    cin >> t >> e >> r;
    dijkstra pass(t);
    pass.input(e);
    pass.discover(r);
}


Measured memory_bytes: 13036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define PI (acos(-1))
typedef long double ld;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  // const dl p1=1, p2=2, p3=3, pinf=-1;

  ld x[n], y[n];
  rep(i, n) cin >> x[i];
  rep(i, n) cin >> y[i];

  ld p1sum=0, p2sum=0, p3sum=0, pinf=0;
  rep(i, n) {
    ld sum = abs(x[i] - y[i]);
    p1sum += sum;
    p2sum += powl(sum, 2);
    p3sum += powl(sum, 3);
    if(pinf < sum) pinf = sum;
  }

  cout << fixed;
  cout << p1sum << endl;
  cout << powl(p2sum, 1.0/2.0) << endl;
  cout << powl(p3sum, 1.0/3.0) << endl;
  cout << pinf << endl;
  
  return 0;
}



Measured memory_bytes: 3472
#include<stdio.h>

#define N 100

static int MAX = 500;
static int INFTY = (1 << 21); //1 shift 21 bits

main(){
  int n, i, j, e, v, sum;
  int u = 0, mincost = 0;
  int cost[N];
  int key[N];
  int p[N], M[N][N];
  
  //input
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      if(e == -1){
	M[i][j] = INFTY;
      }else{
	M[i][j] = e;
      }
    }
  }
  
  //calc
  for(i = 0; i < n; i++){
    key[i] = INFTY;
    p[i] = -1;
    cost[i] = 0;
  }
  
  key[0] = 0;
  
  while(1){
    u = -1;
    mincost = INFTY;
   
    for(i = 0; i < n; i++){
      if(key[i] < mincost && cost[i] == 0){
	mincost = key[i];
	u = i;
      }
    }
    
    if(u == -1) break;
   
    cost[u] = 1;
    
    for(v = 0; v < n; v++){
      if(M[u][v] < key[v] && cost[v] ==0){
	p[v] = u;
	key[v] = M[u][v];
      }
    }

  }//end while
  
  sum = 0;
  
  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }
  
  //output
  printf("%d\n", sum);
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int INF=1e9;

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

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

int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> s(H);
  for(int i=0;i<H;i++)  cin >> s.at(i);
  
  vector<vector<int>> ans(H,vector<int>(W,0));
  int count=1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s.at(i).at(j)=='#'){
        ans.at(i).at(j)=count;
        count++;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=1;j<W;j++){
      if(ans.at(i).at(j)==0)  ans.at(i).at(j)=ans.at(i).at(j-1);
    }
  }
  for(int i=0;i<H;i++){
    for(int j=W-2;j>=0;j--){
      if(ans.at(i).at(j)==0)  ans.at(i).at(j)=ans.at(i).at(j+1);
    }
  }
  for(int j=0;j<W;j++){
    for(int i=1;i<H;i++){
      if(ans.at(i).at(j)==0)  ans.at(i).at(j)=ans.at(i-1).at(j);
    }
  }
  for(int j=0;j<W;j++){
    for(int i=H-2;i>=0;i--){
      if(ans.at(i).at(j)==0)  ans.at(i).at(j)=ans.at(i+1).at(j);
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W-1;j++)  cout << ans.at(i).at(j) << " ";
    cout << ans.at(i).at(W-1) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1280
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    ans = INF
    for i in range(-100, 101):
        score = 0
        for x in a:
            score += (x - i) ** 2
        ans = min(ans, score)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63988
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	string s;
	cin >> s;
	if (s == "Sunny")
		cout << "Cloudy" << endl;
	else if (s == "Cloudy")
		cout << "Rainy" << endl;
	else
		cout << "Sunny" << endl;
}


Measured memory_bytes: 3472
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
S = [0]*N
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
ans = 0
for k in range(N-1,0,-1):
    ans += A[k]*S[k-1]
    ans %= MOD
print(ans)


Measured memory_bytes: 105040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
int N;
vector<int> C;
vector<int> nc[200010];
ll dp[200010] = {1};
int nxt[200010];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        int c;
        cin >> c;
        C.push_back(c);
        nxt[i] = N;
    }

    C.erase(unique(C.begin(), C.end()), C.end());

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

    for(int i = 0; i <= 2e5; i++){
        for(int j = 0; j < (int)nc[i].size() - 1; j++){
            nxt[nc[i][j]] = nc[i][j + 1];
        }
    }

    for(int i = 0; i < C.size(); i++){
        dp[i + 1] += dp[i];
        dp[i + 1] %= mod;
        dp[nxt[i]] += dp[i];
        dp[nxt[i]] %= mod;
    }

    cout << dp[C.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 14324
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b  && b == c && a == c) printf("No\n");
    else if (a != b && a != c && b != c) printf("No\n");
    else printf("Yes\n"); 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
int H, W;
char a[8][8];
int main() {
	cin >> H >> W;
	int cnt = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> a[i][j];
			if (a[i][j] == '#') cnt++;
		}
	}
	if (H + W - 1 == cnt) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define inf 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    #define gcd __gcd
    using namespace std;
    int power(int x, unsigned int y, unsigned int m) 
    { 
        if (y == 0) 
            return 1; 
        int p = power(x, y/2, m) % m; 
        p = (p * p) % m; 
  
        return (y%2 == 0)? p : (x * p) % m; 
    } 
    int modInverse(int a, int m) 
    {   
        return power(a, m-2, m);
    }
    int nCrModPFermat(int n, int r, int p) 
    { 
           if (r==0) 
              return 1; 
  
        int fac[n+1]; 
        fac[0] = 1; 
        for (int i=1 ; i<=n; i++) 
            fac[i] = fac[i-1]*i%p; 
  
        return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
    } 
    signed main()
    {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        ll t=1;
        // cin >> t;
        /*SAARE INPUTS LENA*/
        /*VARIABLES KI RANGE DEKHLENA*/
        /*EXPONENT RANGE OF OUTPUT KA DHYAN RAKHNA*/
        while(t-->0)
        {
            ll a,b,c,d;
            cin>>a>>b>>c>>d;
            if(a>b)
                swap(a,b);
            if(c>d)
                swap(c,d);
            ll ans;
            ans=max(b*d,max(a*c,max(a*d,b*c)));
            cout<<ans;

        }
        return 0;
    }

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	for (int i = 0; i < (s.size() + 1) / 2; i++)
	{
		if (s[i] != s[s.size() - 1 - i])
		{
			cout << "No";
			break;
		}
		if (i == (s.size() + 1) / 2 - 1)
		{
			cout << "Yes";
		}

	}
	cout << endl;
}

Measured memory_bytes: 256
n, k  = map(int, input().split())
H = list(map(int, input().split()))

memo = [10**9 for _ in range(n)]
memo[0] = 0
for i in range(1, n):
  for j in range(1, k+1):
    if i - j >= 0:
      memo[i] = min(memo[i], memo[i-j] + abs(H[i] - H[i-j]))
print(memo[-1])

Measured memory_bytes: 90004
using System;

namespace ALDS1_3
{
    class Stack
    {
        static int top;

        static int MAX;

        static int[] S;

        static void Main(string[] args)
        {
            MAX = 100000;
            S = new int[MAX];
            string[] input = new string[100000];
            input = Program.getsplit();
            int k = 0;

            foreach (string str in input)
            {
                switch (input[k])
                {
                    case "+":
                        {
                            int a = pop();
                            int b = pop();
                            push(a + b);

                            break;
                        }
                    case "-":
                        {
                            int a = pop();
                            int b = pop();
                            push(b - a);
                            break;
                        }
                    case "*":
                        {
                            int a = pop();
                            int b = pop();
                            push(a * b);
                            break;
                        }
                    default:
                        {
                            push(int.Parse(input[k]));
                            break;
                        }
                        
                }
                k++;
            }
            Console.WriteLine(pop());





        }

        static void intialize()
        {
            top = 0;
        }

        static bool isEmpty()
        {
            return top == 0;
        }

        static bool isFull()
        {
            return top >= MAX - 1;
        }

        static void push(int x)
        {
            if (isFull())
            {
                Console.WriteLine("??????????????????????????¨??????push???????????????");
            }
            top++;
            S[top] = x;
        }

        static int pop()
        {
            if (isEmpty())
            {
                Console.WriteLine("???????????????????????????pop???????????????");
            }
            top--;
            return S[top + 1];

        }
    }
    class Program
    {
        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint()
        {
            int x = int.Parse(Console.ReadLine());
            return x;
        }
    }
}

Measured memory_bytes: 10340
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  if(N%2==0){
    cout << N << "\n";
  }else{
    cout << (2*N) << "\n";
  }

  return 0;
}


Measured memory_bytes: 764
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random
def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return list(input())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
s = input().split("/")
if int(s[0]) > 2019:
    print("TBD")
elif int(s[0]) == 2019:
    if int(s[1]) > 4:
        print("TBD")
    elif int(s[1]) == 4:
        if int(s[2]) > 30:
            print("TBD")
        else:
            print("Heisei")
    else:
        print("Heisei")
else:
    print("Heisei")
#B

Measured memory_bytes: 39152
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5+5, LG = 17, MOD = 1e9+7;
const int SQ = 320;
const long double EPS = 1e-7;

int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  int n;
  cin>>n;
  vector<int>a(n);
  vector<ll>ans(n);
  f(i,0,n){
    cin>>a[i];
    ans[0]+=a[i]*((i&1)?-1:1);
  }

  f(i,1,n)
  ans[i]=2*a[i-1]-ans[i-1];
  f(i,0,n)
  cout<<ans[i]<<" ";


  return 0;
}


Measured memory_bytes: 2432
// author : Kartikey Tewari
// date: 2020-02-13   23:12:16
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
using namespace std;

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

    int h,n;
    cin >> h >> n;
    int count=0;
    for (int i=0;i<=n-1;i++)
    {
        int a;
        cin >> a;
        count=count+a;
    }   

    if (h<=count)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    intl a[n];
    cin(i,a);
    intl cnt = 0;
    ld all = 0;
    rep(i,n){
        all += a[i];
    }
    ld b = all / (4.0 * m);
    rep(i,n){
        if(a[i] >= b)cnt++;
    }
    fp(cnt >= m);
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3


def main():
    mod = 10000007                  # 10^9+7
    inf = float('inf')
    input = sys.stdin.readline      # 改行文字が残ることに注意
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def ii():  return int(input())
    def mi():  return map(int, input().rstrip().split())
    def lmi(): return list(map(int, input().rstrip().split()))
    def li():  return list(input().rstrip())
    
    
    n = ii()
    a = lmi()
    print(1 / sum(list(map(lambda x: 1/x, a))))

if __name__ == "__main__":
    main()

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
int a[N];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i ++ ) cin >> a[i];
	
	int res = 0;
	for (int l = 0; l <= min(n, m); l ++ )
		for (int r = 0; r <= min(n - l, m - l); r ++ )
		{
			vector<int> t;
			for (int i = 0; i < l; i ++ ) t.PB(a[i]);
			for (int i = 0, j = n - 1; i < r; i ++ , j -- ) t.PB(a[j]);
			
			int cnt = m - l - r, sum = 0;
			sort(t.begin(), t.end());	

			for (auto u : t)
				if (cnt && u < 0) cnt -- ;
				else sum += u;
				
			res = max(res, sum);
		}
	
	cout << res << endl;
	return 0;
}

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

string s, t;

int main() {
  cin >> s >> t;
  int ans = 0;
  rep (i, s.size()) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3892
N = str(input())
identify = N[-1]
answer = ''
pon_list = ['0','1', '6', '8']
bon_list = ['3']
if identify in pon_list:
  answer = 'pon'
elif identify in bon_list:
  answer = 'bon'
else:
  answer = 'hon'
print(answer)

Measured memory_bytes: 8928
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>

using namespace std;


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

	string s1, s2;
	cin >> s1 >> s2;
	int n1 = s1.length(), n2 = s2.length(), i, j, k, x, y, xx, yy;
	vector<vector<int>> dp(n1 + 1, vector<int>(n2 + 1, 0));
	vector<vector<pair<int, int>>> last(n1 + 1, vector<pair<int, int>>(n2 + 1, { -1, -1 }));
	for (i = 0; i <= n1; i++) {
		for (j = 0; j <= n2; j++) {
			if ((i < n1) && (dp[i][j] > dp[i + 1][j])) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				last[i + 1][j] = { i, j };
			}
			if ((j < n2) && (dp[i][j] > dp[i][j + 1])) {
				dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
				last[i][j + 1] = { i, j };
			}

			if ((i < n1) && (j < n2) && (s1[i] == s2[j]) && (dp[i][j] + 1 > dp[i + 1][j + 1])) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
				last[i + 1][j + 1] = { i, j };
			}
		}
	}

	string ans = "";
	x = n1; y = n2;
	while (last[x][y].first >= 0) {
		xx = last[x][y].first;
		yy = last[x][y].second;

		if ((xx < x) && (yy < y)) ans = s1[xx] + ans;
		x = xx; y = yy;
	}

	cout << ans << "\n";

	return 0;
}




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

#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
	double W,H,x,y;
	
	cin >> W >> H >> x >> y;
	
	printf("%lf ",W*H/2);
	
	if(x==W/2 && y==H/2)	cout << "1" << endl;
	else	cout << "0" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int &i:A)
    cin>>i;
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int ans=A[0];
  if(N%2==0)
    for(int i=1;i<N/2;i++)
      ans+=A[i]*2;
  else{
    for(int i=1;i<N/2;i++)
      ans+=A[i]*2;
    ans+=A[N/2];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4836
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int a = scan.nextInt();
	    int b = scan.nextInt();
	    scan.close();
	    int sum=0;
	    for(int i=1;i<=999;i++) {
	    	sum+=i;
	    	if(i == (b-a) ) {
	    		System.out.println(sum-b);
	    		break;
	    	}
	    }

	}

}

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

typedef long long lint;

lint Plus[200010],ans=0;
int Xor[200010],n,a[200010];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n;i++){
		Xor[i+1]=Xor[i]^a[i];
		Plus[i+1]=Plus[i]+a[i];
	}
	for(int start=0;start<n;start++){
		int low=start,high=n-1;
		while(low<high){
			int mid=low+(high-low+1)/2;
			lint sum1=Xor[mid+1]^Xor[start];
			int sum2=Plus[mid+1]-Plus[start];
			if(sum1==sum2) low=mid;
			else high=mid-1;
		}
		ans+=low-start+1;
	}
	printf("%lld",ans);
	return 0;
	
}

Measured memory_bytes: 3328
#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 MMOD 998244353
#define MAX 2010101
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<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
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 d[303][303];
bool d_n[303][303];

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

  long long ans = 0;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      cin >> d[i][j];
    }
  }
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){

        if(d[i][j] > d[i][k] + d[k][j]){
          cout << "-1" << endl;
          return 0;
        }

        if(d[i][j] == d[i][k] + d[k][j] && d[i][k] > 0 && d[k][j] > 0){
          d_n[i][j] = true;
        }

      }
    }
  }

  for(int i=0; i<n; i++){
    for(int j=0; j<=i; j++){

      if(d_n[i][j] == false){
        ans += d[i][j];
      }

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

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()


int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> C(N-1), S(N-1), F(N-1);
	REP(i, N-1) cin >> C[i] >> S[i] >> F[i];

	REP(i, N)
	{
		ll t{0};
		FOR(j,i,N-1)
		{
			if (t <= S[j]) t = S[j];
			else if (t%F[j]!=0)
				t += F[j] - t%F[j];
			t += C[j];
		}
		std::cout << t << std::endl;
	}
}


Measured memory_bytes: 256
def solve(n, x):
    """
    a + b + c = x
    となる a, b, cを求める。
    重複を無くして考えるため、
    a < b < cとする。
    1 <= a < b <= n
    を満たすような2重ループを作る。
    a,bを固定すれば、cを出せるので、
    a<b<cを満たすとき、ans += 1
    """
    ans = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            c = x - a - b
            if b < c <= n:
                ans += 1

    print(ans)
    return


def main():
    while True:
        n, x = list(map(int, input().split()))
        if n == x == 0:
            break
        else:
            solve(n, x)
    return


if __name__ == "__main__":
    main()



Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int a[n];
    int s = 0;
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a+n, greater<int>());
    for(int i = 0; i < n; ++i) 
    {
        if(i & 1) s -= a[i];
        else s += a[i];
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
long long p[5005], c[5005], f[5005];
int main() {
    long long n, k, ans = 0;
    cin >> n >> k;
    for(long long i = 1; i <= n; i++)
        cin >> p[i];
    for(long long i = 1; i <= n; i++)
        cin >> c[i];
    for(long long i = 1; i <= n; i++) {
        long long tmp = p[i], xhj = 1;
        f[1] = c[i];
        while(tmp != i)
            xhj++, f[xhj] = f[xhj - 1] + c[tmp], tmp = p[tmp];
        if(xhj >= k)
            for(long long j = 1; j <= k; j++)
                ans = max(ans, f[j]);
        else if(f[xhj] <= 0)
            for(long long j = 1; j <= xhj; j++)
                ans = max(ans, f[j]);
        else{
            long long mod = k % xhj, tmp = k / xhj;
            for(long long j = 0; j <= mod; j++)
                ans = max(ans, tmp * f[xhj] + f[j]);
            for(long long j = 1; j <= xhj; j++)
                ans = max(ans, (tmp - 1) * f[xhj] + f[j]);
        }
    }
    if(ans <= 0) {
        ans = c[1];
        for(long long i = 2; i <= n; i++)
            ans = max(ans, c[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x;
	cin>>x;
	long long A,B;
	for(long long a=120;a>=0;a--)
	{
		A=a*a*a*a*a;
		for(long long b=a-1;b>=-120;b--)
		{
			B=b*b*b*b*b;
		//	if(b<=0&&a*a*a*a*a>x)break;
		//	if(-(b*b*b*b*b)>x)break;
			if(A-B==x)
			{
				cout<<a<<" "<<b<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3580
/*
f[i][p]前i个物品恰好价值为p时最少要载重多少
初始化f[i][p]=INF
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=109;
const ll MAXV=100009;
const ll INF=1e16;
ll n,W,w[N],v[N],f[N][MAXV];
int main() {
//	freopen(" .in","r",stdin);
//	freopen(" .out","w",stdout);
	cin>>n>>W;
	for(ll i=1;i<=n;++i)cin>>w[i]>>v[i];
	ll V=n*1000;
	for(ll p=1;p<=V;++p)f[0][p]=INF;
	f[0][0]=0;
	for(ll i=1;i<=n;++i)
		for(ll p=0;p<=V;++p)
			if(v[i]>p)f[i][p]=f[i-1][p];
			else f[i][p]=min(f[i-1][p],f[i-1][p-v[i]]+w[i]); 
	for(int p=V;p>=0;--p)
		if(f[n][p]<=W){
			cout<<p<<endl;
			break;
		}
  	return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
bool is_prime(lli x) {
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main() {
  lli A,B,C=0,D=0,E=0,F=0,G=0,H=0,N,M;
  string S;
  cin >> S;
  rep(i,0,4)if(S[i]=='2')C++;
  Out(C);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,z,a;
	cin>>x>>y>>z;
	a=x;
	x=y;
	y=a;
	a=x;
	x=z;
	z=a;
	cout<<x<<' '<<y<<' '<<z;
	return 0;
 } 

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

using namespace std;

int n,rj;
int mat[100005][3];
int sol[100005][3];
int main () {
	
	cin >>n;
	for(int i=0;i<n;i++)
		cin >>mat[i][0]>>mat[i][1]>>mat[i][2];
	sol[0][0] = mat[0][0];
	sol[0][1] = mat[0][1];
	sol[0][2] = mat[0][2];
	for(int i=1;i<n;i++) {
		sol[i][0] = max(sol[i-1][1], sol[i-1][2]) + mat[i][0];
		sol[i][1] = max(sol[i-1][0], sol[i-1][2]) + mat[i][1];
		sol[i][2] = max(sol[i-1][0], sol[i-1][1]) + mat[i][2];
	}
	
	rj = max(sol[n-1][0], max(sol[n-1][1], sol[n-1][2]));
	cout <<rj;
	
	return 0;
}

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

using namespace std;

int n;

int ask(int id) {
	static char s[42];
	printf("%d\n", id % n);
	fflush(stdout);
	scanf("%s", s);
	if (s[0] == 'M') return 0;
	if (s[0] == 'F') return 1;
	return 2;
}

int main() {
	ignore = scanf("%d", &n);
	int x = ask(0);
	if (x == 2) return 0;
	
	int l = 0, r = n, lx = x, rx = x;
	while (true) {
		int c = (l + r) / 2;
		int y = ask(c);
		
		if (y == 2) break;
		
		if ((c % 2 == l % 2) != (lx == y)) {
			r = c;
			rx = y;
		}
		else {
			l = c;
			lx = y;
		}
	}
	
	return 0;
}


Measured memory_bytes: 852
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int nC2(int n) {
	return n * (n - 1) / 2;
}

vector<pair<int, int>> pairs;
signed main() {
	int N, K;
	cin >> N >> K;
	int last = N % K;
	int packetNum = N / K;
	//1-lastがいっこおおい
	//for (int i = 1; i <= K; i++) {
		//if (i > K - i) break;
		//pairs.push_back(make_pair(i, K - i));
	//}
	int ans = -1;
	if (K % 2 == 0) {
		int halfnum = packetNum;
		if (last >= K / 2) halfnum++;
		ans = packetNum * packetNum*packetNum + halfnum*halfnum*halfnum;
	}
	else {
		//if (last >= K / 2) packetNum++;
		ans = packetNum * packetNum*packetNum;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n1,n2) for(int i=n1;i<n2;i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int res = 0;
    if(n%2==0)res=n;
    else res=n*2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define let const auto
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'

int main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   int a, b, k;

   cin >> a >> b >> k;
   set<int> S;

   for (int i=a; i< a+k && i<=b; ++i)S.insert(i);
   for (int i=b; i> b-k && i>=a; --i)S.insert(i);

   for(int n: S){
      outl(n);
   }
}



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

 
int main() {
   int n;
   cin>>n;
   double bo=0;
   rep(i,n){
       double a;
       cin>>a;
       bo+=1/a;
   }
   cout<<fixed<<setprecision(10)<<1/bo<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>

using namespace std;

int dice[6] = { 1,2,3,4,5,6 }; // 0->5 1 -> 4 2 -> 3  x,5-x
// 1(2,3,4,5) 2(1,3,4,6) 3(1,2,5,6) 4(1,2,5,6) 5(1,3,4,6) 6(2,3,4,5) max는 11
// 1~6 1번 7~11 2번 12~17 3번 18~22 4번  
int main(void)
{
	long long int x;
	long long int res;
	long long int a, b;
	cin >> x;

	a = (x / 11);
	b = (x % 11);
	if (b == 0)
	{
		res = 2 * a;
	}
	else if (b <= 6)
	{
		res = 2*a + 1;
	}
	else
	{
		res = 2*a + 2;
	}

	cout << res << endl;

	return 0;
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            int N = int.Parse(line);
            line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int[] L = new int[N];
            for(int i = 0; i < N; i++)
            {
                L[i] = int.Parse(strs[i]);
            }
            int count = 0;
            for(int i = 0; i < N - 2; i++)
            {
                for(int j = i + 1; j < N - 1; j++)
                {
                    for(int k = j + 1; k < N; k++)
                    {
                        if (L[i] == L[j]
                            || L[i] == L[k]
                            || L[k] == L[j]) continue;
                        if (L[i] + L[j] > L[k]
                            && L[j] + L[k] > L[i]
                            && L[i] + L[k] > L[j])
                        {
                            count++;
                        }
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27504