akhauriyash/Code-Regression huggingface dataset:
from math import gcd
n, k = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
cnt = [0 for _ in range(k+1)]
for i in range(k, 0, -1):
    cnt[i] = pow(k // i, n, mod)
    for j in range(2, k // i + 1):
        cnt[i] = (cnt[i] - cnt[i * j]) % mod
for i in range(1, k+1):
    ans = (ans + cnt[i] * i) % mod

print(ans)

Measured memory_bytes: 11416
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define INF 1e9+1
#define MOD 1e9+7
#define INF64 1e18+1

#define F first
#define S second

#define ll long long int

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 100000

int main (void)
{
  ll x2,y2,x3,y3;
  //x2y3-x3y2 = S
  x2 = 1e9;
  y2 = 1;
  ll S;
  cin >> S;
  y3 = S / 1e9;
  if (y3 < 1e9) {
    y3++;
  }

  x3 = x2*y3-S;

  puts(0);
  puts(0);
  puts(x2);
  puts(y2);
  puts(x3);
  put(y3);
  return 0;
}


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

int main (void)
{
	double r, s1, s2, l;

	scanf("%lf", &r);

	s1=r*M_PI;
	s2=r*s1;
	l=2*r*M_PI;

	printf("%f %f\n", s2,l);

	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{    
    ll n;
    cin >> n;
	ll a;
    vll as(n+1);
    as[0] = 0;
    
    ll r = LLINF;
    
	rrep(i, n) {
		cin >> a;
        as[i] = as[i-1] + a;
	}
 
	rrep(i, n-1) {
        r = min(r, abs(as[n]-as[i] - as[i]));
    }
    mes(r);
	
    
      
    
    
}

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

int main() {
  int N;
  cin>>N;
  vector<int>vecc(N);
  vector<int> vec(N);
for (int i = 0; i < N-1; i++) {
  cin >> vec.at(i);
  vecc.at(vec.at(i)-1)++;
  
}
  for (int i = 0; i < N; i++) {
  cout<<vecc.at(i)<<endl;
}
}

Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

typedef long long ll;
typedef long long unsigned ull;

ull n, a[300000], d[60][2], r[60], p[60], s;

int main() {
    cin >> n;
    for (ull i = 0; i < n; i++) {
        cin >> a[i];
        for (ull j = 0; j < 60; j++) {
            d[j][(a[i] & ((ull) 1 << j)) ? 1 : 0]++;
        }
    }
    for (ull i = 0; i < 60; i++) r[i] = (d[i][0] * d[i][1]) % mod;
    p[0] = 1;
    for (ull i = 1; i < 60; i++) p[i] = (p[i - 1] * 2) % mod;
    for (ull i = 0; i < 60; i++) s = (s + r[i] * p[i]) % mod;
    cout << s << endl;
}

Measured memory_bytes: 2560
def main():
    N, Z, W = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    ans = abs(A[-1] - W)
    if N > 1:
        ans = max(abs(A[-2] - A[-1]), ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
import math
n = int(input())
# 約数の合計が最低の約数のペアを求める
def make_div(n):
    divi = []
    for i in reversed(range(1,int(math.sqrt(n))+1)):
        if n%i == 0:
            return [i, n//i] 

print(sum(make_div(n))-2)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

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

  if (N == 1) {
    cout << "Hello World" << endl;
  } else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng (chrono::steady_clock::now().time_since_epoch().count() );

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 1e5 + 12; //check the limits, dummy

ll par[MX], sz[MX];

void make_set (ll v)  {
    par[v] = v;
    sz[v] = 1;
}

ll find_set (ll v) {
    if (v == par[v]) return v;
    return par[v] = find_set (par[v]);
}

void union_set (ll u, ll v) {
    u = find_set (u);
    v = find_set (v);
    if (u != v) {
        if (sz[u] < sz[v]) swap (u, v);
        par[v] = u;
        sz[u] += sz[v];
    }
}

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

    ll n, m;
    cin >> n >> m;
    vpl in (m);
    FOR (i, 0, m) cin >> in[i].f >> in[i].s;

    ll ans = (n * (n - 1) ) / 2;

    FOR (i, 1, n + 1) make_set (i);

    vl res;
    res.pb (ans);

    FORd (i, 0, m) {
        ll ra = find_set (in[i].f);
        ll rb = find_set (in[i].s);
        if (ra != rb) {
            ans -= sz[ra] * sz[rb];
            union_set (in[i].f, in[i].s);
        }
        if (i != 0) res.pb (ans);
    }

    reverse (all (res) );
    FOR (i, 0, sz (res) ) cout << res[i] << '\n';

    return 0;
}


Measured memory_bytes: 5364
S = list(str(input()))
correct = list("keyence")


def search():
    index = 0
    words = 0
    if S[:7] == correct:
        print("YES")
    elif S[len(S)-7:] == correct:
        print("YES")
    else:
        for now, s in enumerate(S):
            if s == correct[index]:
                index += 1
                words += 1
            else:
                break
        index = 6
        for s in S[::-1]:
            if s == correct[index]:
                index -= 1
                words += 1
            else:
                break
        if words >= 7:
            print("YES")
        else:
            print("NO")
search()

Measured memory_bytes: 3064
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;
bool dp[MAX_N];
int a[101];

int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<=k;i++) dp[i]=false;
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-a[j]>=0 && !dp[i-a[j]]) dp[i]=true;
        }
    }
    if(dp[k]){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
from collections import Counter
N=int(input())
balls=[tuple(map(int, input().split())) for _ in range(N)]

#2ボールの相対座標をぜんぶ調べる
R=[(x[0]-y[0],x[1]-y[1]) for x in balls for y in balls]
C=Counter(R).most_common()

#いちばん多い相対座標を(p,q)とする
#C[0]は(0,0)なので除外
if len(C)<=1:
    print(N)
else:
    print(N-(C[1][1]))

Measured memory_bytes: 40944
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = list(input())
t = list(input())
r, l, u, d = w, 1, 1, h
ns = list(range(n))
for i in ns[::-1]:
    if t[i] == 'L' and r < w:
        r += 1
    elif t[i] == 'R' and l > 1:
        l -= 1
    elif t[i] == 'U' and d < h:
        d += 1
    elif t[i] == 'D' and u > 1:
        u -= 1
    if s[i] == 'L':
        l += 1
    elif s[i] == 'R':
        r -= 1
    elif s[i] == 'U':
        u += 1
    elif s[i] == 'D':
        d -= 1
    if (l > r) or (u > d):
        ans = 'NO'
        break
if (l <= sc <= r) and (u <= sr <= d):
    ans = 'YES'
else:
    ans = 'NO'
print(ans)

Measured memory_bytes: 72140
#include<stdio.h>
int ta[10010],to[60010],nt[60010],id[10010],cmp[100010],r=0,f[10010]={0};
int a[10010],b[10010],c[10010],q[10010];
int Ta[110],To[1010],Co[1010],Nt[1010];
void sdfs(int e,int s,int k){
  int i;
  f[s]++;
  for(i=ta[s];i+1;i=nt[i]){
    if(i<e&&k<0&&f[to[i]]==-1||i>=e&&k>=0&&f[to[i]]==0)sdfs(e,to[i],k);
  }
  k<0?(id[r++]=s):(cmp[s]=k);
}
void scc(int v,int e,int *a,int *b){
  int i,k;
  for(i=0;i<v;i++)f[i]=ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[a[i]]=i;
    ta[b[i]]=i+e;
  }
  for(i=k=0;i<v;i++){
    if(f[i]==-1)sdfs(e,i,-1);
  }
  for(i=r;i;i--){
    if(f[id[i-1]]==0)sdfs(e,id[i-1],id[i-1]);
  }
  }//*/
