akhauriyash/Code-Regression huggingface dataset:
str = gets.split
H,W,K = str[0].to_i, str[1].to_i, str[2].to_i
s = Array.new(H){Array.new(W)}
t = Array.new(H)

for i in 0...H do
    str = gets.chomp
    a = 0
    for j in 0...W do
        s[i][j] = str[j]
        if s[i][j] == "#"
            a += 1
        end
        t[i] = a
    end
end

start = 0
i = 0
while t[i] == 0
    start += 1
    i += 1
end

n = 0
for i in start...H do
    if t[i] == 0
        for j in 0...W do
            s[i][j] = s[i-1][j]
        end
    else
        m = 0
        n += 1
        for j in 0...W do
            if s[i][j] == "#"
                m += 1
                if m > 1
                    n += 1
                end
            end
            s[i][j] = n
        end
    end
end

for i in 0...start do
    for j in 0...W do
        s[i][j] = s[start][j]
    end
end

for i in 0...H do
    for j in 0...W do
        print s[i][j]," "
    end
    puts
end

Measured memory_bytes: 9724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=210;
vector<int>g[mn];
int lev[mn];
int main()
{
    cin.tie(0);

    cin.sync_with_stdio(0);
    int n,i,j;
    string s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s;
        for(j=0;j<n;j++){
            if(s[j]=='1'){
                g[i].push_back(j);
            }
        }
    }
    int ans=-1;
    for(i=0;i<n;i++){
        bool fail=0;
        memset(lev,0,sizeof(lev));
        queue<int>q;
        q.push(i);
        lev[i]=1;
        while(q.size()){
            int x=q.front();
            q.pop();
            for(int y:g[x]){
                if(lev[y]&&lev[y]!=lev[x]-1&&lev[y]!=lev[x]+1)fail=1;
                else if(!lev[y]){
                    lev[y]=lev[x]+1;
                    q.push(y);
                }
            }
        }
        if(!fail)for(j=0;j<n;j++)ans=max(ans,lev[j]);
    }
    printf("%d",ans);
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <numeric>
#include <iterator>
#include <istream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    size_t n;
    cin >> n;
    vector<int> a;
    a.reserve(n + 2);
    a.push_back(0);
    copy(istream_iterator<int>(cin), istream_iterator<int>(), back_inserter(a));
    a.push_back(0);
    vector<int> c(a.size());
    adjacent_difference(begin(a), end(a), begin(c), [](int x, int y){
        return abs(x - y);
    });
    auto total = accumulate(begin(c), end(c), 0);
    for (size_t i = 1; i < a.size() - 1; ++i) {
        cout << total + abs(a[i - 1] - a[i + 1]) - (c[i] + c[i + 1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(check(s)) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
	}

	private static boolean check(String s) {
		char odd = 'L';
		char even = 'R';
		for(int i = 1; i < s.length() + 1; i++) {
			char tmp = s.charAt(i - 1);
			if( i % 2 == 0) {
				if(tmp == even) {
					return false;
				}
			} else {
				if(tmp == odd) {
					return false;
				}
			}
		}
		return true;
	}
}

Measured memory_bytes: 21716
#include <stdio.h>

int main() {
    unsigned int a;
    int b;
    int d,r;
    double f;
    scanf("%d%d",&a,&b);
    d = a/b;
    r = a%b;
    f = (double)a/b;
    
    printf("%d %d %.5lf\n",d,r,f);
    return 0;
}

Measured memory_bytes: 1068
N = gets.to_i

h = Hash.new 0
ans = 0
(1..N).each{|i|
  l = "#{i}"[0].to_i
  r = "#{i}"[-1].to_i
  next if r == 0
  h[[l, r]] += 1
  ans += h[[r, l]] * 2
  ans -= 1 if r == l
}
p ans

Measured memory_bytes: 1788
#include<cstdio>

int main(int argc, char const *argv[]) {
    int a,b,c,d,e,f;
    scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d);
    if(a<b){
        e=a;
    }else{
        e=b;
    }
    if(c<d){
        f=c;
    }else{
        f=d;
    }
    printf("%d",e+f);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int a,b;
il int Gcd(int a,int b){int t;
	while(b) t=b,b=a%b,a=t;
	return a;
}
int main(){
	a=rd(),b=rd();
	printf("%lld",1ll*a*b/Gcd(a,b));
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
int n,a[100002],b,head[10002],cnt,ans,m,x,k,d;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
signed main(){
	scanf("%lld%lld%lld",&x,&k,&d);
	if(x<0)x=-x;
	if(x/d>=k)printf("%lld",x-d*k);
	else{
		k-=x/d;
		x%=d;
		printf("%lld",k&1?d-x:x);
	}
}


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

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

Measured memory_bytes: 256
from collections import Counter
lst=[]
for i in range(int(input())):
    lst.append(input())
dic=Counter(lst)
lst=dic.most_common()
lst2=[]
for i in lst:
    if i[1]==lst[0][1]:
        lst2.append(i[0])
lst2.sort()
for i in lst2:
    print(i)

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

int N, M, Q, L[200005], R[200005], X[505][505], C[505][505];

int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) C[i][j] = C[i][j - 1] + X[i][j];
	}
	for (int i = 1; i <= Q; i++) {
		int p, q; cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; j++) sum += C[j][q] - C[j][p - 1];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int map[60][60];
	int h, w; cin >> h >> w;
	for (int i = 0; i < h; i++) {
		char s[60]; cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '0')map[i][j] = 0;
			else if (s[j] == '1')map[i][j] = 1;
			else if (s[j] == '2')map[i][j] = 2;
			else if (s[j] == '3')map[i][j] = 3;
			else if (s[j] == '4')map[i][j] = 4;
			else if (s[j] == '5')map[i][j] = 5;
			else if (s[j] == '6')map[i][j] = 6;
			else if (s[j] == '7')map[i][j] = 7;
			else if (s[j] == '8')map[i][j] = 8;
			else if (s[j] == '9')map[i][j] = 9;
		}
	}
	int ans[60][60] = {};
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i == 0 && j == 0)ans[i][j] = map[i][j];
			else if (i == 0)ans[i][j] = map[i][j] + ans[i][j - 1];
			else if (j == 0)ans[i][j] = map[i][j] + ans[i - 1][j];
			else ans[i][j] = map[i][j] + min(ans[i - 1][j], ans[i][j - 1]);
		}
	}
	cout << ans[h - 1][w - 1] << endl;
}

