akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll h, w;
    cin >> h >> w;

    ll sa, sb, sc, hb, hc, wb, wc;
    ll ans = INF;
    rep(ha, 1, h) {
        sa = ha * w;
        
        hb = (h-ha) / 2;
        sb = hb * w;
        hc = h - ha - hb;
        sc = hc * w;
        if (sb > 0 && sc > 0) chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
    
        wb = w / 2;
        sb = (h-ha) * wb;
        wc = w - wb;
        sc = (h-ha) * wc;
        if (sb > 0 && sc > 0) chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
    }

    rep(wa, 1, w) {
        sa = wa * h;

        wb = (w-wa) / 2;
        sb = h * wb; 
        wc = w - wa - wb;
        sc = h * wc;
        if (sb > 0 && sc > 0) chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
    
        hb = h / 2;
        sb = (w-wa) * hb;
        hc = h - hb;
        sc = (w-wa) * hc;
        if (sb > 0 && sc > 0) chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

int n;

int V[100][100];
int D[100];
int d = 0;

std::queue<int> Q;

void bfs(int r) {
    Q.push(r);
    D[r] = 0;
    while (Q.size()) {
        r = Q.front();
        Q.pop();
        for (int i = 0; i < n; i++) {
            if ((D[i] == -1) && (V[r][i] == 1)) {
                Q.push(i);
                D[i] = D[r] + 1;
            }
        }
    }
}


int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            V[id - 1][t - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        D[i] = -1;
    }

    bfs(0);
    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << D[i] << std::endl;
    }
}


Measured memory_bytes: 3148
n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
	p,s=input().split()
	p=int(p)-1
	if s=="AC" and a[p]<0:
		a[p] = a[p]*(-1)
	if s=="WA" and a[p]<0:
		a[p] -= 1
ac=0
wa=0
for i in range(n):
	if a[i] > 0:
		ac += 1
		wa += a[i] - 1

print(ac,wa)

Measured memory_bytes: 3956
#include<bits/stdc++.h> 
using namespace std; 
  
const int MAX = 500005; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
}
    int main()
    {
    	int n,q,i,j;
    	cin>>n>>q;
    	int a[n];
    	for(i=0;i<n;i++)
    	{
    		cin>>a[i];
		}
		Query qu[q];
		for(i=0;i<q;i++)
		{
			qu[i].idx=i;
			
			cin>>qu[i].l>>qu[i].r;
			qu[i].l--;
			qu[i].r--;
		}
		sort(qu, qu+q, cmp); 
		answeringQueries(a, n, qu, q);
		
	}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dc[4] = {1, -1, 0,  0};
const int dr[4] = {0,  0, 1, -1};
//const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
//const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

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

    v_int a(n);
    cin >> a;
    
    int odd = 0, even = 0;
    irep(i, n) {
        if(a[i] % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }
    if(even == n) {
        cout << "second" << endl;
    } else {
        cout << "first" << endl;
    }

    return 0;
}

/*atcoder*/


