akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
////////////////////////////////
 
#define int long long

const int N  = 2e5 + 10;

int dp[N];
int a[N];
int h[N];
int stree[N*4];

void update(int idx , int start , int end , int val , int id){

    if(start==end){
        
        stree[idx] = val;
        return;
    }

    int mid = (start + end)/2;

    if(id <= mid && id >= start){

        update(2*idx , start , mid , val , id);
    }
    else{

        update(2*idx + 1 , mid+1 , end , val , id);
    }

    stree[idx] = max(stree[2*idx] , stree[2*idx+1]);
}

int query(int idx , int l , int r, int start , int end){

    if(r < start || end < l){

        return 0;
    }

    if(l <= start && r >= end){

        return stree[idx];
    }

    int mid = (start + end)/2;

    int x = query(2*idx , l , r , start , mid);

    int y = query(2*idx + 1 , l , r , mid + 1 , end);

    return max(x , y);
}

void solve(){

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

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

        dp[h[i]] = a[i] + query(1 , 1 , h[i]-1 , 1 , n);

        update(1 , 1 , n , dp[h[i]] , h[i]);

        // for(int j = 1 ; j <= 10 ; ++j)
        //     cout<<stree[j]<<" ";
        // cout<<endl;
    }

    // for(int i = 1 ; i <= n ; ++i){

    //     cout<<i<<" : "<<dp[i]<<endl;
    // }
    int ans = *max_element(dp , dp + n + 1);

    cout<<ans<<endl;

}
 
signed main(){
 
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}


Measured memory_bytes: 12376
from collections import deque

s = input()
ss = s.replace('x', '')
ans = 0
i, j = 0, len(s)-1

if ss == ss[::-1]:
    while i<j:
        if s[i] != s[j]:
            ans += 1
            if s[i]=='x': i += 1
            else: j -= 1
        else:
            i += 1
            j -= 1
    print(ans)
else: print(-1)

Measured memory_bytes: 3564
import sys
A,B,C,D = map(int, input().split())


count = 0
while True:
  
  if count % 2 == 0:
    C = C - B
  else:
    A = A -D
  
  if A <= 0:
    print("No")
    sys.exit()

  if C <= 0:
    print("Yes")
    sys.exit()
    
  count += 1


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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int main()
{
  int n;
  while (n = in()){
    vector<string> names;
    int table[64][64] = {};
    int table_size[64] = {};
    rep(i, n){
      string name;
      cin >> name;
      names.push_back(name);
      rep(j, in()){
        int v = in();
        table[v][table_size[v]] = i;
        table_size[v]++;
      }
    }
    vector<int> score(n, 0);
    rep(i, 64){
      rep(j, table_size[i]){
        score[table[i][j]] += n + 1 - table_size[i];
      }
    }
    vector<pair<int, string> > res;
    rep(i, n){
      res.push_back(make_pair(score[i], names[i]));
    }
    sort(res.begin(), res.end());
    cout << res[0].first << " " << res[0].second << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner (System.in);
		
	int N = sc.nextInt();
	
	if(N%2 == 0) {
		System.out.println(N/2);
	}else {
		System.out.println((N+1)/2);
	}
	
	}
}

Measured memory_bytes: 21844
#入力
N = int(input())

#赤の座標を取得-->並び替えて左ほど小さくする
red = []
for i in range(N):
    a = list(map(int, input().split()))
    red += [a]
red.sort(reverse = False)

#青の座標を取得-->並び替えて左ほど小さくする
blue = []
for i in range(N):
    a = list(map(int, input().split()))
    blue += [a]
blue.sort(reverse = False)