Measured memory_bytes: 3128
#include <iostream>
#include <cstring>
using namespace std;
int n,sum=0;
int main()
{
	cin>>n;
	for(int i=0;i<40;i++)
	{
		sum++;
		int num=0;
		bool pd=false;
		for(int j=0;j<25;j++)
		{
			num=0;
			num=4*i+7*j;
			if(num==n)
			{
					pd=true;
					break;
			}
		}
		if(pd)
		break;
	}
	if(sum==40)
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
}


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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define M 100001
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define lp(i,a,b) for(i=a;i<b;i++)
#define lpr(i,a,b) for(i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main(){

	/*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/

	fast;  
  int i,j,n,k;
  cin>>n>>k;
  
  int ns=n;
  string s="";
  while(n!=0){
    s+=n%k;
    n=n/k;
  }
  cout<<s.size()<<endl;


	return 0;
}


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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int x, y, b, p;
    cin >> x >> y >> b >> p;
    int ans = 1 << 20;
    for (int j = 0; j <= 6; j++) {
      for (int k = 0; k <= 6; k++) {
        if (j < b || k < p) continue;
        int sum = j * x + k * y;
        if (j >= 5 && k >= 2) sum = sum * 4 / 5;
        ans = min(ans, sum);
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		if(a <= 0 && 0 <= b) {
			System.out.println("Zero");
		}else if(0 < a && 0 < b) {
			System.out.println("Positive");
		}else {
			if((Math.abs(a)-Math.abs(b)+1) % 2 == 0) {
				System.out.println("Positive");
			}else {
				System.out.println("Negative");
			}
		}
	}
}


Measured memory_bytes: 9684
while 1:
    b,r,g,c,s,t=map(int,input().split())
    if [b,r,g,c,s,t].count(0)==6:break
    print(100+(b+r)*15+g*7+c*2+(b*5+r*3)*13-(t-(s+b*5+r*3))*3)

Measured memory_bytes: 7612
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main()
{
    string str;
    string target = "keyence";

    cin >> str;
    if(str==target){
        puts("YES");
        return 0;
    }

    int len=str.size();
    REP(i,len){
        FOR(j,i,len){
            string S = "";
            REP(k,len){
                if(i<=k and k<=j) continue;
                else S.push_back(str[k]);
            }
            if (S == target)
            {
                puts("YES");
                return 0;
        }

        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(){
    int n;

    scanf("%d", &n);

    int min = 1000000;
    int max = -1000000;
    long int sum = 0;

    int l[n];
    for (int i=0; i<n; i++){
        scanf("%d", &l[i]);
        if (min > l[i]){
            min = l[i];
        }
        if (max < l[i]){
            max = l[i];
        }

        sum += l[i];
    }

    printf("%d %d %ld\n",min , max, sum);

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }

class Point {
public:
  ld x, y;

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

  Point operator + (const Point &p) {
    return Point(x + p.x, y + p.y);
  }
  Point operator - (const Point &p) {
    return Point(x - p.x, y - p.y);
  }
  Point operator * (const ld k) {
    return Point(x * k, y * k);
  }
  Point operator / (const ld k) {
    return Point(x / k, y / k);
  }
  Point operator += (const Point &p) {
    x += p.x;
    y += p.y;
    return *this;
  }
  Point operator -= (const Point &p) {
    x -= p.x;
    y -= p.y;
    return *this;
  }
  Point operator *= (const ld k) {
    x *= k;
    y *= k;
    return *this;
  }
  Point operator /= (const ld k) {
    x /= k;
    y /= k;
    return *this;
  }
  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point &p) const {
    return equals(x, p.x) && equals(y, p.y);
  }
  friend ostream& operator << (ostream &os, const Point &p) {
    os << p.x << ' ' << p.y;
    return os;
  }
  friend istream& operator >> (istream &is, Point &p) {
    ld x, y;
    is >> x >> y;
    p = Point(x, y);
    return is;
  }

  ld abs() {return sqrt(norm());}
  ld norm() {return x * x + y * y;}
};

ld dot(Point a, Point b) {
  return a.x * b.x + a.y * b.y;
}

ld cross(Point a, Point b) {
  return a.x * b.y - a.y * b.x;
}

class Segment {
public:
  Point p1, p2;

  Segment() {}
  Segment(Point p1, Point p2): p1(p1), p2(p2) {}
};

class Circle {
public:
  Point p;
  ld r;

  Circle() {}
  Circle(Point p, ld r): p(p), r(r) {}
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int q;
  cin >> q;
  Point p[4];
  while (q--) {
    rep(i, 4) cin >> p[i];
    if (equals(cross(p[1] - p[0], p[3] - p[2]), 0)) cout << 2 << '\n';
    else if (equals(dot(p[1] - p[0], p[3] - p[2]), 0)) cout << 1 << '\n';
    else cout << 0 << '\n';
  }

  

  
  return 0;
}


Measured memory_bytes: 3292
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

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

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


# ===CODE===

def main():
    n, m = ns()
    e = [[] for _ in range(n)]
    for _ in range(m):
        a, b = ns()
        e[a - 1].append(b - 1)

    res = [-1 for _ in range(n)]

    def dfs(ti):
        tmp = 0
        for vi in e[ti]:
            if res[vi] != -1:
                tmp = max(tmp, res[vi] + 1)
            else:
                tmp = max(tmp, dfs(vi) + 1)
        res[ti] = tmp
        return tmp

    ans = 0
    for i in range(n):
        if res[i] == -1:
            ans = max(ans, dfs(i))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 116792
#include <bits/stdc++.h>
using namespace std;
#define fori(i, S, E) for (int i = S; i < E; i++)

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

    vector<int> balls (N);
    unordered_map<int, int> numbers;
    fori(i, 0, N) {
        cin >> balls[i];
        numbers[balls[i]]++;
    }

    long count = 0;
    for (auto p: numbers) {
        long n = p.second;
        count += 1L * n * (n - 1) / 2;
    }

    fori(k, 0, N) {
        int n = numbers[balls[k]];
        cout << (count - (n - 1)) << "\n";
    }
}

Measured memory_bytes: 8392
import std.stdio, std.string, std.conv;

void main() {
    int n = readln.chomp.to!int;
    int[] fib = new int[n+1];
    fib[0] = fib[1] = 1;
    foreach (i; 2 .. n+1) {
        fib[i] = fib[i-1] + fib[i-2];
    }
    fib[n].writeln;
}


Measured memory_bytes: 2456
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, h = MII()
    attacks = [MII() for _ in range(n)]
    max_a = sorted(attacks)[-1][0]
    bb = [a[1] for a in attacks if a[1] > max_a]
    bb.sort(reverse=True)
    total_b = sum(bb)
    if total_b >= h:
        cnt = 0
        for i, b in enumerate(bb):
            cnt += b
            if cnt >= h:
                print(i+1)
                return None
    d = h - total_b
    cnt = DIVC(d, max_a)
    print(cnt + len(bb))

if __name__ == '__main__':
    main()

Measured memory_bytes: 28524
#include  <iostream>

using namespace std;

int main()
{
	int result(0), tmp;
	
	for (int i(0); i < 5; i++)
	{
		cin >> tmp;
		if (tmp < 40) { tmp = 40; }
		
		result += tmp / 5;
	}
	
	cout << result << endl;
}

Measured memory_bytes: 3068
x, y = map(int, input().split())
ans = 0
m = [300000, 200000, 100000]
if x <= 3:
    ans += m[x - 1]
if y <= 3:
    ans += m[y - 1]
if x == 1 and y == 1:
    ans += 400000

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
int main()
{
    int n;
    cin >> n;
    vi v(n);
    int cc = 0;
    rep(i, n)
    {
        cin >> v[i];
        if (v[i] < 0)
        {
            cc++;
        }
    }
    lint ans = 0;
    if (cc % 2 == 0)
    {
        rep(i, n)
        {
            ans += abs(v[i]);
        }
    }
    else
    {
        int index;
        int min = 1 << 20;
        rep(i, n)
        {
            if (min > abs(v[i]))
            {
                index = i;
                min = abs(v[i]);
            }
        }
        rep(i, n)
        {
            if (i != index)
            {
                ans += abs(v[i]);
            }
            else
            {
                ans -= abs(v[i]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

/*高速化*/
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* define */
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)

