akhauriyash/Code-Regression huggingface dataset:
from itertools import product


def solve(string):
    n, m, *ksp = map(int, string.split())
    p = ksp[-m:]
    ans = 0
    for t in product([True, False], repeat=n):
        index = 0
        for i, _p in enumerate(p):
            k = ksp[index]
            use = ksp[index + 1:index + 1 + k]
            index += k + 1
            if sum([t[j - 1] for j in use]) % 2 != _p:
                break
        else:
            ans += 1
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m + 1)])))


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

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define pb push_back
#define mp make_pair
#define MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define IG cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define ll long long int
#define N 1378
#define maxn 1000003
#define FP ff.open("output.txt")
#define FR ff.open("input.txt")
#define valid(a,b) if(a>=1 && a<row-1 && b>=1 && b<col-1)
fstream ff;

ll a, q, b, c, d, k, h, e, f, t, m, n, i, j, x, y, count, tcase = 0, l, r;

string s1, s2, s;

int main() {
	int count = 0,res=0;
	cin>>n;
	while(n--){
		cin>>a>>b;
		if(a==b) count++;else count=0;
		if(count>=3) {
			res=1;
		}
	}
	if(res) cout<<"Yes\n" ; else cout<<"No\n";
	return 0;
}


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

const unsigned int MOD = 1000000007;

int main() {
    std::string L;
    std::cin >> L;

    unsigned int x = 1, y = 0;
    for (char c : L) {
        y = y * 3 % MOD;
        if (c == '1') {
            y = (y + x) % MOD;
            x = x * 2 % MOD;
        }
    }

    std::cout << (x + y) % MOD << "\n";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

template<typename T> struct BIT {
	vector<T> bit;
	int n;
	
	BIT() {}
	BIT(int n) : bit(vector<T>(n + 2, 0)), n(n) {}
	
	T sum(int i) {
		i++;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i, T x) {
		i++;
		while (i <= n) {
			bit[i] += x;
			i += i & -i;
		}
	}
	
	T pquery(int i) {
		return sum(i) - sum(i - 1);
	}
	
	int lower_bound(T x) {
		int l = -1, r = bit.size();
		while (r - l > 1) {
			int m = (l + r) / 2;
			
			if (sum(m) >= x) r = m;
			else l = m;
		}
		if (r == bit.size()) r = -1;
		
		return r;
	}
};

int N, K;
int P[212345];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", P + i);
	
	BIT<int> bit(212345);
	ll cnt = 0;
	REP(i, K) {
		cnt += bit.sum(212340) - bit.sum(P[i]);
		bit.add(P[i], 1);
	}
	int ans = cnt > 0;
	bool zero = cnt == 0;
	FOR(i, K, N) {
		bool ok = false;
		bit.add(P[i - K], -1);
		ll cur = bit.sum(P[i - K]);
		cnt -= cur;
		if (cur > 0 && cnt > 0) ok = true;
		
		
		cur = bit.sum(212340) - bit.sum(P[i]);
		cnt += cur;
		if (cur == 0 && cnt == 0) zero = true;
		bit.add(P[i], 1);
		if (cur > 0) ok = true;
		if (ok) ans++;
	}
	if (zero) ans++;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1920
S = input()
N = len(S)

def dfs(i, f):
    if i == N-1:
        return sum(list(map(int, f.split('+'))))
    return dfs(i+1, f+'+'+S[i+1]) + dfs(i+1, f+S[i+1])

print(dfs(0, S[0]))

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

int main(void)
{
  int l, a, b, c, d;
  cin >> l >> a >> b >> c >> d;
  int ja = a/c + (a%c == 0 ? 0 : 1);
  int ma = b/d + (b%d == 0 ? 0 : 1);
  int result = l - (ja<ma ? ma : ja);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, 0, n) {
        cout <<  s[i] << t[i];
    }
    cout << endl;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
   int n;
   cin>>n;
   string s,t;
   cin>>s>>t;
   string S=s,T=t;
   int ans=0;
   rep(i,n+1){
       bool flag=true;
       s+=t.substr(i);
       rep(k,n){
if(t[k]!=s[s.size()-n+k]) flag=false;
       }
       if(flag){
ans=s.size();
       }
       //cout<<s<<endl;
       s=S;
   }
   cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
class MaximumMatching
  
  def initialize l, r
    @L = l
    @R = r
    @adj = Array.new(l + r) { [] }
  end

  def add u, v
    @adj[u] << v + @L
    @adj[v + @L] << u
  end

  def maximum_matching
    @visited = Array.new(@L)
    @meta = Array.new(@L + @R) { -1 }

    match = 0
    @L.times do |u|
      @visited.fill false
      match += 1 if augment u
    end
    match
  end

  private

  def augment u
    return false if @visited[u]
    @visited[u] = true

    @adj[u].each do |w|
      v = @meta[w]
      if v < 0 || augment(v)
        @meta[u] = w
        @meta[w] = u
        return true
      end
    end

    false
  end
end

x, y, e = gets.split.map(&:to_i)
g = MaximumMatching.new(x, y)
e.times do
  x, y = gets.split.map(&:to_i)
  g.add x, y
end
puts g.maximum_matching


Measured memory_bytes: 9076
#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() {
   string s;
   cin >> s;
   char c='a';
   string ans="a";
   while(s.find(c)!=-1){
      c++;
      ans=c;
      if(c>'z'){
      ans="None"; break;
      }
   }
   cout << ans << endl;
}

