akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			int n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			int ans = 0;
			for (int i = 1; i <= n; i++) {
				if (a[i - 1] > i && a[a[i - 1] - 1] == i) {
					++ans;
				}
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 35744
//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
ll x,y,a,b;
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>x>>y>>a>>b;
    x=min(y,b)-max(x,a);
    if(x>0)cout<<x;
    else cout<<0;
    return 0;
}


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


int main() {
    int a,b,c;
    cin >>a>>b>>c;
    if((a==b or b==c or c==a)&&!(a==b and b==c)){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(ite, x) for (int ite = 0; ite < (int)(x); ite++)
#define FOR(ite, a, done) for (int ite = (a); ite < (done); ++ite)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n,m,x;
	cin>>n>>m>>x;
	vector<vector<int>>skill(n,vector<int>(m));
	vector<int>cost(n);
	rep(ite,n){
		
		cin>>cost[ite];
		rep(j,m){
			cin>>skill[ite][j];
		}
	}
	int ite=0;
	int ans=1e9;
	while(ite<pow(2,n)+1){
		vector<int>skt(m);
		int ct=0;
		rep(j,n){
			if(ite&(1<<j)){
				ct+=cost[j];
				rep(k,m){
					skt[k]+=skill[j][k];
				}
			}
		}
		bool ok=true;
		rep(j,m){
			if(skt[j]>=x){

			}else{
				ok=false;
			}
		}
		if(ok){
			ans=min(ans,ct);
		}
		ite++;
	}
	if(ans<1e9){
		cout<<ans<<endl;	
	}else{
		cout<<-1<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 4092
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main implements Comparator<Main> {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.nextLine()) ;

		while (sc.hasNextLine()){

			String[] nums = sc.nextLine().split(" ");
			String[] colors = sc.nextLine().split(" ");

			ArrayList<Main> tehuda = new ArrayList<Main>();

			for(int j = 0;j < nums.length; j++ ) {
				Main card = new Main(Integer.parseInt(nums[j]), colors[j]);
				tehuda.add(card);
			}
			Collections.sort(tehuda, new Main());


			ArrayList<Integer> cardSet = new ArrayList<Integer>();
			ArrayList<ArrayList<Integer>> cSetList = new ArrayList<ArrayList<Integer>>();


			String checkColor = tehuda.get(0).getColor();
			cardSet.add(tehuda.get(0).getNum());
			for(int j = 1;j < tehuda.size();j++) {
				if(!(tehuda.get(j).getColor().equals(checkColor))) {
					cSetList.add(cardSet);
					cardSet = new ArrayList<Integer>();
					checkColor = tehuda.get(j).getColor();
				}

				cardSet.add(tehuda.get(j).getNum());
				if(j == tehuda.size() - 1) {
					cSetList.add(cardSet);
				}


			}

			int point = 0;


			for(int j = 0;j < cSetList.size(); j++) {
				

				if(cSetList.get(j).size() >= 6) {
					if(cSetList.get(j).get(0)  == cSetList.get(j).get(1) && cSetList.get(j).get(2) == cSetList.get(j).get(3) && cSetList.get(j).get(4) == cSetList.get(j).get(5) ){
						point += 2;
					}
				}
				if(cSetList.get(j).size() == 9) {
					if(cSetList.get(j).get(3)  == cSetList.get(j).get(4) && cSetList.get(j).get(5) == cSetList.get(j).get(6) && cSetList.get(j).get(7) == cSetList.get(j).get(8) ){
						point += 2;
					}
				}

				for(int y = 0;y < cSetList.get(j).size() -2;y++){
					int num1 = cSetList.get(j).get(y);
					int num2 = cSetList.get(j).get(y + 1);
					int num3 = cSetList.get(j).get(y + 2);
					if((num1 + 1 == num2 && num1 + 2 == num3 ) || (num1 == num2 && num1 == num3)) {
						point++;
						y += 2;
					}
				}


			}
			if(point == 3) {
				System.out.println("1");
			} else {
				System.out.println("0");
			}
		}
		sc.close();

	}

	private int num;
	private String color;

	//??????????????????????????????
	Main (int num, String color) {
		this.num = num;
		this.color = color;
	}

	Main() {
	}

	public int getNum() {
		return this.num;
	}

	public String getColor () {
		return this.color;
	}

	@Override
	public  int compare(Main card1 ,Main card2) {
		int num1 = card1.getNum();
		int num2 = card2.getNum();
		String color1 = card1.getColor();
		String color2 = card2.getColor();

		if(color1.compareTo(color2) > 0 && num1 > num2) {
			return 2;
		} else if (color1.compareTo(color2) > 0) {
			return 1;
		} else if (color1.compareTo(color2) == 0 && num1 > num2) {
			return 0;
		} else if (color1.compareTo(color2) == 0 ) {
			return -1;
		} else if (color1.compareTo(color2) < 0 && num1 > num2) {
			return -2;
		} else {
			return -3;
		}

	}


}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int h,w;
    cin >> h>>w;
    string buf;
    rep(i,h){
        cin >>buf;
        cout << buf << endl <<buf<<endl;
    }
}

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