/* 最大値と最小値に置き換える */
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}


/* 型定義 */
typedef vector<long long> vi;
typedef long long ll;
using Graph = vector<vi>;


/* 定数 */
const double PI = 3.141592;
const double e = 2.6;
const long long Inf = 1LL << 60;
const long long mInf = -Inf;


void calc()
{
    long long N;
    cin >> N;
    long long a,b;
    long long res = 1LL << 60;
    for(long long i = 1;i * i <= N;i++)
    {
        if(N % i == 0)
        {
            a = i;
            b = N / i;
            res = min(res,a + b - 2);
        }
    }
    cout << res << '\n';
}


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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  string S;
  cin >> S;
  int N = S.size();
  
  string S1 = S.substr(0, (N-1)/2);
  string S2 = S.substr((N+3)/2 - 1, (N-1)/2);
  
  bool res = true;
  
  rep(i, (N-1)/2) {
    if(S.at(i) != S.at(N-1-i)) res = false;
  }
  
  rep(i, S1.size()/2) {
    if(S1.at(i) != S1.at(S1.size()-1-i)) res = false;
  }
  
  rep(i, S2.size()/2) {
    if(S2.at(i) != S2.at(S2.size()-1-i)) res = false;
  }
  
  if(res) cout << "Yes";
  else cout << "No";
  
  cout << endl;
  //cout << S1 << endl;
  //cout << S2 << endl;
  
}

