akhauriyash/Code-Regression huggingface dataset:
N = gets.to_i

A = []
B = []

N.times do
  a, b = gets.split.map(&:to_i)

  A << a
  B << b
end

ans = 0

A.zip(B).reverse_each do |a, b|
  ans += b - (a + ans) % b if (a + ans) % b > 0
end

puts ans


Measured memory_bytes: 8572
def main():
    import math
    import functools
    n, x = map(int, input().split())
    inset = set(map(int, input().split()))
    inset2 = set()

    for num in inset:
        inset2.add(abs(num - x))

    gcd = functools.reduce(math.gcd, inset2)
    print(gcd)

            



if __name__ == "__main__":
    main()

Measured memory_bytes: 26372
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){		
			int N = scan.nextInt();//スイッチの個数
			int M= scan.nextInt();//ｍ個の電球
			
			int[]k = new int[M];
			int[][]s = new int[M][N];
			
			for(int i = 0;i<M;i++) {
				k[i]  =scan.nextInt();
				for(int j =0;j<k[i];j++) {
					s[i][j] = scan.nextInt();
				}
			}
			int[]p = new int[M];//０or1
			
			for(int i = 0;i<M;i++) {
				p[i] =scan.nextInt();
			}
			
			int[] sw = new int[N];
			int dennkyugatukutouri = 0;
			for(int i = 0;i<(int)Math.pow(2, N);i++) {	
				for(int j = 0;j<N;j++) {
					if((1&i>>j)==1) 
						sw[j] = 1;
					else
						sw[j] = 0;
				}
				
				int hikarukosuu = 0;
				for(int z = 0;z<M;z++) {
					int onkosuu = 0;
					for(int w = 0;w<k[z];w++) {
						if(sw[s[z][w]-1]==1) {
							onkosuu++;
						}
					}
					if(onkosuu%2==p[z]) {
						hikarukosuu++;
					}
				}
				
				if(hikarukosuu==M) {
					dennkyugatukutouri++;
				}
				
				
			}
			
			
			System.out.println(dennkyugatukutouri);
			
			
			
		}
		
		
	}
		
	

}

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

int main() {
  int n; cin >> n;
  vector<double> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  vector<int> v(n);
  rep(i, n) v[i] = i;
  double ans = 0;
  int cnt = 0;
  do {
    rep(i, n-1) {
      double xx = x[v[i]] - x[v[i+1]];
      double yy = y[v[i]] - y[v[i+1]];
      ans += sqrt(xx * xx + yy * yy);
    }
    cnt++;
  } while (next_permutation(v.begin(), v.end()));
  cout << fixed << setprecision(10) << (double)ans/cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  ll s = 0;
  rep(i,n) s += a.at(i);
  if(s >= h) cout<< "Yes" << endl;
  else cout << " No" << endl;
}


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

int main() {
    long N, P;
    cin>>N>>P;
    vector<long> arr(N);
    long w, b;
    long bsum = 0;
    for(int i=0;i<N;++i) {
        cin>>w>>b;
        arr[i] = (100-P)*w + P*b;
        bsum += b;
    }
    sort(arr.begin(), arr.end());
    long tmp = 0;
    int ans;
    for(int i=0;i<N;++i){
        tmp += arr[N-1-i];
        if(P*bsum<=tmp){
            ans = i+1;
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
// printing the string S after lowercasing the Kth character in it
#include<bits/stdc++.h>
using namespace std;

int N, K;
string S;

int main() {
    cin >> N >> K >> S;
    S[K-1] = tolower(S[K-1]);
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 3608
package main

import (
	"fmt"
	"math"
)

func main(){
	var a,b,c,d int
	fmt.Scan(&a,&b,&c,&d)
	ansT := 0
	ansB := 0
	ansT = int(math.Min(float64(a),float64(b)))
	ansB = int(math.Min(float64(c),float64(d)))
	fmt.Println(ansT + ansB)
}

Measured memory_bytes: 512
//by rko27
//One more....
//---------------------------------------------------------------------------------------------------------------------------------------------------

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int  long long 
#define ll  long long 
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define nl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)(x.size())
#define god ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

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


int mod=1000000000+7;
int modu=998244353;

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

ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}
void fun()
{
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	//786
}
bool isPrime(int n){for(int i=2;i*i<=n;i++)if(n%i==0) return false;return true;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}

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

const int N=1e6+7;


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



//--------------------------------------------------------------------------------------------------------------------------------------------------------
signed main() 
{
	//god;
	//rko;
	fun();
	//int ttt=1; //cin>>ttt;
	//while(ttt--)
	{
		string s,t; cin>>s>>t;
		int n=s.length(), m=t.length();
		int dp[n+1][m+1];
		memset(dp, 0, sizeof(dp));
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(s[i-1]==t[j-1]) dp[i][j] = 1 + dp[i-1][j-1] ;
				else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
			}
		}
		int i=n,j=m;
		string ans="";
		int k=dp[n][m];
		while(i>0 and j>0)
		{
			if(s[i-1]==t[j-1])
			{
				ans+=s[i-1];
				i--, j--, k--;
			}
			else if(dp[i][j-1]>dp[i-1][j]) j--;
			else i--;
		}
		reverse(all(ans));
		cout<<ans<<nl;
		// for(int i=1;i<=n;i++)
		// {
		// 	for(int j=1;j<=m;j++)
		// 	{
		// 		cout<<dp[i][j]<<' ';
		// 	}
		// 	cout<<nl;
		// }
	}
	return 0;
}

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

