akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll a,b;
int ma[100][100];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>a>>b;
    rep(i,100)rep(j,100)ma[i][j]=0;
    rep(i,50){
        rep(j,100){
            ma[i][j] = 1;//黒
        }
    }
    a--;
    b--;
    rep(i,50){
        rep(j,100){
            if(a==0)break;
            if(j%2==0){
               if(i%2==0){
                   ma[i][j]=0;
                   a--;
               } 
            }
        }
        if(a==0)break;
    }

    for(int i=99;i>=50;i--){
        rep(j,100){
            if(j%2==1){
                if(i%2==0){
                    ma[i][j]=1;
                    b--;
                }
            }
            if(b==0)break;
        }
        if(b==0)break;
    }
    cout<<100<<" "<<100<<endl;
    rep(i,100){
        rep(j,100){
            if(ma[i][j]==1)cout<<"#";
            else cout<<".";
        }
        print("");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    string s, t;
    cin >> s >> t;

    string ans = "";
    for (int i = n; i >= 0; --i) {
        string f = s + string(t.begin() + i, t.end());
        if (string(f.begin() + n - i, f.end()) == t) {
            ans = f;
            break;
        }
    }
    cout << SZ(ans) << '\n';
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      n: usize,
      q: usize,
      s: chars,
      lrs: [(usize, usize); q],
    }
    let mut ac = 0;
    let mut sum = vec![0; n+1];
    for i in 1..n {
        if s[i] == 'C' && s[i-1] == 'A' {
            ac += 1;
        }
        sum[i+1] = ac;
    }
    for &(l,r) in lrs.iter() {
        println!("{}", sum[r] - sum[l]);
    }
}


Measured memory_bytes: 6908
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )
#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = (c).begin(); it != (c).end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define PB( n ) push_back( ( n ) )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define fst first
#define snd second

const double p500[] = { 70, 55, 50, 43, 40, 37.5, 35.5 };
const double p1000[] = { 148, 116, 105, 89, 83, 77, 71 };
const string rank[] = {	"NA", "E", "D", "C", "B", "A",	"AA", "AAA" };

int main()
{
	double t500, t1000;

	while ( cin >> t500 >> t1000 )
	{
		int rank1 = 0, rank2 = 0;

		REP( i, 0, 7 )
		{
			if ( t500 < p500[i] )
			{
				rank1++;
			}

			if ( t1000 < p1000[i] )
			{
				rank2++;
			}
		}

		cout << rank[ min( rank1, rank2 ) ] << endl;
	}
	
	return 0;
}

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

typedef long long ll;
ll a[200005],b[200005];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	if(n%2==1){
		cout<<(ll)(b[n/2+1]-a[n/2+1]+1)<<endl;
	}
	else {
		cout<<(ll)(b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1]+1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 6712
# -*- coding: utf-8 -*-
#import math

# 整数の入力
#a = int(input())
# スペース区切りの文字列の入力
st = input().split()
st_list = []
st_list = [str(st) for st in st]

# スペース区切りの数値の入力
a, b = map(int, input().split())

# 文字列の入力
s = input()

# スペース区切りの文字列の入力
#a,b = map(input().split())

if(str(s) == st_list[0]):
  a = a-1
elif(str(s) == st_list[1]):
  b = b-1
# 出力

print(a,b)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		if(n==6){
			System.out.println(1);
		}else if(n%11==6){
			if (2 * n % 11 == 0) {
				System.out.println(2 * n / 11-1);
			} else {
				System.out.println((2 * n / 11));
			}	
		}else{
		if (2 * n % 11 == 0) {
			System.out.println(2 * n / 11);
		} else {
			System.out.println((2 * n / 11) + 1);
		}
	}
}
}

Measured memory_bytes: 21844
#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}





fn main() {
    input! {
        n: usize,
        xs: [(i64, i64); n],
    }

    let mut xs = xs;
    xs.sort_by_key(|&(_, b)| -b);
    let last = xs[0].1;
    let init = xs.iter().fold(last, |c, &(a, b)| min(c, b) - a);
    let ans = if 0 <= init { "Yes" } else { "No" };
    println!("{}", ans);    
}


Measured memory_bytes: 13688
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 998244353
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define r2 1.41421356237
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int nax=100005;
vector<bool>vis(nax,0);
vector<int>g[nax];