int mca(int v,int e,int k,int *a,int *b,int *c){
  int i,j,t,r,s,p=0;
  int bk[110]={0};
  int mi[110];
  for(i=0;i<v;i++)Ta[i]=mi[i]=-1;//??£??\??????????????????
  for(i=0;i<e;i++){
    Nt[i]=Ta[a[i]];
    To[i]=b[i];
    Co[Ta[a[i]]=i]=c[i];
    bk[a[i]]=bk[b[i]]=1;
  }
  for(i=0;i<v;i++)p+=bk[i];
  for(i=0;i<e;i++){//?????????MIN???????±???????
    if(mi[To[i]]==-1||Co[mi[To[i]]]>c[i])mi[To[i]]=i;
  }
  mi[k]=-1;
  q[t=0]=k;
  for(r=1;r-t;t++){
    for(j=Ta[q[t]];j+1;j=Nt[j]){
      if(mi[To[j]]==j)q[r++]=To[j];
    }
  }
  if(r==p){
    for(i=s=0;i<e;i++){
      if(mi[To[i]]==i)s+=Co[i];
    }
    return s;
  }
  for(i=r=0;i<v;i++){
    bk[i]=0;
    for(j=Ta[i];j+1;j=Nt[j]){
      if(mi[To[j]]-j)continue;
      a[r]=i;
      b[r++]=To[j];
    }
  }
  scc(v,r,a,b);//?????£?????????????§£??§???????????????????????????
  for(i=0;i<v;i++)bk[cmp[i]]++;
  for(i=r=s=0;i<v;i++){
    for(j=Ta[i];j+1;j=Nt[j]){
      a[r]=cmp[i];
      b[r]=cmp[To[j]];
      if(a[r]==b[r]){
	if(j==mi[To[j]])s+=Co[j];
      }
      else c[r++]=bk[cmp[To[j]]]-1?Co[j]-Co[mi[To[j]]]:Co[j];
    }
  }
  return mca(v,r,k,a,b,c)+s;
}
	 
