akhauriyash/Code-Regression huggingface dataset:
/*
            _           __                _      _____ _____ _____ 
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / / 
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /  
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/   

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ; 
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) cout<<n<<"\n"
#define pff(n) cout << n << " " ; 
#define ar array
#define endl "\n" 
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
long const M=1e9+7;
const long mxN =1e5+2 ;
const long mxNN =1e6+2 ;
void solve(){
    int a,b,c,d ;
    cin >> a >> b  >> c >> d ;
    for(int i=0;a>0&&c>0;i++){
        if(i&1)a-=d ;
        else c-=b ;
    }
    cout << (a>0?"Yes":"No")  << endl ;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << setprecision(20) << fixed ;
    solve() ;
    //ll t ; cin >> t ; while(t--)solve();
	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define MAX 1000                                      
typedef long long ll;
typedef unsigned long long ull;
extern inline int max( int a, int b ) { return a > b ? a : b ; }
extern inline int min( int a, int b ) { return a > b ? b : a ; }
extern inline ll lmax( ll a, ll b ) { return a > b ? a : b ; }
extern inline ll lmin( ll a, ll b ) { return a > b ? b : a ; }
extern inline ull ulmax( ull a, ull b ) { return a > b ? a : b ; }
extern inline ull ulmin( ull a, ull b ) { return a > b ? b : a ; }

int main()
{
	int A, B, T;
	
	scanf("%d %d %d", &A, &B, &T);
	printf("%d", (T/A)*B);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];

  ll ans = 0;
  rep(i,2){
    if(i) sort(all(a),greater<int>());
    else sort(all(a));
    list<int> lst;
    int l = 0, r = n-1;
    lst.push_front(a[l]);
    l++;
    while(1){
      lst.push_front(a[r]);
      r--;
      if(r < l) break;
      lst.push_back(a[r]);
      r--;
      if(r < l) break;
      lst.push_front(a[l]);
      l++;
      if(r < l) break;
      lst.push_back(a[l]);
      l++;
      if(r < l) break;
    }
    ll res = 0, pre = -1;
    for(auto now : lst){
      if(pre != -1) res += abs(now-pre);
      pre = now;
    }
    chmax(ans,res);
  }
  cout << ans;
  cout << "\n";
  return 0;
}


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

int main() {
  int a;
  int b;

  cin >> a >> b;

  if(a%2 != 0 && b%2 != 0){
  cout << "Odd" << endl;
  }
  else{
  cout << "Even" << endl;
  }
}



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

const int nmax = 102000;
const int inf =999999999;

int h[nmax];
int dp[nmax];

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

    int n,k;cin>>n>>k;
    vector<int>mov;
    for(int i=1;i<=k;++i)mov.push_back(i);


    for(int i=1;i<=n;++i){cin>>h[i];dp[i]=inf;}
    dp[1]=0;
    dp[0]=inf;

    for(int i=2;i<=n;++i)
    {
        for(auto j:mov)
        {
            if(i-j<=0)break;
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n];

    return 0;
}


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

LL solve(LL H, LL W) {
  LL a, b, c, ans1, ans2, h, w, maxs, mins;
  a = b = c = 10000000000;
  ans1 = ans2 = 10000000000;
  w = W / 2;
  for (LL i = 1; i <= H/2 + 1; i ++) {
    a = i * W;
    h = (H - i) / 2;
    b = h * W;
    c = (H - i - h) * W;
    maxs = max(a, max(b, c));
    mins = min(a, min(b, c));
    ans1 = min(ans1, maxs - mins);
  }

  for (LL i = 1; i <= H/2 + 1; i ++) {
    a = i * W;
    b = (H - i) * w;
    c = (H - i) * (W - w);
    maxs = max(a, max(b, c));
    mins = min(a, min(b, c));
    ans2 = min(ans2, maxs - mins);
  }

  return min(ans1, ans2);
}

int main() {
  LL h, w;
  cin >> h >> w;

  cout << min(solve(h, w), solve(w, h)) << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main{
    static Scanner in = new Scanner(System.in);

    void solve(){
        HashMap<Integer, Integer> map = new HashMap<>();
        int n = in.nextInt();
        int max = 0;
        for(int i = 0; i < n; i++){
            int a = in.nextInt();
            for(int k = a - 1; k <= a + 1; k++){
                if(map.containsKey(k)){
                    map.put(k, map.get(k) + 1);
                }else {
                    map.put(k, 1);
                }
            }
        }
        for(int a : map.keySet()) {
            max = Math.max(max, map.get(a));
        }
        System.out.println(max);

    }

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

Measured memory_bytes: 65828
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, p = map(int, readline().split())
a = list(map(int, readline().split()))
cnt_1 = 0
cnt_2 = 0
for i in a:
    if i % 2 == 1:
        cnt_1 += 1
    else:
        cnt_2 += 1
ans = 2 ** max(0, cnt_1 - 1) * 2 ** cnt_2
if p == 1 and cnt_1 == 0:
    ans = 0
print(ans)


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

int main(){
    int Ta, Th, Aa, Ah;
    cin >> Th >> Ta >> Ah >> Aa;
    bool f = 1;
    while(Th > 0 && Ah > 0){
        if(f){
            Ah -= Ta;
            f = !f;
        }
        else{
            Th -= Aa;
            f = !f;
        }
    }
    if(Th > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
import math
Q = int(input())

ps = []
maxfac = math.sqrt(10**5)
nums = [i+1 for i in range(1, 10**5)]
while True:
    p = nums[0]
    if maxfac <= p:
        break
    ps.append(p) 
    nums = [num for num in nums if num % p != 0]

ps = set(ps + nums)

c = [0] * 10**5
for i in range(3, 10**5+1, 2):
    if i in ps and (i+1)//2 in ps:
        c[i] = 1

from itertools import accumulate
cs = list(accumulate(c))

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

Measured memory_bytes: 8984
#include <stdio.h>

int main (void)
{
    int mountain[10], i;
    int first, second, third;
    int fflag, sflag, tflag;

    for (i = 0; i < 10; i++) scanf("%d", &mountain[i]);
    
    first = mountain[0];
    second = mountain[0];
    third = mountain[0];

    for (i = 0; i < 10; i++) if(mountain[i] >= first){
        first = mountain[i];
        fflag = i;
    }
    
    if (fflag == 0) second = mountain[1];

    for (i = 0; i < 10; i++) if (mountain[i] >= second && mountain[i] <= first && i != fflag){
        second = mountain[i];
        sflag = i;
    }
    //printf("fflag %d sflag %d\n", fflag, sflag);
    if (fflag == 0 || sflag == 0) third = mountain[1];
    if (fflag == 1 || sflag == 1) third = mountain[2];
    for (i = 0; i < 10; i++) if (mountain[i] >= third && mountain[i] <= second && i != fflag && i != sflag){
        third = mountain[i];
        tflag = i;
    }
    
    printf("%d\n%d\n%d\n", first, second, third);

    return (0);
}


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

int main()
{
    long n, m, s, c;
    long a[4] = {-1, -1, -1, -1};
    bool flag = false;

    std::cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        std::cin >> s >> c;
        if ((n != 1 && s == 1 && c == 0) || (a[s] != -1 && a[s] != c))
        {
            flag = true;
            break;
        }
        a[s] = c;
    }
    if (!flag)
    {
        for (int i = 0; i < n; i++)
        {
            if (i == 0 && a[i + 1] == -1 && n != 1)
            {
                std::cout << 1;
            }
            else
            {
                std::cout << (a[i + 1] == -1 ? 0 : a[i + 1]);
            }
        }
    }
    else
    {
        std::cout << -1;
    }
    std::cout << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  vll b1(50);
  vll b0(50);
  sort(all(a));
  rep(i,n){
    bitset<50> g(a[i]);
    
    for(int j=0;j<50;j++){
      if(g.test(j)){
        b1[j]++;
      }
      else{
        b0[j]++;
      }
    }
  }
  ll bi=max(a[n-1],k);
  bitset<50> bb(bi);
  ll j=49;
  while(1){
    if(bb.test(j))break;
    j--;
  }
  bitset<50> kk(k);
  ll cu=1;
  ll ans=0;
  ll s=modpow(2,j,INF);
  for(int i=j;i>=0;i--){
    if(cu&&!kk.test(i)){
      ans+=b1[i]*s;
      s/=2;
    }
    else if(cu&&kk.test(i)){
      if(b1[i]>b0[i]){
        ans+=b1[i]*s;
        s/=2;
        cu=0;
      }
      else{
        ans+=b0[i]*s;
        s/=2;
      }
    }
    else{
      ans+=max(b1[i],b0[i])*s;
      s/=2;
    }
  }
  COUT(ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int n;
    int a[100];
    int free = 0, ans = 0;
    bool color[8] = {false};

    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] >= 3200) ++free;
        else color[a[i] / 400] = true;
    }
    
    for(int i = 0; i < 8; ++i)
        if(color[i]) ++ans;
    
    if(ans == 0)
        cout << "1 " << free << "\n";
    else
        cout << ans << " " << free + ans << "\n";

    return 0;
}

Measured memory_bytes: 256
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
using namespace std;
typedef long long ll;

inline ll read() {
    ll X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

inline ll f(ll n,ll a,ll b) { ll res=0;
    res+=a-1,b-=a-1,a=1;
    if (a==b) return res;
    ++res,--b;
    return res+((b-a)>>1);
}

int main() {
    ll n=read(),a=read(),b=read();
    if ((a&1)^(b&1)) {
        printf("%lld\n",min(f(n,a,b),f(n,n-b+1,n-a+1)));
    } else {
        printf("%lld\n",(b-a)>>1);
    }
    return 0;
}


Measured memory_bytes: 256
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int n,x,t;cin>>n>>x>>t;cout<<(n+x-1)/x*t;
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 3616
wf = input()
rwf = wf[::-1]

wl = wf[0:int((len(wf)-1)/2)]
rwl = wl[::-1]

wr = wf[int((len(wf)+3)/2-1):len(wf)]
rwr = wr[::-1]

if wf == rwf and wl == rwl and wr == rwr:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        double res = 0;
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
         res  =  (arr[0]+arr[1])/2.0;
        for(int i = 2;i<n;i++)
        {
            res = (res + arr[i] )/ 2.0;
        }
        System.out.println(res);


    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
using ll = long long;
int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	ll d = a - k;
	k = k - a;
	d = (d < 0) ? 0 : d;
	k = (k < 0) ? 0 : k;
	ll e = b - k;
	e = (e < 0) ? 0 : e;
	cout << d << " " << e << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }


int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];

int dist(int x1,int y1,int x2,int y2)
{
    int dx=x2-x1;int dy=y2-y1;
    float ans=sqrt(dx*dx+dy*dy);
    return ceil(ans);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,n;
    cin>>h>>n;
    vector<int>vec(n);
    ll sum=0;
    REP(i,n)
    {
        cin>>vec[i];
        sum+=vec[i];
    }
    if(sum>=h)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll calc(ll x,ll y){

	if(x < y)swap(x,y);

	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}


int main(){

	int H,h,m,s;

	while(true){
		scanf("%d %d %d %d",&H,&h,&m,&s);
		if(H == 0 && h == 0 && m == 0 && s == 0)break;

		ll bunbo = 119*H-1;
		ll bunshi = s*bunbo;
		ll h0 = h;
		ll m0 = m;
		ll deg_h,deg_m,deg_s,diff_1,diff_2;
		ll base;

		while(true){

			base = 3600*H*bunbo;

			deg_h = (3600*h0*bunbo+60*m0*bunbo+bunshi)%base;
			deg_m = (60*H*m0*bunbo+bunshi*H)%base;
			deg_s = (60*H*bunshi)%base;

			if(deg_h != deg_m){
				diff_1 = (deg_s-deg_h+base)%base;
				diff_2 = (deg_m-deg_s+base)%base;
				if(diff_1 == diff_2)break;
			}

			bunshi++;
			if(bunshi/60 == bunbo) {
				bunshi = 0;
				m0++;
			}
			if(m0 == 60) {
				m0 = 0;
				h0++;
			}
			if(h0 == H) {
				h0 = 0;
			}
		}
		ll common = calc(bunshi,bunbo);
		bunshi /= common;
		bunbo /= common;

		printf("%lld %lld %lld %lld\n",h0,m0,bunshi,bunbo);
	}
	return 0;
}



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

int main() {
  int N, M, A, B;
  cin >> N >> M;
  vector<vector<string>> date(N, vector<string>(M));
  for(int i = 0; i < N; i++){
      for(int k = 0; k < M; k++){
        cin >> date.at(i).at(k);
      }
  }
  for(int i = 0; i < N; i++){
      for(int k = 0; k < M; k++){
          if(date.at(i).at(k) == "snuke"){
              A = i;
              B = k+65;
              cout << (char)B << A+1 << endl;
          }
      }
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    long double n,d;
    cin >> n >> d;

    int count=0;
    for (long double i=0;i<=n-1;i++)
    {
        long double a,b;
        cin >> a >> b;

        long double local=(long double)pow((pow(a,2)+pow(b,2)),0.5);
        if (local<=d)
        {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3872
N = int(input())
a = [0] + list(map(int, input().split()))
b = [0] * (N + 1)
c = []
for i in range(N, 0, -1):
    sum_i = 0
    for j in range(i+i, N+1, i):
        sum_i += b[j]
    b[i] = (a[i] + sum_i)%2
print(sum(b))
for k in range(N+1):
    if b[k] == 1:
        c.append(k)
if c != []:
    print(' '.join(map(str, c)))


Measured memory_bytes: 81128
import sys
input = sys.stdin.readline
n = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse = True)
    return divisors
#print(make_divisors(n))
if n != 1:
    ans = float('inf')
    p = 1 if len(make_divisors(n))%2 == 1 else 0
    for i in range(len(make_divisors(n))//2+p):
        ans = min(ans, make_divisors(n)[i])
    print(len(str(ans)))
else:
    print(1)


Measured memory_bytes: 41564
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;


int main() {
	string S;
	cin >> S;
	if (S.length() == 2) cout << S << endl;
	else if(S.length()==3){
		char a = S[2];
		S[2] = S[0];
		S[0] = a;
		cout << S << endl;
	}

	return 0;
}

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



int main(void) {
  int N;
  int A[100];
  double ans = 0;

  scanf("%d", &N);
  for (int i=0;i<N;i++) {
    scanf("%d", A+i);
    ans += 1.0 / A[i];
  }

  printf("%f", 1.0 / ans);
  return 0;
}

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

int main() {
  int n; cin >> n;
  ll ans=1;
  vector<ll> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  // 0が含まれていたら問答無用で0
  for(auto v: a) {
    if(v==0) {
      cout << "0" << endl;
      return 0;
    }
  }
  for(auto v: a) {
    ans*=v;
    if(ans<=0 || ans>(ll)1e18) {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4052
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	a := intScanner()
	b := intScanner()
	c := intScanner()
	d := intScanner()
	x := c / b
	if c%b != 0 {
		x++
	}
	y := a / d
	if a%d != 0 {
		y++
	}
	if x <= y {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1756
#include<iostream>
#include <vector>
#include<algorithm>

using namespace std;
#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)

typedef pair<int, int> P;

bool pairCompare(const P &firstElof, const P &secondElof) {
    return firstElof.first < secondElof.first;
}

int main(void) {
    int N, T;
    vector<pair<int, int >> cost;
    cin >> N >> T;
    rep(i, 0, N) {
        P inp;
        cin >> inp.first >> inp.second;
        if (inp.second <= T) {
            cost.push_back(inp);
        }
    }

    if (cost.empty()) {
        cout << "TLE" << endl;
    } else {
        sort(cost.begin(), cost.end(), pairCompare);
        cout << cost.front().first << endl;
    }
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int mod = 1e9+7;
struct Mint {
    int val;
    Mint inv() const {
        int tmp, a = val, b = mod, x = 1, y = 0;
        while(b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
        return Mint(x);
    }
public:
    Mint() :val(0) {}
    Mint(ll x) :val(x >= 0 ? x % mod : x % mod + mod) {}
    int mtoi() { return this->val; }
    Mint pow(ll t) { Mint res = 1,b = *this; while(t){if(t&1)res *= b;b *= b;t >>= 1;}return res; }
    Mint& operator+=(const Mint& x) { if ((val += x.val) >= mod) val -= mod; return *this; }
    Mint& operator-=(const Mint& x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; }
    Mint& operator*=(const Mint& x) { val = (ll)val * x.val % mod; return *this; }
    Mint& operator/=(const Mint& x) { return *this *= x.inv(); }
    bool operator==(const Mint& x) const { return val == x.val; }
    bool operator!=(const Mint& x) const { return val != x.val; }
    bool operator<(const Mint& x) const { return val < x.val; }
    bool operator<=(const Mint& x) const { return val <= x.val; }
    bool operator>(const Mint& x) const { return val > x.val; }
    bool operator>=(const Mint& x) const { return val >= x.val; }
    Mint operator+(const Mint& x) const { return Mint(*this) += x; }
    Mint operator-(const Mint& x) const { return Mint(*this) -= x; }
    Mint operator*(const Mint& x) const { return Mint(*this) *= x; }
    Mint operator/(const Mint& x) const { return Mint(*this) /= x; }
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx) {
        Fact.resize(maxx+1,Mint(1)),Finv.resize(maxx+1); rep(i,0,maxx)Fact[i+1]=Fact[i]*Mint(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*Mint(i);
    }
    Mint fact(int n,bool inv) { if(inv) return Finv[n]; else return Fact[n]; }
    Mint nPr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[n-r]; }
    Mint nCr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

int main(){
    int n; scanf("%d",&n);
    string s; cin>>s;
    bool lr[200010],pre=1;
    lr[0]=pre;
    rep(i,1,2*n){
        if(s[i-1]==s[i])pre^=1;
        lr[i]=pre; 
    }
    int sum=0; Mint ans=1;
    rep(i,0,2*n){
        if(lr[i])sum++;
        else{
            ans*=sum; sum--;
        }
        if(sum<0){
            printf("0"); return 0;
        }
    }
    if(sum||s[0]=='W'||s.back()=='W'){
        printf("0"); return 0;
    }
    rep(i,1,n+1)ans*=Mint(i);
    printf("%d\n",ans.mtoi());
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

void solve(){
    ll A,B,K; cin>>A>>B>>K;
    if(A>=K) A-=K;
    else{
        B=max(B-(K-A),0ll);
        A=0;
    }
    cout<<A<<" "<<B<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=0;i<n+1;i++){
        cin>>a[i];
    }
    vector<int> b(n);
    
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        int bcopy=b[i];
        int temp=min(a[i],b[i]);
        a[i]-=temp;
        b[i]-=temp;
        int temp1=min(a[i+1],b[i]);
        a[i+1]-=temp1;
        b[i]-=temp1;
        sum+=bcopy-b[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define MAX 10000

typedef struct node{
	int parent,left,right;
}Node;

void setDepth(int,int);
int setHeight(int);
int getSobling(int);
void print(int);


Node tree[MAX];
int n,depth[MAX],height[MAX];

int main(){
	int i,j,v,l,r,root = 0;
	scanf("%d",&n);

	for(i=0;i<n;i++){
		tree[i].parent = -1;
	}
	for(i=0;i<n;i++){
		scanf("%d%d%d",&v,&l,&r);
		tree[v].left = l;
		tree[v].right = r;
		if(l != -1)tree[l].parent = v;
		if(r != -1)tree[r].parent = v;
	}

	for(i=0;i<n;i++){
		if(tree[i].parent == -1) root = i;
	}

	setDepth(root,0);
	setHeight(root);

	for(i=0;i<n;i++){
		print(i);
	}


		return 0;

}



void setDepth(int u,int d){
	if(u == -1)return;
	depth[u] = d;
	setDepth(tree[u].left,d+1);
	setDepth(tree[u].right,d+1);
}	


int setHeight(int u){
	int h1=0,h2=0;
	if(tree[u].left != -1)
		h1 = setHeight(tree[u].left) + 1;
	if(tree[u].right != -1)
		h2 = setHeight(tree[u].right) + 1;
	return height[u] = (h1>h2 ? h1 : h2);
}

int getSobling(int u){
	if(tree[u].parent == -1)return -1;
	if(tree[tree[u].parent].left != u && tree[tree[u].parent].left != -1)
		return tree[tree[u].parent].left;
		if(tree[tree[u].parent].right != u && tree[tree[u].parent].right != -1)
			return tree[tree[u].parent].right;
		return -1;
}

void print(int u){
	int deg = 0;

	printf("node %d: ",u);
	printf("parent = %d, ",tree[u].parent);
	printf("sibling = %d, ",getSobling(u));
	if(tree[u].left != -1)deg++;
	if(tree[u].right != -1)deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",depth[u]);
	printf("height = %d, ",height[u]);

	if(tree[u].parent == -1){
		printf("root\n");
	}else if(tree[u].left == -1 && tree[u].right == -1){
		printf("leaf\n");
	}else{
		printf("internal node\n");
	}
	
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
typedef long long ll;
int n, m, x;

int arr[30][10];
int main()
{
    set<int> s;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)scanf("%d", &arr[i][j]);
    }
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d", &x);
        s.insert(x);
    }
    int flag = 0;
    for(int i=0;i<3;i++){
        if(s.count(arr[i][0]) > 0 && s.count(arr[i][1]) > 0 && s.count(arr[i][2]) > 0)flag = 1;
        if(s.count(arr[0][i]) > 0 && s.count(arr[1][i]) > 0 && s.count(arr[2][i]) > 0)flag = 1;
    }
    if(s.count(arr[0][0]) > 0 && s.count(arr[1][1]) > 0 && s.count(arr[2][2]) > 0)flag = 1;
    if(s.count(arr[0][2]) > 0 && s.count(arr[1][1]) > 0 && s.count(arr[2][0]) > 0)flag = 1;
    printf("%s\n", flag == 1 ? "Yes" : "No");
    return 0;
}


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

int main(){

  int n,k,x[100010];

  cin>>n>>k;
  for(int i=0;i<n;++i)cin>>x[i];

  int ans=1e9,r;

  for(int i=0;i<=n-k;++i){
    r=i+k-1;
    if(x[i]<=0&&x[r]<=0){
        ans=min(ans,-x[i]);
    }else if(x[i]>=0&&x[r]>=0){
        ans=min(ans,x[r]);
    }else{
        ans=min(ans,min(x[r]-2*x[i],2*x[r]-x[i]));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	vector<int> d(n);
	rep(i,n)cin>>d[i];
	sort(d.begin(),d.end());
	if(n%2==0){
		cout<<d[n/2]-d[n/2-1]<<endl;
	}else{
	}
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    double A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A, A+N);
    ll ans = 0;

    double median;
    if(N%2 == 0){
        ans += (A[N/2] - A[N/2 - 1]);
        median = (A[N/2] + A[N/2 - 1])/2;
        for(int i = 0; i < N; i++){
            if(i == N/2 || i == N/2 - 1)
                continue;
            ans += abs(A[i] - median)*2;
        }
        cout << ans << "\n";
        return 0;
    }
    else{
        median = A[N/2];
        for(int i = 0; i < N; i++){
            if(i == N/2 - 1 || i == N/2 +1)
                continue;
            ans += abs(A[i] - median)*2;
        }
        ans += max(abs(A[N/2 - 1] - median)*2 + abs(A[N/2 + 1] - median),
                    abs(A[N/2 - 1] - median) + abs(A[N/2 + 1] - median)*2 );
        cout << ans << "\n";
        return 0;
    }
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c){
	stack<int> S;
	S.push(r);
	color[r] = c;
	while (!S.empty()){
		int u = S.top(); S.pop();
		for(int i = 0; i < G[u].size(); i++){
			int v = G[u][i];
			if(color[v] == NIL){
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor(){
	int id = 1;
	for(int i = 0; i<n; i++) color[i] = NIL;
	for(int u = 0; u<n; u++){
		if(color[u] == NIL)dfs(u,id++);
	}
}

int main(){
	int s,t,m,q;
	
	cin >> n >> m;
	
	for(int i = 0; i < m; i++){
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	
	assignColor();
	
	cin >> q;
	
	for(int i = 0; i < q; i++ ){
		cin >> s >> t;
		if(color[s] == color[t]){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	
	return 0;
}

	









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

int main(){
  int n, m, q;
  cin >> n >> m;
  vector<int> g[n];
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin >> q;
  vector<int> v(q), d(q), c(q);
  rep(i,q) {
    cin >> v[i] >> d[i] >> c[i];
    v[i]--;
  }
  reverse(v.begin(),v.end());
  reverse(d.begin(),d.end());
  reverse(c.begin(),c.end());
  
  vector<int> color(n,0);
  vector<int> dist(n,-1);

  rep(i,q){
    queue<P> que;
    que.push(P(v[i],d[i]));
    while(!que.empty()){
      P p = que.front();
      que.pop();
      if(color[p.first] == 0) color[p.first] = c[i];
      dist[p.first] = p.second;
      rep(j,g[p.first].size()){
        if(p.second-1 > dist[g[p.first][j]]) {
          que.push(P(g[p.first][j],p.second-1));
        }
      }
    }
  }
  rep(i,n) cout << color[i] << endl;
  return 0;
}

Measured memory_bytes: 8912
n, q = [int(i) for i in input().split(" ")]
s = input()
ss = [0] * (n + 1)

for i in range(2, n + 1):
    ss[i] = ss[i - 1] + (1 if s[i - 2:i] == "AC" else 0)

l = [0] * q
r = [0] * q

for i in range(0, q):
    li, ri = [int(i) for i in input().split(" ")]
    l[i] = li
    r[i] = ri
    
for i in range(0, q):
    print(ss[r[i]] - ss[l[i]])

Measured memory_bytes: 15748
function Main(input) {
input = input.split("\n");//行ごとに分解して配列にする。一行の時は"\n"を" "にして三行目を消そう
//適当な変数　= input[複数の要素がある行].split(" ");//複数の要素がある行が無いときはいらない
//省略。
var a = input[0];

length = a.length;  
  
//本題の処理
if(a[length - 1] == "s"){
	result = a + "es";	  
}else{
  result = a + "s";
}
console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));//おまじない

Measured memory_bytes: 29680
#include <bits/stdc++.h>
using namespace std;
 #define MAX 1000000000005
 #define ll long long int
 int main()
 {    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


        long long int m,sum=0,k=0,i,j,x=0,sum1=0,l,kk,y,z,e,f,q=MAX,r=MAX,n;
           ll a,b,c,d,zz=1;
            string s;
             cin>>s;
              if(s[s.size()-1]=='s')
                 cout<<s<<"es";
              else
                cout<<s<<"s";
              


 }



Measured memory_bytes: 3636
# D
import numpy as np

N, C = map(int, input().split())

C_cost_mat = np.zeros((C, C), dtype="int32")
now_mat = np.zeros((3, C), dtype="int32")

for i in range(C):
    c_list = list(map(int, input().split()))
    for j in range(C):
        C_cost_mat[i][j] = c_list[j]
        
for i in range(N):
    c_list = list(map(int, input().split()))
    for j in range(N):
        now_mat[(i + j + 2) % 3, c_list[j] - 1] += 1
        
res_mat = np.dot(now_mat, C_cost_mat)

res = 1000*N*N
for i1 in range(C):
    for i2 in range(C):
        for i3 in range(C):
            if i1 != i2 and i2 != i3 and i3 != i1:
                res = min(res, res_mat[0, i1] + res_mat[1, i2] + res_mat[2, i3])
print(res)

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 n;
  cin >> n;
  map<int64,vector<int64>> mp;
  REP(i,n){
    int64 a;
    cin >> a;
    mp[a].pb(i);
  }
  mp[0].pb(-1);
  vector<int64> ans(n);
  int64 pre = n-1;
  int64 presz = 0;
  int64 cnt = 0;
  for(auto iter = mp.rbegin(); iter != mp.rend(); ++iter){
    ans[pre] += cnt * (presz - iter->first);
    presz = iter->first; 
    pre = min(pre,iter->second.front());
    cnt += iter->second.size();
  }
  REP(i,n)ANS(ans[i]);
  return 0;
}

Measured memory_bytes: 12800
def CountBall_158():
    N, A, B = [int(_) for _ in input().split()]
    X = int(N / (A + B))
    Y = int(N % (A + B))
    if Y > A:
        Y = A
    print(A * X + Y)

if __name__ == "__main__":
    CountBall_158()

Measured memory_bytes: 2940
N=int(input())

tree_list = []
for i in range(N):
  tree_list.append([])

for i in range(N-1):
  ui,vi,wi=map(int,input().split())
  tree_list[ui-1].append((vi-1,wi%2))
  tree_list[vi-1].append((ui-1,wi%2))

paint_list = [-1]*N
paint_list[0] = 0
queue = [0]
while(True):
  if len(queue) == 0:
    break  
  
  new_queue = []
  for q in queue:
    for u,w in tree_list[q]:
      if paint_list[u] == -1:
        paint_list[u] = paint_list[q]^w
        new_queue.append(u)
  queue = new_queue  
    
for i in paint_list:
  print(i)


Measured memory_bytes: 35628
#include <bits/stdc++.h>
#define ff first
#define ss second
#define M 1000000007
#define mp(a, b) make_pair(a, b)
#define pb push_back


using namespace std;

int main() {

    int n, h[100009], m[100009], i, k, j;
    cin>>n>>k;
    for(i=0;i<n; i++)   { m[i+1]=INT_MAX; cin>>h[i];}

    m[1]=0;

    for(i=2; i<=n; i++) {
        for(j=max(1, i-k) ; j<=i-1; j++) {
            m[i]=min(m[i], m[j]+abs(h[i-1]-h[j-1]));
        }

    }
    cout<<m[n];

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    string s;
    cin >> s;
    string ans="";
    string tmp="";
    for(int i=0; i<=s.length(); i++){
        if(i<s.length() && (s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C')){
            tmp+=s[i];
        }else{
            if(tmp.length()>ans.length()){
                ans=tmp;
            }
            tmp="";
        }
    }
    cout<<ans.length()<<endl;
    return 0;
}


Measured memory_bytes: 256
import random

D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]

ans=[random.randint(1,26) for i in range(D)]
res=0
for i in range(D):
    res+=s[i][ans[i]-1]

last=[0]*26
for i in range(D):
    last[ans[i]-1]=i+1
    minus=sum(c[j]*(i+1-last[j]) for j in range(26))
    res-=minus

for i in range(D):
    print(ans[i])


Measured memory_bytes: 78180
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

#define MAX_V (105)
#define INF (2e9 + 5)
ll G[MAX_V][MAX_V];

int main()
{
    int V, E;

    scanf("%d %d", &V, &E);
    for ( int i = 0; i < V; i++ ) {
	for ( int j = 0; j < V; j++ ) {
	    G[i][j] = ( i == j ) ? 0 : INF;	// ?????????
	}
    }
    
    for ( int i = 0; i < E; i++ ) {
	int s, t, d;
	scanf("%d %d %d", &s, &t, &d);
	// ????????°??????
	G[s][t]  = d;
    }

    for ( int k = 0; k < V; k++ ) {
	for ( int i = 0; i < V; i++ ) {
	    if ( G[i][k] == INF ) continue;
	    for ( int j = 0; j < V; j++ ) {
		if ( G[k][j] == INF ) continue;
		G[i][j] = min( G[i][j], G[i][k] + G[k][j] );
	    }
	}
    }
    
    // ?????????????????????????¢??????????
    bool negative_cycle = false;
    for ( int i = 0; i < V; i++ ) {
	if ( G[i][i] < 0 ) {
	    negative_cycle = true;
	    break;
	}
    }
    
    if ( negative_cycle ) printf("NEGATIVE CYCLE\n");
    else {
	for ( int i = 0; i < V; i++ ) {
	    for ( int j = 0; j < V; j++ ) {
		if ( G[i][j] == INF ) printf("INF");
		else printf("%lld", G[i][j]);
		printf("%c", (j == V-1) ? '\n' : ' ');
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 1112
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define in(v) v; cin >> v;
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
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;}

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define repi(i,a,b) for(int i=(a),_i=(b);i<_i;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define _rrep2(i,n) for(int i=(n);i>=0;--i)
#define _rrep3(i,b,a) for(int i=(b);i>=a;--i)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debugln() {cerr << "\n";}
template<class First> void debugln(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debugln(const First& first, const Rest&... rest) {cerr<<first<<",";debugln(rest...);}
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<" ";debug(rest...);}
#else
#define debug(...) 42
#define debugln(...) 42
#endif

int main() {
  string in(S);
  int N = S.size();
  vector<int> amari(N+1, 0), amari2(N+1, 0);
  map<int, int> ms;
  rep(i, N) {
    amari[i+1] = amari[i] * 10 + (S[i]-'0');
    amari[i+1] %= 2019;
  }
  debugln(amari);

  int tmp2 = 1;
  rrep(i, N-1) {
    amari2[i] = tmp2 * (S[i]-'0') + amari2[i+1];
    amari2[i] %= 2019;
    tmp2 *= 10;
    tmp2 %= 2019;
  }
  debugln(amari2);

  int ans = 0;
  ++ms[0];
  rep(i, N) {
    ans += ms[amari2[i]];
    ++ms[amari2[i]];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5140
#!/usr/bin/ruby
cx,cy,r=gets.split.map(&:to_f)
gets.to_i.times{
	x1,y1,x2,y2=gets.split.map(&:to_f)
	if x1==x2
		#(x1 - cx)^2 + (y - cy)^2 = r^2
		#y^2 - 2cyy + cy^2 + (x1 - cx)^2 - r^2 = 0
		d=cy**2-(cy**2+(x1-cx)**2-r**2)
		y=[cy-Math.sqrt(d),cy+Math.sqrt(d)]
		puts [x1,y[0],x1,y[1]]*' '
	else
		a=(y2-y1)/(x2-x1)
		b=y1-a*x1
		#(x - cx)^2 + (ax + b-cy)^2 = r^2
		#x^2 - 2cxx + cx^2 + (ax)^2 + 2a(b-cy)x + (b-cy)^2 = r^2
		#(a^2+1)x^2 + (2ab-2acy-2cx)x + cx^2 + (b-cy)^2 - r^2 = 0
		s=a**2+1
		t=2*a*b-2*a*cy-2*cx
		u=cx**2+(b-cy)**2-r**2
		d=t**2-4*s*u
		x=[(-t-Math.sqrt(d))/2/s,(-t+Math.sqrt(d))/2/s]
		y=x.map{|e|a*e+b}
		puts [x[0],y[0],x[1],y[1]]*' '
	end
}

Measured memory_bytes: 6184
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int sum = 1;
    int sol = 0;
    while (sum < b)
    {
        sum += a;
        sum -= 1;
        sol++;
    }
    cout << sol;
}


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

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

int main(){

    ll N, K;
    cin >> N >> K;

    vector<ll > vec(N, 0);
    for(ll i = 0; i < N; i++){
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());

    ll ans = 0;
    for(ll i = 0; i < N - 1;){
        if(vec[i] != vec[i+1]){
            ans++;
            i += K - 1;
        }else{
            i++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <cstdio>

int n;
int a[105];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		printf("%d%c",a[i],i==n-1?'\n':' ');
	}
	for(int i=1;i<=n-1;i++){
		int v=a[i];
		int j=i-1;
		while(j>=0 && a[j]>v){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		for(int k=0;k<n;k++){
			printf("%d%c",a[k],k==n-1?'\n':' ');
		}
	}
	return 0;
}

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

int main(){
  int n,a,l,ans;
  ans = 0;
  cin >> n;
  for(int i = 0; i < n ;i++){
    cin >> l >> a;
    ans = ans + a - l + 1;
  }
  cout << ans << endl;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll dp[101010];

int main()
{
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];

    const ll inf = 1e10;
    fill(dp, dp+N+10, inf);

    dp[0] = 0;
    rep(i, N) {
        if (i+1<N) dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        if (i+2<N) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }

    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 1408
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val table = Array(n, { readLine()!! })
  fun isValid(d: Int): Boolean {
    for (y in 0 until n) {
      for (x in 0 until n) {
        val x2 = (y + n - d) % n
        val y2 = (x + n + d) % n
        if (table[y][x] != table[y2][x2]) {
          return false
        }
      }
    }
    return true
  }

  var ans = 0
  for (d in (-n + 1)..(n - 1)) {
    if (isValid(d)) {
      val count = n - java.lang.Math.abs(d)
      ans += count
    }
  }

  println(ans)
}

Measured memory_bytes: 37212