akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define MAX 105
#define int long long int
using namespace std;

double dp[305][305][305];
bool visited[305][305][305];
int n;

double solve(int i,int j,int k)
{
    if(i==0 and j == 0  and k == 0)
        return 0;
    if(i<0 or j<0 or k<0)
        return 0;
    if(visited[i][j][k])
        return dp[i][j][k];
    visited[i][j][k] = true;
    int temp = n-i-j-k;
    double den = n-temp;
    return dp[i][j][k] = (n+i * solve(i-1, j, k) + j * solve(i+1, j-1, k) + k * solve(i, j+1,k-1))/den;
    return dp[i][j][k];
}

int32_t main()
{
    cin >> n;
    int a[n];
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];
    memset(visited,false,sizeof(visited));
    map<int,int> mp;
    for(auto it: a)
        mp[it]++;
    double ans = solve(mp[1],mp[2],mp[3]);
    cout << fixed << setprecision(10);
    cout << ans;
    return 0;
}


Measured memory_bytes: 140288
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e+5+5;
const int mo = 1e+9+7;

int n;
struct man{
	int x,v;
}a[N];
int sta[N],top;
int lef[N],rig[N];
multiset<int>w[N];
LL f[N],pre[N];

bool cmp(man x,man y){return x.v<y.v;}

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();
	fo(i,1,n){a[i].x=get();a[i].v=get();}
	sort(a+1,a+1+n,cmp);
	fo(i,1,n)lef[i]=rig[i]=i;
	top=0;
	fo(i,1,n){
		if (!top||a[i].x>a[sta[top]].x)sta[++top]=i;
		int l=1,r=top;
		while(l<=r){
			int mid=(l+r)/2;
			if (a[sta[mid]].x<a[i].x)l=mid+1;
			else r=mid-1,lef[i]=sta[mid];
		}
	}
	top=0;
	fd(i,n,1){
		if (!top||a[i].x<a[sta[top]].x)sta[++top]=i;
		int l=1,r=top;
		while(l<=r){
			int mid=(l+r)/2;
			if (a[sta[mid]].x>a[i].x)l=mid+1;
			else r=mid-1,rig[i]=sta[mid];
		}
	}
	f[0]=1;pre[0]=1;
	fo(i,1,n)w[rig[i]].insert(lef[i]);
	fo(i,1,n){
		pre[i]=pre[i-1];
		for(set<int>::iterator h=w[i].begin();h!=w[i].end();h++){
			LL tmp=(pre[i]+mo-((*h)>=2?pre[(*h)-2]:0))%mo;
			f[i]=add(f[i],tmp);
			pre[i]=add(pre[i],tmp);
		}
	}
	printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 25984
a,b,c=map(int,input().split())
x1=0
x2=a
y1=0
y2=b
for i in range(c):
    e,f,g=map(int,input().split())
    if g==1:
        if x1<e:
            x1=e
    elif g==2:
        if x2>e:
            x2=e
    elif g==3:
        if y1<f:
            y1=f
    else:
        if y2>f:
            y2=f
if (0>(x2-x1))or(0>(y2-y1)):
    print(0)
else:
    print((x2-x1)*(y2-y1))

Measured memory_bytes: 3064
import io.Source.stdin

object Main {
  
  def main(args: Array[String]) {
    for (list <- stdin.getLines().takeWhile(!_.contains("?")).map(_.split(" "))) {
      val (a, op, b) = (list(0).toInt, list(1), list(2).toInt)
      val result = op match {
        case "+" => a + b
        case "-" => a - b
        case "*" => a * b
        case "/" => a / b
      }
      println(result)
    }
  }
}


Measured memory_bytes: 43944
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

        int t=1;
//        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            a=new int[n];
            for(int c=0;c<n;c++) a[c]=scan.nextInt();
            long best=Long.MAX_VALUE;
            for(int c=-200;c<200;c++) best=Math.min(best,calc(c));
            out.println(best);
        }
        out.close();
    }

    static int n;
    static int[] a;
    static long calc(int spot) {
        long ans=0;
        for(int c=0;c<n;c++) ans+=(spot-a[c])*(spot-a[c]);
        return ans;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

Measured memory_bytes: 25408
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        t: f64, a: f64,
        h: [f64;n]
    }

    let mut ret = 0;
    let mut len = (1i64 << 60) as f64;
    for i in 0..n {
        let current = ((t - h[i] * 0.006) - a).abs();
        if current < len {
            len = current;
            ret = i;
        }
    }
    println!("{}", ret+1);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

