akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <math.h>
#include <string.h>
#include <map>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#define INF 1000000
#define MAX 500000
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;
typedef vector <ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
vector <vi> adj(MAX);
vi col;
 ll n;
 vi dfs_num,dfs_parent,dfs_low,vertex;
int dfsnumcnt=0,dfsRoot,rootChildren=0;
void apoint(int u)
{
  dfs_num[u]=dfs_low[u]=dfsnumcnt++;
  for(ll i=0;i<adj[u].size();i++)
  {
    ll v=adj[u][i];
    if(dfs_num[v]==INF)
    {
      dfs_parent[v]=u;
      if(u==dfsRoot) rootChildren++;
      apoint(v);
      if(dfs_low[v]>=dfs_num[u])
        vertex[u]=1;
      dfs_low[u]=min(dfs_low[u],dfs_low[v]);
    }
    else if(v!=dfs_parent[u])
    dfs_low[u]=min(dfs_low[u],dfs_num[v]);
 }
}
int main()
{
  // freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ll n,m=1000000007;
cin>>n;
ll sum=1;
for(ll i=1;i<=n;i++)
{
sum=(sum*i)%m;
}
cout<<sum<<endl;
return 0;
}

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

#define LEN 25000
 int main(){
  char ascii[LEN];
  int i, len, det;
  int sum = 0, alt = 0, pl = 0, stk = 0;
  int height[LEN] = {0}, ex[LEN] = {0};

  scanf("%s", ascii);
  for(len=0; strlen(ascii); len++){
    height[len] = alt;
    if(ascii[len] == '/'){
      alt++;
    }
    if(ascii[len] == '\\'){
      alt--;
    }
    if(ascii[len] == '\0'){
      break;
    }
  }

  while(pl < len){
    while(ascii[pl] != '\\' && pl < len){
      pl++;
    }
    det = pl+1;
    while(det <= len && height[det] != height[pl]){
      det++;
    }
    if(det <= len){
      ex[stk++] = Area(ascii, len, pl, det);
      pl = det;
    }else{
      pl++;
    }
  }

  for(i=0; i<stk; i++){
    sum += ex[i];
  }

  printf("%d\n%d", sum, stk);

  for(i=0; i<stk; i++){
    printf(" %d", ex[i]);
  }
  printf("\n");

  return 0;
}
int Area(char* ascii, int len, int p, int q){
  int depth = 0, i;
  double b = 0;

  for(i=p; i<q; i++){
    if(ascii[i] == '/'){
      b += (double)depth - 0.5;
      depth--;
    }
    if(ascii[i] == '\\'){
      b += (double)depth + 0.5;
      depth++;
    }
    if(ascii[i] == '_'){
      b += depth;
    }
  }
  return b;
}

Measured memory_bytes: 772
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
using namespace std;
#define i64  long long
//  #define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007

struct Point{double x,y;};

void koch(int n,Point a,Point b)
{
  if(n==0)return;
  double th = M_PI*60.0/180.0;
  Point s,t,u;
  s.x = (2.0*a.x + 1.0*b.x)/3;
  s.y = (2.0*a.y + 1.0*b.y)/3;
  t.x = (1.0*a.x + 2.0*b.x)/3;
  t.y = (1.0*a.y + 2.0*b.y)/3;
  u.x = (t.x - s.x)*cos(th) - (t.y -s.y)*sin(th) + s.x;
  u.y = (t.x - s.x)*sin(th) + (t.y -s.y)*cos(th) + s.y;

  koch(n-1,a,s);
  cout<<s.x<<" "<<s.y<<endl;
  koch(n-1,s,u);
  cout<<u.x<<" "<<u.y<<endl;
  koch(n-1,u,t);
  cout<<t.x<<" "<<t.y<<endl;
  koch(n-1,t,b);
}
void solve()
{
  Point a,b;
  int N;
  cin>>N;
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;
  cout<<a.x<<" "<<a.y<<endl;
  koch(N,a,b);
  cout<<b.x<<" "<<b.y<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(8);

  solve();

 
  return 0;
}


Measured memory_bytes: 3280
<?php
fscanf(STDIN, "%d%d", $N, $K);
fscanf(STDIN, "%d%d%d", $s, $p, $r);
$T = trim(fgets(STDIN));
$counter = array_fill(0, $K, 0);
$last = array_fill(0, $K, "");
$score = 0;
for($i = 0; $i < strlen($T); $i++){
    if($last[$i%$K] == $T[$i]){
        $counter[$i%$K]++;
    }else{
        $counter[$i%$K] = 1;
    }
    $last[$i%$K]=$T[$i];
    if($counter[$i%$K] % 2 == 1){
        $score+=${$T[$i]};
    }
}
echo $score;