void dfs(int x) {
	vis[x]=1;
	for(auto p:g[x]) { if(!vis[p]) { dfs(p); } }
}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  int n,m;
  cin>>n>>m;
  while(m--) {
  	int u,v;
  	cin>>u>>v;
  	g[u].pb(v);
  	g[v].pb(u);
  }
  int c=-1;
  for(int i=1;i<=n;i++) {
  	if(!vis[i]) { c++; dfs(i); }
  }
  cout<<c;
  //}
  return 0;
}

Measured memory_bytes: 9596
#!/usr/bin/env python
import sys
from itertools import combinations

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n = _i()
xy = list()
for _ in range(n):
    tmp = []
    for _ in range(_i()):
        x,y = _ia()
        tmp.append((x-1,y))
    xy.append(tmp)
#
a = set(range(n))
for f in range(n+1):
    for p in combinations(range(n),f):
        h = a - set(p)
        tmp = [ None ] * n
        flag = True
        for i in h:
            if not i in h: continue
            for x,y in xy[i]:
                if y==1 and x not in h:
                    flag = False
                    break
                if y==0 and x in h:
                    flag = False
                    break
                #
                tx = tmp[x]
                if tx is None:
                    tmp[x] = y
                else:
                    if tx==y: continue
                    else:
                        flag = False
                        break
            #
            if not flag: break
        if flag:
            print(n-f)
            exit()
            
                        


Measured memory_bytes: 52848
n = int(input())
a = list(map(int,input().split()))
ans = [0]
for i in range(n-1):
    ans.append(a[i]-ans[i])
ans[0] = a[-1]-(ans[0]+ans[-1])
for i in range(1,n):
    ans[i] = (a[i-1]-ans[i-1]//2)*2
print(*ans)


Measured memory_bytes: 14032
#include <bits/stdc++.h>
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1LL<<30;
const int MOD = 1e9+7;

signed main()
{
   const int SIZE = 26;

   string s; cin >> s;
   int n = s.size();

   vector<int> h(n);
   for (int i = 0; i < n; ++i) {
      h[i] = 1LL<<s[i]-'a';
   }

   vector<int> a(n+1);
   for (int i = 0; i < n; ++i) {
      a[i+1] = a[i] ^ h[i];
   }

   vector<int> opt(n+1, INF);
   opt[0] = 0;
   vector<int> dp(1LL<<SIZE, INF);
   dp[0] = 0;

   for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < SIZE; ++j) {
         chmin(opt[i], dp[a[i] ^ (1LL<<j)] + 1);
      }
      chmin(opt[i], dp[a[i]] + 1);

      chmin(dp[a[i]], opt[i]);
   }
   cout << opt[n] << endl;

   return 0;
}


Measured memory_bytes: 265092
import java.util.*;
import java.math.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        PriorityQueue<Pair> list = new PriorityQueue<Pair>((a,b)->{
          return a.a==b.a?b.b-a.b:a.a-b.a;
        });
        for(int i=0;i<N;i++){
          list.add(new Pair(sc.nextInt(),sc.nextInt()));
        }

        Pair el;
        int now = 0;
        int pre = -1;
        int cnt = 0;
        int cmax = 0;
        PriorityQueue<Integer> anses = new PriorityQueue<Integer>((a,b)->b-a);
        int ans = 0;
        for(int i=1;i<=M;i++){
          Pair p;
          while((p=list.poll()) != null){
            int a = p.a;
            int b = p.b;
            if(a<=i){
              anses.add(b);
            }else{
              list.add(p);
              break;
            }
          }
          if(!anses.isEmpty()){
            ans += anses.poll();
          }
        }
        System.out.println(ans);
    }
    private static class Pair{
      public int a, b;
      Pair(int a,int b){
        this.a = a;
        this.b = b;
      }
    }
}


Measured memory_bytes: 66872
program main
   implicit none
   integer s1
   integer:: s(1000000)
   integer i,j
   read(*,*)s1
   s(1)=s1
   do i=1,1000000
      if(mod(s(i),2)==0)then
         s(i+1)=s(i)/2
      else
         s(i+1)=3*s(i)+1
      endif
      do j=1,i
         if(s(i+1)==s(j))then
            write(*,*)i+1
            goto 100
         endif
      enddo
   enddo