#blue[m]がペアを作れるかどうかをTrue or Falseで返す
def judge(m): 
    INF = 10 ** 9
    count = 0
    memo = -1
    for i in range(N): #redのリストを小さい順に探索
        if blue[m][0] > red[i][0]: #x座標が条件を満たすか確認       
            #条件を満たす中で最大のy座標を探す
            if memo < red[i][1] and blue[m][1] > red[i][1]: 
            #red[i][1]=赤のy座標が最も大きくかつ、blue[m][1]=青のy座標より小さい時    
                count = 1 #1つでも条件を満たすものがあれば、count = 1にする
                memo = max(memo, red[i][1]) #最も大きいy座標を記録
                memo_i = i #最も大きくなるときのiをメモ
    if count == 0: #iのループを回してもカウントが増えない=x座標が条件を満たすことが一度もない
        return False
    else: #少なくとも一回は条件を満たした。
        red[memo_i][0] = INF #使ったものをINFで書き換え
        red[memo_i][1] = INF #使ったものをINFで書き換え
        return True

count = 0
for s in range(N): #blue内のxが最も小さいののから着目
    if judge(s):
        count += 1
print (count)


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

int main(){
	string S,mae,ato;
	cin>>S;
	mae = S.substr(0,2);
	ato = S.substr(2,2);
	/*
	cout<<mae<<endl;
	cout<<ato<<endl;
	*/
	int ans=0;
	if(mae>="01" and mae <="12"){
		ans+=1;
	}
	if(ato>="01" and ato <= "12"){
		ans+=2;
	}
	if(ans==0){
		cout<<"NA"<<endl;
	}
	else if(ans==1){
		cout<<"MMYY"<<endl;
	}
	else if(ans==2){
		cout<<"YYMM"<<endl;
	}
	else{
		cout<<"AMBIGUOUS"<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c; cin >> a >> b >> c;
    cout << max(a,max(b,c)) - min(a,min(b,c))  << endl;
}


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

signed
main(){
	int m,n,l;
			while(cin >> m >> n >> l && !(m==0 && n==0 && l==0))
			{
					vector<int> p(m);
					for(int i=0;i<m;i++)
							cin >> p[i];

					sort(p.rbegin(), p.rend());
					int ans = 0, sum = 0;;

					for(int i=n;i<=l;i++)
					{
							if(sum <= p[i-1]-p[i])
							{
								ans = i;
								sum = p[i-1] - p[i];
							}
					}
					cout << ans << endl;
			}
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
   fast;
   ld r;
   cin >> r;
   ld ans = 2*3.14159*r;
   cout << fixed << setprecision(10) << ans;  
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll n, m; cin >> n >> m;
    ll sum = 0;
    rep(i, 0, m){
        ll a; cin >> a;
        sum += a;
    }
    if(n >= sum) cout << n-sum << endl;
    else cout << -1 << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  set<int> c;
  int n=1;
  while(1){
    if(c.count(s)){
      cout<<n<<endl;
      break;
    }else{
      c.insert(s);
      if(s%2==0)
        s/=2;
      else
        s=s*3+1;
      n++;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

int solve(int N) {
    long long h, n, w;
    int min_val, max_val;
    if (N < 4) {
        min_val = 1;
    } else {
        min_val = N/4;
    }
    max_val = 3500;
    h = min_val;
    n = min_val;
    for (int i = 0; h < max_val; h++) {
        n = min_val;
        for (int j = 0; n < max_val; n++) {
            long long a = (h*n*4 - N*n - N*h);
            if (a != 0) {
                if (((h*n*N)%a == 0) and ((h*n*N)/a > 0)) {
                    std::cout << h << ' ' << n << ' ' << (h*n*N)/(h*n*4 - N*n - N*h) << std::endl;
                    return 0;
                }
            }
        }
    }
    std::cout << h << n << (h*n*N)/(h*n*4 - N*n - N*h) << std::endl;
    return 0;
}

int main() {
    struct timeval start,end;
    long long span;
    int n;

    gettimeofday(&start,NULL);

    std::cin >> n;
    solve(n);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

int main(){
    string A, B;
    cin >> A >> B;
    if(A.size() > B.size()){
        cout << "GREATER" << endl;
    }else if(A.size() < B.size()){
        cout << "LESS" << endl;
    }else if(A > B){
        cout << "GREATER" << endl;
    }else if(A < B){
        cout << "LESS" << endl;
    }else{
        cout << "EQUAL" << endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
sN = [int(input()) for i in range(N)]

# dpでやってみる版

# [どこまでのsNを使うか][合計として取りうる値かどうか]
# 範囲は0を含むNまでのN+1個と0～10000までの10001個
dp = [[False] * (N*100+1) for j in range(N+1)]

# 初期値設定(s1～sNを何も使わない時、合計値0は取りうるか→True)
dp[0][0] = True

for i in range(N):
    for j in range(N*100+1):
        # 前回までの設定値でここがTrueになっていたら
        if dp[i][j] == True:
            # sN合計の一つ先で、今までの値はTrue
            dp[i+1][j] = True
            # sN合計の一つ先で、今までの値+今回のsNもTrue
            dp[i+1][j+sN[i]] = True

# 高い値から順に見ていく
for i in range(N*100, -1, -1):
    if dp[N][i]:
        if i % 10 != 0:
            print(i)
            exit()
print(0)

Measured memory_bytes: 10868
if __name__ == '__main__':
    a, b = map(int, input().split())
    max = -10000000
    sum = a+b
    minnus = a-b
    cros = a*b
    if max < sum:
        max = sum
    if max < minnus:
        max = minnus
    if max < cros:
        max = cros
    print(max)


Measured memory_bytes: 2940
hw,hh,n=map(int,input().split())
lw=lh=0
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    lw=max(lw,x)
  elif a==2:
    hw=min(hw,x)
  elif a==3:
    lh=max(lh,y)
  else:
    hh=min(hh,y)
print(max(hh-lh,0)*max(hw-lw,0))

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int a, b; scanf("%d%d", &a, &b);
	printf("%d", (a+b)%24);
}

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define numOfOnes(n) __builtin_popcount(n)
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y
//</DEFINE>
int n, m;
vector<vector<int>>v;
//<FUNCTIONS>
int res[100000];
int solve(int idx) {
	if (~res[idx])return res[idx];
	int& ans = res[idx] = 0;
	for (int i = 0; i < v[idx].size(); i++) {
		ans = max(ans, solve(v[idx][i]) + 1);
	}
	return ans;
}
//</FUNCTIONS>		
int main() {
	Fast();
	cin >> n >> m;
	v.resize(n);
	int x, y;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		v[x - 1].push_back(y - 1);
	}
	memset(res, -1, sizeof(res));
	int mx = 0;
	for (int i = 0; i < n; i++)mx = max(mx, solve(i));
	cout << mx << endl;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=n;i>=1;i--)
		if(i==1||i==2||i==4||i==8||i==16||i==32||i==64)
		{
			cout<<i<<endl;
			return 0;
		}
	return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <functional>
#include <iostream>
#include <memory>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	string candidates[] = { "dream", "dreamer", "erase", "eraser" };
	for (auto &c : candidates) {
		reverse(c.begin(), c.end());
	}
	bool ok = true;
	for (int i = 0; i < s.length();) {
		bool match = false;
		for (const auto &c : candidates) {
			if(s.substr(i, c.length()) == c) {
				i += c.length();
				match = true;
				break;
			}
		}
		if (!match) {
			ok = false;
			break;
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
}


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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 1e9 + 5;
const LL infll = 1e18+5;
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 1e5+5;
int n, m, p[MAXN], val[MAXN];
bool vis[MAXN];

int fp (int x) {
	if (p[x]==x) return x;
	return p[x] = fp(p[x]);
}

int main() {
	gi(n); gi(m);
	for (int i=1; i<=n; i++) gi(val[i]);
	for (int i=1; i<=n; i++) p[i] = i;
	while (m--) {
		int u, v; gi(u); gi(v);
		int x = fp(u);
		int y = fp(v);
		if (x==y) continue;
		p[x] = y;
	}
	int ans = 0;
	setnul(vis);
	for (int i=1; i<=n; i++) {
		if (val[i]==i) ans++;
		else if (!vis[i]) {
			int mks = 0, now = i, lst = 0;
			while (!vis[now]) {
				vis[now] = 1;
				int nex = val[now];
				if (fp(now)==fp(nex)) ans++;
			//	mks = max(mks, lst);
			}
			// ans += mks;
		}
	}
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1152
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#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 <cstdalign>
#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;

int main()
{
  ll n, k;
  cin >> n >> k;

  cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
def dfs(A, M, i):
  if i < 0:
    return
  A[i] += 1
  if A[i] > M:
    dfs(A, M, i-1)
    if i-1 >= 0:
      A[i] = A[i-1]

N,M,Q=map(int, input().split())
a,b,c,d = [], [], [], []
for i in range(Q):
  ai,bi,ci,di = map(int, input().split())
  a.append(ai)
  b.append(bi)
  c.append(ci)
  d.append(di)

A = [1]*N
ans = 0

for _ in range(100000):
  dsum = 0
  for i in range(Q):
    ai,bi,ci,di = a[i], b[i], c[i], d[i]
    if A[bi-1]-A[ai-1] == ci:
      dsum += di
  ans = max(ans, dsum)

  #終了条件
  if A[0]==M:
    break

  #終了しない場合は次の数字
  dfs(A, M, N-1)

print(ans)

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

using namespace std;

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

typedef long long int ll;
typedef long long unsigned int llu;


int main(){
  int N,tmp,maxp,i;
  cin >> N;
  tmp = N;
  FOR(i,2,N+1){
    if(tmp%i==0){
      while(tmp%i==0){
        tmp = tmp/i;
      }
      maxp = i;
    }
  }
  int h = maxp;
  i = 1;
  char answer[100] = "";
  int n,w,flag;
  flag = 0;
  while(h<=3500){
    FOR(n,1,3501){
      FOR(w,n,3501){
        if(4*h*n*w==N*(h*n+n*w+h*w)){
          flag = 1;
          printf("%d %d %d\n",h,n,w);
          break;
        }
      }
      if(flag==1)break;
    }
    if(flag==1)break;
    h = maxp * i;
    i++;
  }
  printf("%s",answer);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double kh = (h+m/60.0) * 30, km = m * 6;
  
  double kaku = abs(kh - km);
  
  kaku = kaku * acos(-1) / 180;
  
  double ans = pow(a, 2) + pow(b, 2) - 2.0 * a * b * cos(kaku);
  printf("%.20lf\n", sqrt(ans));

  return 0;
}


Measured memory_bytes: 4224
#include <iostream>
using namespace std;
typedef long long ll;
static const ll Z = 50;
#define rep(i,s,n)for(ll i = s;i<n;i++)
char s[Z];
char t[Z];

int main() {
	cin >> s >> t;
	char* S = &s[0];
	char* T = &t[0];

	while (*S != '\0' && T != '\0') {
		if (*S != '\0')	cout << *S++;
		if (*T != '\0') cout << *T++;
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools

s = input()
l = s.split()
N = int(l[0])
M = int(l[1])

a = list()
b = list()
edges = set()
for i in range(1, M + 1):
    s = input()
    l = s.split()
    u = int(l[0])
    v = int(l[1])
    a.append(u)
    b.append(v)
    edges.add((u, v))
    edges.add((v, u))
#print(edges)

t = range(1, N + 1)
res = 0
for p in itertools.permutations(t):
    if p[0] != 1:
        break
    c = 0
    for j in range(0, N - 1):
        if (p[j], p[j + 1]) in edges:
            c += 1
    if c == N - 1:
        res += 1
print(res)

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

int main(){
    int A,B,C,X;

    int sum,cnt = 0;
    cin >> A >> B >> C >> X;

    for(int i = 0;i <= A;i++){
        for(int j = 0;j <= B;j++){
            for(int k = 0;k <= C;k++){
                sum = 500*i+100*j+50*k;

                if(sum == X)
                cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n) {
		cin >> a[i];
	}
	int now = 0;
	int ans = 0;
	rep(i, n - 1) {
		if (a[i] >= a[i + 1]) {
			now++;
		}
		else {
			chmax(ans, now); now = 0;
		}
	}
	chmax(ans, now);
	cout << ans << endl;
	return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define D  double
typedef pair<D,int>T;
int N;
int X[1111],Y[1111],R[1111];
D dist[1111];
D INF=1e15;
D EPS=1e-6;

int table2[1111][1111];
D table[1111][1111];

signed main(){

    cin>>X[0]>>Y[0]>>X[1]>>Y[1];
    cin>>N;
    rep(i,N)cin>>X[i+2]>>Y[i+2]>>R[i+2];
    N+=2;

    rep(i,N)rep(j,N){
        table2[i][j]=(X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]);
        table[i][j]=sqrt(1.0*table2[i][j]);
    }

    fill_n(dist,1111,INF);
    dist[0]=0;
    priority_queue<T,vector<T>,greater<T>>que;
    que.push(make_pair(0,0));
    while(que.size()){
        D d;
        int idx;
        tie(d,idx)=que.top();
        que.pop();
        if(dist[idx]+EPS<d)continue;
        rep(i,N){
            int foo=table2[i][idx];
            int bar=R[i]+R[idx];
            D cost;
            if(foo<=bar*bar)cost=0.0;
            else cost=table[i][idx]-bar;
            if(dist[i]<EPS+dist[idx]+cost)continue;
            dist[i]=cost+dist[idx];
            que.push(T(dist[i],i));

        }
    }
    printf("%.20f\n",dist[1]);
    return 0;
}


Measured memory_bytes: 21872
//#define DEB1 //output check function
//#define DEB2 //same output, input from input.txt

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VVI = vector<VI>;


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


#ifdef DEB1
#define DPRINT(x) cout<< #x << "=" << (x) << endl; // print at debug mode
#else
#define DPRINT(x) ;
#endif
#ifdef DEB1
#define DCHECK(x) cout<< "debug check" << #x << endl;
#else
#define DCHECK(x) ;
#endif
 


/*
constant values
*/

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

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9

int list[2000010];
// Main program
void solve(){
    int N,A,B,C,D;
    string S;
    cin >> N >> A >> B >> C >> D;
    // 0start
    A-=1;
    B-=1;
    C-=1;
    D-=1; 
    cin >> S;
    REP(i,N){
        if(S[i]=='.'){
            list[i]=0;
        }
        else{
            list[i]=1;
        }
    }
    
    // A ~ C , B ~ D OK
    int flag1 = 0;
    REPN(i,C,A){
        if(list[i]*list[i+1]==1) flag1=1;
    }
    REPN(i,D,B){
        if(list[i]*list[i+1]==1) flag1=1;
    }
    if(flag1==1) {
        cout << "No" << endl;
        return;
    }
    if(C < D){
        cout << "Yes" << endl;
        return;
    }
    
    int flag2 = 1;
    REPN(i,D,B-1){
        if(list[i]+list[i+1]+list[i+2]==0){
            flag2=0;
        }
    }
    if(flag2==1){
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    return;
}



// ----------------------------------------------
int main() {

#ifdef DEB2
    cout << "DEBUG MODE"  << endl;
	ifstream in("input.txt"); //for debug
	cin.rdbuf(in.rdbuf()); //for debug
#endif

	int T=1; 

	for (int i = 0; i < T; ++i) {
		solve();
	}
}

Measured memory_bytes: 1284
# 深さ優先探索による全探索
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def dfs(N):
    """
    param N:文字列の長さ

    """
    S = "abcdefghij"
    result = []
    stack = ["a"]
    
    while stack:
        s = stack.pop()
        if len(s) == N:
            result.append(s)
            continue
        else:
            for i in S[:len(set(s))+1]:
                stack.append(s + i)
    
    return result


def main():
    N = int(readline())

    ans = dfs(N)
    print("\n".join(ans[::-1]))
            

if __name__ == "__main__":
    main()


Measured memory_bytes: 15128
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n[5];
    string ans;
    while(scanf("%d%*c%d%*c%d%*c%d%*c%d", &n[0],&n[1],&n[2],&n[3],&n[4]) != EOF){
        rep(i,4){
            for(int j = 4; j > i; j--){
                if(n[j] < n[j - 1]){
                    int num = n[j];
                    n[j] = n[j - 1];
                    n[j - 1] = num;
                }
            }
        }
        ans = "null";
        rep(i,4){
            if(n[i] == n[i + 1]){
                ans = "one pair";
                rep(j,4){
                    if(n[j] == n[j + 1] && n[j] != n[i]){
                        ans = "two pair";
                        break;
                    }
                }
            }
        }
        rep(i,3){
            if(n[i] == n[i + 1] && n[i] == n[i + 2]){
                ans = "three card";
                rep(j,4){
                    if(n[j] == n[j + 1] && n[j] != n[i] && n[j] != n[i + 1]){
                        ans = "full house";
                        break;
                    }
                }
            }
        }
        rep(i,2){
            if(n[i] == n[i + 1] && n[i] == n[i + 2] && n[i] == n[i + 3]){
                ans = "four card";
                break;
            }
        }
        bool c = true;
        int f = n[0];
        rep(i,5){
            if(n[i] != f + i){
                c = false;
                break;
            }
        }
        if(c) ans = "straight";
        if(n[0] == 1 && n[1] == 10 && n[2] == 11 && n[3] == 12 && n[4] == 13) ans = "straight";
        cout << ans << endl;
    }
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }


signed main(void){
  int n;cin >> n;
  vint d(n);vin(d);
  vsort(d);
  cout << d[n/2]-d[n/2-1] << endl;


  return 0;
}


Measured memory_bytes: 640
import sys

for line in sys.stdin:
  a,b,c,d,e,f = [float(i) for i in line.strip().split()]

  y = (c*d - a*f) / (b*d - a*e)
  x = (c - b*y) / a

  print('{:.3f}'.format(x), '{:.3f}'.format(y))



Measured memory_bytes: 5592
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def popcnt(n):
    return bin(n).count("1")


def mod(n, cnt):
    if n == 0:
        return cnt
    n = n % popcnt(n)
    cnt += 1
    return mod(n, cnt)


n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c - 1 != 0 else 0

for i in range(n):
    if x2[i] == '0':
        t = (mod1 + pow(2, n - i - 1, c + 1)) % (c + 1)
    else:
        if c - 1 != 0:
            t = (mod2 - pow(2, n - i - 1, c - 1)) % (c - 1)
        else:
            print(0)
            continue
    print(mod(t, 1))

Measured memory_bytes: 10740
N = int(input())

dp = [[0, 0, 0] for _ in range(N + 1)]

for i in range(1, N + 1):
    a = tuple(map(int, input().split()))
    for j in range(3):
        dp[i][j] = max(dp[i - 1][j - 1] + a[j], dp[i - 1][j - 2] + a[j])

print(max(dp[N]))

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Io.Read<int>();
            var Blist = Io.ReadList<int>();

            var output = Blist[0];
            for (var i = 0; i < N - 2; i++)
            {
                output += Math.Min(Blist[i], Blist[i + 1]);
            }

            output += Blist[N - 2];

            Io.Write(output.ToString());
        }
    }

    class Io
    {
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static IEnumerable<string> ReadRepeat(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read());
        }

        public static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        public static IEnumerable<T> ReadRepeat<T>(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read<T>());
        }

        public static string[] ReadList(char devide = ' ')
        {
            return Read().Split(devide);
        }

        public static T[] ReadList<T>(char devide = ' ')
        {
            return ReadList(devide)
                .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                .ToArray();
        }

        public static IEnumerable<T[]> ReadListRepeat<T>(int count, char devide = ' ')
        {
            return Enumerable.Range(0, count).Select(_ => ReadList<T>(devide));
        }

        public static void Write(string value)
        {
            Console.WriteLine(value);
        }
    }
}


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

int main(void){
    char s[1000];
	
  	scanf("%s",s);
  
    char a[]="ABC";

    if(strcmp(s,a)==0){
        printf("ARC\n");
    }else{
        printf("ABC\n");
    }

    return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    int n;
    vector<int> d;
    int ans = 0;

    cin >> n;

    for (int i = 0; i < n; i++){
        int dd;
        cin >> dd;
        d.push_back (dd);
    }

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

    ans = d[n/2] - d[n/2 - 1];

    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007
ll n;
vector<ll> vs;
map<ll,ll> dp[2];

int main(){

  repl(i,1,19){
    rep(S,1<<i){
      string tmp;
      rep(d,i){
        if((S>>d)&1)tmp+="8";
        else tmp+="2";
      }
      vs.push_back(stoll(tmp));
    }
  }
  reverse(all(vs));
  cin>>n;
  if(n==1){
    cout<<-1<<endl;
    return 0;
  }
  ll m=vs.size();

  int crt=0,nxt=1;
  dp[crt][n]=0;
  rep(i,m){
    ll v=vs[i];
    dp[nxt].clear();
    for(auto it : dp[crt]){
      if(it.fi%v==0){
        ll tmp=it.fi,cnt=1;
        while(tmp%v==0){
          maxch(dp[nxt][tmp/v],it.se+cnt);
          tmp/=v;
          cnt++;
        }
      }
      maxch(dp[nxt][it.fi],it.se);
    }
    swap(crt,nxt);
  }
  if(dp[crt].find(1)==dp[crt].end())cout<<-1<<endl;
  else cout<<dp[crt][1]<<endl;
  return 0;
}



Measured memory_bytes: 6948
#include <iostream>
using namespace std;
int main(void){
    int n,k;
    string s;
    cin>>n;
    cin>>s;
    cin>>k;
    for (int i=0;i<n;i++){
        if(s[i]!=s[k-1]){
            s[i]='*';
        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

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

int main(void){
	int n;
	cin>>n;
	vector<string> S;
	string s;
	rep(i,n){
		cin>>s;
		S.push_back(s);
	}
	char A[303][303];
	ll count = 0;
	rep(slide,n){
		rep(i,n){
			rep(j,n){
				A[i][j] = S[(int)((i+slide)%n)][j];
			}
		}
		bool ok = true;
		rep(i,n){
			rep(j,n){
				if(A[i][j] != A[j][i]){
					ok = false;
					break;
				}
			}
			if(!ok) break;
		}
		if(ok) count++;
	}
	cout<<count*n<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N;
    cin >> N;
    vector<P> vec[20];
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        for(int j = 0;j < A;j++) {
            int B,C;
            cin >> B >> C;
            B--;
            vec[i].push_back(P(B, C));
        }
    }
    int ret = 0;
    for(int bit = 0;bit < (1 << N);bit++) {
        vector<int> cnt(N);
        for(int i = 0;i < N;i++) {
            if(bit & (1 << i)) {
                cnt.at(i) = 1;
            }
            else {
                cnt.at(i) = 0;
            }
        }
        bool cnt2 = true;
        for(int i = 0;i < N;i++) {
            if(cnt.at(i) == 1) {
                for(int j = 0;j < vec[i].size();j++) {
                    if(cnt.at(vec[i].at(j).first) != vec[i].at(j).second) {
                        cnt2 = false;
                        break;
                    }
                }
            }
        }
        if(cnt2 == true) {
            int ret2 = 0;
            for(int i = 0;i < N;i++) {
                if(cnt.at(i) == 1) {
                    ret2++;
                }
            }
            ret = max(ret, ret2);
        }
    }
    cout << ret << endl;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int K; cin >> K;
    vector<ll> A(K);
    rep(i, K) cin >> A[i];

    ll mn = 2, mx = 3;
    reverse(ALL(A));
    
    if (A[0] != 2) {
        cout << -1 << endl;
        return 0;
    }

    for (int i=1; i<K; i++) {
        ll nmn = (mn + A[i] - 1) / A[i] * A[i];
        ll nmx = mx / A[i] * A[i] + A[i] - 1;

        if (nmn > nmx || nmn < mn || mx < nmn) {
            cout << -1 << endl;
            return 0;
        }
#ifdef DEBUG
        DUMP2(mn, mx);
#endif
        mn = nmn, mx = nmx;
    }

    cout << mn << " " << mx << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#define fisier 1
using namespace std;
typedef long long ll;
const double dancila = 3.14159265359;

int main(){
	#ifdef fisier
        ifstream cin("input.in");
        ofstream cout("output.out");
    #endif	
		
	ios_base::sync_with_stdio();
	cin.tie(0);
	
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " <<  a << " " <<  b;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  string a[60];
  rep(i,h) cin >> a[i];
  int x[] = {1, 1, 0, -1, -1, -1, 0, 1};
  int y[] = {0, 1, 1, 1, 0, -1, -1, -1};
  rep(i,h) {
    rep(j,w) {
      if (a[i][j] == '.') {
        int num = 0;
        rep(k,8) {
          int ax = i + x[k];
          int ay = j + y[k];
          if (ax >= 0 && ax < h && ay >= 0 && ay < w) {
            if (a[ax][ay] == '#') num++;
          }
          a[i][j] = '0' + num; // charの0と数字で数字が文字列になる(説明として正しいかは知らんけどそういうことが起こる)
        }
      }
    }
  }
  rep(i,h) cout << a[i] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

bool is_prime(int n){
    if (n <= 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    const int limit = min(((int)sqrt(n))+1,n);
    for(int i = 3;i <= limit;i+=2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}

int main(void){
    fast_io();
    
    ll x;
    cin >> x;

    while(!is_prime(x)){
        x++;
    }

    cout << x << endl;
    
    return 0;
}


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

int main(){
  int N;
  string S;
  bool four = false;
  
  cin >> N;
  
  for (int i=0; i < N; i++){
    cin >> S;
    if (S=="Y"){
      four = true;
      break;
    }
  }
  if (four){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
blood = dict(zip(["A","B","AB","O"],[0,0,0,0]))

while(1):
    try:
        i,j = [k for k in input().split(",")]
        for k in ["A","B","AB","O"]:
            if j == k:
                blood[k] = blood[k] + 1
    except EOFError:
        print(blood["A"]);print(blood["B"]);print(blood["AB"]);print(blood["O"])
        break



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

using namespace std;

int main()	{
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')	{
  	cout << "vowel" << endl;
  }
  else	{
    cout << "consonant" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

	char a,b;

	scanf("%s", &a);

	if(a=='A'){
		b = 'T';
	}
	if(a=='T'){
		b = 'A';
	}
	if(a=='G'){
		b = 'C';
	}
	if(a=='C'){
		b = 'G';
	}
	

	printf("%c\n",b);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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

using namespace std;

int main(){
    string str;
    cin >> str;
    string case1(str.size(), '0'), case2(str.size(), '1');
    long count1, count2;
    count1 = count2 = 0;

    rep(i, str.size()){
        if ( i % 2 ){
            case1[i] = '1';
            case2[i] = '0';
        }
        if (str[i] != case1[i])     count1++;
        if (str[i] != case2[i])     count2++;
    }

    cout << min(count1, count2) << endl;

    return 0;
}



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

using namespace std;

const int MAX_N = 100005;
vector<int> table[MAX_N];

int escape_d[MAX_N];
int chase_d[MAX_N];

int dfs(int node, int par, int dis, bool is_e) {
  if (is_e) escape_d[node] = dis;
  else chase_d[node] = dis;
  
  for (int next : table[node]) {
    if (next == par) continue;
    dfs(next, node, dis + 1, is_e);
  }
}

int main() {
  int N, escape, chase;
  cin >> N >> escape >> chase;
  escape--;
  chase--; 
  
  for (int i = 0; i < N-1; i++) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    table[s].push_back(t);
    table[t].push_back(s);
  }
  
  dfs(escape, -1, 0, true);
  dfs(chase, -1, 0, false);

  int goal_node = -1;
  int goal_dis = -1;
  
  for (int i = 0; i < N; i++) {
    if (escape_d[i] < chase_d[i] && chase_d[i] > goal_dis) {
      goal_dis = chase_d[i];
      goal_node = i;
    }
  }
  
  if (escape_d[chase] == 1) {
    if (table[escape].size() == 1) {
      goal_dis = 0;
    }
  } else {
    goal_dis--;
  }
  
  cout << goal_dis << endl;
  return 0;
}

Measured memory_bytes: 11648