Measured memory_bytes: 14840
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0 for _ in range(N)]
    ans = [] 
    for i in range(N, 0, -1):
        cnt = 0
        mul = 2
        while i*mul-1 < N:
            cnt += B[i*mul-1]
            mul += 1
        if A[i-1] == cnt%2:
            B[i-1] = 0
        else:
            B[i-1] = 1
            ans.append(i)
    print(len(ans))
    if len(ans) != 0:
        print(*ans)

    

if '__main__' == __name__:
    resolve()


Measured memory_bytes: 17724
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ods;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

ll dp[22][1<<22];

void solve(ll t)
{
    // cout<<"Case #"<<t<<":\n";
    ll n;
    cin>>n;
    dp[n][0]=1;
    ll a[n][n];
    repf(i,0,n) repf(j,0,n) cin>>a[i][j];
    repb(i,n-1,0)
    {
        repf(j,0,1<<n)
        {
            if(__builtin_popcount(j)!=n-i) continue;
            repf(mask,0,n)
            {
                if((1<<mask)&j && a[i][mask])
                {
                    dp[i][j]=(dp[i][j]+dp[i+1][(1<<mask)^j])%mod;
                }
            }
        }
    }
    ll ans=0;
    // cout<<dp[2][1]<<endl;
    repf(i,0,1<<n) ans=(ans+dp[0][i])%mod;
    cout<<ans<<endl;
}

int main()
{
    IOS;
    ll t;
    // cin>>t;
    t=1;
    ll tt=1;
    while(t--)
    {
        solve(tt);
        tt++;
    }
}     


Measured memory_bytes: 325888
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = 1000000007;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};
vector < ll > v;
ll q , a[55],b[55],c[55],d[55] , n,m, ans = 0;
void dp(ll pos, ll mx){
	if(pos ==  n){
		vector < ll > r = v;
		reverse(r.begin(),r.end());
		ll res= 0;
		//printf("%lld\n",r.size());
		f0(q){
			if(r[b[i]-1] - r[a[i]-1] == c[i]) res += d[i];
		}
		ans = max(res, ans);
		return;
	}
	for(ll i = mx; i >= 1; i--){
		v.pb(i);
		dp(pos+1 , i);
		v.pop_back();
	}
	return;
}

void solve(){
	cin >> n >> m >> q;
	f0(q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	dp(0 , m);
	cout << ans;
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 3620
import sys
import random
from copy import copy
from math import floor

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def write_output(out):
    with open("my_sample2.out", mode="w") as f:
        for x in out:
            f.write(str(x + 1) + "\n")


def main():
    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]

    sat_cur = 0
    last = [1] * 26
    out = [-1] * d

    for day in range(d):
        estimate = [0.0] * 26
        for cid in range(26):
            if s[day][cid] > 16000:
                estimate[cid] = last[cid] * c[cid] + c[cid] ** 1
        cur = estimate.index(max(estimate))
        out[day] = cur
        sat_cur += s[day][cur]
        last[cur] = 1
        for cid in range(26):
            if cid != cur:
                last[cid] += 1
                sat_cur -= last[cid] * c[cid]

    #print(sat_cur)

    num_of_try = 1000
    for i in range(1, num_of_try + 1):
        change_num = floor((num_of_try - i) / 300)
        out_temp = copy(out)
        for j in range(change_num):
            c_day = int(random.triangular(0, 365 - 0.01, 50))
            c_cid = random.randint(0, 25)
            out_temp[c_day] = c_cid

        last = [1] * 26
        sat_temp = 0
        for day in range(d):
            cur = out_temp[day]
            sat_temp += s[day][cur]
            last[cur] = 1
            for cid in range(26):
                if cid != cur:
                    last[cid] += 1
                    sat_temp -= last[cid] * c[cid]
        # print(change_day, change_cid, sat_temp)
        #print(sat_temp)
        if sat_temp > sat_cur:
            out = out_temp
            sat_cur = sat_temp

    for x in out:
        print(x + 1)

    #write_output(out)


if __name__ == '__main__':
    main()


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l;
  cin >> n >> l;
  ll res = 0;
  if(l < 0 && l + n > 0){
    for (int i = 0; i < n; i++) {
      res += l + i;
    }
  } else if(l >= 0){
    for (int i = 1; i < n; i++){
      res += l + i;
    }
  }else{
    for (int i = 0; i < n-1; i++){
      res += l + i;
    }
  }

  cout << res << endl;

}