char a[1111][1111];
ll dp[1111][1111]={};

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

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
	 cin>>a[i][j];
 
  dp[0][0]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
	 if(a[i][j]=='#')continue;
	 dp[i+1][j]+=dp[i][j];
	 dp[i+1][j]%=p;
	 dp[i][j+1]+=dp[i][j];
	 dp[i][j+1]%=p;
    }
  }
  cout<<dp[h-1][w-1]<<endl;
  return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e5+5;
int x[M],l[M];
int main()
{
	int n;
	cin>>n;
	vector<pair<int,int>> vec;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>l[i];
		vec.pb({x[i]+l[i],i});
	}
	sort(all(vec));
	int ans = 0;
	int pre = -1e9;
	for(auto u:vec)
	{
		int z = u.ss;
		if(x[z]-l[z]>=pre)
		{
			ans++;
			pre = u.ff;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

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

int main() {
  int64_t h,mon=0;
  cin >> h;
  int64_t ans=1;
  while(true) {
    if(h < 2) {
      mon++;
      break;
    }
    else if(h >= 2) {
      h /= 2;
      mon++;
    }
  }
  for(int i = 0; i < mon; i++) ans *= 2;
  cout << ans - 1 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    b = [0] * N
    for a in A:
        b[a-1] += 1
    return b


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 2 + 1)]  # type: "List[int]"
    print(*solve(N, A), sep='\n')

if __name__ == '__main__':
    main()


Measured memory_bytes: 35756
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Jan  2 22:45:53 2019
//
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a*b%2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}


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

int main() {
    string S;
    cin >> S;
    int x = stoi(S);
    int y = 0;
    for (int i=0;i<S.size();i++) {
        y += int(S.at(i)-'0');
    }
    cout << (x % y == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
  void Solve()
  {
    var _ = Console.ReadLine().Split();
    var N=int.Parse(_[0]);
    var K = int.Parse(_[1]);
    var S = Console.ReadLine();

    for(int i=0;i<N ;i++ )
    {
      if (i + 1 == K)
      {
        var s = ""+S[i];
        
        Console.Write(s.ToLower());
      }
      else
        Console.Write(S[i]);
    }
    Console.WriteLine();
  }

  static void Main(string[] args)
  {
    new Program().Solve();
  }
}



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

const int INF = 2000000005;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = min(a, b) + min(c, d);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int n;long long d;
  cin>>n>>d;
  vector<long long> X(n),Y(n);
  for(int i=0; i<n ;i++){
      cin>>X.at(i)>>Y.at(i);
    
    X.at(i)*=X.at(i);
    Y.at(i)*=Y.at(i);
   
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(d*d>= X.at(i)+Y.at(i))
      ans++;
    
  }
  cout<<ans<<endl;
  
  

}

Measured memory_bytes: 6424
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e6+10;
int w[N],ne[N],la[N],len[N],t=1,ans,S,T;
void alink(int x,int y,int z){
	w[++t]=y;
	ne[t]=la[x];
	la[x]=t;
	len[t]=z;
}
void link(int x,int y,int z){
	alink(x,y,z);
	alink(y,x,0);
}
int n,p[N],q[N],ip[N],iq[N],dep[N],cur[N];
int bfs(){
	static int d[N],vis[N],l=0,r=1,ti=0;
	l=0,r=1;
	vis[S]=++ti;
	d[1]=S;
	while (l<r){
		int x=d[++l];
		cur[x]=la[x];
		for (int y=la[x];y;y=ne[y]){
			int z=w[y];
			if (len[y]&&vis[z]!=ti){
				vis[z]=ti;
				d[++r]=z;
				dep[z]=dep[x]+1;
			}
		}
	}
	return vis[T]==ti;
}
int flow(int x,int val){
	if (x==T)return val;
	int v1=val;
	for (int y=cur[x];y;y=ne[y],cur[x]=y){
		int z=w[y];
		if (dep[z]!=dep[x]+1||!len[y])continue;
		int use=flow(z,min(val,len[y]));
		val-=use;
		len[y]-=use;
		len[y^1]+=use;
		if (!val)return v1;
	}return v1-val;
}
int main(){
	cin>>n;
	for (int i=1;i<=n;i++)scanf("%d",&p[i]),p[i]++;
	for (int i=1;i<=n;i++)scanf("%d",&q[i]),q[i]++;
	int t1=0;
	for (int i=1;i<=n;i++){
		if (!ip[i]){
			if (p[i]==i)continue;
			ip[i]=++t1;
			for (int x=p[i];x-i;x=p[x])ip[x]=ip[i];
		}
	}
	for (int i=1;i<=n;i++){
		if (!iq[i]){
			if (q[i]==i)continue;
			iq[i]=++t1;
			for (int x=q[i];x-i;x=q[x])iq[x]=iq[i];
		}
	}S=t1+1,T=S+1;
	ans=t1+n;
	for (int i=1;i<=t1;i++){
		link(S,i,1);
		link(i,T,1);
	}
	for (int i=1;i<=n;i++){
		if (p[i]==q[i]){
			if (p[i]==i){
				ans--;
				continue;
			}
			link(ip[i],iq[i],1);
		}
		if (p[i]==i){
			link(iq[i],T,1);
			continue;
		}
		if (q[i]==i){
			link(S,ip[i],1);
			continue;
		}
		link(iq[i],ip[i],1);
	}
	while (bfs())
		ans-=flow(S,1<<30);
	cout<<ans<<endl;
}