Measured memory_bytes: 512
import sys
p = [1<<i for i in range(17)]
li = [[] for i in range(p[16])]
for k in range(p[16]):
    for i in range(16):
        if not (k&p[i]):
            li[k].append(i)
def solve(n,t):
    s = [[(t[i][j+1],j) for j in range(n)] for i in range(n)]
    for i in range(n):
        s[i].sort()
    m = p[n]
    dp = [float("inf")]*(m)
    for i in range(n):
        dp[p[i]] = t[i][0]

    for k in range(m):
        for i in li[k]:
            if i >= n:continue
            l = k|p[i]
            mi = t[i][0]
            for x,j in s[i]:
                if (k&p[j]):
                    if mi > x:
                        mi = x
                        break
            if dp[l] > dp[k]+mi:
                dp[l] = dp[k]+mi
    print(dp[-1])

while 1:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    t = [list(map(int,sys.stdin.readline()[:-1].split())) for i in range(n)]
    solve(n,t)



Measured memory_bytes: 18796
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <cstdio>
#include <iostream>
#include <algorithm>

#define SIZE 200000
#define MAXI 1200012

using namespace std;

int main() {
    long long int i,j,k,N,M,K,Q,X,B;
   long long int A[13][13];
   long long int C[13],T[13];
   scanf("%lld %lld %lld", &N, &M, &X); 
   for (i=1;i<=N;i++) {
       scanf("%lld", &C[i]); 
     for (j=1;j<=M;j++)
        cin >> A[i][j]; 
   }

   long long int combi,combi2;

   long long int mincost,cost;
   int encore;

   mincost = MAXI;
   for (combi=0;combi<(1<<N);combi++) {
     // on teste tout le monde
      combi2 = combi;
      for (i=1;i<=M;i++) // algos
        T[i] = 0;
      cost = 0;
      for (i=1;i<=N;i++) {
          if (combi2 % 2) {
            cost += C[i];
            for (j=1;j<=M;j++)
              T[j] += A[i][j];
          }
          combi2 >>= 1;
      }

      encore = 1;
      for (i=1;(i<=M) && encore;i++)
        if (T[i] < X)
          encore = 0;
      if ((encore) && (cost < mincost))
        mincost = cost;
    }
    if (mincost >= (MAXI) )
        printf("%d\n", -1); 
    else
        printf("%lld\n", mincost); 

  return 0;

}

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


int main(){
   int n;
   cin >> n;
   vector<int> v(n);
   vector<int> order(n);
   for(int i=0;i<n;i++)cin >> v[i],order[v[i]-1]=i+1;
   for(int i=0;i<n;i++)cout<<order[i]<<' '; 
}

Measured memory_bytes: 1536
import java.util.Scanner;

class Main {

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

	int N = sc.nextInt();
	String S = sc.next();

	int count = 0;
	String[] x = S.split("");
	for (int i = 0; i < N - 1; i++) {
	    if (x[i].equals(x[i + 1]))
		count++;
	}

	System.out.println(N - count);
    }
}

Measured memory_bytes: 33008
N = int(input())
S = input()
Wl = []
El = []
c = 0
for i in range(N):
    if S[i] == 'W':
        c += 1
    Wl.append(c)
c = 0
for i in range(N):
    if S[-(1 + i)] == 'E':
        c += 1
    El.append(c)
El.reverse()
Amin = min(El[1], Wl[N - 2])
for i in range(1, N - 2):
    A = Wl[i - 1] + El[i + 1]
    Amin = min(Amin, A)
print(Amin)

Measured memory_bytes: 67964
unittest
{
	assert( [ "oder atc" ].parse.expand.solve == "atcoder" );
	assert( [ "humu humu" ].parse.expand.solve == "humuhumu" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto st = input.front.split.to!( dchar[][] );
	return tuple( st[ 0 ], st[ 1 ] );
}

auto solve( dchar[] s, dchar[] t )
{
	return t ~ s;
}


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

using namespace std;

#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)
#define not_equal(a,b) (!equal(a,b))
#define lt(a,b) (a-b < -EPS)

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
  Point operator / (const double &k)const{ return Point(x/k,y/k); }
  bool operator < (const Point &p)const{ return x != p.x ? x < p.x : y < p.y; }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }
double abs(const Point &p){ return sqrt(norm(p)); }