namespace CSharpSample01
{

    class Program
    {

        static long Solve1(List<int> list, int u)
        {
            int left = -1;
            int right = list.Count;

            while (right - left > 1)
            {
                int mid = left + (right - left) / 2;
                
                if (list[mid] >= u)
                {
                    right = mid;
                }
                else
                {
                    left = mid;  
                }

            }           

            return right - 1;

        }

        static long Solve2(List<int> list, int u)
        {
            int left = -1;
            int right = list.Count;

            while (right - left > 1)
            {
                int mid = left + (right - left) / 2;
               
                if (list[mid] > u)
                {
                    right = mid;
                }
                else
                {
                    left = mid;
                }

            }
            
            return right;
        }


        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            List<int> a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            a.Sort();
            List<int> b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            List<int> c = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            c.Sort();
            
            long ans = 0;
            foreach (var s in b)
            {                
                long ss = Solve1(a, s) + 1;
                long tt = c.Count - Solve2(c, s);
                ans += ss * tt;               
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 40736
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 200200
#define MOD 1000000007
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX];
int f[MAX],lst[MAX];
int main()
{
	n=read();for(int i=1;i<=n;++i)a[i]=read();
	f[0]=1;
	for(int i=1;i<=n;++i)
	{
		add(f[i],f[i-1]);
		if(i-lst[a[i]]>1&&lst[a[i]])add(f[i],f[lst[a[i]]]);
		lst[a[i]]=i;
	}
	printf("%d\n",f[n]);
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 1010;
bool g[N][N];
int col[N];
int C[2];
bool dp[2][N];
int n;

bool dfs(int v) {
	C[col[v]]++;
	for (int u = 0; u < n; u++) {
		if (!g[v][u]) continue;
		if (col[u] != -1) {
			if (col[v] == col[u]) return false;
			continue;
		}
		col[u] = col[v] ^ 1;
		if (!dfs(u)) return false;
	}
	return true;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			g[i][j] = i != j;
	while(m--) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;u--;
		g[v][u] = g[u][v] = 0;
	}
	for (int i = 0; i < n; i++)
		col[i] = -1;
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		if (col[i] != -1) continue;
		col[i] = 0;
		C[0] = C[1] = 0;
		if (!dfs(i)) {
			printf("-1\n");
			return 0;
		}
		for (int j = 0; j <= n; j++)
			dp[1][j] = 0;
		for (int x = 0; x <= n; x++) {
			if (!dp[0][x]) continue;
			dp[1][x + C[0]] = dp[1][x + C[1]] = 1;
		}
		for (int j = 0; j <= n; j++)
			dp[0][j] = dp[1][j];
	}
	int x = n / 2;
	while(!dp[0][x]) x--;
//	cerr << x << endl;
	printf("%d\n", (x * (x - 1) + (n - x) * (n - x - 1)) / 2);

