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

using namespace std;

#define ll long long
#define fr(m) for(int i=0; i<m; i++)
#define frj(m) for(int j=0; j<m; j++)
#define frr(n) for(int i=n; i>=0; i--)
#define pb push_back
#define orr ||
#define nl printf("\n")
#define sci(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define pri(n) printf("%d", n); nl
#define prl(n) printf("%lld", n); nl
#define prc(n) printf("%c", n); nl
#define prs printf(" ")
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define debug(arr,n) for(int i=0; i<n; i++) cout<<arr[i]<<" "; nl
#define debugr(arr,s,e) for(int i=s; i<=e; i++) cout<<arr[i]<<" "; nl


int main()
{
    ll r,c;
    cin>>r>>c;
    ll arr[r+1][c+1],sum1=0,sum2[c]={0},fin=0;

    fr(r){
        sum1=0;
        frj(c){
            cin>>arr[i][j];
            sum1+=arr[i][j];
            sum2[j]+=arr[i][j];
        }
        fin+=sum1;
        arr[i][c]=sum1;
    }
    fr(c){
        arr[r][i]=sum2[i];
    }
    arr[r][c]=fin;
    fr(r+1){
        frj(c+1){
            cout<<arr[i][j];
            if(j!=c) prs;
        }
        nl;
    }
    return 0;
}











Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>> a >>b >>c;
    if ((a>=1 && a<=500) && (b>=1 && b<=500) && (c>=1 && c<=1000))
            if (a+b>=c)
                cout<<"Yes";
            else
                cout<< "No";
    else
        cout<< "stop"


    ;return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define rangeOfValue 11000

using namespace std;

void counting_sort(int a[], int b[], int k);

int n;
int A[2000000];
int B[2000000];
int c[rangeOfValue];

int main(){
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>A[i];
    }
    counting_sort(A,B,rangeOfValue);
    for (int i=0; i<n-1; i++) {
        cout<<B[i]<<" ";
    }
    cout<<B[n-1]<<endl;
}

void counting_sort(int a[], int b[], int k){
    for (int i=0 ; i<k; i++) {
        c[i] = 0;
    }

    for (int j=0; j<n; j++) {
        //cout<<c[a[j]]<<endl;
        c[a[j]]=c[a[j]]+1;
    }
    for (int i=1; i<k-1; i++) {
        c[i]=c[i]+c[i-1];
    }
//    for (int i=0; i<10; i++) {
//        cout<<c[i]<<" ";
//    }
//    cout<<endl;
    for (int j=n-1; j>=0; j--) {
        b[c[a[j]]-1] = a[j];
        c[a[j]]--;
    }
}

Measured memory_bytes: 16828
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static List<Integer> getStrings(Scanner sc, int num) {
		List<Integer> stringList = new ArrayList<>();
		while(num>0) {
			int nextInt = sc.nextInt();
			stringList.add(nextInt);
			num--;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		List<Integer> p = getStrings(sc, n);
		if (n == 0) {
			System.out.println(x);
			return;
		}

		int min = 0;
		for (int i = x; i >=0 ; i--) {
			if (!p.contains(i)) {
				min = i;
				break;
			}
		}
		int max = 200;
		for (int i = x; i <= 101 ; i++) {
			if (!p.contains(i)) {
				max = i;
				break;
			}
		}
		if (Math.abs(x-min) == Math.abs(x-max)) {
			System.out.println(min);
			return;
		} else if (Math.abs(x-min) < Math.abs(x-max)) {
			System.out.println(min);
			return;
		} else {
			System.out.println(max);
			return;
		}

	}

}


Measured memory_bytes: 35772
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#define ll long long int 
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
     
	int n,m;
	cin>>n>>m;
	int a[n];
	int i;
	int s=0;
	for(i=0;i<n;i++){
        cin>>a[i];
		s=s+a[i];
	}
	sort(a,a+n,greater<int>());
    float z=4*m;
	float x=(1/z)*s;
	
    if(a[m-1]>=x){
    cout<<"Yes"<<endl;	
	}
	else{
	cout<<"No"<<endl;	
	}
  
    return 0;	
}

Measured memory_bytes: 3608
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aizu1
{
    public class Solution
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            HashSet<string> map = new HashSet<string>();
            StringBuilder output =new StringBuilder();

            while (n-->0)
            {
                string command = Console.ReadLine();
                var tmp = command.Split(' ');
                if (tmp[0] == "insert") map.Add(tmp[1]);
                else output .Append( (map.Contains(tmp[1])) ? "yes\n" : "no\n");
            }

            Console.Write(output);
        }
    }
}