Measured memory_bytes: 256
input_list = list(map(int, input().split()))
a_list = list(map(int, input().split()))
k = input_list[0]
n = input_list[1]-1

longest = 0
dist = 0
for i in range(n):
    temp_dis = a_list[i+1] - a_list[i]
    if longest < temp_dis:
        longest = temp_dis
    dist += temp_dis
temp_dis_last = k - a_list[n] + a_list[0]
if longest < temp_dis_last:
    longest = temp_dis_last
dist += temp_dis_last

ans = dist - longest
print(ans)

Measured memory_bytes: 78540
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int r, g, b, n; cin >> r >> g >> b >> n;
  int ans = 0;
  REP(i, 3001) REP(j, 3001) {
    int need = n - i * r - j * g;
    if (need < 0) continue;
    if (need % b == 0) {
      // cout << i << ' ' << j << ' ' << need << '\n';
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int main(int argc, char **argv)
{
	string s;
  cin>>s;
  stack <char> stacky;
  for(ll i=0;i<s.size();i++){
    if (s[i]=='1'||s[i]=='0') stacky.push(s[i]);
    else if (s[i]=='B'){
      if (!stacky.empty()) stacky.pop();
    }
    }
  string ans="";
  while (!(stacky.empty())){
    ans+=stacky.top();
    stacky.pop();
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<"\n";
  
	return 0;
}


Measured memory_bytes: 3588
N,K = map(int,input().split())
a_list = list(map(int,input().split()))

# 建物iをミられる高さにするかいなかのbit探索

ans = 100010001000100010001000

for byte in range(pow(2,N-1)):
    height = a_list[0]
    cost = 0
    if bin(byte).count("1")>=K-1:
        for i in range(N-1):
            if not (byte & 1<<i)==0: # i番目を見る場合
                cost += max(0, height + 1 - a_list[i+1])
                height = max(height + 1, a_list[i+1])
            else:
                height = max(height,a_list[i+1])
        ans = min(ans,cost)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    for(int i=0;i<n;i++){
        int b;
        cin >> b;
        a.push_back(b);
    }

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

    int min=a.at(0)+1;
    int atk=0;
    int tmp=a.at(0);
    while(tmp<min){
        min=tmp;    
        for(int i=0;i<a.size();i++){
            if(a.at(i)==0) continue;
            if(i!=atk){
                a.at(i)=a.at(i)%min;
                if(0<a.at(i) && a.at(i)<min){
                    atk=i;
                    tmp=a.at(i);
                    break;
                }
            }
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
void judge(int &ac, int &wa, int &tle, int &re){
    string s;
    cin >> s;
    if (s == "AC"){
        ac += 1;
    }
    else if (s == "WA"){
        wa += 1;
    }
    else if (s == "TLE"){
        tle += 1;
    }
    else if (s == "RE"){
        re += 1;
    }
}

int main(){
    int n, ac, wa, tle, re;
    cin >> n;
    ac = 0;
    wa = 0;
    tle = 0;
    re = 0;
    
    for (int i=0; i<n; i++){
        judge(ac, wa, tle, re);
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}


Measured memory_bytes: 3564
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

//
// セグメント木
//
type segTree []int

const segTreeDefault = 0

// マージ関数
func (s *segTree) segMerge(a, b int) int {
	return a + b
}

func segTreeInit(N int) segTree {
	size := 1
	for N > size {
		size <<= 1
	}
	s := make(segTree, size*2)
	for i := 0; i < size*2; i++ {
		s[i] = segTreeDefault
	}
	s[0] = 0
	return s
}

func (s *segTree) set(i, pos int) {
	N := len(*s)/2 + pos
	(*s)[N] = i
	for N > 1 {
		N /= 2
		(*s)[N] = s.segMerge((*s)[2*N], (*s)[2*N+1])
	}
}

func (s *segTree) setAll(a []int, n int) {
	N := len(*s) / 2
	for i := 0; i < n; i++ {
		(*s)[N+i] = a[i]
	}
	for N > 1 {
		N >>= 1
		for i := 0; i < N; i++ {
			pos := N + i
			(*s)[pos] = s.segMerge((*s)[2*pos], (*s)[2*pos+1])
		}
	}
}

func (s *segTree) querySub(l, r, index, L, R int) int {
	if R <= l || r <= L {
		return segTreeDefault
	}
	if l <= L && R <= r {
		return (*s)[index]
	}
	med := (L + R) / 2
	lval := s.querySub(l, r, index*2, L, med)
	rval := s.querySub(l, r, index*2+1, med, R)
	return s.segMerge(lval, rval)
}

// queryの区間は[l, r)です
func (s *segTree) query(l, r int) int {
	return (*s).querySub(l, r, 1, 0, len(*s)/2)
}

/*
	seg := segTreeInit(N)

	seg.setAll(a, N)
	seg.set(val, pos)
	seg.query(l, r) // [L, R)
*/

var seg segTree

func initPrime(N int) {
	n := make([]int, N+1)
	seg = segTreeInit(N + 1)

	n[1] = 1
	for i := 2; i*i <= N; i++ {
		for j := i * 2; j <= N; j += i {
			n[j] = i
		}
	}

	for i := 1; i <= N; i++ {
		if n[i] == 0 {
			p := (i + 1) / 2
			if n[p] == 0 {
				seg.set(1, i)
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	initPrime(100100)

	Q := getInt()
	for i := 0; i < Q; i++ {
		l, r := getInt(), getInt()
		fmt.Fprintln(w, seg.query(l, r+1))
	}
}


Measured memory_bytes: 5760
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break

    mf = m + f
    if m == -1 or f == -1:
        print("F")
    elif 80 <= mf:
        print("A")
    elif 65 <= mf < 80:
        print("B")
    elif 50 <= mf < 65:
        print("C")
    elif 30 <= mf < 50:
        if 50 <= r:
            print("C")
        else:
            print("D")
    elif mf < 30:
        print("F")




Measured memory_bytes: 5596
import java.util.*;
public class Main {

   public static void main(String[] args) {
        
      int a,b,c,sum;
  	Scanner scan=new Scanner(System.in); 
    String s=scan.nextLine(); 
    String[] str=s.split(" ");
    a = Integer.parseInt(str[0]);
    b = Integer.parseInt(str[1]);
    c = Integer.parseInt(str[2]);
     sum = a + b + c;
     if(sum>=22)
     {
       System.out.println("bust");
     }
     else 
     {
       System.out.println("win");
     }
   }
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

const double PI=acos(-1);

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point& operator+=(Point p){
		x+=p.x,y+=p.y;
		return *this;
	}
	Point& operator-=(Point p){
		x-=p.x,y-=p.y;
		return *this;
	}
	Point& operator*=(double c){
		x*=c,y*=c;
		return *this;
	}
	Point& operator/=(double c){
		x/=c,y/=c;
		return *this;
	}
};
Point operator+(Point a,Point b){
	return a+=b;
}
Point operator-(Point a,Point b){
	return a-=b;
}
Point operator*(Point a,double c){
	return a*=c;
}
Point operator*(double c,Point a){
	return a*=c;
}
Point operator/(Point a,double c){
	return a/=c;
}
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return !(a==b);
}

Point Rot(Point p,double t){
	return Point(cos(t)*p.x-sin(t)*p.y,sin(t)*p.x+cos(t)*p.y);
}

ostream& operator<<(ostream& os,const Point& p){
	return os<<'('<<p.x<<','<<p.y<<')';
}

int main()
{
	for(int n,d;cin>>n>>d && n|d;){
		vi ls(n),rs(n),ts(n);
		rep(i,n) cin>>ls[i]>>rs[i]>>ts[i];
		
		Point pos(0,0),dir(0,1);
		rep(i,n){
			double l=ls[i]/360.*2*PI*ts[i],r=rs[i]/360.*2*PI*ts[i];
			Point pl,pr;
			if(l==r){
				pl=Point(-d,l);
				pr=Point(d,r);
			}
			else if(l==0){
				pl=Point(-d,l);
				pr=Point(-d,0)+Rot(Point(2*d,0),r/(2*d));
			}
			else if(r==0){
				pl=Point(d,0)+Rot(Point(-2*d,0),-l/(2*d));
				pr=Point(d,r);
			}
			else{
				double xc=(l+r)/(l-r)*d;
				double th=r/(d-xc);
				pl=Point(xc,0)+Rot(Point(-d-xc,0),th);
				pr=Point(xc,0)+Rot(Point(+d-xc,0),th);
			}
			Point pc=(pl+pr)/2;
			pos+=Rot(pc,atan2(-dir.x,dir.y));
			dir=Rot(dir,atan2((pr-pc).y,(pr-pc).x));
		}
		printf("%.5f\n",pos.x);
		printf("%.5f\n",pos.y);
	}
}

Measured memory_bytes: 1300
func readThreeInts(separator: String.Element = " ") -> (a: Int, b: Int, c: Int) {
    let ints = readLine()!.split(separator: separator).map { Int($0)! }
    return (a: ints[0], b: ints[1], c: ints[2])
}

func readInts(separator: String.Element = " ") -> [Int] {
    return readLine()!.split(separator: separator).map { Int($0)! }
}

func mainC() {
    let (N, M, K) = readThreeInts()
    let A = readInts()
    let B = readInts()

    // Nまでの和を出しておく、forの中でreduceをやるとo(n^2)で間に合わない
    var a = [0]
    for i in 0..<N {
        a.append(a[i] + A[i])
    }

    var b = [0]
    for i in 0..<M {
        b.append(b[i] + B[i])
    }

    var answer = 0
    var j = M
    for i in 0...N {
        if a[i] > K { break }

        while b[j] > K - a[i] {
            j -= 1
        }

        answer = max(answer, i + j)
    }

    print(answer)
}

mainC()

Measured memory_bytes: 25980
def seek(n, s):
    s = s.rstrip('#').lstrip('.')
    turn_to_black = s.count('.')
    current_min = turn_to_black
    turn_to_white = 0

    if current_min == 0 or current_min == len(s):
        return 0

    # seek minimum turns to create "^\.*#*$"
    for i in range(len(s)):
        if s[i] == '#':
            turn_to_white += 1
        else:
            turn_to_black -= 1
        current_min = min(current_min, turn_to_black + turn_to_white)
    return current_min


def input_from_console():
    n = int(input())
    s = input()
    return n, s


def main():
    n, s = input_from_console()
    print(seek(n, s))
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def solve_iter(hi, wi):
        vec = [(0,1),(0,-1),(1,0),(-1,0)]
        for v in vec:
            hn = hi + v[0]
            wn = wi + v[1]
            if hn >= 0 and hn < H and wn >= 0 and wn < W:
                if NLIST[hn][wn] == '#' or NLIST[hn][wn] == '*':
                    NLIST[hi][wi] = '*'
                    NLIST[hn][wn] = '*'
                    #solve_iter(hn, wn)
        return

    H,W = map(int, lines.pop(0).split(' '))
    NLIST = []
    for i in range(H):
        NLIST.append(list(lines.pop(0)) )

    res = 'Yes'
    for i in range(H):
        for j in range(W):
            if NLIST[i][j] == '#':
                solve_iter(i, j)
            if NLIST[i][j] == '#':
                res = 'No'

    print(res)

#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for d in range(0,a+1):
    for e in range(0,b+1):
        for f in range(0,c+1):
            if ((500 * d) + (100 * e) + (50 * f)) == x:
                count += 1
print(count)

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(3*N);
    rep(i, 3*N) cin >> A[i];

    priority_queue<int, vector<int>, greater<int>> L;
    vector<ll> sumL(3*N+1);
    sumL[0] = 0;
    rep(i, 3*N) {
        ll res = 0;
        L.push(A[i]);
        if (L.size() <= N) {
            res = sumL[i] + A[i];
        } else {
            res = sumL[i] + A[i] - L.top();
            L.pop();
        }
        sumL[i + 1] = res;
    }

    priority_queue<int> R;
    vector<ll> sumR(3*N+1);
    sumR[3*N] = 0;
    repr(i, 3*N) {
        ll res = 0;
        R.push(A[i]);
        if (R.size() <= N) {
            res = sumR[i+1] + A[i];
        } else {
            res = sumR[i+1] + A[i] - R.top();
            R.pop();
        }
        sumR[i] = res;        
    }

    ll ans = -(ll)INF * INF;
    for (int i = N; i <= 2*N; ++i) {
        ans = max(ans, sumL[i] - sumR[i]);
    }

    cout << ans << endl;
}

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

int N;
int A[210];         // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    // 操作が行える限り操作を繰り返す
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;
}

Measured memory_bytes: 3632
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = Integer.parseInt(sc.next());
		HashSet<String> reg = new HashSet<String>();
		for (int i = 0; i < N; ++i) {
			reg.add(sc.next());
		}
		int M = sc.nextInt();
		boolean open = false;
		for (int i = 0; i < M; ++i) {
			String id = sc.next();
			if (reg.contains(id)) {
				System.out.println((open ? "Closed" : "Opened") + " by " + id);
				open = !open;
			} else {
				System.out.println("Unknown " + id);
			}
		}
	}

}

Measured memory_bytes: 20756
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int a, b; cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;

    cin >> N;

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

    vector<ll> sums(N);
    sums[N-1] = array[N-1];
    for(int i = N-2; i >= 0; i-- ){
        sums[i] = (sums[i+1]+array[i])%MOD;
    }

    ll ans = 0;
    for(int i = 0; i < N-1; i++ ){
        ans += (sums[i+1]*array[i])%MOD;
        ans = ans%MOD;
    }

    cout << ans << endl;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
//---------------------------------------------------------------
int main(){
  ll N;
  cin>>N;
  vector<ll> a(N,0);
  llrep(i,N-1){
    ll A;
    cin>>A;
    a.at(A-1)++;
  }


  llrep(i,N){
    cout<<a.at(i)<<" ";
  }

}


Measured memory_bytes: 4800
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

const int N=100005;

int n,m,cnt,last[N],dep[N],deg[N];
bool vis[N];
struct edge{int to,next;}e[N*2];

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
}

void dfs1(int x,int fa)
{
	vis[x]=1;
	dep[x]=dep[fa]+1;
	for (int i=last[x];i;i=e[i].next)
		if (!vis[e[i].to]) dfs1(e[i].to,x);
		else if (e[i].to!=fa&&dep[e[i].to]>dep[x]) deg[x]^=1,printf("%d %d\n",x,e[i].to);
}

void dfs2(int x,int fa)
{
	vis[x]=1;
	for (int i=last[x];i;i=e[i].next)
		if (!vis[e[i].to]) dfs2(e[i].to,x);
	if (!fa) return;
	if (deg[x]) deg[x]^=1,printf("%d %d\n",x,fa);
	else deg[fa]^=1,printf("%d %d\n",fa,x);
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		addedge(x,y);
	}
	if (m&1) {puts("-1");return 0;}
	dfs1(1,0);
	memset(vis,0,sizeof(vis));
	dfs2(1,0);
	return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0){cout<<(b-a)/2;return 0;}
    cout<<(b-a+1)/2+min(a-1,n-b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1e9
int n;
int a[111111],b[111111];
vector<int>v[111111];
int f[111111],s[111111];
int F,S;
queue<int>q;
signed main(){
	cin>>n;
	rep(i,n-1){
		cin>>a[i]>>b[i];
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	fill(f,f+n+1,INF);
	f[1]=0;
	q.push(1);
	while(!q.empty()){
		int t=q.front();
		q.pop();
		for(int i:v[t]){
			if(f[i]>f[t]+1){
				f[i]=f[t]+1;
				q.push(i);
			}
		}
	}
	fill(s,s+n+1,INF);
	s[n]=0;
	q.push(n);
	while(!q.empty()){
		int t=q.front();
		q.pop();
		for(int i:v[t]){
			if(s[i]>s[t]+1){
				s[i]=s[t]+1;
				q.push(i);
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(f[i]<=s[i])F++;
		else S++;
	}
	if(F>S)puts("Fennec");
	else puts("Snuke");
	return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, r[110000], q;
string s;

int main() {
	cin >> n >> q;
	cin >> s;
	REP(i, n - 1) {
		if (s[i] == 'A' and s[i + 1] == 'C')r[i + 2]++;
	}
	REP(i, n)r[i + 1] += r[i];
	REP(i, q) {
		ll a, b;
		cin >> a >> b;
		cout << r[b] - r[a] << endl;
	}
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    while(true) {
        int n; cin >> n;
        if(n == 0) break;
        int tmp = 1000-n;

        int ans = 0;
        int money[] = {500, 100, 50, 10, 5, 1};
        rep(i, 6) {
            ans += tmp/money[i];
            tmp -= money[i]*(tmp/money[i]);
        }
        cout << ans << '\n';
    }
    return 0;
}


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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
struct POS {
    int x;
    int y;
};
int main(void) {

    ios::sync_with_stdio(false);	cin.tie(0);
    //input & init
    int H, W;  cin >> H >> W;
    char field[20][20];
    int dist[20][20];
    int ans = -1;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)	cin >> field[i][j];

    //solve
    int dx[4] = { -1, 0 , 1, 0 }, dy[4] = { 0, 1, 0, -1 };
    for (int sy = 0; sy < H; sy++) {
        for (int sx = 0; sx < W; sx++) {

            if (field[sy][sx] == '#')  continue;

            //init_dist
            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++)  dist[i][j] = INF;
            dist[sy][sx] = 0;

            //幅優先探索
            queue<POS> que;
            que.push(POS{ sx, sy });
            while (!que.empty()) {
                int x = que.front().x, y = que.front().y;
                for (int i = 0; i < 4; i++) {
                    int nx = x + dx[i], ny = y + dy[i];
                    if (0 <= nx && nx < W && 0 <= ny && ny < H && dist[ny][nx] == INF && field[ny][nx] == '.') {
                        dist[ny][nx] = dist[y][x] + 1;
                        que.push(POS{ nx, ny });
                    }
                }
                que.pop();
            }

            //update_ans
            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++)
                    if (field[i][j] == '.')
                        ans = max(ans, dist[i][j]);
        }
    }

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

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

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define y0 yORZDXM0
#define y1 yORZDXM1
#define y2 yORZDXM2
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;

int n, m, a, b;

int main(){
	scanf("%d%d%d%d", &n, &m, &a, &b);
	FOR(i, 0, n){
		FOR(j, 0, m){
			if(i < b && j < a || i >= b && j >= a) putchar('1');
			else putchar('0');
		}
		puts("");
	}
	return 0;
}



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

int main(){
  int k;
  cin >> k;
  if(k%2==0){
    cout << k*k/4 << endl;
  }else{
    cout << (k+1)/2*(k/2) << endl;
  }
  return 0;
}


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

#define int long long



signed main() {
    string s;
    cin >> s;
    int ans = 700;
    for(int i=0; i<3; i++){
        if(s[i]=='o') ans+=100;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def isPrime(n) : 
    if (n <= 1) : 
        return False
    if (n <= 3) : 
        return True
  
    if (n % 2 == 0 or n % 3 == 0) : 
        return False
  
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
  
    return True

X = int(input())
for i in range(X,10**6):
    if isPrime(i):
        print(i)
        exit()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define round(x, y) ((2 * x + y) / (2 * y))
#define ce(x, y) ((x + y - 1) / y)
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))
 
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
void dfs(int a,int b,int distance,vector<string> &graph,vector<vector<ll>> &dist,queue<pair<int,int>> &qt)
{
    graph[a][b]='#';
    dist[a][b]=distance;
    qt.push(make_pair(a,b));
    if(a>=1&&graph[a-1][b]=='.')
    {
        dfs(a-1,b,distance,graph,dist,qt);
    }
    if(b>=1&&graph[a][b-1]=='.')
    {
        dfs(a,b-1,distance,graph,dist,qt);
    }
    if(a<graph.size()-1&&graph[a+1][b]=='.')
    {
        dfs(a+1,b,distance,graph,dist,qt);
    }
    if(b<graph[0].size()-1&&graph[a][b+1]=='.')
    {
        dfs(a,b+1,distance,graph,dist,qt);
    }
    return ;
}
void solve() {

    ll n,m;
    cin >>n>>m;
    ll s1,s2,d1,d2;
    cin >>s1>>s2;
    cin >>d1>>d2;

    s1-=1;
    s2-=1;
    d1-=1;
    d2-=1;


    vector<string> graph;
    vector<vector<ll>> dist(n);
    for(int i=0;i<n;i++)
    {
        string temp;
        cin >>temp;
        graph.push_back(temp);
        for(int j=0;j<m;j++)
        {
            dist[i].push_back(0);
        }
    }
    queue<pair<int,int>> q;
    q.push(make_pair(s1,s2));
    dist[s1][s2]=0;
    graph[s1][s2]='#';
    int cnt=0;
    while(true)
    {
        queue<pair<int,int>> qt;

        while(!q.empty())
        {
            int a=q.front().first;
            int b=q.front().second;
            q.pop();

            dfs(a,b,cnt,graph,dist,qt);
        }
        while(!qt.empty())
        {
            int c=qt.front().first;
            int d=qt.front().second;
            // cout <<c<<" "<<d<<"\n";
            qt.pop();

            for(int i=-2;i<=2;i++)
            {
                for(int j=-2;j<=2;j++)
                {
                    if(c+i<0||c+i>=n) continue;
                    if(d+j<0||d+j>=m) continue;
                    if(graph[c+i][d+j]=='.')
                    {
                        q.push(make_pair(c+i,d+j));
                        dist[c+i][d+j]=cnt+1;
                        graph[c+i][d+j]='#';
                    }
                }
            }
        }

        if(graph[d1][d2]=='#')
        {
            cout << dist[d1][d2]<<"\n";
            return;
        }
        cnt++;
        if(q.empty()) break;
    }
    cout <<"-1\n";

}

 
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solve();
    return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

template<ll mod>
struct RollingHash{
  vector<ll> hash,p;
  ll base;
  RollingHash(string s, ll b){
    ll n = (ll)s.size();
    base = b;
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(ll i=0;i<n;i++){
      hash[i+1]=(hash[i]*base+s[i])%mod;
      p[i+1]=(p[i]*base)%mod;
    }
  }
  ll get(ll l, ll r){
    ll ret=hash[r+1]-(hash[l]*p[r-l+1])%mod;
    if(ret<0)ret+=mod;
    return ret;
  }
};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  //const ll tmp_mod=608396398;
  //const ll tmp_mod=979418779;
  const ll tmp_mod=775791517;
  using RH = RollingHash<tmp_mod>;
  ll base = 100000;
  ll n;cin>>n;
  string s;cin>>s;
  RH rh(s,base);
  /*auto v=vec(n,n,0LL);
  rep(i,0,n)rep(j,0,n){
    if(i+j<n)v[i][j]=rh.get(i,i+j);
  }*/
  rep(i,0,n-1)rep(j,i+1,n){
    if(s[i]!=s[j])continue;
    ll l=i,r=j;
    while(r-l>=2){
      ll mid=(l+r)/2;
      if(j+mid-i>=n||rh.get(i,mid)!=rh.get(j,j+mid-i)){
        r=mid;
      }
      else l=mid;
    }
    chmax(res,l-i+1);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	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*/
}
void solve(){
	ll n;
	cin>>n;
	vector<vector<pair<int, bool>>> t(n + 1);
	for(int i=1;i<=n;i++){
		ll a;cin>>a;
		for(int j=0;j<a;j++){
			ll x,y;cin>>x>>y;
			t[i].pb({x,y});
		}
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		vi h(n+1,0);
		int c=0;bool ck=true;
		for(int j=0;j<n;j++){
			if((i&(1<<j))){
				c+=1;h[j+1]=1;
			}
		}
		for(int j=1;j<=n;j++){
			for(int k=0;k<(int)t[j].size();k++){
				if(h[j] and h[t[j][k].ff]!=t[j][k].ss){
					ck=false;break;
				}
			}
		}
		if(ck){ans=max(ans,c);}
	}
	cout<<ans;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}

Measured memory_bytes: 3644
#include<stdio.h>

int main(){
  int N,i,j,A[300000]={},count[300000]={};
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(j=0;j<N;j++)
    count[A[j]]++;
  for(j=1;j<N+1;j++)
    printf("%d\n",count[j]);
  
  return 0;
}

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

int main() {
  string A,B,C;
  cin >> A >> B >> C;
  A = A.at(0);
  C = C.at(0);
  char G;
  G = B.at(0);
  cout << A << G << C << endl;
 
}

Measured memory_bytes: 3480
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  int pp[25][25];//左上の末端が(1,1)
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> pp[i][j];
    }
  }
  int ans = 1 << 30;
  int num;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      for(int k = 0; k < H; k++){
	for(int l = 0; l < W; l++){
	  num += pp[k][l] * min(abs(i - k), abs(j - l));
	}
      }
      if(num < ans)ans = num;
      num = 0;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3124
import math
import heapq
from heapq import heapify

N,M= map(int,input().split())
A = list(map(int,input().split()))
heapq._heapify_max(A)

def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    lastelt = heap.pop() 
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

for _ in range(M):
  x = math.floor(_heappop_max(A)/2)
  _heappush_max(A,x)
print(sum(A))

Measured memory_bytes: 14380
S = input()

form = -1
ans = 0
for s in S:
    s = int(s)
    if form == -1:
        form = s
    elif form+s == 1:
        form = s
    else:
        if s == 1:
            form = 0
        else:
            form = 1
        ans += 1
print(ans)

Measured memory_bytes: 3188
#include <cstring>
#include <cstdlib>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define ABS(a) ((a)<0?(-(a)):(a))
#define CS while(cases())
#define I(n) int n = gi()
#define II(n) n = gi()
#define L(n) ll n = gli()
#define LL(n) n = gli()
#define F(i, n) for (int i = 0; i < n; i++)
#define Fa(n, a) for (int i = 0; i < n; i++) a[i] = gi()
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

template<class T>
T gcd(T a, T b) {
    return (b == 0 ? a : gcd(b, a%b));
}

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int cases() {
    static int t = gi();
    return t--;
}

#define MD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x = gli(); x = ABS(x);
    ll k = gli();
    ll d = gli();
    ll h = x/d; h = min(h, k);
    k -= h; x -= h*d;
    if (k%2) x = d-x;
    cout << x << endl;

    return 0;
}


Measured memory_bytes: 3704