	return 0;
}


Measured memory_bytes: 896
<?php
  
$hw = explode(' ',fgets(STDIN));
$h = $hw[0];
$w = $hw[1];

$tb = '';
for($i=0; $i<$w+2; $i++){
  $tb = $tb.'#';
}

for($i=0; $i<$h; $i++){
  if ($i == 0) echo $tb;
  echo "\n#".trim(fgets(STDIN))."#"; 
  if ($i == $h-1) echo "\n".$tb;
}
 
?>

Measured memory_bytes: 4604
import numpy as np

c = [list(map(int, input().split())) for i in range(3)]

A = np.array([
    [1, 0, 0, 1, 0, 0],
    [1, 0, 0, 0, 1, 0],
    [1, 0, 0, 0, 0, 1],
    [0, 1, 0, 1, 0, 0],
    [0, 1, 0, 0, 1, 0],
    [0, 1, 0, 0, 0, 1],
    [0, 0, 1, 1, 0, 0],
    [0, 0, 1, 0, 1, 0],
    [0, 0, 1, 0, 0, 1]])

B = np.array([
    [1, 0, 0, 1, 0, 0, c[0][0]],
    [1, 0, 0, 0, 1, 0, c[0][1]],
    [1, 0, 0, 0, 0, 1, c[0][2]],
    [0, 1, 0, 1, 0, 0, c[1][0]],
    [0, 1, 0, 0, 1, 0, c[1][1]],
    [0, 1, 0, 0, 0, 1, c[1][2]],
    [0, 0, 1, 1, 0, 0, c[2][0]],
    [0, 0, 1, 0, 1, 0, c[2][1]],
    [0, 0, 1, 0, 0, 1, c[2][2]]])

rankA = np.linalg.matrix_rank(A)
rankB = np.linalg.matrix_rank(B)

if rankA == rankB:
    print("Yes")
else:
    print("No")


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

int main(){
	int n=0;
	char str[100];
	scanf("%s",str);
	for(int i=0;i<4;i++){
		if(str[i]=='+'){
			n++;
		}
		else{
			n--;
		}
	}
	cout << n << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    int n;
    std::cin >> n;
    VEC(ll,a,n);
    VEC(ll,b,n);
    ll c=0,cc=0;
    rep(i,n){
        if(a[i]>b[i])c+=(a[i]-b[i]);
        if(b[i]>a[i])cc+=(b[i]-a[i])/2;
    }
    if(c>cc)std::cout << No << std::endl;
    else std::cout << Yes << std::endl;
}

Measured memory_bytes: 384
while True:
  n = int(input())
  if n == 0:
    break
  plst = list(map(int, input().split()))
  jlst = sorted(list(map(int, input().split())), reverse=True)
  sump = sum(plst)
  ans = sump * n
  for i in range(n - 1):
    sump += jlst[i]
    n -= 1
    ans = max(ans, sump * n)
  print(ans)


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

signed main(void)
{
	int n, m;
	map<int, int> mp;
	bool ok;

	cin >> n;
	rep(i, n)
	{
		int a;
		cin >> a;
		mp[a]++;
	}
	cin >> m;
	ok = true;
	rep(i, m)
	{
		int b;
		cin >> b;
		if (mp.count(b) && mp[b] > 0)
			mp[b]--;	
		else
			ok = false;
	}
	if (ok)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>

static const int MAX = 500;
static const int INFTY=(1<<21);

int main( ){
  int i,j,n,u,vg,k;
  int Adj[MAX][MAX];
  int d[MAX],p[MAX],v[MAX];
  int mini,sum;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&k);
      Adj[i][j] = (k ==-1)?INFTY:k;
    }
  }

  for(i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    v[i] = 0;
  }
  d[0] = 0;

  while(1){
    mini = INFTY;
    u = -1;
    for(i=0;i<n;i++){
      if(mini>d[i]&&!v[i]){
	u=i;
	mini=d[i];
      }
    }
    if(u==-1)break;
    v[u]=1;
    for(vg=0;vg<n;vg++){
      if(!v[vg] && Adj[u][vg]!=INFTY){
	if(d[vg]>Adj[u][vg]){
	  d[vg]=Adj[u][vg];
	  p[vg]=u;
	}
      }
    }
  }
  sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=Adj[i][p[i]];
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2060
#include<iostream>
#include<algorithm>

using namespace std;

int n;
int d[100002];

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++)
		cin >> d[i];
	sort(d+1,d+n+1);
	int mid = n/2;
	if(d[mid] == d[mid+1])
		cout << "0" << endl;
	else
		cout << d[mid+1]-d[mid] << endl;
	return 0;
}

