akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using P = pair<int,int>;
using ll = long long; 

int main(){
    ll n;
    cin>>n;
    vector<ll> v;
    vector<ll> c;

    ll tmp;
    rep(i,n){
        cin>>tmp;
        v.push_back(tmp);
    }
    rep(i,n){
        cin>>tmp;
        c.push_back(tmp);
    }

    ll ans=0;
    rep(i,n){
        ll p = v[i]-c[i];
        if(p>0)ans+=p;
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 3604
my $count = <STDIN>;

my $hash = {};
my $before_w = '';
for (1..$count) {
    my $w = <STDIN>;
    chomp($w);
    if ($hash->{$w} || ($_ != 1 && (substr($before_w, -1, 1) ne substr($w, 0, 1)))) {
        print('No');
        last;
    } elsif ($_ == $count) {
        print('Yes');
    } else {
        $before_w = $w;
        $hash->{$w} = 100;
    }


}



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

using namespace std;

const int INF = 1e9 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    for (int &x : a) cin >> x;
    sort(a, a + n);
    int ans = INF;
    for (int i = a[0]; i <= a[n - 1]; ++i) {
        int sum = 0;
        for (int x : a) {
            sum += (x - i) * (x - i);
        }
        ans = min(sum, ans);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] hills = new int[10];
            Scanner sc = new Scanner(System.in);
            for(int i = 0; i < hills.length; i++) {
                hills[i] = sc.nextInt();
        }

        Arrays.sort(hills);

        for(int i = 9; i > 6; i--) {
            System.out.println(hills[i]);
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    string ans;
    if(s=="Sunny") ans = "Cloudy";
    if(s=="Cloudy") ans = "Rainy";
    if(s=="Rainy") ans = "Sunny";


    cout << ans << endl;
    return 0;
}


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



int main(){
  long int N;
  cin >>N;
  vector<long int>A(N);
  vector<long int>num(N+1);
  for(int i=0;i<N;i++){
  	cin >>A[i];
    num[A[i]]++;
  }
  long int sum=0;
  for(int i=1;i<=N;i++){
  	sum+=num[i]*(num[i]-1)/2; 
  }
  for(int i=0;i<N;i++){
  	long int x=A[i];
  	long int y=num[x];
    long int z=(y)*(y-1)/2;
    long int w=(y-1)*(y-2)/2;
    cout<<sum-z+w<<endl;
  }
  
}

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

std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  bool ok1=true,ok2=true;
  //2
  int g=__gcd(a[0],a[1]);
  rep(i,n)g=__gcd(g,a[i]);
  if(g!=1)ok2=false;
  //1
  set<int>se;
  vector<int>e=Eratosthenes(1000005);
  rep(i,n){
    set<int>cnt;
    rep(j,e.size()){
      if((ll)e[j]*e[j]>a[i])break;
      while(a[i]%e[j]==0){
        a[i]/=e[j];
        cnt.insert(e[j]);
      }
    }
    if(a[i]!=1)cnt.insert(a[i]);
    for(auto&p:cnt){
      if(se.find(p)!=se.end())ok1=false;
      se.insert(p);
    }
  }
  if(ok1){cout<<"pairwise coprime"<<endl; return 0;}
  if(ok2){cout<<"setwise coprime"<<endl; return 0;}
  cout<<"not coprime"<<endl;
}

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

const int INF = 1e9;

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

	vector<vector<int>> dp(n, vector<int>(n, INF));
	for (int i=0;i<n;i++) dp[i][i] = 0;

	for (int w=1;w<n;w++) {
		for (int j=0;j+w<n;j++) {
			for (int k=0;k<w;k++) {
				dp[j][j+w] = min(dp[j][j+w], dp[j][j+k]+dp[j+k+1][j+w]+r[j]*r[j+k+1]*c[j+w]);
			}
		}
	}

	cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {cout<<"Yes";return 0;}
        n/=10;
    }
    cout<<"No"<<endl;
    return 0;
}
//make all values ll


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

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int a,b;
    cin >> a >> b;
    int res = 0;
    res += b / 2;
 //   if(res % 2)
//  res--;
 b %= 2;
    res += (3 * a + b) / 2;
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N_MAX 100000

