akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;

typedef int Weight;
typedef int Flow;

struct Edge {
  int src, dest, rev;
  Flow cap;
  Weight cost;
  bool operator < (const Edge &rhs) const {
    return cost > rhs.cost;
  }
  Edge(int s, int d) : src(s), dest(d) { ; }
  Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
// Verifed by AOJ 1163
// O(V(V+E))
bool augment(const Graph& g, int u, vector<int>& matchTo, vector<bool>& visited){
  if(u < 0) return true;
  for(Edge e: g[u]) if(!visited[e.dest]){
      visited[e.dest] = true;
      if(augment(g, matchTo[e.dest], matchTo, visited)){
	matchTo[e.src] = e.dest;
	matchTo[e.dest] = e.src;
	return true;
      }
    }
  return false;
}

int bipartiteMatching(const Graph& g, int L, Edges& matching){
  // 0, ..., L-1: left vertices set
  // L, ..., n-1: right vertices set
  // matching: the edges used in matching
  int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L){
    vector<bool> visited(n, false);
    if(augment(g, u, matchTo, visited)) match++;
  }
  REP(u, L) if(matchTo[u] >= 0){
    matching.push_back(Edge(u, matchTo[u]));
  }
  return match;
}

double dist(double ax,double ay,double bx, double by){
  return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
}
int main(void)
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(!n&&!m) return 0;
    vector<tuple<double,double,double> > troop;
    troop.resize(n);
    REP(i,n){
      double x,y,v;
      cin >> x >> y >> v;
      troop[i]=make_tuple(x,y,v);
    }
    vector<tuple<double,double> >base;
    base.resize(m);
    REP(i,m){
      double x,y;
      cin >> x >> y;
      base[i]=make_tuple(x,y);
    }
    vector<tuple<double,int,int> >edges;
    REP(i,n) REP(j,m){
      double tx,ty,tv,bx,by;
      tie(tx,ty,tv)=troop[i];
      tie(bx,by)=base[j];
      double co=dist(tx,ty,bx,by)/tv;
      edges.push_back(make_tuple(co,i,n+j));
    }
    SORT(edges);
    int l=0,r=edges.size();
    while(r-l>1){
      int piv=l+(r-l)/2;
      Graph g;
      Edges ma;
      g.assign(n+m,Edges());
      REP(i,piv){
	int tr,ba;
	tie(ignore,tr,ba)=edges[i];
	g[tr].push_back(Edge(tr,ba));
      }
      //cout << bipartiteMatching(g,n,ma) << endl;
      if(bipartiteMatching(g,n,ma)==m) r=piv;
      else l=piv;
    }
    double minco;
    tie(minco,ignore,ignore)=edges[l];
    cout << fixed << setprecision(10) << minco << endl;


  }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
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(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, T; cin >> N >> T;
  vector<int> t(N, 0);
  REP(i, N){
    cin >> t[i];
  }
  int s = 0, e = 0, ans = 0;
  REP(i, N){
    if(t[i] <= e){
      e = t[i] + T;
    }else{
      ans += e - s;
      s = t[i];
      e = s + T;
    }
  }
  ans += e - s;
  cout << ans << endl;
}

Measured memory_bytes: 1024
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

N = ir()
h0 = (3*N)//4
for h in range(h0,3501):
    n0 = (2*N*h)//(4*h-N)
    for n in range(n0,3501):
        if (N*h*n)%(4*h*n-N*(n+h)) == 0:
            print(h,n,(N*h*n)//(4*h*n-N*(n+h)))
            sys.exit()

Measured memory_bytes: 73188
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    n,d = map(int,input().split())
    lst = [0]*n
    for i in range(n):
        lst[i] = list(map(int,input().split()))
    ans = 0
    for i in range(n-1):
        for j in range(i+1,n):
            sum = 0
            for k in range(d):
                sum += (lst[j][k]-lst[i][k])**2
            if round(math.sqrt(sum))**2 == sum:
                ans +=1
    print(ans) 
    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}


Measured memory_bytes: 105068
#include<iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

void output(vector<int> B, int s) {
    rep(i, s - 1) cout << B.at(i) << " ";
    cout << B.at(s - 1) << endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);
    output(A, N);
    for(int i = 1; i <= N - 1; i++){
        int v = A.at(i);
        int j = i - 1;
        
        while(j >= 0 && A.at(j) > v){
            A.at(j + 1) = A.at(j);
            j--;
        }
        A.at(j + 1) = v;
        output(A, N);
    }
}


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

ll mod=10007;

ll maximum(ll a,ll b,ll c){
    ll ans=0;
    ans=max(ans,max(a,b));
    ans=max(ans,max(b,c));
    ans=max(ans,max(c,a));
    return ans;
}