Measured memory_bytes: 640
package main

import (
  "fmt"
  "sort"
)

func main() {
  var k,t int
  fmt.Scan(&k,&t)
  var a[] int
  for i := 0; i < t; i++ {
    var x int
    fmt.Scan(&x)
    a = append(a, x)
  }
  sort.Sort(sort.Reverse(sort.IntSlice(a)))

  maxNum := a[0]
  a[0] = 0
  for i := 1; i < t; i++ {
    if maxNum > a[i] {
      maxNum -= a[i]
    } else if maxNum == a[i] {
      maxNum = a[(i+1)%t]
    } else {
      a[i] -= maxNum
      maxNum = a[i]
    }
  }

  if maxNum > 0{
    fmt.Println(maxNum-1)
  } else {
    fmt.Println(0)
  }

}

Measured memory_bytes: 512
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	cin >> N;
	VI A(N+2);
	for (int n = 1; n <= N; n++)cin >> A[n];
	A.back() = 0;
	LL money = 1000;
	int cur = 1;
	int p = 2;
	while (p <= N+1) {
		if (A[p - 1] > A[p]) {
			LL t = money / A[cur];
			money -= t * A[cur];
			money += t * A[p - 1];
			cur = p;
		}
		p++;
	}
	cout << money << "\n";
	return 0;
}

Measured memory_bytes: 3192
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			if i == j {
				continue
			}
			if s[i] == s[j] {
				for k := 0; k < 4; k++ {
					if k == i || k == j {
						continue
					}
					l := 6 - i - j - k
					if s[i] != s[k] && s[k] == s[l] {
						fmt.Println("Yes")
						return
					}
				}
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n,m; cin >> n >> m;
  vector<pii> key(m);
  rep(i,m) {
    int a,b; cin >> a >> b;
    int s = 0;
    rep(j,b) {
      int c; cin >> c;
      c--;
      s |= (1 << c);
    }
    key[i] = mp(s,a);
  }
  vi dp((1<<n),1e9);
  dp[0] = 0;
  rep(bit,(1<<n)) rep(j,m) {
    int s = key[j].first;
    int cost = key[j].second;
    chmin(dp[bit|s],dp[bit] + cost);
  }

  int ans = dp.back();
  if(ans == 1e9) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
	#print(name)
	sys.stdin = open(name)

from math import factorial

def combinations_count(n,r):
    if n < r:
        return 0
    else:
        return factorial(n) // ( factorial(n-r) * factorial(r))

n,m = map(int,input().split())

#print(combinations_count(n,2))
#print(combinations_count(m,2))

#print(factorial(0))

print(combinations_count(n,2) + combinations_count(m,2))






Measured memory_bytes: 9188
N = int(input())
ABC = [[0] * 3 for i in range(N)]
for i in range(N):
    ABC[i][0], ABC[i][1] = list(map(int, input().split()))
    ABC[i][2] = - (ABC[i][0] + ABC[i][1])

ABC.sort(key=lambda x:x[2])

taka = 0
aoki = 0
for i in range(N):
    if i % 2 == 0:
        taka += ABC[i][0]
    else:
        aoki += ABC[i][1]

print(taka - aoki)


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;






ll solve(ll cap, vector<vector<ll>> a) {
    vector<ll> dp(cap+1, 0);
    iota(dp.begin(), dp.end(), 0);

    for (int i=1; i<=cap; i++) {
	for (auto item: a) {
	    ll weight = item[0];
	    ll reward = item[1];
	    if (i-weight>=0) {
		dp[i] = max(dp[i], reward+dp[i-weight]);
	    }
	}
    }
    return dp[cap];
}


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


    ll n;
    ll ga,sa,ba;
    ll gb,sb,bb;

    cin>>n;
    cin>>ga>>sa>>ba;
    cin>>gb>>sb>>bb;

    n = solve(n, {{ga,gb},{sa,sb},{ba,bb}});
    n = solve(n, {{gb,ga},{sb,sa},{bb,ba}});
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 198344
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        /*
        int reader = int.Parse(ReadLine());
        long[] ryuka = new long[reader+1];
        ryuka[0] = 2;
        ryuka[1] = 1;
        for(int i=2;i<=reader;i++){
            ryuka[i] = ryuka[i-1]+ryuka[i-2];
        }
        WriteLine(ryuka[reader]);*/
        string reader = ReadLine();
        string a = "abcdefghijklmnopqrstuvwxyz";
        int k = a.IndexOf(reader);
        WriteLine(a[k+1]);
    }
}


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

