akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll h, w, m, ans = 0, a, b;
  cin >> h >> w >> m;
  vector<ll> cnth(h, 0), cntw(w, 0);
  set<pair<ll, ll>> bom;
  rep(i, m) {
    cin >> a >> b;
    a--, b--;
    cnth[a]++, cntw[b]++;
    bom.insert({a, b});
  }
  ll mxh = 0, mxw = 0;
  rep(i, h) mxh = max(mxh, cnth[i]);
  rep(i, w) mxw = max(mxw, cntw[i]);
  vector<ll> idxh, idxw;
  rep(i, h) if (cnth[i] == mxh) idxh.push_back(i);
  rep(i, w) if (cntw[i] == mxw) idxw.push_back(i);

  ans = mxh + mxw;

  rep(i, idxh.size()) rep(j, idxw.size()) if (bom.count({idxh[i], idxw[j]}) == 0) {
    cout << ans << endl;
    return 0;
  }

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


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

using namespace std;

int main(int argc, char *argv[]) {
    int64_t X;
    cin >> X;
    vector<int64_t> plus5 = vector<int64_t>(1000 + 1, 0);
    vector<int64_t> minus5 = vector<int64_t>(1000 + 1, 0);
    for (int i = 0; i <= 1000; i++) {
        int64_t ff = pow(i, 5);
        plus5[i] = ff;
        minus5[i] = ff * -1;
    }

    for (int j = 0; j <= 1000; j++) {
        for (int k = 0; k <= 1000; k++) {
            int64_t one1 = plus5[j]; 
            int64_t one2 = minus5[j]; 
            int64_t other1 = plus5[k];
            int64_t other2 = minus5[k];
            if ((one1 - other1) == X) {
                cout << j << " " << k << endl;
                return 0;
            }
            if ((one1 - other2) == X) {
                cout << j << " " << k * -1 << endl;
                return 0;
            }
            if ((one2 - other1) == X) {
                cout << j * -1 << " " << k << endl;
                return 0;
            }
            if ((one2 - other2) == X) {
                cout << j * -1 << " " << k * -1 << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4120
#include<stdio.h>
#define MAX 100000
int A[MAX],n;
int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

int main(){
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i==q){
      printf("[");
      printf("%d",A[i]);
    }
    if(i==q){
      printf("]");
      if(i!=n-1){
        printf(" ");
      }
    }
    else if(i==n-1){
      printf("%d",A[i]);
    }
    else{
      printf("%d ",A[i]);
    }
  }
  printf("\n");
  return 0;
}


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

typedef long long ll;

using namespace std;

int main()
{
  int n;
  cin >> n;
  ll st, sa;
  cin >> st >> sa;
  for(int i = 0; i < n - 1; i++) {
    ll t, a;
    cin >> t >> a;
    ll et = sa % a == 0 ? sa * t / a : (sa + a - sa % a) / a * t;
    ll ea = st % t == 0 ? st * a / t : (st + t - st % t) / t * a;
    if(et > st) {
      st = et;
      sa = sa % a == 0 ? sa : (sa + a - sa % a);
    } else {
      sa = ea;
      st = st % t == 0 ? st : (st + t - st % t);
    }
  }
  cout << sa + st << endl;
}

Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n, m = MII()
    aa = [IS() for _ in range(n)]
    bb = [IS() for _ in range(m)]
    for i in range(n-m+1):
        for j in range(n-m+1):
            for k in range(m):
                if aa[i+k][j:j+m] != bb[k][:]: break
            else: print('Yes'); exit()
    print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

long long N;
long long arr[105];
long long sum = 0;

int main() {
	
	for(int i = 0; i < 3; i++) {
		scanf("%lld", &arr[i]);
	}
	sort(arr, arr + 3);

	for(int i = 0; i < 2; i++) {
		sum += abs(arr[i] - arr[i + 1]);
	}
	printf("%lld\n", sum);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};


//考察
//下から順に引っ張る
//N*Nまでいける
//木
//lca
//dp


int main(void){
  int Q; cin >> Q;
  rep(i, Q){
    ll A, B; cin >> A >> B;
    if(A > B) swap(A, B);
    if(A == B){
      cout << 2 * A - 2 << endl;
      continue;
    }
    if(A+1 == B){
      cout << 2 * A - 2 << endl;
      continue;
    }
    ll C = sqrt(A * B);
    if(C * C == A * B) C--;
    if(C * (C + 1) >= A * B){
      cout << 2 * C - 2 << endl;
      continue;
    }
    cout << 2 * C - 1 << endl;
  }
}


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

using namespace std;

// int dfs(int v, vector<vector<int>> A, vector<int> visit, int &count)
// {
//     bool all_flag = 1;

//     for (int i = 0; i < visit.size(); i++)
//     {

//         if (visit[i] == 0)
//         {
//             all_flag = 0;
//         }
//     }

//     if (all_flag == 1)
//     {
//         //count++;
//         return 1;
//     }

//     int mas=0;

//     for (int w : A[v])
//     {
//         if (visit[w] == 0)
//         {
      
//             visit[w] = 1;
//             mas+=dfs(w, A, visit, count);
//             visit[w] = 0;
//         }
//     }

//     return mas;
// }

// int main()
// {
//     int N, M;
//     cin >> N >> M;

//     vector<vector<int>> A(N, vector<int>(0));

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

//         int a, b;
//         cin >> a >> b;

//         A[a - 1].push_back(b - 1);
//         A[b - 1].push_back(a - 1);
//     }

//     vector<int> visit(N, 0);

//     visit[0] = 1;

//     int count = 0;
//     count =dfs(0, A, visit, count);

//     cout << count << endl;
//     return 0;
// }


const int nmax=8;
bool graph[nmax][nmax];

 int dfs(int v,int N,bool visited[nmax]){

 bool all_visited=true;

 for(int i=0;i<N;++i){
 if(visited[i]==false)
 all_visited=false;
 }

 if(all_visited){
 return 1;
 }


 int ret=0;

 for(int i=0;i<N;++i){
 if(graph[v][i]==false) continue;
 if(visited[i]) continue;

 visited[i]=true;
 ret+=dfs(i,N,visited);
 visited[i]=false;
 }

 return ret;
 }

 int main(void){
 int N,M;
 cin >> N >> M;

 for(int i=0;i<M;++i){
 int A,B;
 cin >> A >> B;
 graph[A-1][B-1]=graph[B-1][A-1]=true;
 }

 bool visited[nmax];
 for(int i=0;i<N;++i){
 visited[i]=false;
 }

 visited[0]=true;
 cout << dfs(0,N,visited) << endl;
 return 0;
 }

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

using namespace std;
 
typedef long long ll;


int main(){
    int n, m;
    cin >> n >> m;

    vector<pair<ll, ll>> a;
    for(int i = 0; i < n; i++)
    {
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        a.push_back(make_pair(tmp1, tmp2));        
    }

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

    ll totalcnt = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        if (m <= totalcnt + a[i].second){
            ans += (m - totalcnt)*a[i].first;
            break;
        } else {
            ans += a[i].second*a[i].first;
            totalcnt += a[i].second;
        }
        //printf("%d %d en %d  num %d\n", i, ans, a[i].first, a[i].second);
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 2420
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/abc160/tasks/abc160_a

S = input()
print('Yes' if S[2] == S[3] and S[4] == S[5] else 'No')


Measured memory_bytes: 3316
#include <stdio.h>
#include <algorithm>
#include <climits>

long long input[200010];
long long dp[3][200010];
bool check[3][200010];
int n;

long long func(int left, int x) {
	if (x > n) {
		if (left <= 1)
			return 0;
		return LLONG_MIN / 2;
	}
	if (check[left][x] == true)
		return dp[left][x];

	check[left][x] = true;
	dp[left][x] = func(left, x + 2) + input[x];

	if (left > 0) {
		dp[left][x] = std::max(dp[left][x], func(left - 1, x + 1));
	}

	return dp[left][x];
}

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

	for (int i = 1; i <= n; i++)
		scanf("%lld", input + i);

	if (n % 2 == 0)
		printf("%lld\n", func(1, 1));
	else
		printf("%lld\n", func(2, 1));
}

Measured memory_bytes: 13244
ary = gets.chomp.split("").map(&:to_i)
ans = 10000 
(0..(ary.length-3)).each do |n|
    tem= "#{ary[n]}#{ary[n+1]}#{ary[n+2]}"
    temabs = (tem.to_i - 753).abs 
      if ans > temabs
          ans = temabs
      end
end
p ans

Measured memory_bytes: 1916
S = input()
if 'N' in S and 'S' not in S:
    print('No')
elif 'S' in S and 'N' not in S:
    print('No')
elif 'E' in S and 'W' not in S:
    print('No')
elif 'W' in S and 'E' not in S:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 2940
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int C = cin.nextInt();
        long[] ar = new long[N];
        for (int i = 0; i < N; i++)
        {
            int s = cin.nextInt();
            long t = cin.nextInt();
            long c = cin.nextInt();
            ar[i] = (c << 40) + (t << 20) + (s);
        }
        Array.Sort(ar);
        int T = 220000;
        int[] imos = new int[T];

        int pres = 0;
        int pret = 0;
        int prec = -1;
        for (int i = 0; i < N; i++)
        {
            int c = (int)(ar[i] >> 40);
            int t = (int)((ar[i] >> 20) & 0xFFFFF);
            int s = (int)((ar[i] >> 0) & 0xFFFFF);

            if(c == prec && pret == s)
            {
                pret = t;
            }
            else
            {
                if (prec != -1)
                {
                    imos[pres * 2] += 1;
                    imos[pret * 2 + 1] -= 1;
                }
                pres = s;
                pret = t;
                prec = c;
            }
        }

        imos[pres * 2] += 1;
        imos[pret * 2 + 1] -= 1;

        int ans = 0;
        int now = 0;
        for (int i = 0; i < T; i++)
        {
            now += imos[i];
            ans = Math.Max(now, ans);
        }
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 16840
N = int(input())
h = list(map(int, input().split()))
    
inf = 10**9
dp = [0] + [inf]*N
    
for i in range(1,N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    
print(dp[N-1])

Measured memory_bytes: 20600
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod
            
    def comb(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

MOD = 1000000007
K = int(input())
S = len(input())
F = Factorial(K + S + 1, MOD)
res = 0
for i in range(S, K + S + 1):
    res += F.comb(K + S, i) * pow(25, K + S - i, MOD)
    res %= MOD
print(res)

Measured memory_bytes: 185472
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        String t = scan.next();
        scan.close();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != t.charAt(i)) {
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }
}


Measured memory_bytes: 35692
def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = [0] * (10 ** 5)
    for a in A:
        C[a] += 1
    ans = 0
    for i in range(1, len(C) - 1):
        ans = max(ans, C[i - 1] + C[i] + C[i + 1])
    print(ans)


main()


Measured memory_bytes: 13964
#include <iostream>

using namespace std;
 
int main()
{
    int s1[5],s2[5];
 
    while (true) {
	cin >> s1[0] >> s2[0];
	if (!s1[0] && !s2[0]) break;
 
	int max = s1[0] + s2[0], num = 1;
	for (int i = 1; i < 5; i++) {
	    cin >> s1[i] >> s2[i];
	    if (max < s1[i]+s2[i]) {
		max = s1[i] + s2[i];
		num = i + 1;
	    }
	}
	
	switch(num){
            case 1:
                cout << 'A';
                break;
            case 2:
                cout << 'B';
                break;
            case 3:
                cout << 'C';
                break;
            case 4:
                cout << 'D';
                break;
            case 5: 
                cout << 'E';
                break;
	}
	cout << ' ' << max << endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using LP = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

int mod = 1e9+7;

int INF = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> prev(3);
  rep(_, N){
    vector<int> tmp_h(3);
    rep(i, 3) cin >> tmp_h[i];

    vector<int> next_h(3);
    rep(i, 3){
      rep(j, 3){
        if(i==j) continue;
        next_h[i] = max(next_h[i], prev[j] + tmp_h[i]);
      }
    }
    prev = next_h;
  }

  int ans = 0;
  rep(i, 3){
    ans = max(ans, prev[i]);
  }

  cout << ans << endl;


  return 0;
}


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

typedef pair<int,int> pi;

int main() {
	// your code goes here
	int n, m, d, r;
	cin>>n>>m;
	vector<pi> v;
	for(int i=0; i<n; i++)
	{
	    cin>>d>>r;
	    v.push_back(make_pair(r, d));
	}
	sort(v.begin(), v.end(), greater<pi>());
	int count = 0;
	set<int>s;
	for(int i=0; i<=m; i++)
	    s.insert(i);
	long long ans = 0;
	for(int i=0; i<v.size(); i++)
	{
	    int val = m - v[i].second;
	    if(s.upper_bound(val) == s.begin())
	        continue;
	    int temp = *prev(s.upper_bound(val));
	    s.erase(temp);
	    ans += v[i].first;
	}
	cout<<ans;
}


Measured memory_bytes: 5748
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define VI vector<int>
#define VII vector<pair<int, int>>
#define PII pair<int, int>
#define MP make_pair
// #define log(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define log(fmt, ...)
// #define check(...) assert(##__VA_ARGS__)
#define check(...)

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

    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    x = int(input())
    n5 = np.array([i**5 for i in range(-201, 201)])
    diff = np.subtract.outer(n5, n5)
    r = np.where(diff == x)
    # assert (r[0][0] - 201)**5 - (r[1][0] - 201)**5 == x
    print(r[0][0]-201, r[1][0]-201)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27684
#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve(){
  string s;
  cin>>s;
  int sum= 0;
  for(char ch: s){
    sum+=(ch-'0');
  }

  if(sum%9 == 0){
      cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
signed main(){
  // int t;
  // cin>>t;
  // while(t--)
    solve();
}


Measured memory_bytes: 3724
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  a,b,c,d=LI()

  s=''
  for i in range(c-a):
    s+='R'
  for i in range(d-b):
    s+='U'

  for i in range(c-a):
    s+='L'
  for i in range(d-b):
    s+='D'

  s+='D'
  for i in range(c-a):
    s+='R'
  s+='R'
  for i in range(d-b):
    s+='U'
  s+='UL'

  s+='U'
  for i in range(c-a):
    s+='L'
  s+='L'
  for i in range(d-b):
    s+='D'
  s+='DR'

  return s

print(main())


Measured memory_bytes: 7960
using System;
using System.Collections.Generic;
using System.Linq;
using static Common;

public static class Common
{
    public static void CountAdd<T>(this Dictionary<T, long> dict, T key, long v)
    {
        if (dict.ContainsKey(key))
        {
            dict[key] += v;
        }
        else
        {
            dict[key] = v;
        }
    }

    public static void Increment<T>(this Dictionary<T, long> dict, T key)
    {
        dict.CountAdd(key, 1);
    }

    public static void Decrement<T>(this Dictionary<T, long> dict, T key)
    {
        dict.CountAdd(key, -1);
    }

    public static long Get<T>(this Dictionary<T, long> dict, T key)
    {
        long count = 0;
        dict.TryGetValue(key, out count);
        return count;
    }
}

public class Agent
{
    public long High;
    public int Index;

    public Agent(long high, int index)
    {
        High = high;
        Index = index;
    }
}

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        // Ai + i ==  j - Bj
        long count = 0;
        var rights = A.Select((b, j) => j - b).ToArray();
        var lefts = new Dictionary<long, long>();
        for (int i = 0; i < N; i++)
        {
            var r = rights[i];
            count += lefts.Get(r);
            lefts.Increment(A[i] + i);
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 59888
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
av_temp = []
for i in range(n):
    av_temp.append(t-h[i]*0.006)
preTmp = 100000
for i in range(n):
    tmp = abs(av_temp[i]-a)
    if tmp < preTmp:
        preTmp = tmp
        ans = i+1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int k=n;
  rep(i,n){
    if(i<n-1&&s[i]==s[i+1]){k--;}}
  cout<<k<<endl;
}

Measured memory_bytes: 512
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s, t = rsl()
print(t + s)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int i = 1;
                do{
                        int x = i;
                        if(x%3==0){
                                System.out.print(" "+ i);
                                continue;
                        }
                        do{
                                if(x%10==3){
                                        System.out.print(" "+ i);
                                        break;
                                }
                                x/=10;
                       }while(x!=0);
                }while(++i<=n);
                System.out.println();
        }
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A==1){
    A=14;
  }
  if(B==1){
    B=14;
  }
  if(A>B){
    cout << "Alice" << endl;
  }
  else if(A==B){
    cout << "Draw" << endl;
  }
  else if(A<B){
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b;
    cin >> a >>b;
    cout << a*b << endl;
}

Measured memory_bytes: 3620
require 'set'
N, M = gets.split.map(&:to_i)
EDGES = Hash.new{|h,k| h[k] = Set[]}
readlines.each do |l|
  a, b = l.split.map(&:to_i)
  EDGES[a] << b
  EDGES[b] << a
end

def solve(a, visited)
  (EDGES[a] - visited).map{|b|
    new_v = visited + Set[b]
    if new_v.size == N
      1
    else
      solve(b, new_v)
    end
  }.inject(0, :+)
end

p solve(1, Set[1])


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

// 最大公約数 : 3,4 ->  1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数 : 3,4 -> 12
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void solve()
{
  int n, a;
  cin >> n;
  ll ans = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> a;
    ans += a - 1;
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

string s;

signed main()
{
  int score = 0;
  
  cin >> s;

  for(auto p:s){
    if(p == 'p'){
      score--;
    }
  }

  score += s.size() / 2;

  cout << score << endl;
  return 0;
}


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

int main(){
    int a,b,c,d,e,f;
    cin >>a>>b>>c>>d>>e>>f;
    vector<int> water,sugar;
    for(int i=0; i*a*100<=f; i++){
        for(int j=0; i*a*100 +j*b*100 <=f; j++){
            water.push_back(i*a*100 +j*b*100);
        }
    }
    for(int i=0; i*c<=f; i++){
        for(int j=0; i*c+j*d<=f; j++){
            sugar.push_back(i*c+j*d);
        }
    }
    sort(water.begin(), water.end());
    water.erase(unique(water.begin(), water.end()), water.end());
    sort(sugar.begin(), sugar.end());
    sugar.erase(unique(sugar.begin(), sugar.end()), sugar.end());

    double dens = 0, limit = (double)e/(100+e);
    int anst = a*100, anss = 0;
    for(int i=0; i<(int)water.size(); i++){
        for(int j=sugar.size(); j>=0; j--){
            double tmp = (double)sugar[j]/(water[i]+sugar[j]);
            if(water[i]+sugar[j]>f || tmp>limit) continue;
            if(dens < tmp){
                dens = tmp;
                anst = water[i]+sugar[j];
                anss = sugar[j];
            }
        }
    }
    cout << anst << " " << anss << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long A, B, C;
  cin >> A >> B >> C;
  long maximum = max(A, max(B, C));
  long anssum = maximum * 3;
  long currentsum = A + B + C;
  if (anssum % 2 != currentsum % 2) anssum += 3;
  cout << (anssum - currentsum) / 2 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<D,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
vector<P>g[1005];
int n;
D xs,ys,xt,yt;
D x[1005],y[1005],r[1005],d[1005];
int main(void){
    cin>>xs>>ys>>xt>>yt>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>y[i]>>r[i];
        g[0].PB(P(max(D(0),sqrt((xs-x[i])*(xs-x[i])+(ys-y[i])*(ys-y[i]))-r[i]),i));
        g[i].PB(P(max(D(0),sqrt((xt-x[i])*(xt-x[i])+(yt-y[i])*(yt-y[i]))-r[i]),n+1));
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            g[i].PB(P(max(D(0),sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]))-r[i]-r[j]),j));
            g[j].PB(P(max(D(0),sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]))-r[i]-r[j]),i));
        }
    }
    for(int i=1;i<=n+1;i++)d[i]=10000000000;
    priority_queue<P,vector<P>,greater<P> >dik;
    dik.push(P(0,0));
    while(!dik.empty()){
        int v=dik.top().S;
        D c=dik.top().F;
        dik.pop();
        if(c>d[v])continue;
        for(int i=0;i<g[v].size();i++){
            int u=g[v][i].S;
            D l=g[v][i].F;
            if(d[u]>c+l){
                d[u]=c+l;
                dik.push(P(c+l,u));
            }
        }
    }
    printf("%.10lf\n",min(d[n+1],sqrt((xs-xt)*(xs-xt)+(ys-yt)*(ys-yt))));
}