ll i,j,k,l;
int main(){
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;//a:red  b:green  c:no_color
    //x:aのうち食べる個数　y:bのうち食べる個数
    priority_queue<ll> r;
    vector<ll> p(a),q(b);
    vector<ll> number;

    ll rnum;
    for(i=0;i<a;i++){cin>>p[i];}//p,q
    for(i=0;i<b;i++){cin>>q[i];}
    for(i=0;i<c;i++){cin>>rnum;r.push(rnum);}

    sort(p.begin(),p.end(),greater<ll>());//p,q sort
    sort(q.begin(),q.end(),greater<ll>());
    
    //とりあえず大きいものからnumberに入れる
    for(i=0;i<x;i++){
        number.push_back(p[i]);
    }
    for(i=0;i<y;i++){
        number.push_back(q[i]);
    }

    sort(number.begin(),number.end());

    i=0;
    ll ins;//無色のもののうちnumberより大きいものが有れば無色を採用
    while(r.top()>number[i] && r.size()!=0){
        number[i]=r.top();
        r.pop();
        i++;
    }

    ll ans=0;
    for(i=0;i<number.size();i++){
        ans+=number[i];
    }

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

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void code() {
    int n,k;
    cin>>n>>k;
    int ans=0;
    vector<int> A(n);
    for(int i=0; i<n; i++) {
        cin>>A[i];
    }
    for(int i=k; i<n; i++) {
        if(A[i]>A[i-k])
            cout << "Yes\n";
        else
            cout << "No\n";
    }

}

signed main() {
    std::ios_base::sync_with_stdio(false);
    int t=1;
    for(int i=0; i<t; i++) {
        code();
    }
}


Measured memory_bytes: 3984
#include <stdio.h>
#include <algorithm>

int a[100003];
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        a[l]++;
        a[r+1]--;
    }
    int ans = 0;
    int temp = 0;
    for(int i=1;i<=100000;i++)
    {
        temp += a[i];
        if(temp) ans++;
    }
    printf("%d", ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FASTIO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define ll long long int
#define F first
#define S second
#define pll pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vpii vector<pair<int,int> >
#define vvpii vector<vpii >
#define vpll vector<pair<ll,ll> >
#define vvpll vector<vpll >
#define pb push_back
#define MOD 1000000007
#define brk cout<<"\n";

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

struct compare {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F));
		else return (a.F < b.F);
	}
};

void add_self(ll &a, ll b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	FASTIO;
	ll n; cin >> n;
	vvl can(n, vl(n));
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			cin >> can[i][j];
		}
	}
	vl dp(1 << n);
	dp[0] = 1;
	for (ll mask = 0; mask < (1 << n) - 1; mask++) {
		ll men = __builtin_popcount(mask);
		for (ll i = 0; i < n; i++) {
			if (can[men][i] && !(mask & (1 << i))) {
				ll m2 = mask ^ (1 << i);
				add_self(dp[m2], dp[mask]);
			}
		}
	}
	cout << dp[(1 << n) - 1]; brk;

}

Measured memory_bytes: 16640
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

    map<int, int> d;

    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        if(d.find(tmp)!=d.end()){
            d[tmp]++;
        }
        else{
            d[tmp] = 1;
        }
    }
    cout << d.size() << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define last          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fr            first
#define sc            second
#define lcm(a,b)      (a*b)/__gcd(a,b)
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
#define endl          '\n'
using namespace std;
int main()
{
     ll n,cnt=0;
     cin>>n;
     ll a[n];
     com(i,n) cin>>a[i];
     sortI(a,n);
     
     com(i,n)
     {
          for(int j=i+1;j<n;j++)
          {
               for(int k=j+1;k<n;k++)
               {
                    if(a[i]<a[j] && a[j]<a[k] && a[i]+a[j]>a[k])
                         cnt++;
               }
          }
     }
     cout << cnt << endl;
}


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

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

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N;
long long arr [310], target = 0;