int	main(void)
{
	string str;
	cin >> str;

	for (int i = 0; i < 3; i++)
	{
		if (str[i] == '7')
		{
			cout << "Yes" << endl;
			return (0);
		}
	}

	cout << "No" << endl;
	return (0);
}

Measured memory_bytes: 3584
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)

	flg := true
	for _, v := range n[1:] {
		if v != '9' {
			flg = false
			break
		}
	}

	if len(n) == 1 {
		fmt.Println(n)
		return
	}

	sumDigits := int(n[0]-'0') + 9*(len(n)-1)
	if !flg {
		sumDigits--
	}
	fmt.Println(sumDigits)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  string s("CODEFESTIVAL2016");
  string a;
  cin>>a;
  int ans=0;
  for(int i=0;i<(int)s.size();i++)
    if(s[i]!=a[i]) ans++;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
using namespace std;

int main(){
    string S;
    cin >> S;
    for(int i=1; i<S.length(); i++)if(S[i]==S[i-1]){
        cout << "Bad" << endl;
        return 0;
    }
    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000.0


int main(){
    
	int N,M;
	cin>>N>>M;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		E[a].push_back(b);
	}
	
	vector<double> dp(N,0.0);
	
	for(int i=N-2;i>=0;i--){
		for(int j=0;j<E[i].size();j++){
			dp[i] += (dp[E[i][j]]+1.0)/E[i].size();
		}
	}
	double ans = dp[0];
	for(int i=0;i<N-1;i++){
		int ind = -1;
		double maxi=0.0;
		if(E[i].size()==1)continue;
		for(int j=0;j<E[i].size();j++){
			if(dp[E[i][j]]>maxi){
				maxi=dp[E[i][j]];
				ind=j;
			}
		}
		
		int to = E[i][ind];
		E[i].erase(E[i].begin()+ind);
		
		vector<double> dp2(N,0.0);
		for(int i=N-2;i>=0;i--){
			for(int j=0;j<E[i].size();j++){
				dp2[i] += (dp2[E[i][j]]+1.0)/E[i].size();
			}
		}
		ans = min(ans,dp2[0]);
		
		E[i].push_back(to);
	}
	
	cout<<fixed<<setprecision(15)<<ans<<endl;
		
	
	
	
    return 0;
}



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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace IntModulo
{
	const int mod = 1e9 + 7;

	inline int add(int x, int y, int m = mod)
	{
		if (x + y < m)
			return x + y;
		return x + y - m;
	}

	inline int sub(int x, int y, int m = mod)
	{
		if (x >= y)
			return x - y;
		return x - y + m;
	}

	inline int mult(int x, int y, int m = mod)
	{
		return x * (LL) y % m;
	}

	inline int power(int x, LL y, int m = mod)
	{
		int r = 1;
		while(y)
		{
			if (y & 1)
				r = mult(r, x, m);
			x = mult(x, x, m);
			y >>= 1;
		}
		
		return r;
	}
	
	inline int inverse(int x, int m = mod)
	{
		return power(x, m - 2, m);
	}

	inline void ADD(int& x, int y, int m = mod){
		x += y;
		if (x >= m) x -= m;
	}

	inline void SUB(int& x, int y, int m = mod){
		x -= y;
		if (x < 0) x += m;
	}

	inline void MULT(int& x, int y, int m = mod){
		x = (x * (LL) y) % m;
	}
};

using namespace IntModulo;

const int N = 1 << 20;
int dp[N][2][2];
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n; cin >> n;
	dp[0][0][0] = 1;
	FOR(i, 0, n){
		FOR(j, 0, 2) FOR(k, 0, 2) FOR(t, 0, 10){
			ADD(dp[i + 1][j | (t == 0)][k | (t == 9)], dp[i][j][k]);
		}
	}

	cout << dp[n][1][1] << endl;	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;	
	return 0;
}