100 continue
end program main


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int 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 modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    int n,d;
    cin>>n>>d;
    int cnt=0;
    while(n--){
        int a,b;
        cin>>a>>b;
        if(a*a+b*b<=d*d)
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;

}

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
n = input()
l = []
tail = 0
for i in xrange(n):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        l.append(cmd[1])
    elif cmd[0] == "delete":
        try:
            l.pop(len(l) - l[::-1].index(cmd[1]) -1)
        except ValueError:
            pass
    elif cmd[0] == "deleteFirst":
        l.pop()
    elif cmd[0] == "deleteLast":
        tail += 1

print " ".join(l[tail:][::-1])

Measured memory_bytes: 61656
#include <bits/stdc++.h>
using namespace std ;
 
int main(){

  int n,i;
  cin>>n;
  vector<int> v(n);
  for(int i=0; i<n; ++i){
    cin >> v[i];
  }

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

  int ans = 0;
  for(int i = 0;i<n;i++){
    if(v[i] > c[i])
      ans += (v[i]-c[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

const int N=100010;

int s[N],n;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",s+i);
	std::nth_element(s+1,s+n,s+n+1);

	int ans=-1,maxw=-1;
	for(int i=1;i<n;i++)
	{
		int x=s[i]*2>s[n]?s[n]-s[i]:s[i];
		if(x>maxw)maxw=x,ans=s[i];
	}
	printf("%d %d\n",s[n],ans);
	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
    long[][] A = new long[N][M];
    long[] C = new long[N];
    int[] check = new int[N];
    for (int i =0; i<N; i++) {
      C[i] = Long.parseLong(sc.next());
      for (int j =0; j<M; j++) {
        A[i][j] = sc.nextInt();
      }
    }
    
    long min = 1200001;
    char[] sp = new char[N+1];
    for (int i = 1; i < Math.pow(2, N); i++) { 
      sp = String.format("%0" + N + "d", Long.parseLong(Integer.toBinaryString(i))).toCharArray();
      long[] Acheck = new long[M+1];
      for (int j =0; j<N; j++) {
        if (sp[j] == '0') {
          continue;
        }
        for (int k = 0; k <M; k++) {
          Acheck[k] += A[j][k];
	    }
      }
	  boolean flg = true;
	  for (int j =0; j <M; j++) {
        if (Acheck[j] < X) {
          flg = false;
        }
      }
      if (flg) {
        long ans = 0;
        for (int j = 0; j <N; j++) {
          if (sp[j] == '1') ans += C[j];
	      }
	    min = Math.min(min, ans);
      }
    }
    if (min == 1200001) min = -1;
	System.out.println(min);
  }
} 
  

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((a == b && b == c) || (b == c && c == d))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,m,k,a,ans=0;
	cin >> n >> m;
	int b[m+1];

	rep(i,m+1){
		b[i] = 0;
	}

	rep(i,n){
		cin >> k;
		rep(j,k){
			cin >> a;
			b[a]++;
		}
	}
	
	rep(i,m){
		if(b[i+1]==n) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<time.h>
#include<sstream>
#define MINN -1e8 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f3f3f;
const int P=1e9+7;
const int MAXN=32000;
const double pi=3.1415926;
const ll mod=1000000007;
ll n,k,ans;
ll a[2001];
ll powmod(ll a,ll b)     //快速幂 
{
	ll tmp=a%mod;
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*tmp%mod;
		tmp=tmp*tmp%mod;
		b>>=1;
	}
	return ans%mod;
}
ll f(ll k)
{
	return k%mod*(k-1)%mod*powmod(2,mod-2)%mod;
}
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	int x=0,y=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(a[j]<a[i])x++;
		}
	}
	if(k==1)
	{
		cout<<x;return 0;
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(a[j]<a[i])y++;
			}
		}
		ans=(k*x%mod+f(k)*y%mod)%mod;
		cout<<ans<<"\n";
	}
	return 0;
}

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

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

int gcd(int i,int j,int k){
    return gcd2(i,gcd2(j,k));
}