Measured memory_bytes: 3784
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int L, R;
  cin >> L >> R;
  int ans = 1e9;
  for (int i = L; i <= min(R, L + 2019); i++) {
    for (int j = i + 1; j <= min(R, L + 2019); j++) {
      const int x = (i % 2019) * (j % 2019) % 2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
genom=input()
maxstr=0
bush=0

for i in range(len(genom)):
    if genom[i]=="A" or genom[i]=="G" or genom[i]=="T" or genom[i]=="C":
        bush = bush+1
        maxstr=max(bush, maxstr)
    else:
        bush=0

print(maxstr)

Measured memory_bytes: 3060
// D - Wide Flip

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int N = S.size();

	int l = (N+1) / 2;
	for (int i=(N-1)/2; i<N-1; i++) {
		if (S[i] == S[i+1]) l++;
		else break;
	}

	int r = (N+1) / 2;
	for (int i=N/2; i>0; i--) {
		if (S[i] == S[i-1]) r++;
		else break;
	}

	cout << min(l, r) << endl;

	return 0;
}

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

int main() {
  int N, M;
  cin >> N;
  vector<string> blue(N);

  for (int i = 0; i < N; i++) {
    cin >> blue.at(i);
  }
  cin >> M;
  vector<string> red(M);

  for (int i = 0; i < M; i++) {
    cin >> red.at(i);
  }

  int c, maximam = 0;
  
  for (int i = 0; i < N; i++) {
    c = 1;
    
    for (int j = 0; j < N; j++) {
      if (i != j && blue.at(i) == blue.at(j)) {
        c++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (blue.at(i) == red.at(j)) {
        c--;
      }
    }

    if (maximam < c) {
      maximam = c;
    }
  }

  cout << maximam << endl;
}

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

int main() {
    int n;
    cin >> n;
    int j = 0;
    
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        
        if (s == "Y") {
            j += 1;
        }
    }
    
    if (j > 0) {
        cout << "Four" << endl;
    }
    
    else {
        cout << "Three" << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()
S=''
for i in range(H):
    S+=input()

C=Counter(S)
if H%2==0 and W%2==0:
    for k, v in C.items():
        if v%4!=0:
            No()
            exit()
    Yes()
elif H%2==0:
    mod2=0
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                mod2+=1
            else:
                No()
                exit()
    if mod2<=H//2:
        Yes()
    else:
        No()
elif W%2==0:
    mod2=0
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                mod2+=1
            else:
                No()
                exit()
    if mod2<=W//2:
        Yes()
    else:
        No()
else:
    mod2=mod1=0
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                mod2+=1
            elif v%3==0:
                mod2+=1
                mod1+=1
            else:
                mod1+=1
    if mod1==1 and mod2<=(H+W)//2-1:
        Yes()
    else:
        No()


Measured memory_bytes: 3316
from sys import stdin
import math
n = int(stdin.readline().rstrip())
m = int(n**0.5) +2

data =[0] *100000
tmp = 0
# # x + y + z =3以上
for x in range (1, m):
    for y in range(1, m):
        for z in range(1, m):
            tmp = x*x + y*y + z*z + x*y + y*z + z*x
            if tmp <= n :
                data[tmp] += 1

#配列の0番目除く
for i in range(1,n+1):
    print(data[i])


Measured memory_bytes: 10020
from math import *
from bisect import bisect_left

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def bs(arr, l, r, x): 
    while l <= r: 
        mid = l + (r - l) // 2; 
        if arr[mid] == x: 
            return mid 
        elif arr[mid] < x: 
            l = mid + 1
        else: 
            r = mid - 1
    return -1


def main():
    a = cino()
    if a%1000==0:
        print(0)
    else:
        x = a//1000
        # print(x)
        print((x+1)*1000-a)       

if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
// Last Change: 03/03/2019 21:01:54.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  B = B / A;
  if (B > C) {
    B = C;
  }
  cout << B << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def checksame(self, faces):
        if self.number(2) in (faces.number(3), faces.number(4)):
            faces.roll_west()
        while self.number(2) != faces.number(2):
            faces.roll_north()
        while self.number(1) != faces.number(1):
            faces.roll_west()
        return self.number(3) == faces.number(3)

dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))

print("Yes" if dice1.checksame(dice2) else "No")

Measured memory_bytes: 6772
<?php

fscanf(STDIN, "%d", $n);

$max_cnt = 0;
$ans = $n;
for ($i = $n; $i > 1; $i--) {
   // echo $i."\n";
    $cnt = 0;
    $m = $i;
    while (true) {
  //  echo $m."\n";
        if ($m % 2 == 0) {
            $m = $m/2;
            $cnt++;
        } else {
            if($max_cnt<$cnt){
                $ans = $i;
                $max_cnt = $cnt;
            }
            break;
        }
    }
}
echo $ans;


Measured memory_bytes: 4604
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e18
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,k,a[maxn],f[maxn];

inline bool jud(ll x)
{
	ll tmp=k;
	for(int i=1;i<=n;i++)
	{
		ll p=f[n-i+1],q=x/p;
		if(a[i]>q) tmp-=(a[i]-q);
	}
	if(tmp>=0) return true; return false;
}

int main()
{
	n=read(); k=read();
	rep(i,1,n) a[i]=read(); rep(i,1,n) f[i]=read();
	sort(a+1,a+n+1); sort(f+1,f+n+1);
	ll l=0,r=inf,ans=inf;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(jud(mid)) r=mid-1,ans=mid;
		else l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int[] a = new int[3];
        for(int i = 0;i<a.length;i++){
            a[i]= scanner.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[0]+" "+a[1]+" "+a[2]);

    }

}