Measured memory_bytes: 38400
n, k, c = map(int, input().split())
s = list(str(input()))

def getpos(s):
    l = []
    i = 0
    while i <= n-1 and len(l) < k:
        if s[i] == 'o':
            l.append(i)
            i += c+1
        else:
            i += 1
    return l

l = getpos(s)

s.reverse()
r = getpos(s)
for i in range(len(r)):
    r[i] = n-1-r[i]

#print(l)
#print(r)

lastl = [-1]*(n+1)
lastr = [-1]*(n+1)

for i in range(k):
    lastl[l[i]+1] = i

for i in range(n):
    if lastl[i+1] == -1:
        lastl[i+1] = lastl[i]

for i in range(k):
    lastr[r[i]] = i

for i in reversed(range(n)):
    if lastr[i] == -1:
        lastr[i] = lastr[i+1]

#print(lastl)
#print(lastr)

ans = []
s.reverse()
for i in range(n):
    if s[i] != 'o':
        continue
    cnt = 0
    cnt += lastl[i]+1
    cnt += lastr[i+1]+1
    if lastl[i] != -1 and lastr[i+1] != -1 and r[lastr[i+1]] - l[lastl[i]] <= c:
        cnt -= 1
    if cnt < k:
        ans.append(i+1)

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

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();++i)
    {
        sum+=(s[i]-'0');
    }
    int dp[n+1];
    dp[0]=0;
    for(int i=1;i<=n;++i)
    {
        dp[i]=dp[i%__builtin_popcount(i)]+1;
    }
    int po1[n];
    int po2[n];
    int po3[n];
    int u=1;
    for(int i=0;i<n;++i)
    {
        po1[i]=u;
        u*=2;
        u%=(sum+1);
    }
    if(sum==0)
    {
        for(int i=0;i<n;++i)
        {
            po2[i]=0;
        }
    }
    else
    {
         u=1;
    for(int i=0;i<n;++i)
    {
        po2[i]=u;
        u*=2;
        u%=(sum);
    }
    }
    if(sum<=1)
    {
        for(int i=0;i<n;++i)
        {
            po2[i]=0;
        }
    }
    else
    {
         u=1;
    for(int i=0;i<n;++i)
    {
        po3[i]=u;
        u*=2;
        u%=(sum-1);
    }
    }
    int answ1=0;int answ2=0;int answ3=0;
    reverse(s.begin(),s.end());
    for(int i=0;i<n;++i)
    {
        answ1+=po1[i]*(s[i]-'0');
        answ2+=po2[i]*(s[i]-'0');
        answ3+=po3[i]*(s[i]-'0');
    }
    for(int i=s.size()-1;i>=0;--i)
    {
        if(s[i]=='1')
        {
            if(sum==1)
            {
                cout<<0<<endl;
                continue;
            }
            int r=answ3;
            r-=po3[i];
            cout<<dp[((r%(sum-1))+(sum-1))%(sum-1)]+1<<endl;
        }
        else
        {
            int r=answ1;
            r+=po1[i];
            cout<<dp[r%(sum+1)]+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10004
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var n = o.a();
  var k = o.a();
  var s = o.a();
  var ans = xArray(1,n);
  for(var i = 0; i < k; i++){
    ans[i] = s;
  }
  if(s <= n)for(;i < n; i++){
    ans[i] = s+1;
  }
  return ans.join(" ");
}

Measured memory_bytes: 22856
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}