Measured memory_bytes: 22384
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep(i,n-1)cin >> c[i];
    int sum=0;
    rep(i,n){
        sum+=b[a[i]-1];
        if(i<n-1&&a[i]+1==a[i+1])sum+=c[a[i]-1];
    }
    cout << sum << endl;
    return 0;
}

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

void  ExtendedEuclid(int a, int b) {
  int r0 = a, r1 = b;
  int x0 = 1, x1 = 0;
  int y0 = 0, y1 = 1;
  int q, r2, x2, y2;

  while(r1 != 0) {
    q = r0 / r1;
    r2 = r0 % r1;
    x2 = x0 - q * x1;
    y2 = y0 - q * y1;
    r0 = r1;
    r1 = r2;
    x0 = x1;
    x1 = x2;
    y0 = y1;
    y1 = y2;
  }
  cout << x0 << " " << y0 << endl;
}

int main() {
  int a, b;
  cin >> a >> b;
  ExtendedEuclid(a, b);
  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
    
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
    
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
    
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
    
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
    string S;
    cin >> S;

    LL s = 0;
    LL del = 0;

    REP(i, S.size()) {
        if(S[i] == 'S') {
            s++;
        } else if(s > 0) {
            s--;
            del += 2;
        }
    }

    cout << S.size() - del << endl;
}

