akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int n, dp[100000];
vector<vector<int> > v(18, vector<int> (18));
vector<int> group_val(1 << 17, -1);

int cal_group_val(int mask) {
	int val = 0;

	if (group_val[mask] != -1) {
		return group_val[mask];
	}

	for (int i = 0; i < 17; i++) {
		for (int j = i + 1; j < 17; j++) {
			if ((mask >> i) & 1 && (mask >> j) & 1) {
				val += v[i][j];
			}
		}
	}
	
	group_val[mask] = val;
	return val;
}
 
int solve(int mask) {
	if (mask == 0) {
		return 0;
	}

	if (dp[mask] != -1) {
		return dp[mask];
	}

	// generate all submask of mask
	for (int submask = mask; submask != 0; submask = (submask - 1) & mask) {
		dp[mask] = max(dp[mask], cal_group_val(submask) + solve (mask ^ submask)); // mask ^ submask = gives all mask of values that are not included in submask
	}

	return dp[mask];
}

void c_p_c()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
   #ifndef ONLINE_JUDGE
	freopen("/home/abhinav/c++ codes/input output c++/input.txt", "r", stdin);
	freopen("/home/abhinav/c++ codes/input output c++/output.txt", "w", stdout);
   #endif
   
   cin >> n;

   for (int i = 0; i < n; i++) {
   		for (int j = 0; j < n; j++) {
   			cin >> v[i][j];
   		}
   }
   memset(dp, -1, sizeof dp);
   cout << solve((1 << n) - 1);
}
 
int32_t main()
{
    c_p_c();
    return 0;
}

