akhauriyash/Code-Regression huggingface dataset:
//21
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 101;
const int lbt = 1e9 + 7;
const int inf = 1e9;

int n;
int h[maxn];

int fast_pow(int a, int t);
pair<int, int> cal(int l, int r, int bot);

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &h[i]);
	}
	pair<int, int> ans = cal(1, n, 0);
	printf("%d", (ans.first + ans.second) % lbt);
	return 0;
}

int fast_pow(int a, int t) {
	int ans = 1;
	for (int i = 31; i >= 0; i--) {
		ans = (long long)ans * ans % lbt;
		if (t >> i & 1) ans = (long long)a * ans % lbt;
	}
	return ans;
}

pair<int, int> cal(int l, int r, int bot) {
	int minh = inf;
	for (int i = l; i <= r; i++) {
		minh = min(minh, h[i]);
	}
	int g = 0;
	int prod = 1;
	int prod0 = 1;
	int last = l;
	for (int i = l; i <= r; i++) {
		if (h[i] == minh) {
			g++;
			if (last < i) {
				pair<int, int> cur = cal(last, i - 1, minh);
				prod = (long long)prod * ((long long)2 * cur.first + cur.second) % lbt;
				prod0 = (long long)prod0 * cur.first % lbt;
			}
			last = i + 1;
		}
	}
	if (last <= r) {
		pair<int, int> cur = cal(last, r, minh);
		prod = (long long)prod * ((long long)2 * cur.first + cur.second) % lbt;
		prod0 = (long long)prod0 * cur.first % lbt;
	}
	int dp0 = (long long)fast_pow(2, minh - bot) * prod0 % lbt;
	int dp1 = ((long long)fast_pow(2, g) * prod + (long long)(lbt - 2) * prod0) % lbt;
	return make_pair(dp0, dp1);
}

Measured memory_bytes: 128
S = input()


N = len(S)

count_0 = 0
count_1 = 0

for i in range(N):
    if S[i] == '0':
        count_0 += 1
    else:
        count_1 += 1

if count_0 > count_1:
    print(int(count_1*2))

else:
    print(int(count_0*2))

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

struct item{
   
   int wt;
   int val;
};

ll solve(vector<item> ar,int n,int W){

    ll dp[n+1][W+1];

    for(int w=0;w<=W;w++){
        dp[1][w]=0;
    }
    dp[1][ar[1].wt]=ar[1].val;
    
    for(int i=2;i<=n;i++){
        for(int w=0;w<=W;w++){
            dp[i][w]=dp[i-1][w];
            if(ar[i].wt >w){
               continue;
            }
            dp[i][w]=max(dp[i][w],ar[i].val+dp[i-1][w-ar[i].wt]);
        }
    }
    return *max_element(dp[n],dp[n]+W+1);
}



int main(){

    int n,w;
    cin>>n>>w;
    vector<item> arr(n+1);
    for(int i=1;i<=n;i++){
        cin>>arr[i].wt>>arr[i].val;
    }
    cout<<solve(arr,n,w);
}

Measured memory_bytes: 81648
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits>
#include <map>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <cstring>

typedef long long li;
using namespace std;

li max(li a, li b) {
    return a > b ? a : b;
}

li max(li a, li b, li c) {
    return max(a, max(b, c));
}

li max(li a, li b, li c, li d) {
    return max(a, max(b, max(c, d)));
}

li max(li a, li b, li c, li d, li e) {
    return max(a, max(b, max(c, max(d, e))));
}


li pow_mod(li n, li e, li mod)
{
    li r = 1;
    
    while(e > 0)
    {
        if(e & 1)
            r *= n;
            r %= mod;
        
        n *= n;
        n %= mod;
        e >>= 1;
    }
    
    return r;
}