int v[100][100];

signed main()
{
  int n;
  int u, k;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int tmp;
      cin >> tmp;
      v[u - 1][tmp - 1] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == n - 1) cout << v[i][j] << endl;
      else cout << v[i][j] << " ";
    }
  }

  return (0);
}

Measured memory_bytes: 3104
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
from collections import Counter
def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

N =        int( stdin.readline().strip() )

alphabet = [chr(ord('a') + i) for i in range(26)]
have = None
for i in range(N):
    here = Counter(stdin.readline().strip())
    if i == 0:
        have = here
    else:
        others = set(alphabet)
        for c, count in here.items():
            have[c] = min(have[c], count)
            others.remove(c)
        for c in others:
            have[c] = 0

rr = []
for c in alphabet:
    rr.append(c * have[c])

print ''.join(rr)



Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> L(M);
    vector<int> R(M);
    for(int i=0; i<M; i++) {
        cin >> L.at(i) >> R.at(i);
    }
    int ans = max(*min_element(R.begin(), R.end()) - *max_element(L.begin(), L.end()) + 1, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h" // {{{
using namespace std;
#define val         const auto
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define X           first
#define Y           second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      ((long long)(1e##p))
#define FILL(a,v)   memset((a), (v), sizeof(a))
#define FAST()      ios::sync_with_stdio(false), cin.tie(nullptr)
#ifndef DEBUG
#define debug(...)
#define show(x)
#define show2(x,y)
#define LN()
#endif
typedef long long ll;
typedef pair<int,int> pii;
namespace ydk{
TMPLT(T,U) inline bool chmax(T &a, U b){return b>a ? a=b,1 : 0;}
TMPLT(T,U) inline bool chmin(T &a, U b){return b<a ? a=b,1 : 0;}
TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y)
{ return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
constexpr int INF   = 0x3f3f3f3f;
constexpr ll LINF   = 0x3f3f3f3f3f3f3f3fLL;
// }}}

constexpr int MX = ten(5) + 10;

void Xx_main_xX(const int argc, char *argv[])
{
    int N;
    int a[105];
    cin >> N;
    int sum = 0;
    rep(i, N) {
        cin >> a[i];
        sum += a[i];
    }

    double ave = (double)sum / N;
    int ans = 0;
    rep(i, N) {
        if (fabs(ave - a[ans]) > fabs(ave - a[i])) {
            ans = i;
        }
    }
    outl(ans);
    return;
}

} // {{{

signed main(int argc, char *argv[]){cout << fixed << setprecision(9); ydk::Xx_main_xX(argc, argv); return 0;} // }}}



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

long long int gcd(long long int a, long long int b) {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

int main() {
    long long int a, b;
    while(cin >> a) {
        cin >> b;
        cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
n = int(input())
li = list(map(int,input().split()))
li.sort()
from collections import Counter
a = dict(Counter(li))
#print(a)
num = 0
for k,v in a.items():
    #print(k,v)
    if k < v:
        num += (v-k)
    elif k > v:
        num += v
print(num)

Measured memory_bytes: 21232
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);
ll modadd(ll x, ll y) {
  return (x%mod + y%mod)%mod;
} 
ll modmul(ll x, ll y) {
  return (x%mod * y%mod)%mod;
}
const ll MOD  = (ll)(1e9+7);
ll fast_exp(ll base, ll exp) {
  ll res=1;
  while(exp>0) {
    if(exp%2==1) res=(res*base)%MOD;
      base=(base*base)%MOD;
      exp/=2;
  }
  return res%MOD;
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  vll a(n);
  vector<vll> sb(n+1, vll(61, 0));
  for(auto &it : a) cin >> it;
  for(ll i = n-1; i >= 0; i--) {
    for(ll j = 0; j < 60; j++) {
      sb[i][j]+= sb[i+1][j];
      if(a[i]&(1ll<<j)) sb[i][j]++;
    }
  }
  ll ans = 0;
  for(ll i = 0; i < n; i++) {
    for(ll j = 0; j < 60; j++) {
      if(a[i]&(1ll<<j)) {
        ll tot = (n - (i+1));
        ans= modadd(ans, modmul((tot - (sb[i+1][j])), fast_exp(2, j)));
      } else {
        ans= modadd(ans, modmul(sb[i+1][j], fast_exp(2, j)));
      }
    }
  }
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 155008
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  string s;cin>>s;
  int count=0;
  for(int i=0;i<n-2;i++)
  	if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
      count++;
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	char a[51];
	char b[51];
	char c[101];
	int x,y,z;
	int i;
	cin>>a;
	cin>>b;
	x=strlen(a);
	y=strlen(b);
	z=x+y;
	int h,r;
	h=0;
	r=0;
	for(i=1;i<=z;i++){
		if(i%2!=0){
			c[i-1]=a[h];
			h++;
		}
		else{
			c[i-1]=b[r];
			r++;
		}
	}
	c[z]='\0';
	cout<<c<<endl;
	return 0;
}
			

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,m;
    cin>>n>>m;
    priority_queue<ll> q;
    rep(0,i,n){
        ll a;
        cin>>a;
        q.push(-a);
    }
    vector<pair<ll,ll>>b(m);
    rep(0,i,m){
        cin>>b[i].first>>b[i].second;
    }
    sort(b.rbegin(),b.rend());
    rep(0,i,m){
        ll x=-b[i].first,y=-b[i].second;
        ll a=q.top();
        if(a>y){
            q.pop();
            q.push(y);
            rep(0,i,abs(x)-1){
                if(q.top()>y){
                    q.pop();
                    q.push(y);
                }else{
                    break;
                }
            }
        }
    }
    ll ans=0;
    while(!q.empty()){
        ans-=q.top();
        q.pop();
    }
    cout<<ans;
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t A,V,B,W,T; cin>>A>>V>>B>>W>>T;

    string ans="YES";
    if(abs(A-B)>(V-W)*T) ans="NO";
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
n,x = map(int,input().split())
lst = []
for _ in range(n):
    p = int(input())
    lst.append(p)
ing = x -(sum(lst))
mini = 10**5
for i in range(n):
    if lst[i] <= mini:
        mini = lst[i]
print(ing//mini+n)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m;
    cin>>n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ans+= gcd(gcd(i,j),k);
            }
            
        }
        
    }
    
    cout<<ans;

    return 0;
}