Measured memory_bytes: 640
n, a, b = map(int, input().split())
ans = 0
ans += (n //(a + b)) * a
# print(ans)
val =  n - ((a + b) * (n // (a + b)))

# print(val)
if val <= a:
    ans += n - ((a + b) * (n // (a + b)))
else:
    ans += a
# print(ans * (n // (a + b)))
print(ans)

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

using namespace std;

int main(void){
    // Your code here
    int N; string S;
    int i;
    long r=0,g=0,b=0;
    int x=0,y=0,z=0;

    cin >> N >> S;

    for(i=0;i<N;i++){
        if(S.at(i)=='R')r++;
        if(S.at(i)=='G')g++;
        if(S.at(i)=='B')b++;   
    }

    long long all = r*g*b;

    for(x=0;x<N-2;++x){
        for(y=x+1;y<N-1;++y){
            z=y*2-x;
            if(z>N-1||S.at(x)==S.at(z)||S.at(y)==S.at(z)||S.at(x)==S.at(y))continue;
            all--;
        }
    }


    cout << all << endl;
}


Measured memory_bytes: 3596
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;

#define MAX_V 1000

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void initialize(int v){
	V = v;
	for(int i = 0; i < v; ++i){
		G[i].clear();
	}
}

void add_edge(int u, int v){
	G[u].push_back(v);
	G[v].push_back(u);
}

bool dfs(int v){
	used[v] = true;
	for(int i = 0; i < G[v].size(); ++i){
		int u = G[v][i], w = match[u];
		if( w < 0 || !used[w] && dfs(w) ){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching(){
	int res = 0;
	memset(match, -1, sizeof(match));
	for(int v = 0; v < V; ++v){
		if( match[v] < 0 ){
			memset(used, 0, sizeof(used));
			if( dfs(v)){
				++res;
			}
		}
	}
	return res;
}

int gcd(int a, int b){
	while(b){
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(){
	int m, n;
	int b[500], r[500];
	while( scanf("%d%d", &m, &n), m != 0 ){
		for(int i = 0; i < m; ++i){
			scanf("%d", &b[i]);
		}
		for(int i = 0; i < n; ++i){
			scanf("%d", &r[i]);
		}

		initialize(m + n);
		for(int i = 0; i < m; ++i)
		for(int j = 0; j < n; ++j){
			if( gcd(b[i], r[j]) > 1 ){
				add_edge(i, j + m);
			}
		}
		
		printf("%d\n", bipartite_matching());
	}
}

Measured memory_bytes: 3116
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	l := nextLine()
	strs := strings.Split(l, " ")
	res :=int64(0)
	for _, v := range strs {
		x, _ := strconv.ParseInt(v, 10, 0)
		res = res + x
	}
	if res >= 22 {
		fmt.Println("bust")
	} else {
		fmt.Println("win")
	}
}


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

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

	long long array[n+1];
	array[0] = 2;
	array[1] = 1;

	for (int i = 2; i <= n; i++)
	{
		array[i] = array[i-1] + array[i-2];
	}

	cout << array[n];
	return 0;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

const int N = 3005;

int A[N], B[N];
int dp[N][N][2];
int n;

int sol(int idx, int w, int f) {
    if(w < 0) return -1e9;
    if(idx == n || w == 0) return 0;

    int &ret = dp[idx][w][f];

    if(ret != -1) return ret;

    if(!f) ret = sol(idx + 1, w - 1, 1) + B[idx];
    ret = max(ret, sol(idx + 1, w, f));
    return ret = max(ret, sol(idx + 1, w - A[idx], f) + B[idx]);
}

int main(){
    fIO

    int t;
    cin >> n >> t;

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

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

    cout << sol(0, t, 0);
}








Measured memory_bytes: 71040
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    string s;
    cin >> s;

    if (s[0] == s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0; 
}


Measured memory_bytes: 256
N = int(input())
X = []
p = 0
for i in range(N):
    X.append(tuple([int(n) for n in input().split()]))
a = sorted(X)
while p<len(a)-1:
    if a[p][0]+a[p][1] > a[p+1][0]+a[p+1][1]:
        a.pop(p)
    elif  a[p][0]+a[p][1] > a[p+1][0]-a[p+1][1]:
        a.pop(p+1)
    else:
        p += 1
print(len(a))


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

int main() {
    int a, b, c;
    cin >>a >>b >>c;
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
    if (b - a == c - b) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

int main(){
    int a,b;
    char op;
    while(cin >> a >> op >> b,op != '?'){
        cout << (op=='+'?a+b : op=='-'?a-b : op=='*'?a*b : a/b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int sum1[1010];
int sum2[1010];
int X[1010];
bool judge = true;
vector<int> G[1010];

void dfs(int v){
    
    int ok[2][5010] = {};
    ok[0][0] = true;
    int sum = 0;
    for(int i = 0; i < G[v].size(); i++){
        int u = G[v][i];
        dfs(u);
        sum += sum1[u] + sum2[u];
        for(int j = 0; j <= 5000; j++){
            if(ok[i & 1][j]){
                if(j + sum1[u] <= 5000) ok[(i + 1) & 1][j + sum1[u]] = true;
                if(j + sum2[u] <= 5000) ok[(i + 1) & 1][j + sum2[u]] = true;
            }
            ok[i & 1][j] = false;
        }
    }
    int mx = -1;
    int id = (int)G[v].size() & 1;
    for(int j = 0; j <= X[v]; j++){
        if(ok[id][j]) mx = j;
    }
    if(mx == -1) judge = false;
    sum1[v] = X[v], sum2[v] = sum - mx;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 2; i <= N; i++){
        int p;
        cin >> p;
        G[p].push_back(i);
    }
    for(int i = 1; i <= N; i++){
        cin >> X[i];
    }
    dfs(1);
    cout << (judge ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}

Measured memory_bytes: 17280
from collections import defaultdict
N, Ma, Mb = map(int, input().split())
INF, MAX = 1000000000, 10 * N + 1
dp = defaultdict(lambda : INF)
dp[(0, 0)] = 0
for i in range(N):
    a, b, c = map(int, input().split())
    predp = dp.copy()
    for ab, v in predp.items():
        _a, _b = ab
        dp[(_a+a, _b+b)] = min(dp[(_a+a, _b+b)], v+c)
ans = INF
for i in range(1, N+1):
    ans = min(ans, dp[(Ma*i, Mb*i)])
ans = -1 if ans == INF else ans
print(ans)


Measured memory_bytes: 10836
#include<iostream>
#include<vector>
#include<math.h>

std::vector<std::vector<std::pair<int,bool>>> A(20);     

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

    for(int i = 0; i < n; i++){
        int nra;
        std::cin >> nra;
        for(int j = 0; j < nra; j++){
            int x, y;
            std::cin >> x >> y;
            if(y == 1){
                A[i].push_back(std::make_pair(x-1,1));
            }
            else{
                A[i].push_back(std::make_pair(x-1, 0));
            }
        }
    }
        
    int sol = 0;
        
    for(int k = 0; k < (1 << n); k++){
        std::vector<bool> pos(n);
        int cnt = 0;
        int current = k;
        for(int i = 0; i < n; i++){
            pos[i] = (current&1);
            current = current >> 1;
            if(pos[i]){
                cnt++;
            }
        }

        bool ok = 1;
        for(int i = 0; i < n; i++){
            if(pos[i]){
                for(int j = 0; j < A[i].size(); j++){
                    if(pos[A[i][j].first] ^ A[i][j].second){
                        ok = 0;
                    }
                }
            }
        }
        if(ok){
            if(cnt > sol){
                sol = cnt;
            }
        }
    }

    std::cout << sol;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
int main(){
    int N,K; cin >> N >> K;
    string S; cin >> S;
    
    vector<int> num;
    int now = 1;
    int cnt = 0;

    rep(i,N){
        if(S[i] == (char)('0' + now)) cnt++;
        else{
            num.push_back(cnt);
            now ^= 1;
            cnt = 1;
        }
    }
    if(cnt != 0) num.push_back(cnt);

    if(num.size() % 2 == 0) num.push_back(0);

    vector<int> sum(num.size() + 1);
    for(int i = 0; i<num.size(); i++){
        sum[i+1] = sum[i] + num[i];
    }

    int ans = 0;
    for(int i = 0; i < num.size(); i+=2){
        int left = i;
        int right = min(i+K+K+1,(int)num.size());
        int tmp = sum[right] - sum[left];
        ans = max(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1272
#include<stdio.h>

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

    n = N%10;

    if(n==2||n==4||n==5||n==7||n==9){
        printf("hon");
    }else if(n==0||n==1||n==6||n==8){
        printf("pon");
    }else{
        printf("bon");
    }

    return 0;
}

Measured memory_bytes: 1704
S = list(input())
flag = True

if len(S) % 2 == 0:
  for i in range(0, len(S), 2):
    if S[i] == 'h' and S[i + 1] == 'i':
      pass
    else:
      flag = not flag
      break
else:
  flag = not flag

if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = null;
		for (;;) {
			try {
				input = br.readLine();
			} catch (IOException e) {
			}
			String[] inputs = input.split(" ");
			int H = Integer.parseInt(inputs[0]);
			int W = Integer.parseInt(inputs[1]);
			if (H == 0 && W == 0) {
				break;
			}
			for (int i = 1; i <= H; i++) {
				for (int j = 1; j <= W; j++) {
				    if ((i + j) % 2 == 0) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
					// printlnは改行して表示。printは横並びに書いていく
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}


Measured memory_bytes: 31080
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
    int a[4];
    REP(i,4)
        scanf("%d",a + i);

    int sum = 0;
    REP(i,4)
        sum += a[i];

    printf("%d\n%d\n",sum / 60,sum %  60);
    return 0;
}

Measured memory_bytes: 3232
#include <iostream>

#include <vector>

#include <algorithm>

#include <set>

#include <queue>

#include <stack>

#include <string>

#include <map>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>



using namespace std;



int main(void){

    int n;

    while (cin >> n, n) {

        vector<pair<double, string> > list;

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

            string l;

            int p, a, b, c, d, e, f, s, m;

            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;

            double cost = (-1.0)*(m*s*f-p)/((a+b+c)+m*(d+e));

            list.push_back(make_pair(cost, l));

        }

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

        for (int i = 0; i < list.size(); i++) {

            cout << list[i].second << endl;

        }

        cout << "#" << endl;

    }



	return 0;

}

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> s(N);
    for (int i = 0; i < N; i++)
        std::cin >> s[i];

    long long ans = 0;
    for (int c = 1; c < N; c++) {
        long long res = 0;
        int i = 0, j = N - 1;
        if ((N - 1) % c) {
            while (j > c) {
                res += s[i] + s[j];
                ans = std::max(ans, res);
                i += c;
                j -= c;
            }
        }
        else {
            while (i < j) {
                res += s[i] + s[j];
                ans = std::max(ans, res);
                i += c;
                j -= c;
            }
        }
    }
    std::cout << ans << "\n";
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

typedef long long ll;

const int N = 405, M = N * N, dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};

int n, m, fa[M], cb[M], cw[M];
char s[N][N];
ll ans;

int which(int x, int y)
{
	return (x - 1) * m + y;
}

int cx(int x)
{
	if (fa[x] != x) fa[x] = cx(fa[x]);
	return fa[x];
}

void zm(int x, int y)
{
	int ix = cx(x), iy = cx(y);
	if (ix != iy) fa[iy] = ix,
		cb[ix] += cb[iy], cw[ix] += cw[iy];
}

int main()
{
	std::cin >> n >> m;
	for (int i = 1; i <= n; i++)
		scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			int x = which(i, j);
			fa[x] = x;
			(s[i][j] == '#' ? cb[x] : cw[x]) = 1;
		}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			if (s[i][j] == '.') continue;
			for (int k = 0; k < 4; k++)
			{
				int x = i + dx[k], y = j + dy[k];
				if (x < 1 || x > n || y < 1 || y > m || s[x][y] == '#')
					continue;
				zm(which(i, j), which(x, y));
			}
		}
	for (int i = 1; i <= n * m; i++)
		if (fa[i] == i) ans += 1ll * cb[i] * cw[i];
	std::cout << ans << std::endl;
	return 0;
}

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

using namespace std;

int main(int argc,char* argv[]){
	int A, B, C;
	int safe;
	cin >> A >> B >> C;

	safe = A+B;

	if(safe+1 >= C) safe = B+C;
	else safe += (B+1);

	cout << safe << endl;
	return 0;
}

Measured memory_bytes: 256