Measured memory_bytes: 256
# coding: utf-8

a, b, m = map(int, raw_input().split())
al = map(int, raw_input().split())
bl = map(int, raw_input().split())
mls = [map(int, raw_input().split()) for _ in xrange(m)]

minp = min(al) + min(bl)

for xi, yi, ci in mls:
    p = al[xi - 1] + bl[yi - 1] - ci
    minp = min(minp, p)

print minp




Measured memory_bytes: 27148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}



int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(184);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  rep(d,D){
    rep(q,26){
      if(chmax(now,calc(t,d,q))){
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d=mt()%365, q=mt()%26;
    if(chmax(now,calc(t,d,q))){
      t[d]=q;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3688
import java.util.*;

class Main 
{ 
  public static void main(String[] args)
  {
	Scanner sc=new Scanner(System.in);
	String input=sc.nextLine();
	String[] inputArray =input.split(" ");
	
	if(inputArray.length==2)
	{
		int a = Integer.parseInt(inputArray[0]);  
    	int b = Integer.parseInt(inputArray[1]);
		
		if(a<b)
		{
			System.out.println("a < b");
		}
		
    	else if(a>b)
      	{
	    	System.out.println("a > b");
	    }
	    
	    else if(a == b)
	    {
	    	System.out.println("a == b");
	    }
	}
  }
}

Measured memory_bytes: 26036
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#define PI 3.141592653589
typedef long long ll;
const int MOD = 1000000007;
const int INF = 2002002002;
const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
using namespace std;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a)
		cout << k << endl;
	else if (k <= a + b)
		cout << a << endl;
	else
		cout << a - (k - a - b) << endl;
	return 0;
}


Measured memory_bytes: 3592
N = int(input())
S = input()

codes = []

henkan = []

s = ""

for i in range(len(S)):
    codes.append(ord(S[i])-ord("A"))

for i in range(len(S)):
    henkan.append((codes[i] + N)%26 + ord("A"))

for i in range(len(S)):
    s += chr(henkan[i])

print(s)




Measured memory_bytes: 41964
#include <bits/stdc++.h>
using namespace std;
int main(){
	int D; cin >> D; 
	int C[30] = {}; 
	for(int i = 1; i <= 26; i++) cin >> C[i]; 
	int S[370][30] = {}; 
	for(int i = 1; i <= D; i++){
		for(int j = 1; j <= 26; j++){
			cin >> S[i][j]; 
		}
	}
	int T[370] = {}; 
	for(int i = 1; i <= D; i++) cin >> T[i]; 
	int ans[370] = {}; 
	int L[30] = {}; 
	for(int i = 1; i <= D; i++){
		int E[30] = {}; 
		for(int j = 1; j <= 26; j++){
			E[j] = S[i][j] - C[j] * (i - L[j]); 
		}
		int a = 0; int mx = -1145141919; 
		for(int j = 1; j <= 26; j++){
			if(E[j] > mx){
				a = j; mx = S[i][j]; 
			}
		}
		ans[i] = a; L[a] = i; 
	}
	for(int i = 1; i <= D; i++) cout << ans[i] << endl; 
}

Measured memory_bytes: 3680
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
 
from fractions import gcd
 
def lcm(a,b):
    return a//gcd(a,b)*b

AA = 1
for i in range(N):
    AA = lcm(AA,A[i])
AA %= mod

ans = 0
for i in range(N):
    ans += AA*pow(A[i],mod-2,mod)
    
print(ans%mod)

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e15);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
std::string s;
int main()
{
	std::cin >> n >> s;

	int num = 0;
	for (int i = 0; i < n; ++i)
		if (s[i] == 'R')
			++num;

	if (num > n - num)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
ll MOD=1e9+7;

ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%13;
        a=a*a%13;
        x>>=1;
    }
    return res;
}