int main()
{
	long long n, k, s;

	cin >> n >> k >> s;

	for(int i = 0; i < k; i++)
		cout << s << " ";

	for (int i = k; i < n; i++) {
		if(s == 1000000000)
			cout << s - 1 << " ";
		else
			cout << s + 1 << " ";
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	char X, Y;
	cin >> X >> Y;
	int x, y;
	char a[6] = {'A', 'B', 'C', 'D', 'E', 'F'};
	for(int i = 0; i < 6; i++){
		if(a[i] == X){
			x = i;
		}
		if(a[i] == Y){
			y = i;
		}
	}
	if(x > y){
		cout << ">" << endl;
	}
	else if(x == y){
		cout << "=" << endl;
	}
	else{
		cout << "<" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;

int main()
{
	string S, T;
	bool flag = false;

	cin >> S >> T;

	for (int i = 0; i < T.size();i++)
	{
		if (S == T)
		{
			flag = true;
			break;
		}		
		rotate(T.begin(), T.begin() + 1, T.end());
	}

	if(flag == true)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2000005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n+1,0),b(m+1,0);
    rep(i,n) cin >> a[i+1];
    rep(i,m) cin >> b[i+1];
    rep(i,n){
        a[i+1] += a[i];
    }
    rep(i,m){
        b[i+1] += b[i];
    }
    ll ans = 0;
    rep(i,n+1){
        ll s = upper_bound(all(b),max(k-a[i],0ll))-b.begin()-1;
        if (a[i] <= k) chmax(ans,i+s);
    }
    PRINT(ans);
}


Measured memory_bytes: 6344
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    for(int i = 0; i < k; i++) {
        if (a % 2 == 1)
            a -= 1;
        b += a/2;
        a /= 2;
        swap(a, b);
    }
    if (k % 2 == 1)
        swap(a, b);
    cout << a << " " << b << endl;
    return 0;
}



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

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int N;
	map<int,int> arr;
	cin>>N;

	REP(i,N){
		int a;
		cin>>a;
		arr[a]++;
	}
	int count = 0;
	
	for(auto& ar : arr){

		count += (ar.second % 2 == 1) ? 1 : 0;
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1e9+7

int daijkstra(const vector<vector<pair<int,int>>> graph, int s, int t){
    vi dist(graph.size(),1e9);
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > que;
    dist[s]=0;
    que.push({0,s});
    while(!que.empty()){
        auto v=que.top(); que.pop();
        if(v.first>dist[v.second]) continue;
        for(auto x:graph[v.second]){
            if(dist[x.second]>dist[v.second]+x.first){
                dist[x.second]=dist[v.second]+x.first;
                que.push({dist[x.second],x.second});
            }
        }
    }
    return dist[t];
}

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<pair<int,int>>> graph(10);
    rep(i,10){
        rep(j,10){
            int a;
            cin >> a;
            graph[i].push_back({a,j});
        }
    }

    vi cost(10);
    rep(i,10){
        cost[i]=daijkstra(graph,i,1);
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            int a;
            cin >> a;
            if(a==-1) continue;
            ans+=cost[a];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	long long k;
	cin>>k;
	char same='~';
	int sum=0;
	long long ans=0;
	int pd=1;
	for(int i=0;i<s.size();i++) {
		if(s[i]==same) {
			sum++;
			if(i==s.size()-1) {
				ans+=sum/2;
			}
			pd++;
		} else {
			ans+=sum/2;
			sum=1;
			same=s[i];
		}
	}
	if(pd==s.size())
	{
		long long h;
		h=pd*k/2;
		cout<<h;
		return 0;
	}
	same=s[0];
	int first=1;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]==same)
		{
			first++;
		}
		else
		{
			break;
		}
	}
	same=s[s.size()-1];
	int last=1;
	for(int i=s.size()-2;i>=0;i--)
	{
		if(s[i]==same)
		{
			last++;
		}
		else
		{
			break;
		}
	}
	ans*=k;
	if(s[0]==s[s.size()-1]&&(first+last)%2==0&&k>1&&(first%2!=0||last%2!=0))
	{
		ans+=k-1;
	}
	cout<<ans;
	return 0;	
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b and b == c){
    cout << "1" << endl;
  }
  else if(a == b or a == c or b == c){
    cout << "2" << endl;
  }
  else{
    cout << "3" << endl;
  }
  return 0;
}


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

bool check(vector<string> &v, i64 n, i64 x, i64 y)
{
  return (v[x][y] == v[n - x - 1][y] && v[x][y] == v[x][n - y - 1] && v[x][y] == v[n - x - 1][n - y - 1]);
}

