akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
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; }

struct xydata {
    int x; int y;
};

int main() {
    int n; cin >> n;
    vector< vector<xydata> > axy(n, vector<xydata>());
    vector<int> A(n, 0);
    for(int i = 0; i < n; ++i) {
        int aa; cin >> aa;
        A.at(i) = aa;
        for(int j = 0; j < aa; ++j) {
            int xx, yy; cin >> xx >> yy;
            xx--;
            xydata indata; indata.x = xx; indata.y = yy;
            axy.at(i).emplace_back(indata);
        }
    }

    int ans = 0;
    for(int bit = 0; bit < (1<<n); ++bit) {
        // 正直者の数
        int cnt = 0;
        vector<bool> honest(n, false);
        for(int i = 0; i < n; ++i) {
            if(bit&(1<<i)) {
                honest.at(i) = true; cnt++;
            }
        }
        bool flg = true;
        for(int i = 0; i < n; ++i) {
            if(honest.at(i)) {
                for(int j = 0; j < A.at(i); ++j) {
                    if(axy.at(i).at(j).y == 1) {
                        if(!honest.at(axy.at(i).at(j).x)) {
                            flg = false;
                            break;
                        }
                    }else {
                        if(honest.at(axy.at(i).at(j).x)) {
                            flg = false;
                            break;
                        }
                    }
                }
                if(!flg) break;
            }
        }
        if(flg) chmax(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define MAX 100001

typedef struct{
    char mark;
    int num;
    int sta;
} card;

int partition(card *A, int p, int r){
    int x, i, j;
    card tmp1, tmp2;

    x = A[r].num;
    i = p-1;

    for(j=p; j<=r-1; j++){
        if(A[j].num <= x){
            i = i+1;
            tmp1 = A[i];
            A[i] = A[j];
            A[j] = tmp1;
        }
    }

    tmp2 = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp2;

    return i+1;
}

void quicksort(card *A, int p, int r){
    int q;

    if(p < r){
        q = partition(A, p, r);
        quicksort(A, p, q-1);
        quicksort(A, q+1, r);
    }
}


int main(){
    int n, i, flag = 0;
    card A[MAX];

    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf(" %c%d", &A[i].mark, &A[i].num);
        A[i].sta = i;
    }

    quicksort(A, 0, n-1);

    for(i=0; i<n; i++){
        if(A[i].num == A[i+1].num){
            if(A[i].sta > A[i+1].sta){
                flag = 1;
            }
        }
    }

    if(flag == 0){
        printf("Stable\n");
    }else{ 
        printf("Not stable\n");
    }

    for(i=0; i<n; i++){
        printf("%c %d\n", A[i].mark, A[i].num);
    }

    return 0;
}



Measured memory_bytes: 2964
N=int(input())
S=input()

ans=S[1:].count('E')
c=S[1:].count('E')
for i in range(1,N):
    if S[i]=='E':
        c-=1
    if S[i-1]=='W':
        c+=1
    ans=min(ans,c)
print(ans) 


Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main() {
    int h, m, s;
    cin >> s;
    h = s / 3600;
    s %= 3600;
    m = s /60;
    s %= 60;
    cout << h << ":" << m << ":" << s  << endl;
    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int x=0,y=0,ans=0;
signed main()
{
    cin>>a;
    for (int i=0;i<sizeof(a);i++)
     if (x==y)
     {
         x++; 
         if(a[i]=='p') ans--;
     }    
     else
     {
         y++; 
         if(a[i]=='g') ans++;
     }         
    cout<<ans<<endl;                    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
typedef long long ll;

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

  while(b<=a){
    k--;
    b*=2;
    if(k<0) break;
  }
  while(c<=b){
    k--;
    c*=2;
    if(k<0) break;
  }

  if(k>=0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

// ランレングス圧縮(Run Length Encoding)
vector<pair<char,int>> RLE(string S){
  vector<pair<char,int>> p;
  int N = S.size();
  for (int i=0;i<N;i++) {
    if (S[i]==S[i+1]){
      int cnt = 1;
      char c = S[i];
      while (i+1<N && S[i]==S[i+1]) {
        i++;
        cnt++;
      }
      p.push_back({c,cnt});
    }
    else p.push_back({S[i],1});
  }

  return p;
}

int main(){
  ll N, K; cin >> N >> K;
  int a[N]; rep(i,N) cin >> a[i];

  int c[N]={}, d[N]={};
  rep(i,N){
    rep(j,N){
      if (j==i) continue;
      if (j>i && a[i]>a[j]) c[i]++;
      else if (j<i && a[i]>a[j]) d[i]++;
    }
  }
  ll retval = 0;
  ll MOD = 1000000007;
  rep(i,N){
    ll c1 = ((K+1)*K/2)%MOD, c2 = ((K-1)*K/2)%MOD;
    retval += c1*c[i] + c2*d[i];
    retval %= MOD;
  }
  cout << retval << endl;

  // cout << fixed << setprecision(10);
  
  return 0;
}


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	int N;
  cin >> N;
  int count = 0,sw = 0;
  froop1(0,N){
    int a,b;
    cin >> a >> b;
    if(a == b) count++;
    else count = 0;
    if(count >= 3)sw = 1;
  }
	if(sw == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  
return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

main(){
  int a, b, c, d, e, f;
  while(1){
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
    if((a|b|c|d|e|f) == 0) break;
    a += d;
    b += e;
    c += f;
    int lim = min(a, min(b, c)), ans = 0;
    for(int i=0;i<=lim&&i<3;i++) ans = max(ans, i + (a-i) / 3 + (b-i) / 3 + (c-i) / 3);
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = a; i < (b); i++)

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main () {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    int can[10];
    FOR(i, 0, 10) {
        can[i] = 0;
    }
    // int can[10][10][10];
    // FOR(i, 0, 10) {
    //     FOR(j, 0, 10) {
    //         FOR(k, 0, 10) {
    //             can[i][j][k] = 0;
    //         }
    //     }
    // }
    int t[n];
    FOR(i, 0, n) {
        t[i] = ctoi(s[i]);
    }
    // FOR(i, 0, n-2) {
    //     FOR(j, i+1, n-1) {
    //         FOR(k, j+1, n) {
    //             can[t[i]][t[j]][t[k]] = 1;
    //         }
    //     }
    // }
    int ans = 0;
    int flag = 0;
    FOR(i, 0, 10) {
        FOR(j, 0, 10) {
            FOR(k, 0, n) {
                if (flag == 0) {
                    if (t[k] == i) flag = 1;
                } else if (flag == 1) {
                    if (t[k] == j) flag = 2;
                } else {
                    can[t[k]] = 1;
                    int l;
                    for (int l = 0; l < 10; l++) {
                        if (can[l] == 0) break;
                    }
                    if(l == 10) break;
                }
            }
            FOR(l, 0, 10) {
                if (can[l] == 1) ans++;
                can[l] = 0;
            }
            flag = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

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

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

  int range = 2*D+1;

  if(N%range!=0)
    cout << N/range+1 << endl;
  else
    cout << N/range << endl;








  


  return 0;
}


//cout << setprecision(13);
//next_permutation(v.begin(), v.end());



Measured memory_bytes: 256
i = input()
list = i.split()
[W, H, x, y, r] = list

W = int(W)
H = int(H)
x = int(x)
y = int(y)
r = int(r)

X = x + r
Y = y + r

A = x - r
B = y - r

if A < 0 or B < 0:
    ans = "No"
elif W >= X and H >= Y:
    ans = "Yes"
else:
    ans = "No"

print(ans)


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

long long dp[50000005][2];

int cost[3][2];

// max profit with x acorns left
/*long long dp(int x, int mode){
    if(x == 0){
        return 0;
    }else if(memo[x][mode] != -1){
        return memo[x][mode];
    }else{
        long long ans = 0;
        for(int i = 0; i < 3; i ++){
            long long diff = cost[i][mode^1] - cost[i][mode];
            if(diff > 0 && x >= cost[i][mode]){
                ans = max(ans, diff + dp(x-cost[i][mode], mode));
            }
        }

        return memo[x][mode] = ans;
    }
}*/

int main(){
    int N;
    scanf("%d", &N);

    for(int j = 0; j < 2; j ++){
        for(int i = 0; i < 3; i ++){
            scanf("%d", &cost[i][j]);
        }
    }

    dp[0][0] = 0;
    dp[0][1] = 0;
    for(int x = 1; x <= N*5000; x ++){
        for(int mode = 0; mode < 2; mode ++){
            long long ans = 0;
            for(int i = 0; i < 3; i ++){
                long long diff = cost[i][mode^1] - cost[i][mode];
                if(diff > 0 && x >= cost[i][mode]){
                    ans = max(ans, diff + dp[x-cost[i][mode]][mode]);
                }
            }

            dp[x][mode] = ans;
        }
    }

    long long temp = N+dp[N][0];
    //printf("debug: %lld\n", temp);

    long long ans = temp+dp[temp][1];
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 391424
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var n = parseInt(input[0][0], 10);
    var line;
    arr_distance = Array.from({length: n}, () => [0, -1]);
    arr_v = [];
    for (var i = 0; i < n; i++){
        line = input[i + 1].map(e => parseInt(e, 10));
        arr_v.push([]);
        for (var j = 2; j < line.length; j++){
            arr_v[i].push(line[j]);
        }
        arr_distance[i][0] = i + 1;
    }
    distance = 0;
    currentLayer = [1];
    nextLayer = [];
    finished = BFS(currentLayer);

    for (var x of arr_distance){
        console.log(x.join(" "))
    }
}

function BFS(currentLayer){
    while (true){
        for (let x of currentLayer){
            arr_distance[x - 1][1] = distance;
        }
        for (let x of currentLayer){
            for (var y of arr_v[x - 1]){
                if (arr_distance[y - 1][1] === -1) nextLayer.push(y);
            }
        }
        if (nextLayer.length === 0) return true;
        currentLayer = nextLayer.slice();
        nextLayer = [];
        distance ++;
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main()
{
    int i,ans = 0;
    vector<int> x(3);
    for(i = 0;i < 3;++i){
        cin >> x.at(i);
    }
    sort(x.begin(),x.end());
    if((x.at(2) - x.at(1))%2 == 0 && (x.at(1)-x.at(0))%2 == 0){
        ans += (2*x.at(2)-x.at(1)-x.at(0))/2;
    }else if((x.at(2) - x.at(1))%2 == 1 && (x.at(1)-x.at(0))%2 == 0){
        ans += (x.at(2)-x.at(1))/2 + (x.at(2)-x.at(0))/2+1;
    }else if((x.at(2) - x.at(1))%2 == 0 && (x.at(1)-x.at(0))%2 == 1){
        ans += (2*x.at(2)-x.at(1)-x.at(0))/2+2;
    }else{
        ans += (2*x.at(2)-x.at(1)-x.at(0))/2+2;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;

/*-------------------------------*/

int main(void)
{
  int n;
  int m, x;

  while (true){
    cin >> n;
    x = 0;
    if (n == 0) break;
    rep(i, 9){
      cin >> m;
      x += m;
    }
    cout << n - x << endl;
  }
  return 0;
}

Measured memory_bytes: 3072
N,T=map(int,input().split())
t=list(map(int,input().split()))

ans=0
time=[]
time.append([t[0],t[0]+T])
for i in range(1,N):
    if time[-1][0]<t[i] and t[i]<=time[-1][1]:
        time[-1]=[time[-1][0],t[i]+T]
    else:
        ans+=time[-1][1]-time[-1][0]
        time.append([t[i],t[i]+T])

ans+=time[-1][1]-time[-1][0]
print(ans)

Measured memory_bytes: 25708
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) {return b?gcd(b, a%b):a;}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
inline constexpr int modpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
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 ll LINF=0x1fffffffffffffff;

struct unionfind{
    vector<ll> d;
    unionfind(ll x):d(x,-1){}
    ll root(ll x) {return d[x]<0?x:d[x]=root(d[x]);}
    ll size(ll x) {return -d[root(x)];};
    bool unite(ll x,ll y) {x=root(x),y=root(y); if(x!=y){if(d[x]>d[y])swap(x,y);d[x]+=d[y];d[y]=x;}return x!=y;}
    bool find(ll x,ll y) {return root(x)==root(y);}
};
int main(){
    ll n,m;
    cin>>n>>m;
    unionfind uf(n);
    ll ans=n;
    rep(i,0,m){
        ll x,y,z;
        cin>>x>>y>>z;
        ans-=uf.unite(x-1,y-1);
    }
    cout<<ans;
}


Measured memory_bytes: 1024
n = int(input())
s = list(input())
t = 0
a = 'No'

if n % 2 == 0:
  t = int(n / 2)
  for i in range(t):
    if s[i] == s[t+i]:
      pass
    else:
      a = 'No'
      break
    a = 'Yes'

print(a)

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

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,k;
  cin >> n >> k;
  vector<vl> edge(n,vl(0));
  REP(i,n-1){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  //REP(i,n){
  //  cout << i << ": ";
  //  REP(j,edge[i].size()){
  //    cout << edge[i][j] << ",";
  //  }
  //  cout << endl;
  //}
  ll ans = k;
  ll MOD = 1e9+7;
  queue<pll> que;
  que.push(make_pair(0,0));
  while(!que.empty()){
    pll node = que.front();
    //cout << "first:" << node.first << ", second:" << node.second << endl;
    que.pop();
    // except parent
    if(node.first==0){
      REP(i,edge[node.first].size()){
        ans *= k - (i+1);
        ans %= MOD;
      }
    }else{
      REP(i,edge[node.first].size()-1){
        ans *= k - (i+2);
        ans %= MOD;
      }
    }
    //DEBUG(ans);
    REP(i,edge[node.first].size()){
      if(edge[node.first][i]!=node.second) 
        que.push(make_pair(edge[node.first][i],node.first));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8180
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, wa = 0, s1 = 0, s2 = 0, ans = 100000;
    cin >> n;
    vector<int> w(n);
    for(int i = 0; i < n; i++) {
        cin >> w[i];
        wa += w[i];
    }

    REP(i, n)
    {
        s1 += w[i];
        s2 = wa - s1;
        ans = min(ans, abs(s1 - s2));
    }

    cout << ans << endl;    
}

Measured memory_bytes: 256
import math

A,B = list(map(int, input().rstrip().split()))

#x=A/0.08
#y=B/0.10

ans=9999
#max_y=( int(y) + 10 )%100
for i in range(1,1251):
  v_08 = math.floor(i * 0.08)
  v_10 = math.floor(i * 0.1)
  
  if v_08==A and v_10==B:
    ans=min(ans,i)

print(ans if ans != 9999 else -1)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    P=LI()
    m=P[0]
    cnt=1
    for i in range(1,N):
        if P[i]<m:
            cnt+=1
            m=P[i]
            
    print(cnt)

main()


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

int countfactor(int n){
    if(n<1) return 0;
    if(n==1) return 1;
    int count = 2;
    for (long long i = 2; i < n;++i){
        if(n%i)continue;
        count++;
    }
    return count;
}

int main() {
    //input
    int n;
    cin >> n;
    int count=0;

    for(int i=1;i<=n;i+=2){
        if(countfactor(i) == 8){
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <utility> // pair make_pair
#include <algorithm>

using namespace std;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<string> field;


/* if bfs

   queue<pair<int, int> > que
   que.push(make_pair(start x, start y));

   int dist[x][y];
   memset(dist, -1, sizeof(dist));
   dist[start x][start y] = 0;
*/


// int N; cin >> N;
// field.resize(N);

int main() {
  int H, W; cin >> H >> W;
  field.resize(H);
  
  for (int i = 0; i < H; i++) {
    cin >> field[i];
  }

  int dist[H][W];
  memset(dist, -1, sizeof(dist));
  dist[0][0] = 0;

  queue<pair<int, int> > que;
  que.push(make_pair(0, 0));

  while(!que.empty()) {
    
    pair<int, int> v = que.front(); que.pop();

    for (int i = 0; i < 4; i++) {
      
      int nx = v.first + dx[i];
      int ny = v.second + dy[i];

      // 場外要素２つ
      // この順番大事かも
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (field[nx][ny] == '#') continue;

      // すでに訪れていたら変更しちゃダメ
      if (dist[nx][ny] != -1) continue;

      dist[nx][ny] = dist[v.first][v.second] + 1;
      que.push(make_pair(nx, ny));
    }
  }
  int cnt = 0;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '#') cnt++;
    }
  }

  if (dist[H-1][W-1] == -1) cout << -1 << endl;
  else cout << H*W - (dist[H-1][W-1] + 1) - cnt << endl;

  return 0;
}


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

int main() {
  int n,x,t;
  cin>>n>>x>>t;
  int a;
  if(n%x==0){
    a=n/x;
  }
  else{
    a=n/x +1;
  }
  cout<<a*t<<endl;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	map<int, int> mp;
	for( int i = 0; i < N; i++ ) {
		mp[ A[i] ]++;
	}
	long long all = 0;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		long long n = it->second;
		all += n * (n - 1) / 2;
	}

	for( int i = 0; i < N; i++ ) {
		long long ans = all;
		long long n = mp[ A[i] ];
		ans -= n * (n - 1) / 2;
		n--;
		ans += n * (n - 1) / 2;
		cout << ans << endl;
	}
}


Measured memory_bytes: 10052
from sys import stdin
import numpy as np

s = input()
a = [c for c in s]

lst = []
for i in range(len(a)-2):
  var = int(a[i]+a[i+1]+a[i+2])
  lst.append(var)  
    
ans = 1000
for i in range(len(lst)):
  ans = min(ans, abs(lst[i]-753))
    
print(ans)   

Measured memory_bytes: 12500
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 2000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int n;
vector<long long> a;
long long memo[1000000] = {};
long long calc_wa(long long l, long long r) {
	return memo[r] - memo[l - 1];
}
long long solve(long long border) {
	for (int i = 0;i < n;++i) {
		int now_itr = i;
		for (int q = 0;q < 3 && memo[now_itr] != LONG_INF;++q) {
			int bot = now_itr;
			int top = a.size();
			while (top - bot > 1) {
				int mid = (top + bot) / 2;
				if (calc_wa(now_itr, mid) >= border) {
					top = mid;
				}
				else bot = mid;
			}
			if (calc_wa(now_itr, bot) >= border) {
				now_itr = bot + 1;
			}
			else if (calc_wa(now_itr, top) >= border) {
				now_itr = top + 1;
			}
			else {
				now_itr = a.size();
				break;
			}
		}
		if (now_itr - i <= n) return true;
	}
	return false;
}
int main() {
	cin >> n;
	REP(i, n) {
		long long tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	REP(i, n) {
		long long tmp = a[i];
		a.push_back(tmp);
	}
	REP(i, n) {
		long long tmp = a[i];
		a.push_back(tmp);
	}
	REP(i, n) {
		long long tmp = a[i];
		a.push_back(tmp);
	}
	memo[0] = a[0];
	for (int i = 1;i < a.size();++i) {
		memo[i] = memo[i - 1] + a[i];
	}
	memo[a.size()] = LONG_INF;
	memo[a.size() + 1] = LONG_INF;
	memo[a.size() + 2] = LONG_INF;
	long long bot = 0;
	long long top = LONG_INF;
	while (top - bot > 1) {
		long long mid = (top + bot) / 2;
		if (solve(mid) == true) {
			bot = mid;
		}
		else top = mid;
	}
	if (solve(top)) {
		cout << top << endl;
	}
	else cout << bot << endl;
	return 0;
}


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

int main() {
	int d,a;
	a = 0;
	while(cin >> d){
		for(int i = 0;i!=600;i+=d){
			a += i*i*d;

		}
		cout << a << endl;
		a = 0;
	}

	


	return 0;
}




Measured memory_bytes: 3072
N = int(input())
a = {}
b = set()

for i in range(N):
    S, P = input().split()

    if not S in a:
        a[S] = []

    a[S].append((int(P), i+1))
    b.add(S)
b = list(b)
b.sort()

for v in a.values(): v.sort(reverse=True)

for s in b:
    for _, i in a[s]:
        print(i)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        String ans = "";
        while(num != 0) {
            if(num % 2 != 0) {
                ans = "1" + ans;
                num--;
            } else {
                ans = "0" + ans;
            }
            num /= (-2);
        }
        if(ans.length() == 0) ans = "0";
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
L, R = map(int, input().split())
a=[]

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

Measured memory_bytes: 9096
#include<stdio.h>
int main(){
	int t,ans,c1,c2,c3,c4;
	while(~scanf("%d",&t)){
		ans=0;
		for(c1=0;c1<10;c1++){
			for(c2=0;c2<10;c2++){
				for(c3=0;c3<10;c3++){
					for(c4=0;c4<10;c4++){
						if(c1+c2+c3+c4==t)ans++;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  char a;
  cin >> a;
  if(isupper(a)) cout << "A" << endl;
  else cout << "a" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    double M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A.at(i);
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    int sum=0;
    for(int i=0;i<N;i++){
        sum+=A.at(i);
    }
    if(A.at(M-1)<sum/(4*M)) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a=0,b=0,mi=1000000;
	string s;
	cin>>n>>s;;
	vector<pair<int,int>>v(n);
	for(int i=0;i<n;i++){
		if(s[i]=='W'){
			a++;
		}else {
			b++;
		}
		v.at(i).first=a;
		v.at(i).second=b;
	}
	for(int i=0;i<n-1;i++){
		if(i==0){
			if(v.at(0).second==1){
				mi=b-1;
			}else if(v.at(0).second==0){
				mi=b;
			}
		}else{
			mi=min(v.at(i-1).first+b-v.at(i).second,mi);
		}
	}
	if(s.substr(n-1,1)=="W")a--;
	mi=min(a,mi);
	cout<<mi<<endl;
	return 0;
}


Measured memory_bytes: 2964
#include<iostream>
#include<stdio.h>
#include <ctype.h>
using namespace std;

int main()
{
	char c;
	char alpha_count[26]={0};

	int n=0;
    
    while (cin >> c) {
		if(isalpha(c)){
			c = tolower(c);
		}
	    alpha_count[c-'a']++;
	}
	for(int i=0; i<26; i++) {
		printf("%c : %d\n", i+'a', alpha_count[i]);
	}
	return 0;
}

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

#define mod 1000000007

// F_mod 上でのべき乗, 蟻本p115
ll modPow(ll x, ll n) {
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

#define MAX_a 1050000

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

    // 累積XORと累積0の個数
    vector<int>cuXOR(N);
    vector<int>zero(N, 0);
    cuXOR[0] = a[0];
    if(a[0] == 0) zero[0]++;
    for (int i = 1; i < N; ++i) {
        zero[i] = zero[i-1];
        cuXOR[i] = cuXOR[i-1] ^ a[i];
        if(cuXOR[i] == 0) zero[i]++;
    }

    // 美しさbで現在の区間より前のxorが0ならdp[b][0], bならdp[b][1]が場合の数
    ll dp[MAX_a][2] = {};
    for (int i = 0; i < MAX_a; ++i) {
        dp[i][0] = 1;
    }
    ll prev[MAX_a] = {};
    for (int i = 0; i < N; ++i) {
        int cur = cuXOR[i];
        if(cur != 0){
            dp[cur][0] += dp[cur][1] * (zero[i] - zero[prev[cur]]);
            dp[cur][0] %= mod;
            dp[cur][1] += dp[cur][0];
            dp[cur][1] %= mod;
            prev[cur] = i;
        }
    }

    ll ans = 0;
    if(cuXOR[N-1] == 0){
        ans += modPow(2, zero[N-1]-1);
        for (int i = 1; i < MAX_a; ++i) {
            ans += dp[i][1];
            ans %= mod;
        }
    } else{
        ans += dp[cuXOR[N-1]][0];
        ans %= mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 30720
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    
    int n;
    string s;
    cin >> n >> s;
    
    int l = 0,r = 0,t = 0;
    
    for(int i = 0; i < n; i++){
        if(s[i] == ')'){
            if(t >= 1){
                t--;
            }else{
                l++;
            }
        }else{
            t++;
        }
    }
    
    t = 0;
    
    for(int i = n-1; i >= 0; i--){
        if(s[i] == '('){
            if(t >= 1){
                t--;
            }else{
                r++;
            }
        }else{
            t++;
        }
    }
    
    for(int i = 0; i < l; i++)
        cout << '(';
    cout << s;
    for(int i = 0; i < r; i++)
        cout << ')';
    cout << endl;
    
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    char c;
    cin >> c;
    cout << char(c + 1) << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
count = []
tempcount = 0
for i in range(N-1):
  temp = H[i]
  if H[i] >= H[i+1]:
    tempcount +=1
  else :
    count += [tempcount]
    tempcount = 0
count += [tempcount]
print(max(count))

Measured memory_bytes: 14224
from math import gcd
def main():
    K=int(input())
    ans=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            p=gcd(a,b)
            if p==1:
                ans+=p*K
            else:
                for c in range(1,K+1):
                    ans+=gcd(p,c)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

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

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

    int n;
    cin >> n;

    int dsum[112345];

    int n_ = n;
    int tmp = 0;
    while (n_ >= 1)
        tmp += n_ % 10, n_ /= 10;

    fill(dsum, dsum + n + 1, INT_MAX);
    //dsum[0] = tmp;

    priority_queue<P, vector<P>, greater<P>> q;

    // q.push(make_pair(dsum[0], 0));

    for (int i = 1; i <= 9; i++)
    {
        dsum[i % n] = min(dsum[i % n], i);
        q.push(make_pair(dsum[i % n], i % n));
    }

    while (q.size())
    {
        P p = q.top();
        q.pop();

        if (p.first > dsum[p.second])
            continue;

        for (int i = 0; i <= 9; i++)
        {
            int ne = (p.second * 10 + i) % n;
            if (dsum[ne] > p.first + i)
            {
                dsum[ne] = p.first + i;
                q.push(make_pair(dsum[ne], ne));
            }
        }
    }

    cout << dsum[0] << endl;

    return 0;
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n, k;
  cin >> n >> k;
  mint ans = 0;
  rep2(i, k, n+2){
    ll l = (ll)(i-1)*(i)/2;
    ll r = (ll)i*(n+(n-i+1))/2;
    // cerr << l << " " << r << endl;
    ans += r - l + 1;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3580
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n, m;
char as[200][200];
int a[200][200];
int d1[2][200][200][200];
int d2[2][200][200][200];
int s[200][200];

inline int getsum(int sx, int sy, int ex, int ey)
{
	return s[ex][ey]-s[sx-1][ey]-s[ex][sy-1]+s[sx-1][sy-1];
}

int main()
{
	int i, j, k, l;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		scanf("%s", as[i]);
		for(j=0;j<m;j++)
		{
			a[i+1][j+1]=s[i+1][j+1]=as[i][j]=='#';
		}
	}
	for(i=0;i<=n+1;i++) for(j=0;j<=m+1;j++) s[i][j]=j==0?s[i][j]:s[i][j-1]+s[i][j];
	for(i=0;i<=n+1;i++) for(j=0;j<=m+1;j++) s[i][j]=i==0?s[i][j]:s[i-1][j]+s[i][j];
	for(i=1;i<=n;i++) for(j=i;j<=n;j++)
	{
		int cur=0;
		for(k=1;k<=m;k++)
		{
			if(cur < k-1) cur=k-1;
			while(cur < m)
			{
				//cur+1 가능?
				int u=getsum(i, k, j, cur+1);
				if(u == (j-i+1)*(cur+1-k+1) || u == 0) cur++;
				else break;
			}
			d1[0][i][j][k]=cur;
		}
	}
	for(i=1;i<=m;i++) for(j=i;j<=m;j++)
	{
		int cur=0;
		for(k=1;k<=n;k++)
		{
			if(cur < k-1) cur=k-1;
			while(cur < n)
			{
				int u=getsum(k, i, cur+1, j);
				if(u == (cur+1-k+1)*(j-i+1) || u == 0) cur++;
				else break;
			}
			d2[0][i][j][k]=cur;
		}
	}
	for(l=0;l<=16;l++)
	{
		int cur=l%2, tar=(l+1)%2;
		if(d1[cur][1][n][1] == m) return !printf("%d\n", l);
		for(i=1;i<=n;i++) for(j=i;j<=n;j++)
		{
			for(k=1;k<=m;k++)
			{
				int u=d1[cur][i][j][k];
				int v=d1[cur][i][j][u+1];
				d1[tar][i][j][k]=max(u, v);
			}
			int now=0;
			for(k=1;k<=m;k++)
			{
				if(now < k-1) now=k-1;
				//now+1 가능?
				while(now < m)
				{
					int u=d2[cur][k][now+1][i];
					int v=d2[cur][k][now+1][u+1];
					if(max(u, v) >= j) now++;
					else break;
				}
				d1[tar][i][j][k]=max(d1[tar][i][j][k], now);
			}
		}
		for(i=1;i<=m;i++) for(j=i;j<=m;j++)
		{
			for(k=1;k<=n;k++)
			{
				int u=d2[cur][i][j][k];
				int v=d2[cur][i][j][u+1];
				d2[tar][i][j][k]=max(u, v);
			}
			int now=0;
			for(k=1;k<=n;k++)
			{
				if(now < k-1) now=k-1;
				while(now < n)
				{
					int u=d1[cur][k][now+1][i];
					int v=d1[cur][k][now+1][u+1];
					if(max(u, v) >= j) now++;
					else break;
				}
				d2[tar][i][j][k]=max(d2[tar][i][j][k], now);
			}
		}
	}
	return 0;
}
//*/

Measured memory_bytes: 125056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        for (int i = 0; i < s.Length; i++)
        {
            for (int j = i; j < s.Length; j++)
            {
                string str = s.Substring(0, i) + s.Substring(j);
                if (str == "keyence")
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
        }

        Console.WriteLine("NO");
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 26912
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Maxn=1e5;
const ll INF=1e18;
struct Edge {
	int to;
	ll cost;
	Edge(int a,ll b){to=a,cost=b;}
};
vector<Edge> G[Maxn+4];
ll F[Maxn+5][2];
ll Root=-1,L=1,R=INF+5;
void AddEdge(int u,int v,ll w) {
	G[u].push_back(Edge(v,w));
}
int N,M;
bool vis[Maxn+5];
void BFS(int s) {
	queue<int> q;
	vis[s]=true;q.push(s);
	F[s][0]=1,F[s][1]=0;
	while(!q.empty()) {
		int u=q.front();q.pop();
		for(int i=0;i<G[u].size();i++) {
			int v=G[u][i].to;
			ll w=G[u][i].cost;
			if(vis[v])continue;
			F[v][0]=-F[u][0];
			F[v][1]=w-F[u][1];
			vis[v]=true;
			q.push(v);
		}
	}
}
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&M);
	for(int i=1;i<=M;i++) {
		int u,v,w;
		scanf("%d %d %d",&u,&v,&w);
		AddEdge(u,v,w);
		AddEdge(v,u,w);
	}
	BFS(1);
	for(int i=1;i<=N;i++) {
		if(F[i][0]==1)L=max(L,1-F[i][1]);
		else R=min(R,F[i][1]-1);
		for(int j=0;j<G[i].size();j++) {
			int v=G[i][j].to;
			ll w=G[i][j].cost;
			ll x=F[i][0]+F[v][0];
			ll y=F[i][1]+F[v][1];
			if(x==0&&y!=w) {
				puts("0");
				return 0;
			}
			if(x!=0) {
				ll tmp=w-y;
				if(tmp%2||tmp/x<=0) {
					printf("0\n");
					return 0;
				}
				if(Root==-1)
					Root=tmp/x;
				if(Root!=tmp/x) {
					printf("0\n");
					return 0;
				}
			}
		}
	}
	if(Root==-1)
		printf("%d\n",max(0*1LL,R-L+1));
	else
		printf("%d\n",(L<=Root&&Root<=R));
	return 0;
}

Measured memory_bytes: 9728
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	int x;
	cin >> x;
	if (x % 1000 == 0)cout << 0 << endl;
	else cout << 1000 - (x % 1000) << endl;
	return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    int n,m;
    cin>>n>>m;
    long long sum=0;
    vector<long long>a(n);
    rep(i,n){
    cin>>a[i];
    sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int cnt=0;
    rep(i,n){
        if(a[i]<(double)sum/(4*m)){
            break;
        }
        cnt++;
    }

    if(cnt>=m){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;

}
/*


*/


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <set>
const int maxlongint=2147483647;
const int mo=1e9+7;	
const int N=505;
using namespace std;
int n,m,a[N][N],v[N][N],v1[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			char c=getchar();
			while(c!='.' && c!='#') c=getchar();
			v[i][j]=v1[i][j]=a[i][j]=c=='#';
		}
	for(int i=1;i<=n;i++)
	{
		v[i][1]=1,v1[i][m]=1;
		if(i&1)
			for(int j=1;j<=m-1;j++) v[i][j]=1;
		else
			for(int j=2;j<=m;j++) v1[i][j]=1;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) printf("%c",v[i][j]?'#':'.');
		putchar('\n');
	}
	putchar('\n');
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) printf("%c",v1[i][j]?'#':'.');
		putchar('\n');
	}
}

Measured memory_bytes: 6728
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

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


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int gcd(int x, int y)
{
    if (x > y)
    {
        int t = y;
        y = x;
        x = t;
    }
    if (x == 0 || x == y) return y;
    if (x == 1) return 1;
    return gcd(y % x, x);
}

int main(int argc, char const *argv[])
{
    int x, y;
    scanf("%d %d\n", &x, &y);
    printf("%d\n", gcd(x, y));
    return 0;
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

int N, C, K;

int main() {
    cin >> N >> C >> K;
    vector<int> A(N);
    REP(i, N)cin >> A[i];
    sort(A.begin(), A.end());
    int t = 0, res = 1;
    REP(i, N) {
        if (A[i] - A[t] <= K && i-t < C) continue;
        res++;
        t = i;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

class E
{
	static void Main() => Console.WriteLine(((MInt)2).Pow(2 * int.Parse(Console.ReadLine()) - 2) * Console.ReadLine().Split().Select(int.Parse).OrderBy(x => -x).Select((c, i) => (MInt)(i + 2) * c).Aggregate((x, y) => x + y));
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;

	public MInt Pow(int i) => MPow(V, i);
	public override string ToString() => $"{V}";

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 37632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int a,b;
	cin  >> a >>b;
	if(a+b>9)
	{
		cout<<"error"<<endl;
	}
	else
	{
		cout<<a+b<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n,s = map(int,input().split())
    a = tuple(map(int,input().split()))

    mod = 998244353

    res = 0

    #dp[i][j]:a[i]まででf(L,?) = jとなるLの合計数
    dp = [[0]*3003 for i in range(n)]

    for i in range(n):
        if a[i] < s:
            res = (res+dp[i-1][s-a[i]]*(n-i))%mod
        elif a[i] == s:
            res = (res+(i+1)*(n-i))%mod
        for j in range(3003):
            if j < a[i]:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = (dp[i-1][j] + dp[i-1][j-a[i]])%mod
        dp[i][a[i]] += i+1
    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 111964