Measured memory_bytes: 26348
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i < n; i++) {
            try{
                dp[i + 1] = Math.min(dp[i + 1], dp[i] + Math.abs(nums[i + 1] - nums[i]));
            } catch(Exception e) {

            }
            try{
                dp[i + 2] = Math.min(dp[i + 2], dp[i] + Math.abs(nums[i + 2] - nums[i]));
            } catch(Exception e) {

            }
        }
        System.out.println(dp[n - 1]);
    }
}


Measured memory_bytes: 48724
#include <cstdlib>
#include <cstdio>
#include <iostream>

typedef int type;
using namespace std;
const bool isDebug = false;

void showArray(type A[], int N){
    for(int i=0; i<N; i++){
        printf("%d", A[i]);
        if(i != N-1) printf(" ");
    }
    printf("\n");
}

int selectionSort(type A[], int N){
    int changeTime = 0;
    for(int i=0; i<N; i++){
        int minJ= i;
        for( int j=i; j<N; j++){
            if(A[j] < A[minJ]){
                minJ = j;
            }
        }
        //swap
        if(i != minJ){
            changeTime ++;
            type tmp = A[i];
            A[i] = A[minJ];
            A[minJ] = tmp;
        }
    }
    return changeTime;
}

#define MAX_N 100
int N;
int A[MAX_N];
void input(){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
}

int main(){
    input();
    int changeTime = selectionSort(A, N);
    showArray(A, N);
    printf("%d\n", changeTime);
    return 0;
}

Measured memory_bytes: 3160
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    TIN(string, n);
    ll d = 0;
    rep(i, n.size()) {
        d += n[i] - '0';
    }
    cout << (d % 9 == 0 ? "Yes" : "No") << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

using namespace std;
 

typedef long long ll;
const ll MAX_N = 1<< 20 ;
typedef pair<ll,ll> P;
ll n;
P dat[2*MAX_N-1];
 

void init(ll a){
  n = 1;
  while( n < a ) { n *=2;}
  for(ll i=0;i<2*n-1;i++) { dat[i]=P(INT_MAX,INT_MAX);}
}
 
ll update(ll a,ll b, ll  k, ll l, ll r,ll x){
  if(r<=a||b<=l)return dat[k].second;
  if(a<=l&&r<=b){
    dat[k]=P(x,x);
    return x;
  }else{
    if(dat[k].first!=INT_MAX){
      dat[k*2+1].first=dat[k*2+1].second=dat[k].first;
      dat[k*2+2].first=dat[k*2+2].second=dat[k].first;
      dat[k].first=INT_MAX;
    }
    ll m=(l+r)/2;
    ll v1=update(a,b,k*2+1,l,m,x);
    ll v2=update(a,b,k*2+2,m,r,x);
    return dat[k].second=min(v1,v2);
  }
}
 
ll query(ll a,ll b,ll k,ll l,ll r){
  if(r<=a||b<=l)return INT_MAX;
  if(a<=l&&r<=b)return dat[k].second;
  else{
    if(dat[k].first!=INT_MAX){
      dat[k*2+1].first=dat[k*2+1].second=dat[k].first;
      dat[k*2+2].first=dat[k*2+2].second=dat[k].first;
      dat[k].first=INT_MAX;
    }
    return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
  }
}

int main(){
  ll N,Q; cin >> N >> Q;
  init(N);
  for(ll i = 0; i < Q; i++){
    int com; cin >> com;
    if( com ){
      ll s,t; cin >> s >> t; cout << query(s,t+1,0,0,n) << endl;}
    else{
      ll s,t,x; cin >> s >> t >> x; update(s,t+1,0,0,n,x) ;}
  }
  
  return 0;}
  
  
  



Measured memory_bytes: 35892
lines = readlines.map{|line| line.split(' ').map(&:to_i)}
a=lines[0][0]
b=lines[0][1]
m=lines[0][2]
rei=lines[1]
den=lines[2]
v=[rei[lines[3][0]-1]+den[lines[3][1]-1]-lines[3][2],rei.min+den.min].min
for i in 3..3+m-1 do
  x=rei[lines[i][0]-1]+den[lines[i][1]-1]-lines[i][2]
  if x<v then
    v=x
  end