Measured memory_bytes: 19372
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    while(cin>>a>>b>>c){
        if(a == b && a == c){
            cout<<"No\n";
        }
        else if(a != b && a != c && b != c){
            cout<<"No\n";
        }
        else{
            cout<<"Yes\n";
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    string str;
    cin >> str;
    sort(str.begin(), str.end());
    for (int i = 0; i < str.length() - 1; i++)
        if (str[i] == str[i + 1])
        {
            cout << "no";
            return 0;
        }
    cout << "yes";
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
signed main(){
  int n;
  cin>>n;
  string ans;
  n%=10;
  if(n==3){
    ans="bon";
  }else if(n==0||n==1|n==6||n==8){
    ans="pon";
  }else{
    ans="hon";
  }

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


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

int main(){
    int N;
    scanf("%d%*c",&N);
    char *s = (char *)malloc(11 * N * sizeof(char));
    char *ms = s;
    fgets(s,11*N,stdin);
    unsigned long int max = 0;
    unsigned long int sum = 0;
    for(int i = 0;i < N; i++){
        int n;
        unsigned long int a;
        int j = 0;
        for(j = 0; j < 11; j++){
            if(s[j] == ' '){
                
                s[j] = '\0';
                break;
            }
        }
        a = (unsigned long int)atoi(s);
        if(max > a){
            sum += max - a;
        }else
        {
            max = a;
        }
        if(i<N-1)
        s = &s[j+1];
    }
    free(ms);
    printf("%ld\n",sum);
    return 0;
}

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

using namespace std;

int main(){
	string str;
	int i,count=0;

	cin>>str;
	for(i=0;i<str.length();i++){
		if(str[i] == '1'){
			count++;
		}
	}
	cout<<count<<endl;
	
	

	return 0;
}

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

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<vector<int>> A(1000, vector<int>(3));
  int c = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        A.at(c).at(0) = i;
        A.at(c).at(1) = j;
        A.at(c).at(2) = k;
        c++;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    int k = 0;
    for (int j = 0; j < N; j++) {
      if (ctoi(S.at(j)) == A.at(i).at(k)) {
        k++;
      }
      if (k == 3) {
        break;
      }
    }
    if (k == 3) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll n_ints, stack_numb;
vl numbers;
vl dp_start_wins;


bool active_wins(ll curr_numb){
    if(dp_start_wins[curr_numb] < 0){
        return false;
    } else if(dp_start_wins[curr_numb] > 0){
        return true;
    }
    for(auto take_numb : numbers){
        if(curr_numb-take_numb >= 0 && ! active_wins(curr_numb - take_numb)){
            dp_start_wins[curr_numb] = 10;
            return true;
        }
    }

    dp_start_wins[curr_numb] = -100;
    return false;
}

int main() {

    cin >> n_ints >> stack_numb;
    numbers.resize(n_ints);
    dp_start_wins.assign(stack_numb+10, 0);
    FOR(i, 0, n_ints){
        cin >> numbers[i];
    }
    sort(all(numbers), greater<int>());

    if(n_ints == 1 && numbers[0] == 1){
        if(stack_numb%2 == 1){
            cout << "First" << endl;
        }
        else{
            cout << "Second" << endl;
        }
        return 0;
    }
    if(active_wins(stack_numb)){
        cout << "First" << endl;
    }
    else{
        cout << "Second" << endl;
    }

    return 0;
}



Measured memory_bytes: 1024
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def power(x, y, p):
    res = 1  # Initialize result

    x = x % p  # Update x if it is
    # more than or equal to p

    while (y > 0):

        # If y is odd,
        # multiply x with result
        if (y & 1):
            res = (res * x) % p

            # y must be even now
        y = y >> 1  # y = y/2
        x = (x * x) % p

    return res
def ncr(n, r, p):
    # initialize numerator
    # and denominator
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
            p - 2, p)) % p

n,a,b = MAP()

print(int((power(2, n, mod)-1-ncr(n, a, mod)-ncr(n, b, mod))%mod))

# print(ncr(10**9,10**5 ,10**9+7))

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

int main(){
    int n;
    cin >> n;
    int64_t count[110000];
    for(int64_t i=0; i<110000; i++){
        count[i] = 0;
    }
    int64_t sum = 0;
    for(int64_t i=0; i<n; i++){
        int64_t a;
        cin >> a;
        count[a]++;
        sum += a;
    }

    int64_t q;
    cin >> q;
    for(int64_t i=0; i<q; i++){
        int64_t b, c;
        cin >> b >> c;
        int64_t tmp = count[b];
        sum -= (b*count[b]);
        sum += (c*count[b]);
        count[c] += tmp;
        count[b] = 0;
        cout << sum << endl;
    }


    return 0;
}

Measured memory_bytes: 4532
program TMPC2020B
    implicit none
    integer(8)A,V,B,W,T
    read*,A,V,B,W,T
    if(B>A)then
        if(B+T*W>A+T*V)then
            print'(A)',"NO"
        else
            print'(A)',"YES"
        end if
    else
        if(B-T*W<A-T*V)then
            print'(A)',"NO"
        else
            print'(A)',"YES"
        end if
    end if
end program TMPC2020B

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
char s[1005];
bool v[5];

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='N') v[1]=1;
		if(s[i]=='S') v[2]=1;
		if(s[i]=='W') v[3]=1;
		if(s[i]=='E') v[4]=1;
	}
	if((v[3]^v[4])||(v[1]^v[2])) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
