akhauriyash/Code-Regression huggingface dataset:
(defun solver ()
  (let* ((h (read)) (w (read))
         (sq (make-array (list h w))))
    (loop for i fixnum below h do
          (loop for j fixnum below w with temp do
                (setf temp (read-char))
                (when (equal temp #\Newline)
                  (setf temp (read-char)))
                (setf (aref sq i j) temp)))
    (loop for i fixnum below (1- h) do
          (loop for j fixnum below w do
                (when (and (or (equal (aref sq i j) #\#)
                               (equal (aref sq i j) #\a))
                           (or (equal (aref sq (1+ i) j) #\#)
                               (equal (aref sq (1+ i) j) #\a)))
                  (setf (aref sq i j) #\a
                        (aref sq (1+ i) j) #\a))))
    (loop for i fixnum below h do
          (loop for j fixnum below (1- w) do
                (when (and (or (equal (aref sq i j) #\#)
                               (equal (aref sq i j) #\a))
                           (or (equal (aref sq i (1+ j)) #\#)
                               (equal (aref sq i (1+ j)) #\a)))
                  (setf (aref sq i j) #\a
                        (aref sq i (1+ j)) #\a))))
    (loop for i fixnum below h do
          (loop for j fixnum below w do
                (when (equal (aref sq i j) #\#)
                  (return-from solver  (format t "No~%")))))
    (format t "Yes~%")))

(solver)


Measured memory_bytes: 13792
require 'pp'

n = gets.chomp!.to_i
x_n = Array.new(n)
l_n = Array.new(n)
n.times do |i|
    x, l = gets.split.map(&:to_i)
    x_n[i] = x
    l_n[i] = l
end

min_n = Array.new(n)
max_n = Array.new(n)

n.times do |i|
    min_n[i] = [x_n[i] - l_n[i], x_n[i] + l_n[i]]
    #max_n[i] = [min_n[i][1], min_n[i][0]]
end

min_n.sort!

i = 0
count = 1
head = 0
tail = 1
while tail < n
    #pp "====="
    #pp head
    #pp tail
    min1, max1 = min_n[head]
    min2, max2 = min_n[tail]
    if max1 <= min2
        count += 1
        head = tail
        tail = head + 1
    elsif max1 >= max2
        # i番目つかうメリットなし
        head += 1
        tail = head + 1
    else
        # i番目は使う可能性あり，i+1番目は使うメリットなし
        tail += 1
    end
end

puts count



Measured memory_bytes: 10216
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int k = 0;
    
    if ((a+b)%2 != 0) {
      System.out.println("IMPOSSIBLE");
      return;
    } else {
      System.out.println((a+b)/2);
    }

  }
}


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

class Dice_c{

private:
  int me[4];
  int topbot[2]; // top,bottom

public:
  void Input();
  void Roll(int top, int front);
  void Output();

};


int main(){

  Dice_c dice;
  int m;
  int top,front;

  dice.Input();
  cin >> m;

  for(int i=0; i<m; i++){
    cin >> top >> front;
    dice.Roll(top,front);
    dice.Output();
  }

  
  return 0;
}


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




void Dice_c::Input(){

  cin >> me[1] >> topbot[1] >> me[2] >> me[0] >> topbot[0] >> me[3];
  getchar();

}

void Dice_c::Roll(int top,int front){
  
  int tmp;

  if(me[1]!=top){


    if(me[0]==top){
      tmp=me[3];
      me[3]=me[2] , me[2]=me[1] , me[1]=me[0] , me[0]=tmp;
    }
    else if(me[2]==top){
      tmp=me[0];
      me[0]=me[1] , me[1]=me[2] , me[2]=me[3] , me[3]=tmp;
    }
    else{
      while(me[1]!=top){
	tmp = topbot[0];
	topbot[0]=me[1] , me[1]=topbot[1] , topbot[1]=me[3] , me[3]=tmp;
	
	/*
	cout << endl << "top:" <<top << endl;

	cout <<endl <<  "  " << topbot[0] << endl;
	for(int i=0; i<4; i++)
	  cout << me[i] << ' ';
	cout << endl << "  " << topbot[1] << endl;
	*/


      }
    }
  }
  ///////fix top

  while(topbot[1]!=front){
    tmp=topbot[1];
    topbot[1]=me[2] , me[2]=topbot[0] , topbot[0]=me[0] , me[0]=tmp;

  }
  ///////fix front
 

}


void Dice_c::Output(){

  cout << me[2] << endl;

}

Measured memory_bytes: 1160
import sys
import numpy as np
from itertools import product

N = int(input())
info = []

for i in range(N):
    for _ in range(int(input())):
        x, y = map(int, input().split())
        info.append((i, x-1, y))

whole = np.array(list(product([0,1],repeat=N)), np.bool)

for i, x, y in info:
    b = (whole[:, i] & whole[:, x]==y) | (~whole[:, i])
    whole = whole[b]

print(whole.sum(axis=1).max())

Measured memory_bytes: 18664
/*
RAHULKUMAR SINGH
*/
#include<iostream> 
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<climits>
#include<queue>
#include<algorithm>
#include<iomanip>
#define ll long long int
double PI =3.14159265;
using namespace std;


int main(){
 int k;
 string s;
 cin>>k>>s;
 if(k>s.size()){
 	cout<<s<<endl;
 }
 else{
int size=s.size();
 for(int i=0;i<k;i++){
 	cout<<s[i];
 }
 
 if(k<s.size()){
 	cout<<"..."<<endl;
 }
 }
}



Measured memory_bytes: 3628
n,m,q = [int(i) for i in input().split()]
p = []
for i in range(q):
  p.append([int(i) for i in input().split()])
dmax = 0
a = [1 for i in range(n)]
while True:
  d = 0
  for i in range(q):
    if a[p[i][1]-1]-a[p[i][0]-1] == p[i][2]:
      d += p[i][3]
  if d > dmax:
    dmax = d
  if a[0] == m:
    break
  c = 1
  l = a.pop()
  while l==m:
    l = a.pop()
    c += 1
  for i in range(c):
    a.append(l+1)
    
print(dmax)

Measured memory_bytes: 9252
#include <stdio.h>
#define mod 1000000007
typedef long long ll;
 
ll rev(ll a) {
  ll b = mod - 2, ans = 1;
  while(b) {
    if(b & 1) ans *= a, ans %= mod;
    b >>= 1, a *= a, a %= mod;
  }
  return ans;
}
 
int main(void) {
  ll i, j, k, r[2], c[2], ans = 0, now;
  scanf("%lld%lld%lld%lld", &r[0], &c[0], &r[1], &c[1]);
  r[0]--, c[0]--;
  ll n = r[1] + c[1], fact[n + 10];
  fact[0] = 1;
  for(i = 1; i <= n + 9; ++i) fact[i] = fact[i - 1] * i, fact[i] %= mod;
  for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) {
    now = fact[c[i] + r[j] + 2] * rev(fact[c[i] + 1]);
    now %= mod;
    now *= rev(fact[r[j] + 1]);
    now %= mod;
    ans += now * ((i ^ j) ? -1 : 1) + mod;
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 15744
#include <iostream>
#include <queue>
#include <string>

using namespace std;

static const int MAX = 100;
static const int INFTY = (1<<21);

// 幅優先探索
// 最短距離を求める。

struct Node
{
    // 頂点 0オリジン
    int id;
    // 頂点1からの距離。たどり着けない場合はINFTY
    int direction;
};

int M[MAX][MAX] = { 0 };
Node nodes[MAX];

void initNodes(Node *nodes, int len)
{
    for (int i = 0; i < len; i++)
    {
        nodes[i].id = i;
        nodes[i].direction = INFTY;
    }
    // nodes[0]は頂点1で、ここから開始するのでdirecton=0にする
    nodes[0].direction = 0;
}

// s 始点0オリジン
// n 頂点数
void depthFirstSearch(int s, int n)
{
    queue<Node> q;
    q.push(nodes[s]);

    while (!q.empty())
    {
        // c++のqueueはpopで値を返さない。先頭の参照を取得後、popで削除。
        Node uNode = q.front(); q.pop();
        // ここで訪問完了

        for (int v = 0; v < n; v++)
        {
            if (M[uNode.id][v] == 0) continue;     // 行き先がない。
            if (nodes[v].direction != INFTY) continue;   // すでに到達しているのでスキップ

            // u->vで、頂点uが保持している距離+1をnodes[v]に入れる
            nodes[v].direction = nodes[uNode.id].direction + 1;

            // 頂点uに隣接するvがここでキューに入る。
            // for文なので、このループで隣接する頂点がキューに入る。
            q.push(nodes[v]);
        }
    }
}

void printNodes(Node *nodes, int n)
{
    for (int i = 0; i < n; i++)
    {
        int val = nodes[i].direction == INFTY ? -1 : nodes[i].direction;
        cout << nodes[i].id + 1 << " " << val << endl;
    }
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u; // 頂点番号
        cin >> k; // 次数
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            M[u-1][v-1] = 1;
        }
    }

    initNodes(nodes, MAX);
    depthFirstSearch(0, n); //始点0 = 頂点1から探索開始
    printNodes(nodes, n);
    return 0;
}


Measured memory_bytes: 3164
from collections import*
n,m,*t=map(int,open(0).read().split())
i=[0]*n
o=[[]for _ in i]
for a,b in zip(*[iter(t)]*2):
  o[a-1]+=b-1,
  i[b-1]+=1
q,r=deque(v for v in range(n)if i[v]<1),[]
while q:
  v=q.popleft()
  r+=v,
  for w in o[v]:
    i[w]-=1
    if i[w]==0:q+=w,
print(-(len(r)==n))

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    int n;
    cin >> n;
    string s = "Christmas";
    rep(i, 25-n) s += " Eve";
    cout << s << endl;
    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		int yoko = 0; int tate = 0; int cnt = 0; int x = -1;
		for(int i = n - 1 ; i >= 0 ; i--) {
			if(x != a[i]) {
				x = a[i];
				cnt = 1;
			} else {
				cnt++;
				if(cnt >= 2) {
					if(yoko >= tate) {
						tate = a[i];
					} else {
						yoko = a[i];
					}
					cnt = 0;
				}
			}
			if(yoko != 0 && tate != 0) {
				System.out.println(1L * yoko * tate);
				return;
			}
		}
		System.out.println(0);
	}
}

Measured memory_bytes: 51232
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    ll a=in();
    cout<<3*a*a<<endl;
}

Measured memory_bytes: 256
length = int(raw_input())
directions = raw_input()

from_west = [None] * length
from_east = [None] * length

# west count
west = 0
east = 0
west_reverse = 0
east_reverse = 0

for n in range(length):
    if directions[n] == 'W':
        west += 1
    else:
        east += 1

    if directions[-(n + 1)] == 'W':
        west_reverse += 1
    else:
        east_reverse += 1

    from_west[n] = (west, east)
    from_east[-(n + 1)] = (west_reverse, east_reverse)


min_length = length + 1
for i in range(length):
    left = None
    right = None
    if i != 0:
        left = from_west[i - 1]
    if i != length - 1:
        right = from_east[i + 1]

    left_turns = 0
    if left:
        left_turns = left[0]
    right_turns = 0
    if right:
        right_turns = right[1]

    if left_turns + right_turns < min_length:
        min_length = left_turns + right_turns

print min_length


Measured memory_bytes: 74344
import Control.Applicative
import qualified Control.Monad as Monad

main = calculator

calculator :: IO ()
calculator = do
    [a, op, b] <- words <$> getLine
    Monad.when (op /= "?") $ do
        print $ calculate (read a) op (read b)
        calculator

calculate :: Int -> String -> Int -> Int
calculate a op b = interpret op
    where interpret "+" = a + b
          interpret "-" = a - b
          interpret "*" = a * b
          interpret "/" = a `div` b


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

int main() {
    int N;
    int K;
    string s;
    cin >> N;
    cin >> K;
    cin >> s;

    bool continuous0flag = false;

    typedef std::pair<int, int> intPair;
    intPair startEndPairs[N];
    int pairNum = 0;

    for (int i = 0; i < N; i++) {
        char si = s[i];
        //start of continuous1
        if (!continuous0flag && si == '0') {
            continuous0flag = true;
            startEndPairs[pairNum].first = i;
        }
        //end of continuous1
        if (continuous0flag && si == '1') {
            continuous0flag = false;
            startEndPairs[pairNum].second = i - 1;
            pairNum++;
        }
    }

    if (continuous0flag) {
        startEndPairs[pairNum].second = N - 1;
        pairNum++;
    }
    if (K >= pairNum) {
        cout << N << endl;
        return 0;
    }


    int result = -1;
    for (int i = 0; i < pairNum - K + 1; i++) {
        int start;
        if (i == 0) {
            start = 0;
        } else {
            start = startEndPairs[i-1].second + 1;
        }
        int end;
        if (i == pairNum - K) {
            end = N-1;
        } else {
            end = startEndPairs[i + K].first - 1;
        }
        int rangeContinuous1 = end - start + 1;
        if (rangeContinuous1 > result) {
            result = rangeContinuous1;
        }
    }

    cout << result << endl;

	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int maxn=(1e5+10);
int n,r[maxn];
string s;
bool check(int a,int b,int c,char t)
{
	if(t=='o'&&!b)
	{
		if(a==c)
			return true;
		return false;
	}
	if(t=='o')
	{
		if(a==c)
			return false;
		return true;
	}
	if(!b)
	{
		if(a==c)
			return false;
		return true;
	}
	if(a==c)
		return true;
	return false;
}
int main()
{
	bool ok=false;
	cin>>n>>s;
	for(int i=0;i<4;i++)
	{
		r[0]=i/2,r[1]=i%2;
		for(int j=2;j<n;j++)
		{
			if(s[j-1]=='o')
				r[j]=r[j-2];
			else
				r[j]=1-r[j-2];
			if(r[j-1])
				r[j]^=1;
		}
		if(!check(r[n-2],r[n-1],r[0],s[n-1]))
			continue;
		if(!check(r[n-1],r[0],r[1],s[0]))
			continue;
		for(int j=0;j<n;j++)
			cout<<(r[j]?'W':'S');
		return 0;
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
ll llabs(ll a)
{
    if(a < 0) a*= -1;
    return a;
}
int main()
{
    she_told_me_dont_worry
    ll n, l;
    cin>>n>>l;
    ll tot = n*(n-1)/2;
    tot += n*l;
    ll i;
    ll md = inf;
    ll ans = -1;
    FOR0(i, n)
    {
        ll cur = tot - (l + i);
        ll dif = llabs(tot - cur);
        if( md > dif )
        {
            md = dif;
            ans = cur;
        }
    }
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [[10**9 for _ in range(K+1)] for _ in range(N)]
dp[0] = [0 for _ in range(K+1)]

for i in range(N):
    for l in range(K):
        if i-(l+1) >= 0:
            dp[i][l] = dp[i - (l + 1)][K] + abs(h[i] - h[i - (l + 1)])
        else:
            dp[i][l] = min(dp[i])
        if l == K-1:
            dp[i][K] = min(dp[i])
print(min(dp[N-1]))

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9 + 7;
int main() 
{
    ll n;
    cin>>n;
    vector <ll> a(200005),ls(200005,-1);
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector <ll> dp(200005);
    dp[0] = 1;
    ls[a[0]] = 0;
    for(int i=1;i<n;i++)
    {
        ll inx = ls[a[i]];
        if(inx == -1 || inx == i-1)
        {
            ls[a[i]] = i;
            dp[i] = dp[i-1];
            // cout<<dp[i]<<endl;
            continue;
        }
        dp[i] = (dp[inx] + dp[i-1])%mod;
        // cout<<dp[i]<<endl;
        ls[a[i]] = i;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
long long n;
inline void work(int x)
{
	while(x%7!=0&&x>0)x-=4;
	if(x>=0)printf("Yes");
	else printf("No");
	return;
}
int main()
{
	scanf("%d",&n);
	if(n>17)printf("Yes");
	else work(n);
	return 0;
}

Measured memory_bytes: 384
import heapq

def main():
    x, y, a, b, c = [int(x) for x in input().split(" ")]
    red = [int(x) for x in input().split(" ")]
    green = [int(x) for x in input().split(" ")]
    white = [int(x) for x in input().split(" ")]

    red.sort(reverse=True)
    green.sort(reverse=True)
    white.sort(reverse=True)

    red1 = red[:x]
    green1 = green[:y]

    heapq.heapify(red1)
    heapq.heapify(green1)

    ans = sum(red1) + sum(green1)
    #print(ans)
    i = 0

    while(i < c and (white[i] > red1[0] or white[i] > green1[0])):
        #print("%d %d %d" % (white[i], red1[0], green1[0]))
        if red1[0] < green1[0]:
            removed = heapq.heappop(red1)
            ans += white[i] - removed
            heapq.heappush(red1, white[i])
        else:
            removed = heapq.heappop(green1)
            ans += white[i] - removed
            heapq.heappush(green1, white[i])
        i += 1

    print(ans)


main()

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

int main(){
  long long int h,w;
  cin>>h>>w;
  
  long long int ans=0;
  
  if(h==1 or w==1)
    ans=1;
  else
  	ans=floor((h*w+1)/2);
  
  cout<<ans;
  
  return 0;
}

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

using namespace std;


typedef long long int ll;
typedef vector<int>vi;
typedef deque<int> di;
#define f(i, a, b) for(int i = a; i < b; i++)

int main() {
char x;
string s;
cin >> s;
x = s[0];
if (islower(x)) {

    cout << "a";
}
else {

 cout << "A";
}
return 0;
}


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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] sum = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i - 1] + sc.nextInt();
        }
        int min = sum[n];
        for (int i = 1; i <= n; i++) {
            min = Math.min(min, Math.abs(sum[n] - 2 * sum[i]));
        }
        System.out.println(min);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){      
    lint n,k;
    cin>>n>>k;
    lint a[n];
    rep(i,n){
        lint q;
        cin>>q;
        --q;
        a[i]=q;
    }
    lint isv[n+10];
    fill(isv,isv+n+10,0);
    isv[0]=1;
    lint x=0;
    if(k<=1000000){
        rep(i,k){
        x=a[x];
        }
        cout<<x+1<<endl;
    }else{
        rep(i,n){
            lint y=x;
            x=a[x];
            if(isv[x]!=0){
            k-=isv[x];
            k++;
            lint t=isv[y]-isv[x]+1;
            lint g=k%t;
            lint ans=x;
            rep(i,g){
                ans=a[ans];
            }
            cout<<ans+1<<endl;
            return 0;
            }
            isv[x]=isv[y]+1;
        }
    }
      }
      
    

  
          
  

Measured memory_bytes: 6780
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int t = scanner.nextInt();
		int a = scanner.nextInt();

		double bestDiff = -1;
		int bestPoint = 0;
		for (int i = 0; i < n; i++) {
			int h = scanner.nextInt();
			if (i == 0) {
				bestPoint = i + 1;
				bestDiff = Math.abs(a - (t- h * 0.006));
			} else {
				double diff = Math.abs(a - (t- h * 0.006));
				if (diff < bestDiff) {
					bestDiff = diff;
					bestPoint = i + 1;
				}
			}
		}
		System.out.println(bestPoint);
	}

}

Measured memory_bytes: 22996
import java.util.Scanner;

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

		int count = 0;

		while(true) {
			int x = scan.nextInt();
			if (x == 0){
			    break;
                         }
			count++;
			System.out.println("Case " + count + ": " + x);
		}
	}

}

Measured memory_bytes: 41836
H_1,M_1,H_2,M_2,K=input().split()
H_1=int(H_1)
M_1=int(M_1)
H_2=int(H_2)
M_2=int(M_2)
K=int(K)
H1=H_1*60+M_1
H2=H_2*60+M_2
answer=H2-H1-K
print(answer)

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll d, g;
	cin >> d >> g;
	g /= 100;
	vl p(d), c(d);
	REP(i, d)cin >> p[i] >> c[i];
	REP(i, d)c[i] /= 100;
	ll ans = INF;
	REP(i, 1 << d) {
		ll sum = 0, cnt = 0;
		REP(j, d) {
			if (i&(1 << j)) {
				cnt += p[j];
				sum += (j + 1)*p[j];
				sum += c[j];
			}
		}
		ll j = d - 1;
		while (sum < g&&j>=0) {
			if (i&(1 << j)) {
				j--; continue;
			}
			int tmp = min(p[j] - 1, (g - sum + j) / (j + 1));
			sum += tmp * (j + 1);
			j--;
			cnt += tmp;
		}
		if(sum>=g)ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

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

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int m;
  cin >> n >> m;
  vector<int> vec;
  vec.push_back(0);
  for(int i = 1; i <= n; i++){
    int p;
    cin >> p;
    vec.push_back(p);
  }
  UnionFind uf(n + 1);
  for(int i = 0; i < m; i++){
    int x;
    int y;
    cin >> x >> y;
    uf.unionSet(x, y);
  }
  int sum = 0;
  for(int i = 1; i <= n; i++){
    if(uf.findSet(i, vec[i])) sum++;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001;
typedef pair<int,int> P;
#define foreach(ix,a) for(auto& (ix) : (a)) 
int main(){
  //ios::sync_with_stdio(false);
  //cin.tie(nullptr);
  int n,h=1000,w=1000,x,y;

  cin>>h>>w;
  //cin>> sy>> sx;
  //cin>> gy>> gx;
  char ma [h][w];  
  int cnt =0;
  rep(i,h)rep(j,w){
    cin>>ma[i][j];
    if(ma[i][j]=='#')cnt++;
  }

  int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
  //int ans =0;
  
  //rep(sx,h)rep(sy,w){
    //if(ma[sx][sy] == '#')continue;
    queue <P> que;
    vector<vector<int>> d(h,vector<int>(w,INF));
    auto update=[&](int i,int j,int x){
      if(d[i][j]!=INF)return;
      d[i][j]=x;
      que.push(P(i,j));
    };
    update(0,0,0);
    while(!que.empty()){
      int i = que.front().first;
      int j=que.front().second; que.pop();
      rep(a,4){
        int nx = i + dx[a],ny = j +dy[a];
        if(0>nx||0>ny||nx>=h||ny>=w)continue;
        if(ma[nx][ny]=='#')continue;
        update(nx,ny,d[i][j]+1);
      }
    }
  // rep(i,h)rep(j,w){
  //   if(d[i][j]==INF)continue;
  //   ans = max(ans,d[i][j]);}
//}
if(d[h-1][w-1]==INF) cout<<-1<<endl;
else cout<<h*w-d[h-1][w-1]-cnt-1<<endl;


}

Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    cout << fixed << setprecision(15);
    
    int n,k;
    cin >> n >> k;
    int c=0;
    fff(i,n) {
        int x;cin >> x;
        if(x>=k)
        c++;
    }
    
    cout << c;
    
	return 0;
    
}

Measured memory_bytes: 8832
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, a[210];
    cin >> n;

    int cnt[210] = {0};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        while (a[i] > 0) {
            if (a[i] % 2 == 0) cnt[i]++;
            else break;
            a[i] /= 2;
        }
    }

    int min = 1000000;
    for (int i = 0; i < n; i++) {
        if (cnt[i] < min) {
            min = cnt[i];
        }
    }
    cout << min << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a,b,k;
  cin>>a>>b>>k;
  set<int> S;
  REP(i,a,a+k){
    if(i<=b){
      S.insert(i);
    }
  }
  for(int i=b;i>b-k;i--){
    if(i>=a){
      S.insert(i);
    }
  }
  for(int x:S){
    cout<<x<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
/*
.   Bismillahir Rahmanir Rahim
.   Author - Marajul islam
.   created- Sun Apr 19 17:55:11 2020

*/ 
#include<bits/stdc++.h>
using namespace std;


 
int sc1() {int x; scanf("%d", &x); return x;}
long long sc2() {long long x; scanf("%lld", &x); return x;}

const int mod= 1e9 + 7;
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (long long)a * b % mod;}
 
#define F               first
#define S               second 
#define mp              make_pair
#define pb              push_back
#define pf              push_front
#define speed_up        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x)           (int)x.size()
#define all(x)          x.begin(), x.end()
#define debug           cerr << "OK\n";
#define ub              upper_bound
#define lb              lower_bound
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define Int             sc1()
#define LL              sc2()
#define For(n)          for(int i=0;i<n;i++)
#define Forj(n)         for(int j=0;j<n;j++)
#define Fork(n)         for(int k=0;k<n;k++)
#define For1(n)         for(int i=1;i<=n;i++)

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef set <int>       si;
typedef set <ll>        sll;
typedef multiset <int>  msi;
typedef multiset <ll>   msll;
typedef map <int, int>  mi;
typedef map <ll, ll>    mll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
  
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
 
ll arr[N];
int solve() {
 

 	ll n,k;
 	cin>>n>>k;
 	ll sum=0;
 	for(ll i=n;i>=0;i--){
 		sum+=i;
 		arr[i]=sum;
 		// cout<<sum<<endl;
 	}
 	ll ans=0;
 	for(ll i=k;i<=n+1;i++){
 		ll px=((i)*(i-1))/2;
 		ll pm=arr[n-i+1];
 		// error(px,pm)
 		ans=(ans%mod+ ((pm-px)+1)%mod)%mod;
 		// cout<<pm-px<<endl;

 	}
 	cout<<ans<<endl;
	return 0;
}
 
 
 
 
int main()
{
	//speed_up;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 5200
x, n = input().split(' ')
line = input()
if line == '':
    print(x)
    exit()

x = int(x)

alist = line.split(' ')
for i in range(int(n)):
    alist[i] = int(alist[i])
if not x in alist:
    print(x)
    exit()

blist = [i for i in range(0,102)]
bset = set(blist)
aset = set(alist)
cset = bset-aset
clist = list(cset)
clist.append(x)
clist.sort()

count = 0
for i,v in enumerate(clist):
    if v == x:
        count = i
if count == 0:
    print(clist[1])
elif count == len(clist)-1:
    print(clist[-2])
else:
    minx = x - clist[count-1]
    maxx = clist[count+1]-x
    if minx > maxx:
        print(clist[count+1])
    else:
        print(clist[count-1])

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> a(3 * N);
    rep(i, 3 * N) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, N) {
        ans += a[3 * N - 2 - 2 * i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1408
def f():
     h,w = map(int,input().split())
     field = []
     for i in range(h):
          field.append(list(input()))
          
     que = []
     for i in range(h):
          for j in range(w):
               if field[i][j] == "#":
                    que.append([i,j])
     if que == []:
          print(0)
          return
     cnt = 0
     while que != []:
          que1 = []
          for p in que:
               for v in [[1,0],[0,1],[-1,0],[0,-1]]:
                    newx,newy = p[1]+v[1],p[0]+v[0]
                    if (0<=newx) and (newx<w) and (0<=newy) and (newy<h):
                         if field[newy][newx] == ".":
                              field[newy][newx] = "#"
                              que1.append([newy,newx])
          que = que1
          cnt += 1
     print(cnt-1)
     return
f()


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

int n;

void cut(int k,int *deck){
  // cout << "cut" << endl;
  queue<int>q;
  for (int i = 0; i < n; i++){
    q.push(deck[i]);
  }
  for (int i = 0; i < k; i++){
    q.push(q.front());q.pop();
  }
  for (int i = 0; i < n; i++){
    deck[i]=q.front();q.pop();
  }
}

void riffle(int *deck){
  //cout << "riffle" << endl;
  queue<int>q1,q2;
  for (int i = 0; i < n; i++){
    if (i<n/2) {
      q1.push(deck[i]);
    }else{
      q2.push(deck[i]);
    }
  }
  for (int i = 0; i < n; i++){
    if (i%2) {
      deck[i]=q2.front();q2.pop();
    }else{
      deck[i]=q1.front();q1.pop();
    }
  }
}

int main(){
  int m;
  cin>>n>>m;
  n*=2;
  int deck[n];
  for (int i = 0; i < n; i++)deck[i]=i;

  int ope;
  for (int i = 0; i < m; i++){
    cin>>ope;
    if(ope){
      cut(ope,deck);
    }else{
      riffle(deck);
    }
  }
  for (int i = 0; i < n; i++){
    cout << deck[i]+1 << endl;
  }
  return 0;
}

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

struct Vec{
	double x,y;
	Vec(double xx,double yy):x(xx),y(yy){}
};

Vec Relate(Vec o, Vec x, Vec p){
	Vec ans{0,0};
    x.x-=o.x; x.y-=o.y;
	ans.x += x.x*p.x; ans.y += x.y*p.x;
	ans.x -= x.y*p.y; ans.y += x.x*p.y;
	ans.x+=o.x; ans.y+=o.y;
	return ans;
}

vector<Vec> buf;

int main(){
	UL N; cin>>N;
	buf.push_back(Vec(0.0,0.0));
	buf.push_back(Vec(100.0,0.0));
	rep(n,N){
		vector<Vec> tmp;
        tmp.push_back(Vec(0.0,0.0));
		rep(i,buf.size()-1){
			tmp.push_back(Relate(buf[i],buf[i+1],Vec(1.0/3.0,0.0)));
			tmp.push_back(Relate(buf[i],buf[i+1],Vec(0.5,sqrt(0.75)/3.0)));
			tmp.push_back(Relate(buf[i],buf[i+1],Vec(2.0/3.0,0.0)));
			tmp.push_back(Relate(buf[i],buf[i+1],Vec(1.0,0.0)));
		}
        buf=move(tmp);
	}
	cout<<fixed<<setprecision(10);
	for(Vec& v:buf){
		cout<<v.x<<" "<<v.y<<endl;
	}
}


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>>a(m,vector<int>(2));
  vector<int>ans(n);
  for(int i=0; i<m; i++){
    for(int j=0; j<2; j++){
      cin >> a[i][j];
    }
  }
  
  for(int i=0;i<m; i++){
    for(int j=0; j<2; j++){
      ans[a[i][j]-1]++;
    }
  }
  for(int i=0;i<n; i++){
    cout << ans[i] << endl;
  }
  
  
}

Measured memory_bytes: 256
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

let inline memo2 size1 size2 f =
  let dp = Array2D.create size1 size2 None
  let rec g x y =
    match dp.[x, y] with
    | None ->
      let v = f g x y
      dp.[x, y] <- Some v
      v
    | Some v -> v
  g

// start
let (H, W) = readInts() |> pair
let c=
  let c=Array2D.zeroCreate 10 10
  for i in 0..9 do
    readInts() |> Array.iteri (fun j -> Array2D.set c i j)
  c
let A=
  seq {
    for _ in 1..H do
      yield! readInts()
  }

let minCost = 
  let d= c |> Array2D.copy
  for k in 0..9 do
    for i in 0..9 do
      for j in 0..9 do
        Array2D.modify d i j (min (d.[i,k]+d.[k,j]))
  Array2D.get d

A
|> Seq.sumBy (fun x -> if x= -1 then 0 else minCost x 1)
|> printfn "%d"

Measured memory_bytes: 16220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	string s;
	cin >> s;
	string t;
	cin >> t;
	int ans=0;
	FOR(i,3){
		if(s[i]==t[i])ans++;

	}	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 999999999
#define ll long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
5
3 2 2 4 1
1 2 2 2 1
)");
#define cin input
#endif

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

	vector<int> a1(n);
	vector<int> a2(n);
	REP(i,n)
		cin >> a1[i];
	REP(i,n)
		cin >> a2[i];
	reverse(a2.begin(), a2.end());

	vector<int> sum1(n+1);
	vector<int> sum2(n+1);
	REP(i,n)
		sum1[i+1]=sum1[i]+a1[i];
	REP(i,n)
		sum2[i+1]=sum2[i]+a2[i];

	int sum = 0;
	int max = a1[0]+a2[0];
	REP(i,n-1)
	{
		sum = sum1[i+1] + sum2[n-i];
		if (sum>max)
			max = sum;
	}
	cout << max << endl;
}

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

int main() {
  string T;
  cin >> T;
  int tempa;
  tempa = T.size();
  for (int i = 0; i < tempa; i++){
    if ( T[i] == '?' ){
      T.replace(i, 1, "D");
    }
  }
  cout << T << endl;
}

Measured memory_bytes: 3724
#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;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 1;
//----------------------//

int N;
int a[112345], b[112345];

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	return res;
}

int main() {
	cin >> N;
	REP(i, N) scanf("%d", a + i);
	REP(i, N) scanf("%d", b + i);
	
	vector<pii> v;
	REP(i, N) v.push_back(pii(a[i], 1));
	REP(i, N) v.push_back(pii(b[i], 0));
	
	sort(ALL(v));
	
	ll ans = 1;
	int cnt = 0;
	
	REP(i, 2 * N) {
		if (v[i].se == 1) {
			if (cnt > 0) ans = ans * cnt % MOD;
			cnt--;
		}
		else {
			if (cnt < 0) ans = ans * -cnt % MOD;
			cnt++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

typedef long long ll;
typedef long double lld;

#define ci(x) cin >> x 
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define x first
#define y second
#define ub upper_bound
#define lb lower_bound
#define pii pair <int ,int >
#define pll pair <ll ,ll > 
#define vpii vector<pii > v;
#define fore(i, a, b) for (int i=a; i<(b); i++)
#define cs(x) cout<<x<<" "
#define Yes printf("YES\n")
#define No printf("NO\n")
#define cl(x) cout<<x<<endl;
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define SET(arr,val) memset(arr,val,sizeof arr)

const int N = 1e5;
//int a[N+5];
pii v0[N+5], v1[N + 5];

int main() {
	int n, a;
	pii max10 = { 0,0 }, max00 = { 0,0 };
	pii max11 = { 0,0 }, max01 = { 0,0 };
	cin >> n;
	fore(i, 0, n) {
		ci(a);
		if (i % 2 == 0) {
			v0[a].x++;
			v0[a].y = a;
		}
		else {
			v1[a].x++;
			v1[a].y = a;
		}
	}
	fore(i, 0, N+5) {
		if (v0[i].x >= max00.x) {
				max01 = max00;
				max00 = v0[i];
		}
		else if (v0[i].x < max00.x && v0[i].x >= max01.x) {
			max01 = v0[i];
		}
	}
	fore(i, 0, N + 5) {
		if (v1[i].x >= max10.x) {
			max11 = max10;
			max10 = v1[i];
		}
		else if (v1[i].x < max10.x && v1[i].x >= max11.x) {
			max11 = v1[i];
		}
	}
	if (max00.y != max10.y) {
		cout << n - max00.x - max10.x;
	}
	else {
		cout << n - max((max00.x + max11.x), (max10.x + max01.x));
	}
	
	

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define 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())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#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())

using namespace std;


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

    int n, t;
    cin >> n >> t;

    vector<int> v;
    int c;
    int test;
    REP(_, n){
        cin >> c >> test;
        if (test <= t){
            v.PB(c);
        }
    }
    if ((int)v.size() == 0){
        cout <<"TLE";return 0;
    }else
   cout << *std::min_element(ALL(v));
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H==0&&W==0) {break;}
			for (int i=0; i<H; i++) {
				for (int j=0; j<W; j++) {
					if (i%2==0) {
						if (j%2==0) {System.out.print("#");}
						else {System.out.print(".");}
					}
					else {
						if (j%2==0) {System.out.print(".");}
						else {System.out.print("#");}
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 33976
import java.lang.*;
import java.util.*;
import java.io.*;

public class Main
{
	public static void main (String[] arg)throws IOException
	{
		int month[]= new int[12];
		int days[]= {31,29,31,30,31,30,31,31,30,31,30,31};
		int mod=4;
		month[0]=mod;
		for (int i = 1 ; i <12;i++){
			month[i]=(mod+days[i-1]%7)%7;
			mod=month[i];
		}
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String line;
		StringTokenizer tokenizer1;
		int a[] = new int[2];
		while ((line = input.readLine()) != null && !line.isEmpty()) {
			tokenizer1 = new StringTokenizer(line);
			for(int i=0;i<2;i++){
				a[i]=Integer.parseInt(tokenizer1.nextToken());
			}
			if(a[0]==0){
				break;
			}
			output((month[a[0]-1]+a[1]-1)%7);
		}
	}
	
	public static void output(int a){
		switch (a){
		  case 1:
			System.out.println("Monday");
		    break;
		  case 2:
		    System.out.println("Tuesday");
		    break;	
		  case 3:
		    System.out.println("Wednesday");
		    break;
		  case 4:
		    System.out.println("Thursday");
		    break;
		  case 5:
			System.out.println("Friday");
			break;
		  case 6:
			System.out.println("Saturday");
			break;
		  case 0:
			System.out.println("Sunday");
			break;
		}
	}
}	

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

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.begin(), A.end());
    int cost=pow(10,9);
    for(int x=A[0]; x<A[N-1]+1; x++){
        
        int tmp=0;
        for(int i=0; i<N; i++) tmp += (A[i]-x)*(A[i]-x);
        cost=min(tmp,cost);

    }

    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256