long long diffTest(long long x, long long y){
    if(y+x-2 < target || target%2 != abs(x-y)%2) {
        return -1;
    }
    long long otherBits = (x+y-target)/2;
    if(x < otherBits) {
        return -1;
    }
    for(int i = 0; i < 40; i++)
        if(((otherBits&(1ll<<i)) > 0) && ((target&(1ll<<i)) > 0)){
            return -1;
        }
    for(int i = 40; i > -1; i--)
        if((target&(1ll<<i)) > 0 && otherBits+(1ll<<i) <= x)
            otherBits += (1ll<<i);
    return x-otherBits;
}

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> arr[i];
        if(i > 1) target ^= arr[i];
    }
    long long x = arr[0], y = arr[1];
    if(y+x < target || target%2 != abs(x-y)%2) {
        cout << "-1\n";
        return 0;
    }
    long long otherBits = (x+y-target)/2;
    if(x < otherBits) {
        cout << "-1\n";
        return 0;
    }
    for(int i = 0; i < 40; i++)
        if(((otherBits&(1ll<<i)) > 0) && ((target&(1ll<<i)) > 0)){
            cout << "-1\n";
            return 0;
        }
    for(int i = 40; i > -1; i--)
        if((target&(1ll<<i)) > 0 && otherBits+(1ll<<i) <= x)
            otherBits += (1ll<<i);
    if(x-otherBits >= x) otherBits = x+1;
    cout << x-otherBits << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  string str;
  cin>>str;
  int len=str.size();
  if(str[len-1]=='s')
  {
    str+='e';
    str+='s';
    cout<<str<<endl;
  }
  else
  {
    str+='s';
    cout<<str<<endl;
  }
}

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

using namespace std;

int main(){
    string s;
    int a,z;

    cin>>s;
        for(int i=0;i<s.size();++i){
            if(s[i]=='A'){
                a=i;
                break;
            }
        }
            for(int i=a;i<s.size();++i){
                if(s[i]=='Z'){
                    z=i;
                }
            }
        cout<<z-a+1;
}

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