int main(){
    int n;cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=1;
    for(int i=0;i<n;i++){
        if(a[i]<=(ll)1e18/ans){
            ans*=a[i];
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    bool flag = true;
    
    if(N == 2){
      cout << N << endl;
      return 0;
    }

    while(flag){
        for(int j = 2; j<= N/2; j++){
            if(N%j == 0){
                N++;
                break;
            }
            if(j == N/2){
                flag = false;
            }
        }
    }

    cout << N << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			
			
			//System.out.println("test");
	
			int num = Integer.parseInt(br.readLine());
			//System.out.println("num = "+num);
			if(num == 0){
				
				break;
			}
			int[] cardsA = new int[num];
			int[] cardsB = new int[num];
			Player playerA = new Player();
			Player playerB = new Player();
	
			//input
			for(int i = 0; i < num ; i++){
				String[] tmpStr = br.readLine().split(" ");
				cardsA[i] = Integer.parseInt(tmpStr[0]);
				cardsB[i] = Integer.parseInt(tmpStr[1]);
			}
	
			//judge
			for(int i = 0; i < num; i++){
				if(cardsA[i] > cardsB[i]){
					playerA.addPoint(cardsA[i]+cardsB[i]);
				}
				else if(cardsA[i] < cardsB[i]){
					playerB.addPoint(cardsA[i]+cardsB[i]);
				}
				else{
					playerA.addPoint(cardsA[i]);
					playerB.addPoint(cardsB[i]);
				}
			}
	
			System.out.println(playerA.getPoint()+" "+playerB.getPoint());
		}
	}
}

class Player{
	private int point = 0;

	public void addPoint(int p){
		point += p;
	}

	public int getPoint(){
		return point;
	}
}

Measured memory_bytes: 36904
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    ll X;
    cin>>X;
    ll now=100;
    int ans=0;
    while(now<X){
        ans++;
        now+=now/100;
    }
    cout<<ans<<endl;
}

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


