akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

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

    cout << (n-2)*180 << endl;

    return 0;
}

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

  long long a,b,c,x,y;

  cin>>a>>b>>c>>x>>y;
  
  long long ans=0;
  if(x>y){
    ans=min((a*y+b*y),(c*(y*2)));
  }else if(x<=y){
    ans=min((a*x+b*x),(c*(x*2)));
  }

  if(x>y){
   
    ans+=min((a*(x-y)),(c*((x-y)*2)));
    
  
    
  }else if(x<=y){
    
    ans+=min((b*(y-x)),(c*((y-x)*2)));
    

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
		public static void main(String[] args) {
			Scanner scanner = new Scanner(System.in);
			int animals = scanner.nextInt();
			int legs = scanner.nextInt();
			int cranes = (legs - 2 * animals) / 2;
			int turtles = animals - cranes;
			boolean result = true;
			
			if(turtles * 2 + cranes * 4 != legs || turtles < 0 || cranes < 0) {
				result = false;
			}
			
			String decision = result? "Yes" : "No";
			System.out.print(decision);
		}
}


Measured memory_bytes: 27040
N, W = map(int, input().split())
items = [[0, 0]]
for _ in range(N):
    items.append(list(map(int, input().split())))

dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(W + 1):
        if j - items[i][0] >= 0:
            dp[i][j] = max(dp[i - 1][j - items[i][0]] + items[i][1], dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]

print(max(dp[N]))

Measured memory_bytes: 171912
n,q=map(int,input().split())
s=input()
ac=[0]*(n)
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        ac[i+1]=ac[i]+1
    else:
        ac[i+1]=ac[i]
#print(ac)
# 01122233
# ACACTACG
for i in range(q):
    l,r=map(int,input().split())
    #print(ac[l:r])
    print(ac[r-1]-ac[l-1])

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