int main(){
  int l,r;
  cin>>l>>r;
  int minv=10000;
  if(l==0){
    cout<<0<<endl;
    return 0;
  }
  if(r/2019-(l-1)/2019>=1){
    cout<<0<<endl;
    return 0;
  }else if(r/673-(l-1)/673>=1 && r/3-(l-1)/3>=1){
    cout<<0<<endl;
    return 0;
  }else{
    for(int i=l;i<r;i++){
      for(int j=i+1;j<r+1;j++){
        minv=min(minv,(i%2019)*(j%2019)%2019);
      }
    }
  }
  cout<<minv<<endl;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(X: String, Y: String){
    when{
        X < Y -> '<'
        X == Y -> '='
        X > Y -> '>'
        else -> ' '
    }.let{println(it)}
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val X = sc.next()
    val Y = sc.next()
    solve(X, Y)
}



Measured memory_bytes: 31132
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    """
    cs = 0
    ret = []
    for v in it:
        cs += v
        ret.append(cs)
    return ret


X, Y, A, B, C = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))
Q = list(map(int, sys.stdin.buffer.readline().split()))
R = list(map(int, sys.stdin.buffer.readline().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

ps = sum(P[:X])
qs = sum(Q[:Y])
r_cum = cumsum(R)

x = X - 1
y = Y - 1

ans = ps + qs
# 何個着色するか
for cnt in range(1, min(X + Y, C) + 1):
    if x >= 0 and y >= 0 and P[x] < Q[y] or y < 0:
        ps -= P[x]
        x -= 1
    else:
        qs -= Q[y]
        y -= 1
    s = r_cum[cnt - 1] + ps + qs
    ans = max(ans, s)
print(ans)


Measured memory_bytes: 70380
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
int m,n,sum,a[maxn];
int main() {
	scanf("%d%d",&n,&m);
	for (int i = 1; i <= n; i++)
		scanf("%d",&a[i]), sum += a[i];
	sort(a + 1,a + n + 1,greater<int>());
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] * 4 * m < sum)
			break;
		else cnt++;
	}
	if (cnt < m) puts("No");
	else puts("Yes");
	return 0;
}

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

int main(){
	int x1,x2,x3,x4,x5;
	cin>>x1>>x2>>x3>>x4>>x5;
	if (x1==0){
		cout<<"1"<<endl;
	}
	if (x2==0){
		cout<<"2"<<endl;
	}
	if (x3==0){
		cout<<"3"<<endl;
	}
	if (x4==0){
		cout<<"4"<<endl;
	}
	if (x5==0){
		cout<<"5"<<endl;
	}
	return 0;
}



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

long long a, ans;
string b;

int main(){
	cin >> a >> b;
	string b1="";
	for (char c : b){
		if (c=='.') continue;
		b1.push_back(c);
	}
	long long bb=stoi(b1);
	cout << (a*bb)/100 << "\n";
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  char c1[4], c2[4], c3[4];
  unused = scanf("%s", c1);
  unused = scanf("%s", c2);
  unused = scanf("%s", c3);

  printf("%c%c%c", c1[0], c2[1], c3[2]);

  return 0;
}

Measured memory_bytes: 128
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def gcd(x: int, y: int) -> int:
    if x < y:
        return gcd(y, x)
    elif y == 0:
        return x
    else:
        return gcd(y, x % y)


def lcm(x: int, y: int) -> int:
    return x * y // gcd(x, y)


def main() -> None:
    n, m = [next_int() for _ in range(2)]
    s, t = [next_str() for _ in range(2)]
    l = lcm(n, m)
    dic = dict()

    for i, c in enumerate(s):
        j = i * l // n
        dic[j] = c

    for i, c in enumerate(t):
        j = i * l // m
        if j in dic and dic[j] != c:
            print(-1)
            return

    print(l)


if __name__ == '__main__':
    main()

Measured memory_bytes: 15228
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
    ll x , y ;
    cin >> x >> y ;
    ll low = x*2 ;
    ll high = x*4 ;
    if(y%2==0 && y>=low && y<=high){
        cout << "Yes";
        return ;
    }
    cout << "No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    int case1 = 1 ;
    while(t--){
        //cout << "Case #" << case1 << ": " ;
        case1++;
        solve( );
    }
}


Measured memory_bytes: 3644
import itertools

k = int(input())
comb = list(itertools.combinations_with_replacement([i for i in range(1,k+1)], 3))
ans = 0
for a,b,c in comb:
  permutation = len(set([a,b,c]))
  r = b % a
  while r > 0:
    b = a
    a = r
    r = b % a
    
  r = c % a
  while r > 0:
    c = a
    a = r
    r = c % a
    
  if permutation == 3:
    ans += 6 * a
  elif permutation == 2:
    ans += 3 * a
  else:
    ans += a
    
print(ans)

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

int main(){
    long long N;
    scanf("%lld", &N);
    long long h, p(0), ans(0);
    for(int i = 0; i < N; ++i){
        scanf("%lld", &h);
        if(h > p)ans += h - p;
        swap(h, p);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
	int r;
	r = a % b;
	if(r==0)
		return b;
	else
		return gcd(b,r);
}
int main(){
	int a,b;
	while(cin >> a >> b){
		int result = gcd(a,b);
		int lcm = a*(b/result);
		cout << result << " " << lcm << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

import static java.lang.Integer.parseInt;

/**
 * Princess's Gamble
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int N, M;
			N = parseInt(line.substring(0, line.indexOf(' ')));
			M = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((N | M) == 0) break;

			int[][] dp = new int[N][2];
			int expected = 0;

			for (int i = 0; i < N; i++) {
				line = br.readLine();
				dp[i][0] = parseInt(line.substring(0, line.indexOf(' ')));
				dp[i][1] = parseInt(line.substring(line.indexOf(' ') + 1));
				expected += dp[i][0] * dp[i][1];
			}

			Arrays.sort(dp, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return Integer.compare(o1[1], o2[1]);
				}
			});

			for (int i = N - 1; i >= 0; i--) {
				if (dp[i][0] <= M) {
					expected -= dp[i][0] * dp[i][1];
					M -= dp[i][0];
				} else if (dp[i][0] > M) {
					expected -= M * dp[i][1];
					M = 0;
				}
				if (M == 0) break;
			}

			System.out.println(expected);

		} //end while
	} //end main
}

Measured memory_bytes: 49644
N = int(input())
A = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(N-1):
    if A[i]<A[i+1]:
        if money >= A[i]:
            kabu = money//A[i]
            money = money%A[i]
    elif A[i]>A[i+1]:
        if kabu > 0:
            money += kabu*A[i]
            kabu = 0
if kabu>0:
    money += kabu*A[-1]
print(max(money,1000))

Measured memory_bytes: 61756
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

ll n,k;

vector <ll> v[MAXN];
ll fact[MAXN];
ll invfact[MAXN];
ll ans = 1;

ll modInverse(ll a)
{
	ll m = MOD;
	ll y = 0, x = 1;
	if (m == 1)
		return 0;
	while (a > 1)
	{
		ll q = a / m;
		ll t = m;
		m = a % m, a = t;
		t = y;
		y = x - q * y;
		x = t;
	}
	if (x < 0)
		x += MOD;
	return x;
}

void setup()
{
	fact[0] = 1;
	for (int i = 1; i < MAXN; ++i)
		fact[i] = (fact[i-1] * i) % MOD;

	invfact[0] = 1;
	invfact[1] = 1;
	for (int i = 2; i < MAXN; ++i)
		invfact[i] = modInverse(fact[i]);
}

ll P(ll a, ll b)
{
	if(b == 0) return 1;
	if(b > a)
	{
		cout << 0 << endl;
		exit(0);
	}

	ll res = fact[a];
	res = (res * invfact[a-b]) % MOD;
	return res;
}

void dfs(int node, int par)
{
	if(node != 1)
		ans = (ans * P(k-2,v[node].size()-1)) % MOD;

	for (int i = 0; i < v[node].size(); ++i)
		if(v[node][i] != par)
			dfs(v[node][i], node);
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	
	cin >> n >> k;
	setup();
	for (int i = 0; i < n-1; ++i)
	{
		int a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}


	dfs(1,-1);


	ans = (ans * k) % MOD;
	ans = (ans * P(k-1,v[1].size())) % MOD;

	cout << ans << endl;
}

Measured memory_bytes: 13824
a = input()

N = len(a)
t = int((N-1)/2) #真ん中まで
hantei = True

for i in range(t):
  if a[i] == a[t-1-i]:
    hantei = True
  else:
    hantei = False

if hantei == False:
  print("No")
else:
  b = a[:t+1] + a[:t]
  if a == b:
    print("Yes")
  else:
    print("No")

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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

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

    println("A" << b[0] << "C");
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

//		long ans2 = 0;
		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int  n = sc.nextInt();
//		int  k = sc.nextInt();

//		int  k = sc.nextInt();
//		long d = sc.nextLong();

//		String string = sc.next();
//		StringBuilder s = new StringBuilder(string);

//		boolean f = true;
//
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = 0;
		}
//		for (int i = 0; i < k; i++) {
//			b[i] = sc.nextInt();
//		}
//		for (int i = 1; i <n; i++) {
//			b[i] = sc.nextInt();
//		}
//		int[][] c = new int[h][w];
//		for (int i = 0; i < h; i++) {
//			for(int j = 0; j < w; j++) {
//				c[i][j] = 0;
//			}
//		}

//		int tmp_a = 0;
//		int tmp_b = 0;
		int cnt=1;


		fool : for(int i = 0;i<n;i++) {
			b[a[i]-1] = i+1;
		}

		for(int i:b)
			System.out.println(i);

		sc.close();
	}
}

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

bool isPrime(int x) {
  if (x < 2) return false;
  for (int i = 2; i*i <= x; ++i) {
    if (x % i == 0) return false;
  }
  return true;
}

int N;

int main() {
  scanf("%d", &N);
  for (int i = 2; i <= 55555; ++i) {
    if (isPrime(i) && (i % 5) == 1) {
      printf("%d ", i);
      --N;
    }
    if (N == 0) break;
  }

  printf("\n");
  return 0;
}

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

int main(){
	string s,a,b,c;
	while(cin>>s){
		int p,e;
		p=s.find('+',0);
		e=s.find('=',p);
		a=s.substr(0,p);
		b=s.substr(p+1,e-p-1);
		c=s.substr(e+1);
		int lz=(1<a.size()&&a[0]=='X'||1<b.size()&&b[0]=='X'||1<c.size()&&c[0]=='X');
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		reverse(c.begin(),c.end());
		int ans;
		for(int i=lz;i<10;i++){
			int carry=0;
			ans=i;
			for(int j=0;j<126;j++){
				int x,y,z;
				x=a.size()<=j?0:a[j]=='X'?i:a[j]-'0';
				y=b.size()<=j?0:b[j]=='X'?i:b[j]-'0';
				z=c.size()<=j?0:c[j]=='X'?i:c[j]-'0';
				if((x+y+carry)%10!=z){
					ans=-1;
					break;
				}
				carry=(x+y+carry)/10;
			}
			if(ans!=-1)break;
		}
		if(ans==-1)cout<<"NA"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

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

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {



        public void Calc()
        {


            var N = Console.ReadLine()[0];

            Console.WriteLine((char)(N + 1));

        }
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
 
int takoyaki(int n,int x,int t){
  int a;
  if(n%x!=0)
    return (n/x+1)*t;
  else
    return (n/x)*t;
}
int main(void){
  int X,T,N;
  scanf("%d" "%d" "%d",&N,&X,&T);
  printf("%d\n",takoyaki(N,X,T));
  
  return 0;  
}  

Measured memory_bytes: 2104
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    S = input()
    if S == "AC":
        AC += 1
    elif S == "WA":
        WA += 1
    elif S == "TLE":
        TLE += 1
    else: 
        RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int n;
long long s[555555],a[555555],ans;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
        {
		int x;
		cin>>x;
		s[i]=s[i-1]+x;
		a[i]=a[i-1]^x;
	}
	int l=1;
	for (int r=1;r<=n;r++){
		for (;(s[r]-s[l-1])!=(a[r]^a[l-1]);l++);
		ans+=r-l+1;
	}
	printf("%lld\n",ans);
} 


Measured memory_bytes: 3840
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define P 1000000007

int main(void){
	int n, m, i;
	char a[100001];
	memset(a, 0, sizeof(a));
	int d[100001];
	scanf("%d%d", &n, &m);
	for(i=0; i<m; i++){
		int A;
		scanf("%d", &A);
		a[A]=1;
	}
	d[0]=1;
	d[1]=(a[1]==0?1:0);
	for(i=2; i<=n; i++){
		if(a[i]==0){
			d[i]=(d[i-2]+d[i-1])%P;
		}else d[i]=0;
	}
	printf("%d\n", d[n]);
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int n;
	cin >> n;
	REP(i, 10) {
		REP(j, 10) {
			if (n == i * j) {
				put("Yes");
				return 0;
			}
		}
	}
	put("No");
	return 0;
}


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

int main(){
    int m,n;
    cin >> m >> n;
    // nC2 + mC2
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    return 0;
}

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

void sort(long long int a[], int N){
  long long int buf;
  for(int i=0; i<N; i++){
    for(int j=0; j<N-1; j++){
      if(a[j]<a[j+1]){
        buf = a[j];
        a[j] = a[j+1];
        a[j+1] = buf;
      }
    }
  }
};

int main(void){

  int N,M;
  scanf("%d %d", &N, &M);

  long long int *x, *y, *z;
  x = (long long int*)malloc(N*sizeof(long long int));
  y = (long long int*)malloc(N*sizeof(long long int));
  z = (long long int*)malloc(N*sizeof(long long int));

  for(int i=0; i<N; i++){
    scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);
  }

  long long int *sum;
  sum = (long long int*)malloc(N*sizeof(long long int));

  long long int ans=0,buf=0;

  int coef[3];
  int rest;
  for(int rep=0; rep<8; rep++){
    buf = 0;
    for(int i=0; i<3; i++){
      rest=rep;
      for(int j=0; j<i; j++){
        rest = rest/2;
      }
      if(rest%2) coef[i]=-1;
      else coef[i]=1;
    }

    for(int i=0; i<N; i++){
      sum[i] = x[i]*coef[0] + y[i]*coef[1] + z[i]*coef[2];
    }
    sort(sum,N);
    for(int i=0; i<M; i++){
      buf += sum[i];
    }
    if(buf>ans) ans=buf;
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int cnt[SIZE];
char a[SIZE];
int main(){
    string s;
    cin>>s;
    int n=SZ(s);
    int m=0;

    REP(i,n){
        if(s[i]=='x'){
            cnt[m]++;
        }
        else{
            a[m++]=s[i];
        }
    }
    REP(i,m){
        if(a[i]!=a[m-1-i])return 0*puts("-1");
    }
    int an=0;
    for(int i=0;i<m-i;i++){
        an+=abs(cnt[i]-cnt[m-i]);
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertionsort(int A[], int n)
{
  int j, i, v;
  for(i = 2 ; i <= n ; i++)
    {
      v = A[i];
      j = i - 1;
      while(j >= 0 && A[j] > v)
        {
          A[j + 1] = A[j];
          j--;
        }

      A[j + 1] = v;
      trace(A, n);
    }
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  /*

    your code

   */
  insertionsort(A, n);
  return 0;
}

Measured memory_bytes: 2684
#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  string S; cin>>S;
  vector<int> num(S.size());
  for(int i=0;i<S.size();i++){
    num[i]=S[S.size()-i-1]-'0';
  }
  long long ans=0;
  for(int i=0;i<(1<<(S.size()-1));i++){
    long long sum=0,n=num[0],dig=1;
    for(int j=0;j<(S.size()-1);j++){
      if(i&(1<<j)){
        sum+=n;
        n=num[j+1];
        dig=1;
      }
      else{
        n+=num[j+1]*pow(10,dig);
        dig++;
      }
    }
    sum+=n;
    ans+=sum;
  }

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 256
import sys

# def calc_minus1(n):
#     n-=1
#     return n

A = [int(x) for x in input().split()]
#print(AB)
N = A[0]
K = A[1]
Q = A[2]
B = K - Q
if K > Q:
    for i in range(Q):
        n = int(input())
    for i in range(N):
        print('Yes')
    sys.exit()
a = [B]*N
#print(a)
for i in range(Q):
 #   print(i)
    n = int(input())
    #print(n)
    #print(a)
    a[n-1]+=1
    #print(a)

for i in a:
    if i > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 6600
#include <iostream>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;
typedef long long ll;
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,n) REP(i,0,n)
void solve(){
}

int day[] = {0, 20, 19, 20, 19, 20, 19, 20, 19, 20, 19};

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

  while(T--){
    int cnt = 1;
    int y, m, d;
    cin >> y >> m >> d;

    while(true){
      if(y == 1000 && m == 1 && d == 1){
        break;
      }

      d++;

      int lim = (y % 3 == 0 ? 20 : day[m]);

      if(lim < d){
        d = 1;
        m++;
      }

      if(10 < m){
        m = 1;
        d = 1;
        y++;
      }

      cnt++;
    }

    cout << cnt - 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 868
#!/usr/local/bin/python3
N = int(input())
H = list(map(int, input().split()))

rev_H = H[::-1]

for i in range(N - 1):
    if H[i] < H[i + 1]:
        H[i + 1] = H[i + 1] - 1

for i in range(N - 1):
    if H[i] > H[i + 1]:
        print("No")
        exit()

print("Yes")


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

#define mod(a,b) ((((a)%(b))+(b))%(b))

ll thesum(ll n,ll p,ll qq,ll rr){ //sum{i=1..n}[(qq*i+rr)/p]
	ll q=qq%p;if(q<0)q+=p;
	ll r=rr%p;if(r<0)r+=p;
	ll last=(n*q+r)/p;
	if(q==0)return (qq-q)/p*n*(n+1)/2+(rr-r)/p*n;
	else return (qq-q)/p*n*(n+1)/2+(rr-r)/p*n+(n+1)*last-thesum(last,q,p,q-1-r);
}

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

ll maxrem(ll n,ll p,ll q){ //i in {0,...,n-1} such that i*q%p attains max (q<p, n<=(period of seq.))
	if(q==0)return 0;
	ll lp=1,lq=0;
	ll up=0,uq=1;
	for(;;){
		ll maxk;
		maxk=(q*up-p*uq)/(p*lq-q*lp);
		if(up+maxk*lp<n-1){up+=maxk*lp;uq+=maxk*lq;}
		else{
			ll k=(n-1-up)/lp;
			up+=k*lp;
			uq+=k*lq;
			return up;
		}
		maxk=(q*lp-p*lq-1)/(p*uq-q*up);
		lp+=maxk*up;lq+=maxk*uq;
	}
}

double solve(ll w,ll d,ll n,ll m,ll t){
	ll v=w+d;
	ll l=w+1;
	ll g=gcd(v,t);
	double ans;
	if(l>=t)ans=0;
	else{
		if(t/gcd(t,m)<n){ //cutting-point ga kaburu
			ll cnt=thesum(t/gcd(t,m),g,gcd(t,m),0)-thesum(t/gcd(t,m),g,gcd(t,m),-min(gcd(t,m),l));
			ans=(double)(t/g-cnt)/(t/g);
		}else{ //cutting-point ga kaburanai
			ll i=maxrem(n,t,mod(-m,t));
			ll j=maxrem(n,t,mod(m,t));
			ll d1=t-mod(-m*i,t);
			ll d2=t-mod(m*j,t);
			ll cnt=0;
			cnt+=thesum(n-i,g,-m,m)-thesum(n-i,g,-m,m-min(d1,l));
			cnt+=thesum(i+j-n,g,-m,-m*(n-i-1))-thesum(i+j-n,g,-m,-m*(n-i-1)-min(d1+d2,l));
			cnt+=thesum(n-j,g,-m,-m*(j-1))-thesum(n-j,g,-m,-m*(j-1)-min(d2,l));
			ans=(double)(t/g-cnt)/(t/g);
		}
	}
	return ans;
}

main(){
	ll w,d,n,m,t;
	scanf("%lld%lld%lld%lld%lld",&w,&d,&n,&m,&t);
	printf("%.15f\n",solve(w,d,n,m,t));
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, k, x, y, c;
  cin >> n >> k >> x >> y;
  
  
  if(n<=k){
      c=n*x;
  }
  else{
    c=k*x+(n-k)*y;
  }
 
  
  
 
  
  cout << c << endl;
  
  
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> v = {A,B,C};
  sort(v.begin(),v.end());
  int a = v[2]-v[0];
  int b = v[2]-v[1];
  int p = a-b;
  int q = 0;
  if(p%2 == 0)  q = p/2;
  else q = p/2+2;
  cout << b+q << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
int n,m;
int c[1001]; int a[1001],b[1001];int k;int dp[100000];
int main(){
	cin>>n;
	if(n%2==0)cout<<(n/2)-1;
	else cout<<n/2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define s second
#define int long long
#define pb push_back
#define pencho ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 100005
#define mod 1000000007




void solve() {
       pencho
       int n, k; cin >> n >> k;
       int dp[N] = {0}, a[n];
       for (int i = 0; i < n; i++) cin >> a[i], dp[a[i]] = 1;
       dp[0] = 1;
       for (int i = 1; i <= k; i++) {
              if (dp[i] == 1)  continue;
              for (int j = 0; j < n; j++) {
                     if (i < a[j])    continue;
                     else if (dp[i - a[j]] == 0) {      dp[i] = 1; break;}
              }
       }
       if (dp[k] == 1)  cout << "First";       else cout << "Second";

}


signed main()
{
#ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("o.txt", "w", stdout);
#endif

       solve();
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;

#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
const ll mn=1e5+4;
ll dp[mn];
const ll MAXLOG=18;
#define LOG2(X) ((unsigned) (8*sizeof (unsigned long long) - __builtin_clzll((X)) - 1))
ll table[MAXLOG][mn];
void preprocess_rmq(ll *array, ll n) {
	for(ll i=0;i<n;i++)            
   table[ 0 ][ i ]=array[ i ];         //building base
  for(ll j=1;j<=LOG2(n);j++)
   for(ll i=0;i+(1LL<<(j-1))<n;i++) {
     table[ j ][ i ] = max ( table[ j-1 ][ i ], table[ j-1 ][ i+(1LL<<(j-1)) ] );  //use previously computed
     //printf("j:%lld i:%lld t:%lld i+(1LL<<(j-1)):%lld\n",j,i,table[j][i],i+(1LL<<(j-1)));
   }
}
ll query_rmq(ll x, ll y) {
  ll len=y-x+1;
  ll k=LOG2(len);
  //printf("Query. k:%lld x:%lld y:%lld y+1-(1LL<<k):%lld\n",k,x,y,y+1-(1LL<<k));
  return max(table[ k ][ x ],table[ k ][ y+1-(1LL<<k) ]);   // ranges may overlap
}
ll a[mn];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n,m,klim; scanf("%lld%lld%lld",&n,&m,&klim);
	for (ll i=1;i<=n;i++) scanf("%lld",a+i);
	//	for (ll j=1;j<=n;j++) printf("%lld ",a[j]);
	//		printf("end a\n");
	ll jlim;
	{
		ll j=0;
		while((1<<j)<m) j++;
		jlim=j-1;
	}
	memset(dp,0,sizeof dp);
	preprocess_rmq(dp,n+1);
	ll cur=1,prev=0;
	ll final=0;
	for (ll k=1;k<=klim;k++) {
		fill(dp,dp+n+1,-INF);
		for (ll x=1;x<=n;x++) {
			ll best=query_rmq(max(0ll,x-m),x-1);
			//printf("%lld %lld: %lld\n",max(0ll,x-m),x-1,best);
			if (best==-INF) continue;
			chkmax(dp[x],best+k*a[x]);
			chkmax(final,dp[x]);
		}
		//for (ll x=0;x<=n;x++) printf("%lld ",dp[x]);
		//printf("\n");
		preprocess_rmq(dp,n+1);
		swap(cur,prev);
	}
	printf("%lld\n",final);
}



Measured memory_bytes: 14720
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
typedef long long Int;
char cnt[10][10];

void ok(){
  cout << "Possible" << endl;
  exit(0);
}

void ng(){
  cout <<  "Impossible" << endl;
  exit(0);
}

char c;
int main(){
  Int h, w;
  cin >> h >> w;
  for(int i = 1;i <= h;i++)
    for(int j = 1;j <= w;j++)
      cin >> cnt[i][j];
  for(int i = 1;i < h;i++){
    for(int j = 1;j < w;j++){
      
      if(cnt[i][j] == '#' && cnt[i+1][j] == '#' && cnt[i][j+1] == '#')ng();
      if(cnt[i][j] == '#' && cnt[i+1][j] == '.' && cnt[i][j+1] == '.')ng();
      if(cnt[i+1][j+1] == '#' && cnt[i+1][j] == '#' && cnt[i][j+1] == '#')ng();
    }
  }
  ok();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) 				for(int i=0; i<(n); ++i)
#define all(c) 					(c).begin(),(c).end()
#define sortall(x)              sort(all(x))
#define tr(c,i) 				for( typeof( (c).begin() ) i = (c).begin();  i != (c).end(); ++i)
#define pb 						push_back
#define sz(a) 					int((a).size())
#define mp                      make_pair
#define ll                      long long
#define F                       first
#define S                       second
#define PI                      3.1415926535897932384626
// Input macros
#define s(n)                    scanf("%d",&n)
#define sc(n)                   scanf("%c",&n)
#define sl(n)                   scanf("%lld",&n)
#define sf(n)                   scanf("%lf",&n)
#define ss(n)                   scanf("%s",n)

// Others
#define test(t) 				int t; cin>>t; while(t--)
#define endl 					"\n"

using namespace std;

typedef pair<int, int> 			pii;
typedef pair<ll, ll> 	        pll;
typedef vector<int> 			vi;
typedef vector<ll>              vl;

// const int mod = 1000000007;
// const int INF = 1e9+5;

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

     int n,x,t;
     scanf("%d%d%d",&n,&x,&t);
     
     int rem = n%x;
     int ans = n/x;
     
     if(rem){
		 ans++;
	 }
	 
	 cout << ans*t << endl;
     

     return 0;

}

Measured memory_bytes: 3664