# AtCoder
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A)
k = sorted(c.most_common(), reverse=True, key=lambda x: x[1])[K:]

ans = 0
for e in k:
    ans += e[1]
print(ans)


Measured memory_bytes: 40880
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

func toInt(str string) int {
    n, _ := strconv.Atoi(str)
    return n
}

func abs(a int) int {
    return int(math.Abs(float64(a)))
}

func main() {
    wh := strings.Split(readLine(), " ")
    w := toInt(wh[0])
    h := toInt(wh[1])
    readLine()
    pString := strings.Split(readLine(), " ")
    var x1 [300]int
    var y1 [300]int
    var x2 [300]int
    var y2 [300]int
    cnt := 0
    for i := 0; i <= w - 1; i++ {
        x1[cnt] = i
        y1[cnt] = 0
        cnt ++
    }
    for i := 1; i <= h - 1; i++ {
        x1[cnt] = w - 1
        y1[cnt] = i
        cnt ++
    }

    for i := w - 2;i >= 0; i-- {
        x1[cnt] = i
        y1[cnt] = h - 1
        cnt ++
    }
    cnt = 0
    for i := 0; i <= w - 2; i++ {
        x2[cnt] = i
        y2[cnt] = 1
        cnt ++
    }
    for i := 2; i <= h - 2; i++ {
        x2[cnt] = w - 2
        y2[cnt] = i
        cnt ++
    }

    for i := w - 3;i >= 0; i-- {
        x2[cnt] = i
        y2[cnt] = h - 2
        cnt ++
    }

    pos1 := 0
    pos2 := 0
    ans := 0
    for _, value := range pString {
        p := toInt(value)
        if p == 0 {
            pos1 ++
        } else {
            pos2 ++
        }
        px1, py1 := x1[pos1], y1[pos1]
        px2, py2 := x2[pos2], y2[pos2]
        if abs(px1 - px2) + abs(py1 - py2) == 1 {
            ans ++
        }
    }
    fmt.Println(ans)
}


Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>

#define MX 105

using namespace std;

int w, h, a[MX][MX];
int xdir[6] = {0, 1, 1, 1, 0, -1};
int ydir[6] = {-1, -1, 0, 1, 1, 0};
int xdir2[6] = {-1, 0, 1, 0, -1, -1};
int ydir2[6] = {-1, -1, 0, 1, 1, 0};

int dfs(int x, int y)
{
  int cnt = 0, dy, dx;
  a[y][x] = -1;

  for(int i = 0; i < 6; ++i){
    if(y%2){dy=y+ydir[i]; dx=x+xdir[i];}
    else {dy=y+ydir2[i]; dx=x+xdir2[i];}

    if(0 <= dy && dy < h+2 && 0 <= dx && dx < w+2){
      if(a[dy][dx] == 0){
       cnt += dfs(dx, dy);
      } else if(a[dy][dx] == 1){
       ++cnt;
      }
    }
  }

  return cnt;
}

int main()
{
  while(cin>>w>>h && w+h){
    fill(&a[0][0], &a[MX][0], 0);
    for(int i = 1; i <= h; ++i)
      for(int j = 1; j <= w; ++j) cin >> a[i][j];

    cout << dfs(0, 0) << endl;
  }

  return 0;
}

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

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

using namespace std;

int main(){
  int x,a,b;
  cin>>x;
  cin>>a;
  cin>>b;
  
  cout<<x-a-b*((x-a)/b);
  
  return 0;
}


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

using namespace std;

using ll=long long;