int main(){
  int m,n, ans=0;

  cin >> m >> n;
  for( int i=0,sum;i<m;i++ ){ // 参加者
    sum=0;
    for( int j=0,k;j<n;j++ ){
      cin >> k; sum+=k;
    }
    if( sum>ans ) ans = sum;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define ll long long int
#define MIN(x,y) (x)>(y)?(y):(x)
#define MAX(x,y) (x)>(y)?(x):(y)
#define ABS(x) (x)>0?(x):(-x)

bool isPositive(ll x){
	if(x>0)return true;
	return false;
}

int main(void){
	int n;
	scanf("%d",&n);
	ll a[n];
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	ll ans=0,ans2=0,sum=0;
	
	//npnpnp...
	for(int i=0;i<n;i++){
		sum+=a[i];
		if(i%2==0){
			if(sum>=0){
				ans+=sum+1;
				sum=-1;
			}
		}
		else{
			if(sum<=0){
				ans+=1-sum;
				sum=1;
			}
		}
	}
	
	sum=0;
	for(int i=0;i<n;i++){
		sum+=a[i];
		if(i%2==0){
			if(sum<=0){
				ans2+=-sum+1;
				sum=1;
			}
		}
		else{
			if(sum>=0){
				ans2+=1+sum;
				sum=-1;
			}
		}
	}
	ans=MIN(ans,ans2);
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 896
#include <iostream>

#include <vector>

using namespace std;

int main(){
	int N,T;
	int temp;

	vector<int> c,t;

	cin >> N >> T;

	for(int i=0; i<N;i++){
		cin >> temp;
		c.push_back(temp);

		cin >> temp;
		t.push_back(temp);
	}

	temp = 1001;

	for(int i=0; i<N; i++){
		if(t[i] <= T){
			if(temp > c[i]){
				temp = c[i];
			}
		}
	}

	if(temp == 1001){
		cout << "TLE" << endl;
	}else{
		cout << temp << endl;
	}

	return 0;
}



Measured memory_bytes: 256
from sys import *
from itertools import *
n=int(input())
l=[i for i in range(1,10**4)]
t=list(accumulate(l))
for i in range(len(t)):
    if t[i]==n:
        ans=l[0:i+1]
        for i in ans:
            print(i)
        exit()
    if t[i]>n:
        m=t[i]-n
        ans=l[0:i+1]
        ans.remove(m)
        for i in ans:
            print(i)
        exit()

Measured memory_bytes: 74596
#include<bits/stdc++.h>
#include<bitset>
#define B bitset<510>
#define INF 0x3f3f3f3f
using namespace std;
inline int read(){
    int w=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        w=(w<<3)+(w<<1)+ch-48;
        ch=getchar();
    }
    return w*f;
}
int n,m,x[200010],y[200010];
bool die[510];
B a[510];
signed main(){
	//freopen("rabbit.in","r",stdin);
	//freopen("rabbit.out","w",stdout);
    n=read();m=read();
    for(int i=1;i<=m;i++){
        x[i]=read();y[i]=read();
    }
    for(int i=1;i<=n;i++){
        a[i][i]=1;
        for(int j=m;j;j--){
            if(a[i][x[j]]&&a[i][y[j]]){
                die[i]=true;break;
            }
            else if(a[i][x[j]]) a[i][y[j]]=true;
            else if(a[i][y[j]]) a[i][x[j]]=true;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(die[i])continue;
        for(int j=i+1;j<=n;j++){
            if(die[j])continue;
            if((a[i]&a[j]).none())ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> t(n);
    for(int i=0; i<n; i++){
        cin >> t[i];
    }
    vector<int> diff(n-1);
    for(int i=0; i<n-1; i++){
        diff[i] = t[i+1] -t[i] -1;
    }
    sort(diff.begin(), diff.end(), greater<int>());
    int ans = t[n-1]+1 -t[0];
    for(int i=0; i<m-1; i++){
        ans -= diff[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3624
def bellman_ford(edges, n, src):
    # n:ノード数, src:スタートノード
    # edges:edge(src, tgt, cost)のリスト
    inf = float('inf')
    dist = [inf for _ in range(n)]
    dist[src] = 0
    # 移動経路
    pre = {}

    # 最短経路算出
    for i in range(n-1):
        for edge in edges:
            # srcにコストがあり、tgtのコストよりも低いコストで更新できそうなら
            if dist[edge[0]] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]
                pre[edge[1]] = edge[0]

    # 負の閉路検出
    def checkpath(pre, n, src):
        if src in pre and pre[n-1] == src and pre[src] == n-1:
            return True
        count = 0
        p = pre[n-1]
        while p != src:
            p = pre[p]
            if p == src and src in pre:
                return True
            count += 1
            if count >= n-1:
                return True
        return False

    is_cycle = checkpath(pre, n, src)
    return (dist, is_cycle)


N, M = map(int, input().split())
edges = []
for _ in range(M):
    a, b, c = map(int, input().split())
    edges.append((a-1, b-1, -c))

d, is_cycle = bellman_ford(edges, N, 0)
if is_cycle:
    print('inf')
else:
    print(-d[N-1])


Measured memory_bytes: 3444
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val ans = readLine()!!.split(" ").map { shiftCount(it.toLong()) }.min()!!
    println(ans)
}

fun shiftCount(n: Long):Int {
    var ret = 0
    var cur = n
    while (cur % 2 == 0L) {
        ret ++
        cur /= 2
    }
    return ret
}


Measured memory_bytes: 37584
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	b := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		b[i] = nextInt()
	}

	sum := 0
	for i := 0; i < n; i++ {
		if i == 0 {
			sum += b[0]
		} else if i == n-1 {
			sum += b[n-2]
		} else {
			sum += min(b[i-1], b[i])
		}
	}
	fmt.Println(sum)
}

Measured memory_bytes: 640
x,n=map(int, input().split())
P=list(map(int, input().split()))
ans=[]
for i in range(102):
    ans.append(i)

m=99999999999999
for p in P:
    del ans[ans.index(p)]
y=99999999999999
#print(ans)
for i in ans:
    if abs(i-x)<y:
        y=abs(i-x)
        m=i

print(m)

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;

signed main(){
	cin >> N;
	
	int t, x, y, st=0, sx=0, sy=0;
	REP(i, 0, N) {
		scanf("%d %d %d", &t, &x, &y);
//		cin >> t >> x >> y;
//        cout << "[" << ((t - st) & 1) << "]  [" << ((x - sx + y - sy) & 1) << "]" << endl;
		if(((t - st) & 1) != ((x - sx + y - sy) & 1)
				|| (t - st) < (x - sx + y - sy)) {
//		if(((t - st) % 2) != ((x - sx + y - sy) % 2)
//				|| (t - st) < (x - sx + y - sy)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    ll ans=1;
    for(int i=1;i<=n;i++){
        ans*=i;
        ans=ans%1000000007;
    }
    cout<<ans<<endl;
    return 0;
}


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

public class Main {
    Scanner sc;
    int H, W;
    char[][] rect;
    int[][] xmax;

    Main() {
        sc = new Scanner(System.in);
    }

    boolean init() {
        H = sc.nextInt();
        W = sc.nextInt();
        if (H == 0 && W == 0) return false;
        rect = new char[H][W];
        for (int i = 0; i < H; i++) 
            rect[i] = sc.next().toCharArray();
        return true;
    }

    void run() {
        while (init()) {
            xmax = new int[H][W];
            for (int i = 0; i < H; i++) {
                if (rect[i][0] == '.') xmax[i][0] = 1;
                else xmax[i][0] = 0;
                for (int j = 1; j < W; j++) {
                    if (rect[i][j] == '.') {
                        xmax[i][j] = xmax[i][j-1]+1;
                    } else {
                        xmax[i][j] = 0;
                    }
                }
            }

            int max_area = 0;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    int min_xmax = xmax[i][j];
                    for (int y = i; y >= 0; y--) {
                        min_xmax = Math.min(min_xmax, xmax[y][j]);
                        max_area = Math.max(max_area, min_xmax * (i-y+1));
                    }
                }
            }

            System.out.println(max_area);
        }
    }

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

Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#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 mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<ll, ll>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

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

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

ll ans = 1, n, a[200005], b[200005];

int main(void) {
    cin >> n;
    ll zero = 0;

    rep(i, 0, n) cin >> a[i] >> b[i];
    
    rep(i, 0, n){
      ll x = a[i], y = b[i];
      if (x==0 && y == 0) continue;
      ll g = gcd(x, y);
      x /= g, y /= g;
      if ((x>0 && y<0) || (x<0 && y<0)) x *= -1, y *= -1;
      a[i] =x, b[i] = y;   
      //printf("%lld %lld %lld\n", x, y, g);
    }
    
    map<P, P> m;
    

    rep(i, 0, n) {
        ll x = a[i], y = b[i];
        if (x==0 && y==0) {
          zero++;
          continue;
        }
        
        bool f = false;
        if (x<=0) {
          ll tmp = x;
          x = y;
          y = -tmp;
          f = true;
        }
        
        auto t = mp(x, y);
        f ? m[t].second++ : m[t].first++;
        
    }
    
    for (auto p : m) {
      ll s = p.second.first, t = p.second.second;
      
      ll x = mod_pow(2, s) - 1;
      x += mod_pow(2, t) -1;
      x += 1;
      x %= MOD;
      
      ans *= x;
      ans %= MOD;
    
    }
    
    ans += zero;
    ans--;
    ans %= MOD;
    if (ans<0) ans += MOD;
    
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 22284
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

X = int(input())

while True:
    if is_prime(X):
        print(X)
        exit()
    else:
        X += 1

Measured memory_bytes: 3060
#include<iostream>
#include <bits/stdc++.h> 
#include<cmath>
using namespace std;
int main()
{
	long long int a;
	string b;
	long long b1;
	
	cin>>a>>b;
	long double pro=1.0;
	b1=((b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0'));
	

	


	




cout<<a*b1/100<<endl;


	
	
}

Measured memory_bytes: 3612
#include <vector>
#include <bitset>
#include <iostream>
#include <algorithm>
#define coor(i,j) ((i)+(j)*m)
#define in(i,j) (0<=(i)&&(i)<m&&0<=(j)&&(j)<n)
using namespace std;
vector<bitset<626> > M(625);

int main(){
	int m,n,d;
	int i,j,k;
	int success,ans;
	for(;cin>>m>>n>>d,d;cout<<ans<<endl){
		//create M
		for(j=0;j<n;j++){
			for(i=0;i<m;i++){
				M[coor(i,j)].reset();
			}
		}
		for(j=0;j<n;j++){
			for(i=0;i<m;i++){
				M[coor(i,j)][coor(i,j)]=1;
				cin>>k;M[coor(i,j)][m*n]=k;

				for(k=0;k<=d;k++){
					if(in(i-k,j-(d-k)))M[coor(i,j)][coor(i-k,j-(d-k))]=1;
					if(in(i+k,j-(d-k)))M[coor(i,j)][coor(i+k,j-(d-k))]=1;
					if(in(i-k,j+(d-k)))M[coor(i,j)][coor(i-k,j+(d-k))]=1;
					if(in(i+k,j+(d-k)))M[coor(i,j)][coor(i+k,j+(d-k))]=1;
				}
			}
		}

		//solve
		k=0;
		for(i=0;i<m*n;i++){
			for(j=k;j<m*n&&!M[j][i];j++);
			if(j==m*n)continue;
			swap(M[k],M[j]);
			for(j=k+1;j<m*n;j++)if(M[j][i])M[j]^=M[k];
			k++;
		}

		//finalize
		ans=1;
		for(j=k;j<m*n;j++)if(M[j][m*n])ans=0;
	}
}

Measured memory_bytes: 1248
package main

import (
	"fmt"
	"math"
)

func main(){
	var N int 
	var a[10000] int
	fmt.Scanf("%d",&N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d",&a[i])
	} 
	Max := a[0]
	Min := a[0]
	for i := 1; i < N; i++ {
		Max = int(math.Max(float64(Max),float64(a[i])))
		Min = int(math.Min(float64(Min),float64(a[i])))
		//fmt.Printf("%d %d\n",Max,Min) 
	}
	fmt.Printf("%d\n",Max-Min)
}

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

main(){
  string n;
  cin >> n;
  if (n[0]==n[1] && n[1]==n[2]) cout << "Yes" << endl;
  else if (n[1]==n[2] && n[2]==n[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
  int a[5];
  for(int i=0;i<5;i++)cin>>a[i];
  sort(a, a+5);
  cout<<a[4];
  for(int n=4;n--;)cout<<" "<<a[n];
  cout<<endl;
  return 0;
}

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

// lib/signum.hpp
#ifndef SIGNUM_HPP
#define SIGNUM_HPP


/*
usage:

tools::signum(-5) // => -1
*/

namespace tools {
  template <typename T>
  constexpr int signum(const T x, const std::false_type) noexcept {
    return T(0) < x;
  }

  template <typename T>
  constexpr int signum(const T x, const std::true_type) noexcept {
    return (T(0) < x) - (x < T(0));
  }

  template <typename T>
  constexpr int signum(const T x) noexcept {
    return signum(x, std::is_signed<T>());
  }
}

#endif

// main.cpp

int main() {
  std::string x, y;
  std::cin >> x >> y;
  std::cout << "<=>"[tools::signum(std::stoi(x, nullptr, 16) - std::stoi(y, nullptr, 16)) + 1] << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int a[n], sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int ave, ave2;
    ave  = sum/n; ave2 = ave+1;
    int ans1 = 0, ans2 = 0;
    for(int i = 0; i < n; i++){
        ans1 += (a[i] - ave)*(a[i] - ave);
        ans2 += (a[i] - ave2)*(a[i] - ave2);
    }
    cout << min(ans1,ans2) << endl;

}


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



int32_t main(){
    int r,c;cin>>r>>c;
    int dp[r+1][c+1];
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            char a;cin>>a;
            if(a=='#'){dp[i][j] = 0;}
        }
    }
    for(int i=1;i<=c;i++){
        if(i==1){dp[1][i] = 1;}
        else{
            if(dp[1][i] != 0){
            dp[1][i] = dp[1][i-1];
        }
        }
    }
    for(int i=1;i<=r;i++){
        if(i==1){dp[i][1] = 1;}
        else{
            if(dp[i][1] != 0){
            dp[i][1] = dp[i-1][1];
        }
        }
    }
    for(int i=2;i<=r;i++){
        for(int j=2;j<=c;j++){
            if(dp[i][j] != 0){
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] = dp[i][j] % 1000000007;
            }
        }
    }
    cout<<dp[r][c];

    
    
    }

    



Measured memory_bytes: 11388
from collections import deque

A=deque(input())
B=deque(input())
C=deque(input())

turn={"a":A,"b":B,"c":C}

next = A.popleft()

flag = True
while flag:
  if len(turn[next]) != 0:
    next = turn[next].popleft()
  else:
    print(next.upper())
    break

Measured memory_bytes: 3316
#include "bits/stdc++.h"
 
using namespace std;
 
#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238
 
typedef pair<int, int> P;
 

void solve(std::string S, std::string T){
    cout<<T+S<<endl;
}
 
signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


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

ll mod = (ll)pow(10,9)+7;

ll mpow2(ll a){
  if(a == 0) return 1;
  return (2*mpow2(a-1))%mod;
}

int main(){
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll,ll>,pair<int,int>> mp;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    if(a==0 && b==0){
      zero ++;
      continue;
    }
    ll g = gcd(a,b);
    a /= g;
    b /= g;
    bool rev = 0;
    if(b < 0){
      a = -a;
      b = -b;
    }
    if(a <= 0){
      ll tmp = a;
      a = b;
      b = -tmp;
      rev = 1;
    }
    if(rev == 0) mp[{a,b}].first++;
    if(rev == 1) mp[{a,b}].second++;
  }
  ll ans = 1;
  for(auto p : mp){
    ll s = p.second.first;
    ll t = p.second.second;
    ll tmp = mpow2(s)+mpow2(t)-1+mod;
    tmp %= mod;
    ans *= tmp;
    ans %= mod;
  }
  cout << (ans+zero-1+mod)%mod << endl;
}


Measured memory_bytes: 16008
#include "iostream"
using namespace std;
#define ll long long int
int main()
{
    ll n,m;
    cin>>n>>m;
    
    ll arr[m];
    ll sum=0;
    for(ll i=0;i<m;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    
    if(sum>n)
    {
        cout<<"-1"<<endl;
    }
    
    else
        cout<<abs(sum-n)<<endl;
    
}


Measured memory_bytes: 3652
// Algorithms and Data Structures 1
// Fibonacci Numbers
// Name: Ryuya Asada
// ID: s1260064

#include <iostream>

int fibonacci(int);

int main() {
    int n(0);
    std::cin >> n;

    std::cout << fibonacci(n) << "\n";

    return 0;
}

int fibonacci(int n) {
    int a(0), b(1), c(1);
    for(int i=1; i <= n; ++i) {
        c = a + b;
        a = b;
        b = c;
    }

    return c;
}


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

using namespace std;

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int ans = 0;

  // for (int i = 0; i < k; ++i) {
  //   if (a > 0) {
  //     ++ans;
  //     --a;
  //   } else if (b > 0) {
  //     --b;
  //   } else {
  //     --ans;
  //   }
  // }

  int xa = min(a, k);
  k -= xa;
  int xb = min(b, k);
  k -= xb;
  int xc = k;

  ans = xa - xc;

  cout << ans << '\n';

  return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

struct Monster {
  ll X, H;
  bool operator<(const Monster& m) const {
    return X < m.X;
  }
};

Monster monster[200000];

ll Add(ll a, ll b) { return a + b; }

int main() {
  CIN(ll, N, D, A);
  REP(i, N) cin >> monster[i].X >> monster[i].H;
  sort(monster, monster + N);

  ll ans = 0;
  queue<pair<ll, ll>> que;
  ll damage_sum = 0;
  REP(i, N) {
    DBG(i, monster[i].X, monster[i].H, damage_sum);
    while (!que.empty() && que.front().first < monster[i].X) {
      DBG(que.front().first, que.front().second);
      damage_sum -= que.front().second;
      que.pop();
    }
    ll remaining = monster[i].H - damage_sum;
    if (remaining > 0) {
      ll cnt = (remaining + A - 1) / A;
      ans += cnt;
      damage_sum += cnt * A;
      que.push({monster[i].X + 2 * D, cnt * A});
      DBG(que.front().first, que.front().second);
    }
  }
  COUT(ans);
}


Measured memory_bytes: 4992
class SegmentTree:
    def __init__(self, data, default=0, func=max):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        """func of data[start, stop)"""
        start += self._size
        stop += self._size

        res_left = res_right = self._default
        while start < stop:
            if start & 1:
                res_left = self._func(res_left, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res_right = self._func(self.data[stop], res_right)
            start >>= 1
            stop >>= 1

        return self._func(res_left, res_right)

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)
    
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
seg = SegmentTree([0] * (1 << 20))
for _ in range(n):
    v = int(input())
    most = seg.query(max(0, v - k), v + k + 1)
    seg[v] = most + 1
print(seg.query(0, 1 << 20))


Measured memory_bytes: 94712
#include <bits/stdc++.h>
#define pb push_back
#define sc1(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sc3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define MX 100000
#define PI acos(-1)
using namespace std;

typedef long long int ll;


int main()
{
    ll a,b;
    sc2(a,b);
    ll ans=a+b;
    ans=max(ans,max(a-b,a*b));
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))

# 累積和を使ってみる
s1 = [0]*(n+1)
for i in range(n):
    s1[i+1] = s1[i] + a1[i]

s2 = [0]*(n+1)
for i in range(n):
    s2[i+1] = s2[i] + a2[i]

cmax = 0
for i in range(n):
    cmax = max(cmax, s1[i+1] + s2[n] - s2[i])

print(cmax)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	if((n-2)*(n-1)/2<k){
		cout<<-1<<endl;
		return 0;
	}
	int m=n*(n-1)/2-k;
	cout<<m<<endl;
	while(m>=n){
		for(int i=0;i<n-1;i++)
			cout<<i+1<<' '<<n<<endl;
		m-=n-1;
		n--;
	}
	for(int i=0;i<m;i++)
		cout<<i+1<<' '<<n<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>

int main()
{
    int n,i,j,key;
    int a[50];
    float s[50];
    float sum=0.0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(j=1;j<n;j++){
        key=a[j];
        i=j-1;
        while(i>=0&&a[i]>key){
            a[i+1]=a[i];
            i--;
        }
        a[i+1]=key;
    }
    for(i=0;i<n;i++){
        s[i]=(float)a[i];
    }
    sum=(s[0]+s[1])/2.0;
    if(n>2){
        for(i=2;i<n;i++){
        sum=(sum+s[i])/2.0;
        }
    }
    printf("%f\n",sum);
    return 0;
}


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	int res = N * M;
	for (int i = 1; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int cnt = 0;
			for (int x = 0; x < N; x++) {
				for (int y = 0; y < M; y++) {
					if (x < i) {
						cnt += S[x][y] != 'W';
					}
					else if (x < j) {
						cnt += S[x][y] != 'B';
					}
					else {
						cnt += S[x][y] != 'R';
					}
				}
			}
			res = min(res, cnt);
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x,y,z;
	cin>>n>>m;
	for(x=0;x<=m/10000;x++)
		for(y=0;y<=m/5000;y++)
		{
			z=n-x-y;
			if(z>=0&&x*10000+y*5000+z*1000==m)
			{
			    cout<<x<<" "<<y<<" "<<z;
			    return 0;
		    }
		}
	cout<<"-1 -1 -1";
	return 0;
}

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

using namespace std;

typedef long long int 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; }
 
typedef pair<int,int> pair;

int main(){
  int n[5];
  for(int i=0;i<5;i++) cin >> n[i];
  sort(n,n+5);
  for(int i=0;i<6;i++){
    if(n[i]!=i){
      printf("%d\n",i);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3764
H,W=map(int,input().split())
ls=[]
ls.append("."*(W+2))
for i in range(H):
    ls.append("."+input()+".")
ls.append("."*(W+2))
lans=[]
for i in range(1,H+1):
    clans=""
    for j in range(1,W+1):
        if ls[i][j]==".":
            clans+=str((ls[i-1][j-1]=="#")+(ls[i-1][j]=="#")+(ls[i-1][j+1]=="#")+(ls[i][j-1]=="#")+(ls[i][j+1]=="#")+(ls[i+1][j-1]=="#")+(ls[i+1][j]=="#")+(ls[i+1][j+1]=="#"))
        else:
            clans+=ls[i][j]
    lans.append(clans)
for i in range(H):
    print(lans[i])


Measured memory_bytes: 3064
n, m = map(int,input().split())
lst = [[0, 0] for i in range(n)]
for i in range(m):
    p, s = map(str,input().split())
    p = int(p) - 1
    if (lst[p][0] == 0):
        if (s == "AC"):
            lst[p][0] = 1
        else:
            lst[p][1] = lst[p][1] + 1

ans = 0
pena = 0
for i in range(n):
    if (lst[i][0] == 1):
        ans = ans + 1
        pena = pena + lst[i][1]

print(ans, pena)


Measured memory_bytes: 17604
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,q;
char ma[2010][2010];
int a[2010][2010],li[2010][2010],ha[2010][2010];
int main(){
	int i,j;
	scanf("%d%d%d",&n,&m,&q);
	for(i=1;i<=n;++i){
		scanf("%s",ma[i]);
		for(j=m;j>=1;--j)  ma[i][j]=ma[i][j-1];
	}
	memset(a,0,sizeof(a));
	memset(li,0,sizeof(li));
	memset(ha,0,sizeof(ha));
	for(i=1;i<=n;++i){
		for(j=1;j<=m;++j){
			a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			li[i][j]=li[i-1][j]+li[i][j-1]-li[i-1][j-1];
			ha[j][i]=ha[j][i-1]+ha[j-1][i]-ha[j-1][i-1];
			if(ma[i][j]=='1'){
				a[i][j]++;
			}
			if(ma[i][j]=='1' && ma[i][j-1]=='1'){
				li[i][j]++;
			}
			if(ma[i][j]=='1' && ma[i-1][j]=='1'){
				ha[j][i]++;
			}
		}
	}
	int x,y,xa,ya;
	for(i=1;i<=q;++i){
		scanf("%d%d%d%d",&x,&y,&xa,&ya);
		int one=a[xa][ya]-a[x-1][ya]-a[xa][y-1]+a[x-1][y-1];
		int ans,kk;
		kk=li[xa][ya]-li[xa][y]-li[x-1][ya]+li[x-1][y];
		kk+=ha[ya][xa]-ha[ya][x]-ha[y-1][xa]+ha[y-1][x];
		ans=one-kk;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 53120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i < n+1; i++) {
        ans += i * (n / i) * (n / i + 1) / 2;
    }
    cout << ans << endl;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string input = Console.ReadLine();

                if (input[0] == '0') break;

                int a = 0, b = 0;

                for(int i = 1; i < input.Length; i++)
                {
                    if (input[i] == 'A') a++;
                    else b++;
                }

                if (a > b) a++;
                else b++;

                sb.AppendLine(a + " " + b);
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9052
import numpy as np
from numba import njit

import math

n,k = map(int,input().split())
a = np.array(input().split(),np.int64)

@njit
def solve(n,k,a):
    for i in range(k):
        new = np.zeros_like(a)
        for j in range(n):
            distance = j - a[j]
            if distance < 0:
                distance = 0
            last =  j + a[j]
            if last > n-1:
                last = n-1
            new[distance]+=1
            if last+1 < n:
                new[last+1]-=1
        a = np.cumsum(new)
        if np.all(a==n):
            break
    return a

a = solve(n,k,a)
print(" ".join(a.astype(str)))

Measured memory_bytes: 154904
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	long long int ganjil = 0,genap = 0;
	for(long long int i = 0;i<n;i++){
		long long int a;scanf("%lld",&a);
		if(a%2 == 0){
			genap++;
		}else ganjil++;
	}
	if(ganjil%2 ==0 || n==1){
		printf("YES\n");
	}else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for(int (i) = (n)-1; (i) >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define FI first
#define SE second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}



int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<bool> ex(100000, false);
  rep(S,1<<n) {
    int sum = 0;
    rep(i,n) {
      if(S>>i&1) sum += a[i];
    }
    ex[sum] = true;
  }
  int q;
  cin >> q;
  rep(qi,q) {
    int m;
    cin >> m;
    cout << (ex[m] ? "yes" : "no") << '\n';
  }
  return 0;
}


Measured memory_bytes: 3140
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NTL (-1)
#define L 14

char H[M][L];

//文字から数値に変換
int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

//文字列から数値へ変換してkeyを生成する
long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for(i=0; i<strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
    long long key, i, h;
    key = getKey(str); //文字列を数値に変換
    for(i=0;; i++){
        h = (h1(key) + i * h2(key)) % M;
        if( strcmp(H[h], str) == 0 ) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;; i++){
        h = (h1(key) + i * h2(key)) % M;
        if( strcmp(H[h], str) == 0 ) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for(i=0; i<M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s %s", com, str);

        if(com[0] == 'i'){
            insert(str);
        }else{
            if( find(str) ){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}


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

using namespace std;


#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)

#define sl(a) scanf("%I64d", &a)
#define sll(a, b) scanf("%I64d %I64d", &a, &b)
#define slll(a, b, c) scanf("%I64d %I64d %I64d", &a, &b, &c)

#define outi(a) printf("%d\n", a)
#define outii(a, b) printf("%d %d\n", a, b)
#define outiii(a, b, c) printf("%d %d %d\n", a, b, c)

#define outl(a) printf("%I64d\n", a)
#define outll(a, b) printf("%I64d %I64d\n", a, b)
#define outlll(a, b, c) printf("%I64d %I64d %I64d\n", a, b, c)

#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))


#define fr(i, n) for(ll i=0; i<n;i++)
#define fr1(i, n) for(ll i=1; i<=n;i++) 

#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef long long ll;
typedef pair<int,int> pii;


int main()
{
    // #ifndef LOCAL
    // readf("in.txt");
    // writef("out.txt");
    // #endif

    int h[200005], n, a, k;
    cin>>n>>k;

    long long total = 0;

    fr(i,n){
        cin>>h[i];
       
    }

    sort(h, h+n);

    n -= k;
    fr(i, n)
        total += h[i];

    cout<<total<<"\n";  
    


    return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    int alice=0;
    int bob=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            alice+=a[i];
        }else{
            bob+=a[i];
        }
    }
    cout<<alice-bob<<endl;
}

Measured memory_bytes: 256
import itertools
import math

N=int(input())
X=[]
Y=[]
s=0
l=[int(x) for x in range(N)]
L = list(itertools.permutations(l, N))
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
for i in range(math.factorial(N)):
    for j in range(N-1):
        s+=((X[L[i][j]]-X[L[i][j+1]])**2+(Y[L[i][j]]-Y[L[i][j+1]])**2)**0.5
print(s/(math.factorial(N)))

Measured memory_bytes: 80988
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int R, C, K;

vvi form_sets(int n){
    vvi out;
    forn(mask, (1<<n)){
        vi cur;
        forn(j,n){
            if((mask>>j)&1)
                cur.pb(j);
        }
        out.pb(cur);
    }
    return out;
}

bool good(vi &rows, vi &cols, vs grid){
    for(auto r: rows){
        forn(c,C) grid[r][c] = 'R';
    }

    for(auto c: cols)
        forn(r,R) grid[r][c] = 'R';
    
    int cnt = 0;
    forn(i,R) forn(j,C) cnt+=(grid[i][j]=='#');
    return (cnt==K);
}


int main(){
    while(cin>>R>>C>>K){
        vvi rsets = form_sets(R);
        vvi csets = form_sets(C);

        vs grid(R);
        forn(i,R) cin>>grid[i];

        int ans = 0;
        for(auto r: rsets){
            for(auto c: csets)
                ans+=good(r,c,grid);
        }

        cout<<ans<<"\n";
        

    }
    return 0;
}

Measured memory_bytes: 3668
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

/*
A = 1, B = 2, C = 100, D = 100みたいなケースもある
*/

void main() {
    int t;
    scan(t);

    while (t--) {
        long ai, bi, ci, di;
        scan(ai, bi, ci, di);
        writeln(solve(ai, bi, ci, di));
    }
}

string solve(long a, long b, long c, long d) {
    if (a < b) {
        return "No";
    }

    if (b > c) {
        if (b == c + 1) {
            if (d >= b) {
                return "Yes";
            }
            else {
                return "No";
            }
        }
        if ((a % b) > c) {
            return "No";
        }
        else {
            long g = gcd(b, d);
            if (d >= b && (c + 1 + g - 1) / g * g >= b) {
                return "Yes";
            }
            else {
                return "No";
            }
        }
    }
    else {
        if (b == 1) {
            return "Yes";
        }
        if (d >= c) {
            return "Yes";
        }
        else {
            if (b <= d) {
                return "Yes";
            }
            else {
                return "No";
            }
        }
    }
}









































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
from math import ceil


def main():
    H, W = map(int, input().split())
    if H*W % 3 == 0:
        print(0)
        return
    ans1 = float('inf')
    ans2 = float('inf')
    ans3 = min(H, W)
    # h == Tの上
    for h in range(1, H + 1):
        if W % 2 == 0:
            ans1 = min(ans1, abs(h*(W//2) - W*(H - h)))
        else:
            ans1 = min(
                ans1,
                max([
                    abs((h*(W//2) - W*(H - h))),
                    abs(h*((W + 1)//2) - W*(H - h)),
                    h
                ]))
    for w in range(1, W + 1):
        if H % 2 == 0:
            ans2 = min(ans2, abs(w*(H//2) - H*(W - w)))
        else:
            ans2 = min(
                ans2, max([abs((w*(H//2) - H*(W - w))), abs(w*((H + 1)//2) - H*(W - w)), w]))
    print(min([ans1, ans2, ans3]))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
n, m, k = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)
b = gets.strip.split.map(&:to_i)
amax = -1
asum = 0
a.each_with_index do |e,i|
  if asum + e <= k
    asum += e
  else
    amax = i
    break
  end
end
amax = n if amax < 0

ans = amax
bidx = 0
flag = false
amax.downto(0) do  |i|
  if i != amax
    asum -= a[i]
    amax -= 1
  end
  while asum + b[bidx] <= k
    asum += b[bidx]
    amax += 1
    ans = amax if amax > ans
    bidx += 1
    if bidx >= m
      flag = true
      break
    end
  end
  if flag then break end
end
p ans


Measured memory_bytes: 46144
#include <stdio.h>

int main (void)
{
  int n;
  scanf("%d",&n);
  
  int a[n];
  for(int i = 0;i < n;i ++){
    scanf("%d",&a[i]);
  }
   int i = 0;
  for(int j = 0;j < n;j ++){
    int s = a[i]-1;
        i = s;
    if(i==1){
      printf("%d\n",j+1);
      return 0;
    }}
  
  printf("-1");
  return 0;
}

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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

i64 repeated_squaring(i64 x, i64 n) {
    i64 res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    i64 n;
    cin >> n;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 c;
        cin >> c;
        v.push_back(c);
    }
    sort(v.rbegin(), v.rend());
    i64 ans = 0;
    for(i64 k=1;k<=n;++k){
        ans += (v[k-1] * (k+1)) % MOD;
        ans %= MOD;
    }

    ans *= repeated_squaring(4, n-1);
    ans %= MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2420
def main():
    N = int(input())
    v = [int(a) for a in input().split()]
    c = [int(a) for a in input().split()]
    ds = 0
    for i in range(N):
        d = v[i] - c[i]
        if d > 0:
            ds += d
    print(ds)
main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<endl
#define rep(i,l,r) for(int i = l;i < r;i++)
#define per(i,l,r) for(int i = r-1;i >= l;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6+7;
const int M = 1e6+7;
const int MOD = 1e9+7;
int dp[N][6][6];
int a[N];
int main() {
	int n,k;scanf("%d%d",&n,&k);
	if(k > (n + 1) / 2) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 256