akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    for(int i=0;flag;i++){
        flag=0;
        for(int j=N-1;j>=i+1;j--){
            if(A[j]<A[j-1]){
                swap(A[j], A[j-1]);
                flag=1;
                sw++;
            }
        }
    }
    return sw;
}

int main(){
    int A[100], N, sw;
    cin >> N;
    for(int i=0;i<N;i++)cin>>A[i];
    sw=bubbleSort(A,N);
    for(int i=0;i<N;i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <bits/stdc++.h>
#pragma GCC Optimize("Ofast")
using namespace std;
#define ll long long
ll vis[100];

ll solve(ll val, ll n, bool flag)
{
    if(n <= val)
    {
        return val;
    }
    
    ll ans=INT_MAX;
    if(flag)
    {
        for(ll i=1;i<=9;i++)
        {
            if(vis[i]==0)
            {
                ans = min(ans,solve(val*10+i,n,false));
            }
        }
    }
    else{
    for(ll i=0;i<=9;i++){
        if(vis[i]==0)
        {
            ans = min(ans,solve((val*10)+i,n,flag));
        }
    }
        
    }
    return ans;
}



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n,m;
    cin>>n>>m;
    
    string s[n+1];
    
    for(ll i=0;i<n;i++)
        cin>>s[i];
    
    sort(s,s+n);
    for(ll i=0;i<n;i++)
        cout<<s[i];
    
    
    
    
    
   return 0;
}

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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){

  int N, M; cin >> N >> M;
  vector<pair<ll, ll> > AB;

  for(int i = 0; i < N; i++)
  {
     int a, b;
     cin >> a >> b;
     AB.push_back(mp(a,b));
  }
  
  sort(AB.begin(), AB.end());

  ll ans = 0;
  bool flag = true;
  int count = 0;

  while(flag){

    if(M > AB[count].second){
      ans += AB[count].first * AB[count].second;
      M -= AB[count].second;
    }
    else{
      ans += AB[count].first * M;
      flag = false;
    }
    count++;
  }

  pr(ans);

 return 0;

}


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

char next(char c)
{
    if ('a' <= c && c <= 'y') {
        return c+1;
    } else if (c == 'z') {
        return 'a';
    }
    return c;
}

int main()
{
    char str[81];
    while(true) {
        if(!fgets(str,81,stdin)) break;
        for(int j=0;j<26;++j) {
            if (strstr(str, "the") || strstr(str, "this") || strstr(str, "that")) {
                break;
            }
            for(int k=0,len=strlen(str);k<len;++k) {
                str[k] = next(str[k]);
            }
        }
        fputs(str,stdout);
    }
    return 0;
}

Measured memory_bytes: 928
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    int ans = 0;
    int N;
    cin >> N;
    vector<int>a(N);
    cin >> a[0];
    for(int i = 1; i < N; i++){
        cin >> a[i];
        if(a[i] == a[i-1]){
            a[i] = 10000 - ans;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,d=0;
  cin >> A>>B;
  for(A;A<B+1;A++){
  if((A%10==A/10000) && ((A%100)/10==(A%10000)/1000))
        d++;
      }
    cout<<d;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<vector<int>>data(n,vector<int>(n));
    rep(i,n)rep(j,n)data[i][j] = -1;
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int x,y;
            cin >> x >> y;
            x--;
            data[i][x] = y;
        }
    }

    int ans = 0;

    rep(i,(1<<n)){
        vector<int>h(n);
        rep(j,n){
            if((i>>j) & 1)h[j] = 1;
        }
        bool ok = true;
        rep(j,n){
            if(h[j] == 1){
                rep(k,n){
                    if(data[j][k] == -1)continue;
                    if(data[j][k] != h[k])ok = false;
                }
            }
        }
        if(ok)ans = max(ans,__builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}

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

int N,ans;
string x;
struct p{int n,s;};
vector<p> v;

int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}

int f(int a){//長さaのループがX以下に何種類存在するか
  int res=0;
  for(int i=0;i<a;i++) if(x[i]=='1') res+=pw(2,a-i-1),res%=MOD;//桁DPっぽいところ
  //最初a文字がXと完全に一致しているやつがx以下かどうかの判定
  string s,A=x.substr(0,a);
  while(s.size()<N)s+=A;
  for(int i=0;i<s.size();i++) if((i/a)&1) s[i]=(s[i]^'1')+'0';
  //sがx以下かどうか判定する
  for(int i=a;i<N;i++){
    if(x[i]^s[i]) {res+=s[i]^'1';break;}
    res+=(i==N-1);
  }
  return res+(a==N);
}

