akhauriyash/Code-Regression huggingface dataset:
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
#N, M = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
#S = input()
#S = [input() for _ in range(N)]

A.sort(reverse = True)
#print(A)

answer = 0
for i in range(N):
    ai = A[i]
    for j in range(i + 1, N):
        aj = A[j]
        for k in range(j + 1, N):
            ak = A[k]
            
            if ai < aj + ak and aj < ai + ak and ak < ai + aj and ai != aj and aj != ak and ak != ai:
                answer += 1

print(answer)

Measured memory_bytes: 68516
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;

#define pb 					push_back

template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}

template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<" ";

	return os;
}

int main() {
    //ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
 	string s;
 	int n;
 	cin >> n >> s;
 	bool ok  =0;
 	if(n%2==1)
 		ok = 0;
 	else{

 		string a = s.substr(0, n/2);
 		string b =s.substr(n/2);
 		ok = a==b;
 	}
 	if(ok)
 		cout <<"Yes\n";
 	else
 		cout <<"No\n";

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<math.h>
#include<map>
#include<vector>
#include <tuple>
using namespace std;
int main() {
  int N, L;
  cin >> N >> L;
  int sum = 0;
  if(L + N - 1 < 0){
    for(int i = 1; i <= N - 1; i++){
      sum += L + i - 1;
    }
  }
  else if (L <= 0 && 0 <= L + N - 1){
    for(int i = 1; i <= N; i++){
      sum += L + i - 1;
    }
  }
  else{
    for(int i = 2; i <= N; i++){
      sum += L + i - 1;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int r;
	cin >> r;

	if (r < 1200)
		cout << "ABC" << endl;
	else if (r >= 1200 && r < 2800)
		cout << "ARC" << endl;
	else
		cout << "AGC" << endl;
}

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

	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int L[2000][2000] = {};
int R[2000][2000] = {};
int T[2000][2000] = {};
int B[2000][2000] = {};
bool S[2000][2000] = {};

int main()
{
	int h, w;

	cin >> h >> w;

	for (int i = 0; i < h; i++)
	{
		string line;
		cin >> line;

		for (int j = 0; j < w; j++)
		{
			if (line[j] == '#')
			{
				S[i][j] = true;
				L[i][j] = 0;
				T[i][j] = 0;
			}
			else
			{
				if (j == 0) L[i][j] = 1;
				else L[i][j] = L[i][j - 1] + 1;

				if (i == 0) T[i][j] = 1;
				else T[i][j] = T[i - 1][j] + 1;
			}
		}
	}

	int max = 0;

	for (int i = h - 1; i >= 0; i--)
	{
		for (int j = w - 1; j >= 0; j--)
		{
			if (S[i][j])
			{
				R[i][j] = 0;
				B[i][j] = 0;
			}
			else
			{
				if (j == w - 1) R[i][j] = 1;
				else R[i][j] = R[i][j + 1] + 1;

				if (i == h - 1) B[i][j] = 1;
				else B[i][j] = B[i + 1][j] + 1;

				int sum = L[i][j] + R[i][j] + T[i][j] + B[i][j] - 3;
				if (max < sum) max = sum;
			}
		}
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 66688
N, K = map(int,input().split())
A = [0] + list(map(int,input().split()))
T = {1:1}
current_town = 1
for i in range(2,K+1):
    current_town = A[current_town]
    K -= 1
    if current_town in T:
        loop_towns = list(T.keys())[T[current_town]-1:]
        print(loop_towns[K%len(loop_towns)])
        break
    else:
        T[current_town] = i
else:
    print(A[current_town])

Measured memory_bytes: 32384
#include <iostream>
#include <algorithm>
#define INF 100000000
using namespace std;
int main(){
  string ma[100];
  int dp[100][100];
  int h,w;
  for(int i = 0 ; i < 100 ; i++ )
    for(int j = 0 ; j < 100 ; j++ )dp[i][j] = INF;

  cin >> h >> w;
  for(int i = 0 ; i < h ; i++ )cin >> ma[i];
  dp[0][0] = 0;
  for(int y = 0 ; y < h ; y++ ){
    for(int x = 0 ; x < w ; x++ ){
      int c = ma[y][x]-'0';
      if(y > 0)dp[y][x] = min(dp[y][x],dp[y-1][x])+c;
      if(x > 0)dp[y][x] = min(dp[y][x-1] + c,dp[y][x]);
    }
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}

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

if n == 52:
    pass

else:
    s_list = list(range(1, 14))
    h_list = list(range(1, 14))
    c_list = list(range(1, 14))
    d_list = list(range(1, 14))
    
    for i in range(n):
        mark, number = input().split()
    
        if mark == 'S':
            s_list.remove(int(number))
        elif mark == 'H':
            h_list.remove(int(number))
        elif mark == 'C':
            c_list.remove(int(number))
        elif mark == 'D':
            d_list.remove(int(number))
    
    s_list = ['S ' + str(x) for x in s_list]
    h_list = ['H ' + str(x) for x in h_list]
    c_list = ['C ' + str(x) for x in c_list]
    d_list = ['D ' + str(x) for x in d_list]
    
    card_list = s_list + h_list + c_list + d_list
    
    card_list = '\n'.join(card_list)
    print(card_list)


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

using namespace std;

#define int long long

const int N = 2e5 + 100;

int a[N], b[N];
int n, ind;

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
	cin >> a[i];
	b[i] = a[i];
    }
    sort(b, b + n);
    ind = n / 2 - 1;
    for (int i = 0; i < n; i++)
	cout << (a[i] <= b[ind] ? b[ind + 1] : b[ind]) << '\n';
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    string A,B,C;
    cin >> A >> B >> C;

    queue<char> a,b,c;

    rep(i,A.size()) {
        a.push(A[i]);
    }
    rep(i,B.size()) {
        b.push(B[i]);
    }
    rep(i,C.size()) {
        c.push(C[i]);
    }

    char now = a.front();
    a.pop();
    char ans;
    while(1) {
        if (now=='a') {
            if (a.size()==0) {
                ans = 'A';
                break;
            }
            else {
                now = a.front();
                a.pop();
            }
        }   
        if (now=='b') {
            if (b.size()==0) {
                ans = 'B';
                break;
            }
            else {
                now = b.front();
                b.pop();
            }
        }
        if (now=='c') {
            if (c.size()==0) {
                ans = 'C';
                break;
            }
            else {
                now = c.front();
                c.pop();
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
A, B, C, D = map(int, input().split())

numC = B//C - (A-1)//C
numD = B//D - (A-1)//D

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if a % b == 0:
        return b
    return gcd(b, a%b)

CD = C * D // gcd(C, D)

numCD = B//CD - (A-1)//CD
numAll = B - A + 1
print(numAll - numC - numD + numCD)


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

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


ans = 0
for i in range(n):
    ans = ans + b[i]

ans2 = 0    
for i in range(n-1):
    if a[i] - a[i+1] == -1:
        ans2 = ans2 + c[a[i]-1]

print(ans + ans2)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = Read().ToInt();
            decimal ans = 0;
            for (int i = 1; i <= r; i++)
            {
                for (int j = 1; j <= r; j++)
                {
                    for (int k = 1; k <= r; k++)
                    {
                        var tmp = Gcd(i, j);
                        tmp = Gcd(k, tmp);
                        ans += tmp;
                    }
                }
            }
            WriteRead(ans);
        }

        public static int Gcd(int a, int b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 18128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d,x,a,sum=0;
  cin>>n>>d>>x;
  for(int i=0;i<n;i++){
    cin>>a;
    sum+=1+(d-1)/a;
  }
  cout<<sum+x<<'\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const ll mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

ll N, M, K, H, W, L, R, X;
string S, T;

int main(){
  cin >> X;
  ll i=0;
  while (i*i+i <= X*2){
    i++;
    if( i*i+i == X*2 ) {
      cout << i << endl;
      return 0;
    }
  }
  cout << i<< endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <vector>
#define min(a,b) (a<b?a:b)
#define llmax 1000000001
using namespace std;
typedef long long ll;
ll a[100001];
int main()
{
	ll n, MIN = llmax, cnt = 0, sum = 0;
	cin >> n;
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
		MIN = min(MIN, llabs(a[i]));
		if (a[i] < 0)
			cnt++;
		sum += llabs(a[i]);
	}
	if (cnt & 1)
		sum -= 2 * MIN;
	cout << sum << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
from math import sqrt
from math import floor
#https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_c
#C - Align
"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()

hasO = 0

for i in range(N):
    a = gi()
    if (a % 2):
        hasO = 1

if hasO:
    print("first")
else:
    print("second")

#HLHL


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

void decToBinary(int n,int base)
{

    vector<int>binaryNum;

    int i = 0;
    while (n > 0) {


        binaryNum.push_back(n % base);
        n = n / base;
        i++;
    }



        cout<<binaryNum.size()<<endl;
        binaryNum.clear();
}

int main()
{
    int n,b;
    cin>>n>>b;
    decToBinary(n,b);
    return 0;
}


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

namespace aizu1
{
    public class Solution
    {
        public static void Main(string[] args)
        {
            int H = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            for(int i = H/2-1; i >=0; i--)
            {
                Maxify(A, i, H);
            }

            PresentHeap(A,H);
        }

        public static void Maxify(int[] A, int i, int H)
        {
            int largest;
            int tmp;
            int left = 2 * i + 1;
            int right = 2 * i + 2;
            if (left < H && A[left] > A[i]) largest = left;
            else largest = i;
            if (right < H && A[right] > A[largest]) largest = right;

            if (largest != i)
            {
                tmp = A[largest];
                A[largest] = A[i];
                A[i] = tmp;
                Maxify(A,largest,H);
            } 
        }

        public static void PresentHeap(int[] A, int H)
        {
            StringBuilder builder = new StringBuilder();

            for(int i = 0; i < H; i++)
            {
                builder.Append(" ").Append(A[i]);
            }
            Console.WriteLine(builder);
        }
    }
}

Measured memory_bytes: 68568
n,m = map(int, input().split())

wa_l = [0]*(n+1)
ac_l = [False]*(n+1)
for _ in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'WA' and not ac_l[p]:
        wa_l[p] += 1
    elif s == 'AC':
        ac_l[p] = True


ans_a = 0
ans_w = 0
for wa,ac in zip(wa_l,ac_l):
    if ac:
        ans_a+=1
        ans_w += wa

print(ans_a,ans_w)

Measured memory_bytes: 71352
N,W = map(int,input().split())

dp = [[-1] * (W + 1) for i in range(N + 1)]
dp[0][0] = 0

for i in range(N):
  w,v = map(int,input().split())
  for j in range(len(dp[i]) - 2, -1, -1):
    if dp[i][j] == -1:
      continue
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
    if j + w >= len(dp[i]):
      continue
    dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)

print(max(dp[N]))

Measured memory_bytes: 148404
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;

    if (U == S) cout << A - 1 << " " << B << endl;
    else if (U == T) cout << A << " " << B - 1 << endl;
    else cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.chars
ans = 0
n = 0
if s[0] == 'R'
  n += 1
end
ans = [ans, n].max
if s[1] == 'S'
  n = 0
else
  n += 1  
end
ans = [ans, n].max
if s[2] == 'S'
  n = 0
else
  n += 1
end
ans = [ans, n].max
puts ans

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
int main() {
	ios::sync_with_stdio(false);

	ll N; cin >> N;
	vl a(N);
	ll ges = 0;
	FOR(i,0,N) {
		cin >> a[i];
		ges ^= a[i];
	}

	FOR(i,0,N) {
		a[i] &= (~ges);
	}

	ll stelle = 0;
	FORD(i,0,61) {
		bool found = false;
		FOR(j,stelle,N) {
			if (a[j] & (1LL<<i)) {
				// bit is set
				found = true;
				swap(a[j],a[stelle]);
				break;
			}
		}
		if (found) {
			FOR(j,0,N) {
				if (j == stelle) {
					continue;
				}
				if (a[j] & (1LL << i)) {
					a[j] ^= a[stelle];
				}
			}
			stelle++;
		}
	}
	ll erg = 0LL;
	FOR(i,0,N) {
		erg ^= a[i];
	}
	
	cout << 2 * erg + ges << endl; 
	return 0;
}


Measured memory_bytes: 1024
/*#include<bits/stdc++.h>
using namespace std;
int main(){
long long int a,b,k;
cin>>a>>b>>k;
 
if(a+b<k)
	cout<<0<<" "<<0;
 
else if(a-k>=0)
 
	cout<<a-k<<" "<<b;
 
 else{
	b=b-(k-a);
	cout<<0<<" "<<b;
}
}
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int a,b,k;
cin>>a>>b>>k;
  if(a<k)
  {
    if(b<k-a)
      b=0;
    else 
      b=b-(k-a);
     
    a=0;
  }
  else 
    a=a-k;
  
  cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
int main()
{
    string s,s1;
    while(cin>>s>>s1)
    {
         if(s[0]=='H')
            cout<<s1;
         else if(s[0]=='D')
         {
             if(s1[0]=='D')
                cout<<"H\n";
             else
                cout<<"D\n";
         }
         cout<<"\n";

    }
    return 0;
}


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

int n, a, q, b, c, nums[100005];
long long ans;

int main(){
    scanf("%d", &n);
    for (int i=0; i<n; ++i){
        scanf("%d", &a);
        ans += a;
        ++nums[a];
    }
    scanf("%d", &q);
    for (int i=0; i<q; ++i){
        scanf("%d%d", &b, &c);
        ans += (long long) (c-b) * nums[b];
        printf("%lld\n", ans);
        nums[c] += nums[b];
        nums[b] = 0;
    }
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;

    vector<ll> a;
    unordered_map<ll, ll> m;

    NREP() {
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
        m[tmp]++;
    }

    ll total = 0;
    for(auto x : m) {
        total += x.second * (x.second - 1) / 2;
    }

    NREP() {
        MSG(total - (m[a[i]] - 1))
    }
}


Measured memory_bytes: 9148
#include <stdio.h>
#include <string.h>
int mon[100001];
int main(void){
    int N,M,i,x,AC=0,WA=0;
    char y[3];
    scanf("%d%d",&N,&M);
    for(i=0;i<M;i++){
        scanf("%d %s",&x,y);
        if(mon[x-1]!=-1 && strcmp(y,"AC")==0){
            AC++;
            WA+=mon[x-1];
            mon[x-1]=-1;
        }
        if(mon[x-1]!=-1 && strcmp(y,"WA")==0) mon[x-1]++;
    }
    printf("%d %d",AC,WA);
    return 0;
}


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

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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1920
import java.util.*;

class Main{
  
  public static void main (String args[]){
    
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    
    String op = sc.next();
    
    int b = sc.nextInt();
    
    int rs;
    
    if(op.equals("+")){
      
      rs = a + b;
      
    }else{
      
      rs = a - b;
      
    }
    
    System.out.println(rs);
    
  }
  
}

Measured memory_bytes: 21716
def main():
    A,B,M=map(int,input().split())
    a=[int(_) for _ in input().split()]
    b=[int(_) for _ in input().split()]
    ans=min(a)+min(b)
    for m in range(M):
        x,y,c=map(int,input().split())
        ans=min(ans,a[x-1]+b[y-1]-c)
    print(ans)
main()

Measured memory_bytes: 18488
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  ll s;
  cin >> s;
  int cnt = 0;
  ll S = s;
  while(S > 0){
    S /= 10;
    cnt++;
  }
  const int f = 753;
  int ans = 1000;
  for(int i = 3; i <= cnt; i++){
    int x = s/pow(10,cnt -i);
    ans = min(abs(x-f), ans);
    ll p = pow(10,cnt+2-i);
    s %= p;
  }
  cout << ans << endl;
}
  
    

Measured memory_bytes: 4028
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int Combination(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int x;
  cin>>x;
  x=pow(x,3);
  cout<<x<<endl;
}


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

int dp[3005][3005];


int main(){
    string s, t;
    cin >> s >> t;

    int ns = s.size();
    int nt = t.size();

    rep(i, ns){
        rep(j, nt){
            if(s[i]==t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;

            }else{
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }
    vector<char> ans;
    int x=ns, y=nt;
    while(x&&y){
        if(s[x-1]==t[y-1]){
            ans.emplace_back(s[x-1]);
            x--;
            y--;
        }else if(dp[x][y]==dp[x-1][y]){
            x--;
        }else{
            y--;
        }
    }

    rep(i, ans.size()){
        cout << ans[ans.size()-1-i];
    }
    cout << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>
#include <iostream>
#define Re register int

double p[3005],f[3005][3005],ans;
int N;

int main(int argc, char const *argv[])
{
	scanf("%d\n",&N);
	for (Re i=1; i<=N; ++i) scanf("%lf",&p[i]);
	f[1][0]=1-p[1],f[1][1]=p[1];
	for (Re i=2; i<=N; ++i)
	{
		f[i][0]=f[i-1][0]*(1-p[i]);
		for (Re j=1; j<=i; ++j)
			f[i][j]=f[i-1][j]*(1-p[i])+f[i-1][j-1]*p[i];
	}
	for (Re i=(N+1)/2; i<=N; ++i) ans+=f[N][i];
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin) - 1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int a, b, q;
  ll input;
  ll x;
  cin >> a >> b >> q;
  multiset<ll> s{-1000000000000000, 1000000000000000};
  multiset<ll> t{-1000000000000000, 1000000000000000};
  REP(i, a) {
    cin >> input;
    s.insert(input);
  }
  REP(i, b) {
    cin >> input;
    t.insert(input);
  }
  REP(i, q) {
    cin >> x;
    auto si = s.lower_bound(x);
    auto ti = t.lower_bound(x);
    ll ans;
    ll es = *si;
    ll et = *ti;
    si--;
    ti--;
    ll ws = *si;
    ll wt = *ti;
    ans = min(x - min(ws, wt), max(es, et) - x);
    ans = min(ans, min(et - x, x - ws) + et - ws);
    ans = min(ans, min(es - x, x - wt) + es - wt);
    cout << ans << endl;
  }
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 10752
#include<iostream>
#include<math.h>
#include<cstring>
#include<vector>
#include<map>

typedef long long ll;

using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
int main(){
    int i;
    char n[100];
    cin>>n;
    int max=0;
    int cnt=(int)strlen(n);
    int t=0;
    if(cnt==1){
        cout<<n<<endl;
        return 0;
    }
    rep(i,cnt){
        if(n[i]=='9')
            t++;
    }
    if(t==cnt){
        cout<<9*cnt<<endl;
        return 0;
    }else if(t==cnt-1 && n[0]!='9'){
        cout<<9*(cnt-1)+(int)(n[0]-'0')<<endl;
        return 0;
    }
    max=(cnt-1)*9;
    for(i=1;i<=10;i++){
        if((int)(n[0]-'0')<i){
            max+=(int)(n[0]-'0')-1;
            break;
        }
    }
    cout<<max<<endl;
}


Measured memory_bytes: 3580
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var name = Console.ReadLine();

            var nick = name.Substring(0,3);

            Console.WriteLine(nick);
        }
    }
}


Measured memory_bytes: 25888
N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
  tmp = 0
  for j in range(i+1, N):
    if A[i] > A[j]:
      tmp += 1
  tmp *= K*(K+1)//2
  ans += tmp
  tmp = 0
  for j in range(i):
    if A[i] > A[j]:
      tmp += 1
  tmp *= K*(K-1)//2
  ans += tmp
  ans = ans % (10**9+7)
print(ans)

Measured memory_bytes: 9152
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    int N;
    cin >> N;

    vector<int> dp(N + 1);
    dp[0] = 0;
    FOR(i, 1, N + 1) {
        dp[i]     = INF32;
        int power = 1;
        while (power <= i) {
            chmin(dp[i], dp[i - power] + 1);
            power *= 6;
        }
        power = 1;
        while (power <= i) {
            chmin(dp[i], dp[i - power] + 1);
            power *= 9;
        }
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  ll mival=A[0];
  int mit=0;
  for(int i=1;i<N;i++){
    if(mival>A[i]){
      mival=A[i];
      mit=i;
    }
  }

  cout<<mit+1<<endl;

  return 0;
}



Measured memory_bytes: 3544
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int A = nextInt();
        int B = nextInt();

        if(A>9 || B>9) println("-1");
        else println(A*B);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 23252
// //Coded by Abhijay Mitra
// #include <iostream>
// #include <stdlib.h>
// #include <algorithm>
// #include <cstdio>
// #include <numeric>
// #include <cstring>
// #include <numeric>
// #include <vector>
// #include <iterator> 
// #include <map>
// #include <set>
// #include <climits>
// #include <queue>
// #include <cmath>
// #include <stack>
// #include <cctype>
// #include <bitset>
#include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
// const int N=2e6+10;
// const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
// const double Pi = 3.14159265;
#define F first
#define S second

int n, ans;

void Solve(vector<pair<int, int>>& cams)
{
    priority_queue<int> pq;
    // int result = 0;
    int initalAns = ans;

    for(auto i : cams)
    {
        pq.push(-i.second);
        ans+=i.second;
        //we assume its left is best
        while(pq.size()>i.first)ans+=pq.top(),pq.pop();
    }

}

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

    int testcases;
    cin >> testcases;
    while(testcases--)
    {

        cin>>n;ans=0;

        std::vector<pair<int, int>> f;
        std::vector<pair<int, int>> b;

        for(int i = 1; i <=  n; i++)
        {
            int K, L, R;
            cin >> K >> L >> R;

            if(L>R)
            {
                ans+=R;
                f.push_back({K,L-R});
            }
            else{
                ans+=L;
                b.push_back({n-K,R-L});
            }
        }

    // rep(i,1,n)cin>>k[i]>>l[i]>>r[i];
    // rep(i,1,n){
    //     if(l[i]>r[i]){
    //         ans+=r[i];
    //         f.pb({k[i],l[i]-r[i]});
    //     }
    //     else{
    //         ans+=l[i];
    //         b.pb({n-k[i],r[i]-l[i]});
    //     }
    // }
    sort(all(f));
    sort(all(b));

    Solve(f);
    Solve(b);

        std::cout << ans << "\n";

    }

    return 0;
}


Measured memory_bytes: 8276
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n,k,s;
int bitcount(int S) {
    int res=0;
    rep(i,n+2) if((S>>i)&1) res++;
    return res;
}
void solve() {
    ll ans=0;

    rep(i, 1<<(n)) {
        int sum=0;
        if(bitcount(i)!=k) continue;
        rep(j,(n+1)) {
            if(j==0) continue;
            if((i>>(j-1))&1) sum+=j;
        }

        if(sum==s) ans++;
    }

    cout<<ans<<endl;


}

int main() {
    while(cin>>n>>k>>s) {
        if(n+k+s==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1156
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

const int N = 1407;
const int K = 38;

vi dat[N+5];

int main(){
    FOR(i,N+3) dat[i].clear();
    // connector
    REP(num,1,K){
        dat[N-1].pb(num);
        FOR(i,K-1) dat[(num-1)*(K-1) + i].pb(num);
    }
    // alternate
    FOR(round,N-K){
        int num = K+1 + round;
        int diff = round/(K-1);
        int start = round%(K-1);
        // push
        dat[diff].pb(num);
        REP(i,1,K-1){
            int pos = i*(K-1) + (start+i*diff)%(K-1);
            dat[pos].pb(num);
        }
    }
    // print
    printf("%d %d\n", N, K);
    FOR(i,N) FOR(j,K) printf("%d%c", dat[i][j], " \n"[j==K-1]);
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
using namespace std;
int N_MAX = 80;
typedef long long ll;
int main()
{
  int n,i;
  ll m=1000,k=0,t,b;
  ll c[N_MAX];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> c[i];
    if(k==0&&i>0&&c[i]>c[i-1]){
      k=m/c[i-1];
      m-=k*c[i-1];
    }else if(k>0&&i>0&&c[i]<c[i-1]){
      m+=k*c[i-1];
      k=0;
    }
  }
  m+=c[n-1]*k;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 3636
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

N = int(input())
ps= primes(55555)

ans = []
for p in ps:
    if p % 5 == 3:
        ans.append(p)
    if len(ans) == N:
        break
print(" ".join(list(map(str,ans))))



Measured memory_bytes: 3572
#include <stdio.h>

void Do(int H, int N){
  int i, A, S;
  S = 0;
  for(i = 0;i < N;i++){
    scanf("%d", &A);
    S += A;
  }
  if(S >= H) printf("Yes\n");
  else printf("No\n");
}

int main(void){
  int H, N;
  scanf("%d %d", &H, &N);
  Do(H, N);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);i++)
int main() {
	bool isprime[100001];
	rep(i,100001) isprime[i]=true;
	isprime[0]=isprime[1]=false;
	for(int i=0 ; i*i<100001; i++){
		if(isprime[i]){
			for(int j=2;i*j<100001;j++){
				isprime[i*j]=false;
			}
		}
	}
	int cnt[100000];
	cnt[0]=0;
	rep(i,100001){
		if(isprime[i+1]&&isprime[(i+2)/2]){
			cnt[i+1]=cnt[i]+1;
		}
		else cnt[i+1]=cnt[i];
	}
	int Q;
	cin>>Q;
	rep(i,Q){
		int l,r;
		scanf("%d %d",&l,&r);
		printf("%d\n",cnt[r]-cnt[l-1]);
	}
	return 0;

}


Measured memory_bytes: 1152
n, m = map(int, input().split())
l_max = 1
r_min = n
for _ in range(m):
    l,r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)
    
print(max(0,r_min-l_max+1))

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

#define ll long long int
#define LD long double

const int N = 100010;

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

signed main()
{
    //freopen("IN", "r", stdin);
    //freopen("OUT", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    int cnt[n + 1];
    memset(cnt, 0, sizeof(cnt));
    for(int i = 1; i <= 100; i++) {
        for(int j = 1; j <= 100; j++) {
            for(int k = 1; k <= 100; k++) {
                int r = i * i + j * j + k * k + i * j + j * k + k * i;
                if(r <= n) cnt[r]++;
            }
        }
    }
    for(int i = 1; i <= n; i++)
        cout << cnt[i] << "\n";
    
    return 0;
}

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

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

  if (n % 2 == 0) {
    cout << 0.5 << endl;
  }
  else {
    double a = ((n/2)+1) / (double)n;
    printf("%.10f\n", a);
  }

  return 0;
}


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

using namespace std;

int main() {
    int n,w;
    cin >> n >> w;
    vector<pair<int,int>> v(n); //first -- weight
    for(int i=0;i<n;i++)cin >> v[i].first >> v[i].second;
    
    vector<vector<long long int>> dp(w+1,vector<long long int> (n+1));
    for(int i=0;i<=w;i++){
        dp[i][0]=0;
    }
    for(int i=0;i<=n;i++){
        dp[0][i]=0;
    }
    
    for(int i=1;i<=w;i++){
        for(int j=1;j<=n;j++){
           if(i >=v[j-1].first){
               dp[i][j]=max(dp[i-v[j-1].first][j-1] + v[j-1].second,dp[i][j-1]);
           }
           else dp[i][j]=dp[i][j-1];
        }
    }
      cout << dp[w][n];  
}

Measured memory_bytes: 82304
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
using namespace std;

int main(void){
	char s;
	int num[26]={0};
	while(cin >>s){
		s=tolower(s);
		if(isalpha(s)){
			num[s-'a']++;
		}
	}
	for(int i=0; i<26; i++){
		printf("%c : %d\n", i+'a', num[i]);
	}
    return 0;
}

Measured memory_bytes: 1124
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<unordered_set>
#include<unordered_set>
#include<cmath>
#define mod 1000000000000000000
int main(void) {
char ch;
cin>>ch;
if(ch>='A'&&ch<='Z')
cout<<'A'<<"\n";
else if(ch>='a'&&ch<='z')
cout<<'a'<<"\n";
	return 0;
}



Measured memory_bytes: 3588
a=int(input())
b=int(input())
c=int(input())
x=int(input())
d=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                d+=1
print(d)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        if(400 <= n && n <= 599)
        {
            Console.WriteLine(8);
        }
        if (600 <= n && n <= 799)
        {
            Console.WriteLine(7);
        }
        if (800 <= n && n <= 999)
        {
            Console.WriteLine(6);
        }
        if (1000 <= n && n <= 1199)
        {
            Console.WriteLine(5);
        }
        if (1200 <= n && n <= 1399)
        {
            Console.WriteLine(4);
        }
        if (1400 <= n && n <= 1599)
        {
            Console.WriteLine(3);
        }
        if (1600 <= n && n <= 1799)
        {
            Console.WriteLine(2);
        }
        if (1800 <= n && n <= 1999)
        {
            Console.WriteLine(1);
        }



        Console.ReadLine();
    }


}




Measured memory_bytes: 17644
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	string s;
	ll k;
	cin >> s >> k;
	ll n = s.length();
	vector<ll> ren;

	if (n == 1){
		cout << k/2 << endl;
		return 0;
	}

	for (int i = 0; i < n-1; ){
		if (s[i] == s[i+1]){
			int j = 1;
			while(s[i] == s[i+j]){
				j++;
				if (i+j == n) break;
			}
			ren.push_back(j);
			i += j;
		}else{
			ren.push_back(1);
			if (i == n-2) ren.push_back(1);
			i++;
		}
	}
	
	if (s[0] == s[n-1]){
		if (ren[0] == n){
			cout << n*k/2 << endl;
		}else{
			ll ans = 0;
			ll temp = ren[0] + ren.back(); 
			ans += (ll)(temp/2)*(k-1);
			ans += ren[0]/2;
			ans += ren.back()/2;
			for (int i = 1; i < (int)ren.size()-1; i++){
				ans += (ll)(ren[i]/2)*k;
			}
			cout << ans << endl;
		}
	}else{
		ll ans = 0;
		for (int i = 0; i < (int)ren.size(); i++){
			ans += (ll)(ren[i]/2)*k;
		}
		cout << ans << endl;
	}
	
 	return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include<string.h>
using namespace std;


int main() {

	string S;
	cin >> S;

	if (S[0] == S[1] && S[1] == S[2] && S[2] == S[0]) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

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

int main()
{
	char buf[256];
	int i, j;

	scanf("%s", buf);
	j = strlen(buf) - 1;
	for (i = 0; i < j; i++, j--) {
		char tmp = buf[i];
		buf[i] = buf[j];
		buf[j] = tmp;
	}
	puts(buf);
	return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC057_B();
        }

        static void ABC057_B()
        {
            var NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];

            var students = new Dictionary<int, List<int>>();
            var points = new Dictionary<int, List<int>>();
            for (var n = 1; n <= N; n++)
            {
                var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                students.Add(n, input);
            }

            for (var m = 1; m <= M; m++)
            {
                var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                points.Add(m, input);
            }

            var ans = new List<int>();
            foreach (var student in students)
            {
                var min = int.MaxValue;
                var minNumber = 1;
                foreach (var point in points)
                {
                    var kyori = Math.Abs((student.Value[0] - point.Value[0])) + Math.Abs((student.Value[1] - point.Value[1]));
                    if (kyori == min) continue;
                    if (min > kyori)
                    {
                        minNumber = point.Key;
                        min = kyori;
                    }
                }
                ans.Add(minNumber);
            }

            foreach (var a in ans)
                Console.WriteLine(a);
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

struct flower
{
    ll hi;
    ll bty;
};

ll solve(vector<flower>& v, int n)
{
    vector<ll> dp(n+1);
    map<ll,ll> meaningful;
    dp[1] = v[1].bty;
    meaningful[v[1].hi] = dp[1];
    ll ans = dp[1];

    for(int i = 2; i <= n; i++)
    {
        dp[i] = v[i].bty;
        auto it = meaningful.lower_bound(v[i].hi + 1);
        if(it != meaningful.begin())
        {
            it--;
            dp[i] += it->second;
        }        
        meaningful[v[i].hi] = dp[i];
        it = meaningful.upper_bound(v[i].hi);
        while(it!=meaningful.end() && it->second <= dp[i])
        {
            auto temp = it;
            temp++;
            meaningful.erase(it);
            it = temp;
        }
        ans = max(ans, dp[i]);
    }
    return ans;
}


int main() {
   int n;
   cin >> n ;
   vector<flower> v(n+1); 
   for(int i = 1; i <= n; i++)
        cin >> v[i].hi;
   for(int i = 1; i <= n; i++)
        cin >> v[i].bty;
   cout << solve(v, n);
   return 0;
}


Measured memory_bytes: 20408
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
vector<int>v;
int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    v.pb(x);
    v.pb(y);
    v.pb(z);
    sort(v.begin(),v.end());
    int val = v[2]*10+v[1];
    val+=v[0];
    cout<<val<<endl;
}


Measured memory_bytes: 768
class WeightedUnionFind():
    def __init__(self, n):
        self.parents = [-1] * n
        self.par_weight = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            root = self.find(self.parents[x])
            self.par_weight[x] += self.par_weight[self.parents[x]]
            self.parents[x] = root
            return self.parents[x]

    def union(self, x, y, w):
        w = w + self.weight(x) - self.weight(y)
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            self.par_weight[x] = -w
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            self.par_weight[y] = w

    def weight(self, x):
        if self.parents[x] < 0:
            return 0
        else:
            return self.par_weight[x] + self.weight(self.parents[x])

    def diff(self, x, y):
        if self.find(x) != self.find(y):
            raise Exception('"{}" belongs to a different tree from "{}"'.format(x, y))
        return self.weight(y) - self.weight(x)


N, M = map(int, input().split())
uf = WeightedUnionFind(N)
for i in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    if uf.find(L) == uf.find(R):
        if uf.diff(L, R) != D:
            res = 'No'
            break
    else:
        uf.union(L, R, D)
else:
    res = 'Yes'

print(res)


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

int main() {

  char a[4];
  for(int i=0;i<3;i++)cin >> a[i];
  if(a[0]==a[1]&&a[1]==a[2])cout << "No" << endl;
  else cout << "Yes" << endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input())

m = -2
S = []
while(N):
    Nm = abs(N) % abs(m)
    S.append("1" if Nm else "0");
    if Nm:
        N = N - m / (-2)
    m = m * -2

S = "".join(reversed(S))
print("0" if S == "" else S)


Measured memory_bytes: 3188