akhauriyash/Code-Regression huggingface dataset:
$input = $stdin.read.split("\n")
N,K=$input.shift.split(" ").map(&:to_i)
a = $input.shift.split(" ").map(&:to_i)

dest = a.map.with_index(1) {|x,i| [i,x]}.to_h

# p dest

ss = {}

v = 1
ss = {} # いった場所を覚えておく
xs = [] # 閉路を覚えるためルートを記録しておく
nv = -1
loop do
  nv = dest[v]
  ss[v] = true
  xs << v
  if ss[nv] # もういった
    # puts "#{v}:#{nv} already visited"
    break
  end
  v = nv
end

# p ss
# p xs

pos = xs.index(nv)
# puts "pos=#{pos}"
k = K - pos
path = xs[pos..]

if K < pos
  puts xs[K]
else
  mod = k % path.count
  # puts "mod=#{mod}"
  puts path[mod]
end


Measured memory_bytes: 55680
from itertools import product
from collections import deque
from sys import stdin
input = stdin.readline

H,W = map(int, input().split())
Ch,Cw = map(lambda x: int(x) - 1, input().split())
Dh,Dw = map(lambda x: int(x) - 1, input().split())
S = [None]*H
for i in range(H):
    S[i] = list(input())

moveA = ((1,0),(0,1),(-1,0),(0,-1))
moveB = []
for i,j in product((-2,-1,0,1,2), repeat=2):
    if (i,j) not in moveA:
        moveB.append((i,j))

mapmatrix = [[-1]*W for _ in range(H)]
queue = deque()
queue.append((Cw,Ch))
mapmatrix[Ch][Cw] = 0

worpqueue = deque()
worpqueue.append((Cw,Ch))
while queue or worpqueue:
    while queue:
        x,y = queue.popleft()
        worpnum = mapmatrix[y][x]

        for dx, dy in moveA:
            X = x + dx; Y = y + dy
            if X >= 0 and X < W and Y >= 0 and Y < H:
                if mapmatrix[Y][X] == -1 and S[Y][X] == '.':
                    mapmatrix[Y][X] = worpnum
                    queue.append((X,Y))
                    worpqueue.append((X,Y))
                    
    nextworpqueue = deque()
    while worpqueue:
        x,y = worpqueue.popleft()
        worpnum = mapmatrix[y][x]

        for dx, dy in moveB:
            X = x + dx; Y = y + dy
            if X >= 0 and X < W and Y >= 0 and Y < H:
                if mapmatrix[Y][X] == -1 and S[Y][X] == '.':
                    mapmatrix[Y][X] = worpnum + 1
                    queue.append((X,Y))
                    nextworpqueue.append((X,Y))
    
    while nextworpqueue:
        x,y = nextworpqueue.popleft()
        worpqueue.append((x,y))
        
print(mapmatrix[Dh][Dw])

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