signed main(){
  cin>>N>>x;
  for(int i=1;i<=N;i++) if(N%i==0&&(N/i)&1) v.push_back({i,f(i)*2});
  for(int i=0;i<v.size();i++){
    ans+=v[i].s*v[i].n;ans%=MOD;
    for(int j=i+1;j<v.size();j++) if(v[j].n%v[i].n==0) v[j].s-=v[i].s;
  }
  if(ans<0)ans+=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 1120
#include<stdio.h>

int A[50],n;
  
int solve(int i,int m){
	int res;
	if(m == 0)return 1;
	if(i >= n)return 0;
	res = solve(i+1,m)||solve(i+1,m-A[i]);
    return res;
}

int main(void){
	int q,i,M;  
	scanf("%d",&n);  
	for(i=0;i<n;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
	}
	return 0; 
}

Measured memory_bytes: 1804
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

x = int(input())
a = [1]
for i in range(2, 1001):
    for j in range(2, 10):
        a.append(i**j)
aa = sorted(set(a))
# print(aa)
b = []
for i in range(len(aa)):
    if aa[i] <= x:
        b.append(aa[i])
print(max(b))


Measured memory_bytes: 4852
N = int(input())
works = []
for i in range(0, N):
	works.append(list(map(int, input().split())))
works.sort(key = lambda v: v[1])
now = 0
for i in range(0, N):
	now += works[i][0]
	if works[i][1] < now:
		print('No')
		break
	if i == N-1:
		print('Yes')

Measured memory_bytes: 88152
I=lambda:list(map(int,input().split()))
n,m=I()
a=[[i]+I() for i in range(m)]
a=sorted(a,key=lambda x:(x[1],x[2]))
b=[]
j0=0
p=1
for i,j,k in a:
  p=1 if j!=j0 else p+1
  b.append([i,j,p])
  j0=j
  
for i,j,k in sorted(b):
  print("{:06d}{:06d}".format(j,k))

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

# define F first
# define S second
# define mp make_pair
# define pii pair<int,int>

# define long long long
# define pb push_back
# define sz(a) (int)(a.size())

# define y1     tipa_y1
# define left   tipa_left
# define right  tipa_right

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 4611686018427387903;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
}
int n;
             
string s;

int p[Sz];

int cnt[Sz];

int main()
{
  Read_rap ();
  cin >> n;
  for (int i = 1;i <= n;i ++) {
    cin >> s;
    for (char c : s)
      cnt[c - 'a'] ++;
                            
    if (i == 1)
      for (int i = 0;i < 26;i ++)
        p[i] = cnt[i], cnt[i] = 0;
    else
      for (int i = 0;i < 26;i ++)
        p[i] = min (p[i], cnt[i]), cnt[i] = 0; 
  }
  for (int i = 0;i < 26;i ++)
    while (p[i] --)
      cout << char (i + 'a');

  return 0;
}









// Coded by Z...


Measured memory_bytes: 2304
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scanln(&N, &M)

	data := make([][]int, N)

	for i := 0; i < N; i++ {
		var K int
		fmt.Scan(&K)

		fav := make([]int, K)
		for j := 0; j < K; j++ {
			var a int
			fmt.Scan(&a)
			fav[j] = a
		}
		data[i] = fav
	}

	result := 0
	for i := 1; i <= M; i++ {
		ok := true
		for _, fav := range data {
			found := false
			for _, n := range fav {
				if n == i {
					found = true
					break
				}
			}
			if !found {
				ok = false
				break
			}
		}
		if ok {
			result++
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {


	public static void main(String[] args) throws Exception{
		BufferedReader  jk =  new BufferedReader(new InputStreamReader( System.in))  ; 
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)) ; 
		//StringTokenizer ana = new StringTokenizer(jk.readLine()) ;

		String ss = jk.readLine() ; 
		String tt = jk.readLine()  ; 
		char[] s= ss.toCharArray() ; 
		char [] t = tt.toCharArray() ; 
		int n = s.length ; int m = t.length ; 
		int dp[][] = new int[n][m] ; 
		int pa[][] = new int[n][m] ; 
		if(s[0]==t[0]) dp[0][0]=1 ; 
		for(int i=1 ; i<n;i++)
		{
			dp[i][0]=dp[i-1][0] ; 
			if(s[i]==t[0]) dp[i][0]=Integer.min(dp[i][0]+1, 1) ;

		}
		for(int j=1 ; j<m ;j++)
		{
			dp[0][j]=dp[0][j-1] ; 
			if(t[j]==s[0]) dp[0][j]=Integer.min(dp[0][j]+1, 1) ;
			pa[0][j]=1 ;
		}
		for(int i=1 ; i<n ;i++)
		{
			for(int j=1 ; j<m ;j++)
			{
				if(s[i]==t[j])
				{
					dp[i][j] = dp[i-1][j-1]+ 1 ; 
				}
				else
				{
					int y = dp[i][j-1] ; int x= dp[i-1][j] ; 
					if(y>x)
					{
						dp[i][j]= y ;pa[i][j]=1 ;
					}
					else dp[i][j]=x ; 
				}


			}
		}
		int i=n-1 ; int j = m-1 ; 
		int ans = dp[i][j] ; 
		char d[]= new char[ans] ; 
		int u = ans -1 ;

		while(i>0 && j>0)
		{
			if(t[j]==s[i]) 
			{
				d[u]=t[j] ;    u-- ; 	
				i-- ; j-- ;
			}
			else
			{
				if(pa[i][j]==1) j-- ; 
				else i-- ; 
			}	
		}
		if(dp[i][j]==1)
		{
             if(i==0) d[0]=s[0] ; 
             else d[0]=t[0] ; 
		}
		for(int te=0 ; te<ans ;te++)
		{
			out.print(d[te]);
		}



		out.flush();
	}
}