int main()
{
  i64 c, n;
  cin >> c >> n;
  vector<string> p(n);
  for (i64 i = 0; i < n; i++)
    cin >> p[i];
  i64 def = 0;
  vector<vector<bool>> ok(n, vector<bool>(n));
  for (i64 i = 0; i < n / 2; i++)
    for (i64 j = 0; j < n / 2; j++)
      if (check(p, n, i, j))
        ok[i][j] = true;
      else
      {
        ok[i][j] = false;
        def++;
      }
  i64 ans = (def == 0 ? 1 : 0);
  for (i64 i = 0; i < c - 1; i++)
  {
    i64 d;
    cin >> d;
    vector<i64> pr(d), pc(d);
    for (i64 j = 0; j < d; j++)
    {
      cin >> pr[j] >> pc[j];
      pr[j]--;
      pc[j]--;
    }
    for (i64 j = 0; j < d; j++)
    {
      p[pr[j]][pc[j]] = (p[pr[j]][pc[j]] == '1' ? '0' : '1');
      if (n / 2 <= pr[j])
        pr[j] = n - 1 - pr[j];
      if (n / 2 <= pc[j])
        pc[j] = n - 1 - pc[j];
      bool s = check(p, n, pr[j], pc[j]);
      if (s != ok[pr[j]][pc[j]])
      {
        if (s)
          def--;
        else
          def++;
      }
      ok[pr[j]][pc[j]] = s;
    }
    if (def == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4288
n, k = input().split(" ")
n = int(n)
k = int(k)
okashi = set()
for i in range(k):
  d = int(input())
  a_list = input().split(" ")
  a_list = map(int, a_list)
  for j in a_list:
    okashi.add(j)
print(n - len(okashi))

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int a,b;
  char op;
int main(){

cin>>a>>op>>b;
while(op!='?'){
switch(op){
case '+':
cout<<a+b<<endl;
break;
case '-':
cout<<a-b<<endl;
break;
case '*':
cout<<a*b<<endl;
break;
case '/':
cout<<a/b<<endl;
break;
}
cin>>a>>op>>b;
}}




Measured memory_bytes: 3104
#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <climits>
#include <cmath>
#include <set>
#include <map>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std; 
const long long  mod=998244353;
typedef long long LL;
const int N=3e5+5;
LL fac[N],inv[N];
LL quickPow(LL a,LL b){
	LL ans=1;
	while(b){
		if(b&1){
			ans=(ans*a)%mod;
		}
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
LL C(int n,int m){
	if(n<0||m<0||m>n) return 0;
	if(n==m||m==0) return 1;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void init(){
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=(fac[i-1]*i)%mod;
	}
	inv[N-1]=quickPow(fac[N-1],mod-2);
	for(int i=N-2;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
LL Lucas(int n,int m){
	if(m==0) return 1;
	return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
int main(){
	LL n,a,b,k,j,ans=0;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
	if(k==0){
		printf("1");
		return 0;
	} 
	init();
	for(int i=0;i<=n;i++){
		if((k-a*i)%b==0&&(k-a*i)>=0){
			j=(k-a*i)/b;
			if(j>n) continue;
			ans=(ans+C(n,i)*C(n,j))%mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>

using namespace std;

int main() {

	string s;
	cin >> s;

	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';

	cout << s << endl;

	return 0;
}

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

int main()
{
	char s[256]{};
	long long k;
	scanf("%s%lld", s, &k);
	k--;

	int first_dif{};
	while (s[first_dif] == '1') first_dif++;
	if (k < first_dif) puts("1");
	else printf("%c\n", s[first_dif]);

	return 0;
}

Measured memory_bytes: 256
class Node
  attr_reader :go, :come

  def initialize(id)
    @id = id
    @go = []
    @come = []
  end
end

class Arrow
  attr_reader :source, :sink, :label
  
  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
    source.go << self
    source.come << self
  end
end

class Result
  attr_reader :parent, :node, :spell

  def initialize(parent, node, spell)
    @parent = parent
    @node = node
    @spell = spell
  end
end

def advance(table, nodes, arrows)
  next_table = table
  nodes.each do |node|
    best = table[node]
    node.go.each do |arrow|
      result = table[arrow.sink]
      next unless result
      test = arrow.label + result.spell
      if !best || test < best.spell
        best = Result.new(result, node, test)
      end
    end
    next_table[node] = best if best
  end
  next_table
end

def has_loop(result)
  used = {}
  while result
    node = result.node
    return true if used[node]
    used[node] = true
    result = result.parent
  end
  return false
end

def work(nodes, arrows, start, goal)
  table = {goal => Result.new(nil, goal, '')}
  (nodes.size*6).times do
    table = advance(table, nodes, arrows)
  end
  result = table[start]
  puts result && !has_loop(result) ? result.spell : 'NO'
end

loop do
  n, a, s, g = STDIN.gets.split.map(&:to_i)
  break if n == 0

  nodes = (0...n).map{|i| Node.new(i)}

  arrows = (0...a).map do |i|
    x, y, lab = STDIN.gets.split
    x = x.to_i
    y = y.to_i
    Arrow.new(nodes[x], nodes[y], lab)
  end

  start = nodes[s]
  goal = nodes[g]

  work(nodes, arrows, start, goal)
end

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

int func(int x)
{
    if(x%2==0)
    {
        return x/2;
    }
    else
    {
        return 3*x+1;
    }
}
int main()
{
    ll h;
    cin>>h;
    ll count = 0;
    ll total = 0;
    while(h)
    {
        h=h/2;
        total += pow(2,count);
        count++;
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[1000],t[1000];
int main()
{
    cin>>s;
    cin>>t;
    int l=strlen(t);
    for(int i=0;i<l;i++)
        t[i+l]=t[i];
    for(int i=0;i<l;i++)
        for(int j=0;j<l;j++)
        {
            if(s[j]!=t[i+j]) break;
            if(j==l-1) {
                printf("Yes");
                return 0;
            }
        }
    printf("No");
    return 0;
}

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

double x[2000],y[2000],r[2000];
double eps = 1e-9;
double dist(int i,int j){
    double dx=x[i]-x[j], dy=y[i]-y[j];
    double d = dx*dx + dy*dy;
    double dr = r[i]*r[i] + 2*r[i]*r[j] + r[j]*r[j];
    if(d + eps <= dr) return 0;
    return sqrt(d) - r[i]-r[j];
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    double a,b,c,d;
    cin>>a>>b>>c>>d;
    int n;
    cin>>n;
    x[0] = a, y[0] = b, r[0] = 0;
    x[n+1] = c, y[n+1] = d, r[n+1] = 0;
    for(int i=1;i<=n;i++){
        double a,b,c;
        cin>>a>>b>>c;
        x[i]=a,y[i]=b,r[i]=c;;
    } 
    n += 2;
    double dp[n][n]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            else dp[i][j] = 1e15;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j] = min(dp[i][j],dist(i,j));
        }
    }
    for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++){
        dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
    }
    cout << dp[0][n-1] << endl;


}

Measured memory_bytes: 8192
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]

amt = 0
for i in range(n+1):
    amt += abs(A[i] - A[i+1])
    
for i in range(1, n+1):
    ans = amt - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])) + abs(A[i-1] - A[i+1])
    print(ans)

Measured memory_bytes: 14176
#include<stdio.h>

int main(void){
    char weather[10];
    scanf("%s",weather);
    if(weather[0]=='S'){
        printf("Cloudy\n");
    }else{
        if(weather[0]=='C'){
            printf("Rainy\n");
        }else{
            printf("Sunny\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i] != L[j] and L[i] != L[k] and L[j] != L[k]:
                if L[i] + L[j] > L[k] and L[i] + L[k] > L[j] and L[k] + L[j] > L[i]:
                   ans += 1
print(ans)

Measured memory_bytes: 9200
#include <iostream>

long long gcd(long long m, long long n){

    long long temp;

    while(m % n != 0){
        temp = n;
        n = m % n;
        m = temp;
    }
    return n;
}

long long lcm(long long m, long long n){

    return m / gcd(m, n) * n;
}

int main(){

    long long a, b, c, d;
    std::cin >> a >> b >> c >> d;

    long long l = lcm(c, d);

    a = a-1;

    long long p_a = a / c;
    long long q_a = a / d;
    long long r_a = a / l;

    long long p_b = b / c;
    long long q_b = b / d;
    long long r_b = b / l;

    long long p = p_b - p_a;
    long long q = q_b - q_a;
    long long r = r_b - r_a;

    long long ans = b - a - p - q + r;

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

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

int a,b,c,d,e,ans;

signed main()
{
	cin>>a>>b>>c>>d>>e;
	if (a==0)  ans=1;
	if (b==0)  ans=2;
	if (c==0)  ans=3;
	if (d==0)  ans=4;
	if (e==0)  ans=5;
	cout<<ans<<endl;
	
	return 0;
} 

Measured memory_bytes: 3584
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
map<int,int> cnave[200005];
int a[200005],b[200005];
inline int finda(int t){
	if(a[t]==t) return a[t];	
	return a[t]=finda(a[t]);
}
inline int findb(int t){
	if(b[t]==t) return b[t];
	return b[t]=findb(b[t]);
}
int main(){
	ios_base::sync_with_stdio(false);
	int n,p,q,i,j,x,y;
	cin>>n>>p>>q;
	for(i=0;i<n;i++) a[i]=b[i]=i;
	while(p--){
		cin>>x>>y;
		a[finda(x-1)]=finda(y-1);
	}
	while(q--){
		cin>>x>>y;
		b[findb(x-1)]=findb(y-1);
	}
	for(i=0;i<n;i++){
		finda(i),findb(i);
		cnave[a[i]][b[i]]++;
	}
	for(i=0;i<n;i++) cout<<cnave[a[i]][b[i]]<<" ";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	for(int i=0;i<100000;i++){
		int t=60*i+c;
		if(t%(a+b)<=a){
			cout<<t<<endl;
			return 0;
		}
	}
	puts("-1");
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    long long int n,ans=1;cin >> n;
    for(int i=1; i<=n; i++){
        ans=(ans%1000000007)*i;
    }
    cout << ans%1000000007 << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,X = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = []
count = 0
for i in range(X,N+1):
    if i in ar:
        count += 1
br.append(count)
count = 0
for i in range(X,-1,-1):
    if i in ar:
        count += 1
br.append(count)
print(min(br))

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

ll H;

ll div_2(ll val){
  if(val == 0) return 0;
  else return (div_2(val/2) * 2 + 1);
}

int main(){
  cin >> H;

  cout << div_2(H) << endl;
  return 0;
}

  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <complex>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
int norm(int a){return a*a;}
int main() {
	int s[3],type[3]={},sum=0;
	while(true){
	REP(i,3)
			cin >>s[i];
	sort(s,s+3);
	if(s[0]+s[1]<=s[2])
		break;
	if(norm(s[0])+norm(s[1])==norm(s[2]))
	type[0]++;
	if(norm(s[0])+norm(s[1])<norm(s[2]))
	type[2]++;
	if(norm(s[0])+norm(s[1])>norm(s[2]))
	type[1]++;
	
	sum++;
	}
	cout <<sum;
	REP(i,3)
		cout <<" " << type[i];
	cout << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1176
// E - Cell Distance

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

// mod p （pは素数）の下でのべき乗を求める
ll mod_pow(ll a, ll n, ll p) {
		ll result = 1;
		while (n > 0) {
			if (n & 1) result = result * a % p;
			a = a * a % p;
			n >>= 1;
		}
		return result;
	};

// mod p（pは素数）の下での逆元を求める（フェルマーの小定理を利用）
ll mod_inverse(ll a, ll p) {
	return mod_pow(a, p-2, p);
}

// mod p （pは素数）の下での除算 (a / b)
ll mod_devide(ll a, ll b, ll p) {
	return a * mod_inverse(b, p) % p;
}

// mod p （pは素数）の下での組み合わせ（nCk）を計算
ll mod_comb(ll n, ll k, ll p) {
	ll numerator = 1;
	for (int i=n; i>n-k; i--) {
		numerator *= i;
		numerator %= p;
	}

	ll denominator = 1;
	for (int i=k; i>0; i--) {
		denominator *= i;
		denominator %= p;
	}

	return mod_devide(numerator, denominator, p);
}

int main() {
	ll N, M, K;
	cin >> N >> M >> K;

	ll comb = mod_comb(N * M - 2, K - 2, MOD);

	// x方向
	ll x_total_dist = 0;
	for (ll dx=1; dx<=M-1; dx++) {
		// dx_total_dist = (M - dx) * (N * N) * dx;
		ll dx_total_dist =(((((M - dx) * N * N)) % MOD) * dx) % MOD;
		x_total_dist = (x_total_dist + dx_total_dist) % MOD;
	}
	//cout << "x_total_dist:" << x_total_dist << endl; // **** debug ****

	// y方向
	ll y_total_dist = 0;
	for (ll dy=1; dy<=N-1; dy++) {
		// dy_total_dist = (N - dy) * (M * M) * dy;
		ll dy_total_dist = (((((N - dy) * M * M)) % MOD) * dy) % MOD;
		y_total_dist = (y_total_dist + dy_total_dist) % MOD;
	}
	//cout << "y_total_dist:" << y_total_dist << endl; // **** debug ****

	ll ans = ((x_total_dist + y_total_dist) * comb) % MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,i,j,k,a;
  scanf("%lld",&n);
  for(j=0;n%2==0;j++)n/=2;for(k=1;k*(k+1)/2<=j;k++);a=k-1;
  for(i=3;i*i<n;i+=2){for(j=0;n%i==0;j++)n/=i;for(k=1;k*(k+1)/2<=j;k++);a+=k-1;}
  printf("%lld",a+(n!=1));
}


Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, r, ans=1;
	cin>>n;
	r=7%n;
	vector<bool> vis(n+1);
	while(r){
		if(vis[r])
			return cout<<-1, 0;
		vis[r]=true;
		ans++;
		r=(r*10+7)%n;
	}
	cout<<ans;
}

Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, k;
  cin>>n>>k;
  int h[n];
  REP(i, n) cin>>h[i];
  if(n==2){
    cout<<abs(h[1]-h[0]);
    return 0;
  }

  sort(h, h+n);
  int ans=INF;
  REP(i, n-k+1){
    //cout<<h[i+k-1]<<" "<<h[i]<<endl;
    ans = min(ans, h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);
    	int N=sc.nextInt();

    	long[][] data=new long[N][2];

    	for(int i=0;i<N;i++) {
    		data[i][0]=sc.nextLong();
    		data[i][1]=sc.nextLong();
    	}

    	int max=-1;
    	int indexMAX=-1;
    	Long min=data[0][1];
    	int indexMIN=0;

    	for(int i=0;i<N;i++) {

    		Long buf=data[i][1];


    		if(min>buf) {
    			min=buf;
    			indexMIN=i;
    		}
    	}

    	Long result=data[indexMIN][0]+min;

    	System.out.println(result);

    }

}



Measured memory_bytes: 94856
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i, j;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] x = new int[n];
		int[] y = new int[n];
		for(i=0;i<n;i++) {
			x[i] = Integer.parseInt(sc.next());
			y[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		int dx,dy;
		int max = 1;
		HashMap<Long, Integer> dxdyMap = new HashMap<>(); 
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(i==j)continue;
				dx = x[i]-x[j];
				dy = y[i]-y[j];
				long dxdy = (((long)dx) << 32) + dy;
				Integer cnt = dxdyMap.get(dxdy);
				if(cnt == null) {
					cnt = 1;
				} else {
					cnt++;
				}
				dxdyMap.put(dxdy, cnt);
			}
		}
		if(!dxdyMap.isEmpty()) {
			ArrayList<Integer> dxdyList = new ArrayList<>(dxdyMap.values());
			max = Collections.max(dxdyList);
		} else {
			max = 1;
		}
		if(max==n)max--;
		System.out.println(n-max);
	}
}


Measured memory_bytes: 22224
n,k=map(int,input().split())
s=input()
s01=[[1,s[0]]]
for i in range(1,n):
  if s[i]==s[i-1]:
    s01[-1][0]+=1
  else:
    s01.append([1,s[i]])
a=len([i0 for i0,i1 in s01 if i1=='0'])
if a<=k:
  print(n)
  exit()
# 累計和
si=0
sums=[0]
for s01i in s01:
  si+=s01i[0]
  sums.append(si)
ans=0
#print(s01)
#print(sums)
l=0 if s[0]=='0' else 1
for i in range(l,len(s01),2):
  l=max(0,i-1)
  r=min(len(sums)-1,2*k+i)
  #print(sums[r]-sums[l],i,l,r)
  ans=max(ans,sums[r]-sums[l])
print(ans)


Measured memory_bytes: 18028
// BFS(幅優先探索)
package main

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

type intQueue []int

func (queue *intQueue) enqueue(i int) {
	*queue = append(*queue, i)
}

func (queue *intQueue) dequeue() int {
	result := (*queue)[0]
	*queue = (*queue)[1:]
	return result
}

func createGroups(n int, links [][]int) []int {
	groups := make([]int, n)
	for i := 0; i < n; i++ {
		groups[i] = i
	}
	var queue intQueue = make([]int, 0)
	for i := 0; i < n; i++ {
		if groups[i] != i {
			continue
		}
		queue.enqueue(i)
		for len(queue) != 0 {
			j := queue.dequeue()
			for _, k := range links[j] {
				if groups[k] != i {
					groups[k] = i
					queue.enqueue(k)
				}
			}
		}
	}
	return groups
}

func readLinks(n, k int) [][]int {
	links := make([][]int, n)
	for i := 0; i < k; i++ {
		p := readInt()
		q := readInt()
		links[p-1] = append(links[p-1], q-1)
		links[q-1] = append(links[q-1], p-1)
	}
	return links
}

func main() {
	defer flush()

	n := readInt()
	k := readInt()
	l := readInt()

	roadLinks := readLinks(n, k)
	railLinks := readLinks(n, l)

	roadGroups := createGroups(n, roadLinks)
	railGroups := createGroups(n, railLinks)

	d := map[int]int{}
	for i := 0; i < n; i++ {
		d[2000001*roadGroups[i]+railGroups[i]]++
	}

	for i := 0; i < n; i++ {
		println(d[2000001*roadGroups[i]+railGroups[i]])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


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

void yorimichi(int a,int b,int c){
    if((c-b)*(c-a)<0){
        cout << "Yes" << endl;
    }
    else   cout << "No" << endl;
}

int main(){
    int A,B,C;
    cin >> A >> B >> C;

    yorimichi(A,B,C);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int K,X; cin >> K >> X;
    for (int i = X-K+1; i <= X+K-1; i++) {
        cout << i << " ";
    }
    cout << ln;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

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

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

    int N, A, B;
    cin >> N >> A >> B ;
    cout << min(N*A, B) << endl;

    return 0;
}



Measured memory_bytes: 256