int main() {
    // ifstream fin("read.txt");
    li k, x;
    
    cin >> k >> x;
    
    if (k * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    int g = abs(a-b);
    n -= 1;
    bool flag = false;
    REP(i,n+1){
        int mi = - (n-i) * d + c * i;
        int ma = - (n-i) * c + d * i;
        if( mi <= g and g <= ma){
            flag = true;
            break;
        }
    }
    if(flag){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

const ll INF = 1e9;
const long long INFL = 1LL<<60;

int find_k(int n) {
  for (int k = 0; k <= n; k++) {
    if (k * (k - 1) == 2 * n) {
      return k;
    }
  }
  return 0;
}

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

  int n;
  cin >> n;

  if (n == 1) {
    cout << "Yes" << endl;
    cout << 2 << endl;
    cout << "1 1" << endl;
    cout << "1 1" << endl;
    return 0;
  }

  int k = find_k(n);
  if (k == 0) {
    puts("No");
    return 0;
  } else {
    cout << "Yes" << endl;
  }
  cout << k << endl;

  vector<vector<int>> ans(k, vector<int>(k-1));
  int c = 1;
  rep(i, k) {
    rep(j, k - 1 - i) {
      ans[i][i+j] = c;
      ans[i+j+1][i] = c;
      c++;
    }
  }

  rep(i, k) {
    cout << k-1 << " ";
    rep(j, k-1) {
      cout << ans[i][j];
      if (j != k - 2) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 4000
//無断転用の一切を禁ずるよ//////////////////////////
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
#define rt "\n"//改行を最速化するよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define cncn int cnt=0
#define please return
#define AC 0
/////////////////////////////////////////////////
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool; 
//////////////////////////////////////////////////
//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　（A＋B）÷ GCD　 ＞＞で求まるよ

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


int main(void) {
	string s;
	cin >> s;
	sort(s);
	Yes(s=="abc")
	please AC;
}

// abc : 141 , aoj : ITP1_6_D
//sort, abs, swap, reverse, max, min
//__gcd, sbstring, erase, push_back,stoll、stoi

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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    
    int n, m;
    cin >> n >> m;
    vi x(m);
    vi a(m-1);
    for(int i = 0; i < m; i++)
        cin >>  x[i];
    sort(all(x));
    for(int i = 0; i < m-1; i++)
        a[i] = abs(x[i]-x[i+1]);
    int ind = n-1;
    sort(all(a), [](int a, int b){return a>b;});
    int suma = 0;
    for(int i = ind; i<m-1; i++){
        suma += a[i];
    }
    cout << suma;
}

Measured memory_bytes: 1024
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  br.readLine()
  val a = br.readLine().split(" ").map { it.toInt() }

  tailrec fun gdc(a: Int, b: Int): Int =
    if(b == 0) a
    else gdc(b, a % b)

  val ans = a.reduce { a, b -> gdc(b, a) }
  println(ans)
}

Measured memory_bytes: 55480
#include<stdio.h>
int main()
{
    long long int a,b,a1,b1,i=0;
    scanf("%lld%lld",&a,&b);
    for(i=0;i<=1000;i++)
    {
        a1=i*0.08;
        b1=i*0.1;
        if(a1==a && b1==b)
            break;
    }
    if(i!=1001)
    printf("%lld",i);
else
    printf("-1");
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int k,a,b;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout << "OK\n";
      return 0;
    }
  }

  cout << "NG\n";
}


Measured memory_bytes: 3636
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
int main(void){
    // Your code here!
    int n,a,b;
    cin >> n >> a >> b;
    if(n * a < b){
        cout << n * a << endl;
    }
    else{
        cout << b << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct Real{

	long long top, bot;

	Real(long long top, long long bot) : top(top), bot(bot) {
		normalize();
	}

	long long gcd(long long a, long long b){
		if(!a || !b) return a+b;
		if(a < b) return gcd(b, a);
		return gcd(b, a%b);
	}

	void normalize(){
		if(bot<0){
			bot = -bot;
			top = -top;
		}
		int divisor = gcd(top<0 ? -top : top, bot);
		top /= divisor;
		bot /= divisor;
	}

	Real operator+(const Real& rhs){
		return Real(top*rhs.bot+rhs.top*bot, bot*rhs.bot);
	}

	Real operator+(long long x){
		return Real(top + x*bot, bot);
	}

	Real operator-(const Real& rhs){
		return Real(top*rhs.bot-rhs.top*bot, bot*rhs.bot);
	}

	Real operator*(const Real& rhs){
		return Real(top*rhs.top, bot*rhs.bot);
	}

	Real operator*(long long x){
		return Real(top*x, bot);
	}

	Real operator/(const Real& rhs){
		return Real(top*rhs.bot, bot*rhs.top);
	}

	Real operator/(long long x){
		return Real(top, bot*x);
	}

	Real operator%(long long x){
		return Real(top % (x*bot), bot);
	}

	bool operator==(Real rhs){
		return top*rhs.bot == rhs.top*bot;
	}

	bool operator<(const Real& rhs) const{
		return top*rhs.bot < rhs.top*bot;
	}

	long long toInt(){
		return top / bot;
	}

	double toDouble(){
		return (double)top / bot;
	}

};

int main() {
	while(true){
		int H, h, m, s;
		scanf("%d %d %d %d", &H, &h, &m, &s);
		if(!H && !h && !m && !s) break;
		Real speedH = Real(1, 10*H);
		Real speedM = Real(1, 10);
		Real speedAvg = (speedH + speedM) / 2;
		Real speedS = Real(6, 1);
		long long past = 3600*h + 60*m + s;
		Real positionAvg = speedAvg * past % 360;
		Real positionS = speedS * past % 360;
		Real distance = min((positionAvg+540-positionS)%360, (positionAvg+360-positionS)%360);
		Real final = distance / (speedS - speedAvg) + past;
		if(speedH*final%360 == speedM*final%360 && speedM*final%360 == speedS*final%360){
			distance = (distance+180)%360;
			final = distance / (speedS - speedAvg) + past;
		}
		final = final % (H * 3600);
		long long Hour = final.toInt() / 3600;
		final = final + Hour*-3600;
		long long Minute = final.toInt() / 60;
		final = final + Minute*-60;

		printf("%lld %lld %lld %lld\n", Hour, Minute, final.top, final.bot);
	}
	return 0;
}

Measured memory_bytes: 1192
import math
while True:
    n = int(input())
    if n == 0: break
    s = list(map(int, input().split()))
    ave = sum(s) / n
    S = []
    for i in range(n):
        key = ave - s[i]
        S.append(key * key)
    print('{:.5f}'.format(math.sqrt(sum(S) / n)))



Measured memory_bytes: 5712
#include<iostream>
using namespace std;
int main () {
    long long int  s,t;
    cin>>s>>t;
    long long  int m,n ;
    if (t==1) cout<<"0"<<endl;
    else {
    
    s=s-1;t=t-1;
    m=t/s;
    n=t%s;
    if (n!=0) n=1;
    else n=0;
    cout<<m+n<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int count = 0;
    if(s[0] == t[0]) count++;
    if(s[1] == t[1]) count++;
    if(s[2] == t[2]) count++;
    cout << count << endl;
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI


void Main() {
    ll x;
    cin >> x;
    FOR(a, -1000, 1000) {
        FOR(b, -1000, 1000) {
            if (pow(a, 5) - pow(b, 5) == x) {
                cout << a << " " << b << endl;
                return;
            }
        }

    }
}

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


Measured memory_bytes: 3920
/*
ID: yzshang1
LANG: C++11
TASK: Rem of Sum is Num
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
int n, k;
const int N = 200010;
LL a[N], s[N], v[N];
map <int, int> m;
int main() {
	cin >> n >> k;
	repn(i, n) cin >> a[i];
	repn(i, n) s[i] = (s[i - 1] + a[i]) % k;
	repn(i, n) v[i] = (s[i] % k - i + (LL)k * 1000000000LL) % k;
	LL ans = 0;
	m[v[0]]++;
	repn(i, n) {
		if (i - k >= 0) m[v[i - k]]--;
		ans += m[v[i]];
		m[v[i]]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 14336
package main

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

var debug = false

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var input string
	if sc.Scan() {
		input = sc.Text()
	}

	res := GetAnswer(input)
	fmt.Printf("%v\n", res)
}

// GetAnswer ...
func GetAnswer(input string) int {
	prt("input:%v", input)
	result := -1
	arr := getIntArray(input)
	a := arr[0]
	b := arr[1]
	result = int(math.Ceil(float64(a+b) / 2))
	prt("ave: %v", float64(a+b)/2)
	prt("ceil: %v", math.Ceil(float64(a+b)/2))
	prt("res: %v", int(math.Ceil(float64(a+b)/2)))
	return result
}

func getIntArray(str string) []int {
	strarr := strings.Split(str, " ")
	intarr := []int{}
	for _, st := range strarr {
		ti, _ := strconv.Atoi(st)
		intarr = append(intarr, ti)
	}
	return intarr
}

func prt(format string, inputs ...interface{}) {
	if debug {
		fmt.Printf(format+"\n", inputs...)
	}
}

Measured memory_bytes: 640
import copy

def resolve():
	n = int(input())
	t = list(map(int, input().split()))
	m = int(input())
	for i in range(m):
		p, x = map(int, input().split())
		tt = copy.deepcopy(t)
		tt[p-1] = x
		print(sum(tt))
resolve()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
vector<int> color;
vector<vector<P> > edge;
int maxv = 0;
void solve(int now, P past){
    int c = 1;
    for (const auto &x : edge[now]){
        if (x.first==past.first) continue;
        if (c==past.second) c+=1;
        color[x.second] = c;
        maxv = max(maxv, c);
        if (edge[x.first].size()!=0) solve(x.first, P(now, c));
        c += 1;
    }
}

int main(){
    int n, a, b; sc(n);
    edge.resize(n), color.resize(n-1,0);
    rep(i, 0, n-1){
        sc(a), sc(b);
        a--, b--;
        edge[a].push_back(P(b,i));
        edge[b].push_back(P(a,i));
    }
    solve(0, P(0, 0));
    cout << maxv << endl;
    rep(i, 0, n-1) cout << color[i] << endl;
    return 0;
}

Measured memory_bytes: 7424
def d_semi_common_multiple():
    from fractions import gcd
    from functools import reduce
    N, M = [int(i) for i in input().split()]
    A = [int(i) // 2 for i in input().split()]  # 先に2で割っておく

    def count_divide_2(n):
        """n に含まれる因数 2 の指数"""
        return (n & -n).bit_length()

    def lcm(a, b):
        return a * b // gcd(a, b)

    # A の全要素について，2で割れる回数は等しいか？
    tmp = count_divide_2(A[0])
    for a in A:
        if count_divide_2(a) != tmp:
            return 0

    t = reduce(lambda x, y: lcm(x, y), A)
    return (M // t) - (M // (2 * t))

print(d_semi_common_multiple())

Measured memory_bytes: 16308
#include<iostream>
using namespace std;
int main(){
  int m,f,r;
  cin >> m >> f >> r;
  while(m!=-1||f!=-1||r!=-1){
    if(m==-1||f==-1) cout << "F" << endl;
    else if(m+f>=80) cout << "A" << endl;
    else if(m+f>=65) cout << "B" << endl;
    else if(m+f>=50) cout << "C" << endl;
    else if(m+f>=30)
      if(r>=50) cout << "C" << endl;
      else cout << "D" << endl;
    else cout << "F" << endl;

    cin >> m >> f >> r;
  }
  return 0;
}


Measured memory_bytes: 3072
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
dp=[defaultdict(lambda:-float('inf'))for _ in range(n)]
for i in range(n):dp[i][0]=0
for i,a in enumerate(a):
    for j in range(n//2-(n-i)//2,i//2+2):
        dp[i][j]=max(dp[i-2][j],dp[i-2][j-1]+a,dp[i-1][j])
print(dp[-1][n//2])

Measured memory_bytes: 198608
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		int C;
		for(int i=0; i<K; i++){
			C = A/2;
			A = B + C;
			B = C;
		}
		if(K%2==1){
			C = A;
			A = B;
			B = C;
		}
		System.out.println(A+" "+B);
		System.out.flush();
		return;
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
long long x[100005], y[100005], n, m, mod = 1000000007;
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++)cin >> x[i];
	for (int i = 1; i <= m; i++)cin >> y[i];
	long long cnt1 = 0, cnt2 = 0;
	for (int i = 1; i <= n - 1; i++) { long long Y = 1LL * i*(n - i); Y %= mod; Y *= (x[i + 1] - x[i]); Y %= mod; cnt1 += Y; cnt1 %= mod; }
	for (int i = 1; i <= m - 1; i++) { long long Y = 1LL * i*(m - i); Y %= mod; Y *= (y[i + 1] - y[i]); Y %= mod; cnt2 += Y; cnt2 %= mod; }
	cout << cnt1*cnt2%mod << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

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; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll cnt[100000];
bool red[100000];

int main() {
    init();
    ll N, M;
    cin >> N >> M;
    fill(cnt, cnt + N, 1);
    red[0] = true;
    rep(i,M){
        ll x, y;
        cin >> x >> y;
        x--, y--;
        
        if(cnt[x]==1){
            red[y] |= red[x];
            red[x] = false;
        }
        else{
            red[y] |= red[x];
        }
        cnt[x]--, cnt[y]++;
    }

    ll ans = 0;
    rep(i, N) ans += red[i];
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
 
int main() {
  int x;
  long long int y = 1;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    y *= i;
    y %= mod;
  }
  cout << y;
}

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

template <typename flow_t>
struct FordFulkerson
{
  struct edge
  {
    ll to;
    flow_t cap;
    ll rev;
    bool isrev;
  };

  vector<vector<edge>> graph;
  vector<ll> used;
  const flow_t INF;
  ll timestamp;

  FordFulkerson(ll n) : INF(numeric_limits<flow_t>::max()), timestamp(0)
  {
    graph.resize(n);
    used.assign(n, -1);
  }

  void add_edge(ll from, ll to, flow_t cap)
  {
    graph[from].emplace_back((edge){to, cap, (ll)graph[to].size(), false});
    graph[to].emplace_back((edge){from, 0, (ll)graph[from].size() - 1, true});
  }

  flow_t dfs(ll idx, const ll t, flow_t flow)
  {
    if (idx == t)
      return flow;
    used[idx] = timestamp;
    for (auto &e : graph[idx])
    {
      if (e.cap > 0 && used[e.to] != timestamp)
      {
        flow_t d = dfs(e.to, t, min(flow, e.cap));
        if (d > 0)
        {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  flow_t max_flow(ll s, ll t)
  {
    flow_t flow = 0;
    for (flow_t f; (f = dfs(s, t, INF)) > 0; timestamp++)
    {
      flow += f;
    }
    return flow;
  }

  void output()
  {
    for (ll i = 0; i < graph.size(); i++)
    {
      for (auto &e : graph[i])
      {
        if (e.isrev)
          continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
      }
    }
  }
};

int main()
{
//宣言 FordFulkerson< ll > g(V);
//追加 g.add_edge(from,to,cap);
//結果 ll ans = g.max_flow(to,from);
ll v , e ;
cin >> v >> e ;
FordFulkerson< ll > g(v);
rep(i,e){
  ll a , b , c ;
  cin >> a >> b >> c ;
  g.add_edge(a,b,c);
}

cout << g.max_flow(0,v-1) << endl;
return 0;
}



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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 50;

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

int log(int n) {
	int res = 0;
	while (n % 2 == 0) {
		res++;
		n /= 2;
	}
	return res;
}

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] /= 2;
	}
	int lcm = 1;
	
	set<int> st;
	for (int i = 0; i < n; i++) {
		int g = gcd(a[i], lcm);
		lcm = lcm * a[i] / g;
		st.insert(log(a[i]));
		if (lcm > m || st.size() > 1) {
			cout << 0;
			return;
		}
	}

	int x = m / lcm;
	x = x / 2 + x % 2;
	cout << x;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    int unit = 1;
    ll ans = 0;
    for (int i=0; i<N; i++) {
        if (unit == 1) {
            ans += A[i] - 1;
            unit++;
        } else {
            ans += (A[i]-1) / unit;
            if (A[i] == unit) unit++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
	int MOD = 1000000;
	int N = scanner.nextInt();
	int M = scanner.nextInt();
	if (M == 2) {
	    long[][] dp = new long[N][5];
	    Arrays.fill(dp[0], 1);
	    dp[0][4] = 0;
	    for (int i = 1; i < dp.length; i++) {
		dp[i][0] += (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][4]);
		dp[i][0] %= MOD;
		dp[i][1] += (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]);
		dp[i][1] %= MOD;
		dp[i][2] += (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3]);
		dp[i][2] %= MOD;
		dp[i][3] += (dp[i - 1][0] + dp[i - 1][3]);
		dp[i][3] %= MOD;
		dp[i][4] += (dp[i - 1][2] + dp[i - 1][4]);
		dp[i][4] %= MOD;
	    }

	    long ans = dp[N - 1][0] + dp[N - 1][1] + dp[N - 1][2]
		    + dp[N - 1][3];
	    ans %= MOD;
	    System.out.println(ans);
	} else {
	    long ans = 1;
	    for (int i = 0; i < N; i++) {
		ans *= 2;
		ans %= MOD;
	    }
	    System.out.println(ans);
	}

    }

}

Measured memory_bytes: 26304
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>

using namespace std;

typedef long long li;

#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

double eps = 1e-5;
const int INF = 1e9 + 7;
const li LINF = 9e18 + 7;

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	li x, y;
	cin >> x >> y;

	li ans = 0;
	while (x <= y) {
		ans++;
		x <<= 1;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
//=template==================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)
#define MIN_V(v) *min_element(v.begin(), v.end())
#define MAX_V(v) *max_element(v.begin(), v.end())

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;

// conversion
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
inline int countChar(string s, char c) {int cnt,i; cnt=0; REP (i,s.size()) {if (s[i]==c) cnt++;} return cnt;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//===========================================================================//

//=function prototype========================================================//

//===========================================================================//

//=variables=================================================================//

//===========================================================================//
int main(void)
{
  // Scan begin.
  int n;
  cin >> n;
  VI w(n);
  REP(i,n) {
    cin >> w[i];
  }
  // Scan done.

  // Code begin.
  int ans = 99999;
  REP(i, n) {
    int sum1 = 0;
    int sum2 = 0;
    FOR(j,0,i) {
      sum1 += w[j];
    }
    FOR(j,i,n) {
      sum2 += w[j];
    }
    if (abs(sum2 - sum1) < ans) {
      ans = abs(sum2 - sum1);
    }
  }
  cout << ans << endl;
  // Code done.

  return 0;
}

//=functions=================================================================//

//===========================================================================//

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

namespace abc131_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var items = input.Split(' ');
            // リンゴの個数
            var n = int.Parse(items[0]);
            // 味のパラメータ
            var l = int.Parse(items[1]);
            //n:3 l:-3
            // 食べたリンゴの味
            // lが正だったら、初めのリンゴを食べる
            var eat = l + 0;
            if (l < 0)
            {
                // lが負だったら、0に近いものを食べる
                if (n > -l)
                {
                    // nがlよりも大きければ、食べるリンゴの味は0
                    eat = 0;
                }
                else
                {
                    // nがl以下だったら、最後のリンゴを食べる
                    eat = l + n - 1;
                }
            }
            // リンゴの味の総和
            var sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += l + i;
            }
            // パイの味
            var pie = sum - eat;
            Console.WriteLine($"{pie}");
        }
    }
}


Measured memory_bytes: 13268
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
ll arr[100005];
ll vis[100005];
vector<ll>v[100005];
ll dfs(ll ind)
{
	vis[ind]=1;
	for(ll i=0;i<v[ind].size();i++)
	if(!vis[v[ind][i]])
	arr[ind]=max(dfs(v[ind][i])+1,arr[ind]);
	else
	arr[ind]=max(arr[ind],arr[v[ind][i]]+1);
	if(arr[ind]!=-1)
	return arr[ind];
	return arr[ind]=0;//v[ind].size()=0
}
int main()
{
	sync;
	aset(arr,100005,-1);
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
		ll x,y;
		cin>>x>>y;
		v[x].push_back(y);
	}
	for(ll i=1;i<=n;i++)
	if(!vis[i])
	dfs(i);
	ll ans=0;
	for(ll i=1;i<=n;i++)
	ans=max(ans,arr[i]);
	cout<<ans<<endl;
	
}

Measured memory_bytes: 9344
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,k;
	cin >> n >> k;
	ll ans = 0;
	ll cnt = 0;
	if(k % 2 == 0){
		for(int i = 1; i <= n; i++){
			if(i%k == 0) cnt++;
		}
		ans += cnt*cnt*cnt;
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(i%k == k/2) cnt++;
		}
		ans += cnt*cnt*cnt;
	}else{
		for(int i = 1; i <= n; i++){
			if(i%k == 0) cnt++;
		}
		ans = cnt*cnt*cnt;
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
  ll n; cin >> n;
  vector<ll> a;

  rep(i, 3*n) {
    ll tmp; cin>>tmp;
    a.push_back(tmp);
  }

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

  ll ans=0;
  for (int i=0, j=a.size()-2; i < n; i++, j-=2) {
    ans+= a[j];
  }
  // while (true) {
  //   ans += a[a.size()-2];

  //   a.erase(a.begin());
  //   a.pop_back();
  //   a.pop_back();
  //   if(a.size() == 0) break;
  // }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5872
N = int(input())
a = list(map(int, input().split()))

# 操作回数が最も多くなるのは、数列のうち1つだけを2で割る操作を繰り返すとき
# 数列全体に含まれる因数2の個数が解

def n_factor2(x):
    i = 0
    while x%2 == 0:
        x /= 2
        i += 1
    return i

ans = 0
for x in a:
    ans += n_factor2(x)

print(ans)

Measured memory_bytes: 4148
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long ll;
ll n, mx, k, x[1005], y[1005];
vector<ll> b;
ll ab(ll p) {return p > 0 ? p : -p;}
ll f(ll p, ll q) {
	return ab(p) + ab(q);
}
int main()
{
	ll i, j;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%lld %lld", &x[i], &y[i]);
		if (f(x[i], y[i]) % 2 != f(x[0], y[0]) % 2) {
			cout << -1;
			return 0;
		}
		mx = max(mx, f(x[i], y[i]));
	}
	if (mx % 2 == 0) b.push_back(1);
	for (k = 1; k < mx; k *= 2) b.push_back(k);
	b.push_back(k);
	cout << b.size() << endl;
	for (i = b.size() - 1; i >= 0; i--) printf("%lld ", b[i]);
	puts("");
	for (j = 0; j < n; j++) {
		for (i = b.size() - 1; i >= 0; i--) {
			if (ab(x[j]) >= ab(y[j])) {
				if (x[j] <= 0) {x[j] += b[i]; printf("L");}
				else {x[j] -= b[i]; printf("R");}
			} else {
				if (y[j] <= 0) {y[j] += b[i]; printf("D");}
				else {y[j] -= b[i]; printf("U");}
			}
		}
		puts("");
	}
//	cout << k;
    return 0;
}


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

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(auto &a:A)cin>>a;
    vector<int> L(N),R(N);
    L[0]=A[0];
    for(int i=1;i<N;i++) L[i]=gcd(A[i],L[i-1]);
    R[N-1]=A[N-1];
    for(int i=N-2;i>=0;i--) R[i]=gcd(A[i],R[i+1]);
    int ans=max(R[1],L[N-2]);
    for(int i=1;i<N-1;i++) ans=max(ans,gcd(L[i-1],R[i+1]));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <unordered_map>
#include <iomanip>


using namespace std;
#define ASCII 97


int main() {
	long long int N;
	cin >> N;
	N -= 1;
	cout << N*(N+1)/2 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(void){
	int h;
	int w;
	char s[50+2][50+2] = {0};

	cin >> h >> w;

	for (int i=0; i < h; i++){
		for (int j=0; j < w; j++)
			cin >> s[i+1][j+1];
	}

	for (int i=0; i < 52; i++){
		for (int j=0; j < 52; j++)
			if (s[i][j] == '#'){
				if( (s[i-1][j] == '.' || s[i-1][j] == 0) && (s[i+1][j] == '.' || s[i+1][j] == 0) && (s[i][j-1] == '.' || s[i][j-1] == 0) && (s[i][j+1] == '.' || s[i][j+1] == 0) ){
					cout << "No";
					return 0;
				}
			}
	}

	cout << "Yes";
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  string s,t;
  cin >> s >> t;
  int n = s.size();
  map<char,char> mp;
  rep(i,n){
    char sc = s.at(i);
    char tc = t.at(i);
    if(mp.count(sc)){
      if(mp.at(sc) != tc){
        cout << "No" << endl;
        return 0;
      }
    }else{
      mp[sc] = tc;
    }
  }
  set<char> st;
  rep(i,26){
    char x = 'a' + i;
    if(mp.count(x)){
      char y = mp.at(x);
      if(st.count(y)){
        cout << "No" << endl;
        return 0;
      }else{
        st.insert(y);
      }
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

// long version
long long int GCD(long long int x, long long int y){
    if(x>y){
        long long int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            long long int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

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

    int ans = 0;

    srep(i,1,n+1){
        srep(j,1,n+1){
            srep(k,1,n+1){
                ll tmp = gcd(gcd(i,j), k);
                ans += tmp;
            }
        }
    }

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


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long long h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << '\n';
	} else {	
		cout << (h * w + 1) / 2 << '\n';
	}
	
	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    cin >> a >> b >> c;

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    vector<lli> cnt(n + 1, 0);
    for (int i = 0; i < n; ++i) {
      cnt[i] = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
    }

    // cout << cnt << endl;
    
    for (int i = n - 2; 0 <= i; --i) {
      cnt[i] += cnt[i + 1];
    }

    // cout << cnt << endl;

    lli sum = 0;
    for (int i = 0; i < n; ++i) {
      int j = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
      // cout << j << ' ' << cnt[j] << ' ' << a[i] << ' ' << b << endl;
      sum += cnt[j];
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

/* include file*/
#include <functional>
#include <vector>
using namespace std;

template <class Monoid>
struct Segment {
  using Func = function<Monoid(Monoid, Monoid)>;

  vector<Monoid> node;
  Monoid ide;
  int n = 1;

  Func bin_f;
  Func update_f;

  Segment(const vector<Monoid>& init, Monoid ide_, Func f_, Func u_f)
      : bin_f(f_), ide(ide_), update_f(u_f) {
    int sz = init.size();
    while (n < sz) n *= 2;
    node.assign(n * 2 - 1, ide);
    for (int i = 0; i < sz; i++) node[i + n - 1] = init[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
  }

  void update(int i, Monoid x) {
    i += n - 1;
    node[i] = update_f(node[i], x);
    while (i) {
      i = (i - 1) / 2;
      node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }

  Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (a <= l && r <= b) return node[k];
    if (r <= a || b <= l) return ide;

    Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
    Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
    return bin_f(lm, rm);
  }
};

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1


int W,H,N;

vector<int> x,y;

int main(){
  cin >> W >> H >> N;
  x.resize(N);
  y.resize(N);

  rep(i,0,N - 1) cin >> x[i] >> y[i];

  vector<int> init(W,-1);

  rep(i,0,N - 1){
    init[x[i]] = max(init[x[i]],y[i]);
  }

  rep(i,0,W - 1){
    if(init[i] == -1){
      init[i] = -1;
    }
  }
  Segment<int> seg(init,-1,[](int a,int b){
    return max(a,b);
  }
  ,[](int a,int b){
    return b;
  });

  int ans = 1e9;

  rep(i,0,W - 1){
    int temp = seg.get_inter(i + 1,W);
    if(temp == -1) temp = 0;
    ans = min(ans , i + temp);

    //cout << i << " " << temp << endl;
  }
  cout << ans << endl;
}


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

const vector<int> di = {-1, -1, -1, 0, 0, 1, 1, 1};
const vector<int> dj = {-1, 0, 1, -1, 1, -1, 0, 1};

int w, h;
vector<vector<int>> field;

void dfs(int i, int j) {
  field[i][j] = 0;

  rep(dir, 8) {
    int ni = i + di[dir];
    int nj = j + dj[dir];

    if (ni < 0 || nj < 0 || ni >= h || nj >= w) continue;
    if (field[ni][nj] == 0) continue;
    dfs(ni, nj);
  }
}

int main() {
  vector<int> ans;

  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;

    field.assign(h, vector<int>(w));
    rep(i, h) rep(j, w) { cin >> field[i][j]; }

    int count = 0;

    rep(i, h) rep(j, w) {
      if (field[i][j] == 0) continue;
      dfs(i, j);
      count++;
    }

    ans.push_back(count);
  }

  for (auto &&i : ans) {
    printf("%d\n", i);
  }
}



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

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>

#define ll long long
#define vl vector<ll>
#define vll vector<vl>

const int INF = 1e9;

ll mod=1000000007;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int a[200010];
	rep(i, 2*n)
	{
		if(s[i]=='B') a[i]=1;
		else a[i]=0;
	}
	rep(i, 2*n) if(i%2!=0) a[i]=1-a[i];
	//rep(i, 2*n) cout << a[i] << endl;
	int kosu=0;
	rep(i, 2*n) if(a[i]==1) kosu++;
	if(kosu!=n)
	{
		cout << '0' << endl;
		return 0;
	}
	int b[100010];
	int tmp=0;
	rep(i, 2*n)
	{
		if(a[i]==1)
		{
			b[tmp]=i;
			tmp++;
		}
	}
	ll ans=1;
	for(int i=n-1; i>=0; i--)
	{
		if(n+i<=b[i])
		{
			cout << '0' << endl;
			return 0;
		}
		ans=ans*((ll)(2*i+1-b[i]))%mod;
	}
	ll kai=1;
	rep(i, n) kai=kai*((ll)(i+1))%mod;
	ans=ans*kai%mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1796
#include <stdio.h>
int main(){
  int x,y,i,tmp,r;

scanf("%d%d",&x,&y);

if(x<y){
tmp = x;
x = y;
y = tmp;
}

r = x%y;
while(r != 0){
  x = y;
  y = r;
  r = x%y;
}
printf("%d\n",y);
return 0;
}


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


const int MOD = 1e9+7;

int main(void){
    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());
    std::vector<long long> dp(13);
    int mul = 1;
    dp[0] = 1;
    for(int i = 0; i < s.size(); i++){
        std::vector<long long> dp_next(13);
        if(s[i] == '?'){
            for(int j = 0; j < 13; j++){
                for(int k = 0; k < 10; k++){
                    dp_next[(mul * k + j) % 13] += dp[j] % MOD;
                }
            }
        }else{
            for(int j = 0; j < 13; j++){
                dp_next[(mul * (s[i] - '0') + j) % 13] += dp[j] % MOD;
            }
        }
        mul = (mul * 10) % 13;
        std::swap(dp, dp_next);
    }
    std::cout << dp[5] % MOD << std::endl;
    return 0;
}

Measured memory_bytes: 3768
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

ll mod_pow(ll x,ll n,ll m){
    if(n==0) return 1;
    ll res=mod_pow(x*x%m,n/2,m);
    if(n&1) res=res*x%m;
    return res;
}

int main(){
    ll H,W,A,B;
    cin>>H>>W>>A>>B;
    ll h=H-A-1;
    ll w=W-B-1;
    ll c=1;
    ll ww=W-1;
    for(ll i=0;h+ww-i>ww;i++) c=(c*(h+ww-i))%mod;
    for(ll i=2;i<=h;i++) c=(c*mod_pow(i,mod-2,mod))%mod;
    ll ans=c;
    ll sum=h+ww;
    ll cnt=A;
    ll a=A;
    for(ll i=0;i<w;i++){
        c=(c*mod_pow(sum-i,mod-2,mod))%mod;
        c=(c*(ww-i))%mod;
        ans=(ans+(c*(cnt%mod))%mod)%mod;
        cnt=(cnt*(a+1))%mod;
        cnt=(cnt*mod_pow(i+2,mod-2,mod))%mod;
        a++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256