Measured memory_bytes: 127568
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	for (;;) {
		int H, W; cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++)
				cout << '#';
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1156
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;


int main(){
  int n;
  int a,b;
  char c;

  double x=0.0, y=0.0;
  int angle=90;

  // cout << M_PI << endl;
  
  while(cin >> a >> c >> b){
    // cout << "---" << endl;
    // cout << a << endl;
    // cout << b << endl;
    if(a==0 && b==0){
      break;
    }
    x += a*cos(angle*M_PI/180.0);
    y += a*sin(angle*M_PI/180.0);
    angle -= b;
    
    if(angle <= -180){
      angle += 360;
    }
    if(angle >= 180){
      angle -= 360;
    }
  }

  cout << (int)x << endl;
  cout << (int)y << endl;
  return 0;
}

Measured memory_bytes: 3476
import sys
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                
    # divisors.sort()
    return sorted(divisors)


X = int(input())

divisor = make_divisors(X)

for i in divisor:
    if i % 2 == 0:
        A = i // 2
    else:
        A = (i + 1) // 2
    
    ans = 0
    while(ans <= X):
        ans = A ** 5 - (A - i) ** 5
        if ans == X:
            print(A, A - i)
            exit()
        A += 1

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

int main(){
	int n;
	string s;
	cin >> n >> s;
	int count=0;
	for(int i = 2; i< n; i++){
		if(s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C' ){
			count++;
		}
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
#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>
#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>
#define _io ios_base::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;

int n, a, b, c, co[100005];
vector< pair<int, int> > g[100005];

void dfs(int k) {
    for (auto i : g[k]) {
        if (co[i.first] == -1) {
            co[i.first] = co[k] ^ (i.second%2);
            dfs(i.first);
        }
    }
}

int main() { _io 
    memset(co, -1, sizeof co);
    cin >> n;
    for (int i=0; i<n-1; i++) {
        cin >> a >> b >> c;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    co[1] = 0; dfs(1);
    for (int i=1; i<=n; i++) {
        cout << co[i] << '\n';
    }
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
#define sz 100002
#define ll long long
using namespace std;
int a[sz],b[sz],c[sz];
ll int dp[sz][4];
int main()
{
    int test,i,j,k;
    cin>>test;
    for(int i=0;i<test;i++)cin>>a[i]>>b[i]>>c[i];
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];

    for(int i=1;i<test;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);

    }
    cout<<max(dp[test-1][0],max(dp[test-1][1],dp[test-1][2]))<<endl;
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long int  ll;
long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
long long bigpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main() 
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0 && c>0)
	{
		c-=b;
		if(c<=0)break;
		a-=d;
	}
	if(c<=0)
	cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3612
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
  static class Pair {
    int left;
    int right;

    Pair(int l, int r) {
      left = l;
      right = r;
    }
  }

  public static void main(String[] args) {
    Scanner std = new Scanner(System.in);
    int n = std.nextInt();
    int m = std.nextInt();
    //    int[][] dp = new int[n + 10][2];
    Map<Integer, Pair> map = new HashMap<>();
    for (int i = 0; i < m; i++) {
      int number = std.nextInt();
      String res = std.next();
      int resValue = (res.equals("AC")) ? 1 : 0;
      Pair p = map.getOrDefault(number, new Pair(0, 0));
      if (resValue == 0 && p.left != 1) {
        p.right++;
      } else {
        p.left = 1;
      }

      map.put(number, p);
    }
    int correctCount = 0;
    int wrongCount = 0;
    for (Map.Entry<Integer, Pair> entry : map.entrySet()) {
      Pair p = entry.getValue();
      if (p.left == 1) {
        correctCount++;
        wrongCount += p.right;
      }
    }

    String ans = correctCount + " " + wrongCount;
    System.out.println(ans);
  }
}


Measured memory_bytes: 71364
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int h = sc.nextInt();
    int w = sc.nextInt();
    
    for (int i = 0; i < h+2; i++) {
       String s = "";
       if (1 <= i && i <= h) {
         s = sc.next();
       }
       for (int j = 0; j < w+2; j++) {
         char c = '#';
         if (1 <= i && i <= h && 1 <= j && j <= w) {
            c = s.charAt(j-1);
         }
         System.out.print(c);
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 24324
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }
    int left = 0;
    int right = K - 1;
    ll lp = A[left], rp = A[right];
    while (right < N - 1) {
        right++;
        rp = A[right];
        if (lp < rp) {
            cout << "Yes" << endl;
        } else
            cout << "No" << endl;
        left++;
        lp = A[left];
    }
}

Measured memory_bytes: 4776
def resolve():
    '''
    code here
    '''
    N = int(input())
    Ls = [int(item) for item in input().split()]
    Ls.sort()
    res = 0
    if N >= 3:
        for i in range(N):
            for j in range(i+1, N):
                for k in range(j+1, N):
                    if Ls[i] + Ls[j] > Ls[k] and Ls[i] != Ls[j] and Ls[j] != Ls[k] and Ls[k] != Ls[i] :
                        res += 1
    print(res)

if __name__ == "__main__":
    resolve()


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e5+1;
int n, a[N][3], dp[N][3];

int main()
{
  fastio;
  cin >> n;
  for (int i = 1; i <= n; i++){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  for (int i = 0; i < 3; i++) dp[1][i] = a[1][i];
  for (int i = 2; i <= n; i++){
    for (int u = 0; u < 3; u++){
      for (int v = 0; v < 3; v++){
        if (u != v) dp[i][u] = max(dp[i][u], dp[i - 1][v] + a[i][u]);
      }
    }
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
  return 0;
}

Measured memory_bytes: 2560
# ans = 全白マス数 - 最短距離のマス数

H,W=map(int,input().split())
grid=[None]*H
white=0
for i in range(H):
  grid[i]=input()
  white+=grid[i].count(".")
  
from collections import deque
q=deque()
q.append([0,0,0])

seen=[[False for i in range(W)] for j in range(H)]

while q:
  v=q.popleft()
  y=v[0]
  x=v[1]
  p=v[2]
  if grid[y][x]=="#" or seen[y][x]:
    continue
  if y==H-1 and x==W-1:
    print(white-(p+1))
    break
  seen[y][x]=True
  if y-1>=0:
    q.append([y-1,x,p+1])
  if y+1<H:
    q.append([y+1,x,p+1])
  if x-1>=0:
    q.append([y,x-1,p+1])
  if x+1<W:
    q.append([y,x+1,p+1])
else:
  print(-1)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

const int mod = 1e9+7;
#define ll long long int
const double epsilon = 1e-7;

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
ll a[300];
ll b[300];
ll c[300];
ll d[300];
bool ans[300];
ll gcd(ll a, ll b){
    if(a < b){
        ll t = a;
        a = b;
        b = t;
    }
    if(a % b == 0)return b;
    else return gcd(b, a%b);
}
int main(void){
    int t;
    scanf("%d", &t);
    for(int i = 0;i < t;i++)scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &d[i]);
    for(int i = 0;i < t;i++){
        if(a[i] < b[i]|| d[i] < b[i]){
            ans[i] = false;
            continue;
        }
        a[i] -= (a[i]-c[i])/b[i]*b[i];
        //printf("%d %lld\n", i+1, a[i]);
        if((a[i] < b[i] && c[i] < a[i])|| d[i] < b[i]){
            ans[i] = false;
            continue;
        }
        ll g = gcd(b[i], d[i]);
        ll e = a[i] - ((a[i] - b[i])/g + 1)*g;
        if(e < b[i] && e > c[i])ans[i] = false;
        else ans[i] = true;
    }
    for(int i = 0;i < t;i++){
        if(ans[i])printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-4;

using namespace std;

int n, m;
char g[100][100];
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

typedef pair<int, int> Q;
typedef pair<int, Q> P;

int main()
{
	while (scanf("%d %d\n", &n, &m), n | m)
	{
		for (int i = 0; i < m; ++i)
		{
			char buf[128];
			cin.getline(buf, sizeof(buf));
			for (int j = 0; j < n; ++j)
				g[i][j] = buf[j];
		}

		int destY, destX;
		for (int i = 0; i < m; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				if (g[i][j] == '&')
				{
					destY = i;
					destX = j;
					g[i][j] = '.';
				}
			}
		}
		bool visited[100][100];
		memset(visited, 0, sizeof(visited));
		priority_queue<P, vector<P>, greater<P> > q;
		q.push(P(0, Q(destX, destY)));
		visited[destY][destX] = true;
		int ans = -1;
		while (ans == -1)
		{
			P v = q.top();
			q.pop();
			int x = v.second.first;
			int y = v.second.second;
			for (int i = 0; i < 4; ++i)
			{
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (nx < 0 || ny < 0 || nx >= n || ny >= m)
				{
					ans = v.first;
					break;
				}
				if (visited[ny][nx])
					continue;
				int c = v.first;
				if (g[y][x] == '.' && g[ny][nx] == '#')
					++c;
				q.push(P(c, Q(nx, ny)));
				visited[ny][nx] = true;
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

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


int main(void){
    int n;
    cin >> n;
    if(n==1){
        cout << "Hello World" <<endl;
    }
    else{
        int a,b;
        cin >> a >> b;
        int ans =a+b;
        cout << ans <<endl;
    }
    
    return 0;
}








































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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;

ll floor(ll a, ll b) {
    if (abs(a) % abs(b) == 0) return a / b;
    if ((a > 0 && b > 0) || (a < 0 && b < 0)) return a / b;
    else return a / b - 1;
}

ll ceil(ll a, ll b) {
    if (abs(a) % abs(b) == 0) return a / b;
    if ((a > 0 && b > 0) || (a < 0 && b < 0)) return a / b + 1;
    else return a / b;
}

signed main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,0,N) cin >> A[i];
    sort(all(A));
    ll left = -1e18-2;
    ll right = 1e18+2;
    while (right - left > 1) {
        ll middle = (right + left) / 2;
        ll cnt = 0;
        rep(i,0,N-1) {
            if (A[i] == 0) {
                if (0 < middle) cnt += N - i - 1;
            } else if (A[i] < 0) {
                ll d = distance(lower_bound(A.begin() + i + 1, A.end(),  floor(middle, A[i]) + 1), A.end());
                cnt += d;
            } else {
                ll d = distance(A.begin() + i + 1, lower_bound(A.begin() + i + 1, A.end(), ceil(middle, A[i])));
                cnt += d;
            }
        }
        if (cnt < K) {
            left = middle;
        } else {
            right = middle;
        }
    }
    cout << left << "\n";
}


Measured memory_bytes: 1792
def divisor(n):
    res = []
    i = 1
    while i*i <= n:
        if n%i == 0:
            res.append(i)
            if i*i != n:
                res.append(n//i)
        i += 1
    res.sort()
    return res

N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
ans = 1
for d in divisor(S):
    rs = [a%d for a in A]
    rs.sort()
    Sum = [0]*(N+1)
    Sum2 = [0]*(N+1)
    for i in range(1,N+1):
        Sum[i] = Sum[i-1]+rs[i-1]
        Sum2[i] = Sum2[i-1]+(d-rs[i-1])
    for i in range(N+1):
        if Sum[i] == Sum2[N]-Sum2[i]:
            if Sum[i] <= K:
                ans = d
print(ans)


Measured memory_bytes: 42092
// AtCoder ARC074, F. Lotus Leaves
// http://arc074.contest.atcoder.jp/tasks/arc074_d

#include <bits/stdc++.h>
using namespace std;

struct Network
{
    int N = 2, source = 0, sink = 1;
    struct Edge { int source, target, id, reverse; };
    vector<vector<Edge>> adjacency_lists;
    vector<int> capacities, flows;

    Network() : adjacency_lists(2) {}

    int add_vertex()
    {
        adjacency_lists.push_back({});
        return N++;
    }

    void add_edge(const int source, const int target, const int capacity)
    {
        if (source == target) return;
        const auto id = int(capacities.size());
        const auto reverse = id+1;
        adjacency_lists[source].push_back({source, target, id, reverse});
        adjacency_lists[target].push_back({target, source, reverse, id});
        capacities.insert(end(capacities), {capacity, 0});
        flows.insert(end(flows), {0, 0});
    }

    int maxflow()
    {
        auto seen = vector<bool>(N);
        const function<int(int, int)> dfs = [&](const int v, const int flow)
        {
            if (v == sink) return flow;

            if (seen[v]) return 0;
            else seen[v] = true;

            for (const auto e : adjacency_lists[v])
            {
                const auto residual = capacities[e.id] - flows[e.id];
                if (residual == 0) continue;
                if (const auto x = dfs(e.target, min(flow, residual)))
                {
                    flows[e.id] += x;
                    flows[e.reverse] -= x;
                    return x;
                }
            }
            return 0;
        };

        auto flow = 0;
        while (true)
        {
            fill(begin(seen), end(seen), false);
            const auto delta = dfs(source, numeric_limits<int>::max());
            if (delta > 0) flow += delta;
            else break;
        }
        return flow;
    }
};

int main()
{
    int R, C; cin >> R >> C;

    auto network = Network();

    auto rows = vector<int>(R);
    for (auto r = 0; r < R; r++)
        rows[r] = network.add_vertex();

    auto columns = vector<int>(C);
    for (auto c = 0; c < C; c++)
        columns[c] = network.add_vertex();

    const auto infinity = R + C;
    for (auto r = 0; r < R; r++)
    {
        string row; cin >> row;
        for (auto c = 0; c < C; c++)
        {
            if (row[c] == '.') continue;
            if (row[c] == 'S') network.source = rows[r];
            if (row[c] == 'T') network.sink = columns[c];
            const auto capacity = row[c] == 'o' ? 1 : infinity;
            network.add_edge(rows[r], columns[c], capacity);
            network.add_edge(columns[c], rows[r], capacity);
        }
    }

    const auto mincut = network.maxflow();
    cout << (mincut >= infinity ? -1 : mincut) << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
int main()
{
	dbl n,k;
	cin>>n>>k;
	dbl ans=0;
	for(dbl i=1; i<=n; i++)
	{
		dbl temp=1/n;
		dbl score=i;
		while(score<k)
		{
			temp*=0.5;
			score*=2;
		}
		ans+=temp;
	}
	cout<<fixed<<setprecision(9)<<ans;
	return 0;

}

Measured memory_bytes: 3732
#include<stdio.h>
int main()
{
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='A') a=10;
	if(a=='B') a=11;
	if(a=='C') a=12;
	if(a=='D') a=13;
	if(a=='E') a=14;
	if(a=='F') a=15;
	if(b=='A') b=10;
	if(b=='B') b=11;
	if(b=='C') b=12;
	if(b=='D') b=13;
	if(b=='E') b=14;
	if(b=='F') b=15;
	if(a>b) {printf(">\n");}
	if(a<b) {printf("<\n");}
	if(a==b){printf("=\n");}

}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define display(v) for (auto x : v) cout << x << ", "
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define ceel(x, y) ((x) / (y) + !((x) % (y) == 0))
#define ss second
#define ff first
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef INCLUDEWHENOFFLINE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main()
{
    fastio;

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({a * c, b * d, a * d, b * c});
    cout << ans;

    return 0;
}

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

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            for(int i; (i = int.Parse(Console.ReadLine())) != 0;) {
                var data = Enumerable.Range(0, i).Select(q => {
                        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
                        var f = false;
                        return new { n = d[0], v = d.Skip(1).Sum(p => p * ((f = !f) ? 60 : 1) ) };
                }).OrderBy(q => q.v).ToArray();
                Console.WriteLine("{0}{3}{1}{3}{2}", data[0].n, data[1].n, data[data.Length - 2].n, System.Environment.NewLine);
            }
        }
    }
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; ++i){
        cin >> A[i] >> B[i];
    }

    vector<ll> C(N+1, 0); // 番兵C[N] = 0
    for (int i = N-1; i >= 0; --i) {
        A[i] += C[i+1];
        ll amari = A[i] % B[i];
        ll need = 0;
        if (amari != 0){
            need = B[i] - amari;
        }
        C[i] = C[i+1] + need;
    }
    cout << C[0] << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#define maxn 502
using namespace std;
int dp[maxn][maxn],h[maxn][maxn];
int main(){
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		h[x][y]++;
	}
	for(int len=1;len<=n;len++){
		for(int i=1;i+len-1<=n;i++){
			int j=i+len-1;
			if(i==j){
				dp[i][j]=h[i][j];
			}
			else if(i+1==j){
				dp[i][j]=dp[i][i]+dp[j][j]+h[i][j];
			}
			else{
				dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+h[i][j];
			}
		}
	}
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		printf("%d\n",dp[x][y]);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define pb push_back
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

int N;
int a[10101];

int canDiv2(int x) {
  int ret = 0;
  while (x % 2 == 0) {
    ret++;
    x /= 2;
  }
  return ret;
}
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  cin >> N;
  int ans = 0;
  REP(i,N) {
    cin >> a[i];
    ans += canDiv2(a[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i, n) cin >> a[i];

  // cout << "in" << endl;
  vi ones(41);
  ll x = 0;
  int digit = 0;
  ll topone = 0;
  rep(d, ones.size()) {
    rep(i, n) {
      if ((a[i] >> d) & 1) {
        ones[d]++;
      }
    }
  }
  for (int d = ones.size() - 1; d >= 0; d--) {
    if (ones[d] * 2 < n) {
      if (x + (1LL << d) <= k) {
        x += (1LL << d);
      }
    }
  }

  ll ans = 0;
  rep(i, n) { ans += (x ^ a[i]); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int h,w;
  cin>>h>>w;

  vector<vector<int>> A(h,vector<int>(w));
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin>>A[i][j];

  vector<vector<int>> B(h,vector<int>(w));
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin>>B[i][j];

  const int MAX = 81 * 81;
  vector< vector<int> > dp(w+1,vector<int>(MAX,0));
  dp[0][0]=1;
  for(int i=0;i<h;i++){
    vector< vector<int> > nx(w+1,vector<int>(MAX,0));
    for(int j=0;j<w;j++){
      int dif=abs(A[i][j]-B[i][j]);
      for(int k=0;k<MAX;k++){
        if(k+dif<MAX){
          dp[j+1][k+dif]|=dp[j][k];
          nx[j+0][k+dif]|=dp[j][k];
        }
        {
          dp[j+1][abs(k-dif)]|=dp[j][k];
          nx[j+0][abs(k-dif)]|=dp[j][k];
        }
      }
    }
    swap(dp,nx);
  }

  for(int i=0;i<MAX;i++){
    if(!dp[w-1][i]) continue;
    cout<<i<<endl;
    break;
  }
  return 0;
}


Measured memory_bytes: 4564
N, K = map(int, input().split())
A = list(map(int, input().split()))

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

beauty = []
for left in range(N):
    for right in range(left + 1, N + 1):
        b = cumA[right] - cumA[left]
        beauty.append(b)

ans = 0
M = max(beauty).bit_length()

for digit in range(M)[:: -1]:
    new = ans + (1 << digit)
    cnt = 0
    for b in beauty:
        if b & new == new:
            cnt += 1
    if cnt >= K:
        ans = new

print(ans)

Measured memory_bytes: 22960
n, k = [int(x) for x in input().split()]

a_list = [int(x) for x in input().split()]
a_list.sort()

mod = 10 ** 9 + 7

temp_list = [1] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = i * temp_list[i - 1] % mod

i_temp_list = [1] * (n + 1)
i_temp_list[-1] = pow(temp_list[-1], mod - 2, mod)
for i in range(n, 0, -1):
    i_temp_list[i - 1] = i_temp_list[i] * i % mod

y = k - 1

ans = 0
for i in range(k - 1, n):
        x = i
        num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
        ans += a_list[i] * num % mod
for i in range(n - k + 1):
        x = n - 1 - i
        num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
        ans -= a_list[i] * num % mod

ans %= mod
print(ans)

Measured memory_bytes: 14936
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 200005
using namespace std;

typedef long long ll;
ll n, cnt, ans, a[N], b[N], c[N], d[N];
int main()
{
	ll i, j, k;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (i = 0; i < n; i++) scanf("%lld", &b[i]);
	for (i = 0; i < 30; i++) {
		k = 1 << i;
		for (j = 0; j < n; j++) c[j] = a[j] % (2 * k), d[j] = b[j] % (2 * k);
		sort(d, d + n);
		cnt = 0;
		for (j = 0; j < n; j++) {
			cnt += lower_bound(d, d + n, 2 * k - c[j]) - lower_bound(d, d + n, k - c[j]);
			cnt += lower_bound(d, d + n, 4 * k - c[j]) - lower_bound(d, d + n, 3 * k - c[j]);
		}
		ans += cnt % 2 * k;
	}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var v = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
        Array.Sort(v);
        for (int i = 0; i < N - 1; i++){
            v[i + 1] = Math.Round((v[i] + v[i + 1]) / 2, 7);}
        double answer = v[^1];
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27548
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define loop(n) for(int i=0; i<n; i++)
void solve()
{
    int a,b,n;cin>>a>>b>>n;
    int x=min(n,b-1);
    int ans=((a*x)/b)-(a*(x/b));
    cout<<ans;
    
	return;
}
int32_t main() 
{ 
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0; 
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

struct Shogen {
  int x, y;
};

void solve(void)
{
  int N; cin >> N;
  vector<vector<Shogen>*> A{};
  for (int i = 0; i < N; ++i) {
    int sz; cin >> sz;
    auto vc = new vector<Shogen>(sz);
    for (auto& p : *vc) {
      cin >> p.x >> p.y;
      --p.x;
    }
    A.push_back(vc);
  }

  int ans{};
  int itr = 1 << N;
  while (itr) {
    int res{};
    for (int i = 0; i < N; ++i) {
      if (itr >> i & 0x01) {
        ++res;
        for (const auto& p : *A[i]) {
          auto isPass = ((itr >> p.x) & 0x01) == p.y;
          if (!isPass) {
            goto err;
          }
        }
      }
    }

    chmax(ans, res);
err:
    --itr;
  }
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a, b, d, r;
    double f;
    
    scanf("%d %d %d %d %lf", &a, &b, &d, &r, &f);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f", d, r, f);
    return 0;
}



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


int main()
{
    string s; cin>>s;
    int i;
    for(i = 1; i < s.size()/2; i++){
        if(s.substr(0, s.size()/2 - i) == s.substr(s.size()/2 - i, (int)s.size()/2 - i)) break;
    }
    cout << s.size() - i*2 << endl;
}

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

typedef struct{
  char name[10];
  int num;
}data;

void enqueue(data);
data dequeue(void);

#define MAX 500000

data dg[MAX];
int head=0,tail,gyo;

int main(){
  int quan;
  int i;
  int rest;
  data dbuf;
  int total=0;
  int cnt=0;
  int buf;
  
  scanf("%d%d",&gyo,&quan);

  for(i=0;i<gyo;i++){
    scanf("%s",dg[i].name);
    scanf("%d",&dg[i].num);
  }

  while(1){
    dbuf=dequeue();
    if(quan<dbuf.num){
      dbuf.num-=quan;
      total+=quan;
    }else {
      buf=dbuf.num;
      dbuf.num-=buf;
      total+=buf;
    }
    if(dbuf.num>0){
      enqueue(dbuf);
    }
    else{
      cnt++;
      printf("%s %d\n",dbuf.name,total);
      if(cnt>=gyo) break;
    }
  }
  
  return 0;
}

void enqueue(data de){
  
  dg[tail]=de;
  if(tail+1==gyo){
    tail=0;
  }else tail++;
}

data dequeue(void){
  int headbuf;
  
  headbuf=head;
  if(head+1==gyo){
    head=0;
  }else head++;

  return dg[headbuf];
}



Measured memory_bytes: 2532
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sections Sections

type Sections []*Section

type Section struct {
	l, r int
}

func (r Sections) Len() int {
	return len(r)
}

func (r Sections) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func (r Sections) Less(i, j int) bool {
	if r[i].r != r[j].r {
		return r[i].r < r[j].r
	}
	return r[i].l < r[j].l
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N, M int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &N, &M)

	sections = make([]*Section, M)
	for i := 0; i < M; i++ {
		s := &Section{}
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &s.l, &s.r)
		sections[i] = s
	}
	sort.Sort(sections)

	ans := 0
	r := sections[0].r
	for i := 1; i < M; i++ {
		if sections[i].l < r {
			continue
		}
		ans++
		r = sections[i].r
	}
	ans++
	fmt.Println(ans)
}


Measured memory_bytes: 5120
all_N = []
while True:
	N = list(map(int, input().split(' ')))
	if N[0] == 0 and N[0] == 0:
		break
	all_N.append(N)

for i in range(len(all_N)):
	for j in range(all_N[i][0]):
		print('#' * all_N[i][1])
	print('')

Measured memory_bytes: 7668
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

string s;

int main(int argc, char **argv) {
	cin >> s;
	int l = 0, r = s.length()-1;
	while (l < r) {
		if (s[l] != s[r]) {
			cout << "No" << endl;
			return 0;
		}
		l++;
		r--;
	}
	if (s.length()%2 == 0) {
		l = 0, r = s.length()/2-1;
		while (l < r) {
			if (s[l] != s[r]) {
				cout << "No" << endl;
				return 0;
			}
			l++;
			r--;
		}
		l = s.length()/2, r = s.length()-1;
		while (l < r) {
			if (s[l] != s[r]) {
				cout << "No" << endl;
				return 0;
			}
			l++;
			r--;
		}
		cout << "Yes" << endl;
	} else {
		l = 0, r = s.length()/2-1;
		while (l < r) {
			if (s[l] != s[r]) {
				cout << "No" << endl;
				return 0;
			}
			l++;
			r--;
		}
		l = s.length()/2+1, r = s.length()-1;
		while (l < r) {
			if (s[l] != s[r]) {
				cout << "No" << endl;
				return 0;
			}
			l++;
			r--;
		}
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def a_colorful_slimes_2(N, A):
    import itertools
    straight_group = itertools.groupby(A)
    ans = 0
    for _, group in straight_group:
        ans += len(list(group)) // 2
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(a_colorful_slimes_2(N, A))

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

namespace Prison
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] list = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] L = new int[list[1]];
            int[] R = new int[list[1]];
            
            for(int i = 0; i < list[1]; i++)
            {
                int[] gatepass = Console.ReadLine().Split().Select(int.Parse).ToArray();
                L[i] = gatepass[0];
                R[i] = gatepass[1];

            }

            int max = L.Max();
            int min = R.Min();
            if(max <= min)
            {
                Console.WriteLine(min - max + 1);
            }
            else if(max > min)
            {
                Console.WriteLine(0);
            }
        }
    }
}


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

int main()
{
	int n,x,t = 0;
	while(1){
		t = 0;
		cin >> n >> x;
	    if(n + x == 0) break;
	    for(int i = 1;i <= n;i++){
	    	for(int j = i + 1;j <= n;j++){
	    		for(int k = j + 1;k <= n;k++){
	    			if(i + j + k == x) t++;
	    			}
	    		}
	    	}
	    cout << t << endl;
	   }
	    return 0;
	    }

Measured memory_bytes: 3088
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main(){
	int board[2020];
	for(int i = 0; i < 2020; i++){
		board[i] = 0;
	}
	int N;
	cin >> N;
	int tkn[N];
	for(int i = 0; i < N; i++){
		int p = 0;
		cin >> p;
		tkn[i] = p;
		board[p] = i + 1;
	}
	int M;
	cin >> M;
	for(int i = 0; i < M; i++){
		int move;
		cin >> move;
		if(tkn[move-1] != 2019){
			if(board[tkn[move-1]+1] == 0){
				board[tkn[move-1]+1] = move;
				board[tkn[move-1]] = 0;
				tkn[move-1]++;
			}
		}
	}
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < 2020; j++){
			if(board[j] == i){
				cout << j << "\n";
				break;
			}
		}
	}
}


Measured memory_bytes: 3124