Measured memory_bytes: 5044
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    while(true){
        int na, nb, nc;
        na = b / 2 + c / 2;
        nb = a / 2 + c / 2;
        nc = a / 2 + b / 2;

        a = na;
        b = nb;
        c = nc;
        ans++;
        if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
            break;
        }else if(ans > 10000000){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


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

int a[100000], n;
int binarysearch(int a[], int key)
{
    int left = 0;
    int right = n;

    while (left < right)
    {
        int mid = (left + right) / 2;
        if (a[mid] == key)
        {
            return 1;
        } else if(a[mid] < key)
        {
            left = mid + 1;
        } else if (a[mid] > key)
        {
            right = mid;
        }
        
    }
    
    return 0;
}

int main()
{
    int q, key, sum = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d", &key);
        if(binarysearch(a, key) == 1)
        {
            sum++;
        }
    }
    
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <stdio.h>
using namespace std;

const int M=25;
int a[M],b[M],c[M];

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(int i=1;i<n;i++)
		scanf("%d",&c[i]);
	int pre=-1;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int now=a[i];
		ans+=b[now];
		if(now==pre+1)
			ans+=c[pre];
		pre=now;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N, K;
    string S, ans;
    cin >> N >> K >> S;
    for ( int i = 0; i < N; i++ ) { 
        char c = S[i];
        if ( i + 1 == K ) {
            if (c == 'A') c = 'a';
            if (c == 'B') c = 'b';
            if (c == 'C') c = 'c';
        }
        ans += c;
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

int main(){
  int i,n,a,ans[100001];
  cin >> n;
  for (i=0;i<n;i++) {cin>>a;ans[a-1]=i;}
  for (i=0;i<n;i++) cout << ans[i]+1 << " ";
}


Measured memory_bytes: 1152
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

typedef complex<double> P;
//typedef vector<P> G;

// 内積 (dot product) : a・b = |a||b|cosΘ
double dot(P a, P b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

// 外積 (cross product) : a×b = |a||b|sinΘ
double cross(P a, P b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}
//(x,y)をx昇順にソート
bool cmp(P a,P b){
	if(a.real()!=b.real()){
		return a.real()<b.real();
	}else{
		return a.imag()<b.imag();
	}
}

/*Graham Scan*/
//凸多角形を求める
int n;
vector<P> getConvex(P *ps){
	sort(ps,ps+n,cmp);
	int k = 0;
	vector<P> convex(n*2);
	for(int i =0;i < n;i++){
		while(2 <=k&&cross(convex[k-1]-convex[k-2],ps[i]-convex[k-1])<=0){
			k--;
		}
		convex[k++]=ps[i];
	}
	for(int i =n-2,t = k;i >=0;i--){
		while(t <k&& cross(convex[k-1]-convex[k-2],ps[i]-convex[k-1])<=0){
			k--;
		}
		convex[k++]=ps[i];
	}
	convex.resize(k-1);
	return convex;
}
int main(){
	while(cin>>n,n){
		P g[120];
		for(int i =0; i<n;i++){
			double x,y;
			char c;
			cin>>x>>c>>y;
			g[i]=P(x,y);
		}
		vector<P> convex =getConvex(g);
		cout <<n-convex.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>

int main(void) {
	int a;
	while (scanf("%d", &a) != EOF) {
		int count = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						if (a == i + j + k + l) count++;
					}
				}
			}
		}
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 1024
n=int(input())

a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
aa=[0 for i in range(n)]
bb=[0 for i in range(n)]

aa[0]=a[0]
bb[n-1]=b[n-1]

for i in range(n-1):
  aa[i+1]=a[i+1]+aa[i]
  bb[n-2-i]=b[n-2-i]+bb[n-1-i]

ame=0
for i in range(n):
  ame=max(ame, aa[i]+bb[i])
  
print(ame)

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

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

  string O ,E;
  cin >> O >> E;

  for (int i = 0; i < O.size(); ++i) {
    if (i == O.size() - 1 && O.size() == E.size()) {
      cout << O.at(i) << E.at(i) << endl;
    }
    else if (i == O.size() - 1 && O.size() != E.size()) {
      cout << O.at(i) << endl;
    }
    else {
      cout << O.at(i) << E.at(i);
    }
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 1
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		cnt = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	for i := 0; i < cnt; i++ {
		if i > 0 {
			fmt.Fprintln(writer, "-----------------------------------")
		}
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	mc := newModcom(n + k + 1)
	for i := 1; i <= k; i++ {
		if n-k+1 < 0 || n-k+1 < i {
			fmt.Fprintln(writer, 0)
			continue
		}
		fmt.Fprintln(writer, mc.choose(k-1, i-1).mul(mc.choose(n-k+1, i)))
	}
}

type modcom struct {
	facs, invs []mint
}

func newModcom(n int) modcom {
	facs := make([]mint, n+1)
	invs := make([]mint, n+1)
	facs[0] = 1
	for i := 0; i < n; i++ {
		facs[i+1] = facs[i].mul(mint(i + 1))
	}
	invs[n] = facs[n].inv()
	for i := n - 1; i >= 0; i-- {
		invs[i] = invs[i+1].mul(mint(i + 1))
	}
	return modcom{
		facs: facs,
		invs: invs,
	}
}
func (mc *modcom) choose(n, k int) mint {
	return mc.facs[n].mul(mc.invs[k]).mul(mc.invs[n-k])
}

type mint int64

func (mt mint) mod() mint {
	m := mint(1e9 + 7)
	mt %= m
	if mt < 0 {
		return mt + m
	}
	return mt
}
func (mt mint) inv() mint {
	return mt.pow(mint(0).sub(2))
}
func (mt mint) pow(n mint) mint {
	if n == 0 {
		return 1
	}
	p := mt.pow(n >> 1)
	if n%2 == 0 {
		return p.mul(p)
	}
	return mt.mul(p).mul(p)
}
func (mt mint) add(x mint) mint {
	return (mt + x).mod()
}
func (mt mint) sub(x mint) mint {
	return (mt - x).mod()
}
func (mt mint) mul(x mint) mint {
	return (mt * x).mod()
}
func (mt mint) div(x mint) mint {
	return mt.mul(x.inv())
}
func (mt *mint) addAs(x mint) *mint {
	*mt = mt.add(x)
	return mt
}
func (mt *mint) subAs(x mint) *mint {
	*mt = mt.sub(x)
	return mt
}
func (mt *mint) mulAs(x mint) *mint {
	*mt = mt.mul(x)
	return mt
}
func (mt *mint) divAs(x mint) *mint {
	*mt = mt.div(x)
	return mt
}


Measured memory_bytes: 768
from math import gcd
from collections import defaultdict

n=int(input())
abd=defaultdict(int)
mod=10**9+7
wzero=0
azero=0
bzero=0
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        wzero+=1
    elif a==0 and b!=0:
        azero+=1
    elif a!=0 and b==0:
        bzero+=1
    else:
        g=gcd(a,b)
        a=a//g
        b=b//g
        abd[(a,b)]+=1

liskey=list(abd.keys())
ans=1
for k in liskey:
    if abd[k] != 0:
        a,b=k
        x=abd[(a,b)]+abd[(-a,-b)]
        y=abd[(-b,a)]+abd[(b,-a)]
        abd[(a,b)]=0
        abd[(-a,-b)]=0
        abd[(-b,a)]=0
        abd[(b,-a)]=0
        ans*=(2**x+2**y-1+mod)%mod
        ans%=mod

ans*=(2**azero+2**bzero-1)
ans%=mod
ans=(ans+wzero)%mod
ans=(ans+mod-1)%mod
print(ans)

Measured memory_bytes: 184408
/*================================================
# ~  file:B.cpp
# ~~ date:2020-03-22
# ~~~author: Accelerator
#        |everybody finds love,in the end|
#   人の運命か,人の希望は悲しみにつづられているね
=================================================*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N=1e6+10;
using namespace std;
typedef pair<int,int>PII;

string s;

int main(){
 ios::sync_with_stdio(false);
  cin>>s;
   int len=s.size();
   string s1=s.substr(0,(len-2)/2+1);
   string s2=s.substr((len+2)/2,len-((len+2)/2));
      string ts=s,ts1=s1,ts2=s2;
    reverse(s.begin(),s.end());
    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());
    if(s1==ts1 && s2==ts2 && ts==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    
    for j in range(H) :
        for i in range(W) :
            if (j + i) % 2 == 0 :
                print("#", end = "")
            else :
                print(".", end = "")
        print()
    print()


Measured memory_bytes: 7000
import java.util.Scanner;

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

        long ans = 0;
        for(int a = 1 ; a <= n ; a++){
            int tmp = 1;
            while(tmp*10 < a){
                tmp *= 10;
            }
            ans += count(a% 10, a/tmp, n);
        }
        System.out.println(ans);
    }

    static long count(int first, int last, int max){
        if(first == 0 || last == 0){
            return(0);
        }
        int keta = 0;
        int tmp = max;
        while(tmp > 0){
            tmp /= 10;
            keta++;
        }

        long ans = 0;
        if(first == last && max >= first){
            ans = 1;
        }
        if(keta == 1){
            return(ans);
        }

        long tens = 1;
        for(int i = 2 ; i < keta ; i++){
            ans += tens;
            tens *= 10;
        }


        long F = first*tens*10+last;
        long L = first*tens*10+last;
        long tens2 = 10;
        for(int i = 2; i < keta ; i++){
            L += 9*tens2;
            tens2 *= 10;
        }

        if(L <= max){
            ans += tens;
        }else{
            ans += (max - F + 10)/10 < 0 ? 0 : (max - F + 10)/10;
        }

        return(ans);
    }
}

Measured memory_bytes: 23892
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll n,m;
    cin>>n>>m;
    vector<ll> v(n+1);
    FOR(i,0,n){
      cin>>v[i+1];
      v[i+1]+=v[i];
      v[i+1] %= m;
    }
    map<ll,ll> mp;
    FOR(i,0,n+1){
      mp[v[i]]++;
    }

    ll ans = 0;
    FORm(i,mp){
      ll t = i->second - 1;
      ans += (1+t)*t/2;
    }
    cout<<ans<<endl;

}


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

int main() {
  int A,B;
  cin >> A >> B;
  
  if((A-B) % 2 ==0){
    cout << (A+B)/2 << endl;
  }
  
  else{
    cout << "IMPOSSIBLE" << endl;
  }
}


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

int main(void) {
 int N;
 scanf("%d",&N);
 int arr[N];
 for (int i=0;i<N;i++)
    scanf("%d",&arr[i]);
    int sum=0;
 for (int i=0;i<N;i++)
 {
  for (int j=i+1;j<N;j++)
   {
    sum+=arr[i]*arr[j];


   }
 }
printf("%d",sum);
 return EXIT_SUCCESS;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int s = scan.nextInt();
		int w = scan.nextInt();
		if (w >= s) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35780
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <stack>


int main (void){

	int n, a;

	std::cin >> n >> a;

	n %= 500;

	if (n <= a) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
class EmployeeRecord
  NUM_EMPLOYEE = 4000
  MILLION = 1000000
  
  def initialize
    @sales = Array.new(NUM_EMPLOYEE + 1).fill(0, 0...(NUM_EMPLOYEE+1))
  end
  
  def updateSales(id, newSales)
    @sales[id] += newSales
  end
  
  def printIdOverMillionSales(idSet)
    count = 0
    for i in 0...idSet.size
      if @sales[idSet[i]] >= MILLION
        count += 1
        puts idSet[i]
      end
    end
    puts "NA"   if count == 0
  end
end

employee = nil
while true
  n = gets.to_i
  idSet = Array.new
  break   if n == 0
  employee = EmployeeRecord.new
  n.times do
    input = gets.split(" ")
    id = input[0].to_i
    idSet << id   if idSet.index(id) == nil
    price = input[1].to_i
    numItems = input[2].to_i
    employee.updateSales(id, price * numItems)
  end
  employee.printIdOverMillionSales(idSet)
end

Measured memory_bytes: 6316
N, T = (int(i) for i in input().split())
A = [[int(i) for i in input().split()] for i in range(N)]
c = [0]
for i in range(N):
    if A[i][1] <= T:
        c.append(A[i][0])
    c = sorted(c)

if len(c) == 1:
    print("TLE")
else:
    print(c[1])


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

using ll = long long;

int N; // 店の数
int F[111][11]; // 営業時間
int P[111][11]; // 利益

int main() {
   cin >> N;
   for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
         cin >> F[i][j];
      }
   }
   
   for (int i = 0; i < N; i++) {
      for (int j = 0; j < 11; j++) { // 0個~10個なので1列の入力は11個ある
         cin >> P[i][j];
      }
   }

   ll ans = -1e15;
   for (int mask = 1; mask < (1<<10); mask++) {
      ll sum = 0;
      for (int i = 0; i < N; i++) {
         int cnt = 0;
         for (int j = 0; j < 10; j++) {
            if (((mask>>j)&1) && F[i][j]) cnt++;
         }
         sum += P[i][cnt];
      }
      ans = max(ans, sum);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (u == s) {
    cout << a - 1 << " " << b << endl;
  } else if (u == t) {
    cout << a << " " << b-1 << endl;
  } else {
    cout << a << " " << b << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int i,j,n,k,c,h,w,p[50],q[50];
int main(){
  for(cin>>n;i<n;i++)cin>>p[i],q[i]=p[i];
  sort(p,p+n);
  for(i=0;i<n;i++){
    if(q[i]!=p[i])c++;
    if(c>2)return cout<<"NO",0;
  }
  cout<<"YES";
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

const std::array<int32_t, 4> dx = {1, 0, -1, 0};
const std::array<int32_t, 4> dy = {0, 1, 0, -1};

int main() {
  int32_t N = 0;
  std::cin >> N;
  std::vector<int32_t> ord(N * N);
  for (auto &&o : ord) std::cin >> o;

  std::vector<std::vector<bool>> grid_e(N, std::vector<bool>(N, true));
  std::vector<std::vector<uint32_t>> grid(N, std::vector<uint32_t>(N, 0));
  for (int32_t c = 0; c < (N + 1) / 2; c++) {
    for (int32_t i = 0; i < N - c * 2; i++) {
      grid[c][c + i] = c;
      grid[(N - 1) - c][c + i] = c;
    }
    for (int32_t i = 1; i < N - c * 2 - 1; i++) {
      grid[c + i][c] = c;
      grid[c + i][(N - 1) - c] = c;
    }
  }

  auto row = [=](int32_t no) { return (no - 1) / N; };
  auto col = [=](int32_t no) { return (no - 1) % N; };

  uint64_t cost = 0;
  for (auto &&e : ord) {
    cost += grid[row(e)][col(e)];
    grid_e[row(e)][col(e)] = false;

    std::queue<int32_t> Q;
    Q.push(e);

    while (!Q.empty()) {
      int32_t q = Q.front();
      int32_t r = row(q), c = col(q);
      Q.pop();

      for (size_t i = 0; i < dx.size(); i++) {
        // todo:dx/dy範囲外チェック
        if ((r + dx[i]) >= 0 && (r + dx[i]) < N && (c + dy[i]) >= 0 &&
            (c + dy[i]) < N)
          if (grid[r + dx[i]][c + dy[i]] > grid[r][c] + grid_e[r][c]) {
            grid[r + dx[i]][c + dy[i]] = grid[r][c] + grid_e[r][c];
            Q.push(q + N * dx[i] + dy[i]);
          }
      }
    }
  }

  std::cout << cost << std::endl;

  return 0;
}

Measured memory_bytes: 5328
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b)
{
    if (a < b)
        ll c = a, a = b, b = c;

    return a % b == 0 ? b : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

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

    ll n, m;
    string s, t;

    cin >> n >> m;
    cin >> s >> t;

    bool b = true;

    ll num = max(s.size() * m, t.size() * n);
    ll r = min(m, n);

    for (ll i = 0; i < num; i += r)
    {
        if ((i) % n == 0 && (i) % m == 0)
        {
            if (s[i / m] != t[i / n])
            {
                b = false;

                cout << -1 << endl;
                return 0;
            }
        }
    }

    cout << lcm(n, m) << endl;

    return 0;
}

Measured memory_bytes: 640
import sys
import math

def read_int():
    line = sys.stdin.readline().rstrip('\n')
    return int(line)

def read_int_list():
    line = sys.stdin.readline().rstrip('\n')
    return [int(e) for e in line.split(' ')]

N = read_int()

print(1000 * math.ceil (N / 1000) - N)

Measured memory_bytes: 9172
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 1e5 + 10;
int N;
int64_t d[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    
    for (int i = 1; i <= N; i++) {
        std::cin >> d[i];
    }

    if (N % 2 == 1) {
        std::cout << 0 << std::endl;
        return 0;
    }

    std::sort(d + 1, d + 1 + N);

    std::cout << d[N/2 + 1] - d[N/2] << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll MOD = (ll)1e9+7;
const ll MAX = (ll)6e3+10;


// union by size + path having
class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;

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

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    // Union(Unite, Merge)
    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)];
    }
};


int main(void) {
   ll N,K,L;
   cin>>N>>K>>L;
   UnionFind puf0 = UnionFind(N);
   puf0.init(N);
   UnionFind puf1 = UnionFind(N);
   puf1.init(N);
   rep(i,0,K) {
      ll p,q;
      cin>>p>>q;
      puf0.merge(p-1,q-1);
   }
   rep(i,0,L) {
      ll p,q;
      cin>>p>>q;
      puf1.merge(p-1,q-1);
   }
   map<pair<ll,ll>,ll> ans;
   rep(i,0,N) ans[make_pair(puf0.root(i),puf1.root(i))]++;
   rep(i,0,N) cout<<ans[make_pair(puf0.root(i),puf1.root(i))]<<" ";
   cout<<endl;

   return 0;
}



Measured memory_bytes: 18048
#define MST(a, b) memset(a,b,sizeof(a))
#define ALL(v) (v).begin(),(v).end()
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;

#include <ext/pb_ds/priority_queue.hpp>

using namespace __gnu_pbds;
typedef __gnu_pbds::priority_queue<pii, greater<>, pairing_heap_tag> heap;
typedef heap::point_iterator iter;
typedef long long LL;
typedef unsigned long long ULL;
//typedef __int128 LL128;

#define int LL
void init_all(int t = 0) {
    if (t & 1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
#ifdef LOCAL
    if ((t >> 1) & 1) freopen("input", "r", stdin);
    if ((t >> 2) & 1) freopen("output", "w", stdout);
#endif
}

const int N = 1e5+19;
int x[N],p[N],n,s;
LL ans;

void work(int l,int r,int dir) {
    if(s <= x[l]) {
        ans += x[r]-s;
        return ;
    }
    if(s >= x[r]) {
        ans += s-x[l];
        return ;
    }
    if(p[l] >= p[r]) {
        p[l] += p[r];
        if(dir == -1 || dir) ans += x[r]-x[l];
        work(l,r-1,0);
    }
    else {
        p[r] += p[l];
        if(dir == -1 || !dir) ans += x[r]-x[l];
        work(l+1,r,1);
    }
}

void solve() {
    cin >> n >> s;
    for(int i = 1; i <= n ; ++i)
        cin >> x[i] >> p[i];
    work(1,n,-1);
    cout << ans << endl;
}

signed main() {
    srand((int)time(0));
    init_all(3);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}

Measured memory_bytes: 1792
N, M = list(map(int, input().split()))
data = list(map(int, input().split()))
result = 10**9
for i in range(N-M+1):
  result = min([abs(data[i])+abs(data[i+M-1]-data[i]), 
                abs(data[i+M-1])+abs(data[i]-data[i+M-1]),
                result])
print(result)

Measured memory_bytes: 14564
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
string n;
int sum,a;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<sz(n);i++) sum+=(n[i]-'0'),a=a*10+(n[i]-'0');
	cout<<(a%sum?"No":"Yes");
	re 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

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

int main(){

    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N){
        cin >> A[i];
    }

    vector<ll> S(N+1);
    S[0]=0;
    FOR(i,1,N+1){
        S[i] = S[i-1] + A[i-1];
    }
    sort(S.begin(), S.end());

    ll ans=0, count=0;

    REP(i,N){
        if(S[i]==S[i+1]){
            if(count==0){
                count=1;
            }
            count++;
        }else{
            ans += count*(count-1)/2;
            count=0;
        }
    }

    ans += count*(count-1)/2;

    cout << ans << endl;
    return 0;

}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n, x;
  scanf("%d %d", &n, &x);

  vector<int> a(n);
  REP (i, n) {
    scanf("%d", &a[i]);
  }

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

  int i = 0;
  while (i < n && x > 0) {
    if (x - a[i] >= 0)
      x -= a[i];
    else
      break;
    if (i + 1 == n && x > 0)
      break;
    i++;
  }

  cout << i << endl;
}


Measured memory_bytes: 256
def insertion_sort(N,input_list):
    for i in range(1,N):
        for j in range(N):
            if j != N - 1:
                print(input_list[j],end=" ")
            else:
                print(input_list[j])
        v = input_list[i]
        j = i - 1
        while j>=0 and input_list[j] > v:
            input_list[j+1] = input_list[j]
            j -= 1
            input_list[j+1] = v
    return input_list

def main():
    N = int(input())
    input_list = [int(i) for i in input().split()]
    input_list = insertion_sort(N,input_list)
    for i in range(N):
        if i != N - 1:
            print(input_list[i],end=" ")
        else:
            print(input_list[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 6032
kind = [0, 0, 0, 0]
N = int(input())
for _ in range(N):
    line = input()
    if line == 'AC':
        kind[0] += 1
    elif line == 'WA':
        kind[1] += 1
    elif line == 'TLE':
        kind[2] += 1
    elif line == 'RE':
        kind[3] += 1

print('AC x ' + str(kind[0]))
print('WA x ' + str(kind[1]))
print('TLE x ' + str(kind[2]))
print('RE x ' + str(kind[3]))


Measured memory_bytes: 9012
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10000*x + 5000*y + 1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

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

int main() {
  string S;
  cin >> S;
  ll cnt = 0;
  for(ll i = 0; i < S.size(); i++) {
    if(S.at(i) == 'R') cnt++;
  }
  if(S.at(1) == 'R') cout << cnt << endl;
  else cout << min((ll)(1), cnt) << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    int ans=0;
    for(int i=0; i<str.size(); i++) {
        if(i%2) {
            if(str[i]=='g') {
                ans++;
            }
        } else {
            if(str[i]=='p') {
                ans--;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000009
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl '\n'

int dp[105][100005];
int wt[101],val[101];
int n,w;

int knapsack(int ind,int v){
	if(ind == n && v == 0) return 0;
	if(ind == n || v < 0) return INT_MAX;
	if(dp[ind][v]!=-1)return dp[ind][v];
	return dp[ind][v]=min(wt[ind]+knapsack(ind+1,v-val[ind]),knapsack(ind+1,v));
}

signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	cin >> n >> w;

	int sum = 0;
	for0(i,n){
		cin >> wt[i] >> val[i];
		sum += val[i];
	}

	memset(dp,-1,sizeof(dp));

	for(int i=sum;i>=0;i--){
		if(knapsack(0,i) <= w){
			cout << i;
			return 0;
		}
	}

	return 0;
}

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

using namespace std;

struct info{
	string src;
	string dst;
	string msg;
};

int main()
{
	int n, m;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		
		info rule[1024], pat, ok[1024];
		int t = 0;
		for(int i = 0; i < n; i++){
			cin >> rule[i].msg >> rule[i].src >> rule[i].dst;
		}
		
		for(int i = 0; i < m; i++){
			cin >> pat.src >> pat.dst >> pat.msg;
			bool f = false, f2 = true;	
			for(int j = 0; j < n; j++){
				f2 = true;
				if(rule[j].msg == "deny"){
					for(int k = 0; k < 8; k++){
						if(rule[j].src[k] == '?'){
							continue;
						}
						if(rule[j].src[k] != pat.src[k]){
							f2 = false;
							break;
						}
					}
					if(!f2){
						continue;;
					}
					for(int k = 0; k < 8; k++){
						if(rule[j].dst[k] == '?'){
							continue;
						}
						if(rule[j].dst[k] != pat.dst[k]){
							f2 = false;
							break;
						}
					}
					if(f2){
						f = false;
					}
				} else if(rule[j].msg == "permit"){
					for(int k = 0; k < 8; k++){
						if(rule[j].src[k] == '?'){
							continue;
						}
						if(rule[j].src[k] != pat.src[k]){
							f2 = false;
							break;
						}
					}
					if(!f2){
						continue;
					}
					for(int k = 0; k < 8; k++){
						if(rule[j].dst[k] == '?'){
							continue;
						}
						if(rule[j].dst[k] != pat.dst[k]){
							f2 = false;
							break;
						}
					}
					if(f2){
						f = true;
					}
				}
			}
			if(f){
				for(int j = 0; j < t; j++){
					if(ok[j].src == pat.src && ok[j].dst == pat.dst && ok[j].msg == pat.msg){
						f = false;
						break;
					}
				}
				if(f){
					ok[t++] = pat;
				}
			}
		}
		cout << t << endl;
		for(int i = 0; i < t; i++){
			cout << ok[i].src << " " << ok[i].dst << " " << ok[i].msg << endl;
		}
	}
	
	return 0;
}

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


int main() 
{
    int A[251];
    int size;
    int i, j;
    scanf("%d", &size);
    
    for (i = 1; i <= size; i++) 
    {
        scanf("%d ", &A[i]);
    }
        
    for(i = 1; i <= size; i++)
     {
         printf("node %d: key = %d, ", i, A[i]);
         j = i / 2;
         if (j >= 1)printf("parent key = %d, ", A[j]);
         if (2 * i <= size)printf("left key = %d, ", A[i * 2]);
         if (2 * i + 1 <= size)printf("right key = %d, ", A[i * 2 + 1]);
         printf("\n");
    }

 return 0;
}


Measured memory_bytes: 2040
DIR = [(1, 0), (-1, 0), (0, 1), (0, -1)]

H, W = [int(x) for x in input().split()]
G = []
B = 0

G.append('#' * (W + 2))
for i in range(H):
    s = input()
    B += s.count('.')
    G.append(['#'] + list(s) + ['#'])
G.append('#' * (W + 2))

que = [(1, 1, 1)]
ans = -1

while que:
    y, x, c = que.pop(0)
    if (y, x) == (H, W):
        ans = c
        break
    for dir in DIR:
        ny = y + dir[0]
        nx = x + dir[1]
        if G[ny][nx] == '.':
            G[ny][nx] = '#'
            que.append((ny, nx, c + 1))

print(B - ans if ans != -1 else -1)

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

int main(){
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    int sum=1;
    int max=h[0];
    for(int i=1;i<n;i++){
        if(max<=h[i]){
            max=h[i];
            sum++;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import copy

num_of_switch, num_of_lights = [int(_) for _ in input().split()]


def toSwitch(xs):
    xs[1:]


S = [[int(s) - 1 for s in input().split()[1:]] for i in range(num_of_lights)]
P = [_ == "1" for _ in input().split()]

# i は switch の添字


def rec(switch_idx, lights):
    if switch_idx == num_of_switch:
        if lights == P:
            return 1
        else:
            return 0

    switch_off_result = rec(switch_idx + 1, lights)

    _lights = copy.deepcopy(lights)

    for light_idx in range(num_of_lights):
        # print(f"switch_idx = {switch_idx}, light_idx = {light_idx}")
        is_connect = switch_idx in S[light_idx]
        if is_connect:
            _lights[light_idx] = not _lights[light_idx]

    # print(f"switch_idx = {switch_idx}: not choose = {lights}, choose = {_lights} ")

    switch_on_result = rec(switch_idx + 1, _lights)

    return switch_off_result + switch_on_result


ans = rec(0, [False] * num_of_lights)
print(ans)


Measured memory_bytes: 9140
#include"bits/stdc++.h"
using namespace std;

bool isOK(string S, int m) {
    //mでできるかどうか
    vector<int> flip_num(S.size(), 0);
    for (int i = 0; i <= S.size() - m; i++) {
        if (i != 0) {
            flip_num[i] += flip_num[i - 1];
        }
        if (((int)(S[i] == '1') + flip_num[i]) % 2 == 1) {
            flip_num[i]++;
            if (i + m < S.size()) {
                flip_num[i + m]--;
            }
        }
    }
    for (int i = S.size() - m; i < S.size() - 1; i++) {
        flip_num[i + 1] += flip_num[i];
    }
    for (int i = 0; i < m; i++) {
        if ((flip_num[i] % 2 == 0 && S[i] == '1')
            ||(flip_num[i] % 2 == 1 && S[i] == '0')) {
            return false;
        }
    }
    return true;
}

int main() {
    string S;
    cin >> S;
    int ok = 1, ng = S.size() + 1;
    while (ok + 1 < ng) {
        int mid = (ng + ok) / 2;
        if (isOK(S, mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 896
# coding: utf-8
from collections import defaultdict

num_card, num_ave = map(int, input().split())
l_card = map(lambda x: int(x) - num_ave, input().split())

counter = defaultdict(int)
counter[0] = 1

for card in l_card:
    for d, c in list(counter.items()):
        counter[d + card] += c

print(counter[0] - 1)

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

const ll INF = ll(1e18)+1;

ll f(ll i){
  if(i==1) return 1;
  ll a = f(i/2);
  return a*2 + 1;
}

int main(){
  ll h;
  cin >> h;
  cout << f(h) << endl;
  return 0;
}

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

// main
int main(){
    string A, B; cin >> A >> B;
    string num = "123";
    num.erase(num.find(A), 1);
    num.erase(num.find(B), 1);
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
#define MOD 1000000007
#define INF (1<<30)

const int MAX_C = 60;
ll Com[MAX_C][MAX_C];

void calc_com() {
	for (int i = 0; i < MAX_C; ++i) for (int j = 0; j < MAX_C; ++j) Com[i][j] = 0.0;
	Com[0][0] = 1.0;
	for (int i = 1; i < MAX_C; ++i) {
		Com[i][0] = 1.0;
		for (int j = 1; j < MAX_C; ++j) {
			Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]);
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, A, B; cin >> N >> A >> B;
	vector<ll> v(N);
	for (int i = 0; i < N;i++) cin >> v[i];
	sort(v.begin(), v.end());
	map<ll, ll> m;
	for (int i = 0; i < N;i++) {
		m[v[i]]++;
	}
	v.erase(unique(v.begin(), v.end()), v.end());

	sort(v.begin(), v.end(),greater<ll>());

	calc_com();

	if (m[v[0]] >= A) {
		cout << fixed << setprecision(10) << (double)v[0] << endl;
		ll ans = 0;
		ll X = min(m[v[0]], B);
		for (int i = A; i <= X;i++) {
			ans += Com[m[v[0]]][i];
		}
		cout << ans << endl;
		return 0;
	}

	ll sub_A = A;
	ll ans = 1;
	double ave = 0;
	for (int i = 0; i < v.size();i++) {
		ll x = m[v[i]];
		if (sub_A > x) {
			ans *= x;
			sub_A -= x;
			ave += v[i] * x;
		}
		else {
			ans *= Com[x][sub_A];
			ave += v[i] * sub_A;
			break;
		}
	}
	ave /= A;
	cout << fixed << setprecision(10) << ave << endl;
	cout << ans << endl;
}

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

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

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

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

    vector<long long> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(p.begin(), p.end(), greater<long long>());
    sort(q.begin(), q.end(), greater<long long>());
    sort(r.begin(), r.end(), greater<long long>());

    vector<long long> s(x + y + c);

    rep(i, x) s[i] = p[i];
    rep(i, y) s[i + x] = q[i];
    rep(i, c) s[i + x + y] = r[i];

    sort(s.begin(), s.end(), greater<long long>());

    long long sum = 0;
    rep(i, x+y){
        sum += s[i];
    }
    cout << sum << endl;

}

Measured memory_bytes: 4864
#include<stdio.h>
int main(){
  int w,h,i,j,t,r,c;
  int x[400],y[400];
  int X[4]={0,1,0,-1};
  int Y[4]={1,0,-1,0};
  char m[20][20];
  while(scanf("%d %d",&w,&h),w||h){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf(" %c",&m[i][j]);
	if(m[i][j]=='@'){
	  y[0]=i;
	  x[0]=j;
	  m[i][j]='#';
	}
      }
    }
    t=c=0;
    for(r=1;r-t;t++){
      for(i=0;i<4;i++){
	if(x[t]+X[i]<0||w<=x[t]+X[i]||
	   y[t]+Y[i]<0||h<=y[t]+Y[i])continue;
	if(m[y[t]+Y[i]][x[t]+X[i]]=='#')continue;
	y[r]=y[t]+Y[i];
	x[r]=x[t]+X[i];
	m[y[r  ]][x[r++]]='#';
	c++;//printf("%d %d\n",y[r-1],x[r-1]);
      }
    }
    printf("%d\n",c+1);
  }
  return 0;
}
    

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];

  map<int, int> ma;
  for (int i = 0; i < m; i++) {
    ma[a[i]]++;
    ma[b[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cout << ma[i + 1] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){

    string N;
    cin >> N;

    int num = N.size();

    if(N.at(num-1) == '2' || N.at(num-1) == '4' || N.at(num-1) == '5' || N.at(num-1) == '7' || N.at(num-1) == '9'){
        cout << "hon" << endl;
    }

    else if(N.at(num-1) == '0' || N.at(num-1) == '1' || N.at(num-1) == '6' || N.at(num-1) == '8'){
        cout << "pon" << endl;
    }

    else {
        cout << "bon" << endl;
    }


}

Measured memory_bytes: 3624
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less_equal<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define mem(a, b) memset(a, b, sizeof a)
#define sq(x) (x) * (x)
#define out return cout << "NO" << endl, 0
//const int mx = 1e5 + 10;
int dp[305][305][305];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	int k, n;
	cin >> s >> k;
	n = sz(s);
	for(int l = n - 1; ~l; l--)
		for(int r = l + 1; r <= n; r++)
			for(int t = 0; t <= k; t++){
				if(r - l == 1){
					dp[l][r][t] = 1;
					continue;
				}
				if(s[l] == s[r - 1])
					dp[l][r][t] = dp[l + 1][r - 1][t] + 2;
				else{
					dp[l][r][t] = max(dp[l + 1][r][t] , dp[l][r - 1][t]);
					if(t)
						smax(dp[l][r][t] , dp[l + 1][r - 1][t - 1] + 2);
				}
			}
	cout << dp[0][n][k] << endl;
	return 0;
}




Measured memory_bytes: 112268
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
input = input.split('\n').map(x=> x*1);
// 1桁目が0以外で1に近いほうをあとに注文したい（待たされるから）
let oneKetaMin =Math.min(...input.map(x=> x % 10).filter(x=> x!= 0));
// 原則は繰り上げて足し合わせる
let Sum = input.map(x => Math.ceil(x/10)*10).reduce((x,a)=> a+=x);
// 必要な数を最後に引く
// 全部の1桁目以外かどうかで分岐
if(isFinite(oneKetaMin)){
	Sum = Sum - 10 + oneKetaMin
}

console.log(Sum);


Measured memory_bytes: 22464
N= int(input())
C0 = 0
C1 = 0
C2 = 0
C3 = 0

for i in range(N):
    a = input()
    if a == 'AC':
        C0 += 1
    if a == 'WA':
        C1 += 1
    if a == 'TLE':
        C2 += 1
    if a == 'RE':
        C3 += 1
print(f'AC x {C0}')
print(f'WA x {C1}')
print(f'TLE x {C2}')
print(f'RE x {C3}')

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

namespace AtCoderDISCO
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            long[] info = Console.ReadLine().Split().Select(x => Convert.ToInt64(x)).ToArray();

            long t_sm = info.Sum();
            long mn = long.MaxValue;
            long sm = 0;
            for(int i = 0; i < n - 1; ++i)
            {
                sm += info[i];
                mn = Math.Min(Math.Abs(t_sm - 2 * sm), mn);
            }

            Console.WriteLine(mn);
        }
    }
}


Measured memory_bytes: 37504
#!/usr/bin/env python3
#ABC134 A

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

r = int(input())
print(3*r**2)


Measured memory_bytes: 38384
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N, M;
	cin >> N >> M;
	vector<int> sum(M, 0);
	for (int i = 0; i < N; ++i) {
		int K;
		cin >> K;
		int A;
		for (int j = 0; j < K; ++j) {
			cin >> A;
			A--;
			sum[A]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < M; ++i) {
		if (sum[i] == N) {
			ans++;
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256