end
puts v

Measured memory_bytes: 32396
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 998244353
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,a[MAXN],b[MAXN],c[MAXN],d[MAXN];
map<int,int> mpc,mpd;
int perm[MAXN];
bool vis[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        c[i]=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        d[i]=b[i];
    }
    sort(c+1,c+n+1); sort(d+1,d+n+1);
    for(int i=1;i<=n;i++)
    {
        if(c[i]>d[i])
        {
            puts("No");
            return 0;
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(c[i]<=d[i-1])
        {
            puts("Yes");
            return 0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        mpc[c[i]]=i; mpd[d[i]]=i;
    }
    for(int i=1;i<=n;i++)
    {
        perm[mpd[b[i]]]=mpc[a[i]];
    }
    memset(vis,false,sizeof(vis));
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            int cur=i;
            do
            {
                vis[cur]=true;
                cur=perm[cur];
            }while(!vis[cur]);
            cnt++;
        }
    }
    if(cnt==1) puts("No"); else puts("Yes");
    return 0;
}


Measured memory_bytes: 11648
from collections import Counter
H, W = map(int, input().split())
S = []
for h in range(H):
    tmp = list(input())
    for w in tmp:
        S.append(w)

S = Counter(S)
square = (H // 2) * (W // 2)
line = (H // 2) * (W % 2 == 1) + (W // 2) * (H % 2 == 1)

if H % 2 == 1 and W % 2 == 1:
    for key, value in S.items():
        if value % 2 == 1:
            S[key] -= 1
            break

for key, value in S.items():
    if value >= 4:
        while value >= 4 and square != 0:
            square -= 1
            value -= 4
            S[key] -= 4


for key, value in S.items():
    if value >= 2:
        while value >= 2:
            line -= 1
            value -= 2
            S[key] -= 2

print("Yes" if square == 0 and line == 0 else "No")


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, K;
  cin >> N >> K;
  vl A(N);
  rep(i, N) cin >> A[i];

  if(K <= N){
    ll pos = 0;
    rep(i, K)  pos = A[pos] - 1;
    cout << pos + 1 << endl;
  } else{
    ll pos = 0;
    ll cnt = 0;
    ll enter, loop;
    vl dist(N, -1);
    while(true){
      if(dist[pos] != -1){
	enter = pos;
	loop = cnt - dist[pos];
	break;
      }
      dist[pos] = cnt;
      pos = A[pos] - 1;
      cnt++;
    }
    ll left = K - dist[enter];
    // cout << enter << ' ' << loop << ' ' << left << endl;
    left %= loop;
    pos = enter;
    rep(i, left) pos = A[pos] - 1;
    cout << pos + 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6428
using System;
using System.Collections.Generic;
using System.IO;

namespace MinPro2019D
{
    public class Program
    {
        void Solve(SimpleScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var L = ss.NextLong();
            var dp = new long[5];

            for (var i = 0; i < L; i++)
            {
                var A = ss.NextLong();
                var x = A == 0 ? 2 : A & 1;

                dp[0] += A;
                dp[1] += x;
                dp[2] += (x & 1) ^ 1;
                dp[3] += x;
                dp[4] += A;

                for (var t = 1; t < 5; t++)
                {
                    dp[t] = Math.Min(dp[t], dp[t - 1]);
                }
            }

            sw.WriteLine(dp[4]);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new SimpleScanner(Console.OpenStandardInput());
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }

    //ref: https://qiita.com/Camypaper/items/de6d576fe5513743a50e#%E5%85%A5%E5%8A%9B%E3%81%AE%E9%AB%98%E9%80%9F%E5%8C%96
    //by Camypaperさん 
    public class SimpleScanner
    {
        const int DefaultCapacity = 1024;

        readonly Stream stream;
        readonly int capacity;
        readonly byte[] buffer;
        readonly List<char> chars;

        int index = 0;
        int length = 0;
        bool isEof = false;

        public SimpleScanner(Stream stream, int capacity = DefaultCapacity)
        {
            this.stream = stream;
            this.capacity = capacity;
            this.buffer = new byte[capacity];
            this.chars = new List<char>();
        }

        void Reload()
        {
            index = 0;
            length = stream.Read(buffer, 0, capacity);
            isEof = length <= 0;
        }

        void CheckBuffer()
        {
            if (index < length) return;
            if (isEof) throw new EndOfStreamException();
            Reload();
            CheckBuffer();
        }

        byte Peek()
        {
            CheckBuffer();
            return buffer[index];
        }

        byte Read()
        {
            CheckBuffer();
            return buffer[index++];
        }

        bool CanInput(byte b)
        {
            return 33 <= b && b <= 126;
        }

        public string Next()
        {
            chars.Clear();
            while (!CanInput(Peek())) Read();
            while (CanInput(Peek())) chars.Add((char)Read());
            return new string(chars.ToArray());
        }

        bool IsNumber(byte b)
        {
            return 48 <= b && b <= 57;
        }

        public long NextLong()
        {
            var ret = 0L;
            while (!CanInput(Peek())) Read();
            while (IsNumber(Peek())) ret = ret * 10 + Read() - 48;
            if (CanInput(Peek())) throw new FormatException();
            return ret;
        }
    }
}


Measured memory_bytes: 13012
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define mk make_pair
#define ll long long
#define int long long
using namespace std;

inline int read()
{
  int x=0,f=1;char ch=getchar();
  while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
  while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
  return x*f;
}

int n;
int ans;

signed main()
{
  int x=read(),y=read(),z=read();
  ans=ans+y;
  ans=ans+min(z,y);
  z-=min(z,y);
  if (z==0) 
  {
  	cout<<ans;
  	return 0;
  }
  else
  {
  	ans=ans+min(x,z);
  	z-=min(x,z);
  }
  if (z>0) ans++;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
class Physical
  def initialize
    @v = []
    while v = $stdin.gets
      @v << v.chomp.to_f
    end
    calc
  end

  def calc
    @v.each do |v|
      t = v / 9.8
      y = 4.9 * t * t
      puts floor_check(y)
    end
  end

  def floor_check(y)
    f = 1
    while y > f * 5 - 5
      f += 1
    end
    return f
  end
end

p = Physical.new

Measured memory_bytes: 2292
#include<stdio.h>
#include<string.h>

#define M 1000000
#define NIL (-1)
#define L 14

char H[M][L];/* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, j;
  key = getKey(str);
  for ( i = 0;; i++){
    j = (h1(key)+i*h2(key))%M;
    if( strcmp(H[j],str) == 0 ) return 1;
    else if ( strlen(H[j]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, j;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    j = (h1(key)+i*h2(key))%M;
    if( strcmp(H[j],str) == 0 ) return 1;
    else if ( strlen(H[j]) == 0 ){
      strcpy(H[j], str);
      return 0;
    }
  }
  return 0;
}

main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      if (insert(str)){

      }
    } else {
      if (find(str) ){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}




Measured memory_bytes: 15428
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, s;
    cin>>n;
    vector<int> a;
    rep(i, n){
        cin>>s;
        a.eb(s);
    }
    int ma;
    /*
    for(int i = 0; i < n; i++){
        ma = a[0];
        for(int j = 0; j < n; j++){
            if(i != j){
                if(ma < a[j]){
                    ma = a[j];
                }
            }
        }
        cout<<ma<<endl;
    }
    */
   /*
   int ma1, ma2;
   for(int i = 0; i < n; i++){
        if(i == 0){
            cout<<*max_element(a.begin()+1, a.end())<<endl;
        }
        else if(i == n-1){
            cout<<*max_element(a.begin(), a.end()-1)<<endl;
        }
        else{
            ma1 = *max_element(a.begin(), a.begin()+i-1);
            ma2 = *max_element(a.begin()+i+1, a.end());
            if(ma1 > ma2){
                cout<<ma1<<endl;
            }
            else{
                cout<<ma2<<endl;
            }
        }
   }
   */
    vector<int>t = a;
    sort(all(t));
    for(int i = 0; i < n; i++){
        if(a[i] == t[n-1]){
            cout<<t[n-2]<<endl;
        }
        else{
            cout<<t[n-1]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3316
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int> > c;
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    c.push_back(make_pair(b,a));
  }
  sort(c.begin(),c.end());
  //reverse(c.begin(),c.end());
  int count = 0;
  int br = -1;
  for(int i=0;i<m;i++){
    b = c[i].first;
    a = c[i].second;
    if(a < br) continue;
    br = b;
    count += 1;
  }
  cout << count << endl;

  return 0;
}


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

int main(){
     int N,A,B,C,X;
     while(cin>>N>>A>>B>>C>>X,N||A||B||C||X){
	  queue<int> lists;
	  for(int i=0;i<N;i++){
	       int a;
	       cin>>a;
	       lists.push(a);
	  }
	  int ans=-1;
	  for(int i=0;i<10001;i++){
	       int t=lists.front();
	       if(X==t){
		    lists.pop();
	       }
	       if(lists.empty()){
		    ans=i;
		    break;
	       }
	       X=(A*X+B)%C;
	  }
	  cout<<ans<<endl;
     }
     return 0;
}

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

using namespace std;

int main()
{
    int n,k,a[100006];
    cin>>n>>k;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    if(n==k){
        cout<<1<<endl;
        return 0;
    }
    int x=0;
    sort(a, n+a);
    for(int i=1; i<n; i=i+k-1){
        x++;
    }
    cout<<x<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;


int main(void){
  int a,b;
  cin >> a >> b;
  if(a==1) a=14;
  if(b==1) b=14;
  if(a > b) cout << "Alice\r\n";
  else if(a == b) cout << "Draw\r\n";
  else cout << "Bob\r\n";
  return 0;
}


Measured memory_bytes: 256
n=int(input())

a=list(map(int,input().split()))
b=list(map(int,input().split()))


b.reverse()
mondai=-1
kasho=0
mondai_basho=-1
for i in range(n):
    if(a[i]==b[i]):
        mondai=a[i]
        kasho+=1
        if(kasho==1):
            mondai_basho=i



kano=True
ans=[]
if(kasho==0):
    ans=b
else:
    hajimea=0
    hajimeb=0
    owaria=0
    owarib=0
    for i in range(n):
        if(a[i]<mondai):
            hajimea+=1
        if(a[i]>mondai):
            owaria+=1
        if(b[i]>mondai):
            hajimeb+=1
        if(b[i]<mondai):
            owarib+=1
    hajime=min(hajimea,hajimeb)
    owari=min(owaria,owarib)
    if(kasho>hajime+owari):
        kano=False
    else:
        for i in range(kasho):
            if(i<hajime):
                temp=b[mondai_basho+i]
                b[mondai_basho+i]=b[i]
                b[i]=temp
            else:
                temp=b[mondai_basho+i]
                b[mondai_basho+i]=b[n-owari+i-hajime]
                b[n-owari+i-hajime]=temp
        ans=b

if(not kano):
    print("No")
else:
    print("Yes")
    for i in range(n):
        b[i]=str(b[i])
    print(" ".join(b))

Measured memory_bytes: 113608
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
	#endif


	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	vector<int> h;
	vector<int> dp(n);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		h.push_back(x);
	}
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
	return 0;

}
	/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
	

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

int n;
void call(int n);
void call2(int n);

int main(){
    cin>>n;
    call2(n);
    return 0;
}

void call2(int n){
    for(int i=1;i<=n;++i){
        int x=i;
        if(x%3 == 0){
            cout<<" "<<i;
        }
        else{
            while(1){
                if(x%10 == 3 ){
                    cout<<" "<<i;
                    break;
                }
                x /=10;
                if(x==0)break;
            }
        }
    }
    cout<<endl;
}

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}


Measured memory_bytes: 3104
main :: IO ()
main = do
    n <- readLn :: IO Int
    points <- map read . words <$> getLine
    let allPoints = 0 : (points ++ [0])
    let totalDist = sum $ calcDist allPoints
    let fellPointsTotal =  map (+totalDist) $ zipWith (-) (distsNotStopAt allPoints) (distsStopAt allPoints)

    mapM_ print fellPointsTotal

calcDist :: [Int] -> [Int]
calcDist [] = []
calcDist [x] = []
calcDist (x:y:s) = (dist x y) : calcDist (y:s)

dist :: Int -> Int -> Int
dist x y = abs $ x - y

distsStopAt :: [Int] -> [Int]
distsStopAt [] = []
distsStopAt (a:b:c:xs) = ((dist a b) + (dist b c)) : (distsStopAt (b:c:xs))
distsStopAt lis = []
    
distsNotStopAt :: [Int] -> [Int]
distsNotStopAt [] = []
distsNotStopAt (a:b:c:xs) = (dist a c) : (distsNotStopAt (b:c:xs))
distsNotStopAt lis = []

calcFellDist :: Int -> [Int] -> Int -> Int
calcFellDist total lis i = total - distStopAt + dist (lis !! (i+1)) (lis !! (i-1))
    where distStopAt = (dist (lis !! i) (lis !! (i - 1))) + (dist (lis !! i) (lis !! (i + 1)))


Measured memory_bytes: 29692
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

#define REP(i,n) for(ll i=0 ; i<ll(n) ; i++)
#define ALL(x) x.begin(),x.end()

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x,y,z,k;
    cin >> x >> y >> z >> k;

    vector<ll> xl(x), yl(y),zl(z);
    REP(i,x) cin >> xl[i];
    REP(i,y) cin >> yl[i];
    REP(i,z) cin >> zl[i];
    vector<ll> xyl;
    for(int i = 0 ; i < x; i++ ){
        for(int j=0 ; j < y ; j++){
            xyl.push_back(xl[i]+yl[j]);
        }
    }
    sort(xyl.begin(), xyl.end(), greater<ll>());
    
    vector<ll> xyzl;
    for(int i=0 ; i<min(k,x*y) ; i++){
        for(int j=0 ; j < z; j++){
            xyzl.push_back(xyl[i]+zl[j]);
        }
    }

    sort(xyzl.begin(), xyzl.end(), greater<ll>());
    for(int i = 0; i < k ; i++){
        cout << xyzl[i] << endl;
    }

}

Measured memory_bytes: 44056
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

const int MAX=510000;

vll fac(MAX);
vll finv(MAX);
vll inv(MAX);

void combinit(ll m){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    rep2(i,2,MAX){
        fac[i]=fac[i-1]*i%m;
        inv[i]=m-inv[m%i]*(m/i)%m;
        finv[i]=finv[i-1]*inv[i]%m;
    }
}

ll combi(ll n,ll k,ll m){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%m)%m;
}

map<ll,ll> prime;
ll tmp=-1;

void factorization(ll x){
    for(ll i=2;i*i<=x;i++){
        while(x%i==0){
            prime[i]++;
            x/=i;
        }
    }
    if(x!=1){
        prime[x]++;
        tmp=x;
    }
    return;
}

int main(){
    ll n,m;cin>>n>>m;
    factorization(m);
    combinit(inf);
    ll ans=1;
    for(ll i=2;i*i<=m;i++){
        if(prime.count(i)){
            ans*=combi(n-1+prime[i],prime[i],inf);
            ans%=inf;
        }
    }
    if(tmp*tmp>m){
        ans*=combi(n-1+prime[tmp],prime[tmp],inf);
        ans%=inf;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define int long long
#define inf 1000000007
#define MAXN 250
#define MAXT 250
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef pair<int,int> pii;

	
int32_t main(){
	fastio;
	int A,B;
	cin>>A>>B;
	if(A<=5)cout<<0<<endl;
	else if(A<=12)cout<<B/2<<endl;
	else cout<<B<<endl;
	
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
using ll = long long ;
int n;
string a, b;

int main(){
    cin >> n;
    cin >> a >> b;
    for(int i = 0 ;i < n; i ++){
        cout << a[i] << b[i];
    }
    cout << endl;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  for(int i = 1; 10 > i; i++){
    for(int j = 1; 10 > j; j++){
      if(i*j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import deque
import sys
input2 = sys.stdin.readline()

s=list(input2)
Q=int(input())
direction=0
d=deque(s)
d.pop()

for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        if direction == 0:
            direction = 1
        else:
            direction = 0
    else:
        if tmp[2] == "1":
            if direction == 0:
                d.appendleft(tmp[4])
            else:
                d.append(tmp[4])
        else:
            if direction == 0:
                d.append(tmp[4])
            else:
                d.appendleft(tmp[4])
if direction==1:
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

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

    int l = 0;
    char c = 'R';
    int to[n]; rep(i,n) to[i] = -1;
    for (int i = 1; i < n; i++) {
        if (c != s[i]) {
            for (int j = l; j < i; j++) {
                if (c == 'R') to[j] = i-1;
                else to[j] = l;
            }
            l = i;
            c = s[i];
        }
    }
    for (int j = l; j < n; j++) {
        to[j] = l;
    }

    int ans[n]; rep(i,n) ans[i] = 0;
    rep(i,n) {
        if (abs(i-to[i])%2) {
            if (s[i] == 'R') ans[to[i]+1]++;
            else ans[to[i]-1]++;
        }
        else ans[to[i]]++;
    }
    rep(i,n-1) printf("%d ", ans[i]);
    printf("%d\n",ans[n-1]);

    return 0;
}


Measured memory_bytes: 4632
/*
Author : N_o_o_B
Created : April 12 2020 17:30:33 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    string s;
    cin >> s;
    bool ok = 0;
    for(char c:s) ok |= (c=='7');
    cout << (ok ? "Yes":"No") << endl;



    time_taken();
    return 0;
}

Measured memory_bytes: 3788
N = int(input())
D = []
for _ in range(N):
    D.append(list(map(int,input().split())))
check = ''
for i in range(N):
    if D[i][0] == D[i][1]:
        check += 'T'
    else:
        check += 'F'

if 'TTT' in check:
    print('Yes')
else:
    print('No')

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

dp = [0,abs(h[1]-h[0])]+[0 for i in range(N-2)]

for i in range(2,N):
    dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])

print(dp[N-1])



Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000000007;



signed main(){
    int n;
    cin >> n;
    map<int,int> a;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        a[b]++;
    }
   if(n % 2 == 1){
       for(int i = 0; i < n; i+=2){
           bool ans = true;
           if(i == 0 && a[i] != 1 || i > 0 && a[i] != 2){
               ans = false;
           }
           if(!ans){
               cout << 0 << endl;
               return 0;
           }
       }
   }
   else
   {
       for(int i = 1; i < n; i += 2){
           if(a[i] != 2)
           {
               cout << 0 << endl;
               return 0;
           }
       }
   }
   
    
    
    int ans = 1;
    for(int i = 1; i <= (n / 2); i++){
        ans *= 2;
        ans = ans % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
import java.util.*;

public class Main {
    public static void main(String [] args)
    {
        String txt;


        Scanner sc = new Scanner(System.in);
        txt = sc.nextLine();
        if(palindrome(txt))
        {
            String firstHalf = txt.substring(0,(txt.length()-1)/2);
            if(palindrome(firstHalf))
            {
                String secondHalf = txt.substring((txt.length()+3)/2-1,txt.length());
                if(palindrome(secondHalf))
                {
                    System.out.print("Yes");
                }
                else
                {
                    System.out.print("No");
                }
            }
            else
            {
                System.out.print("No");
            }
        }
        else
        {
            System.out.print("No");
        }
    }

    public static boolean palindrome(String word)
    {
        String copy = "";
        for(int i = word.length(); i > 0; i--)
        {
            copy += word.substring(i-1,i);
        }
        if(word.equals(copy))
        {
            return true;
        }
        return false;
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
int n;
char vote[101];
int counta;
void solve(){
  //counta ++;
  //cout << counta<< ":" << endl;
  vector<int> candidate(26,0);

  for(int i = 0; i < n ; i++){
    candidate[vote[i] - 'A'] ++; //reset candidate[]
    for(int j = 0 ; j < 26; j++){
      bool finish = true;
      for(int k = 0; k < 26; k++){
        if( j != k &&  candidate[j] <= (candidate[k] + n - i - 1) ){
          finish = false;
          break;
        }
      }


      if(finish == true){
        printf("%c %d\n",(char)(j + 'A'),i + 1 );
        candidate.clear();
        return;
      }

    }
  }
  printf("TIE\n");
  candidate.clear();
  return ;
}

int main(){
  while(true){
    cin >> n;
    if(n == 0) break;
    for(int input = 0; input < n; input++){
      cin >> vote[input];
    }
    solve();
  }
  return 0;
}



Measured memory_bytes: 3128