int main(void){
	int i, j;

	int n;
	scanf("%ld", &n);

	int a[N_MAX], ans[N_MAX];
	long sum = 0, sum0 = 0;
	for(i = 0; i < n; i++){
		scanf("%ld", &a[i]);
		sum += a[i];
		if(i%2 == 0) sum0 += a[i];
	}

	ans[0] = 2*sum0-sum;

	for(i = 1; i < n; i++){
		ans[i] = 2*a[i-1]-ans[i-1];
	}

	for(i=0;i<n;i++){
		printf("%ld ", ans[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 2048
#include <cstdio>

using namespace std;

int main()
{
    int n;
    scanf( "%d\n", &n );
    for( int i = 0; i < n; i++ )
    {
        int k,p;
        scanf( "%d %d\n", &k, &p );
        if( k % p == 0 )
        {
            printf( "%d\n", p );
        }
        else
        {
            printf( "%d\n", k % p );
        }
        
    }
    return 0;
}


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

using namespace std;

const int NMAX = 1e5 + 10;
int v[NMAX],n,dp[NMAX],ans;

int main(){
    int i,j;
    cin >> n;
    for(i = 1 ; i <= n ; i++)
        cin >> v[i];

    for(i = n ; i >= 1 ; i--)
        if(v[i] >= v[i + 1]){
            dp[i] = dp[i + 1] + 1;
            ans = max(dp[i], ans);
        }else
            dp[i] = 1;

    cout << ans - 1;

    return 0;
}


Measured memory_bytes: 1024
import scala.io.StdIn.{readLine,readInt}
import scala.language.postfixOps

object Main {
  var cnt = 0
  val l = new Array[Int](260000)
  val r = new Array[Int](260000)

  def merge(a:Array[Int],left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    Array.copy(a,left,l,0,n1)
    l(n1) = Int.MaxValue
    Array.copy(a,mid,r,0,n2)
    r(n2) = Int.MaxValue
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        j += 1
      }
      cnt += 1
    }
  }

  def getSortIndex(n:Int):Iterator[IndexedSeq[(Int,Int)]] = {
    var w = n
    var h = 0
    while(w>1) {
      h += 1
      w /= 2
    }

    def scan(h:Int,l:List[IndexedSeq[(Int,Int)]]):List[IndexedSeq[(Int,Int)]] = {
      if(h==0) l
      else
        scan(h-1,(for(i<-l.head;j<-List((i._1,(i._2+i._1)/2),((i._2+i._1)/2,i._2))) yield j)::l)
    }
    scan(h-1,List(IndexedSeq((0,n/2),(n/2,n)))).to[Iterator]
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val l = getSortIndex(n)
    for(e2<-l) {
      for(e<-e2) {
        val mid = (e._2+e._1)/2
        if(e._2-e._1>1)
          merge(a,e._1,mid,e._2)
      }
    }
    merge(a,0,n/2,n)
    println(a.mkString(" "))
    println(cnt)
  }
}

Measured memory_bytes: 320236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    ll n; cin >> n;
    ll ans = 0;
    Rep(i, 1, n+1) ans += (i + n - n%i) * (n/i) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 3628
import bisect
N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
#print(Ls)
r = 0
for i in range(N):
  for j in range(i+1, N):
    c = Ls[i]+Ls[j]
    k = bisect.bisect_left(Ls, c, j+1, N)
    #print(i, j, k)
    r += k-j-1
print(r)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define CLEAR(a) memset(a,0,sizeof a)
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fr freopen("input.txt", "r", stdin);
#define fw freopen("output.txt", "w", stdout);
#define int long long 
typedef long long LL;
typedef pair<int,int> pii;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
int a[MAX], b[MAX];

 main() {
    int n;
    cin >> n;
    REP(i, n) cin >> a[i] >> b[i];
    int ret = 0;
    for(int i=n-1;i>=0;i--){
      a[i] += ret;
      if(a[i]%b[i] == 0) continue;
      ret += b[i] - a[i]%b[i];
    }
    cout << ret;
    return 0;
}

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

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

	int height[n];
	int pd[n];

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

	for (int i = 0; i < n; i++) {
		pd[i] = 1e9 + 10;
	}
	pd[0] = 0;

	for (int i = 1; i < n; i++) {
		for (int j = i - k; j < i; j++) {
			if (j >= 0)
				pd[i] = min(pd[i], pd[j] + abs(height[j] - height[i]));
		}
	}

	cout << pd[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
//桁
int kt(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a;
  cin>>a;
  if(a==3||a==5||a==7)
    cout<<"YES";
  else
    cout<<"NO";
}

Measured memory_bytes: 764
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String s = saori.nextHayami();
		for(char i = 'a';i <='z';i++){
			if(s.indexOf(i) < 0){
				System.out.println(i);
				return;
			}
		}
		System.out.println("None");
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

void Print(int size, std::vector<int> ls) {
	for (int i = 0; i < size; i++)
		i != size - 1 ? std::cout << ls[i] << " " :
		std::cout << ls[i] << "\n";
}

void BubbleSort(int size, std::vector<int> ls) {
	int swap = 0;
	for (int i = 0; i < size; i++)
		for (int j = size - 1; j > 0; j--)
			if (ls[j] < ls[j - 1]) {
				int _ = ls[j];
				ls[j] = ls[j - 1];
				ls[j - 1] = _;
				swap++;
			}
	Print(size, ls);
	std::cout << swap << "\n";
}

std::vector<int> scan(int size) {
	std::vector<int> ls(size);
	for (int i = 0; i < size; i++) {
		std::cin >> ls[i];
	}
	return ls;
}

int main() {
	int size;
	std::cin >> size;
	BubbleSort(size, scan(size));
	return 0;
}



Measured memory_bytes: 3176
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); //整数の入力
		int k = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int min = Integer.MAX_VALUE;
		for (int i = 0; i + k - 1 < n; i++) {
			int val = arr[i + k - 1] - arr[i];
			if (val < min) {
				min = val;
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 48636
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ses   "\n"
#define whp   " "
#define mxi 99999

#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define PI acos(-1)
#define sz(a) long long(a.size())
#define ff first
#define ss second
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)

#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)

#define MS(a,b) memset(a,b,sizeof(a));

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll fx[4]= {1,-1,0,0};
ll fy[4]= {0,0,1,-1};

typedef vector<ll> vll;
typedef vector<string> vss;
typedef vector<pair<ll,ll > > vpr;
typedef vector<pair<string,ll > > vspr;
typedef list<ll> li;
typedef list<string> ls;
typedef list<pair<ll,ll> > lpr;
typedef list<pair<string,ll> > lspr;


bool rs(ll a, ll b){return(a>b);}
int main()
{
   vll v,m;

    double k; cin>>k;
    for(ll i=0; i<k; i++){
        ll x; cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end(),rs);
    m.push_back(v[0]);
    ll d=ceil(k/2);
    for(ll i=1; i<d; i++){
        m.push_back(v[i]);
        m.push_back(v[i]);
    }
    ll s=0;
    for(ll i=0; i<k-1; i++){
        s+=m[i];
    }

    cout<<s<<endl;


return 0;
}


Measured memory_bytes: 8100
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = 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;
}

inline long long simula(ll n, ll k) {
    if(k == 1) return 2; 
    if(n == k) return 1; 
    ll end = n;
    while(end >= k) {
        while(end % k == 0) end /= k;
        if(end > k ) end = (end % k);
    }
    return end;
}

set<ll> ans;

void go(ll n, ll x) {
    for(ll i = 1; i * i <= x; ++i) {
        if(x % i == 0) {
            if( simula(n, i) == 1) ans.insert(i);
            if(i != x / i) {
                if(simula(n, x / i) == 1) ans.insert(x/i);
            }
        }
    }
}

// End of template code!
int main() 
{
    buff();
    ll n;
    cin >> n;
    go(n, n);
    go(n, n - 1);
    cout << sz(ans) << endl;
    return 0;
}



Measured memory_bytes: 256
import kotlin.math.*
import java.util.*
import java.io.*
var ans:Int = 0
fun main() {
    val N:Int = readLine()!!.toInt()
    val L = readLine()!!.split(" ").map { it.toLong() }.sorted()
    for(i in 0..N-3){
        for(j in i+1..N-2){
            for(k in j+1..N-1){
                if(L[i]<L[j] && L[j]<L[k]){
                    if(L[k] < L[i]+L[j]){
                        ans++
                    }
                }
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 40824
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x: x, y = x.left if key < x.key else x.right, x
    if y is None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result is None

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'f': print(['yes','no'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))



Measured memory_bytes: 53440
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    string s, t;
    cin >> s;
    cin >> t;

    bool flag = true;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            flag = false;
        }
    }
    if (flag) {
        cout << "Yes" << newl;
    } else {
        cout << "No" << newl;
    }




    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

int main()
{
    int N;
    cin >> N;
    vector<int> Ws(N);

    for (int i = 0; i < N; i++) {
        cin >> Ws[i];
    }

    // Calculate accumulated W
    vector<int> SortedAccW(N);
    for (int i = 0; i < N; i++) {
        SortedAccW[i] = (i >= 1 ? SortedAccW[i - 1] : 0) + Ws[i];
    }
    
    // Find the minimum W dividing
    int minV = std::numeric_limits<int>::max();
    for (int T = 0; T < N-1; T++) {
        int lower = SortedAccW[T];
        int upper = SortedAccW.back() - SortedAccW[T];
        int value = std::abs(upper - lower);
        minV = std::min(minV, value);
    }

    cout << minV << endl;

    return 0;
}

Measured memory_bytes: 256
def b():
    import re
    s = input()
    s = re.sub(r'BC', 'D', s)
    ls = range(len(s))
    ac, c = 0, 0
    for i in ls:
        if s[i] == 'A':
            ac += 1
        elif s[i] == 'D':
            c += ac
        else:
            ac = 0
    return c


ans = b()
print(ans)


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


def solve(D: int):
    ret = 'Christmas' + ''.join([' Eve' for _ in range(25 - D)])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  # type: int
    solve(D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
// ABC154 E - Almost Everywhere Zero
// 問題URL
// https://atcoder.jp/contests/abc154/tasks/abc154_e

#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>

using namespace std;

const int64_t N_MAX = 100;
int64_t pascal_delta[N_MAX][N_MAX];

// combinationを計算
void comb_init()
{
  for (int i = 0; i < N_MAX; i++) {
    pascal_delta[i][0] = 1;
    pascal_delta[i][i] = 1;
  }
  for (int j = 1; j < N_MAX; j++) {
    for (int k = 1; k < j; k++) {
      pascal_delta[j][k] = (pascal_delta[j - 1][k - 1] + pascal_delta[j - 1][k]);
    }
  }
  return;
}

int64_t comb(int n, int r)
{
  if (n < r)
    return 0;
  else
    return pascal_delta[n][r];
}

int main()
{
  char N[100] = {0};
  int digit_num_of_N;
  string string_n;
  int K;

  cin >> string_n >> K;

  digit_num_of_N = string_n.size();
  for (int i = 0; i < string_n.size(); i++) {
    N[i] = string_n[string_n.size() - 1 - i];
  }

  comb_init();

  // Nの桁数より小さい桁数の数字で条件を満たすものの数
  int sum = 0;
  for (int digit_num = 1; digit_num <= digit_num_of_N - 1; digit_num++) {
    sum += comb(digit_num - 1, K - 1) * pow(9, K);
  }

  // Nの桁数と同じ桁数の数字について
  // 最上位の位がNの最上位の位の数字より小さい
  sum += comb(digit_num_of_N - 1, K - 1) * pow(9, K - 1) * (N[digit_num_of_N - 1] - '0' - 1);

  // 上の桁から見て2番目に0以外の数字が出てくる桁は？
  int digit_num_of_N_second = digit_num_of_N;
  for (int i = digit_num_of_N - 2; i >= 0; i--) {
    if (N[i] != '0') {
      digit_num_of_N_second = i + 1;
      break;
    }
  }

  if (digit_num_of_N_second != digit_num_of_N) {
    sum += comb(digit_num_of_N_second - 1, K - 2) * pow(9, K - 2) * (N[digit_num_of_N_second - 1] - '0' - 1);
    sum += comb(digit_num_of_N_second - 1, K - 1) * pow(9, K - 1);
  }
  else {
    if (K == 1) sum += 1;
    cout << sum << endl;
    return 0;
  }

  // 上の桁から見て3番目に0以外の数字が出てくる桁は？
  int digit_num_of_N_third = digit_num_of_N_second;
  for (int i = digit_num_of_N_second - 2; i >= 0; i--) {
    if (N[i] != '0') {
      digit_num_of_N_third = i + 1;
      break;
    }
  }

  if (digit_num_of_N_third != digit_num_of_N_second) {
    sum += comb(digit_num_of_N_third - 1, K - 3) * (N[digit_num_of_N_third - 1] - '0');
    sum += comb(digit_num_of_N_third - 1, K - 2) * pow(9, K - 2);
  }
  else {
    if (K == 2) sum += 1;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct Tree{
  string name;
  Tree* par;
  vector<Tree> chd;

  Tree* found(string s){
	REP(i,SZ(chd))
	  if(chd[i].name == s)
		return &chd[i];
	return 0;
  }
  Tree(): par(0){}
};

void dfsp(Tree& t, int d){
  REP(i,d) cout << " ";
  cout << t.name << endl;
  for(auto& ch: t.chd)
	dfsp(ch, d+1);
}

VS part(string s){
  VS res;
  int p = 0;
  for(int j=0;j<SZ(s);++j){
	if(s[j] == '/' || j == SZ(s)-1){
	  string t = s.substr(p, j-p+1);
	  res.PB(t);
	  p = j + 1;
	}
  }

  return res;
}


Tree* dir(VS& path, Tree* cur){
  REP(j,SZ(path)){
	if(path[j] == "." || path[j] == "./") continue;
	else if(path[j] == ".." || path[j] == "../"){
	  cur = cur->par;
	  if(!cur) return 0;
	}
	else{
	  Tree* nxt = cur->found(path[j]);
	  if(nxt)
		cur = nxt;
	  else if(path[j].back() != '/')
		cur = cur->found(path[j]+"/");
	  else
		cur = 0;
	  if(!cur) return 0;
	}
  }

  if(cur->name.back() == '/'){
	//	for(auto& s: path) cout << s << "->";cout<<endl;
	cur = cur->found("index.html");
  }
  return cur;
}

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

  int N, M;
  while(cin>>N>>M,N){
	Tree root;
	root.chd.emplace_back();
	root.chd.back().name = "/";
	REP(i,N){
	  Tree* cur = &root;
	  string s; cin >> s;
	  // /?????¨?????????
	  VS p = part(s);

	  for(int j=0;j<SZ(p);++j){
		string& t = p[j];
		Tree* nxt = cur->found(t);
		// ?????£??¬?????????????????¨???????????¨???
		if(!nxt){
		  cur->chd.emplace_back();
		  cur->chd[SZ(cur->chd)-1].par = cur;
		  cur = &cur->chd[SZ(cur->chd)-1];
		  cur->name = t;
		}
		else cur = nxt;
	  }
	}
	
	REP(i,M){
	  string d1, d2; cin >> d1 >> d2;
	  VS p1 = part(d1), p2 = part(d2);
	  Tree* t1 = dir(p1, &root);
	  Tree* t2 = dir(p2, &root);

	  if(!t1 || !t2) cout << "not found" << endl;
	  else if(t1 != t2) cout << "no" << endl;
	  else cout << "yes" << endl;
	}
  }

  return 0;
}

Measured memory_bytes: 1236
# ABC159a


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと
    import math

    def dump(*args):
        sys.stderr.write(str(args))

    def c_count(n, r):  # 組み合わせ
        if n - r < 0:
            return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    n, m = map(int, input().split())
    print(c_count(n, 2)+c_count(m, 2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
s=input()
q=int(input())
is_reverse=False
pre=[]
post=[]
for i in range(q):
    qi=list(input().split())
    if(len(qi)==1):
        is_reverse = not is_reverse
    elif(qi[1]=="1"):
        if(is_reverse):
            post.append(qi[2])
        else:
            pre.append(qi[2])
    else:
        if(is_reverse):
            pre.append(qi[2])
        else:
            post.append(qi[2])

if(is_reverse):
    print(''.join(post)[::-1] + s[::-1] + ''.join(pre))
else:
    print(''.join(pre)[::-1] + s + ''.join(post))

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

int main() {
    ll N, M;
    multiset<double> A;
    cin >> N >> M;
    for(ll i = 0; i < N; i++) {
        double tmp;
        cin >> tmp;
        A.insert(tmp);
    }
    for(ll i = 0; i < M; i++) {
        double tmp = *(--A.end()) / 2;
        A.erase(--A.end());
        A.insert(tmp);
    }
    ll ans = 0;
    for(auto itr = A.begin(); itr != A.end(); itr++){
        ans += (ll)*itr;
    }
    cout << ans << endl;
    cin >> N;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int n,g[3][MX];

ll numInv(vi x) {
    Tree<int> T;
    ll ans = 0;
    for (int i: x) {
        ans += sz(T)-T.order_of_key(i);
        T.insert(i);
    }
    return ans;
}

void checkEven(vi x) {
    int ans = 0;
    for (int i = 1; i < sz(x); i += 2) if (x[i] < 0) ans ++;
    vi X;
    for (int i = 0; i < sz(x); i += 2) X.pb(abs(x[i]));
    if ((ans&1) != (numInv(X)&1)) {
        cout << "No";
        exit(0);
    }
}

void checkOdd(vi x) {
    int ans = 0;
    for (int i = 0; i < sz(x); i += 2) if (x[i] < 0) ans ++;
    vi X;
    for (int i = 1; i < sz(x); i += 2) X.pb(abs(x[i]));
    if ((ans&1) != (numInv(X)&1)) {
        cout << "No";
        exit(0);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    F0R(i,3) F0R(j,n) cin >> g[i][j];
    vi ans;
    F0R(i,n) {
        vi z; F0R(j,3) z.pb(g[j][i]);
        sort(all(z));
        if (z[0]+2 != z[2]) {
            cout << "No";
            return 0;
        }
        if (z[0]+1 != g[1][i]) {
            cout << "No";
            return 0;
        }
        if (z[0] == g[0][i]) ans.pb(z[2]/3);
        else ans.pb(-z[2]/3);
    }
    F0R(i,n) {
        if (i&1) {
            if (ans[i] % 2 != 0) {
                cout << "No";
                return 0;
            }
        } else {
            if (ans[i] % 2 == 0) {
                cout << "No";
                return 0;
            }
        }
    }
    checkEven(ans);
    checkOdd(ans);
    // must reduce by a factor of 4
    /*F0R(i,n) {
        if (i < n-2) {
            if (ans[i] < 0) ans[i] *= -1, ans[i+1] *= -1, ans[i+2] *= -1;
        } else if (ans[i] < 0) {
            cout << "No";
            return 0;
        }
    }*/
    cout << "Yes";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 4984
#include "bits/stdc++.h"
using namespace std;
int main(int argc, char const *argv[])
{
	int N,T,minimum=100000;
	cin>>N>>T;
	while(N--)
	{
		int c,t;
		cin>>c>>t;
		if (t<=T)
		{
			minimum=min(c,minimum);
		}
		
	}
	if (minimum==100000)
	{
		cout<<"TLE"<<endl;
	}
	else
		cout<<minimum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    char str[100005]={0};
    scanf("%s", str);

    long s[30]={0};

    long len=strlen(str);
    long i;
    for(i=0; i<len; i++) {
        s[str[i]-'a']=1;
    }

    for(i=0; i<26; i++) {
        if(s[i]!=1) {
            printf("%c\n", (char)'a'+i);
            return 0;
        }
    }
    printf("None\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,true,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000000000000007
#define sz(a) ll((a).size())
#define pii 3.14159265358979
#define ld long double
int main()
{
	// freopen("in.txt","r",stdin);
	// freopen("out","w",stdout);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll t;t=1;
	// BAhUT KHUSI ,MILI YE QUESTION BANAKE
	// cin >> t;
	while(t--)
	{
		ld a,b; cin >>a>>b;
		ld ans = a*b;
		cout<<(ll)ans;
	}
}

Measured memory_bytes: 3736
#!/usr/bin/env python3
import math
def main():
    S = input()
    S_len = len(S)
    hug_count = 0
    for i in range(math.floor(S_len/2)):
        if S[i] != S[S_len - (i+1)]:
            hug_count += 1
    print(hug_count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
//ll const mod=1e9+7;
const ll MAX=300000;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////


int main(){
    int n,k;
    cin>>n>>k;
    int ans=(n-1)/(k-1);
    if((n-1)%(k-1))ans++;
    
    rep(i,n){
      int a;
      cin>>a;
    }
    
    cout<<ans<<endl;

    return 0;
}

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

typedef long long ll;

int f(ll a, ll b) {
    if (a > b) swap(a, b);
    int res = 0;
    while (b > 0) {
        res++;
        b /= 10;
    }
    return res;
}

int main(void){
    // Your code here!
    ll N;
    cin >> N;
    
    int ans = 1001001001;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            ans = min(ans, f(i, N / i));
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();
const unsigned long long int ULLINF = numeric_limits<unsigned long long int>::max();

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

    string s; cin >> s;

    if (s == "RRR") { cout << 3 << endl; return 0;}

    else if (s.substr(0,2)=="RR" | s.substr(1,2)=="RR") {cout << 2 << endl; return 0;}

    else if ((s[0]=='R'||s[1]=='R')||s[2]=='R') {cout << 1 << endl; return 0;}

    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s,t;
  	cin>>s>>t;
  	ll i,n=s.size();
  	vector<int>  a(26),b(26);
  
  	
  	for(i=0;i<n;i++){
		a[s[i]-'a']++;
		b[t[i]-'a']++;
    }
  	
  	sort(a.begin(),a.end());
  	sort(b.begin(),b.end());
  
  	for(i=0;i<26;i++){
  		if(a[i]!=b[i]){
			cout<<"No"<<endl;
          	return 0;
  	    }
    }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 3e6;
const int PLS = 3e5 + 123;
const ll mod = 1e9 + 7;
const ll inf = 1e16;


ll n, a[30][30], dp[N], pw[30];
vector <int> M[30];

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    ll t = 1;
    for (int i = 0; i <= 22; i++) {
        pw[i] = t;
        t *= 2;
    }
    dp[0] = 1;
    for (int mask = 1; mask < pw[n]; mask++) {
        ll tmp = __builtin_popcount(mask);
        for (int j = 0; j < n; j++)
            if ((1 & (mask>>j)) && a[tmp - 1][j])
                dp[mask] = (dp[mask] + dp[(mask ^ pw[j])]) % mod;
    }
    cout << dp[pw[n] - 1];
}

Measured memory_bytes: 18688
// AtCoder Grand Contest 050
// A - Addition and Subtraction Easy
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  char op;
  cin >> a >> op >> b;

  if (op == '+') {
    cout << a + b << endl;
  } else {
    cout << a - b << endl;
  }
}

Measured memory_bytes: 256
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

void main() {
  long [] a = readln.chomp.split.to!(long[]);
  long N = a[0], M = a[1];
  long ans;

  if (N == 1 && M == 1) {
    ans = 1;
  }
  else if (N == 1 || M == 1) {
    ans = max(N, M) - 2;
  }
  else if (N == 2 || M == 2) {
    ans = 0;
  }
  else {
    ans = (N - 2) * (M - 2);
  }

  writeln(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll h,w,pt[1000][1000];

ll dp(ll x,ll y);
int main() {
	cin >> h >> w;
	fill(pt[0], pt[1000], -1);
	pt[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			char c;
			cin >> c;
			if (c == '#')pt[i][j] = 0;
		}
	}
	cout << dp(h - 1, w - 1) << endl;
}
ll dp(ll x,ll y) {
	if (pt[x][y] == -1) {
		pt[x][y] = ((x!=0?dp(x-1,y):0)+(y!=0?dp(x,y-1):0))%mod;

	}
	return pt[x][y];
}


Measured memory_bytes: 8064
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]

s = input()
t = input()

t = t[:-1]
if s == t:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll a[99]={0,0,2,0,1,0,1,0,0,1,0,1,0};
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	puts(a[n]==a[m]?"Yes":"No");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>

#define nl '\n'

using namespace std;

double n;

int main(){

    cin >> n;

    cout << ceil(n/2);




}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out


//Surely this is going to AC

Measured memory_bytes: 256
n=int(input())
tasks=[]
for i in range(0,n):
    a,b=map(int,input().split())
    tasks.append((b,a))
tasks.sort()
now=0
fail=0
for i in tasks:
    b=i[0]
    a=i[1]
    now+=a
    if now>b:
        fail=1
if fail:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 29444
#include <stdio.h>
#define MAX_N (22)

int n, q;
int A[MAX_N];

bool solve( int i, int m );

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

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

    scanf("%d", &q);
    
    for ( int i = 0; i < q; i++ ) {
	int m;
	scanf("%d", &m);
	if ( solve( 0, m ) ) {
	    printf("yes\n");
	}
	else {
	    printf("no\n");
	}
    }

    return 0;
}


bool solve( int i, int m )
{
    if ( m == 0 ) {
	return true;
    }

    if ( m < 0 ) {
	return false;
    }

    if ( i >= n ) {
	return false;
    }
   
    if ( solve( i + 1, m ) ) return true;
    if ( solve( i + 1, m - A[i] ) ) return true;
       
    return false;
}

Measured memory_bytes: 1012
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = 1;
		for(int i = 0 ; i < n ; i++) {
			if(ans * 2 > ans + k) {
				ans += k;
			} else {
				ans *= 2;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22356
x, k, d = map(int, input().split())

mx = x + k * d
mn = x - k * d

if (mx > 0 and mn < 0):
    ans1 = x % d
    ans2 = d - x % d
    k -= abs(x % d - x) // d
    if k % 2 == 0:
        print(ans1)
    else:
        print(ans2)
else:
    print(min(abs(mx), abs(mn)))

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N,M,H,W,K,Q,A,B;

int main(){
  cin>>N; 
  vector<string> G(N); 
  rep(i,N) cin>>G[i]; 
  vec row(N,0), col(N,0);
  rep(i,N) rep(j,N) row[i] += G[i][j] == '#'; 
  rep(j,N) rep(i,N) col[j] += G[i][j] == '#';
  ll temp = -1, ans = 0; 
  bool ok= false; 
  rep(i,N) { 
    if(col[i] > 0) temp = max(temp, row[i] ); 
    else temp = max(temp, row[i] - 1);
    ans += col[i] != N;  
    if(col[i] != 0) ok = true;
  } 
  cout<<(ok ? ans + N - temp : -1)<<endl; 
}


Measured memory_bytes: 512
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string a,b; cin>>a>>b;
    for(int i=0;i<a.size();i++){
        cout<<a[i];
        if(i<b.size())cout<<b[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
int main(){
    char stl[1001];
    scanf("%s",stl);
    for(int i=0;;i++){
        if(stl[i]==0)
            break;
        //A=65
        if(stl[i]<=67)
            stl[i]+=23;
        else
            stl[i]-=3;
        printf("%c",stl[i]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1112
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
 
int q;
 
int main(){
    multimap<string, int> mma;
    cin >> q;
    for(int i = 0; i < q; i++){
        char query;
        cin >> query;
        if(query == '0'){
            string key;
            int x;
            cin >> key >> x;
            mma.insert(make_pair(key, x));
        }else if(query == '1'){
            string key;
            cin >> key;
            multimap<string, int>::iterator itr;
            pair<multimap<string, int>::iterator, multimap<string, int>::iterator> itr1 = mma.equal_range(key);
            for(itr = itr1.first; itr != itr1.second; itr++){
                cout << itr -> second << endl;
            }
        }else if(query == '2'){
            string key;
            cin >> key;
            pair<multimap<string, int>::iterator, multimap<string, int>::iterator> itr1 = mma.equal_range(key);
            mma.erase(itr1.first, itr1.second);
        }else if(query == '3'){
            string L, R;
            cin >> L >> R;
            multimap<string, int>::iterator itr, itr1, itr2;
            itr1 = mma.lower_bound(L);
            itr2 = mma.upper_bound(R);
            for(itr = itr1; itr != itr2; itr++){
                cout << itr -> first << ' ' << itr -> second << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 24896