Measured memory_bytes: 47284
n = int(input())
list = list(map(int,input().split()))

list2 = []

o= len(list)
new_list = sorted(list)
max = new_list[o-1]

for i in range(max+1):
    t = sum((i-k)**2 for k in list)
    list2.append(t)

list3 = sorted(list2)

print(list3[0])

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<ctime>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 1e5+3;
const int inf = 1e5;
const int modn = 1e9+7;
const ld eps = 1e-8;
const long double PI = acos(-1.0);
void qRead(ll &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
void qRead(int &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
ll qpow(ll a,ll b,ll mo = modn){
//    printf("%lld\n",mo);
    ll res = 1;
    while(b){
        if(b & 1)res = (res*a) % mo;
        a = (a*a) % mo;
        b >>= 1;
    }
    return res;
}
ld qpow(ld a,ll b){
    ld res = 1;
    while(b){
        if(b & 1)res *= a;
        a = a*a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
//ll vis[maxn],prime[maxn],cnt,smallP[maxn];
//void getPrime(int n){
//    cnt = 0;
//    for(int i = 1;i <= n;i++)vis[i] = 0;
//    for(ll i = 2;i <= n;i++){
//        if(!vis[i]){
//            prime[++cnt] = i;
//            smallP[i] = i;
//        }
//        for(int j = 1;j <= cnt && i*prime[j] <= n;j++){
//            vis[prime[j]*i] = 1;
//            smallP[prime[j]*i] = prime[j];
//            if((i % prime[j]) == 0)break;
//        }
//    }
//}
char s[maxn];
int main(){
    s[0] = '0';
    scanf(" %s",s+1);
//    printf("%s",s);
    for(int i = 2;i < strlen(s);i++){
        if(s[i] == s[i-1]){
            printf("%d %d\n",i-1,i);
            return 0;
        }
        else if(s[i] == s[i-2]){
            printf("%d %d\n",i-2,i);
            return 0;
        }
    }
    printf("-1 -1\n");
}


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

class Vector2{
  public:
  double x, y;
  Vector2(){}
  Vector2(double x, double y): x(x), y(y) {}

  Vector2 operator + (Vector2 v) {
    return Vector2(x + v.x , y + v.y);
  }
  Vector2 operator - (Vector2 v) {
    return Vector2(x - v.x , y - v.y);
  }

  Vector2 operator * (double d){
    return Vector2(d*x, d*y);
  }

};

double dot(Vector2 a, Vector2 b){
  return a.x * b.x + a.y * b.y; 
}

double cross(Vector2 a, Vector2 b){
  return a.x * b.y - a.y*b.x;
}

Vector2 projection(Vector2 a, Vector2 b, Vector2 p){
  Vector2 base = b - a;
  Vector2 hypo = p - a;
  double norm_base = pow(base.x,2) + pow(base.y,2);

  Vector2 x;
  x = a + base*(dot(hypo,base) / norm_base);
  return x;
}

int main(){
  Vector2 a, b, p, x;
  int queri;
  cin >> a.x >> a.y >> b.x >> b.y;
  cin >> queri;
  rep(i,queri){
    cin >> p.x >> p.y;
    x = projection(a,b,p);
    cout << fixed << setprecision(10);
    cout << x.x << " " << x.y << endl;
  }
  
  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,t;
	cin >>a >>b >>t;
	ll sm =0;
	rep2(i, 1, 10000000){
		ll f = (ll)a*i;
		if(f <= t) sm +=b;
		else break;
	}
	cout << sm <<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
 
int main()
 {
	char name1[32],name2[32];

	gets(name1);
	gets(name2);


	int len,i;

	len=strlen(name1);

	for(i=0;i<len+1;i++)
	{
		if(name1[i]!=name2[i]){
			break;
		}

	}

	if(i==len){
		printf("Yes");
	}

	else{
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
#include <atcoder/all>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

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

int main()
{
	int n, m;
	cin >> n >> m;
	dsu d(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		d.merge(a, b);
	}
	map<int, int> mp;
	rep(i, n) {
		mp[d.leader(i)]++;
	}
	int ans = mp.size();
	--ans;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7472
function main(input) {
  input = input.trim();
  const a = input.split("").map(Number);
  if(a[0]==9 || a[1]==9){
  	console.log('Yes');
  }else{
    console.log('No');
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29516
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long sum=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			sum+=i;
		}
	}
	cout<<sum;

	return 0;
}



Measured memory_bytes: 3636
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}


func main() {
    let n = Int(readLine()!)!
    let A = readWords { Int($0)! }

    // ans: a b c d
    // inp: b^c^d a^c^d a^b^d a^b^c
    // b^c^d ^ a^c^d --> a^b
    // a^b^d ^ a^b --> d
    // 他のやつ全部でxorとればOK
    // いったん全部のxor取得 -> それに対して各要素とxorをとる

    let total = A.reduce(0, ^)
    print(A.map { (total^$0).description }.joined(separator: " "))
}


main()

Measured memory_bytes: 26324
N, M = [int(i) for i in input().split()]
PY = []
for i in range(M):
    PY.append([int(i) for i in input().split()])

x = {}

for i in range(len(PY)):
    prefecture = PY[i][0]
    year = PY[i][1]

    if prefecture in x.keys():
        x[prefecture].append((year, i))
    else:
        x[prefecture] = [(year, i)]

for i in x:
    x[i] = sorted(x[i])



for i in x:
    for t in range(len(x[i])):
        PY[x[i][t][1]] = str(i).zfill(6) + str(t + 1).zfill(6)

for py in PY:
    print(py)

Measured memory_bytes: 50016
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  string N;
  cin >> N;
  int ans=0;
  rep(i, 3){
  if(N[i]=='7')
    ans++;
  }
  if(ans>0)
    cout << "Yes"  << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3600
import sys

N = int(input())
nlist = list(map(int, input().split()))

for i in range(N):
    if nlist[i]%2 == 0:
        if nlist[i]%3 != 0 and nlist[i]%5 != 0:
            print('DENIED')
            sys.exit()

print('APPROVED')

Measured memory_bytes: 2940
#include<iostream>
#include<bitset>
#include<string>
#include<algorithm>
#define UP_DIRECTION 3
#define RIGHT_DIRECTION 2
#define DOWN_DIRECTION 1
#define LEFT_DIRECTION 0
using namespace std;
int dy[]={0,1,0,-1},dx[]={-1,0,1,0};
int main(){
    bitset<4>Square[5][5];
    string Wall[9];
    char For_Output[]="LDRU";
    for(int i=0;i<9;i++)cin>>Wall[i];

    for(int i=0;i<9;i+=2){
        Wall[i]="0"+Wall[i]+"0";
        for(int j=0;j<5;j++){
            Square[i/2][j][LEFT_DIRECTION]=(Wall[i][j]-'0');
            Square[i/2][j][RIGHT_DIRECTION]=(Wall[i][j+1]-'0');
        }
    }

    for(int i=1;i<9;i+=2){
        for(int j=0;j<5;j++){
            Square[i/2][j][DOWN_DIRECTION]=(Wall[i][j]-'0');
            Square[i/2+1][j][UP_DIRECTION]=(Wall[i][j]-'0');
        }
    }
    int Direction=RIGHT_DIRECTION;
    int y=0,x=0;

    do{
        int R=Direction-1;
        int L=Direction+1;
        int B=Direction-2;
        if(R<0)R=3;
        if(B<0)B+=4;
        L%=4;
        if(Square[y][x][L])
            Direction=L;

        else if(Square[y][x][Direction]);
        else if(Square[y][x][R])
            Direction=R;
        else Direction=B;

        y+=dy[Direction];
        x+=dx[Direction];
        cout<<For_Output[Direction];
    }while(y!=0||x!=0);
    cout<<endl;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define int long long
const double PI=3.141592653589793238;
double calc(int res,int ans){
  return abs(((double)res/ans)-PI);
}
signed main(){
  double d;
  while(cin>>d,d!=0){
    //cout<<d<<endl;
    int ans=1,res=0;
    while(1){
      res=floor(ans*(PI-d))-1;
      //cout<<res<<" " <<ans<<":"<<calc(res,ans)<<endl;
      while(calc(res,ans)>calc(res+1,ans)) res++;
      if(calc(res,ans)<d) break;
      ans++;
    }
    cout<<res<<"/"<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3036
// finish date: 2018/01/10
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int fact(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans *= i;
    }
    return ans;
}

int main() {
    string s;
    cin >> s;
    replace(s.begin(), s.end(), ',', ' ');
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <climits>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <fstream>
#include <functional>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <iomanip>
#define memtst(x) (sizeof(x) / 1024. / 1024.)
#define mem0(x) memset((x), 0, (sizeof x))
#define meminf(x) memset((x), INF, (sizeof x))
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define pf(x) push_front(x)
#define pq std::priority_queue
#define iter iterator
#define mp(x, y) std::make_pair((x), (y))
#define fst first
#define sec second
#define lc(x) ((x) * 2)
#define rc(x) ((x) * 2 + 1) 
#define md(x, y) (((x) + (y)) / 2)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair <int, int> pii;
const double PI = acos(-1);
const double EPS = 1e-6;
const ll MOD = 1e8 + 7;
const ll INF = 0x3F3F3F3F;
template <typename T>
inline T Abs(T x)
{
    return x < 0 ? x * -1 : x;
}
template <typename T>
inline T Max(T x, T y, T z)
{
    return std::max(std::max(x, y), z);
}
template <typename T>
inline T Min(T x, T y, T z)
{
    return std::min(std::min(x, y), z);
}
template <typename T>
inline T Ckmax(T &x, T y)
{
    return x = std::max(x, y);
}
template <typename T>
inline T Ckmin(T &x, T y)
{
    return x = std::min(x, y);
}
template <typename T>
inline T Sqr(T x)
{
    return x * x;
}
template <typename T>
T Pow(T x, T y, T z)
{
    T r = 1;
    while (y > 0)
    {
        if (y % 2 > 0)
            (r *= x) %= z;
        (x *= x) %= z;
        y /= 2;
    }
    return r % z;
}
template <typename T>
inline T gcd(T x, T y)
{
    return y > 0 ? gcd(y, x % y) : x;
}
template <typename T>
inline T lcm(T x, T y)
{
    return x / gcd(x, y) * y;
}
inline void cinspu(void)
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
}
inline ll read(void)
{
    char x;
    while (x = getchar(), x != '-' && !isdigit(x))
        ;
    char flg = x == '-';
    ll num = (flg ? getchar() : x) - '0';
    while (isdigit(x = getchar()))
        ((num *= 10) += x - '0') %= MOD;
    return flg ? -num : num;
}
const int N = 1e5 + 10;
std::string a;
int main()
{
	cinspu();
	std::cin >> a;
	int ans = 0, f = 0;
	for (auto i : a)
		if (i == '1')
		{
			if (f < 0)
			{
				++ans;
			}
			++f;
		}
		else
		{
			if (f > 0)
			{
				++ans;
			}
			--f;
		}
	std::cout << ans * 2 << std::endl;
	return 0;
}

Measured memory_bytes: 592
Scanf.scanf "%d %d" @@ fun n m ->
let a = Array.make n max_int in
for _=1 to m do
  Scanf.scanf " %d %d" @@ fun i j->
  a.(i-1) <- min a.(i-1) (j-1)
done;
let c = ref 0 in
for i=0 to n-2 do
  if a.(i)=i+1 then c:= !c+1 else
  a.(i+1)<- min a.(i+1) a.(i)
done;
Printf.printf "%d\n" !c


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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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 rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！


const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX]; 
void COMinit() {  //MOD combの計算を行う．COMinitを宣言してから以下のCOMルーチンを実行すればよい
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
int main(){
    ll x,y;
    std::cin >> x>>y;
    COMinit();
    if((x+y)%3!=0||x>2*y||y>2*x){
        std::cout << 0 << std::endl;

    }
    else{
        ll a=(2*x-y)/3,b=(2*y-x)/3;
        std::cout << COM(a+b,a) << std::endl;
    }
}

Measured memory_bytes: 23680
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())
lst = [[] for _ in range(N)]

for i in range(N):
    A = int(input())
    for _ in range(A):
        XY = tuple(map(int, input().split()))
        lst[i].append(XY)


ans = 0
for i in range(2 ** N):
    count = 0
    flag = True
    for j in range(N):
        if (i >> j) & 1: #正直者の時、証言を確認する
            for x, y in lst[j]:
                if y == 1:
                    if (i >> (x - 1)) & 1:
                        continue
                    else:
                        pass
                if y == 0:
                    if (i >> (x - 1)) & 1:
                        pass
                    else:
                        continue
                flag = False
                break
            count += 1
        if not flag:
            break
    if flag:
        ans = max(ans, count)

print (ans)




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

int main(){
  int s,a,b,c;
  cin >> s;
  a = s / 100;
  b = s / 10 - a * 10;
  c = s / 1 - b * 10 - a * 100;
  cout << a + b + c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <list>

using namespace std;

#define ul unsigned long

ul gcd(ul m, ul n) {
	if (n==0) return m;
	return gcd(n, m % n);
}

int main() {
	ul n,m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	
	#ifdef DEBUG
	cout << n << "," <<m << endl;
	cout << s << "|"<<t<<endl;
	#endif

	ul l;
	if (n<=m) l=gcd(m,n);
	else l=gcd(n,m);

	if (l==1) {
		if (s[0]==t[0])	cout << n * m;
		else cout << "-1";
	} else {
		ul lcm=n*m/l;
		bool isGood=true;
		for (ul i=1,j=1,c=0;c<l;c++) {
#ifdef DEBUG
			cout << "|"<< s[i-1] <<","<<t[j-1]; 
#endif

			if (s[i-1]!=t[j-1]) {
				isGood=false;
				break;
			}
			i+=n/l;
			j+=m/l;
		}
		if (isGood) cout << lcm;
		else cout << "-1";

	}

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

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

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int n;
  cin>>n;
  cout << (n)/3 << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using Graph = vector<vector<int>>;
using ll = long long;
using p = pair<int, int>;

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < (int)s.size(); ++i)
    {
        char sc = s[i];
        char tc = t[i];
        if (sc != tc)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        //int N = sc.nextInt();
        String str = sc.nextLine();
        char c[] = str.toCharArray();
        int count = 0;
        
        for(int i = 0; i < c.length; i++){
           if(c[i] == 'x'){
               count++;
           }
        }
        if(count < 8){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
        
    }
}


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

int main(){
  int n,k;
  cin >> n >> k;
  int a = 1;
  for (int i = 0;i<n;i++){
    if (a > k)
      a += k;
    else
      a *= 2;
  }
  cout << a << endl;
}


Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    string s; cin >> s;

    if (n % 2) {
        cout << "No" << endl;
    } else {
        bool ans = true;
        REP(i, n / 2) {
            if (s[i] != s[i + n/2]) {
                ans = false;
            }
        }
        cout << Yes(ans) << endl;
    }
    
}

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

int main() {
  string S, T;
  cin >> S >> T;
  bool can = true;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != T[i]) {
      can = false;
      break;
    }
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int dx = c - a;
    int dy = d - b;
    cout << c - dy << " " << d + dx << " " << a - dy << " " << b + dx << endl;

}

signed main() {
    solve();
}


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

const int DIM = 1e5 + 5;

deque<int> ans; bitset<DIM> oki;
vector<int> edg[DIM];

bool good(int x, bool pos)
{
    for (int y : edg[x]) {
        if (oki[y])
            continue;
        
        oki[y] = true;
        if (pos) ans.push_back(y);
        else     ans.push_front(y);
        
        return false;
    }
    
    return true;
}

int main(void)
{
    int n, m; cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int x, y; cin >> x >> y;
        
        edg[x].push_back(y);
        edg[y].push_back(x);
    }
    
    ans.push_back(1); oki[1] = true;
    while (true) {
        if (good(ans.front(), false) and good(ans.back(), true))
            break;
    }
    
    cout << ans.size() << endl;
    for (int x : ans)
        cout << x << " ";
    
    return 0;
}

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

int main(){
  string p, s;
  cin >> s;
  cin >> p;
  while(s.size() <= 100) s += s;
  if(s.find(p) != string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;
}



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

const int INF = 1 << 30;
vector<vector<int>> T(17);
vector<int> Si(1 << 16, INF);

void init() {
	T[1] = {0b0000000000000000,
			0b1111111111111111,
			0b1010101010101010,
			0b1100110011001100,
			0b1111000011110000,
			0b1111111100000000};

	for(auto t : T[1]) Si[t] = 1;

	for(int k = 2; k <= 16; ++k) {
		for(int t : T[k - 1]) {
			int v = (~t) & ((1 << 16) - 1);
			if (Si[v] == INF) {
				Si[v] = k;
				T[k].push_back(v);
			}
		}

		for(int i = 1; i <= k - 3 - i; ++i) {
			for(auto t1 : T[i]) {
				for(auto t2 : T[k - 3 - i]) {
					int v = t1 & t2;
					if (Si[v] == INF) {
						Si[v] = k;
						T[k].push_back(v);
					}
					v = t1 ^ t2;
					if (Si[v] == INF) {
						Si[v] = k;
						T[k].push_back(v);
					}
				}
			}
		}
	}
}

string S;
int pat;

bool expr(int&);

bool bin(int& i) {
	bool ret = expr(i);
	if (S[i] == '*') {
		++i;
		ret = (expr(i) && ret);
	} else if (S[i] == '^') {
		++i;
		ret = (expr(i) != ret);
	}
	return ret;
}

bool term(int& i) {
	bool ret;
	if (0 <= S[i] - '0' && S[i] - '0' <= 1) {
		ret = S[i] - '0';
	} else if (0 <= S[i] - 'a' && S[i] - 'a' <= 3) {
		ret = (pat >> (S[i] - 'a')) & 1;
	}
	++i;
	return ret;
}

bool expr(int& i) {
	bool ret;
	// assert(S[i] != '*' && S[i] != '^');

	if (S[i] == '(') {
		++i;
		ret = bin(i);
		// assert(S[i] == ')');
		++i;
	} else if (S[i] == '-') {
		++i;
		ret = expr(i);
		ret = !ret;
	} else {
		ret = term(i);
	}
	return ret;
}

bool solve() {
	cin >> S;
	if (S == ".") return false;

	int tab = 0;
	int i;
	for(pat = 0; pat < 16; ++pat) {
		i = 0;
		tab += (expr(i) << pat);
	}
	cout << Si[tab] << endl;
	return true;
}

int main(){
	init();
	while(solve());
	return 0;
}


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


int main() {


    long n;
    cin >> n;

    vector<long> a(n);
    map<long,long> b;
    for(long i=0;i<n;i++){
        cin >> a[i];
        b[a[i]]++;
    }

    long long max_n=0;
    for(auto x : b) {
        if(x.second>=2){
            max_n += x.second * (x.second-1)/2;
        }
    }

    for(long i=0;i<n;i++){
        if(b[a[i]]<2){
            cout << max_n << endl;
        } else{
            cout << max_n - (b[a[i]]-1) << endl;
        }
    }
    
}

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

using namespace std;

int main(){
    int N; cin>>N;
    int K; cin>>K;
    vector<int> V(N+1);
    int value=0,max_value=0;
    int isi=0;

    for(int i=1;i<=N;i++){
        cin>>V[i];//V[1]---V[N]
    }

    vector<int> COPY(N);
    for(int get=1;get<=min(K,N);get++){//get回とる
        for(int left=0;left<=get;left++){//左からleft回
            for(int l=1;l<=left;l++){//実際にとる
                value+=V[l];
                COPY[isi]=V[l];
                isi++;
            }
            for(int r=1;r<=get-left;r++){
                value+=V[N+1-r];
                COPY[isi]=V[N+1-r];
                isi++;
            }
            //K-get回捨てれる(左からleft,右からget-leftの中から-で大きいもの)
            sort(&COPY[0],&COPY[isi]);
            for(int gomi=1;gomi<=min(K-get,isi);gomi++){
                if(COPY[gomi-1]>=0) break;
                value-=COPY[gomi-1];
            }
            if(value>max_value) max_value=value;
            value=0;
            isi=0;
            //printf("%d\n",max_value);
        }
    }
    if(max_value==0) printf("0");
	else printf("%d",max_value);
  
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define vmax_p(v) max_element(v.begin(), v.end())
#define vmin_p(v) min_element(v.begin(), v.end())
#define vmax_idx(v) distance(v.begin(), vmax_p(v))
#define vmin_idx(v) distance(v.begin(), vmin_p(v))
#define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// floor(x): truncate

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

void displayVec(vector<int> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << endl;
    }
    cout << endl;
}

int binarySearch(vector<int> v, int target)
{
    int left = -1;
    int right = v.size();

    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (v[mid] >= target)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }

    if (right < v.size() && v[right] == target)
    {
        return right;
    }
    return -1;
}

int main(int argc, const char *argv[])
{
    ll r, d, x, pre;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++)
    {
        x = r * x - d;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int main(){
    cin>>a;
    while(1){
        if(a%111==0){
            out(a);
            return 0;
        }
        a++;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        Dice dice1 = new Dice();
        Dice dice2 = new Dice();

        for(int i=0;i<dice1.getLength();i++){
            dice1.setNumber(i, sc.nextInt());
        }
        sc.nextLine();

        for(int i=0;i<dice2.getLength();i++){
            dice2.setNumber(i, sc.nextInt());
        }
        sc.nextLine();

        if(dice1.equals(dice2)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

        sc.close();
    }
}

class Dice{
    private int number[];
    private final String patterm = "NNNNWNNNWNNNENNNENNNWNNN";

    Dice(){
        number = new int[6];
    }

    void setNumber(int x, int num){
        number[x] = num;
    }
    int getLength(){
        return number.length;
    }
    int getTop(){
        return number[0];
    }
    int getNumber(int i){
        return number[i];        
    }
    void printArray(int array[]){
        for(int i=0;i<array.length;i++)System.out.printf("%d ", array[i]);
        System.out.println();
    }
    void roll(char d){
        int array[] = new int[number.length];
        switch (d){
            case 'S':
                //roll
                array[0] = number[4];
                array[1] = number[0];
                array[5] = number[1];
                array[4] = number[5];
                //not roll
                array[2] = number[2];
                array[3] = number[3];
                break;
            case 'W':
                array[0] = number[2];
                array[3] = number[0];
                array[5] = number[3];
                array[2] = number[5];

                array[1] = number[1];
                array[4] = number[4];
                break;
            case 'N':
                array[0] = number[1];
                array[1] = number[5];
                array[5] = number[4];
                array[4] = number[0];

                array[2] = number[2];
                array[3] = number[3];
                break;
            case 'E':
                array[0] = number[3];
                array[3] = number[5];
                array[5] = number[2];
                array[2] = number[0];
                
                array[1] = number[1];
                array[4] = number[4];
                break;
        }
        for(int i=0;i<getLength();i++){
            setNumber(i, array[i]);
        }
    }
    boolean equals(Dice another){
        boolean flag;

        for(int i=0;i<patterm.length();i++){
            roll(patterm.charAt(i));
            flag = true;
            for(int j=0;j<6;j++){
                if(this.number[j]!=another.number[j]){
                    flag = false;
                    break;
                }
            }
            if(flag)return true;
        }
        return false;
    }
}


Measured memory_bytes: 26352
#include<iostream>
#include<vector>
#include<map>
using namespace std;
long long Fac(long long a){
  long long b;
  if(a==0) return 1;
  b=Fac(a-1);
  return a*b;
}



int main(){
  long long n;
  cin >> n;
  map<int,int> mp;
  while(n!=1){
    long long a=2;
    int m=n;
    while(a*a<=m){
      if(m%a==0){
	m=m/a;
	mp[a]++;
      }
      else a++;
    }
    mp[m]++;
    n--;
  }
  vector<int> vec(5);
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    if(74<=itr->second) vec[0]++;
    if(24<=itr->second) vec[1]++;
    if(14<=itr->second) vec[2]++;
    if(4<=itr->second) vec[3]++;
    if(2<=itr->second) vec[4]++;
  }
  int ans=vec[0]+vec[1]*(vec[4]-1)+vec[2]*(vec[3]-1)+vec[3]*(vec[3]-1)/2*(vec[4]-2);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
// AOJ 2906 Santa's Gift
// 2018.4.5 bal4u

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()  // 非負整数にしか対応せず
{
	int n = 0, c = gc();
//	while (isspace(c)) c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)  // 非負整数の表示（出力）
{
	int i;
	char b[20];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int dp[10002]; // DP用配列

int main()
{
	int i, a, C, N, M;

	C = in(), N = in(), M = in();
	while (N--) {
		int s = in(), p = in();
		for (i = C; i >= s; i--) {
			if (dp[i] < dp[i - s] + p) dp[i] = dp[i - s] + p;
		}
	}
	for (i = 1; i <= M; i++) {
		a = dp[C / i];
		if (!a) break;
		out(i*a);
	}
	while (i++ <= M) pc('0'), pc('\n');
	return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

using Graph = vector<vector<int>>;

vector<int> t_sort(const Graph& g){
  int n = g.size();
  vector<int> sorted;
  vector<int> in(n, 0);

  for(int v=0; v<n; v++){
    for(const auto& to: g[v]){
      in[to]++;
    }
  }

  queue<int> que;

  for(int i=0; i<n; i++){
    if(in[i] == 0){
      que.push(i);
    }
  }

  while(!que.empty()){
    int now = que.front(); que.pop();
    sorted.emplace_back(now);
    for(const auto& to: g[now]){
      in[to]--;
      if(in[to] == 0){
        que.push(to);
      }
    }
  }

  return sorted;
}

int main(){
  int n, m; cin >> n >> m;
  Graph g(n);
  REP(i, m){
    int x, y; cin >> x >> y;
    x--; y--;
    g[x].emplace_back(y);
  }

  vector<int> sorted = t_sort(g);
  vector<int> dis(n, 0);

  for(const auto& v: sorted){
    for(const auto& to: g[v]){
      dis[to] = max(dis[to], dis[v] + 1);
    }
  }

  cout << *max_element(dis.begin(), dis.end()) << endl;

  return 0;
}


Measured memory_bytes: 6780
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

char dto36(int n){
    if (0 <= n and n <= 9 ) {
        return (char)(n + (int)'0');
    }
    if(10 <= n and n <= 36){
        return (char)(n-10 + (int)'A');
    }
    return '?';
}

int main(){
    int N,M,Q;
    while (cin >> N >> M >>Q && N) {
        if(N==1 and M==1){
            cout << 0 << endl;
            continue;
        }
        int g[N][M];
        for (int i=0;i<N;i++) {
            for (int j=0; j<M; j++) {
                g[i][j]=2;
            }
        }
        string bs="",bb="";
        for (int i=0; i<M; i++) {
            bs += "0";
            bb += "0";
        }
        for (int q=0;q<Q; q++) {
            string s,b;
            cin >> s >> b;
            for (int i=0; i<N; i++) {
                for (int j=0; j<M; j++) {
                    if (s[i]=='1' and b[j]!=bb[j] and g[i][j]!=0) {
                        g[i][j] = 1;
                    }
                    if (s[i]=='0' and b[j]!=bb[j]) {
                        g[i][j] = 0;
                    }
                    if (s[i]=='1' and b[j]==bb[j]) {
                        g[i][j] = 0;
                    }
                    if (s[i]=='0' and b[j]==bb[j] and g[i][j]!=0) {
                        g[i][j] = 1;
                    }
                    
                }
            }
            bs = s;
            bb = b;
        }
        
        for (int i=0; i<M; i++) {
            int ch = 0, rep=-1;
            for (int j=0; j<N; j++) {
                if(g[j][i]==1){
                    rep = j;
                    ch++;
                }
            }
            if (ch == 1) {
                cout << dto36(rep);
            }else{
                cout << '?';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < (n); i++)
using pint = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int n, a, b, c;
int A[10];
int ans = inf;

void calc (vector<int> v) {
    vector<vector<int>> ans_sum (3);
    rep (i, n) {
        if (v[i] == 3) continue;
        ans_sum[v[i]].push_back (A[i]);
    }
    int sum = 0;
    int cnt[3] = {};
    rep (i, 3) {
        if (ans_sum[i].size() == 0) return;
        sum += 10 * (ans_sum[i].size() - 1);
        rep (j, ans_sum[i].size()) { cnt[i] += ans_sum[i][j]; }
    }
    sort (cnt, cnt + 3);
    sum += abs (c - cnt[0]) + abs (b - cnt[1]) + abs (a - cnt[2]);
    ans = min (ans, sum);
}

void dfs (int depth, vector<int> &v) {
    if (depth == n) {
        calc (v);
        return;
    }

    rep (i, 4) {
        v[depth] = i;
        dfs (depth + 1, v);
    }
}

int main() {
    cin >> n >> a >> b >> c;
    rep (i, n) cin >> A[i];
    vector<int> v (n);
    dfs (0, v);
    cout << ans << "\n";
}

Measured memory_bytes: 3604
package main

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

func bitNum(b, c int) int {
	if b&c > 0 {
		return 1
	}
	return 0
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()

	bits := make([][]int, N)
	for i := 0; i < len(bits); i++ {
		bits[i] = make([]int, 60)
	}
	for i := uint(0); i < 60; i++ {
		bits[N-1][i] = bitNum(A[N-1], 1<<i)
	}
	for i := N - 2; i >= 0; i-- {
		for j := uint(0); j < 60; j++ {
			bits[i][j] += bits[i+1][j] + bitNum(A[i], 1<<j)
		}
	}
	sum := 0
	for i := 0; i < len(bits)-1; i++ {
		for j := uint(0); j < 60; j++ {
			B := 1 << j
			B %= 1000000007
			if A[i]&(1<<j) > 0 {
				sum += B * ((N - i - 1) - bits[i+1][j])
			} else {
				sum += B * bits[i+1][j]
			}
			sum %= 1000000007
		}
	}
	fmt.Println(sum)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 164720
N=int(input())
AB=sorted([list(map(int,input().split())) for _ in range(N)])
CD=sorted([list(map(int,input().split())) for _ in range(N)], key=lambda x:x[1])

cnt=0
for a,b in AB[::-1]:
    for i,j in enumerate(CD):
        c,d=j
        if a<c and b<d:
            cnt +=1
            del CD[i]
            break
print(cnt)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

int32 toi[300];
char toc[2000] = {};

int64 to_int(const string& s){
	int32 ret = 0;
	REP(i, s.size()){
		if(isdigit(s[i])){
			ret += (s[i]-'0')*toi[s[i+1]];
			i++;
		}else{
			ret += toi[s[i]];
		}
	}
	return ret;
}

int main(void){
	toi['i'] = 1; toi['x'] = 10; toi['c'] = 100; toi['m'] = 1000;
	toc[1] = 'i'; toc[10] = 'x'; toc[100] = 'c'; toc[1000] = 'm';

	int32 N;
	cin >> N;
	REP(i, N){
		string s, t;
		int64 res = 0;
		cin >> s >> t;
		res = to_int(s)+to_int(t);

		string r = "";
		for(int32 j = 1;j <= 1000;j *= 10){
			if(res/j%10 == 1){
				r = toc[j]+r;
			}else if(res/j%10 > 1){
				r = toc[j]+r;
				r = static_cast<char>(res/j%10+'0')+r;
			}
		}
		cout << r << endl;
	}
}



Measured memory_bytes: 3184