istream &operator >> (istream &is,Point &p){ 
  return is >> p.x >> p.y;
}

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a,b) > EPS){ return COUNTER_CLOCKWISE; }
  if(cross(a,b) < -EPS){ return CLOCKWISE; }
  if(dot(a,b) < -EPS){ return ONLINE_BACK; }
  if(norm(a) < norm(b)){ return ONLINE_FRONT; }
  return ON_SEGMENT;
}

struct Segment{
  Point s,t;
  Segment(){}
  Segment(Point s,Point t) : s(s),t(t) {}
};

Point projection(const Segment &s,const Point &p){
  Vector b = s.t-s.s;
  double t = dot(p-s.s,b)/norm(b);
  return s.s+b*t;
}

bool isIntersectSP(const Segment &s,const Point &p){
  return equal(ccw(s.s,s.t,p),0);
}

bool isIntersectSS(const Segment &a,const Segment &b){
  Point s[2] = {a.s,a.t}, t[2] = {b.s,b.t};
  return (ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0
          && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0);
}

double distanceSP(const Segment &s,const Point &p){
  Point r = projection(s,p);
  if(isIntersectSP(s,r)){ return abs(r-p); }
  return min(abs(s.s-p),abs(s.t-p));
}

double distanceSS(const Segment a,const Segment b){
  if(isIntersectSS(a,b)){ return 0; }
  return min(min(distanceSP(a,b.s),distanceSP(a,b.t)),
             min(distanceSP(b,a.s),distanceSP(b,a.t)));
}

int main(){
  int N1,N2;
  vector<Point> p[2];
  cin >> N1;
  p[0].resize(N1+2);
  p[0][0] = Point(0,0);
  p[0][N1+1] = Point(1000,0);
  for(int i = 1 ; i <= N1 ; i++){
    cin >> p[0][i];
  }
  cin >> N2;
  p[1].resize(N2+2);
  p[1][0] = Point(0,1000);
  p[1][N2+1] = Point(1000,1000);
  for(int i = 1 ; i <= N2 ; i++){
    cin >> p[1][i];
  }
  vector<Segment> s[2];
  for(int i = 1 ; i <= N1+1 ; i++){
    s[0].push_back(Segment(p[0][i-1],p[0][i]));
  }
  for(int i = 1 ; i <= N2+1 ; i++){
    s[1].push_back(Segment(p[1][i-1],p[1][i]));
  }
  double res = (1<<29);
  int l1 = s[0].size(), l2 = s[1].size();
  for(int i = 0 ; i < l1 ; i++){
    for(int j = 0 ; j < l2 ; j++){
      res = min(res,distanceSS(s[0][i],s[1][j]));
    }
  }
  printf("%.10f\n",res);
  return 0;
}

Measured memory_bytes: 1260
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,c,k;
int t[200000];
int main(){
	scanf("%d%d%d",&n,&c,&k);
	for(int i = 0;i < n;i++){
		scanf("%d",&t[i]);
	}
	sort(t,t+n);
	int pre = -1;
	int cnt = 0;
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(pre == -1){
			pre = t[i];
			ans++;
			cnt++;
		}
		else{
			if(t[i] - pre > k){
				pre = -1;
				cnt = 0;
				i--;
			}
			else if(cnt >= c){
				pre = -1;
				cnt = 0;
				i--;
			}
			else{
				cnt ++;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

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

    int n,m;
    cin >> n >> m;
    vector<int> arr(n+1,0);
    int l,r;
    REP(i,m){
        cin >> l >> r;
        arr[l-1]++;
        arr[r]--;
    }
    int cou=0,sum=0;
    REP(i,n){
        sum += arr[i];
        if(sum==m)cou++;
    }
    cout << cou << endl;

}


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

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

    int count = -4;

    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
            if(S.at(i) == S.at(j)){
                count++;
            }
        }
    }


    if(count == 4){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    
}