int main(){
    int k,sum=0;
    cin>>k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                sum=sum+gcd(i,j,l);
            }    
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
static const int mod = 1e9+7;
static const long long INF = 1LL << 60;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int> dp(n+1);
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        dp[i] = 1 + dp[i-1];
        int pow6 = 1;
        while(pow6*6 <= i){
            pow6 *= 6;
            chmin(dp[i], 1+dp[i-pow6]);
            // dp[i] = min(dp[i], 1+dp[i-pow6]);
        }
        int pow9 = 1;
        while (pow9 * 9 <= i)
        {
            pow9 *= 9;
            chmin(dp[i], 1+dp[i-pow9]);
            //dp[i] = min(dp[i], 1+dp[i-pow9]);
        }
    }   
    cout << dp[n] << endl;
}


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

//Party
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0&&m==0)break;
			boolean[][] f = new boolean[n+1][n+1];
			while(m--!=0){
				int a = sc.nextInt();
				int b = sc.nextInt();
				f[a][b] = f[b][a] = true;
			}
			List<Integer> f1 = new ArrayList<Integer>();
			for(int i=2;i<=n;i++)if(f[1][i])f1.add(i);
			f1.add(1);
			boolean[] invite = new boolean[n+1];
			for(int k:f1){
				invite[k] = true;
				for(int i=1;i<=n;i++){
					if(f[k][i])
						invite[i] = true;
				}
			}
			int c = 0;
			for(int i=1;i<=n;i++)c+=invite[i]?1:0;
			System.out.println(--c);
		}
	}
}

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

int a[200010];