int main(){
  int n; cin >> n;
  vector<int> av(n), bv(n), p(n), av2(n), bv2(n);
  for(int i=0; i<n; ++i){
    cin >> av[i] >> bv[i];
  }
  iota(p.begin(), p.end(), 0);
  sort(p.begin(), p.end(), [&](int a, int b) { return bv[a] < bv[b]; });
  for (int i = 0; i < n; i++) {
    av2[i] = av[p[i]];
    bv2[i] = bv[p[i]];
  }
  av = av2;
  bv = bv2;
  int sum=0;
  for(int i=0; i<n; ++i){
    sum+=av[i];
    if(bv[i]<sum){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

const ll INF=1e18;
ll n,a,b,c,d;
map<ll,ll>mp;

ll dfs(ll x){
  if(x==0)return 0;
	if(x==1)return d;
  if(mp.find(x)!=mp.end())return mp[x];
  ll res=INF;
  if(x<=INF/d)res=x*d;
  res=min(res,dfs(x/2)+a+(x%2)*d);
  res=min(res,dfs(x/3)+b+(x%3)*d);
  res=min(res,dfs(x/5)+c+(x%5)*d);
  if(x!=2)res=min(res,dfs(x/2+1)+a+(2-x%2)*d);
  res=min(res,dfs(x/3+1)+b+(3-x%3)*d);
  res=min(res,dfs(x/5+1)+c+(5-x%5)*d);
  return mp[x]=res;
}

void solve(void){
  mp.clear();
  cin>>n>>a>>b>>c>>d;
  cout<<dfs(n)<<endl;
}

int main(){
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4796
N=int((input()))

data=[]
for _ in range(N):

    S,P=input().split()
    data.append([_+1,S,int(P)])
    data.sort(key=lambda x:x[2])
    data.reverse()
    data.sort(key=lambda x:x[1])

for i,S,P in data:
    print(i)


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

int main(){
  int n, i, j;
  int r[200]={ };
  int p[200][3],s[101][3]={ };

  cin >> n;
  for (i=0; i<n; i++){
    for (j=0; j<3; j++){
      cin >> p[i][j];
      s[p[i][j]][j]++;
      
      // cout << i << " " << j << " " <<  s[p[i][j]][j] << endl;
      
    }
  }

  for (i=0; i<n; i++){
    for (j=0; j<3; j++){
      // cout << i << " " << j << " " << s[p[i][j]][j] << endl;
      if (s[p[i][j]][j]==1){
	r[i]+=p[i][j];
      }
    }
    cout << r[i] << endl;
  }

  return 0;

}

Measured memory_bytes: 3092
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(n%2==1){
    cout << "No";
  }
  else{
    int i;
    for( i=0;i<n/2;i++){
      if(s[i]!=s[n/2+i]){
        cout << "No";
        break;
      }
    }
    if(i==n/2){
      cout << "Yes";
    }
  }
  return 0;
}
    
      
        

Measured memory_bytes: 256
def factorization(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            retlist.append([i, cnt])

    if temp!=1:
        retlist.append([temp, 1])

    if retlist==[]:
        retlist.append([n, 1])

    return retlist

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

n,p=map(int,input().split())
l=factorization(p)
l.sort(key=lambda x: x[1])
ans=1
for ll in l:
    ans*=ll[0]**(ll[1]//n)
print(ans)



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int a,b,k;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b>>k;
	for(int i=1000;i>=1;i--){
		if((a%i==0)&&(b%i==0)){
			k--;
			if(k==0){
				cout<<i<<endl;
				return 0;
			}
		}
	}
	return 0;
}



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

using namespace std;

using int64 = long long;

int main()
{
  int64 N, A[100000], B[100000];

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

  // 後ろから要素を見ていきたい気持ちになる
  int64 ret = 0, preadd = 0;
  for(int i = N - 1; i >= 0; i--) {
    A[i] += preadd;
    auto need = (B[i] - A[i] % B[i]) % B[i];
    preadd += need;
    ret += need;
  }

  cout << ret << endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

#define BIT_N 333
typedef long long ll;
typedef pair<ll,ll> P;
typedef bitset<BIT_N> Bit;
vector<int> baseNum;

ll pow_two[BIT_N];

vector<Bit> gauss(vector<Bit> &v, ll &ran){
	ran = 0;
	REP(i,BIT_N) {
		int pla = -1;
		for(int j = ran;j < v.size();j++){
			if(v[j][i] == 1){
				pla = j;
				break;
			}
		}
		
		if(pla != -1){
			swap(v[ran], v[pla]);
			for(int j = 0;j < v.size();j++){
				if(j != ran && v[j][i] == 1)v[j] ^= v[ran];
			}
			ran++;
		}
	}
	return v;
}

int main(){
	fastcin();
	
	pow_two[0] = 1;
	REP(i,BIT_N - 1)pow_two[i+1] = pow_two[i] * 2 % MOD;
	
	vector<Bit> v;
	ll n, m;cin >> n >> m;
	REP(i,n){
		Bit now;
		REP(j,m){
			int a;cin >> a;
			if(a)now[j] = 1;
		}
		v.PB(now);
	}
	
	ll ran = 0;
	ll ans = 0;
	gauss(v, ran);
	
	cout << ((pow_two[n] - pow_two[n - ran] + MOD) % MOD) * pow_two[m-1] % MOD << endl;
	
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, raw_input().split())
D = map(int, raw_input().split())
W = filter(lambda x: not x in D, range(10))
def dfs(x):
    if x >= N:
        return x
    return min([dfs(10*x + d) for d in W])
print min([dfs(i) for i in W if (i > 0)])

Measured memory_bytes: 2568
#include <stdio.h>
int main(void){
   int a,b,c;
   scanf("%d %d %d", &a, &b, &c);
   
   if(b>c&&c>a){
       printf("Yes");
   } else if(a>c && c>b){
       printf("Yes");  
   } else {
       printf("No");
   }
    
    return 0;
}


Measured memory_bytes: 128
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use std::cmp::min;

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize,
    mut h: [usize; n]
    }
    h.sort();
    let mut ans = std::usize::MAX;
    for i in k - 1..n {
        ans = min(ans, h[i] - h [i + 1 - k]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4228
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, d = map(int, input().split())
xy = []
for _ in range(n):
    xy.append([int(x) for x in input().split()])
cnt = 0
for x, y in xy:
    if x**2 + y**2 <= d**2:
        cnt += 1
print(cnt)

Measured memory_bytes: 100352
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{	
	int K, X;
	cin >> K >> X;
	for (int i = X - K + 1; i < X + K; i++) {
		cout << i << " ";
	}
}

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

using namespace std;

typedef long long ll;

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

	int r, g;
	cin >> r >> g;

	cout << 2 * g - r << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector <int> cnt(1e5 + 2);
    forn (i, 0, n) {
        int x;
        cin >> x;
        cnt[x]++;
    }
    long long s = 0;
    forn (i, 0, sz(cnt))
        s += 1LL * i * cnt[i];
    int q;
    cin >> q;
    while (q --> 0) {
        int b, c;
        cin >> b >> c;
        s -= 1LL * b * cnt[b];
        s += 1LL * c * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << s << "\n";
    }
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
    string s;
    cin >> n >> s;
    if(n%2!=0){
      cout << "No" << endl;
      return 0;
    }
    string str_1 = s.substr(0,n/2);
    string str_2 = s.substr(n/2,n/2);
    if (str_1 == str_2){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  } 

Measured memory_bytes: 256
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <stdlib.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){
    ll n;
    cin >> n;
    vector<ll> vec(n+1);
    vec[0] = 0;
    for(ll i=0;i<n;i++){
        cin >> vec[i+1];
    }
    if(n == 1){
        if(vec[1] == 1){
            cout << 1 << endl << vec[1] << endl;
            return 0;
        }
        else{
            cout << 0 << endl;
            return 0;
        }
    }
    vector<ll> b(n+1);

    ll cnt = 0;

    for(ll i=n;i>n/2;i--){
        b[i] = vec[i];
        if(b[i] == 1) cnt++;
    }
    ll tmp = 0;

    for(ll i=n/2;i>1;i--){
        tmp = 0;
        for(ll j=2;i*j<=n;j++){
            tmp += b[i*j];
        }
        if(tmp%2 != vec[i]){
            cnt++;
            b[i] = 1;
        }
        else{
            b[i] = 0;
        }
    }

    ll sum = 0;
    ll sum1 = 1;

    for(ll i=2;i<=n;i++){
        sum += b[i];
        sum1 += b[i];
    }

    if(sum%2 == vec[1]){
        cout << cnt << endl;
        for(ll i=2;i<=n;i++){
            if(b[i] == 1){
                cout << i << " ";
            }
        }
        cout << endl;
    }
    else if(sum1%2 == vec[1]){
        cout << cnt+1 << endl;
        cout << 1 << " ";
        for (ll i = 2; i <= n; i++)
        {
            if (b[i] == 1)
            {
                cout << i << " ";
            }
        }
        cout << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3968
# -*- coding: utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    a = list(map(float, input().split()))

    mean = sum(a) / n

    dist = [0. for _ in range(n)]
    for i in range(n):
        dist[i] = abs(a[i] - mean)

    print(dist.index(min(dist)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,x) for (register int (i)=(1);(i)<=(x);(i)++)
#define repd(i,x) for (register int (i)=(x);(i)>=(1);(i)--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
using namespace std;
const ll inf=0x1212121212121212ll;
ll n,m,i,j;
ll mi[400005],tag[400005];
struct eee
{
	ll l,r,c;
}a[100005];
bool cmp(eee x,eee y){return x.l<y.l;}
void build(ll x,ll l,ll r)
{
	tag[x]=inf;
	if(l==r){if(l==1)mi[x]=0;else mi[x]=inf;return;}
	int mid=(l+r)/2;build(x+x,l,mid);build(x+x+1,mid+1,r);
	mi[x]=min(mi[x+x],mi[x+x+1]);
}
void upd(ll x,ll y)
{
	mi[x]=min(mi[x],y);
	tag[x]=min(tag[x],y);
}
void pushdo(ll x)
{
	if(tag[x]!=inf){
		upd(x+x,tag[x]);
		upd(x+x+1,tag[x]);
		tag[x]=inf;
	}
}
void update(ll x,ll l,ll r,ll ql,ll qr,ll c)
{
	if(ql<=l&&r<=qr){upd(x,c);return;}
	int mid=(l+r)/2;pushdo(x);
	if(ql<=mid)update(x+x,l,mid,ql,qr,c);
	if(qr>mid)update(x+x+1,mid+1,r,ql,qr,c);
	mi[x]=min(mi[x+x],mi[x+x+1]);
}
ll query(ll x,ll l,ll r,ll ql,ll qr)
{
	if(ql<=l&&r<=qr)return mi[x];
	int mid=(l+r)/2;pushdo(x);
	if(qr<=mid)return query(x+x,l,mid,ql,qr);
	if(ql>mid)return query(x+x+1,mid+1,r,ql,qr);
	return min(query(x+x,l,mid,ql,qr),query(x+x+1,mid+1,r,ql,qr));
}
int main()
{
	scanf("%lld%lld",&n,&m);
	rep(i,m){scanf("%lld%lld%lld",&a[i].l,&a[i].r,&a[i].c);}
	sort(a+1,a+m+1,cmp);build(1,1,n);
	rep(i,m){
		update(1,1,n,a[i].l,a[i].r,query(1,1,n,a[i].l,a[i].r)+a[i].c);
	}
	ll ans=query(1,1,n,n,n);
	if(ans==inf) puts("-1");else printf("%lld\n",ans);
	return 0;
}

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

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


int main(){
    int n,k;cin >>n>>k;
    vector<int>l(n);
    for (int i = 0; i < n; ++i) {
        cin >>l[i];
    }
    sort(all(l));
    reverse(all(l));
    int ans=0;
    for (int i = 0; i < k; ++i) {
        ans+=l[i];
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 3620
#include"bits/stdc++.h"
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    char S[N];
    cin >> S;
    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    }else if(S[K-1] == 'B'){
        S[K-1] = 'b';
    }else if(S[K-1] == 'C'){
        S[K-1] = 'c';
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
              	          String ab = input.readLine();
			  String[] strAry = ab.split(" ");
			  //????????????????????\??????????????°????????????????????§???????????????


			  int x = Integer.parseInt(strAry[0]);
			  //??????strAry??????????????????????????????????????????
			  int y = Integer.parseInt(strAry[1]);

			  System.out.println(x*y +" "+ 2*(x+y));
		    }catch(IOException e) {   System.out.println("Exception : " + e);
		    }


	}//60 split?????????????????£???

}

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

using namespace std;

char s[15];
int frecv[15];

int main(){
    int n,i,j;

    cin>>s;

    for(i=0;i<strlen(s);i++)
        if(s[i]=='B'){
            int ok=1;

            for(j=i;j>=0 && ok;j--)
                if(!frecv[j] && isdigit(s[j])){
                    frecv[j]=1;
                    ok=0;
                }
        }

    for(i=0;i<strlen(s);i++)
        if(!frecv[i] && isdigit(s[i]))
            cout<<s[i];

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

class Main {
    public static void main(String[] args) {
        int n, m, l;
        long sum;
        int[][] a;
        int[][] b;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        l = sc.nextInt();
        a = new int[n][m];
        b = new int[m][l];
        for (int i = 0; i < n; i++) 
        	for (int j = 0; j < m; j++) 
        		a[i][j] = sc.nextInt();
        for (int i = 0; i < m; i++)
        	for (int j = 0; j < l; j++)
	        	b[i][j] = sc.nextInt();

        for (int i = 0; i < n; i++) {
        	for (int k = 0; k < l; k++) {
        		sum = 0;
	        	for (int j = 0; j < m; j++) {
    	    		sum += a[i][j] * b[j][k];
        		}
        		System.out.print(sum);
        		if (k != l - 1) 
        			System.out.print(" ");
        	}
        	System.out.println();
        }
    }
}


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

int a[10000];

int main(void)
{
	int H, W, N;
	cin >> H >> W >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}

	int pos = 0;
	string str = "";
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (a[pos] == 0) ++pos;
			if (i % 2 == 1) {
				str = to_string(pos+1) + " " + str;
			} else {
				str = str + " " + to_string(pos+1);
			}
			--a[pos];
		}
		cout << str << endl;
		str = "";
	}

	return 0;
}

Measured memory_bytes: 384
#![allow(unused_mut)]
#![allow(non_snake_case)]

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:https://beta.atcoder.jp/contests/abc107/tasks/abc107_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

fn main(){
    input!{N:usize,i:usize};
    println!("{}",N-i+1);
}

Measured memory_bytes: 4352