Measured memory_bytes: 256
import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, w, a, b = ns()

    for i in range(h):
        if i < b:
            print("0" * a + "1" * (w - a))
        else:
            print("1" * a + "0" * (w - a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6016
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll N,M; cin>>N>>M;
  vector<bool> kanou(N,false);
  kanou.at(0)=true;
  vector<ll> kosu(N,1);
  rep(i,M)
  {
    ll x,y; cin>>x>>y;
    x--; y--;
    if(kanou.at(x)) {kanou.at(y)=true;}
    kosu.at(x)--;
    kosu.at(y)++;
    if(kosu.at(x)==0) {kanou.at(x)=false;}
  }
  ll ans=0;
  rep(i,N)
  {
    if(kanou.at(i)) {ans++;}
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){ 
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  if (s[0] == '2' || s[0] == '4' || s[0] == '5' || s[0] == '7' || s[0] == '9') {
    cout << "hon" << endl;
  } else if (s[0] == '0' || s[0] == '1' || s[0] == '6' || s[0] == '8') {
    cout << "pon" << endl;
  } else {
    cout << "bon" << endl;
  }
  return 0;
} 

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

int main() {
  int N;
  string A;
  
  cin >> N;
  
 
  for (int i=0;i<N;i++){
    cin >> A;
    if (A=="Y"){
      cout << "Four" << endl;
      break;
    }
    if (i==N-1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;


int main()
{
	int n,a,b,c;
	int zen[9];//0...not used 1...A 2...B 3...C
	int l[8];
	ll ans=1e14-1;
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++)
		cin>>l[i];
	fill(zen,zen+9,0);
	for(int i=0;i<(1<<16);i++)
	{
		//更新
		zen[0]++;
		for(int i=0;i<n;i++)
		{
			if(zen[i]==4)
			{
				zen[i]=0;
				zen[i+1]++;
			}
		}

		int ban[3];
		ll cnt=0;
		fill(ban,ban+3,0);
		for(int i=0;i<n;i++)
		{
			if(zen[i]!=0)
			{
				if(ban[zen[i]-1]>0)
					cnt+=10;
				ban[zen[i]-1]+=l[i];
			}
		}
		if(ban[0]==0 || ban[1]==0 || ban[2]==0)
			continue;
		cnt+=abs(a-ban[0])+abs(b-ban[1])+abs(c-ban[2]);
		ans=min(cnt,ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int n;
    while(cin>>n&&n){
        map<int, vector<int> > m;
        vector<set<int> > s(n);
        REP(i, n){
            s[i].insert(i);
            int time;
            cin >> time;
            REP(j, time){
                int d;
                cin >> d;
                m[d].push_back(i);
            }
        }
        int ans = -1;
        foreach(i, m){
            vector<int> line = i.second;
            set<int> sum;
            foreach(j, line){
                foreach(k, s[j])sum.insert(k);
            }
            foreach(j, line){
                foreach(k, sum)s[j].insert(k);
            }
            if(sum.size()==n){
                ans=i.first;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3188
#include <stdio.h>

int main(){
  long a,b,c;
  long p1,p2,p3;
  long min;
  scanf("%ld %ld %ld",&a,&b,&c);
  if(a%2==0 || b%2==0 || c%2==0){
    printf("0\n");
    return 0;
  }
  p1=b*c;
  p2=a*b;
  p3=a*c;
  min=(p1<p2)?p1:p2;
  min=(min<p3)?min:p3;
  printf("%ld\n",min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    string s;
    cin>>s;
    int ans=(int)(s[0]-'0')+(int)(s[1]-'0')+(int)(s[2]-'0');
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int,int> P;
#define MAX_N 1000
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int W,H,N;
int X1[MAX_N],X2[MAX_N],Y1[MAX_N],Y2[MAX_N];

bool fld[MAX_N*6][MAX_N*6];

int compress(int *x1,int *x2,int w){
  vector<int> xs;
  for(int i=0;i<N;i++){
    for(int d=-1;d<=1;d++){
      int tx1=x1[i]+d,tx2=x2[i]+d;
      if(1<=tx1&&tx1<=w)xs.push_back(tx1);
      if(1<=tx2&&tx2<=w)xs.push_back(tx2);
    }
  }
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  
  for(int i=0;i<N;i++){
    x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
    x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
  }
  
  return xs.size();

}

void solve(){


  W = compress(X1,X2,W);
  H = compress(Y1,Y2,H);
  

  memset(fld,0,sizeof(fld));
  
  for(int i=0;i<N;i++){
    for(int y=Y1[i];y<=Y2[i];y++){
      for(int x=X1[i];x<=X2[i];x++){
	fld[y][x]=true;
      }
    }
  }
  /*
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<fld[i][j];
    }
    cout<<endl;
  }
  */
  int ans=0;
  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      if(fld[y][x])continue;
      ans++;
      queue< P > que;
      que.push(P(x,y));
      while(!que.empty()){
	int sx=que.front().first;
	int sy=que.front().second;
	que.pop();
	for(int i=0;i<4;i++){
	  int tx=sx+dx[i],ty=sy+dy[i];
	  if(tx<0||W<=tx)continue;
	  if(ty<0||H<=ty)continue;
	  if(fld[ty][tx])continue;
	  que.push(P(tx,ty));
	  fld[ty][tx]=true;
	}
      }
    }
  }
  cout<<ans<<endl;
}

int main(){
  while(1){
    cin>>W>>H;
    if(W==0&&H==0)break;
    cin>>N;
    for(int i=0;i<N;i++){
      cin>>X1[i]>>Y1[i]>>X2[i]>>Y2[i];
      X1[i]++;
      Y1[i]++;
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 36416
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

int main(){
	while(1){
		char a[20];
		int L;
		cin>>a>>L; 
		if(!L) break;

		int hist[30], after=0, count=1;
		int ans1, ans2;
		hist[0] =atoi(a);
		while(1){
			fill(a+strlen(a), a+L, '0');
			vector<int> max(L, 0), min(L, 0);
			for(int i=L-1; i>=0; i--){
				max[i] = min[i] = a[i]-'0';
			}
			sort(max.begin(), max.end());
			sort(min.begin(), min.end(),greater<int>());
			int imax=0, imin=0;
			for(int i=0; i<L; i++){
				if(max[i] == 0) imax*=10;
				else imax += max[i]*pow(10, i);
				imin += min[i]*pow(10, i);
			}
			after = imax - imin;
			bool flag=false;
			for(int i=0; i<count; i++){
				if(hist[i] == after){
					flag =true;
					ans1 = i;
					break;
				}
			}
			if(flag) break;
			hist[count++] = after;
			//itoa(after, a, 10);
			sprintf(a, "%d", after);
		}
		cout << ans1 << " " << after << " " << count-ans1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3476
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<stack>
#include<cstring>
#include<map>
#include<vector>
#define ll long long int
using namespace std;
int main()
{
    ll a,b;
    char c;
    scanf("%lld %c %lld",&a,&c,&b);
    if(c=='+')
        printf("%lld",a+b);
    else
        printf("%lld",a-b);
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    m2 = len([a for a in A if a % 2 == 0])
    m4 = len([a for a in A if a % 4 == 0])
    mx = N - m2
    if mx == m4 + 1 and m2 - m4 == 0:
        print('Yes')
    elif mx > m4:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

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

int main(){
	
	string word ;
	cin >> word ;
	
	for( int i=0 ; i<word.size() ; i++ ){
		if( word[i] <= 67 ) word[i] = word[i]+26-3 ;
		else word[i] = word[i]-3 ;
	}
	
	cout << word << endl ;
	
return 0 ;
}

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

class Mondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var T = 1L;
        var A = 1L;
        for (int i=0;i<N;++i)
        {
            var ta = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            var a = Math.Max((T+ta[0]-1)/ta[0],(A+ta[1]-1)/ta[1]);
            T = a * ta[0];
            A = a * ta[1];
        }
        Console.WriteLine(T+A);
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define end return 0;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 200005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W;

int main(void) {
    ll i, j;
    cin >> H >> W;
    char a[H][W];
    ll cnt=0;
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            cin >> a[i][j];
            if(a[i][j]=='#') cnt++;
        }
    }
    if(cnt==H+W-1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<vector>
#include<utility>
using namespace std;
void chmax(int &X,int Y)
{
	if(X < Y) X = Y;
}
int popcount(int bit,int N)
{
	int ans = 0;
	for(int i = 0;i < N;i++)
	{
		if(bit & (1<<i)) ans++;
	}
	return ans;
}
void ConvertToVector(vector<int> &tmpvec,int bit,int N)
{
	for(int i = 0;i < N;i++)
	{
		if(bit & (1<<i)) tmpvec[i] = 1;
		else tmpvec[i] = 0;
	}
}
int main()
{
	int N;
	cin >> N;
	vector<vector<pair<int,int>>> V(N);
	int i;
	for(i = 0;i < N;i++)
	{
		int tmp;
		cin >> tmp;
		for(int j = 0;j < tmp;j++)
		{
			pair<int,int> tmppair;
			cin >> tmppair.first >> tmppair.second;
			tmppair.first += -1;
			V[i].push_back(tmppair);
		}
	}
	int max = 0;
	for(int bit = 0;bit < (1<<N);bit++)
	{
		vector<int> tmpvec(N);
		ConvertToVector(tmpvec,bit,N);
		bool exist = true;
		for(i = 0;i < N;i++)
		{
			if(tmpvec[i] == 0) continue;
			for(int j = 0;j < V[i].size();j++)
			{
				if(tmpvec[V[i][j].first] != V[i][j].second)
				{
					exist = false;
				}
			}
		}
		if(exist == false) continue;
		chmax(max,popcount(bit,N));
	}
	cout << max << endl;
	return 0;
}


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

using namespace std;

int main()
{
    int a, b, x;
    cin >> a >> b >> x;

    if ((x - a) <= b && x >= a) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int, int>;

int main() {
  string s;
  cin >> s;
  for (int i=0; i<19; i++) {
    if (i==5 || i==13) {
      cout << " ";
      continue;
    }
    cout << s[i];
  }
  cout << endl;
}

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

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = sorted(i+j for i in a for j in b)[:-k-1:-1]
c = c[:k]
abc = sorted(i+j for i in ab for j in c)[:-k-1:-1]

print(*abc[:k], sep="\n")

Measured memory_bytes: 162072
using System;
using System.Collections;
using System.Collections.Generic;


public class A
{
	public static void Main()
	{
		char b = Console.ReadLine()[0];
		char result = '\0';
		switch(b)
		{
			case 'A':
				result = 'T';
				break;
				
			case 'C':
				result = 'G';
				break;
				
			case 'G':
				result = 'C';
				break;
				
			case 'T':
				result = 'A';
				break;
				
			default:
				throw new Exception();			
		}
			
		Console.WriteLine(result);
	}	
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
using namespace std;
int main() {
	int A, B;
  	cin >> A >> B;
  	string S;
  	cin >> S;
  	int j = 0;
  	for(int i = 0; i <= A - 1; i++){
      	if('0'> S[i] || '9' < S[i])
          	j = 1;
    }
  	if(S[A] != '-')
      	j = 1;
  	for(int i = A + 1; i <= A + B - 1; i++) {
      	if('0' > S[i] || '9' < S[i])
          	j = 1;
    }
  	if(j == 0)
      	cout << "Yes" << endl;
  	else
      	cout << "No" << endl;
   	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long A, long double B){
  //long double x = A*B;
  long long ans = floor(A*B);
  std::cout << ans << std::endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long double B;
  scanf("%Lf",&B);
  solve(A, B);
  return 0;
}



Measured memory_bytes: 3832
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long X = sc.nextLong();
		long K = sc.nextLong();
		long D = sc.nextLong();
		
		X = Math.abs(X);
		long move = Math.min(K, X/D);
		X -= move*D;
		if((K-move)%2==1) {
			X = X-D;
		}
		System.out.println(Math.abs(X));

		sc.close();
	}
}


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

using namespace std;

using p = pair<int,int>;
const int NIL = -1;
int sx,sy, H,W;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int main() {
    cin >> H >> W;
    vector<string> data(H);
    for(int i=0;i<H;i++) cin >> data[i];

    vector<vector<int>> dist(H, vector<int>(W, NIL));
    queue<p> Q;
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            if(data[i][j] == '#') {
                dist[i][j] = 0;
                Q.push(p(i,j));
            }
        }
    }

    while(!Q.empty()) {
        auto pos = Q.front(); Q.pop();
        for(int k=0;k<4;k++) {
            int nx = pos.first + dx[k];
            int ny = pos.second + dy[k];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(dist[nx][ny] == -1) {
                dist[nx][ny] = dist[pos.first][pos.second] + 1;
                Q.push(p(nx,ny));
            }
        }
    }

    int ans = 0;
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            ans = max(ans, dist[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13456
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int main(){

  long long int N, K;
  scanf("%lld%lld", &N, &K);

  if(K > ((N-1)*(N-2))/2){
    std::cerr << "Answer: " << std::endl;
    std::cout << -1 << std::endl;
  }
  else{

    std::vector<std::vector<long long int> > G(N);
    for(long long int i = 0; i < N; i++){
      for(long long int j = 0; j < N; j++){
        G[i].push_back(1);
      }
    }
    long long int n_pairs = 0;
    // remove edges. edges concerning 0-th node is not removed
    for(long long int i = 1; i < N; i++){
      for(long long int j = i+1; j < N; j++){
        if(n_pairs == K){
          j = N; i = N; // break from the loop
          break;
        }
        G[i][j] = 0;
        n_pairs++;
      }
    }

    // print result
    std::cerr << "Answer: " << std::endl;
    std::cout << (N*(N-1))/2 - K << std::endl;
    for(long long int i = 0; i < N; i++){
      for(long long int j = i+1; j < N; j++){
        if(G[i][j] == 1){
          std::cout << i+1 << " " << j+1 << std::endl;
        }
      }
    }
  }

  return 0;
  
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

//http://hos.ac/slides/20140319_bit.pdf
int MAX_N=1000010;
vector<int>bit(MAX_N+1,0);//1-index
void add(int a,int w){
    for (int x = a; x <=MAX_N; x+=x&-x)bit[x]+=w;
}
int sum(int a){//sum v[1]～v[a]
    int ret=0;
    for (int x = a; x>0;x-=x&-x)ret+=bit[x];
    return ret;
}

int main(){
    //input

    ll n,q;cin >>n>>q;
    vector<ll>c(n+1);
    for (int i = 1; i <=n; ++i) {
        cin >>c[i];
    }
    //pre calc ok
    vector<ll>pre(n+1,-1);
    vector<vector<ll>>num(n+1,vector<ll>());
    for (int i = n; i>=1; --i) {
        num[c[i]].push_back(i);
    }

    vector<ll>w(n+1,0);
    for (int i = n; i >=1;--i) {
        if(num[c[i]].size()>w[c[i]]+1) {
            w[c[i]]++;
            pre[i] = num[c[i]][w[c[i]]];
        }
    }

//    for (int i = 1; i <=n; ++i) {
//        cout <<pre[i]<<" ";
//    }
//    cout <<endl;
    vector<pair<ll,P>>rl;
    for (int i = 0; i < q; ++i) {
        ll l,r;cin >>l>>r;
        rl.push_back({r,{l,i}});
    }
    sort(all(rl));
    ll k=0;
    vector<bool>ch(n+1,true);
    for (int i = rl[0].first; i>=1; --i) {
        if(ch[c[i]]){
            add(i,1);
            ch[c[i]]=false;
        }
    }
    ll r=rl[0].first;
    ll a=0;
    vector<ll>ans(q);
    while(a<q){
        ll l=rl[a].second.first;
        if(rl[a].first==r){
            ans[rl[a].second.second]=sum(r)-sum(l-1);
            a++;
        }
        else {
            r++;
            if(pre[r]>0){
                add(pre[r],-1);
            }
            add(r,1);
        }
    }
    for (int i = 0; i < q; ++i) {
        cout <<ans[i]<<endl;
    }
}


Measured memory_bytes: 62456
#include <iostream>
#include <cstdint>

using namespace std;

uint64_t N,W,v[100],w[100],dp[100][10000];

uint64_t max(uint64_t a,uint64_t b)
{
	if(a > b)
		return a;
	else
		return b;
}

int _dp(int _d,int _w)
{
	if(_d < 0 || _w < 0 || _d >= N || _w >= W)
		return 0;
	else
		return dp[_d][_w];
}

int main(void)
{
	cin >> N >> W;
	for(int i = 0;i < N;i++)
	{
		cin >> v[i] >> w[i];
	}
	for(int i = N - 1;i >= 0;i--)
	{
		for(int ii = 0;ii < W;ii++)
		{
			uint64_t t = 0;
			if(ii + 1 >= w[i])
			{
				t = _dp(i + 1,ii - w[i]) + v[i];
			}
			dp[i][ii] = max(_dp(i + 1,ii),t);
		}
	}
	uint64_t result = dp[0][W - 1];
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 10912
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  set<string> s;
  ll N;
  cin >> N;
  rep(i, N){
    string tmp;
    cin >> tmp;
    s.insert(tmp);
  }
  cout << s.size();

  return 0;
}


Measured memory_bytes: 19224
n=int(raw_input())
i = 1
print "",
while(i<=n):
    x=i
    if x%3 is 0:
        print i,
    else:
        for j in xrange(0,4):
            if (x/10**j)%10 is 3:
                print i,
                break
    i = i+1

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a == 1)
        a += 13;
    if(b == 1)
        b += 13;
    if(a > b)
        cout << "Alice" << endl;
    else if(a < b)
        cout << "Bob" << endl;
    else
       cout << "Draw" << endl;


    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = sum(b) - sum(a)

numa, numb = 0, 0
for i in range(n):
    if a[i] > b[i]:
        numb += a[i] - b[i]
    elif a[i] < b[i]:
        numa += (b[i] - a[i] + 1) // 2

if numa <= dif and numb <= dif:
    print('Yes')
else:
    print('No')


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int h, w, a, b; std::cin >> h >> w >> a >> b;
  vector<string> grid(h, string(w, '0'));
  rep(i, b) rep(j, a) grid[i][j] = '1';
  srep(i, b, h) srep(j, a, w) grid[i][j] = '1';
  rep(i, h) std::cout << grid[i] << "\n";
}


Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

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

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

int H, W;
char field[11][21];
map<string, int> v;

void solve(int x, int y){
  rep(i, 8){
    string s = "";
    s += field[y][x];
    bool used[11][21];
    memset(used, false, sizeof(used));
    used[y][x] = true;
    int nx = x+dx[i], ny = y+dy[i];
    while(true){
      if(nx < 0) nx = W-1;
      else if(nx >= W) nx = 0;
      if(ny < 0) ny = H-1;
      else if(ny >= H) ny = 0;      
      if(used[ny][nx]) break;
      used[ny][nx] = true;
      s += field[ny][nx];
      nx += dx[i], ny += dy[i];
      if(s.size() >= 2) v[s]++;
    }    
  }
}

int main(){
  while(cin >> H >> W, H|W){
    v.clear();
    rep(i, H) cin >> field[i];        

    rep(i, H) rep(j, W) solve(j, i);
    
    string ans = "";
    int L = 0;
    for(map<string, int>::iterator it = v.begin() ; it != v.end() ; it++){
      if(it->second < 2) continue;

      if(it->first.size() > L){
	L = it->first.size();
	ans = it->first;
      }
      else if(it->first.size() == L && ans > it->first) ans = it->first;
    }
    if(ans.size() == 0) cout << "0" << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 36028
n = int(input())
l = list(map(int, input().split()))
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j] and l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                ans += 1

print(ans)

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

int main() {
  int N;
  cin >> N;
  int totalY = 0;
  
  for (int i = 0; i < N; i++) {
    char S;
    cin >> S;
    
    if (S == 'Y') {
      totalY++;
    }
  }
  
  if (totalY == 0) {
    cout << "Three" << endl;
  }
    
    else {
      cout << "Four" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct tree{
    size_t n,r,md;
    vector<vector<int>> e;
    vector<int> pa,d,sz;
    explicit tree(int n):n(n),e(n),d(n){}
    explicit tree(string&s):n(s.length()/2+1),e(n),pa(n),d(n),sz(n,1){
        pa[0]=-1;
        int i{};
        stack<int> p;
        p.push(0);
        for(auto c:s){
            if(c=='('){
                pa[++i]=p.top();
                d[i]=p.size();
                e[p.top()].push_back(i);
                p.push(i);
            }
            else{
                sz[pa[p.top()]]+=sz[p.top()];
                p.pop();
            }
        }
        assert(i==n-1);
    }
    void built(bool f=true){
        static int a,b;
        fr(i,n-1){
            cin>>a>>b;
            if(f) --a,--b;
            ++d[a],++d[b];
            add(a,b);
        }
    }
    void pbuilt(bool f=true){
        static int a;
        Fr(i,n-1){
            cin>>a;
            if(f) --a;
            add(a,i,false);
        }
    }
    void add(int a,int b,bool f=true){
        e[a].emplace_back(b);
        if(f) e[b].emplace_back(a);
    }
    template<class T>
    vector<T> square(int i){
        vector<T> ans(3,1);
        ans[1]=2;
        for(auto j:e[i]){
            auto a=move(square<T>(j));
            auto m0=ans.size(),m1=a.size();
            ans.resize(m0+m1-1,0);
            ifr(i0,m0){
                iFr(i1,m1-1) ans[i0+i1]+=ans[i0]*a[i1];
                ans[i0]*=a[0];
            }
        }
        return ans;
    }
    void r_dfs(int i,int p=-1,int D=0){
        pa[i]=p;d[i]=D;md=max(md,(size_t)D);++D;
        for(auto j:e[i]) if(j!=p) r_dfs(j,i,D),sz[i]+=sz[j];
    }
    void r_i(int r_){
        pa.resize(n);d.resize(n);sz.resize(n,1),r=r_;md=0;
        r_dfs(r);
    }
    int r2(){
        r_i(0);
        int m=0,M=0;
        fr(i,n) m=max(m,d[i]);
        fr(i,n) if(d[i]==m) M=i;
        pa.clear(),d.clear();
        r_i(M);
        m=0;
        fr(i,n) m=max(m,d[i]);
        return m;
    }
    bool solve(){
        queue<int> q;
        vector<bool> v(n);
        fr(i,n) if(d[i]==1) q.emplace(i);
        while(!q.empty()){
            int i=q.front(),k{-1},c{};q.pop();
            for(auto&j:e[i]) if(!v[j]) k=j;
            v[k]=true;
            for(auto&j:e[k]){
                --d[j];
                if(d[j]==1) q.emplace(j);
                if(!d[j]) ++c;
            }
            if(c>1) return true;
        }
        return false;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    tree t(n);
    t.built(n);
    puts(t.solve()?"First":"Second");
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF (1<<30)
#define LINF (1ll<<60ll)
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload4(_1,_2,_3,_4,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 _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload4(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
#define d(a) cerr<<#a<<":"<<a<<endl
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl


int main(){
    int n,k;
    cin>>n>>k;
    vi h(n);
    REP(i,n){
        cin>>h[i];
    }
    sort(all(h));
    int m=INF;
    REP(i,n-k+1){
        chmin(m,h[i+k-1]-h[i]);
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
		int x,n,i;
		int a[99999];
		i=0;
			scanf("%d",&x);
		while(x!=0){
			a[i]=x;
			i+=1;
			scanf("%d",&x);
		}
		for(n=0;n<=i-1;n++){
		printf("Case %d: %d\n",n+1,a[n]);
		}
	return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#define INF 10000000000
#define MOD 1000000007

using namespace std;
int main(void){
    int H,W,N;
    cin>>H>>W>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int ans[H*W];
    int num=0;
    for(int i=0;i<N;i++){
       while(a[i]>0){
           ans[num]=i+1;
           num++;
           a[i]--;
       }
    }
    for(int i=0;i<H;i++){
        if(i%2==0){
            for(int j=0;j<W;j++){
                cout<<ans[i*W+j]<<' ';
            }
            cout<<endl;
        }
        else{
            for(int j=W-1;j>=0;j--){
                cout<<ans[i*W+j]<<' ';
            }
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define MAXN 200 + 5
const long long INF = 1LL << 60;
const int inf = 1 << 30;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

long long  mod = 1e9 + 7;

int main(){
  int n;
  vector<int> a(n);
  string s; cin >> s;
  if(s[2] == s[3] && s[4] == s[5]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
     


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		if(A == 1) A=14;
		if(B == 1) B=14;
		if(A < B){
			System.out.println("Bob");
		}else if(A > B){
			System.out.println("Alice");
		}else{
			System.out.println("Draw");
		}
		System.out.println();
		scanner.close();
	}
}


Measured memory_bytes: 20948