int main(){
	int a, b;
	string op;
	while (cin >> a >> op >> b){
		if (op == "+"){
			cout << (a + b) << endl;
		}
		else if (op == "-"){
			cout << (a - b) << endl;
		}
		else if (op == "*"){
			cout << (a * b) << endl;
		}
		else if (op == "/"){
			cout << (a / b) << endl;
		}
		else {
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p 998244353

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

int rank(int N, int M, int **a){
	int i, j, k, l;
	int **sub = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		sub[i] = (int *)malloc(sizeof(int) * M);
		for(j = 0; j < M; j++){
			sub[i][j] = a[i][j];
		}
	}
	for(i = 0, j = 0; i < N && j < M; i++, j++){
//		printf("(i, j) = (%lld, %lld)\n", i, j);
		for(k = i; k < N; k++){
			if(sub[k][j] == 1){
				break;
			}
		}
//		printf("k = %lld\n", k);
		if(k == N){
			i--;
			continue;
		}
		int *tmp = sub[i];
		sub[i] = sub[k];
		sub[k] = tmp;
		for(k = 0; k < N; k++){
			if(i != k && sub[k][j] == 1){
				for(l = j; l < M; l++){
					sub[k][l] ^= sub[i][l];
				}
			}
		}
/*		printf("sub:\n");
		for(k = 0; k < N; k++){
			for(l = 0; l < M; l++){
				printf("%lld ", sub[k][l]);
			}
			printf("\n");
		}
*/	}
/*	printf("sub:\n");
	for(k = 0; k < N; k++){
		for(l = 0; l < M; l++){
			printf("%lld ", sub[k][l]);
		}
		printf("\n");
	}
*/	return i;
}

signed main(){
	int N, M, i, j;
	scanf("%lld%lld", &N, &M);
	int **a = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		a[i] = (int *)malloc(sizeof(int) * M);
		for(j = 0; j < M; j++){
			scanf("%lld", &a[i][j]);
		}
	}
	printf("%lld\n", MOD((power(2, N) - power(2, N - rank(N, M, a))) * power(2, M - 1)));
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define INF 1e9;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int ans=0,cnt=0;
	for(int i=0;i<n-1;i++){
		if(h[i]>=h[i+1]){
			cnt++;
		}
		else{
			ans=max(ans,cnt);
			cnt=0;
		}
	}
	ans=max(ans,cnt);
	cout<<ans<<endl;
	return 0;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  vector<int> vec(5);
  for(int i = 0; i < 5; i++){
    cin >> vec[i];
    if(vec[i] == 0){
      cout << i+1 <<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner sn, PrintWriter out) {
            String a[] = sn.next().split("");
            if (a[0].equals(a[1]) && a[1].equals(a[2])) {
                System.out.println("Yes");
            } else if (a[1].equals(a[2]) && a[2].equals(a[3])) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }

    }
}



Measured memory_bytes: 21972
#include <stdio.h>

int f(int x){
	int cnt=0;
	
	if(x%100!=0) return 0;
	else {
		while(1){
			x/=100;
			cnt++;
			if(x%100!=0) break;
		}
		return cnt;
	}
}

int main(){
	int i, d, n, cnt=0;
	
	scanf("%d %d", &d, &n);
	
	for(i=1;;i++){
		if(f(i)==d) {
			cnt++;
//			printf("%d %d\n", i, cnt);
		}
		if(cnt==n) break;
	}
	printf("%d", i);
}

Measured memory_bytes: 128
#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>;

vector<vector<int>> MOVE_A = {{0,1},{0,-1},{1,0},{-1,0}};


void bfs(int H, int W, int Sh, int Sw, vector<string> &S, vector<vector<bool>> &visited, queue<pair<int,int>> &now_pos) {
  queue<pair<int,int>> q;
  q.push(make_pair(Sh, Sw));
  int h, w, y, x;
  while (!q.empty()) {
    tie(h, w) = q.front(); q.pop();
    now_pos.push(make_pair(h, w));
    for (auto next: MOVE_A) {
      y = h + next[0];
      x = w + next[1];
      if (y < 0 || H <= y || x < 0 || W <= x) continue;
      if (S[y][x] == '#') continue;
      if (visited[y][x]) continue;
      q.push(make_pair(y, x));
      visited[y][x] = true;
    }
  }
}


void move_b(int H, int W, int Sh, int Sw, vector<string> &S, vector<vector<bool>> &visited, queue<pair<int,int>> &next_pos) {
  int h, w;
  for (int i: {-2, -1, 0, 1, 2}) {
    h = Sh + i;
    if (h < 0 || H <= h) continue;
    for (int j: {-2, -1, 0, 1, 2}) {
      w = Sw + j;
      if (w < 0 || W <= w) continue;
      if (S[h][w] == '#') continue;
      if (visited[h][w]) continue;
      next_pos.push(make_pair(h, w));
      visited[h][w] = true;
    }
  }
}


int main() {
  int H, W, Ch, Cw, Dh, Dw;
  cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  Ch--; Cw--; Dh--; Dw--;
  vector<string> S(H);
  rep(i,H) cin >> S[i];

  int ans = 0;
  vector<vector<bool>> visited(H, vector<bool>(W, false));
  queue<pair<int,int>> now_pos;
  queue<pair<int,int>> next_pos;
  next_pos.push(make_pair(Ch, Cw));
  visited[Ch][Cw] = true;
  int h, w;
  while (true) {
    while (!next_pos.empty()) {
      tie(h, w) = next_pos.front(); next_pos.pop();
      bfs(H, W, h, w, S, visited, now_pos);
    }

    if (visited[Dh][Dw]) break;

    while (!now_pos.empty()){
      tie(h, w) = now_pos.front(); now_pos.pop();
      move_b(H, W, h, w, S, visited, next_pos);
    }
    if (next_pos.empty()) {
      ans = -1;
      break;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5764
from datetime import datetime

H1,M1,H2,M2,K=[int(i) for i in input().split(" ")]

t1=datetime(2020,5,30,H1,M1,0)
t2=datetime(2020,5,30,H2,M2,0)
d=t2-t1
print(d.seconds//60-K)


Measured memory_bytes: 9440
#include <iostream>

using namespace std;

int main() {
    int n, m, l, r;
    int count = 0;

    cin >> n >> m;
    l = 0;
    r = n;

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (a > l) {
            l = a;
        }
        if (b < r) {
            r = b;
        }
    }

    for (int i = 1; i <= n; i++) {
        if (i >= l && i <= r) {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n;
string s;
set <string> ss;
// main solution goes here:
void execute(int test_number)
{
    cin>>n;
    for (int i=1; i<=n; i++) {
        cin>>s;
        ss.insert(s);
    }

    cout<<ss.size();
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

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

using namespace std;

#define ll			long long
#define pb			push_back
#define mp			make_pair
#define fi 			first
#define sec			second

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int x=0,y=0;
	int time1=0;
	int flag=0;
	for(int i=0;i<n;i++)
	{
		int t,a,b;
		cin>>t>>a>>b;
		if(flag==1)
		{
			continue;
		}
		int temp=abs(a-x)+abs(b-y);
		if(temp>(t-time1))
		{
			flag=1;
			continue;
		}
		if(((t-time1)-temp)%2==1)
		{
			flag=1;
			continue;
		}
		time1=t;
		x=a;
		y=b;
		// cout<<flag<<endl;

	}	
	if(flag==1)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
xyc = [list(input().split()) for i in range(n)]
for i in range(n):
  x,y,c = xyc[i]
  x = int(x)
  y = int(y)
  xq = x//k
  yq = y//k
  if (xq+yq)%2:
    if c == "B":
      c = "W"
    else:
      c = "B"
  x %= k
  y %= k
  xyc[i] = x,y,c
gridw = [[0 for i in range(k+1)] for j in range(k+1)]
gridb = [[0 for i in range(k+1)] for j in range(k+1)]
for x,y,c in xyc:
  x += 1
  y += 1
  if c == "B":
    gridb[x][y] += 1
  else:
    gridw[x][y] += 1
for grid in gridb,gridw:
  for i in range(1,k+1):
    for j in range(k+1):
      grid[i][j] += grid[i-1][j]
for grid in gridb,gridw:
  for i in range(k+1):
    for j in range(1,k+1):
      grid[i][j] += grid[i][j-1]
nw = gridw[-1][-1]
nb = gridb[-1][-1]
ans = 0
def sm(grid,i,j):
  return grid[i][j]+grid[-1][-1]-grid[-1][j]-grid[i][-1]+grid[i][j]
for i in range(k+1):
  for j in range(k+1):
    x = sm(gridb,i,j)+nw-sm(gridw,i,j)
    ans = max(ans,x,n-x)
print(ans)

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

int N, X;
int x[1000];

int main() {
    cin >> N >> X;
    int sum = 0;
    int m = 1e9;
    for(int i = 0; i < N; i++) {
        cin >> x[i];
        sum += x[i];
        m = min(m, x[i]);
    }

    cout << N + ((X - sum) / m) << endl;

    return 0;
}

Measured memory_bytes: 256
//“ In order to be irreplaceable, one must always be different”
#include <bits/stdc++.h>
using namespace std;
# define ll long long
#define endl "\n"
# define pi 3.14159265359
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
# define pb push_back
# define popb pop_back
# define pf push_front
# define popf pop_front
# define sll set<ll>
# define schar set<char>
//find()
//erase(x) removes element x
//erase(position,position)
# define qll queue<ll>
# define qstr queue<str>
//front(),back()
# define stll stack<ll>
# define ststr stack<str>
//top()
# define dll deque<ll>
//at()
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define mss map<str,str>
# define mci map<char,ll>
# define vp vector< pair<ll,ll> >
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define fr(x,y,z) for(int x=y;x<z;x++)
# define rr(x,y,z) for(int x=y;x>z;x--)
ll power(ll a , ll b){ll res=1;for(ll i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
vll inp(int n){
    vll a;
    ll x;
    f(i,n){
        cin>>x;
        a.pb(x);
    }
    return a;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    str s;
    cin>>s;
    if(s[3]==s[2] && s[4]==s[5]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}




Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
        
        int smallest = 0;
        int first = scan.nextInt();
      for (int i=1;i<n;i++){
        int next = scan.nextInt();
        if(first<next){
          smallest = next-1;
          first=next;
          continue;
        }else if(first==next){
          continue;
        }else{
          if(first-1>next|| first==smallest){
            System.out.println("No");
            return;
          }
        }
      }
      System.out.println("Yes");
	}
}

Measured memory_bytes: 47072
import math
n = int(input())
ta_li = [list(map(int, input().split())) for _ in range(n)]

def current_result(t, a, x, y):
  #n = max(int(math.ceil(t/x)), int(math.ceil(a/y)))
  #n = max(int((t-1)/x)+1, int((a-1)/y)+1)
  tx, ay = 0, 0
  if t % x == 0:
    tx = t // x 
  else:
    tx = t // x + 1
  if a % y == 0:
    ay = a // y
  else:
    ay = a // y + 1
  n = max(tx, ay)
  return n*x, n*y

if __name__ == "__main__":
  t, a = 1, 1
  for i in range(n):
    x, y = ta_li[i]
    t, a = current_result(t, a, x, y)
  print(t+a)





Measured memory_bytes: 3188
#include <stdio.h>

int main(void) {
	char ch;
	int num,counter[26]={};
	while(scanf("%c",&ch)!= EOF){
		if(ch>='a'&& ch<='z'){
			num = ch -'a';
		}else if(ch>='A'&& ch<='z'){
			num =ch-'A';
		}else{
		continue;
	}
	counter[num]++;
	}
	int i;
	for(i=0;i<26;i++){
		ch ='a'+i;
		printf("%c : %d\n",ch,counter[i]);
	}
	return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll ans = (1LL << 60);
  REP(i, 0, 200001) {
    ll t = C * i + A * max(X - i / 2, 0LL) + B * max(Y - i / 2, 0LL);
    ans = min(ans, t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

int main()
{
	int n,k,ans;
	while(~scanf("%d%d",&n,&k)){
		ans = k;k--;
		for(int i = 2;i <= n;i++) ans *= k;
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int vis[100005];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, ac = 0, pen = 0;
    int x;
    string y;
    cin >> n >> m;
    for ( int i=0; i<m; ++i ) {
        cin >> x >> y;
        if ( vis[x] == -1 )   continue;
        if ( y == "WA" ) {
            vis[x]++;
        } else {
            ac++;
            pen += vis[x];
            vis[x] = -1;
        }
    }
    cout << ac << ' ' << pen << '\n';
    return 0;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
for i in range(N):
    ans += min(A[i], B[i])
    B[i] -= min(A[i], B[i])
    
    ans += min(A[i+1],B[i])
    A[i+1] -= min(A[i+1],B[i])

print(ans)

Measured memory_bytes: 24148
#include <iostream>

enum {X1,Y1,X2,Y2,X3,Y3,X4,Y4};

void calcDistance(int x1, int y1, int x2, int y2, int* dx, int* dy) {
	if(x1 < x2) {
		*dx = x2 - x1;
		*dy = y2 - y1;
	} else {
		*dx = x1 - x2;
		*dy = y1 - y2;
	}
}

int main() {
	int n; std::cin >> n;
	double dp[8];
	int ip[8],dx1,dy1,dx2,dy2;
	for(int i=0; i<n; i++) {
		for(int j=0; j<8; j++) std::cin >> dp[j];
		for(int j=0; j<8; j++) ip[j] = (int)(dp[j] * 1000000);
		if(ip[X1] == ip[X2] || ip[X3] == ip[X4]) {
			if(ip[X1] == ip[X2] && ip[X3] == ip[X4]) {
				std::cout << "YES" << std::endl;
			} else {
				std::cout << "NO" << std::endl;
			}
		} else {
			calcDistance(ip[X1],ip[Y1],ip[X2],ip[Y2],&dx1,&dy1);
			calcDistance(ip[X3],ip[Y3],ip[X4],ip[Y4],&dx2,&dy2);
			if(((long long)dy1 * dx2) == ((long long)dx1 * dy2)) {
				std::cout << "YES" << std::endl;
			} else {
				std::cout << "NO" << std::endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3152
#include<stdio.h>
#define MAX 100000
int partition(int, int);

int n, A[MAX];

int main(){
  int i,q;

  scanf("%d", &n);

  for(i=0;i<n;i++)scanf("%d", &A[i]);
  q=partition(0,n-1);
  
  for(i=0;i<n;i++){ 
    if(i!=q && i!=n-1)printf("%d ", A[i]);
    else if(i==q && i!=n-1)printf("[%d] ", A[i]);
    if(i==n-1)printf("%d", A[i]);
   
  }

  printf("\n");
  return 0;
}


int partition(int p,int r){
  int x, i, j, t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i = i+1;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long  X;
  int N,K;
  cin >> N >> K;
  vector<int> human(N,0);
  int d;
  int result=0;
   
  for(int i=0; i < K ; i++){
    cin >> d;
    for(int j=0; j < d ; j++){
      int tmp;
      cin >> tmp;
      human.at(tmp-1)++;
    }
  }
  for(int i=0; i < N ; i++){
     if(human.at(i)==0){
       result++;
     }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3628
import itertools

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

t = [i for i in range(1,N+1)]
l = list(itertools.permutations(t))

p = 0
q = 0
for i in range(len(l)):
    if P == list(l[i]):
        p = i
    if Q == list(l[i]):
        q = i
        
print(abs(p-q))

Measured memory_bytes: 46064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n;
  cin >> n;

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

  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n * 2; i += 2) {
    ans += l[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;

int main(void)
{
	char a[100], b[100];
	cin >> a;
	int len = strlen(a);
	int j = 0;

	for (int i = 0; i < len; i++)
	{
		if (a[i] == '0'){
			b[j] = '0';
			j++;
		}
		if(a[i] == '1'){
			b[j] = '1';
			j++;
		}
		if(a[i] == 'B'){
			if(j > 0)
				j--;
		}
	}
	for (int i = 0; i < j; i++)
	{
		cout << b[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

# 10000 * x + 5000 * y + 1000 * (N - (x + y)) = Y

ans = [-1, -1, -1]

for i in range(N+1):
  for j in range(N-i+1):
    if 10000 * i + 5000 * j + (N - i - j) * 1000 == Y:
      ans = [i, j, (N-i-j)]
      
print(*ans)
  

Measured memory_bytes: 2940
// abc133c: Remainder Minimization 2019
#include <bits/stdc++.h>
using namespace std;

#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))

int main(){
  int l,r; cin>>l>>r;
  if(r-l>=2019)// 1周すれば余り0となる数が必ずある
    cout<<0<<endl;
  else{
    int a = l%2019;
    int b = r%2019;
    if(a>b) //余りの大小が逆転する間に余り0となる数が必ずある
      cout<<0<<endl;
    else{ // a<=b : この間で最小の数２つをとればよい
      int min = 2018;
      upto(i,a,b,1){
        upto(j,i+1,b+1,1){
          int x = (i*j)%2019;
          if(x==0){
            cout<<0<<endl;
            return 0;
          }
          if(min>x) min = x;
        }
      }
      cout<<min<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;


const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MAXN = 400 + 10;
const ll INF = 1e18;
ll dp[MAXN][MAXN];
ll a[MAXN], n;
int main(){
	IOS;
	memset(dp, 63, sizeof dp);
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++){
		dp[i][i] = 0;
	}
	for (int i = 2; i <= n; i++){
		for (int j = 1; j <= n - i + 1; j++){
			ll Sum = 0;
			for (int k = j; k < j + i - 1; k++){
				dp[j][j + i - 1] = min(dp[j][j + i - 1], dp[j][k] + dp[k + 1][i + j - 1]);
				Sum += a[k];
			}	
			Sum += a[i + j - 1];
			dp[j][j + i - 1] += Sum;
		//	cout << j << ' ' << j + i - 1 << ' ' << dp[j][j + i - 1] << '\n';
		}
	}
	cout << dp[1][n];
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll,P> PP;
int main() {
	int n; cin >> n;
	ll m; cin >> m;
	ll a[100000];
	ll cnt = 0;
	rep(i, n) {
		cin >> a[i];
	}
	ll sum[100001]; sum[0] = 0;
	rep(i, n) {
		sum[i + 1] = (sum[i] + a[i]) % m;
	}
	sort(sum, sum + n + 1);
	ll out = 0;
	rep(i, n + 1) {
		ll chk = i;
		while (i + 1 < n + 1 && sum[i + 1] == sum[i])i++;
		out += (ll)(i - chk+1)*(i - chk) / 2;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<<endl;}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define printpair(v) for(auto val: v){cout<<val.fi<<":"<<val.se<<", ";}cout<<endl;
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define ln length()
const int mod = 998244353;
#define sz size()
const int inf = 1e18;
int n,arr[100005],k;
int dp[100005];
int f(int i){
    if(i==n-1){
        return 0;
    }
    int ans=inf;
    if(dp[i]!=-1){
        return dp[i];
    }
    rep(j,1,k+1) {
        if (i + j <= n - 1) {
            ans = min(ans, f(i + j) + abs(arr[i] - arr[i + j]));
        }
    }
    dp[i]=ans;
    return ans;
}
void solve() {
    clr(dp,-1);
    cin>>n>>k;
    rep(i,0,n){
        cin>>arr[i];
    }
    cout<<f(0)<<endl;
}

int32_t main(){
    fastIO
#ifndef ONLINE_JUDGE
    freopen(R"(C:\Users\swast\CLionProjects\untitled\input.txt)", "r", stdin);
#endif
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 11416
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

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

ll a, b, c, d;
ll cnt(ll x)
{
	ll r, l;
	r = b / x;
	l = (a-1) / x;
	return r - l;
}
void solve()
{
	cin >> a >> b >> c >> d;
	ll sol = 0;
	ll lcm = c * d / (gcd(c, d));
	sol = cnt(c) + cnt(d) - cnt(lcm);
	cout << (b-a+1)-sol;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}


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



int main()
{
	int a ,b ;

	while( scanf( "%d %d" ,&a ,&b ) != EOF )
	{
		char str[ 256 ] ;
		sprintf( str ,"%d" ,a + b ) ;


		printf( "%d\n" ,strlen( str ) ) ;
	}


	return 0 ;
}

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

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

int main() {
  int K, X; cin >> K >> X;
  if (K * 500 >= X) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
  int N; cin>>N;
  int A=N/1000,B=(N%1000)/100,C=((N%1000)%100)/10,D=((N%1000)%100)%10;
  vector<int> SWI(3);
  
  for(int i=0;i<8;i++){
	int rem=i;
    for(int j=2;j>=0;j--){//2^jの位をSWI[j]
      SWI[j]=rem/(int)pow(2,j);
      rem=rem%(int)pow(2,j);
    }//1つのスイッチの状態完成
        
    int tmp=A;
    if(SWI[0]==0) tmp+=B;
    else tmp-=B;
    if(SWI[1]==0) tmp+=C;
    else tmp-=C;
    if(SWI[2]==0) tmp+=D;
    else tmp-=D;
    
    if(tmp==7){
    	printf("%d",A);
      if(SWI[0]==0) printf("+");
      else printf("-");
      printf("%d",B);
      if(SWI[1]==0) printf("+");
      else printf("-");
      printf("%d",C);
      if(SWI[2]==0) printf("+");
      else printf("-");
      printf("%d=7",D);
      break;
    }
  } 
}

Measured memory_bytes: 256
#include<stdio.h>

int S[100000], T[50000], C = 0;

void binarysearch(int,int,int);

int main(){
    //??\???
    int n, q;
    scanf("%d",&n);
    //printf("%d\n",n);
    for(int i = 0; i < n; i++){
        scanf("%d",&S[i]);
        //printf("%d ",S[i]);
    }//S??????????????????????????????
    //printf("\n");
    scanf("%d",&q);
    //printf("%d\n",q);
    for(int j = 0; j < q; j++){
        scanf("%d",&T[j]);
        //printf("%d ",T[j]);
        
    }
    //printf("\n");//T??????????????????????????????
    
   
    for(int k = 0; k < q; k++){
        binarysearch(0,n,T[k]);
    }
    printf("%d\n",C);
    return 0;
}


void binarysearch(left,right,key){
    int mid = (left + right)/2;
    if(left < right){
        if (S[mid] == key){
            //printf("%d ",mid);
            C++;
        }
        else{
            if(S[mid] < key){
                binarysearch(mid+1,right,key);
            }
            else{
                binarysearch(left, mid,key);
            }
        }
    }
}

Measured memory_bytes: 2388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AGC015
{
    public class A
    {
        private void Run()
        {
            var input = Console.ReadLine().Trim().Split();
            var N = long.Parse(input[0]);
            var A = long.Parse(input[1]);
            var B = long.Parse(input[2]);
            Console.WriteLine(Math.Max((B * (N - 1) + A) - (B + A * (N - 1)) + 1, 0));
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new A().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<ctime>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 2e5+7;
const int inf = 1e5;
const int modn = 1e9+7;
const ld eps = 1e-8;
const long double PI = acos(-1.0);
void qRead(ll &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
void qRead(int &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
ll qpow(ll a,ll b,ll mo = modn){
//    printf("%lld\n",mo);
    ll res = 1;
    while(b){
        if(b & 1)res = (res*a) % mo;
        a = (a*a) % mo;
        b >>= 1;
    }
    return res;
}
ld qpow(ld a,ll b){
    ld res = 1;
    while(b){
        if(b & 1)res *= a;
        a = a*a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
//ll vis[maxn],prime[maxn],cnt,smallP[maxn];
//void getPrime(int n){
//    cnt = 0;
//    for(int i = 1;i <= n;i++)vis[i] = 0;
//    for(ll i = 2;i <= n;i++){
//        if(!vis[i]){
//            prime[++cnt] = i;
//            smallP[i] = i;
//        }
//        for(int j = 1;j <= cnt && i*prime[j] <= n;j++){
//            vis[prime[j]*i] = 1;
//            smallP[prime[j]*i] = prime[j];
//            if((i % prime[j]) == 0)break;
//        }
//    }
//}
//ll cnm[maxn][maxn];
//void getCnm(){
//    cnm[0][0] = 1;
//    for(int i = 1;i < maxn;i++){
//        for(int j = 0;j <= i;j++){
//            cnm[i][j] = cnm[i-1][j];
//            if(j)cnm[i][j] += cnm[i-1][j-1];
//            cnm[i][j] %= (modn-1);
//        }
//    }
//}
//ll f[maxn],invF[maxn];
//void getF(){
//    f[0] = invF[0] = 1;
//    for(int i = 1;i < maxn;i++)f[i] = f[i-1]*i % modn;
//    invF[maxn-1] = qpow(f[maxn-1],modn-2);
//    for(int i = maxn-2;i >= 1;i--)invF[i] = invF[i+1]*(i+1) % modn;
//}
ll a[maxn];
int main(){
    int n,mid = -1,k;
    scanf("%d%d",&n,&k);
    for(int i = 1;i <= n;i++){
        scanf("%lld",&a[i]);
        if(a[i] >= 0 && mid == -1)mid = i-1;
    }
    ll ans = 1e18;
    if(mid == -1){
        printf("%lld\n",-a[n-k+1]);
        return 0;
    }
    for(int i = 1;i <= mid;i++){
        if(i + k - 1 <= mid || i+k-1 > n)continue;
        ans = min(ans,-a[i]*2 + a[i+k-1]);
    }
    for(int i = mid+1;i <= n;i++){
        if(i - k + 1 > mid || i-k+1 < 1)continue;
        ans = min(ans,a[i]*2-a[i-k+1]);
    }
    if(mid - k + 1 > 0)ans = min(ans,-a[mid-k+1]);
    if(mid+k <= n)ans = min(ans,a[mid+k]);
    printf("%lld\n",ans);
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using Graph = vector<vector<int>>;

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

    double V = a * a * b;
    double tan_theta;
    if (x >= V / 2)
    {
        tan_theta = 2 * (b / a - x / pow(a, 3));
    } else
    {
        tan_theta = (a * b * b) / (2 * x);
    }
    printf("%.7lf\n", (180 * atan(tan_theta) / M_PI));
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 2e5+10;

int N, Q;
vi adj[MAX], children[MAX];
int X[MAX];

void makeTree(int n, int p) {
    FORE (a, adj[n]) if (a != p) {
        children[n].PB(a);
        makeTree(a, n);
    }
}

void dfs(int n, int v) {
    X[n] += v;
    FORE (c, children[n]) {
        dfs(c, X[n]);
    }
}

void solve() {
    dfs(0, 0);
    REP (i, N) cout << X[i] << ((i == N-1) ? "\n" : " ");
}

int main() {
    cin >> N >> Q;
    REP (i, N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].PB(b);
        adj[b].PB(a);
    }
    makeTree(0, 0);
    REP (q, Q) {
        int p, x; cin >> p >> x;
        X[p-1] += x;
    }
    solve();
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/05/19  Problem: ABC 126 C / Link: http://abc126.contest.atcoder.jp/tasks/abc126_c  ----- */

double  POW(double  x, long long n) {
	double  res = 1;
	while (n > 0) {
		if (n & 1) {
			res = (res*x);
		}
		x = (x*x);
		n >>= 1;
	}
	return res;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N;
	cin >> N;
	LL K; cin >> K;

	auto f = [](int i, LL K) {
		// i*2^ans >=K
		LL two = 1;
		FOR(k, 0, 40) {
			if (i*two >= K) {
				return k;
			}
			two *= 2;
		}
	};
	double ans = 0;
	FOR(i, 1, N + 1) {
		// iがでる
		LL x = f(i, K);
		ans += POW(0.5, x);
	}
	ans /= N;

	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input().strip()


def pon(computer, mine):
    if computer == 'r' and mine == 2: return P
    if computer == 's' and mine == 0: return R
    if computer == 'p' and mine == 1: return S
    return 0


dp = [[0 for _ in range(3)] for _ in range(N+10)]

ans = 0
for st in range(K):
    for i in range(st, N, K):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                if i+1-K >= 0:
                    dp[i+1][k] = max(dp[i+1][k], dp[i+1-K][j] + pon(T[i], k))
                else:
                    dp[i+1][k] = max(dp[i+1][k], pon(T[i], k))
    ans += max(dp[i+1])
print(ans)


Measured memory_bytes: 24444
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0362>
?????????============================================================
 ?????°??°????????????????????????????????????????????§??´??????????¨?????????????????????????
 ?????????????????????????????????????????????????°´?????????????????¶?????¨?????§???????????§?????¢????±??????£???????????????
 ??????????????????????????????????§???????????????¶?????¨?????§?????????????????????????????????????????????????§???£??????????????????
 ???????????°????????????????????????????????????????????????????????§?????£????????????????????????????????????????????????????????¨???????????????
 ??????????????????????????????????????????????????????????????????????????¨?????§????????§???????????????
 
 ???????????????????????§?°´?????????????????¶?????¨?????§???????????§?????¢????????????????????¨??????
 ????????¨???????????????????????§??????????????±?????????????????°????????????????????????
 ???????????????????????????????????§????????????????????¨????????????
=================================================================

?§£??¬=============================================================

================================================================
*/
ll N;
vector<ll> d;
vector<int> used;
bool dfs(int n){
    used[n] = 1;
    for(int i = 1; i <= d[n]/10;i++){
        if(n+i == N - 1) return true;
        if(used[n+i] == 1) continue;
        if(dfs(n+i)) return true;
    }
    return false;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    d.resize(N); used.resize(N);
    for(auto& in:d) cin >> in;
    fill(used.begin(),used.end(),0);
    if(!dfs(0)){
        cout << "no" << endl;
        return 0;
    }
    fill(used.begin(),used.end(),0);
    reverse(d.begin(), d.end());
    if(!dfs(0)){
        cout << "no" << endl;
        return 0;
    }
    cout << "yes" << endl;
	return 0;
}

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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int E=A+B;
  int F=C+D;
  if(E>F)
    cout<<"Left"<<endl;
    else if(E==F)
      cout<<"Balanced"<<endl;
  else
    cout<<"Right"<<endl;
}

Measured memory_bytes: 256
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

int countDifferentChars(string s, string t) {
    const int n = min(s.size(), t.size());

    int count = 0;

    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) count++;
    }

    return count;
}

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

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

    const int n = s.size();
    const int m = t.size();

    int ans = m;

    for (int i = 0; i <= n - m; i++) {
        const string ss = s.substr(i, m);
        const int val = countDifferentChars(ss, t);

        ans = min(val, ans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;

	cin >> N;

	long long mod = pow(10, 9) + 7;

	vector<long long> A(N);

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

	long long count = 0;

	for(int i = 0; i < 62; i++) {
		long long zeros = 0;
		long long ones = 0;
		for(int j = 0; j < N; j++) {
			if(A[j] & (1LL << i)) {
				ones++;
			} else {
				zeros++;
			}
		}

		long long c = (((zeros * ones) % mod) * ((1LL << i) % mod)) % mod;
		count += c % mod;
		count %= mod;
	}

	cout << count << endl;
}


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

typedef pair<int,int> P;

const int N=2e5+5;
const ll INF=numeric_limits<ll>::max();
int n;
P bag[N];
multiset<int> r,b;

ll cost(){
	return 1LL*(*r.rbegin()-*r.begin())*(*b.rbegin()-*b.begin());
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		int x,y;
		cin>>x>>y;
		if(x>y) swap(x,y);
		r.emplace(x);
		b.emplace(y);
		bag[i].first=x;
		bag[i].second=y;
	}
	sort(bag,bag+n);
	ll res=cost();
	for(int i=0;i<n;++i){
		//we will swap color of pair i, in the hope that it could minimize (Rmax-Rmin) by bringing Rmin closer to Rmax
		//the cost function will decrease, then increase back after the breakpoint
		int x=bag[i].first;
		int y=bag[i].second;
		r.erase(r.find(x));
		b.erase(b.find(y));
		r.insert(y);
		b.insert(x);
		res=min(res,cost());
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 23980
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}
 
int main() {
  ll n;
  cin >> n;
  vector<ll> v;
  ll count = 1;
  bool isDesc = false;
  bool isRefreshed = true;
  
  for(ll i=0; i<n; i++){
    ll a;
    cin >> a;
    v.push_back(a);
  }
  
  for(ll i=0; i<n-1; i++){
    bool tempIsDesc;
    if (v.at(i) == v.at(i+1)) continue;

    if (isRefreshed) {
      isRefreshed = false;
      isDesc =  v.at(i) < v.at(i+1);
      continue;
    }

    if ( isDesc != (v.at(i) < v.at(i+1)) ) {
      isRefreshed = true;
      isDesc = v.at(i) < v.at(i+1);
      count++;
    }
    
  }
  cout << count;
  
}

Measured memory_bytes: 1400
import java.util.*;
import java.lang.*;
class Main {
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		int[] count=new int[t+1];
		for (int i=2;i<t+1;i++) {
			count[sc.nextInt()]++;
		}
		for (int i=1;i<t+1 ;i++ ) {
			System.out.println(count[i]);
		}
	}
}

Measured memory_bytes: 61160
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  vector<bool> prime(55556, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= 55555; ++i) {
    if(!prime[i]) continue;
    for (int j = 2; i * j <= 55555; ++j) {
      prime[i * j] = false;
    }
  }
  int N;
  cin >> N;
  for (int i = 2; i <= 55555 && N; ++i) {
    if (prime[i] && ((i % 5) == 1)) {
      cout << i << " ";
      --N;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{
    int a,b;

    scanf("%d %d",&a,&b);
    if (a>=13)
        b=b;
    else if (a>=6 && a<=12)
        b=b/2;
    if (a<=5)
        b=0;

    printf("%d",b);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;



int main(){
    int ans=0;
    
    int N;
    cin >> N;
    ll A[N];
    for(int i=0; i<N; i++){
        cin>>A[i];
    }
    
    sort(A,A+N);
    
    map<ll, int> m;
    for(int i=0; i<N; i++){
        if(i==0 || A[i]!=A[i-1]){
            m.insert(make_pair(A[i],0));
        }
    }
    
    for(int i=0; i<N; i++){
        m[A[i]]++;
    }
    

    
    for(int i=N-1; i>=0; i--){
        if(m[A[i]]>0){
            ll x=2;
            while(x<=A[i]){
                x*=2;
            }
            
            ll b=x-A[i];
            
            if(m.count(b)>0){
                if(A[i]==b){
                    if(m[A[i]]>=2){
                        ans++;
                        m[A[i]]-=2;
                    }
                }else if(m[b]>0){
                    ans++;
                    m[A[i]]--;
                    m[b]--;
                }
            }
            
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 14336
def f(x): return int(x/2) if x % 2 == 0 else (3*x + 1)

s = int(input())
a = set([s])
i = 1

while True:
    s = f(s)
    i += 1

    if s not in a:
        a.add(s)

    else:
        print(i)
        break



Measured memory_bytes: 2940