int main(){
  int n,m,k,i;
  scanf("%d %d %d",&n,&m,&k);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  printf("%d\n",mca(n,m,k,a,b,c));
  return 0;
}

Measured memory_bytes: 680
from collections import defaultdict
n = int(input())


def f(x):
    s = str(x)
    return (s[0], s[-1])


freq = defaultdict(int)

for i in range(1, n+1):
    p = f(i)
    freq[p] += 1


ans = 0

for i in range(1, n+1):
    a, b = f(i)
    ans += freq[(b, a)]

print(ans)

Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
#include <stdio.h>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
#include <iterator>
#include <numeric>
#include <algorithm>

int main() {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a * c, a * d), max(b * c, b * d));
	return 0;
}


Measured memory_bytes: 3632
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
cnt = 0
for _ in range(N):
    A =np.array( list(map(int, input().split())))
    if sum(A * B) + C > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 12392
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

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

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int nHalf = n >> 1;

      int[] seqA = new int[nHalf];
      int[] seqB = new int[nHalf];

      Integer num;
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      int offset=0,next=0;
      char regx = ' ';

      for(int i=0; i<n; i++) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        if((i & 1) == 0) {
          seqA[i>>1] = num;
          mapA.merge(num, 1, Integer::sum);
        }
        else {
          seqB[i>>1] = num;
          mapB.merge(num, 1, Integer::sum);
        }
      }

      int[] vm = new int[2];
      int[] x =  new int[2];
      vm[0] = vm[1] = x[0] = x[1] = 0;

      mapA.forEach((key,val) -> {
        if(vm[0] < val) {
          vm[0] = val;
          x[0]  = key;
        }
      });
      mapB.forEach((key,val) -> {
        if(vm[1] < val) {
          vm[1] = val;
          x[1]  = key;
        }
      });

      int cca = nHalf - vm[0];
      int ccb = nHalf - vm[1];

      int[] vm2 = new int[2];
      final int fxa = x[0];
      final int fxb = x[1];
      int ans = 0;
  
      if(fxa == fxb) {
        mapA.forEach((key,val) -> {
          if(vm2[0] < val && key != fxa)
            vm2[0] = val;
        });
        mapB.forEach((key,val) -> {
          if(vm2[1] < val && key != fxb)
          vm2[1] = val;
        });
      
        int cca2 = nHalf -vm2[0];
        int ccb2 = nHalf -vm2[1];

        ans = cca2 > ccb2 ? cca + ccb2 : cca2 + ccb;
      }
      else {
        ans = cca + ccb;
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 48276
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

int main()
{
    ll a;
    string s;
    cin >> a >> s;

    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
vector<int> c, v;
int n;
int solve(int id, int Xsum, int Ysum) {
    if (id == n) return (Xsum-Ysum);
    int t1 = solve(id+1, Xsum+v[id], Ysum+c[id]);
    int t2 = solve(id+1, Xsum, Ysum);
    return (max(t1, t2));
}

int main(int argc, char const *argv[]) {
    cin >> n;
    c.resize(n); v.resize(n);
    REP(i,n) cin >> v[i];
    REP(i,n) cin >> c[i];
    cout << solve(0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 500001

//int parent(int);
int left(int);
int right(int);
void Maxheap(int *,int);
void BuildMaxheap(int *);

int H;

int main(){
  int i,A[N];

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  BuildMaxheap(A);

  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
/*int parent(int i){
  return i/2;
  }*/
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
void Maxheap(int *A,int i){
  int l,r,tmp,large;
  l=left(i);
  r=right(i);
  if(l<=H && A[l]>A[i])
    large=l;
  else large=i;
  if(r<=H && A[r]>A[large])
    large=r;

  if(large!=i){
    tmp=A[i];
    A[i]=A[large];
    A[large]=tmp;
    Maxheap(A,large);
  }
}
void BuildMaxheap(int *A){
  int i;
  for(i=H/2;i>=1;i--){
    Maxheap(A,i);
  }
}

Measured memory_bytes: 2552
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

int main()
{
	FASTIO;
	int a,b;
	cin >> a >> b;
	int ans = max(0,a - 2 * b);
	cout << ans << ln;
	return 0;
}


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

int main(){
  int N;
  int prex,prey,pret;
  bool flag = true;
  cin>>N;

  prex=prey=pret=0;
  
  for(int i=0; i<N; i++){
    int t,x,y,length;
    cin>>t>>x>>y;
 
    x -= prex;
    y -= prey;
    t -= pret;
    length = abs(x)+abs(y);

    if(length == 0){
      if(t % 2 != 0){
        flag = false;
      }
      continue;
    }

    if(t == length)continue;

    if(t  < length || length % 2 != t % 2){
      flag = false;
    }
    
    prex = x;
    prey = y;
    pret = t;
    
  }

  if(flag )cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np

w,h,n = map(int, input().split())
mp = np.zeros((w,h))
for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1:
        mp[:xi, :] = 1
    elif ai == 2:
        mp[xi:, :] = 1
    elif ai == 3:
        mp[:, :yi] = 1
    elif ai == 4:
        mp[:, yi:] = 1
print(w*h - np.sum(mp))

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

#define ll long long
#define mx 200005

int n,m,ii,k;
int ar[mx];
char ch[mx];

vector<pair<ll,ll>>v;

int main()
{
    scanf("%d",&n);
    ll be=1e18,en=0;
    ll st=1e18,enn=-1e18;
    ll a=1e18,b=0;
    for(int i=1;i<=n;i++)
    {
        ll x,y;
        scanf("%lld%lld",&x,&y);
        be=min(be,x+y);
        en=max(en,x+y);
        st=min(st,x-y);
        enn=max(enn,x-y);
        a=min(a,abs(x-y));
        b=max(b,abs(x-y));
    }


        printf("%lld",max({en-be,enn-st,b-a}));

    return 0;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
long long n,a[100001],sum,sumn;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(n%2!=0){
		cout<<"0";
		return 0;
	}
	sort(a,a+n+1);
	cout<<a[n/2+1]-a[n/2];
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll l;
ll a[100100];

void solve() {
    for (int i = 0; i < n-1; i++) {
        if (a[i] + a[i+1] >= l) {
            cout << "Possible" << endl;
            for (int j = 1; j <= i; j++) {
                cout << j << endl;
            }
            for (int j = n-1; j >= i+1; j--) {
                cout << j << endl;
            }
            return;
        }
    }
    cout << "Impossible" << endl;
}

void input() {
    cin >> n >> l;
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    solve();
}


Measured memory_bytes: 4396
n = int(input())
h = list(map(int, input().split()))
count = 0
ans_list = []
for i in range(len(h)-1):
    if h[i] >= h[i+1]:
        count += 1
    elif h[i] < h[i+1]:
        ans_list.append(count)
        count = 0
ans_list.append(count)
print(max(ans_list))

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int n;

bool b(int a){
	int cnt = 0;
	for(int i = 1; i*i < a; i++){
		if(a%i == 0) cnt+=2; 
	}
	if(cnt == 8)return 1;
	else return 0;
}

int main(){
	cin >> n;
	
	int c = 0;
	for(int i = 3; i <= n; i+=2){
		c += b(i);
	}
	
	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val S = readInputLine().toCharArray()
    
    val K = readInputLine().toLong()
    
    for ((i, c) in S.withIndex()) {
        if (c != '1') {
            println(c)
            return
        }
        if (i.toLong() + 1L == K) {
            break
        }
    }
    
    println(1)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 33904
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

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

    vector<long long> cnt(N, 0);
    for(long long i = 0; i < Q; i++){
        cnt[A[i]-1]++;
    }

    
    for(long long i = 0; i < N; i++){
        if(K - (Q - cnt[i]) <= 0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    

    return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S/3600;
		int m = (S-h*3600)/60;
		int s = S-(h*3600)-m*60;
		System.out.println(h+":"+m+":"+s);
	}

}

Measured memory_bytes: 26300
#include<bits/stdc++.h>
using namespace std;
#define ff      first
#define ss      second
#define ll      int
#define ull     unsigned long long
#define mod     1000000007
#define vi      vector<ll>
#define ppi     pair<ll,pair<ll,ll>>
#define pb      push_back
#define mp      make_pair
#define str     string
#define pi      2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)    cout<<a;
#define sp(x,y) fixed<<setprecision(y)<<x
#define w(x)    ll x; cin>>x; while(x--)
#define e       cout<<'\n';
#define all(v)  v.begin(), v.end()
#define test    cout<<"BECOME_EXPERT_FAST"<<endl;
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
int32_t main() {
	kehsihba();
	int a;scanf("%d",&a);
	int L=a/100;
	int R=a%100;
	if(1<=L&&L<=12){
	if(1<=R&&R<=12)printf("AMBIGUOUS\n");
	else printf("MMYY\n");
	}else{
	if(1<=R&&R<=12)printf("YYMM\n");
	else printf("NA\n");
	}
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int maxn=1e5+7;
int getId()
{
	char c;
	scanf("%c",&c);//cout<<c<<endl;
	if(c=='R') return 0;
	if(c=='G') return 1;
	if(c=='B') return 2;
}
int num[5];ll cnt[5];
int main()
{
	int n;scanf("%d",&n);getchar();cnt[0]=n;ll ans=1;
	for(int i=1;i<=3*n;i++)
	{
		int id=getId();
		num[id]++;int x=0;
		for(int j=0;j<3;j++) if(num[j]>num[id]) x++;
		num[id]++;
		ans=ans*cnt[x];cnt[x]--;cnt[x+1]++;ans%=mod; 
	}
	cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, a, ans = 0;
    cin >> N;
    REP(i, N) {
        cin >> a;
        while (a > 0 && (a % 2) == 0) {
            a /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  double n,m,d;
  cin >> n >> m >> d;
  if(d!=0)printf("%lf",(m-1)*(n-d)*2/n/n);
  else printf("%lf",(m-1)*(n-d)/n/n);
}

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



int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int maxi=0;
    int count=0;
    for(int i=0;i<n-1;i++){
        if(arr[i]>=arr[i+1]){
            count++;
            maxi=max(count,maxi);
        }
        else{
            count=0;
        }
    }
    cout<<maxi;

}


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

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

  int x = 7%k;
  set<int> s;
  int i = 1;
  while (s.count(x) == 0) {
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    s.insert(x);
    x =(x*10+7)%k;
    ++i;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 50508
n,m=map(int,input().split())

nm=n*m
if n==1 and m==1:
  print(1)
elif (n==1 and m==2) or (n==2 and m==1):
  print(0)
elif (n==2 and m==2):
  print(0)
elif n==1 or m==1:
  print(n*m-2)
else:
  soto=2*m+2*n-4
  print(n*m-soto)


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
//template<typename... Args>
//void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

const int N=2e5+5;
vector<int> G[N];
const int mod=1e9+7;
ll ans[N];
ll fac[N],inv[N];
ll binpow(ll a,int b){
   ll res=1;
   for(;b;b>>=1){
       if(b&1) res=res*a%mod;
       a=a*a%mod;
   }
   return res;
}
ll dp[N],sz[N];
int n;
void cal(int u,int f){
    sz[u]=1;
    int res=1;
    for(auto to:G[u]){
        if(to!=f){
            cal(to,u);
            sz[u]+=sz[to];
            res=res*dp[to]%mod*inv[sz[to]]%mod;
        }
    }
    res=res*fac[sz[u]-1]%mod;
    dp[u]=res;
}
void dfs(int u,int f,int par){
    ans[u]=par;
    for(auto to:G[u]) if(to!=f){
        dfs(to,u,par*sz[to]%mod*binpow(n-sz[to],mod-2)%mod);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
    inv[n]=binpow(fac[n],mod-2);
    for(int i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
    forn(i,n-1){
        int x,y;
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
    }
    cal(1,0);
    dfs(1,0,dp[1]);
    for1(i,n) cout<<ans[i]<<endl;
    return 0;
}



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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n;
	cin >> n;

	ll a[n];
	rep(i,n) cin >> a[i];

	ll div2 = 0;
	ll notdiv2 = 0;
	ll div4 = 0;

	rep(i,n){
		if(a[i] % 2 == 0 && a[i] % 4 != 0) div2++;
		else if(a[i] % 4 == 0) div4++;
		else notdiv2++;
	}

	if(div2 > 0) cout << (notdiv2 <= div4 ? "Yes" : "No") << endl;
	else cout << (notdiv2 <= div4 + 1 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=100010;
int N,a[maxn],b[maxn];
int main(){
	//freopen("in","r",stdin);
	N=read();
	for(int i=1;i<=N+1;i++)
		a[i]=read();
	for(int i=1;i<=N;i++)
		b[i]=read();
	long long ans=0;
	for(int i=1;i<=N;i++){
		if(b[i]>=a[i]){
			ans+=a[i];
			b[i]-=a[i];
			a[i]=0;
			if(b[i]>=a[i+1]){
				ans+=a[i+1];
				b[i]-=a[i+1];
				a[i+1]=0;
			}
			else{
				ans+=b[i];
				a[i+1]-=b[i];
				b[i]=0;
			}
		}
		else{
			ans+=b[i];
			a[i]-=b[i];
			b[i]=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int cost[6];
bool used[5][5], flag;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

bool can(int y,int x) {
	if(0 <= y && y < 5 && 0 <= x && x < 5) return true;
	return false;
}

ll del(vector<vector<int> > &v, ll bonus) {
	memset(used, 0, sizeof(used));
	rep(i, 5) {
		rep(j, 5) {
			if(v[i][j] == 0) continue;

			int a = i;
			while(a + 1 <= 4 && v[a+1][j] == v[i][j]) {
				a++;
			}

			int b = i;
			while(b - 1 >= 0 && v[b-1][j] == v[i][j]) {
				b--;
			}

			int c = j;
			while(c + 1 <= 4 && v[i][c+1] == v[i][j]) {
				c++;
			}

			int d = j;
			while(d - 1 >= 0 && v[i][d-1] == v[i][j]) {
				d--;
			}

			if(a - b + 1 >= 3 || c - d + 1 >= 3) used[i][j] = true;
		}
	}

	ll ret = 0;
	rep(i, 5) {
		rep(j, 5) {
			if(used[i][j]) {
				ret += bonus * cost[v[i][j]];
				flag = true;
				v[i][j] = 0;
			}
		}
	}

	return ret;
}

void mov(vector<vector<int> > &v) {
	for(int i = 4; i >= 0; i--) {
		rep(j, 5) {
			int y = i;
			while(y + 1 <= 4 && v[y + 1][j] == 0) {
				swap(v[y][j], v[y+1][j]);
				y++;
			}
		}
	}
}

int n;
ll ans = 0;

set<vector<vector<int> > > res;

void dfs(int cnt, int y, int x, vector<vector<int> > v) {
	res.insert(v);

	if(cnt == n) {
		return;
	}

	rep(i, 4) {
		int ny = y + dy[i];
		int nx = x + dx[i];

		if(can(ny, nx)) {
			swap(v[y][x], v[ny][nx]);
			dfs(cnt + 1, ny, nx, v);
			swap(v[y][x], v[ny][nx]);
		}
	}
}

int main() {
	while(cin >> n && n != -1) {
		ans = 0;
		res.clear();

		vector<vector<int> > v(5, vector<int>(5));
		rep(i, 5) rep(j, 5) cin >> v[i][j];
		rep(i, 5) cin >> cost[i+1];

		rep(i, 5) {
			rep(j, 5) {
				dfs(0, i, j, v);
			}
		}

		set<vector<vector<int> > >::iterator ite;
		for(ite = res.begin(); ite != res.end(); ite++) {

			ll bonus = 1, sum = 0;
			vector<vector<int> > t = *ite;

			while(true) {
				flag = false;
				sum += del(t, bonus);

				if(flag) {
					mov(t);
					bonus++;

				} else break;
			}

			// cout << "----- : " << sum << endl;
			// rep(i, 5) {
			// 	rep(j, 5) {
			// 		cout << t[i][j] << " ";
			// 	}
			// 	cout << endl;
			// }
			ans = max(ans, sum);
		}

		cout << ans << endl;
	}

	return 0;
}

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

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0;i < n;i++){
        cin >> a[i];
    }
    ll m = a[0];
    ll ans = 0;

    for (ll i = 1; i < n; i++){
        if (a[i] < m){
            ans += (m-a[i]);
        }
        else{
            m = a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4732
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main()
{
	for(int i=0;;i++)
	{
		int x,y;
		cin>>x>>y;
		if(x == 0 && y == 0) break;
		cout<<min(x,y)<<" "<<max(x,y)<<endl;
	}
	return 0;
}

Measured memory_bytes: 2992
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)


int main() {
	ll a, b, c, d, e, f, g;
	cin >> a >> b;
	if (a < b)cout << 0;
	else cout << 10;

	return 0;
}

	

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    s = []
    for _ in range(H):
        s.append(input())

    mv = [[1,0],[-1,0],[0, 1],[0, -1]]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                isfound = False
                for di, dj in mv:
                    i1, j1 = i+di, j+dj
                    if 0<=i1<H and 0<=j1<W and s[i1][j1] == "#":
                        isfound = True
                        break
                if not isfound: return "No"
    return "Yes"


if __name__ == '__main__':
    print(main())


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

class FC{
public:
    int p[31];
    int n;
    bool is_over(){
        return p[1]==p[2]&&p[2]==p[3]&&p[3]==p[4]&&p[4]==p[5]&&
            p[5]==p[6]&&p[6]==p[7]&&p[7]==p[8]&&p[8]==p[9]&&
            p[10]==p[11]&&p[11]==p[12]&&
            p[13]==p[14]&&p[14]==p[15]&&
            p[16]==p[17]&&p[17]==p[18]&&
            p[19]==p[20]&&p[20]==p[21]&&
            p[22]==p[23]&&p[23]==p[24]&&p[24]==p[25]&&p[25]==p[26]&&
            p[26]==p[27]&&p[27]==p[28]&&p[28]==p[29]&&p[29]==p[30];
    }
    void rot1(){
        swap(p[7],p[22]);
        swap(p[8],p[23]);
        swap(p[9],p[24]);
        swap(p[13],p[18]);
        swap(p[10],p[12]);
    }
    void rot2(){
        swap(p[1],p[28]);
        swap(p[2],p[29]);
        swap(p[3],p[30]);
        swap(p[15],p[16]);
        swap(p[19],p[21]);
    }
    void rot3(){
        swap(p[1],p[24]);
        swap(p[4],p[27]);
        swap(p[7],p[30]);
        swap(p[10],p[21]);
        swap(p[16],p[18]);
    }
    void rot4(){
        swap(p[3],p[22]);
        swap(p[6],p[25]);
        swap(p[9],p[28]);
        swap(p[12],p[19]);
        swap(p[13],p[15]);
    }
};

int main(){
    int N;
    cin>>N;
    for(int i=0; i<N; i++){
        FC now;
        for(int j=1; j<=30; j++){
            cin>>now.p[j];
        }
        now.n=0;

        queue<FC> que;
        que.push(now);
        while(!que.empty()){
            now=que.front();
            que.pop();
            if(now.is_over()){
                cout<<now.n<<endl;
                break;
            }
            FC nex1=now; nex1.rot1(); nex1.n++; que.push(nex1);
            FC nex2=now; nex2.rot2(); nex2.n++; que.push(nex2);
            FC nex3=now; nex3.rot3(); nex3.n++; que.push(nex3);
            FC nex4=now; nex4.rot4(); nex4.n++; que.push(nex4);
        }
    }
    return 0;
}



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

using namespace std;

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

}
}
cout<<x<<endl;
   return 0;
}






Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x = sc.nextInt();
        int t = sc.nextInt();
        
        int time;
        
        if(n % x == 0){
            time = n / x * t;
        } else {
            time = (n / x + 1) * t;
        }
        
        System.out.println(time);
    }
}

Measured memory_bytes: 35696
import sys

def input():
    return sys.stdin.readline().strip()


def main():
    def make_factorial_table(n):
        result = [0] * (n+1)
        result[0] = 1
        for i in range(1,n+1):
            result[i] = result[i-1] * i % mod
        return result
    
    def nCr(n,r):
        return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod

    K = int(input())
    S = input()
 
    mod = 10 ** 9 + 7
    n = len(S)
    ans = 0
    fact = make_factorial_table(n+K+1)

    for i in range(K+1):
        tmp = pow(25,i,mod)
        tmp *= nCr(i+n-1,n-1)
        tmp *= pow(26,K-i,mod)
        ans += tmp
        ans %= mod
    print(ans)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 91356
def findnumberofTriangles(arr): 
    n = len(arr) 
    arr.sort() 
    count = 0

    for i in range(0,n-2): 
        k = i + 2
        for j in range(i+1,n): 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1  
    return count 

n=int(input())
l=list(map(int,raw_input().split()))

print findnumberofTriangles(l)  

Measured memory_bytes: 2816
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
dp = [[0, 0] for _ in range(N + 1)]
dp[0][0] = 1
for _ in range(M):
    x = int(input())
    dp[x][1] = 1
for i in range(1, N + 1):
     if dp[i][1] == 0:
         dp[i][0] = (dp[i - 2][0] + dp[i - 1][0]) % MOD
print(dp[N][0])


Measured memory_bytes: 16372
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int a[200000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	char s[101];
	int select[26] = { 0 };
	int cnt;
	int max = 0;

	scanf("%d", &n);
	scanf("%s", s);

	REPS(i, n) {
		cnt = 0;
		m0(select);
		REP(j, n) {
			if (j < i) {
				select[s[j] - 'a']=1;
			}
			else {
				if (select[s[j] - 'a'] == 1)cnt++;
				select[s[j] - 'a'] = 2;
			}
		}
		if (max < cnt)max = cnt;
	}
	PRINTD(max);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=1e5+10;
int n,l,a[maxn],maxx,pos;

int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(int i=1;i<n;++i)
		if(a[i]+a[i+1]>maxx)
			maxx=a[i]+a[i+1],pos=i;
	if(maxx<l){
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	for(int i=n-1;i>pos;--i)
		printf("%d\n",i);
	for(int i=1;i<=pos;++i)
		printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int n, p = 1000000007;
long long c[60][60];
long long f[60][120];
int main() {
	scanf("%d", &n);
	for (int i = 0; i <= n; i++) {
		c[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % p;
		}
	}
	f[1][n] = f[1][n - 1] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = -i; j <= i; j++) {
			if (f[i][j + n] == 0) {
				continue;
			}
			for (int a = 0; a < n; a++) {
				for (int b = 0; b < n; b++) {
					if (a + b > 0 && i + a + b <= n && (j + a - b) % 2 == 0 && abs(j) <= a + b) {
						long long &t = f[i + a + b][(j + a - b) / 2 + n];
						t = (t + f[i][j + n] * c[i + a + b][a + b] % p * c[a + b][b]) % p;
					}
				}
			}
		}
	}
	printf("%lld\n", f[n][n]);
	return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').map(String::toLong)
    val xList = readLine()!!.split(' ').map { Math.abs(it.toLong() - x) }
    println(gcd(xList))
}

fun gcd(a: Long, b: Long): Long {
    var tempA = a
    var tempB = b
    if (tempA < tempB) {
        val tmp = tempA
        tempA = tempB
        tempB = tmp
    }
    var r = -1L
    while (r != 0L) {
        r = tempA % tempB
        tempA = tempB
        tempB = r
    }
    return tempA
}

fun gcd(param: List<Long>): Long {
    val len = param.size
    if (len == 1) return param[0]
    var g = gcd(param[0], param[1])
    for (i in 1 until len - 1) {
        g = gcd(g, param[i + 1])
    }
    return g
}


Measured memory_bytes: 50088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <deque>

using namespace std;

int main(void) {
    string s;
    int Q;
    cin >> s >> Q;

    deque<char> dq;
    for(int i=0; i<s.size(); i++) {
        dq.push_back(s[i]);
    }

    bool front = true;
    int cnt = 0;
    while(Q--) {
        int T;
        cin >> T;
        if(T == 1) {
            front = 1-front;
            cnt ++;
        } else {
            int F;
            char C;
            cin >> F >> C;
            if((F%2)^front) {
                dq.push_back(C);
            } else {
                dq.push_front(C);
            }
        }
    }

    if(cnt%2) {
        while(dq.size()) {
            cout << dq.back();
            dq.pop_back();
        }
        
    } else {
        for(auto e: dq) {
            cout << e;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#include <stack>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
const ll INF = 1LL << 50;

int solve();

void replace(string& target, const string& from, const string&to) {
	int pos(target.find(from));
	while (pos != string::npos) {
		target.replace(pos, from.length(), to);
		pos = target.find(from);
	}
}

int main(void) {
//	FILE *fpin = freopen("data.txt", "r", stdin);
	while (solve()) {}
//	while (1) {}
	return 0;
}

int solve() {

	int N;
	cin >> N;
	string s, orig, ans;
	cin >> s;
	orig = s;

	while (orig.find("()") != string::npos) {
		replace(orig, std::string("()"), string(""));
	}

	int r = 0, l = 0;

	for (int i = 0; i < orig.length(); i++) {
		if (orig[i] == ')')
			r++;
		else
			l++;
	}

	for (int i = 0; i < r; i++)
		ans += "(";
	ans += s;
	for (int i = 0; i < l; i++)
		ans += ")";


	cout << ans << endl;
	


	return 0;
}

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

class Rollinhash:
    def __init__(self, S):
        N = len(S)
        self.mod = 10**9+9
        self.base = 2009          
        self.has = [0]*(N+1)
        self.power = [1]*(N+1)
        for i in range(N):
            s = S[i]
            self.has[i+1] = (self.has[i]*self.base + s)%self.mod
            self.power[i+1] = self.power[i]*self.base%self.mod
 
    def rh(self, i, j):
        return (self.has[j] - self.has[i]*self.power[j-i])%self.mod

MOD = 10**9+7
 
S = list(map(ord, readline().strip()))
N = len(S)
if len(set(S)) == 1:
    print(N)
    print(1)
else:
    Rs = Rollinhash(S)
    
    tabler = [True]*(N+1)
    for d in range(1, 1+N//2):
        r = Rs.rh(0, d)
        for i in range(1, N//d):
            if r != Rs.rh(i*d, (i+1)*d):
                break
            tabler[(i+1)*d] = False
    tablel = [True]*(N+1)
    for d in range(1, 1+N//2):
        r = Rs.rh(N-d, N)
        for i in range(1, N//d):
            if r != Rs.rh(N-(i+1)*d, N-i*d):
                break
            tablel[N-(i+1)*d] = False
    
    if tabler[N]:
        print(1)
        print(1)
    else:
        print(2)
        ans = 0
        for i in range(N+1):
            if tabler[i] and tablel[i]:
                ans += 1
        assert ans > 0, ''
        print(ans)
        

Measured memory_bytes: 85328