ll dp[5];

void solve() {
    int n; cin >> n;
    for (int _ = 0; _ < n; _++) {
        int x; cin >> x;
        int k = (x&1);
        dp[4] = min(dp[4] + x, dp[3] + x);
        if(x)dp[3] = min(dp[3] + k, dp[2] + k);
        else dp[3] = min(dp[3] + 2, dp[2] + 2);
        dp[2] = min(dp[2] + (k^1), dp[1] + (k^1));
        if(x)dp[1] = min(dp[1] + k, dp[0] + k);
        else dp[1] = min(dp[1] + 2, dp[0] + 2);
        dp[0] = dp[0] + x;
        for (int i = 1; i < 5; i++) {
            dp[i] = min(dp[i], dp[i-1]);
        }
        //for (int i = 0; i < 5; i++) {
        //    cout << dp[i] << ' ';
        //}cout << "\n";
    }
    ll res = 1ll<<60;
    for (int i = 0; i < 5; i++) {
        res = min(res, dp[i]);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

vector<int> x(100010);
vector<int> y(100010);

vector<vector<int>> tree;

void dfs1(int n,int p, int dis) {
	x[n] = dis;
	for (auto i : tree[n]) {
		if (i != p) {
			dfs1(i, n, dis + 1);
		}
	}
}

void dfs2(int n, int p, int dis) {
	y[n] = dis;
	for (auto i : tree[n]) {
		if (i != p) {
			dfs2(i, n, dis + 1);
		}
	}
}

int main() {
	ll n, u, v;
	cin >> n >> u >> v;
	u--; v--;
	tree.assign(n, vector<int>());
	vector<ll> a(n - 1), b(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		tree[a[i]].push_back(b[i]);
		tree[b[i]].push_back(a[i]);
	}
	dfs1(u, -1, 0);
	dfs2(v, -1, 0);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (x[i] < y[i]) {
			ans = max(ans, y[i] - 1);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11904
#include <stdio.h>
#include<string.h>
int a[2];
char b[2][20],c[20];
int main()
{
    scanf("%s%s",b[0],b[1]);
    getchar();
    scanf("%d%d",&a[0],&a[1]);
    getchar();
    scanf("%s",c);
    if(strcmp(c,b[0])==0)a[0]--;
      else a[1]--;
      printf("%d %d",a[0],a[1]);


}


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

int main()
{
  string S; cin >> S;
  int res = 0;
  int n = S.size();
  if(n%2 == 0)
    rep(i,n/2)
    {
      if(S.at(i) != S.at(n-i-1)) res++;
    }
  else
    rep(i,n/2+1)
    {
      if(S.at(i) != S.at(n-i-1)) res++;
    }
  cout << res << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())
A=[0]+list(map(int,input().split()))+[-1]

"""
org_A=A[1:N]

judge=True
for item in org_A:
    if item!=0:
        judge=False
        break
if judge:
    print(N*(N+1)//2)
    exit()
"""

ans=0

wa10=A[1]
wa2=A[1]
front=1
end=0
count=0
while front!=N+1 or end!=N:
    #print(front,end)
    #print(wa10,wa2)
    temp=front-end-1
    if wa10==wa2 and front!=N+1:
        ans+=temp
        front+=1
        wa10+=A[front]
        wa2^=A[front]

    else:
        end+=1
        count=0
        wa10-=A[end]
        wa2^=A[end]
    #print(ans)
    #print("----------------")
print(ans+N)

Measured memory_bytes: 24584
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<vector>
#include<math.h>
using namespace std;


int main() {

	int n;
	cin >> n;
	vector<double> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	while (v.size() > 1) {
		v[0] = (v[0] + v[1]) / 2;
		v.erase(v.begin() + 1);
	}

	cout << v[0] << endl;


	return 0;
}



Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-14 20:58:26
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int k; cin >> k;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  debug(v.size());

  cout << v[k - 1] << endl;  

  return 0;
}

Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding


	int n;
	cin>>n;
	std::vector<ll> a(n),b(n);

	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}

	sort(all(a));
	sort(all(b));

	ll ret ;
	if(n%2==1){
		ret = b[n/2]-a[n/2]+1;		
	}else{
		ret = b[n / 2 - 1]+b[n/2]-(a[n/2-1]+a[n/2])+1;
	}
	cout<<ret<<endl;

	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 6392