int main () {

int n;
cin>>n;
long long int zbr=0;
for (int i=0; i<n; i++) {
	cin>>a[i];
	zbr+=a[i];
}
long long int mini=200000000000001;
long long int br=0;
for (int i=0; i<n-1; i++) {
	br+=a[i];
	if (abs(br-(zbr-br))<mini) {mini=abs(br-(zbr-br));}
}
cout<<mini;

return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int n,i;
    long  l[100]={2,1};
    scanf("%d",&n);
    for(i=2;i<=n;i++){
        l[i]=l[i-1]+l[i-2];
    }
    printf("%ld\n",l[n]);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;
 
 
int main(){
  int H, N ;
  cin >> H >> N ;
  int A[N] ;
  int B[N] ;
  for(int i=0;i<N;i++){
    cin >> A[i] >> B[i] ;
  }  
  int DP[H + 1] ;
  DP[0] = 0 ;
  for(int i=1;i<(H+1);i++){
    DP[i] = INT_MAX ;
    for(int j=0;j<N;j++){
      if(i >= A[j]){
        if(DP[i] > (DP[(i-A[j])] + B[j]) ){
          DP[i] = DP[(i-A[j])] + B[j] ;
        }  
      }
      else{
        if(DP[i] > B[j] ){
          DP[i] = B[j] ;
        }
      }  
    }  
  }  
  cout << DP[H] << endl ;
  return 0 ;
}

Measured memory_bytes: 3668
/**
 *    author:  tourist
 *    created: 22.10.2017 08:47:14       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s.find("AC") != string::npos) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&a==c){
    cout << "No" << endl;
  }
  else  if(a!=b&&a!=c&&b!=c){
    cout << "No" << endl;
  }
    else{
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
#define INF (1LL << 60)

struct Edge{
    int from, to, score;
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<Edge> edges;
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges.push_back({a, b, c});
    }

    vector<long long> d(N, -INF);
    d[0] = 0;
    for(int i=0; i<N-1; i++){
        for(Edge& edge : edges){
            long long score_new = d[edge.from] + edge.score;
            if(score_new > d[edge.to])
                d[edge.to] = score_new;
        }
    }
    long long ans = d[N-1];

    for(int i=0; i<N-1; i++){
        for(Edge& edge : edges){
            long long score_new = d[edge.from] + edge.score;
            if(score_new > d[edge.to])
                d[edge.to] = score_new;
        }
    }
    if(ans != d[N-1]){
        cout << "inf" << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def kaijo(x):
  if x<=1:
    return 1
  elif x==2:
    return 2
  elif x==3:
    return 6
  elif x==4:
    return 24
  elif x==5:
    return 120
  elif x==6:
    return 720
  elif x==7:
    return 5040
  elif x==8:
    return 5040*8
  else:
    return 0

N=int(input())
s=input().split(" ")
P=[int(ss) for ss in s]
s=input().split(" ")
Q=[int(ss) for ss in s]

Ls=[i+1 for i in range(N)]
rank=0
for i in range(N):
  for j in range(len(Ls)):
    if Ls[j]==P[i]:
      a=j
      Ls.pop(j)
      break
  rank+=kaijo(N-i-1)*a
rp=rank

rank=0
Ls=[i+1 for i in range(N)]
#print(Ls)
for i in range(N):
  for j in range(len(Ls)):
    if Ls[j]==Q[i]:
      a=j
      Ls.pop(j)
      break
  rank+=kaijo(N-i-1)*a
rq=rank
#print(rank)
print(abs(rp-rq))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main(){
	dhoom;
	int n , m , x; 
	cin >> n >> m >> x;
	int l = 0 , r = 0;
	int a[m];
	for(int i = 0 ; i < m ; i++){
		cin >> a[i];
	}
	sort(a , a + m);
	for(int i = 0 ; i < m ; i++){
			if(a[i] < x)
				l++;
			if(a[i] > x)
				r++;
	}
	cout << min(l , r) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long GCD(long long x, long long y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main() {
    int K;
    cin >> K;
    long long res = 0;
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                res += GCD(GCD(a, b), c);
            }
        }
    }
    cout << res << endl;
}

















Measured memory_bytes: 3636
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int n;
string s;
string base = "RGB";
char look(char x, char y) {
  fore(i, 0, 3) if (base[i] != x && base[i] != y) return base[i];
  return '-';
}
Long f(int x) {
  char var = s[x];
  map<char, int> left, rigth;
  fore(i, 0, 3) {
    left[base[i]] = 0;
    rigth[base[i]] = 0;
  }
  fore(i, 0, x) left[s[i]]++;
  fore(i, x + 1, n) rigth[s[i]]++;
  Long ans = 0;
  fore(i, 0, 3) {
    if (base[i] == var) continue;
    char busca = look(base[i], var);
    ans += (left[base[i]] * rigth[busca]);
  }
  int ee = min(x, n - x - 1);
  fore(i, 0, ee) {
    if (s[x - i - 1] == var) continue;
    if (s[x + i + 1] == var) continue;
    if (s[x - i - 1] != s[x + i + 1]) {
      ans--;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> s;
  Long ans = 0;
  fore(i, 1, n - 1) {
    ans += f(i);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=128;
int n;
struct point{
    int x,y;
}a[maxn],b[maxn];
int g[maxn][maxn];
int linker[maxn];
bool used[maxn];
bool dfs(int u)
{
    for(int v=1;v<=n;v++)
        if(g[u][v]&&!used[v])
        {
            used[v]=true;
            if(linker[v]==-1||dfs(linker[v]))
            {
                linker[v]=u;
                return true;
            }
        }
    return false;
}
int hungary()
{
    int res=0;
    memset(linker, -1, sizeof(linker));
    for(int u=1;u<=n;u++)
    {
        memset(used, false, sizeof(used));
        if(dfs(u))res++;
    }
    return res;
}
int main()
{
    while (scanf("%d",&n)!=EOF) {
        for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
        for(int i=1;i<=n;i++)scanf("%d%d",&b[i].x,&b[i].y);
        memset(g, 0, sizeof(g));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(a[i].x<b[j].x&&a[i].y<b[j].y)g[i][j]=1;
        printf("%d\n",hungary());
    }
    return 0;
}



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

public class Main {
	
	public static String fix(String s, int h) {
		while(s.length() < h - 1)
			s = "0" + s;
		return s;
	}
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int h = sc.nextInt(), w = sc.nextInt(), k = sc.nextInt();
		int[][] mat = new int[h][w];
		for(int i = 0; i < h; i++) {
			String s = sc.next();
			for(int j = 0; j < w; j++) {
				mat[i][j] = Integer.parseInt("" + s.charAt(j));
			}
		}
		
		int min = h - 1 + w - 1;
		big: for(int prm = 0; prm <= (1 << (h - 1)) - 1; prm++) {
			int b = Integer.bitCount(prm);
			String s = fix(Integer.toBinaryString(prm), h);
			int[] count = new int[b + 1];
			
			int c = b;
			int pre = -1;
			for(int i = 0; i < w; i++) {
				int[] newCount = new int[b + 1];
				int idx = 0;
				for(int j = 0; j < h; j++) {
					if(j > 0 && (s.charAt(s.length() - j) == '1'))
						idx++;
					newCount[idx] += mat[j][i];
				}
				boolean flag = true;
				for(int u = 0; u <= b; u++) {
					count[u] += newCount[u];
					if(count[u] > k) {
						flag = false;
						break;
					}
				}
				
				if(!flag) {
					c++;
					if(pre == i - 1) {
						continue big;
					} else {
						pre = i - 1;
					}
					for(int u = 0; u <= b; u++) {
						count[u] = newCount[u];
					}
					flag = true;
					for(int u = 0; u <= b; u++) {
						if(count[u] > k) {
							flag = false;
							break;
						}
					}
					if(!flag) {
						continue big;
					}
				}
			}
			
			min = Math.min(min, c);
		}
		
		pw.println(min);
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 38912
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[15],mx=99,ans=0,first=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mx=max(mx,a[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==mx&&first)
		ans+=a[i]/2,first=0;
		else
		ans+=a[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
exchange :: Int -> [Int] -> [Int]
exchange amount coins | amount >= 500 = exchange (amount - 500) (500 : coins)
                      | amount >= 5   = exchange (amount - 5) (5 : coins)
                      | amount > 0    = exchange (amount - 5) (1 : coins)
                      | otherwise     = coins

totalValue :: [Int] -> [Int]
totalValue coins = map value coins

value :: Int -> Int
value 500 = 1000
value 5   = 5
value _   = 0

main = do
    str <- getLine
    let num = read str :: Int
    print $ sum $ totalValue $ exchange num []


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

int main(){
  int N; cin >> N;
  vector<int> b(N);
  for(int i=0; i<N; i++) cin >> b[i];
  
  queue<vector<int>> q;
  q.push(b);
  bool f=false;
  vector<int> res(N);
  while(!q.empty()&&!f){
    vector<int> t=q.front(); q.pop();
    int s=t.size();
    if(s==1){
      if(t[0]==1){
        res[0]=1;
        f=true;
        break;
      }
    }else{
      for(int i=s-1; i>=0; i--){
        if(t[i]==i+1){
          vector<int> tt=t;
          res[s-1]=i+1;
          tt.erase(tt.begin()+i);
          q.push(tt);
          break;
        }
      }
    }
  }
  if(f){
    for(int i=0; i<N; i++){
      cout << res[i] << endl;
    }
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 256
N,W = map(int,input().split())
w_list = []
v_list = []
for _ in range(N):
    w,v = map(int,input().split())
    w_list.append(w)
    v_list.append(v)
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(1,N+1):
    w = w_list[i-1]
    v = v_list[i-1]
    for j in range(1,W+1):
        if j-w >= 0:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]
print(dp[N][W])

Measured memory_bytes: 119916
//
//  main.cpp

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,k,cards[11];
bool selected[11];
vector<vector<int>> selectlist;
vector<int> makelist;

void reset(){
	n = k = 0;
	selectlist.clear();
	makelist.clear();
	for(int i=0;i<11;i++){
		cards[i] = 0;
		selected[i] = false;
	}
}

void select_dfs_(int depth,int top,vector<int> vec){
	if(depth == k){
		selectlist.push_back(vec);
		return;
	}
	for(int i=top+1;i<n;i++){
		vec.push_back(cards[i]);
		select_dfs_(depth+1,i,vec);
		vec.pop_back();
	}
}

void makeint_dfs_(int depth,int makedint,vector<int> source){
	if(depth == k){
		makelist.push_back(makedint);
		return;
	}
	for(int i=0;i<k;i++){
		if(!selected[i]){
			selected[i] = true;
			int maked;
			if(source[i]/10 > 0){
				maked = makedint*100+source[i];
			}else{
				maked = makedint*10+source[i];
			}
			makeint_dfs_(depth+1,maked,source);
			selected[i] = false;
		}
	}
}

int main(){
	while(1){
		reset();
		
		cin >> n >> k;
		if(n == 0 && k == 0)break;
		for(int i=0;i<n;i++){
			cin >> cards[i];
		}
		
		for(int i=0;i<n-k+1;i++){
			vector<int> vec;
			vec.push_back(cards[i]);
			select_dfs_(1,i,vec);
		}
		
		for(int i=0;i<selectlist.size();i++){
			for(int j=0;j<selectlist[i].size();j++){
				selected[j] = true;
				makeint_dfs_(1,selectlist[i][j],selectlist[i]);
				selected[j] = false;
			}
		}
		
		sort(makelist.begin(),makelist.end());
		
		int answer=0,memo=-1;
		for(int i=0;i<makelist.size();i++){
			if(memo != makelist[i]){
				answer ++;
				memo = makelist[i];
			}
		}
		
		cout << answer << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3156
Imports System.Collections.Generic
Imports System.Console

Module Program
    Dim n, ans As Integer

    Sub Main()
        n = NextInt()
        For i As Integer = 0 To Integer.MaxValue
            DFS(i, "0")
        Next
    End Sub

    Sub DFS(rest As Integer, s As String)
        If rest = 0 Then
            If CLng(s) > n Then
                WriteLine(ans)
                End 'Program'
            End If
            For Each v As Char In "357"
                If Not s.Contains(v) Then
                    Return
                End If
            Next
            ans += 1
        Else
            For Each c As Char In "357"
                DFS(rest - 1, s & c)
            Next
        End If
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}

int seen[2000000];  // 1:現在探索中のパスで行きがけ 2:探索後の頂点
int d[2000000];     // d[i]:= 始点から i への距離
int dfs(const vector<vector<int>> &G, int now) {
    if (seen[now] == 2) return d[now];
    seen[now] = 1;
    for (auto e : G[now]) {
        if (seen[e] == 1) {  // 閉路を検出
            cout << -1 << endl;
            exit(0);
        }
        chmax(d[now], dfs(G, e) + 1);
    }
    seen[now] = 2;
    return d[now];
}

int main() {
  int N,a,b;
  cin >> N;
  vector<vector<int>> g(N*(N-1)/2+1);
  rep(i,N){
    int bno=N*(N-1)/2;
    rep(j,N-1) {
      a = i;
      scanf("%d",&b);
      b--;
      if (a>b) swap(a,b);
      int no = b*(b-1)/2 + a;
      g[bno].push_back(no);
      swap(bno,no);
    }
  }

  cout << dfs(g, N*(N-1)/2) << endl;
}

Measured memory_bytes: 33664
N,A,*X = `dd`.split.map &:to_i
S = 50*N
dp = (0..N).map{ Array.new(S+1, 0) }
dp[0][0] = 1
X.each{ |x|
  (0...N).reverse_each{ |i|
    (0..S-x).reverse_each{ |a|
      dp[i+1][a+x] += dp[i][a]
    }
  }
}
#dp.each{ |row| p row }
p (1..N).reduce(0){ |a,n| a + (dp[n][A*n] || 0) }

Measured memory_bytes: 39552
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <utility>
#include <tuple>
#include <cmath>
#import <ios>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define na(a, n) rep(i, n) cin >> a[i];
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
vb d(10);
int ans(int x)
{
    while (x)
    {
        if (d[x % 10])
            return 0;
        x /= 10;
    }
    return 1;
}
//ここからメイン
int main()
{
char a,b;
cin >> a >> b;
cout << (a>b?'>':a==b?'=':'<'
);}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[50]={0},b[50]={0},c[50]={0};
int n,sum = 0;
int main(){
	cin >> n;
	for(int i = 1;i<=n;i++)
		cin >> a[i];
	for(int i = 1;i<=n;i++)
		cin >> b[i];
	for(int i = 1;i<n;i++)
		cin >> c[i];
	sum = b[a[1]];	
	for(int i = 2;i<=n;i++){
		if(a[i]==a[i-1]+1)
			sum += c[a[i-1]];
		sum += b[a[i]];
	}
	cout << sum << endl;
}

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

int main(void){
   int a,b,c;
   cin >> a >> b >> c;
   double PI = acos(-1);
   double rad = c*PI/180;
   cout << fixed << setprecision(5);
   cout << a*b*sin(rad)/2 << endl << a + b + sqrt(a*a + b*b - 2*a*b*cos(rad)) << endl << b*sin(rad) << endl;
}


Measured memory_bytes: 3668
def main():
    n=int(input())
    s=input()
    sum=''
    model='ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
    m=list(model)
    for i in range(len(s)):
        now=m.index(s[i])
        sum=sum+m[now+n]
    print(sum)


if __name__=='__main__':
    main()   

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,K,m=0;
  
  cin >> N >> K;
  vector<ll> V(N);
  rep(i,N){
    cin >> V.at(i);
  }
  rep(i,N+1){
    for(ll j=N+1;j>i;j--){
      ll t=0;
      priority_queue<ll,vector<ll>,greater<ll>> Q;
      rep(k,i){
        t+=V.at(k);
        Q.push(V.at(k));
      }
      if(i+N+1-j>K) break;
      for(ll k=N-1;k>j-2;k--){
        t+=V.at(k);
        Q.push(V.at(k));
      }
      rep(k,K-(i+N+1-j)){
        if(!Q.empty()&&Q.top()<0){
          t-=Q.top();
          Q.pop();
        }
      }
      m=max(m,t);
    }
  }
  cout << m << endl;
      
      
}
      

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

int main(){

    int X; cin >> X;
    long long N = 2*X;
    bool seq[N]; fill(seq, seq+N, 1);
    seq[0] = 0, seq[1] = 0;

    for(long long i = 2; i*i < N; i++){
        if(seq[i]){
            for(long long cursor = i*i; cursor < N; cursor += i){seq[cursor] = 0;}
        }
    }

    /*for(int i = 0; i < X; i++){
        if(seq[i]){cout << i << " ";}
    }*/

    for(int i = X; i < N; i++){
        if(seq[i] && (i >= X)){cout << i << endl;break;}
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin>>N;
  if(N%10==7){
    cout<<"Yes"<<endl;
  }
  else if((N/10)%10==7){
    cout<<"Yes"<<endl;
  }
  else if(N/100==7){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

int compare_longlong(const void *a, const void *b)
{
    if( *(long long int*)a - *(long long int*)b < 0 )
        return 1;
    if( *(long long int*)a - *(long long int*)b > 0 )
        return -1;
    return 0;
}
	long long AB[1000000]={};
	long long ABC[3000000]={};
int main(void){
	long X,Y,Z,K;
	long long A[1000]={},B[1000]={},C[1000]={};
	long i,j;
	scanf("%d %d %d %d",&X,&Y,&Z,&K);
	for(i=0;i<X;i++){
		scanf("%lld",&A[i]);
	}
	for(i=0;i<Y;i++){
		scanf("%lld",&B[i]);
	}
	for(i=0;i<Z;i++){
		scanf("%lld",&C[i]);
	}
	qsort(A,X,sizeof(long long),compare_longlong);
	qsort(B,Y,sizeof(long long),compare_longlong);
	qsort(C,Z,sizeof(long long),compare_longlong);
	int temp=0;
	for(i=0;i<X;i++){
		for(j=0;j<Y;j++){
			AB[temp]=A[i]+B[j];
			temp++;
		}
	}
	qsort(AB,temp,sizeof(long long),compare_longlong);
	int temp2 = 0;
	for(i=0;i<3000;i++){
		for(j=0;j<Z;j++){
			ABC[temp2]= AB[i] + C[j];
			temp2 ++;
		}
	}
	qsort(ABC,temp2,sizeof(long long),compare_longlong);
	for(i=0;i<K;i++){
		printf("%lld\n",ABC[i]);
	}
	return 0;
}

Measured memory_bytes: 54916
// 桁数を決めてdfsやる
// K について繰り返すものであれば間に合いそう
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

vector<string> memo;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll K;
vector<ll> A;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

ll ans = 0;
bool finish = false;

void dfs(vector<int> D, int k) {
  if (D.size() == k) {
    string tmp;
    rep(i, k){
      //printf("%d ", D[i]);
      tmp += D[i]+'0';
    }
    //cout << tmp << endl;
    memo.push_back(tmp);
    if (memo.size()==K) {
      //cout << memo[K-1] << endl;
      finish = true;
      return;
    }
    return;
  }
  for (int i=-1; i<=1; ++i) {
    int x = D[D.size()-1];
    //cout << "x: " << x << ", x+i: "<< x+i << ", size: " << D.size()<< endl;
    if (x+i <=9 && x+i >= 0 && D.size()<k && !finish) {
      D.push_back(x+i);
      //cout << "size: " << D.size() << endl;
      dfs(D, k);
      D.pop_back();
    }
  }
}

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

  cin >> K;
  rep1(i, 10) {
    rep1(j, 9) {
      if (!finish)dfs(vector<int>(1,j), i);
      else {
        cout << memo[K-1] << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 6900