Measured memory_bytes: 3648
#include <vector>
#include <string>
#include <iostream>
using namespace std;
string next_str(string s) {
	vector<bool> used(26);
	for (int i = 0; i < s.size(); ++i) {
		used[s[i] - 'a'] = true;
	}
	for (char i = s.back() + 1; i <= 'z'; ++i) {
		if (!used[i - 'a']) {
			s.back() = i;
			return s;
		}
	}
	return "-1";
}
int main() {
	string s;
	cin >> s;
	if (s.size() != 26) {
		vector<bool> used(26);
		for (int i = 0; i < s.size(); ++i) {
			used[s[i] - 'a'] = true;
		}
		for (int i = 0; i < 26; ++i) {
			if (!used[i]) {
				cout << s + (char)(i + 'a') << endl;
				break;
			}
		}
	}
	else {
		string ans = "-1";
		for (int i = s.size(); i >= 1 && ans == "-1"; --i) {
			ans = next_str(s.substr(0, i));
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 888
#define DEBUG 0

/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-6-2 20:42:31
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}

void No()
{
  cout << "No" << endl;
  exit(0);
}

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

// const ll MOD = 1000000007;

string S;
int A, B, C, D, N;

bool solve(int X, int Y)
{
  for (auto i = X; i < Y - 2; i++)
  {
    if (S[i + 1] == '#' && S[i + 2] == '#')
    {
      return false;
    }
  }
  return true;
}

bool solve2(int X, int Y, int Z, int W)
{
  for (auto i = Z; i <= W; i++)
  {
    if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.')
    {
      S[i] = '#';
      return solve(X, Y);
    }
  }
  return false;
}

int main()
{
  cin >> N >> A >> B >> C >> D >> S;
  A--;
  B--;
  C--;
  D--;
  if (C < D)
  {
    if (solve(A, C) && solve(B, D))
    {
      Yes();
    }
    No();
  }
  if (solve(B, D) && solve2(A, C, B, D))
  {
    Yes();
  }
  No();
}

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

int main(){
  int n,ans;
  cin >> n;
  vector<int> v(n),c(n);
  for(int i = 0;i < n;i++){
    cin >> v.at(i);
  }
  for(int i = 0;i < n;i++){
    cin >> c.at(i);
  }
  ans = 0;
  vector<int> juel(n);
  for(int i = 0;i < n;i++){
    juel.at(i) = v.at(i) - c.at(i);
    if(juel.at(i) >= 0){
      ans += juel.at(i);
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <stack>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;


int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N;
	cin >> N;
	int ansMap[N+1][N+1];
	for(int i=0; i<N+1; i++) 
		for(int j=0; j<N+1; j++)
			ansMap[i][j] = -1;

	for(int i=1; i<=N; i++) {
		int a;
		cin >> a;
		for(int j=0; j<a; j++) {
			int x, y;
			cin >> x >> y;
			ansMap[i][x] = y;
		}
	}
	// for(int i=0; i<N+1; i++) {
	// 	cout << "[deb] ";
	// 	for(int j=0; j<N+1; j++)
	// 		cout << ansMap[i][j];
	// 	cout << endl;
	// }

	int ans = 0;
	for(int i=1; i<(1<<N); i++) {
		// cout << "[deb] pattern " << i << endl;

		int test[N+1]; 
		for(int j=0; j<N+1; j++) test[j] = -1;

		stack<int> idxList;
		{
			int idx = 1, j=i;
			while(j) {
				if(j & 1) {
					test[idx] = 1;
					idxList.push(idx);
				}
				j = j >> 1;
				idx++;
			}
		}

		bool isWrong = false;
		set<int> idxSet;

		while(idxList.size() > 0) {
			int idx = idxList.top();
			idxList.pop();
			if(idxSet.find(idx) != idxSet.end()) continue;
			idxSet.insert(idx);
			for(int k=0; k<=N; k++) {
				if(ansMap[idx][k] == -1) continue;
				if(test[k] == -1) {
					test[k] = ansMap[idx][k];
					if(ansMap[idx][k] == 1) idxList.push(k);
				} else if(test[k] != ansMap[idx][k]) {
					isWrong = true;
					break;
				}
			}
		}

		// output
		// for(int j=1; j<N+1; j++) {
		// 	cout << " " << test[j];
		// }
		// cout << endl;

		// check
		if(isWrong) continue;

		// output
		int tmp = 0;
		for(int j=1; j<N+1; j++) {
			if(test[j] == 1) tmp++;
		}
		ans = max(ans, tmp);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
calc :: String -> String -> String -> Int
calc op a b
  | op == "+" = toI a + toI b
  | op == "-" = toI a - toI b
  | op == "*" = toI a * toI b
  | op == "/" = floor $ toD a / toD b
  where
    toI n = (read n :: Int)
    toD n = (read n :: Double)

main = do
    line <- getLine
    let [a, op, b] = words line
    if op == "?" then
        return ()
    else do
        print $ calc op a b
        main


Measured memory_bytes: 4176
#include<stdio.h>

int S[100000],T[100000],n;

int binarysearch(int key)
{
	int left=0;
	int mid=0;
	int right=n;

	while(left<right)
	{
		mid=(left+right)/2;

		if(S[mid]==key)
		{
			return 1;
		}
		else if(key<=S[mid])
		{
			right=mid;
		}
		else
		{
			left=mid+1;
		}
	}
	return 0;
}
int main()
{
	int i,j,q,c=0;

	scanf("%d",&n);

	for(i=0; i<n; i++)
	{
		scanf("%d",&S[i]);
	}

	scanf("%d",&q);

	for(i=0; i<q; i++)
	{
		scanf("%d",&j);
		if(binarysearch(j))
		{
			c++;
		}
	}
	printf("%d\n",c);

	return 0;
}







Measured memory_bytes: 2128
#include <bits/stdc++.h>
 
using namespace std;
 
 
int main(){
    int h, n;
    cin >> h;
    cin >> n;
  	int d = 0;  
  	for (int i = 0; i < n; i++)
    {	
      	int a = 0;
    	cin >> a;
      
        d = d + a;
    }
    if(d>=h){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main(void){
  int i, count, temp, max;
  int *x, *y;

  max = 3000;
  count = 0;
  x = (int *)malloc(sizeof(int)*max);
  y = (int *)malloc(sizeof(int)*max);

  for(i=0;i<max;i++){
    x[i] = 0;
    y[i] = 0;
  }

  while(1){
    scanf("%d %d", &x[count], &y[count]);
    if(x[count]==0 && y[count]==0){
      break;
    }
    if(x[count] > y[count]){
      temp = x[count];
      x[count] = y[count];
      y[count] = temp;
    }
    count++;
  }

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

  return 0;

}



Measured memory_bytes: 2032
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;


string toStr(int n){
    string str;
    if(n == 0) return "0";
    int len = static_cast<int>(log10(n));
    int K = 1;
    rep(i,len) K*=10;
    rep(i,len + 1){
        if(n / K == 0) str+= '0';
        else str+= ('0' + n / K);
        n%=K; K/=10;
    }
    return str;
}

int toNum(string str){
    int num = 0, K = 1;
    for(int i = str.size() - 1; i >= 0; i--){
        num+=(str[i] - '0') * K;
        K*=10;
    }
    return num;
}

int kakezan(string a, string b){
    return toNum(a) * toNum(b);
}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        int maxi;
        int k = 0;
        string s;
        cin >> s;
        while(k != 1000000){
            maxi = 0;
            if(s.size() == 1) break;
            range(j,1,s.size()){
                maxi = max(maxi, kakezan(s.substr(0,j), s.substr(j, s.size()  - j)));
            }
            s = toStr(maxi);
            k++;
        }
        if(k == 1000000) cout << -1 << endl;
        else cout << k << endl;
    }
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

inline bool bit(const ll &x, const int &k) { return x >> k & 1; }

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

    ll a, b;
    cin >> a >> b;
    if(a == b) {
        cout << 1 << endl;
        return 0;
    }

    int x = 60;
    while(bit(a, x) == bit(b, x))
        x--;
    a &= (2LL << x) - 1;
    b &= (2LL << x) - 1;

    ll ans = 0;

    int y = x;
    while(y && !bit(b, y - 1))
        y--;
    ans += 1LL << y;
    ans += (1LL << x) - a;
    chmin(ans, 1LL << x);
    ans += (1LL << x) - a;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
num = gets.chomp.to_i
card = gets.chomp.split.map(&:to_i)
card.sort!.reverse!
#p card
a,b = 0,0
num.times do |i|
    if i % 2 == 0
        a += card[i]
    else
        b += card[i]
    end
end

puts a-b

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

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

    int fx = 0;
    for (int i =0; i<x.size();i++)
    {
        fx += x.at(i) - '0'; 
    }

    if (stoi(x)% fx == 0)
    cout<< "Yes"<<endl;
    else 
    cout << "No"<<endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,ans=0,tmp;
    int d[100];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&d[i]);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(d[i] < d[j]){
                tmp = d[j];
                d[j] = d[i];
                d[i] = tmp;
            }
        }
    }
    for(int i=0;i<n-1;i++){
        if(d[i] > d[i+1]) ans++;
    }
    printf("%d\n",ans+1);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
p = [[] for i in range(N)]

for i in range(N):
    p[i] = list(map(int,input().split()))

p = sorted(p, key=lambda x: x[2], reverse=True)

ok = False
for cx in range(101):
    for cy in range(101):
        x, y, h = p[0]
        H = h + abs(cx - x) + abs(cy - y)
        ok = True
        for i in range(1, N):
            x, y, h = p[i]
            if h != max(H - abs(cx - x) - abs(cy - y), 0):
                ok = False
                break
        if ok:
            print(cx, cy, H)
            break
    if ok:
        break


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

int main(){
  int n, q, query, t, x, s;
  cin >> n >> q;
  vector<list<int>> L(n);
  for(int i = 0; i < q; i++){
    cin >> query;
    if(query == 0){
      cin >> t >> x;
      L[t].push_back(x);
    }else if(query == 1){
      cin >> t;
      bool flag = true;
      for(int i : L[t]){
        if(flag){
          cout << i;
          flag = false;
        }else{
          cout << " " << i;
        }
      }
      cout << endl;
    }else{
      cin >> s >> t;
      L[t].splice(L[t].end(), move(L[s]));
    }
  }
  return 0;
}



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

using namespace std;

const int N = 1e5 + 5, mod = 1e9 + 7;

int s[N], x, n;
int dp[2][N];

void add(int & var, int val) {
  var += val;
  if (var >= mod)
    var -= mod;
}

int main() {
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; ++i)
    scanf("%d", s+i);
  sort(s, s+n);
  int c = 0, b = 1;
  for (int i = 0; i < s[0]; ++i) {
    dp[c][i] = i;
  }
  for (int i = 0; i < n; ++i) {
    swap(c, b);
    fill(dp[c], dp[c]+x+1, 0);
    int now = s[i];
    for (int j = 0; j < now && j + now <= x; ++j) {
      dp[c][j+now] = dp[b][j];
    }
    for (int j = 0; j + now <= x; ++j)
      add(dp[c][j+now], dp[c][j]);
    for (int j = 0; j < now; ++j) {
      add(dp[c][j], 1LL * (i + 1) * dp[b][j] % mod);
    }
    for (int j = now; j <= x; ++j) {
      add(dp[c][j], 1LL * i * dp[b][j] % mod);
    }
  }
  printf("%d\n", dp[c][x]);
  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,(n))
#define MAX_line 40

int stat[MAX_line];
char N[MAX_line];

bool input(){
  REP(i,MAX_line)stat[i]=0;
  REP(i,MAX_line)N[i]=' ';
  cin>>N;
  return (N[0]!='#');
}

void solve(){
  for(int i=0;N[i]!='\0';i++){
    stat[i]=2;
    switch(N[i]){
      case 'y':
      case 'u':
      case 'i':
      case 'o':
      case 'p':
      case 'h':
      case 'j':
      case 'k':
      case 'l':
      case 'n':
      case 'm':
          stat[i]=1;
          break; 
	}
  }
    int c=0;
    for(int i=0;stat[i+1]!=0;i++){
      if(stat[i]!=stat[i+1])c++;
    }
  
    cout<<c<<endl;
}


int main(){
  while(input()){
	  solve();
  }
}



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

int main()
{
  string S, T;
  cin >> S >> T;
  
  int Total = 0;
  
  for (int i = 0; i < S.size(); i++)
  {
    if (S[i] != T[i])
    {
      Total++;
    }
  }
  
  cout << Total << endl;
}

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

int main(){
  int n, k, q;
  cin >> n >> k >> q;
  
  vector<int> a(n, 0);
  
  for(int i=0; i < q; i++){
  	int tmp;
    cin >> tmp;
    a.at(tmp-1)++;
  }
  
  for(int i=0; i < n; i++){
    if(k - q + a.at(i) > 0)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  
}

Measured memory_bytes: 1024
import java.util.*

fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val S = sc.next()
        pw.println(S + if (S.endsWith("s")) "es" else "s")
    }
}


Measured memory_bytes: 37692
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
 
#define pi 3.1415926535

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

  vector<int> a(10001,0);

  for(int x = 1; x < 100; x++){
    for(int y = 1; y < 100; y++){
      for(int z = 1; z < 100; z++){
        int i = x*x + y*y + z*z + x*y + y*z + z*x;
        if(i <= 10000){
          a[i]++;
        }
      }  
    }
  }

  for(int j = 1; j <= N; j++){
    cout << a[j] << endl;
  }

  return 0; 
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
  int x=0,y=0;
  int ans=0;
  scanf("%d",&x);
  int yama[x];
  for (int i = 0; i < x; i++) {
    scanf("%d",&yama[i]);
  }
  for (int i = 0; i < x; i++) {
    if (yama[i]>=y) {
      ans++;
      y=yama[i];
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int i, x, n;

	scanf("%d", &n);

	for ( i = 1; i <= n; i++){
		x = i;
		if (x % 3 ==0){
			printf(" %d", i);
		} else {
			do {
				if (x % 10 == 3){
					printf(" %d", i);
					break;
				} else {
					x = x / 10;
				}
			} while (x);
		}
	}
	printf("\n");

}



Measured memory_bytes: 2140
/*
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;
 
int main()
{
    int ans=0;
    string s;
    cin>>s;
    char x=s[0];
    for(char c:s) if(c!=x) x=c,ans++;
    cout<<ans<<endl;

    return 0;
}

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

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

	int N; cin >> N;
	bool a[1100];
	fill(a+1, a+N+1, true);
	long long ans = 1;
	int z = 2;
	while (z <= N) {
		if (a[z] == true) {
			int i = 2;
			long long c = 2;
			while (i*z <= N) {
				a[z * i] = false;
				i++;
				c++;
			}
			int fo = z;
			while (fo * z <= N) {
				fo *= z;
				c += N / fo;
			}
			ans *= c;
			ans %= 1000000007;
		}
		z++;
	}
	cout << ans;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  double res = 0;
  for (int i = 0; i < N; i++){
    double x;
    cin >> x;
    string u;
    cin >> u;
    if (u == "JPY"){
      res += x;
    } else {
      res += x * 380000;
    }
  }
  cout << res;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int amaru = (a + b) % 2;
        if (amaru == 0) {
            System.out.println((a + b) / 2);
        } else {
            System.out.println((a + b) / 2 + 1);
        }
    }
}

Measured memory_bytes: 21204
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, x] <- map read.words <$> getLine :: IO [Int]
    xs <- U.unfoldrN n (C.readInt.C.dropWhile isSpace) <$> C.getLine
    print $ solve x xs

solve :: Int -> U.Vector Int -> Int
solve x xs = U.foldl gcd 0 $ U.map (subtract x) xs

-------------------------------------------------------------------------------
type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

Measured memory_bytes: 10620
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, C: int, B: "List[int]", A: "List[List[int]]"):
    a=0
    for j in range(N):
        s=0
        for i in range(M):
            s += A[j][i]*B[i]
        if s > (-1)*C:
            a += 1
    print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    A = [[int(next(tokens)) for _ in range(M)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, M, C, B, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int x,y;
  cin>>x>>y;

                //  0,1,2,3,4,5,6,7,8,9,0,1,2
  vector<int> g = {-1,1,3,1,2,1,2,1,1,2,1,2,1};

  if(g[x]==g[y]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll X;
  cin >> X;
  if (X >= 30) {
    cout << "Yes" << "\n";
  }
  else {
    cout << "No" << "\n";
  }
}


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

const int DIM = 1e5 + 5;

long long arr1[DIM], arr2[DIM];

int main(void)
{
    int n; cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> arr1[i] >> arr2[i];
    
    long long ans = 0;
    for (int i = n; i >= 1; --i) {
        arr1[i] += ans;
        
        if (arr1[i] % arr2[i] == 0)
            continue;
        
        ans += (arr1[i] / arr2[i]) * arr2[i] + arr2[i] - arr1[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>

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

    int a[n];
    for(int i = n-1; i >= 0; i--) scanf(" %d", &a[i]);

    for(int i = 0; i < n-1; i++) printf("%d ", a[i]);
    printf("%d\n", a[n-1]);

    return 0;
}



Measured memory_bytes: 2692
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w; cin >> h >> w;
    vvll a(h, vll(w)), b(h, vll(w));
    REP(i, h) REP(j, w) cin >> a[i][j];
    REP(i, h) REP(j, w) cin >> b[i][j];
    V< vvll > dp(h, vvll(w, vll(160 * 80 + 1)));
    dp[0][0][abs(a[0][0] - b[0][0])] = 1;
    REP(i, h) REP(j, w) {
        REP(k, 160 * 80 + 1) {
            if (i - 1 >= 0) {
                if (dp[i - 1][j][k] == 1) {
                    dp[i][j][k + abs(a[i][j] - b[i][j])] = 1;
                    dp[i][j][abs(k - abs(b[i][j] - a[i][j]))] = 1;
                }
            }
            if (j - 1 >= 0) {
                if (dp[i][j - 1][k] == 1) {
                    dp[i][j][k + abs(a[i][j] - b[i][j])] = 1;
                    dp[i][j][abs(k - abs(b[i][j] - a[i][j]))] = 1;
                }
            }
        }
    }
    REP(i, 160 * 80 + 1) {
        if (dp[h - 1][w - 1][i] == 1) {
            cout << i << '\n';
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 648704
//#include <bits/stdc++.h>
#include<iostream>
#include<numeric>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<ctype.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

int ctoi(char c) {
  if('0'<=c && c <= '9') return c-'0';
  return 0;
}

int main(){
  long int n=0;
  cin >> n;
  long long int ans = (n*2)/gcd(n,2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

shuffle :: Int -> String -> String
shuffle h cs = (drop h cs) ++ (take h cs)

shuffles :: [Int] -> String -> String
shuffles (h:hs) cs
    | length (h:hs) == 1 = shuffle h cs
    | otherwise          = shuffles hs (shuffle h cs)

main :: IO()
main = do
    cs <- getLine
    if (cs == "-")
    then return ()
    else do
        m <- read <$> getLine
        hs <- replicateM m (read <$> getLine)
        putStrLn $ shuffles hs cs
        main

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

using namespace std;

int main(){
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  
  if(S == U) A--;
  else B--;
  
  cout << A << ' ' << B << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define MAX 1000003
#define pii pair<ll,ll>
#define VP vector< pii >
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(ll (i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define S2(x,y) scanf("%d%d",&(x),&(y))
#define SL(x) scanf("%lld",&(x))
#define SL2(x) scanf("%lld%lld",&(x),&(y))
#define P(x) printf("%d\n",(x))
#define FF first
#define SS second
using namespace std;

int main(){
	ll n,W;
	cin>>n>>W;
	vector<pair<ll,ll>>pp;
	vector<ll>v(n+1,0),w(n+1,0);
	rep(i,1,n+1)
		{
			ll x,y;
			cin>>x>>y;
			pp.pb(mp(x,y));
		}
	vector<vector<ll>>dp(n+1,vector<ll>(W+1,0));
	sort(all(pp));
	rep(i,1,n+1)
		{
			w[i]=pp[i-1].FF;
			v[i]=pp[i-1].SS;
		}

	rep(i,1,n+1)
		{
			rep(j,1,W+1)
				{
					if(w[i]>j)
							{
								dp[i][j]=dp[i-1][j];
							}
					else
							{
								dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
							}
				}
		}
	// rep(i,1,n+1)
	// 	{
	// 		rep(j,1,W+1)
	// 			{
	// 				cout<<dp[i][j]<<" ";
	// 			}
	// 		cout<<endl;
	// 	}
	cout<<dp[n][W];


 
return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll power(ll x, ll y, ll p) {
    ll res = 1;    x = x % p;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y = y>>1;    x = (x*x) % p;
    } return res;
}
int main()
{
    Imposter

    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ll p=0;
        for(int i=0;i<s.length();i++)
        {
            p=((p%9)+(s[i]-'0')%9)%9;
        }
        if((p%9)==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }
    return 0;
}


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

L = int(input())
A = [int(input()) for _ in range(L)]
dpl = [[10**18]*2 for _ in range(L+1)]
dpl[0][1] = 0
acc = 0

for i in range(1, L+1):
    dpl[i][0] = min(dpl[i-1][0], dpl[i-1][1])+(1 if A[i-1]%2==0 else 0)
    acc += A[i-1]
    dpl[i][1] = acc
    
    if A[i-1]%2==0:
        if A[i-1]>=2:
            dpl[i][1] = min(dpl[i][1], dpl[i-1][1])
        else:
            dpl[i][1] = min(dpl[i][1], dpl[i-1][1]+2)
    else:
        dpl[i][1] = min(dpl[i][1], dpl[i-1][1]+1)
    
acc = 0
dpr = [[10**18]*2 for _ in range(L+1)]
dpr[L][1] = 0

for i in range(L-1, -1, -1):
    dpr[i][0] = min(dpr[i+1][0], dpr[i+1][1])+(1 if A[i]%2==0 else 0)
    acc += A[i]
    dpr[i][1] = acc
    
    if A[i]%2==0:
        if A[i]>=2:
            dpr[i][1] = min(dpr[i][1], dpr[i+1][1])
        else:
            dpr[i][1] = min(dpr[i][1], dpr[i+1][1]+2)
    else:
        dpr[i][1] = min(dpr[i][1], dpr[i+1][1]+1)

ans = 10**18

for i in range(L+1):
    ans = min(ans, dpl[i][0]+dpr[i][1], dpl[i][1]+dpr[i][0], dpl[i][1]+dpr[i][1])

print(ans)

Measured memory_bytes: 95408
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a[5],i,j,swap;
    for(i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<5;i++){
        for(j=4;j>i;j--){
            if(a[j]>a[j-1]){
                swap=a[j];
                a[j]=a[j-1];
                a[j-1]=swap;
            }
        }
    }

        printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
    return 0;
}

Measured memory_bytes: 596
antenna = [int(input()) for i in range(5)]
k = int(input())
judge = ''
i,j = 1,1
for i in range(5):
  for j in range(i+1,5):
    if abs(antenna[i]-antenna[j]) > k:
      judge = ':('
      break

if judge==':(':
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3060