akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k - 1] = tolower(s[k - 1]);
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const p=1e9+7;
int c[1000005],w[1000005],lg2[1000005];
int mod(int x){return x>=p?x-p:x;}
int main()
{
    int h,ans=0;
    scanf("%d",&h);
    for(int i=(1<<(h-1));i<(1<<h);i++)scanf("%d",&c[i]),c[i]+=(1<<(h-1))-1;
    for(int i=2;i<(1<<(h-1));i++)lg2[i]=lg2[i>>1]+1;
    for(int i=1;i<(1<<(h-1));i++)
    {
        int t=lg2[i]+1;
        for(int j=0;j<(1<<(h-t-1));j++)
        {
            int x=(i<<(h-t))+j,now=x,prod=i;
            while(now!=i)prod=1ll*prod*now%p,now>>=1;
            now=c[x];
            while(now)prod=1ll*prod*now%p,w[now]=mod(w[now]+prod),now>>=1;
        }
        for(int j=(1<<(h-t-1));j<(1<<(h-t));j++)
        {
            int x=(i<<(h-t))+j,now=x,prod=1,pre=0;
            while(now!=i)prod=1ll*prod*now%p,now>>=1;
            now=c[x];
            while(now)
            {
                ans=mod(ans+1ll*(w[now]-1ll*w[pre]*now%p+p)*prod%p);
                prod=1ll*prod*now%p,pre=now,now>>=1;
            }
        }
        for(int j=0;j<(1<<(h-t-1));j++)
        {
            int now=c[(i<<(h-t))+j];
            while(now)w[now]=0,now>>=1;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 5856
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, C = ds_in()

DIFF = []
for _ in range(C):
    DIFF.append(ds_in())
DIFF = np.array(DIFF).T

c_list = []
for _ in range(N):
    c_list.append(ds_in())

mod_c = np.zeros((3, C))
for i in range(N):
    for j in range(N):
        if (i + j) % 3 == 0:
            mod_c[0, c_list[i][j] - 1] += 1
        elif (i + j) % 3 == 1:
            mod_c[1, c_list[i][j] - 1] += 1
        else:
            mod_c[2, c_list[i][j] - 1] += 1

# calculate all diff

diff0 = np.dot(DIFF, mod_c[0])
diff1 = np.dot(DIFF, mod_c[1])
diff2 = np.dot(DIFF, mod_c[2])

min_diff = float('inf')
for i in range(C):
    for j in range(C):
        if i == j:
            continue
        for k in range(C):
            if i == k or j == k:
                continue
            min_diff = min(min_diff, diff0[i] + diff1[j] + diff2[k])

print(int(min_diff))


Measured memory_bytes: 17588
fun main(args: Array<String>) {

    val tokenList = readLine()?.split(" ").orEmpty()
    val numA = tokenList[0].toInt()
    val numB = tokenList[1].toInt()
    val numC = tokenList[2].toInt()

    if(numA == numB && numB == numC) {
        println("No")
    } else if(numA != numB && numB != numC && numC != numA){
        println("No")
    } else {
        println("Yes")
    }

}

Measured memory_bytes: 37816
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;

    int ans = 0;
    queue<long long int> q;
    q.push(0);
    while(!q.empty()){
        long long int f = q.front();
        q.pop();

        if(n < f) continue;

        int c3 = 0, c5 = 0, c7 = 0;
        for(long long int d = 1;d < f;d *= 10){
            if(f / d % 10 == 3) c3++;
            if(f / d % 10 == 5) c5++;
            if(f / d % 10 == 7) c7++;
        }

        if(c3 && c5 && c7) ans++;

        q.push(f * 10 + 3);
        q.push(f * 10 + 5);
        q.push(f * 10 + 7);
    }

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

Measured memory_bytes: 768
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#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 repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = 16714589;
const int N = 1e5 + 555; // TL MB
const double PI = acos(-1.0);
double eps = 1e-6;

void solve()
{
	int n;
	cin >> n;
	ll a[n];
	map<ll, ll> d;
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += (d[i - a[i]]);
		d[i + a[i]]++;
	}
	cout << sum;
}


 
 
int main()
{
	Red;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
  	int T = 1; 
  	//cin >> T; 
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
    return 0;
}

Measured memory_bytes: 27876
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, M, C[30], x[20010];
int dp[2][300];
const int kInf = 1 << 28;

void init() {
  rep(i,M) scanf("%d", C+i);
  rep(i,N) scanf("%d", x+i);
}

inline int pow(int v) {
  return v * v;
}

void run() {
  rep(i,2) fill(dp[i], dp[i] + 300, kInf);
  dp[0][128] = 0;
  int *prv = dp[0], *nxt = dp[1];
  
  rep(i,N) {
    fill(nxt, nxt + 300, kInf);
    rep(j,256) {
      rep(k,M) {
        int cur = j, next = j + C[k];
        if (prv[cur] == kInf) continue;
        if (next < 0) next = 0;
        if (next > 255) next = 255;
        int diff = pow(next - x[i]);
        // printf("cur %d : C %d : next %d : diff %d : nxt[next] %d : prv[cur]+diff %d\n",
        //        cur, C[k], next, diff, nxt[next], prv[cur]+diff);
        nxt[next] = min(nxt[next], prv[cur] + diff);
        // if (nxt[next] > prv[cur] + diff) {
        //   printf("cur %d : C %d : next %d : diff : %d\n", cur, C[k], next, diff);
        // }
      }
    }
    swap(prv, nxt);
  }
  printf("%d\n", *min_element(prv, prv + 256));
}

int main() {
  while (scanf("%d%d", &N, &M), N | M) {
    init();
    run();
  }
  return 0;
}

Measured memory_bytes: 1268
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
 
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
 
public class Main {
    
    
    public static void main(String args[] ) throws Exception {
        StringBuffer str = new StringBuffer();
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        
        int n = sc.nextInt();
        int[] dp = new int[3];
        int[] a = new int[3];
        for(int z=0;z<n;z++){
            int[] new_dp = new int[3];
            for(int j=0;j<3;j++)
                a[j] = sc.nextInt();
            for(int i=0;i<3;i++)
                for(int j=0;j<3;j++){
                    if(i!=j){
                        new_dp[j] = Math.max(new_dp[j],dp[i]+a[j]);
                    }
                }
            
            dp= new_dp;
        }
        int ans = dp[0];
        for(int i=0;i<2;i++){
            ans = Math.max(ans,dp[i+1]);
        }
        
        str.append(ans);
        
        pw.println(str.toString());
        
        pw.close();
    }
     
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
}

Measured memory_bytes: 55272
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#define MOD 1000000007
using namespace std;
int main()
{
	int p, q, r;
	cin >> p >> q >> r;
	cout << (p + q + r - max(max(p, q), r)) << endl;
	return 0;
}

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

int N, M;
vector<vector<int>> G;
vector<int> dp;

int f(int now){
  if(dp[now] != 1e9) return dp[now];
    int mxcount = 0;
    for(auto e:G[now]) mxcount = max(mxcount,f(e)+1);
    dp[now] = mxcount;
    return mxcount;
}

int main() {
    cin >> N >> M;
    G.resize(N);
    dp.resize(N,1e9);
    rep(i,M){
      int x,y;
      cin >> x >> y;
      x--;y--;
      G[x].push_back(y);
    }

    int ans = 0;
    rep(i,N){
      ans = max(ans,f(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 8192
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

typedef struct{
  char CITY[11]; int P; int ANS;
}guide;

int main(void){
  int i, N, j, maxp, a;
  char minc[11];
  guide G[101];
  //読み込み
  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf("%s %d", G[i].CITY, &G[i].P);
    G[i].ANS = i+1;
  }
  //小さい都市名を見つけて、Pの比較
  for(i=0; i<N-1; i++){
    maxp = G[i].P; strcpy(minc, G[i].CITY); a=i;
    for(j=i+1; j<N; j++){
      if(strcmp(G[j].CITY, minc) < 0){
        maxp = G[j].P;
        strcpy(minc, G[j].CITY);
        a=j;
      }
      else if(strcmp(G[j].CITY, minc) == 0){
        if(G[j].P > maxp){
          maxp = G[j].P;
          a=j;
        }
      }
    }
    G[100] = G[i];
    G[i] = G[a];
    G[a] = G[100];
  }
  for(i=0; i<N; i++) {
    printf("%d\n", G[i].ANS);
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>

const int MAX_V = 101;
const int INF = 0x3f3f3f3f;

//??? T???cap??????rev????????°???????????§?????£???????????????
struct Edge{
	int to;
	int cost;
	Edge(int to_, int cost_) :to(to_), cost(cost_){}
};

std::vector<Edge > G[MAX_V]; //??£??\?????????

int d[11][MAX_V]; //[?????¨???????????±??????????????°][?????????]
int pre[MAX_V];

void AddEdge(int from, int to, int cost){
	G[from].push_back(Edge(to, cost));
}

void ClearEdge(){
	for (int i = 0; i < MAX_V; ++i) G[i].clear();
	memset(d, 0, sizeof(d));
	memset(pre, -1, sizeof(pre));
}

void Dijkstra(int c, int s){
	typedef std::pair<int, int> P; //first:???????????¢, second:????????????

	std::priority_queue<P, std::vector<P>, std::greater<P> > q;
	std::fill(d[c], d[c] + MAX_V, INF);
	memset(pre, -1, sizeof(pre));
	d[c][s] = 0;
	q.push(P(0, s));

	while (!q.empty()){
		P p = q.top(); q.pop();
		int from = p.second;
		if (d[c][from] < p.first) continue;
		for (Edge e : G[from]){
			int dmin;
			if (c == 0)
				dmin = d[c][from] + e.cost;
			else
				dmin = std::min(d[c][from] + e.cost, d[c - 1][from] + e.cost / 2);

			if (d[c][e.to] > dmin){
				d[c][e.to] = dmin;
				q.push(P(d[c][e.to], e.to));
				pre[e.to] = from;
			}
		}
	}
}

std::vector<int> GetPath(int t){
	std::vector<int> path;
	for (; t != -1; t = pre[t]) path.push_back(t);
	std::reverse(path.begin(), path.end());

	return path;
}

using namespace std;

int main(void){
	int c, n, m, s, g;
	while (1){
		cin >> c >> n >> m >> s >> g;
		if (c == n && n == m && m == s && s == g && g == 0) return 0;
		int a, b, f;
		for (int i = 0; i < m; ++i){
			cin >> a >> b >> f;
			AddEdge(a, b, f);
			AddEdge(b, a, f);
		}
		for (int i = 0; i <= c; ++i){
			Dijkstra(i, s);
		}
		cout << d[c][g] << endl;
		ClearEdge();
	}
}

Measured memory_bytes: 1224
def solve():
    a, b, c = list(map(int, input().split()))

    if a + b >= c:
        print("No")
        return

    lhs = 4 * a * b
    rhs = (c - a - b) ** 2

    if lhs < rhs:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    solve()

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

#define PMAX 10000

int main() {
  bool p[PMAX+1];
  int n, t;
  vector<int> twin;
  vector<int>::iterator it;
  for (int i=0; i<=PMAX; i++) p[i] = true;
  for (int i=2; i*i<=PMAX; i++) {
    for (int j=2*i; j<=PMAX; j+=i) {
      p[j] = false;
    }
  }
  for (int i=2; i<=PMAX; i++) {
    if (p[i] && p[i+2]) {
      twin.push_back(i+2);
    }
  }

  while (1) {
    cin >> n;
    if (!n) break;
    it = upper_bound(twin.begin(), twin.end(), n);
    --it;
    cout << (*it)-2 << " " << *it << endl;
  }

  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint=2e18;
const ll minint =-2e18;
/*******\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\*     */

int main(){
    string s;
    cin>>s;
    if(s[sz(s)-1] == 's'){
        cout<<s<<"es\n";
    }else cout<<s<<"s\n";
    return 0;
}

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

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

    int ans = 0;
    for (int i = 1; i <= min(N, K); i++) {
        for (int j = 0; j <= i; j++) {
            vector<int> p;
            for (int k = 0; k < j; k++) p.push_back(v[k]);
            for (int k = N - i + j; k < N; k++) p.push_back(v[k]);
            sort(p.begin(), p.end());
            int rest = K - i; // 残り手数
            int sum = 0;
            for (int k = 0; k < (int)p.size(); k++) {
                if (p[k] <= 0 && rest > 0) rest--;
                else sum += p[k];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	t := 0
	s := make([]int, m)
	for i := range s {
		fmt.Scan(&s[i])
		t += s[i]
	}

	if n < t {
		fmt.Println("-1")
		return
	}

	fmt.Println(n - t)
}

// =================================
// I/O util
// =================================

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

Measured memory_bytes: 2492
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

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

int main()
{
    int N, M;
    cin >> N >> M;
    
    string s, t;
    cin >> s;
    cin >> t;

    int g = gcd(N, M);
    long long l = (long long) N * M / g;

    int a = M/g;
    int b = N/g;
    
    int flag = 0;
    int le = min(N,M)/(min(N,M)/g);

    for(int i = 0; i < le; i++)
    {
        // cout << s[i*b] << " " << t[i*a] << endl;
        if(s[i*b] != t[i*a]){
            cout << -1 << endl;
            return 0;            
        }
    }

    cout << l << endl;
    return 0;
}

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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define SIZE(arr) ((int)arr.size())
#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;

using namespace std;

using ll = long long;

const int MOD = 1e9 + 7;
const ll INF_LLONG = 1e18 + 9;
const int INF_INT = 1e9 + 9;

template<typename T>
unsigned int index_of_max(vector<T>& arr) {
	unsigned int idx = 0;
	for (int i = 0; i < arr.size(); ++i) {
		if (arr[i] > arr[idx])
			idx = i;
	}
	return idx;
}

template<typename T>
unsigned int index_of_min(vector<T>& arr) {
	unsigned int idx = 0;
	for (int i = 0; i < arr.size(); ++i) {
		if (arr[i] < arr[idx])
			idx = i;
	}
	return idx;
}

int main()
{
	//	#ifndef ONLINE_JUDGE
	//		(void)freopen("input.txt", "r", stdin);
	//		(void)freopen("output.txt", "w", stdout);
	//	#endif	
	FAST_IO;
	int n, m;
	cin >> n >> m;
	cout << (n * (n - 1)) / 2 + (m * (m - 1) / 2);
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n,w,d;
        cin >> n >> w >> d;
        if(n == 0 && w == 0 && d == 0) break;
        vector<i_i> cakes;
        cakes.push_back({-1, -1});
        cakes.push_back({w, d});
        while(n--) {
            int p, s;
            cin >> p >> s;
            i_i now = cakes[p];
            cakes.erase(cakes.begin() + p);
            s %= (now.first + now.second);
            i_i new1 = now, new2 = now;
            if(s < now.first) {
                new1.first = s;
                new2.first = now.first - s;
            } else {
                s -= now.first;
                new1.second = s;
                new2.second = now.second - s;
            }
            if(new1 > new2) swap(new1, new2);
            cakes.push_back(new1);
            cakes.push_back(new2);
        }
        vector<int> ans;
        for(int i = 1; i < cakes.size(); i++) {
            ans.push_back(cakes[i].first * cakes[i].second);
        }
        sort(ans.begin(), ans.end());
        for(int i = 1; i < cakes.size(); i++) {
            cout << ans[i-1];
            if(i != cakes.size() - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)
#define YN(f) f?cout<<"YES"<<endl:cout<<"NO"<<endl;
#define yn(f) f?cout<<"Yes"<<endl:cout<<"No"<<endl;

bool f[1100000];
int ans;

signed main(){
	int s;cin>>s;
	loop{
		ans++;
		if(f[s]){
			break;
		}
		f[s]=true;
		if(s%2==0)s=s/2;
		else s=3*s+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
const int MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 600001;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    auto solve = [](int _) {
        int r, c;
        cin >> r >> c;
        int n;
        cin >> n;
        vector<array<pair<int, int>, 2>> segs(n);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < 2; ++j) {
                cin >> segs[i][j].first >> segs[i][j].second;
            }
        }


        auto is_feasible = [&](pair<int, int> p) {
            return (p.first == 0 || p.first == r) || (p.second == 0 || p.second == c);
        };
        ld cent_x = r * 0.5;
        ld cent_y = c * 0.5;
        vector<pair<ld, ld>> feasible_segs;
        for (int i = 0; i < n; ++i) {
            if (!is_feasible(segs[i][0]) || !is_feasible(segs[i][1])) {
                continue;
            }
            array<ld, 2> ang;
            for (int e = 0; e < 2; ++e) {
                ang[e] = atan2(segs[i][e].second - cent_y, segs[i][e].first - cent_x);
            }
            if (ang[0] > ang[1]) {
                swap(ang[0], ang[1]);
            }
            feasible_segs.emplace_back(ang[0], ang[1]);
        }
        vector<pair<ld, int>> ev;
        for (int i = 0; i < feasible_segs.size(); ++i) {
            ev.push_back({feasible_segs[i].first, i + 1});
            ev.push_back({feasible_segs[i].second, -(i + 1)});
        }
        stack<int> st;
        sort(ev.begin(), ev.end());
        bool ok = true;
        for (auto e:ev) {
            if (e.second > 0) {
                st.push(e.second);
            } else {
                if (-e.second != st.top()) {
                    ok = false;
                    break;
                }
                st.pop();
            }
        }
        if (ok) {
            cout << "YES";
        } else {
            cout << "NO";
        }
    };


    fast_io();

    cout.precision(9);
    cout <<
         fixed;
    for (int i = 1; i <= 1; ++i)
        solve(1);


}


Measured memory_bytes: 11016
while True:
    N,X = map(int,input().split())
    if N == X == 0:
        break
    ans = 0
    for i in range(1,1+N):
        for h in range(1+i,1+N):
            for j in range(1+h,1+N):
                if X == i+h+j:ans += 1
    print(ans)


Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

struct Rec{
  int w,h;
  int age;
  bool operator==(const Rec r)const{
    return r.w==w&&r.h==h&&r.age==age;
  }
};

int N,W,D;
int P[101];
int S[101];
vector<Rec> recs;
int NumToRec[110];
bool used[110];

int main(){
  while(cin>>N>>W>>D&&(N|W|D)){
    recs.clear();
    Rec init;
    init.w=W;
    init.h=D;
    init.age=0;
    recs.push_back(init);
    NumToRec[1]=0;
    for(int i=0;i<N;i++)cin>>P[i]>>S[i];
    for(int i=0;i<N;i++){
      Rec r=recs[NumToRec[P[i]]];
      for(int j=0;j<recs.size();j++){
	if(recs[j]==r){
	  recs.erase(recs.begin()+j);
	  break;
	}
      }
      S[i]%=(r.w+r.h);
      if((S[i]>=0&&S[i]<=r.w)||(S[i]>=r.w+r.h&&S[i]<=2*r.w+r.h)){
	int nw=S[i];
	if(S[i]>=r.w+r.h)nw=S[i]-r.w-r.h;
	Rec r1,r2;
	r1.age=r2.age=i+1;
	r1.w=nw;r1.h=r.h;
	r2.w=r.w-nw;r2.h=r.h;
	recs.push_back(r1);
	recs.push_back(r2);
      }
      else{
	int nh=S[i];
	if(S[i]>=2*r.w+r.h)nh=S[i]-2*r.w-r.h;
	else nh=S[i]-r.w;
	Rec r1,r2;
	r1.age=r2.age=i+1;
	r1.w=r.w;r1.h=nh;
	r2.w=r.w;r2.h=r.h-nh;
	recs.push_back(r1);
	recs.push_back(r2);
      }
      memset(NumToRec,-1,sizeof(NumToRec));
      memset(used,0,sizeof(used));
      for(int k=1;k<=recs.size();k++){
	vector<int> oldest;
	int num=1000000;
	for(int j=0;j<recs.size();j++){
	  if(used[j])continue;
	  if(recs[j].age<num){
	    oldest.clear();
	    num=recs[j].age;
	    oldest.push_back(j);
	  }
	  else if(recs[j].age==num)
	    oldest.push_back(j);
	}
	int cand=oldest[0];
	for(int j=1;j<oldest.size();j++){
	  int candS=recs[cand].w*recs[cand].h;
	  int curS=recs[oldest[j]].w*recs[oldest[j]].h;
	  if(curS<candS)cand=oldest[j];
	}
	used[cand]=true;
	NumToRec[k]=cand;
      }
    }
    vector<int> res;
    for(int i=0;i<recs.size();i++)
      res.push_back(recs[i].w*recs[i].h);
    sort(res.begin(),res.end());
    for(int i=0;i<res.size();i++){
      cout<<res[i];
      if(i!=res.size()-1)cout<<" ";
      else cout<<endl;
    }
  }
  

  return 0;
}

Measured memory_bytes: 912
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 998244353
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 200000
ll b[ma],a[ma];
vector<ll>adj[ma],adj1[ma];
void dfs(ll u,ll cmp)
{
    b[u]=cmp;
    a[cmp]++;
    for(auto p:adj[u])
    {
        if(b[p]==0)dfs(p,cmp);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,x,y,n,m,k;
    while(cin>>n>>m>>k)
    {
       for(i=1;i<=m;i++)
       {
           cin>>x>>y;
           adj[x].pb(y);
           adj[y].pb(x);
       }

       for(i=1;i<=k;i++)
       {
           cin>>x>>y;
           adj1[x].pb(y);
           adj1[y].pb(x);
       }

       ll cn=0;

       for(i=1;i<=n;i++)
       {
           if(b[i]==0)
           {
               cn++;
               dfs(i,cn);
           }
       }

       for(i=1;i<=n;i++)
       {
           ll p=a[b[i]]-adj[i].sz;
           p--;
           for(auto x:adj1[i])
           {
               if(b[i]==b[x])p--;
           }
           cout<<p;
           if(i<n)cout<<" ";
           else cout<<endl;
       }


    }

    return 0;
}


Measured memory_bytes: 21940
open Printf
open Str

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f
                                                 
let () =
  let _ = read_line () in
  let s = read_list int_of_string in
  let _ = read_line () in
  let t = read_list int_of_string in
  List.fold_left (fun c x -> if List.mem x s then c+1 else c) 0 t |> string_of_int |> print_endline

Measured memory_bytes: 3980
# Problem - シャッフル

# search
while True:
    S = input()
    if S=='-':
        break

    m = int(input())
    for i in range(m):
        h = int(input())
        s_1 = S[:h]
        s_2 = S[h:]
        S = s_2 + s_1
    # output
    print(S)



Measured memory_bytes: 5592
import itertools
N=int(input())
a="".join(input().split())
b="".join(input().split())
li=[]
for k in itertools.permutations([str(i+1) for i in range(N)],N):
    li.append("".join(k))
li.sort()
print(abs(li.index(a)-li.index(b)))

Measured memory_bytes: 6040
#include <cstdio>
#include <map>
#include <numeric>

using namespace std;
using lint = long long;
using P = pair<lint, lint>;

constexpr lint Mod = 1000'000'007LL;

lint n, cnt_zero, cnt1, cnt2, mul, ans = 1;
lint pow2[2 * 100010];
map<P, lint>mp;
map<P, bool>used;
int main() {
	scanf("%lld", &n);

	pow2[0] = 1;

	for(lint i = 0; i < n; ++i) {
		lint a, b;
		scanf("%lld %lld", &a, &b);

		if (b < 0) a = -a, b = -b;

		if (a == 0 && b == 0) ++cnt_zero;
		else {
			const lint g = gcd(a, b);

			++mp[P(a / g, b / g)];
		}

		pow2[i + 1] = (pow2[i] << 1) % Mod;
	}

	for (const auto& p : mp) {
		if (used[p.first]) continue;

		const auto [x, y] = p.first;

		mul = pow2[p.second];

		P p1(-y, x);

		if (p1.second < 0) p1.first = y, p1.second = -x;

		used[p1] = true;

		if (mp.find(p1) != mp.end()) {
			cnt2 = mp[p1];

			mul += pow2[cnt2] - 1;
			mul %= Mod;

			cnt1 += p.second + cnt2;

			ans *= mul;
			ans %= Mod;
		}
	}

	ans *= pow2[n - cnt1 - cnt_zero];
	ans %= Mod;

	ans += cnt_zero;
	ans %= Mod;

	if (0 < ans) ans--;
	else ans = Mod - 1;
	
	printf("%lld\n", ans);
}

Measured memory_bytes: 42288
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    
    if(a==b){
        if(b==c){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(a==c){
            cout << "Yes" << endl;
        }else if(b==c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def prime_factorize(n):
    f = defaultdict(lambda: 0)
    f[2] = len(bin(n & -n)) - 3
    i = 3
    k = n >> f[2]
    while k > 1:
        while True:
            d, m = divmod(k, i)
            if m == 0:
                f[i] += 1
                k = d
            else:
                break
        i += 2
    return f


MOD = 1000000007
n, m = map(int, input().split())
pf = prime_factorize(m)
mx = max(pf.values())
f, r = prepare(n + mx, MOD)
ans = 1
for p, e in pf.items():
    ans *= f[n + e - 1]
    ans %= MOD
    ans *= r[n - 1]
    ans %= MOD
    ans *= r[e]
    ans %= MOD
print(ans)


Measured memory_bytes: 46320
#include <cstdio>
    #include <cstring>
    using namespace std;
    int n;
    int t[100050],x[100050],y[100050];
    int dis,times;
    bool flag;
    int read()
    {
    	int s=0,t=1; char c;
    	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
    	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
        return s*t;
    }
    int main()
    {
    	n=read(); flag=true;
    	for (int i=1;i<=n;i++) 
    	{
    	  t[i]=read(),x[i]=read(),y[i]=read();
          dis=x[i]-x[i-1]+y[i]-y[i-1]; times=t[i]-t[i-1];
          if (times<dis) flag=false;
          else 
    	  {
    	  	times-=dis; 
    	  	if (times%2!=0) flag=false;
          }
          if (not flag) break;
      }
      if (flag) puts("Yes");
      else puts("No");
      return 0;
    }

Measured memory_bytes: 1280
#include<stdio.h>

#define N 100

void SelectionSort(int[],int);
/*スワップ数*/
int count=0;
int main(){
  int i,n;
  int A[N];
  scanf("%d",&n);
  /*配列格納*/
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  /*SelectionSort*/
  SelectionSort(A,n);
  /*スワップ後の数&とスワップ数表示*/
  for(i=0;i<n-1;i++)
    
  printf("%d ",A[i]);
  
  printf("%d\n",A[n-1]);
 
  printf("%d\n",count);
  return 0;}
/*SelectionSort*/
void SelectionSort(int A[],int n)
{
  int i,j,mini,temp,hit=0;
 
  
  for(i=0;i<n;i++){
    mini=i;
    hit=0;
    for(j=i+1;j<n;j++){
      if(A[j]<A[mini]){
	mini=j;
	hit=1;
      }
      
    }
    temp=A[i];
    A[i]=A[mini];
    A[mini]=temp;
    if(hit==1)
    count++;
  }
  

}



Measured memory_bytes: 2752
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N,A,B;

	scanf("%d %d %d",&N,&A,&B);

	printf("%d\n",min(N*A,B));

	return 0;
}


Measured memory_bytes: 256
n,a,b=map(int,input().split())

c=n//(a+b)
d=n%(a+b)
e=c*a
f=c*d

if n<=a:
  print(n)
elif a<n<a+b:
  print(a)
elif a+b<=n and d<=a:
  print(e+d)
elif a+b<=n and a<=d:
  print(e+a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    cout<<(x-a)%b<<endl;
}

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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		Map<Integer, Integer> soinsu = bunkai(m);
		long ans = 1;
		for (int k : soinsu.keySet()) {
			int v = soinsu.get(k);
			ans *= nCr(v + n - 1, v);
			ans %= 1000000007;
		}
		System.out.println(ans);
	}

	static Map<Integer, Integer> bunkai(int n) {
		Map<Integer, Integer> soinsu = new HashMap<Integer, Integer>();
		int end = (int) Math.sqrt(n);
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}

	static long nCr(long n, long r) {
		long m = 1000000007;
		long val = 1;
		for (int i = 1; i <= r; i++) {
			val = val * (n - i + 1) % m;
			val = val * modinv(i, m) % m;
		}
		return val;
	}

	static long modinv(long a, long m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

const int MOD = 1000000007;

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

    if(x == 0) {
        cout << "1" << endl;
    } else {
        cout << "0" << endl;
    }
}

Measured memory_bytes: 3628
use std::io::*;
use std::str::FromStr;

const MOD: usize = 1_000_000_007;

fn main() {
    let n: usize = read();
    let mut a = vec![0; n];

    for i in 0..n {
        a[i] = read();
    }

    let mut rui = vec![vec![0; n+1]; 61];
    for i in 0..n {
        for j in 0..61 {
            rui[j][i+1] += rui[j][i];
            rui[j][i+1] += 1 & (a[i] >> j);
        }
    }

    let mut ans = 0;
    for i in 0..n {
        for j in 0..61 {
            let po = (1 << j) % MOD;
            if 1 & (a[i] >> j) == 0 {
                ans += ((rui[j][n] - rui[j][i+1]) * po) % MOD;
            } else {
                ans += ((n - i - (rui[j][n] - rui[j][i+1])-1) * po) % MOD;
            }
            ans %= MOD;
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 258300
using System;
using System.Linq;
using System.Collections.Generic;

class MyClass
{
    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var N = input[0];
        var M = input[1];
        var a = new int[M];
        var b = new int[M];
        for (int i = 0; i < M; i++)
        {
            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            a[i] = input[0];
            b[i] = input[1];
        }
        var c = a.Where(x => x >= N).Count();
        var cost = 0;
        var d = a.Where(x => x < N).ToList();
        d.Sort();
        d.Reverse();
        for (int i = 0; i < (M - 1) - c; i++)
        {
            cost += N - d[i];
        }
        Console.WriteLine(cost);
    }
}


Measured memory_bytes: 16400
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

double dst(pii a, pii b) {
	return sqrt((double) (a.fi - b.fi) * (a.fi - b.fi) + (a.se - b.se) * (a.se - b.se));
}

int fact(int n) {
	int ans = 1;
	for (int i = 1; i <= n; i++) ans *= i;
	return ans;
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	vector<pii> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i].fi >> v[i].se;
	}
	vector<int> per;
	for (int i = 0; i < n; i++) per.push_back(i);
	double sum = 0;
	do {
		for (int i = 1; i < n; i++) {
			sum += dst(v[per[i]], v[per[i - 1]]);
		}
	} while (next_permutation(per.begin(), per.end()));
	cout << setprecision(6) << fixed << sum / fact(n) << "\n";
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    
	    int V [] = new int [N];
        for(int i = 0; i < N; i++)
        	V [i] = scanner.nextInt();
        
        int C [] = new int [N];
        for(int i = 0; i < N; i++)
        	C [i] = scanner.nextInt();
       
        int price = 0;
        for(int i = 0; i < N; i++){
        	if (V[i]>C[i]){
        		price = price + V[i]-C[i];
        	}
        }
        System.out.print(price);

	}

}


Measured memory_bytes: 23124
#include <stdio.h>
int main(void)
{
	int a, b;
	
	scanf("%d %d",&a,&b);
	
	if(a < b){
		printf("a < b\n");
	}
	
	else if(a > b){
		printf("a > b\n");
	}
	
	if(a == b){
		printf("a == b\n");
	}

	return	0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  string a,b;
  cin>>a>>b;
  if(a.size()>b.size()){
  cout<<"GREATER";
    return 0;
    }
  else if(a.size()<b.size()){
    cout<<"LESS";
    return 0;
    }
  else{
    rep(i,a.size()){
      if(a.at(i)<b.at(i)){
        cout<<"LESS";
      return 0;
        }
      else if(b.at(i)<a.at(i)){
        cout<<"GREATER";
          return 0;
        }
      }
  }
  cout<<"EQUAL";
}

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

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    ll a[n+1], b[m+1];
    a[0] = 0;
    b[0] = 0;
    
    for (int i=1;i<=n;i++){
        cin >> a[i];
        a[i] += a[i-1];
    }
    for (int i=1;i<=m;i++){
        cin >> b[i];
        b[i] += b[i-1];
    }
    
    int best = m;
    int ans =0;
    for (int i=0;i<=n;i++){
        for(int j=best;j>=0;j--){
            if(b[j]<= k-a[i]){
                best = j;
                ans = max(i+j, ans);
                break;
            }
        }
    }
    
    cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6760
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) rep(i, begin, end) PRINT_ARRAY(name, i)


using namespace std;

typedef long long ll;

int N, K;
int ans = -1;
char S[100005];
int sum[100005];
vector<int> R;


int main(void) {
    scanf("%d %d", &N, &K);
    scanf("%s", S);
    
    int n = strlen(S);
    
    int i = 0;
    while(i<n) {
      int c = 1;
      while (S[i] == S[i+1] && i<n){c++; i++;}
      R.push_back(c);
      i++;
    }
    
    i = 1;
    sum[0] = R[0];
    while (i<R.size()) {
      sum[i] = sum[i-1] + R[i];
      i++;
    }
    
    
    i = 0;
    if (S[0] == '0') {
      int j = min((int)R.size()-1, i+2*K-1);
      ans = max(ans, sum[j]-sum[i-1]);
      i++;
    
    }
    while(i<R.size()) {
      int j = min((int)R.size()-1, i+2*K);
      ans = max(ans, sum[j]-sum[i-1]);
      i += 2;
    
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1272
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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


	int a[50];
	int n, l, r;
	
	while (cin >> n >> l >> r, n) {
		rep(i, n)cin >> a[i];

		int ans = 0;
		for (int x = l; x <= r;x++) {
			int idx = -1;
			rep(i, n) {
				if (x%a[i]==0) {
					idx = i;
					break;
				}
			}

			if (idx!=-1) {
				if (idx % 2 == 0)ans++;
			}
			else if (n%2==0) {
				ans++;
			}

		}
		cout << ans << endl;

	}



	return 0;
}


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

void solve() {
    int N; cin >> N;
    using P = pair<double, double>;
    vector<P> pairs(N);
    rep(i, N) {
        double a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    vector<int> A;
    rep(i, N) A.push_back(i);
    sort(A.begin(), A.end());
    double sum = 0;
    int cnt = 0;
    do {
        for(int i = 0; i < N - 1; ++i) {
            double tmp = pairs[A[i]].first - pairs[A[i + 1]].first;
            double tmp2 = pairs[A[i]].second - pairs[A[i + 1]].second;
            tmp = tmp * tmp;
            tmp2 = tmp2 * tmp2;
            sum += sqrt(tmp + tmp2);
        }
        ++cnt;
    } while(next_permutation(A.begin(), A.end()));
    printf("%.10lf\n", sum / cnt);
}

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


Measured memory_bytes: 256
#include<stdio.h>
typedef struct tag_query
{
    int l;
    int r;
} query;


int main(void){
    int n,q;
    scanf("%d %d",&n,&q);
    char str[n + 1];
    scanf("%s",str);
    query Query[q];
    for(int i = 0;i < q;i++){
        scanf("%d %d",&(Query[i].l),&(Query[i].r));
    }
    int  cusum_c[n + 2];
    cusum_c[0] = 0;

    for(int i = 0;i < n + 2;i++){
        cusum_c[i] = 0;
    }
    //printf("%s\n",str);
    for(int i = 2;i < n + 2;i++){
        if(str[i - 1] == 'C'&& str[i - 2] == 'A'){
           cusum_c[i] = cusum_c[i - 1] + 1;
        }else{
            cusum_c[i] = cusum_c[i - 1];
        }
    }
    for(int i = 0;i < q;i++){
        printf("%d\n",cusum_c[Query[i].r] - cusum_c[Query[i].l]);
    }
    return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr long double EPSL = numeric_limits<long double>::epsilon();
static constexpr const char* YES = "Yes";
static constexpr const char* NO = "No";

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll a, b, c;
  cin >> a >> b >> c;

  ll t = c - a - b;
  if (t > 0 && 4 * a * b < t * t) {
    put(YES);
    return 0;
  }

  put(NO);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
  	int n, a;
  	cin >> n >> a;
  	n %= 500;
  	cout << (n <= a ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int x, y;
    cin >> x >> y;

    if ((y % 2 == 0) && (y >= 2 * x) && (y <= 4 * x))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
# coding:utf-8

def main():
    N,M = map(int,input().split())
    stores = []
    cost = 0
    number = 0

    for i in range(N):
        A,B = map(int,input().split())
        stores.append([A,B])
    stores.sort()

    for store in stores:
        if number + store[1] >= M:
            cost += (M - number)*store[0]
            break
        else:
            number += store[1]
            cost += store[0]*store[1]

    print(cost)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20072
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
  	unsigned long int w_count = 0, move = 0;
  	cin >> s;
  	for (int i = 0; i < s.length(); i++){
    	if (s[i] == 'W'){
        	w_count++;
          	move += (i - w_count + 1);
        }
    }
  	cout << move << endl;
}

Measured memory_bytes: 640