akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(1, in, out);
        out.close();
    }


    static class Solver {

        public void solve(int testNumber, FastReader in, PrintWriter out) throws IOException {
            String s = in.next(), t = in.next();
            int a = in.nextInt(), b = in.nextInt();
            String u = in.next();

            out.print(s.equals(u) ? (a - 1) + " " + b : t.equals(u) ? a + " " + (b - 1) : a + " " + b);
        }

    }


    static class FastReader implements AutoCloseable {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        @Override
        public void close() throws Exception {

        }
    }
}

Measured memory_bytes: 21460
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    
    ll sm=0;
    ll k;
    cin>>k;
    rep(i,k){
        rep(j,k){
            rep(l,k){
                sm += __gcd((i+1),__gcd((j+1),(l+1)));
            }
        }
    }
    cout<<sm<<endl;
    
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
N = int(input())
res = [N % 2]
for i in range(1, N.bit_length() * 2):
  t = N % pow(2, i + 1)
  u = 0
  for j in range(i):
    u += res[j] * pow(-2, j)
  if u % pow(2, i + 1) == t:
    res.append(0)
  else:
    res.append(1)
res.reverse()
rres = ""
f = 1
for i in range(len(res)):
  if f and res[i] == 0:
    continue
  if f and res[i]:
    f = 0
  rres += str(res[i])
if rres == "": print(0)
else: print(rres)

Measured memory_bytes: 38740
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  int k[15];
  int s[15][15];
  int p[15];
  int sw[15];
  bool jud;
  int ans = 0;  

  cin >> n >> m;
  for(int i = 0;i < m;i++){
    cin >> k[i];
    for(int j = 0;j < k[i];j++){
      cin >> s[i][j];
    }
  }

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

  for(int i = 0;i < (1 << n);i++){
    int temp = i;
    jud = true;
    for(int j = 0;j < n;j++){
      sw[j] = temp % 2;
      temp /= 2;
    }
    
    for(int j = 0;j < m && jud;j++){
      int cnt = 0;
      
      for(int f = 0;f < k[j];f++){
	cnt += sw[s[j][f] - 1];
      }

      if(cnt % 2 != p[j]){
	jud = false;
      }
    }

    if(jud) ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
import bisect

def solve(s):
    if len(s) != 4:
        return False
    for i in range(len(s)):
        if i - 2 >= 0 and s[i-2] == s[i] and s[i-1] == s[i]:
            return True
    return False

def main():
    s = input()
    if solve(s):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


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

///////////////////////////////////////////
const long long int INF = 1000000000000000000LL;
using ll = long long int;
using vi = vector<int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
//template <class  T>T max(T x,T y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
///////////////////////////////////////////

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else if(abs(a-b)<=d && abs(b-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

type town struct {
	a int
	b int
}

func main() {
	n := readi()
	k := readi()
	aa := make([]town, n)
	for i := range aa {
		fmt.Scan(&aa[i].a)
	}
	var t, t2, t3, i int
	for ; i < k; i++ {
		if t2 == 0 && aa[t].b == 2 {
			t2 = i
		}
		if aa[t].b == 3 {
			t3 = i
			m := (k - t2) % (t3-t2)
			for i = 0; i < m; i++ {
				t = aa[t].a-1
			}
			fmt.Println(t+1)
			return
		}
		aa[t].b++
		t = aa[t].a-1
	}
	fmt.Println(t+1)
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

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

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}


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

int main() {
        int a, b, c, d;
        cin >> a >> b >> c >> d;

        long area1, area2;
        area1 = a*b;
        area2 = c*d;
        if (area1>=area2) cout << area1 << endl;
        else cout << area2 << endl;
        return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

ans = 0
pref = A[0]
for i in range(1, N):
    ans = (ans + A[i] * pref % mod) % mod
    pref = (pref + A[i]) % mod
print(ans)


Measured memory_bytes: 31552
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef unsigned long long  ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e15
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll X;
	cin >> X;
	
	ll ans = 0;
	ll okane = 100;
	while (okane < X) {
		okane = okane + okane / 100;
		ans++;
	}

	cout << ans << endl;
	return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

pair<int,int>student[N] , checkpoint[N] ;

int main() {
  int n, m ;
  vector<int> ans ;
  scanf("%d %d", &n, &m) ;

  for(int i = 1 ;i<=n ;i++){
    scanf("%d %d", &student[i].first, &student[i].second);
  }
  for(int i = 1 ;i<=m ;i++){
    scanf("%d %d", &checkpoint[i].first, &checkpoint[i].second) ;
  }

  for(int i =1 ;i<=n ;i++){
    int min_dist = INT_MAX , idx = 0 ;
    for(int j = 1 ; j<=m ; j++){
      int dist = abs(student[i].first - checkpoint[j].first) + 
        abs(student[i].second - checkpoint[j].second) ;

      if(dist<min_dist){
        idx = j ;
        min_dist = dist ;
      }
    }
    ans.pb(idx) ;
  }

  for(int i = 0;i<ans.size() ;i++)
    printf("%d\n", ans[i]) ;
	
  return 0 ;
}



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

using namespace std;
int main(void){

    int h, w;
    cin >> h >> w;
    
    vector<string> data;
    for(int i=0; i<h; i++) {
            string temp;
            cin >> temp;
            data.push_back(temp);
    }
    
    for(int i=0; i<h*2; i++) {
        cout << data[i/2];
        cout << endl;
    }
    

    return 0;
    
}


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

//#define DEBUG

#ifdef DEBUG
using std::endl;
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#endif // DEBUG
#ifndef DEBUG
using namespace std;
#endif // DEBUG

template <class T>
void print_vect(T v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

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

uint64_t pow(uint64_t a , uint64_t p, uint64_t mod){
    if( p < 2){
        uint64_t ans = 1;
        while(p--){
            ans =  (ans * a) % mod;
        }
        return ans;
    }else{
        if( p % 2){
            uint64_t ans = pow(a, p / 2, mod);
            uint64_t real_ans = (ans * ans) % mod;
            real_ans = (real_ans * a) % mod;
            return real_ans;
        }else{
            uint64_t ans = pow(a , p /2, mod);
            return (ans * ans) % mod;
        }
    }
}

uint64_t count_turple(uint64_t N, uint64_t K){
    std::vector<uint64_t> count_gcd(K+1, 0);
    const uint64_t MOD = 1000000007;
    count_gcd[K] = 1;
    for(uint64_t j = K - 1 ; j >= 1 ; j--){
        uint64_t fist_count = pow( K / j, N, MOD);
        //cout << "first count " << fist_count << endl;
        uint64_t multiple = 2;
        while(j <= K / multiple){
            fist_count = (fist_count + MOD - count_gcd[multiple * j]) % MOD;
            multiple++;
        }
        count_gcd[j] = fist_count;
        //cout << "count gcd = " << j << " -> " << fist_count << endl;
    }
    uint64_t ans = 0;
    for(uint64_t i = 1 ; i <= K ; i++){
        ans =  (ans + count_gcd[i] * i) % MOD;
    }
    return ans;
}

void func_to_create(){
    uint64_t N, K;
    cin >> N >> K;
    uint64_t ans = count_turple(N, K);
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /***************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    func_to_create();

    #ifdef DEBUG
    }
    #endif // DEBUG


    return 0;
}


Measured memory_bytes: 3992
#include<iostream>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    string s, t;
    cin >> s;
    t = s;
    reverse(t.begin(), t.end());
    int l = s.length();
    int first = s.find('A');
    int last = l - 1 - t.find('Z');
    cout << last - first + 1 << endl;
    return 0;
}


Measured memory_bytes: 832
while True:
    r, m, f = map(int, input().split())

    test_result = r+m
    end_flag=r+m+f
    if end_flag==-3:
        break
    elif r == -1 or m == -1:
        print('F')
    elif 80 <= test_result:
        print('A')
    elif (65 <= test_result) and (test_result < 80):
        print('B')
    elif (50 <= test_result) and (test_result < 65):
        print('C')
    elif (30 <= test_result) and (test_result < 50) and (50 <= f):
        print('C')
    elif (30 <= test_result) and (test_result < 50):
        print('D')
    elif test_result  <30:
        print('F')




Measured memory_bytes: 5592
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
	long long n;
	cin >> n;
	vector<long long> a(n);
	for (long long i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long counter = 0;
	for (long long i = 0; i < n; i++) {
		if (a[i] < 0) {
			a[i] *= -1;
			counter++;
		}
	}
	sort(a.begin(), a.end());
	long long sum = 0;
	if (counter % 2 == 0) {
		for (long long i = 0; i < n; i++) {
			sum += a[i];
		}
		cout << sum << endl;
	}
	else {
		a[0] *= -1;
		for (long long i = 0; i < n; i++) {
			sum += a[i];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int n,k,a[51],s=0;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=k;i++)
	s+=a[i];
	cout<<s;
	return 0;
}

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

map<string,int> ma;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		string a;
		cin >> a;
		if( ma[a] == 0 ) ans ++;
		ma[a] = 1;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 18852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no2();
	}

	static void no1() {
		try (Scanner sc = new Scanner(System.in)) {
			String str = sc.nextLine();
			System.out.println("2018/01/" + str.substring(8));
		}
	}

	static void no2() {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = 0;
			}

			int ans = 0;
			for (int i = 0; i < n; i++) {
				int flg = 0;
				int t = sc.nextInt();
				for (int j = 0; j < n; j++) {
					if (a[j] == t) {
						flg = 1;
						break;
					}
				}
				if (flg == 0) {
					ans++;
				}
				a[i] = t;
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 23892
n,m=map(int,input().split())
s=[list(map(int, input().split())) for i in range(m)] 
for i in range(m):
    s[i].append(i+1)
a=0
s.sort()
for i in range(m):
    if i>=1:
        if s[i][0]!=s[i-1][0]:
            a=0
        
    s[i].append(str(0)*(6-len(str(s[i][0])))+str(s[i][0]))
    s[i].append(str(0)*(6-len(str(a+1)))+str(a+1))
    a+=1
s.sort(key=lambda x:x[2])
for i in range(m):
    print(s[i][3]+s[i][4])


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


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

    int min = a*x + b*y;
    for(int i=0; i<=x || i<=y; i++){
        int ap, bp, cp;
        ap = x < i ? 0 : a*(x-i);
        bp = y < i ? 0 : b*(y-i); 
        cp = 2*c*i;
        if( ap + bp + cp < min ){
            min = ap + bp + cp;
        }
    }

    cout << min << endl;

    return 0;
}

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

using namespace std;

int main()
{
    string num;
    int sum = 0;
    
    while (cin >> num)
    {
        if ((1 == num.length()) && ('0' == num[0]))
        {
            break;
        }
        
        sum = 0;
        for (int i = 0; i < num.length(); i++)
        {
            sum += (num[i] - '0');
        }
        
        cout << sum << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n;
	cin>>n;
	ll a[n+1];
	ll d[n+1];
	for(ll k=1;k<=n;k++){
		cin>>a[k];
	}
	fill(d,d+n+1,0);
	d[2]=abs(a[2]-a[1]);
	for(ll k=3;k<=n;k++){
		d[k]=min((d[k-1]+abs(a[k]-a[k-1])),(d[k-2]+abs(a[k]-a[k-2])));
	}
	cout<<d[n];
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int a[200010];
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		if(a[i]&1){
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second" << endl;
}

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

int main(){
    int a,b,c,d;
    cin >>a >> b >> c >> d;
    if((a-1)/d+1 >= (c-1)/b+1){
        cout << "Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
}

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

int N,K;
int x[100000];
int y[100000];
char c[100000];

int A[3002][3002];


int calc(int ax,int ay,int bx,int by){
  /*
  int res=0;
  for(int x=ax;x<=bx;x++)
    for(int y=ay;y<=by;y++)
      if(0<=x&&x<3000)
        if(0<=y&&y<3000)
          res+=A[x][y];
  return res;
  */

  if(3000<ax || 3000<ay)return 0;
  if(bx<0 || by<0)return 0;
  if(ax<0)ax=0;
  if(ay<0)ay=0;

  if(by>3001)by=3001;
  if(bx>3001)bx=3001;
  
  if(ax>bx)return 0;
  if(ay>by)return 0;
  
  int res= A[bx][by];
  if(ax)res-= A[ax-1][by];
  if(ay)res-= A[bx][ay-1];
  if(ax&&ay)res+= A[ax-1][ay-1];
  return res;

}

int solve(){
  memset( A, 0 , sizeof(A));
  
  for(int i=0;i<N;i++){
    char ch=c[i];
    int tx=x[i]%(K*2);
    int ty=y[i]%(K*2);
    if(ch=='B'){
      A[tx][ty]++;
    }else{
      ty=(ty+K)%(K*2);
      A[tx][ty]++;
    }
  }

  for(int i=0;i<=3001;i++){
    for(int j=0;j<=3001;j++){
      if(i)A[i][j]+=A[i-1][j];
      if(j)A[i][j]+=A[i][j-1];
      if(i&&j)A[i][j]-=A[i-1][j-1];
    }
  }

  int res=0;
  for(int i=0;i<=2*K;i++){
    for(int j=0;j<=2*K;j++){
      int tmp=0;
      for(int dx=-3;dx<=3;dx++){
        for(int dy=-3;dy<=3;dy++){
          if( ( abs(dx)+abs(dy) )%2 == 1 )continue;
          int X=i+dx*K;
          int Y=j+dy*K;
          int X2=X+K;
          int Y2=Y+K;
          tmp+=calc(X,Y,X2-1,Y2-1);
        }
      }
      res=max(res,tmp);
    }
  }

  return res;
  
}

int main(){
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i]>>c[i];
  }
  cout<<solve()<<endl;
  return 0;
}


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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  long long count = 0, ans = 0;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == 'W')
      ans += count;
    else
      count++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <numeric>
#define M 1000000007
#define pb push_back
#define forz(i,s,n) for(lli i=s;i<n;i++)

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

typedef long long int lli;
//typedef pair<long long int, long long int> pll;
typedef unsigned long long int ull;
using namespace std;

lli recpow(lli x, lli n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x) % M, n / 2);
    else //n is odd
        return (x * recpow((x * x) % M, (n - 1) / 2)) % M;
}

bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b)
{
    return (a.second < b.second);
}

bool comp(pair<lli, lli> a, pair<lli, lli> b)
{
    if(a.first==b.first)
        return a.second<b.second;
    else
        return a.first<b.first;
}

void multiply(lli f[2][2], lli m[2][2])
{
    lli x = (f[0][0] % M * m[0][0] % M) % M + (f[0][1] % M * m[1][0] % M) % M;
    lli y = (f[0][0] % M * m[0][1] % M) % M + (f[0][1] % M * m[1][1] % M) % M;
    lli z = (f[1][0] % M * m[0][0] % M) % M + (f[1][1] % M * m[1][0] % M) % M;
    lli w = (f[1][0] % M * m[0][1] % M) % M + (f[1][1] % M * m[1][1] % M) % M;
    f[0][0] = x % M;
    f[0][1] = y % M;
    f[1][0] = z % M;
    f[1][1] = w % M;
}

lli u[2][2] = {{1, 1}, {1, 0}};

void power(lli f[2][2], lli n)
{
    if (n == 0 || n == 1)
        return;
    power(f, n / 2);
    multiply(f, f);
    if (n % 2 != 0)
        multiply(f, u);
}

lli fib(lli n)
{
    if (n == 1)
        return 2;
    else if (n == 2)
        return 3;
    else
    {
        lli h[2][2] = {{1, 1}, {1, 0}};
        power(h, n + 1);
        return h[0][0];
    }
}

//code begins here
int main()
{
    fast_io;
    lli n, w;
    cin>>n>>w;
    lli dp[n*1000+1];
    forz(i,0,n*1000+1)
    dp[i]=10000000000;
    dp[0]=0;
    forz(i,0,n)
    {
        lli we, val;
        cin>>we>>val;
        for (lli j=n*1000-val;j>=0;--j)
        {
            dp[j+val]=min(dp[j+val], dp[j]+we);
        }
    }
    lli ans=0;
    forz(i,0,n*1000+1)
    {
        if(dp[i]<=w)
        ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
from typing import List


class RollingHash:
    __slots__ = ["_source", "_length", "_base", "_mod", "_hash", "_power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
        self._source = source
        self._length = len(source)
        self._base = base
        self._mod = mod
        self._hash = self._get_hash_from_zero()
        self._power = self._get_base_pow()

    def _get_hash_from_zero(self) -> List[int]:
        """Compute hash of interval [0, right)."""
        hash_from_zero = [0] * (self._length + 1)
        cur = 0
        for i, c in enumerate(self._source, 1):
            cur = (cur * self._base + ord(c)) % self._mod
            hash_from_zero[i] = cur
        return hash_from_zero

    def _get_base_pow(self) -> List[int]:
        """Compute mod of power of base."""
        power = [0] * (self._length + 1)
        power[0] = 1
        cur = 1
        for i in range(1, self._length + 1):
            cur *= self._base % self._mod
            power[i] = cur
        return power

    def get_hash(self, left: int, right: int):
        """Compute hash of interval [left, right)."""
        return (
            self._hash[right] - self._hash[left] * self._power[right - left]
        ) % self._mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()
    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg = False
        memo = set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = True
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()


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

using namespace std;

const int N_MAX = 20002;

int n;

int k;

int p[N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> k;
        p[k] = i;
    }
    for(int i = 1; i <= n; i++)
        cout << i * (n + 1) << " ";
    cout << "\n";
    for(int i = 1; i <= n; i++)
        cout << p[i] + n * (n + 1) - i * (n + 1) << " ";
    cout << "\n";
    return 0;
}


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

int main() {
  //支払う金額nと一円玉を持っているa枚
  int n,a;
  
  cin >> n >> a;
  
  int b = n / 500;
  
  int res = n - 500 * b;
  
  if(a >= res){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define mo 100000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int n,m,i,j,k,p,vis[505][505],head,tail,zhanx[250005],zhany[250005],x,y;
int book[505][505],now1,now2,ans;
void BFS(int u,int v){
	vis[u][v]--;
	ans+=vis[u][v];
	book[u][v]=1;
	head=1;tail=1;zhanx[1]=u;zhany[1]=v;now2=0;
	while(tail!=now2){
		now1=head;
		while(head<=tail){
			x=zhanx[head];
			y=zhany[head];
			if(book[x-1][y]==1&&x>=1){
				if(vis[x-1][y]>vis[x][y]){
					tail++;
					zhanx[tail]=x-1;
					zhany[tail]=y;
					vis[x-1][y]=vis[x][y];
				}
			}
			if(book[x+1][y]==1&&x<=n){
				if(vis[x+1][y]>vis[x][y]){
					tail++;
					zhanx[tail]=x+1;
					zhany[tail]=y;
					vis[x+1][y]=vis[x][y];
				}
			}
			if(book[x][y-1]==1&&y>=1){
				if(vis[x][y-1]>vis[x][y]){
					tail++;
					zhanx[tail]=x;
					zhany[tail]=y-1;
					vis[x][y-1]=vis[x][y];
				}
			}
			if(book[x][y+1]==1&&y<=n){
				if(vis[x][y+1]>vis[x][y]){
					tail++;
					zhanx[tail]=x;
					zhany[tail]=y+1;
					vis[x][y+1]=vis[x][y];
				}
			}
			head++;
		}
		head=now1;
		now2=tail;
		while(head<=now2){
			x=zhanx[head];
			y=zhany[head];
			if(book[x-1][y]==0&&x>=1){
				if(vis[x-1][y]>vis[x][y]+1){
					tail++;
					zhanx[tail]=x-1;
					zhany[tail]=y;
					vis[x-1][y]=vis[x][y]+1;
				}
			}
			if(book[x+1][y]==0&&x<=n){
				if(vis[x+1][y]>vis[x][y]+1){
					tail++;
					zhanx[tail]=x+1;
					zhany[tail]=y;
					vis[x+1][y]=vis[x][y]+1;
				}
			}
			if(book[x][y-1]==0&&y>=1){
				if(vis[x][y-1]>vis[x][y]+1){
					tail++;
					zhanx[tail]=x;
					zhany[tail]=y-1;
					vis[x][y-1]=vis[x][y]+1;
				}
			}
			if(book[x][y+1]==0&&y<=n){
				if(vis[x][y+1]>vis[x][y]+1){
					tail++;
					zhanx[tail]=x;
					zhany[tail]=y+1;
					vis[x][y+1]=vis[x][y]+1;
				}
			}
			head++;
		}
	}
}
int main(){
	//freopen("domino.in","r",stdin);
	//freopen("domino.out","w",stdout);
	n=read();
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			vis[i][j]=min(min(i,n-i+1),min(j,n-j+1));
	for(i=1;i<=n*n;i++){
		p=read();
		BFS((p-1)/n+1,(p-1)%n+1);
	}
	pus(ans,2);
    return 0;
}

Measured memory_bytes: 7484
<?php
$len = intval(fgets(STDIN));
$input = trim(fgets(STDIN));
$ary = array_map("intval", explode(" ", $input));
sort($ary);
$result = 0;
for ($i = 0; $i < $len; $i++) {
 for ($j = ($i + 1); $j < $len; $j++) {
   for ($k = ($j + 1); $k < $len; $k++) {
     $a = $ary[$i];
     $b = $ary[$j];
     $c = $ary[$k];
     if ($a !== $b && $a !== $c && $b !== $c) {
       if (($a + $b) > $c && ($a + $c) > $b && ($b + $c) > $a) {
         $result++;
       }
     }
   }
 }
}
echo $result . PHP_EOL;

Measured memory_bytes: 16212
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  vector<long int> sum(s.size(),0);
  long int answer = 0;
  long int j = 0;
  for(long int i = 0;i < s.size();i++){
    if(s.at(i) == 'W'){
      sum.at(j) = i;
      j++;
    }
  }
  for(long int i = 0; i < j;i++){
    answer += sum.at(i)- i;
  }
  cout << answer << endl;
}

Measured memory_bytes: 2180
#include<iostream>
    #include <string>
   #include <algorithm>
    using namespace std; 
     
    int main(){
int N,K,i;
unsigned long long sum;
cin >> N >> K;
sum = K;
for( i = 1 ; i < N ; i++){
    sum = sum*(K-1);
}
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
    "os"
    "bufio"
)

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    S := readLine(reader)
    arr := []byte(S)

    type Dir struct {
        n int
        s int
        e int
        w int
    }

    dir := Dir{n:0, s:0, e:0, w:0}

    for _, v := range arr{
        switch string(v) {
        case "N":
            dir.n++
        case "S":
            dir.s++
        case "E":
            dir.e++
        case "W":
            dir.w++
        }

        if dir.n > 0 && dir.s > 0 && dir.e > 0 && dir.w > 0 {
            break
        }
    }

    if dir.n > 0 {
        if dir.s == 0 {
            fmt.Println("No")
            return
        }
    }

    if dir.s > 0 {
        if dir.n == 0 {
            fmt.Println("No")
            return
        }
    }

    if dir.e > 0 {
        if dir.w == 0 {
            fmt.Println("No")
            return
        }
    }

    if dir.w > 0 {
        if dir.e == 0 {
            fmt.Println("No")
            return
        }
    }

    fmt.Println("Yes")
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 640
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()
sum_a = sum(a)
v = sum(a)/2
ans = float("inf")
t = 0
for i in range(len(a)):
	t+=a[i]
	ans = min(ans,abs(sum_a-2*t))
print(ans)

Measured memory_bytes: 33124
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let ab = lines.next().unwrap().unwrap();
    let mut ab = ab.split_whitespace();
    let a: i64 = ab.next().unwrap().parse().unwrap();
    let b: i64 = ab.next().unwrap().parse().unwrap();

    let mut n = gcd(a, b);
    let mut ans = 1;
    for i in 2.. {
        if i * i > n {
            if n > 1 {
                ans += 1;
            }
            break;
        }
        if n % i == 0 {
            while n % i == 0 {
                n /= i;
            }
            ans += 1;
        }
    }

    println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
    let mut t = (a, b);
    while t.1 != 0 {
        t = (t.1, t.0 % t.1);
    }
    t.0
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
vector<ll> V;
int pre[maxn],a[maxn],b[maxn];
int main() {
    int a,b,c,k;cin>>a>>b>>c>>k;
    if(k<=a+b) {
        cout<<min(a,k)<<endl;
    }else{
        cout<<a-(k-(a+b))<<endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int x;
    cin >> x;
    vector<pair<ll, ll>> v;
    for (ll i = 0; i*i*i*i*i-(i-1)*(i-1)*(i-1)*(i-1)*(i-1) <= 2LL*MOD; ++i) {
        v.emplace_back(i, i*i*i*i*i);
    }
    for (auto &&i : v) {
        for (auto &&j : v) {
            if(i.second-j.second == x){
                cout << i.first << " " << j.first << "\n";
                return 0;
            }else if(i.second+j.second == x){
                cout << i.first << " " << -j.first << "\n";
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Linq;

class Solution
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var cat = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var max = cat.Max();
        var maxCount = cat.Count(c => c == max);
        var min = cat.Min();
        var minCount = cat.Count(c => c == min);

        bool ok = false;
        if (max == min)
        {
            // 3 3 3 3 3 3      5 5 5 5 5 5
            // a b c a b c      a b c d e f
            if (2 * max <= n || max == n - 1)
            {
                ok = true;
            }
        }
        else if (max == min + 1)
        {
            // 3 3 4 4 4 4
            // a b c d c d
            if (minCount <= min && 2 * (max - minCount) <= maxCount)
            {
                ok = true;
            }
        }

        Console.WriteLine(ok ? "Yes" : "No");
    }
}

Measured memory_bytes: 19040
#include <stdio.h>
#include <stdlib.h>

#define N_MAX 100

struct node {
	int d;
	int f;
	int pnum;
	struct node **paths;
} nodes[N_MAX+1] = {0};

int time = 0;
int rest = 0;

void
dfs(struct node *arg)
{
	int i;

	time++;
	arg->d = time;

	for (i = 0; i < arg->pnum; i++)
		if (arg->paths[i]->d == 0)
			dfs(arg->paths[i]);

	time++; /* 時刻の定義は謎 */
	arg->f = time;
	rest--;
}

int
main(void)
{
	int i, n;
	int umin = N_MAX, umax = 0;

	scanf("%d", &n);
	rest = n;
	for (i = 0; i < n; i++) {
		int j, u, k, p;

		scanf("%d%d", &u, &k);

		if (umin > u)
			umin = u;
		if (umax < u)
			umax = u;

		nodes[u].pnum = k;
		if (k == 0)
			continue;

		nodes[u].paths = (struct node **)malloc(sizeof(struct node *) * k);
		if (nodes[u].paths == NULL)
			return 1;

		for (j = 0; j < k; j++) {
			scanf("%d", &p);
			nodes[u].paths[j] = nodes + p;
		}
	}

	for (i = umin; i <= umax && rest > 0; i++)
		if (nodes[i].d == 0)
			dfs(nodes + i);

	for(i = 1; i <= n; i++) {
		printf("%d %d", i, nodes[i].d);
		if (nodes[i].f > 0)
			printf(" %d", nodes[i].f);
		printf("\n");
	}

	return 0;
}



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

#define ll long long int
ll dp[3003][3003];
ll arr[3003];
ll solve(ll l,ll r){
	if(l>r)return 0;
	if(l==r)return arr[l];
	if(dp[l][r]!=-1)return dp[l][r];
	
//	cout<<l<<' '<<r<<'\n';
	
	ll x=arr[l]+min(solve(l+2,r),solve(l+1,r-1));
	ll y=arr[r]+min(solve(l,r-2),solve(l+1,r-1));
	dp[l][r]=max(x,y);
	return dp[l][r];
}

int main(){
	ll n,k;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	ll sum=0;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
		
		//cout<<"sun "<<i<<' '<<arr[i]<<' '<<sum<<'\n';
	}
//	cout<<solve(0,n-1)<<' '<<sum<<'\n';
	cout<<2*solve(0,n-1)-sum;
	
}

Measured memory_bytes: 70784
N = int(input())
A = list(map(int,input().split()))
ave = sum(A) / len(A)
ans = 100
ans_index = 0
for i in range(N):
    dif = abs(A[i] - ave)
    if dif < ans:
        ans = dif
        ans_index = i
print(ans_index)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int N;

	cin >> N;

	int n2 = 1 << N;
	vector<int> a(n2);
	
	for (int i = 0; i < n2; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<int> s;
	s.push_back(a.back());
	a.back() = -1;

	for (int i = 0; i < N; i++) {
		vector<int> p = s;
		sort(p.begin(), p.end());
		int ai = n2 - 1;
		while (p.size() > 0 && ai >= 0) {
			if (a[ai] == -1) {
				ai--;
				continue;
			}
			if (a[ai] < p.back()) {
				s.push_back(a[ai]);
				p.pop_back();
				a[ai]= -1;
			}
			ai--;
		}
		if (p.size() > 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 2932
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;

//==============================================
int n;
vi color, D;
vvi M;

void print() {
	REP(i, n) {
		cout << i << " " << D[i] << "\n";
	}
}

void solve() {
	D[0] = 0;

	while (true) {
		int u = -1;
		int minV = INF;

		REP(i, n) {
			if (color[i] != 2 && minV > D[i]) {
				u = i;
				minV = D[i];
			}
		}

		if (u == -1) break;

		color[u] = 2;

		REP(i, n) {
			if (color[i] != 2 && M[u][i] != INF && D[u] + M[u][i] < D[i]) {
				D[i] = D[u] + M[u][i];
				color[i] = 1;
			}
		}
	}

	print();
}

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

	cin >> n;
	color.resize(n);
	D.resize(n, INF);
	M.resize(n, vi(n, INF));

	int u, k, c, v;
	REP(i, n) {
		cin >> u >> k;
		REP(j, k) {
			cin >> c >> v;
			M[u][c] = v;
		}
	}

	solve();
	return 0;
}

Measured memory_bytes: 3236
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

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

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

  int ans = 1000;
  for(int flip = 0; flip < (1 << N); flip++){
    multiset<int> values;
    map<pair<int, bool>, set<int>> val_even_befidx;
    for(int i = 0; i < N; i++){
      if((flip >> i) & 1){
        values.insert(B[i]);
        val_even_befidx[make_pair(B[i], i % 2 == 1)].insert(i);
      }else{
        values.insert(A[i]);
        val_even_befidx[make_pair(A[i], i % 2 == 0)].insert(i);
      }
    }
    /*for(auto x: values){
      cout << x;
    }cout << endl;
    */
    int i = 0;
    bool ok = true;
    vector<int> befidx;
    for(auto val: values){
      if(val_even_befidx[make_pair(val, i % 2 == 0)].size() == 0){
        ok = false;
        break;
      }else{
        auto itr = val_even_befidx[make_pair(val, i % 2 == 0)].begin();
        befidx.push_back(*itr);
        val_even_befidx[make_pair(val, i % 2 == 0)].erase(itr);
      }
      i++;
    }
    if(ok){
      int ans_tmp = 0;
      for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
          if(befidx[i] > befidx[j]){
            ans_tmp++;
          }
        }
      }
      ans = min(ans, ans_tmp);
    }
  }
  if(ans == 1000){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 888
#include<stdio.h>
int main(){
	int N;
	int K;
	int A = 1;
	scanf("%d", &N);
	scanf("%d", &K);
	for(int i = 0 ; i < N ; i++){
		if(A <= K){
			A *= 2;
		}else{
			A += K;
		}
	}
	printf("%d", A);
	return 0;
}

Measured memory_bytes: 1712
import math
import collections
n=int(input())
s=[sorted(input()) for _ in range(n)]
c=[str(collections.Counter(s[i])) for i in range(n)]
k=collections.Counter(c).values()
ans = 0
for i in k:
	if i >= 2:
		ans += math.factorial(i)//2//math.factorial(i-2)
print(ans)

Measured memory_bytes: 136708
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
    int N, K; cin >> N >> K;
    bool check[100] = {};
    rep(i, K){
        int d; cin >> d;
        rep(j, d){
            int a; cin >> a; a--; check[a] = true;
        }
    }
    int cnt = 0;
    rep(i, N){
        if(!check[i]) cnt++;
    }
    cout << cnt << endl;
}
    

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
bool matrix[105][105];
int arr[105];
int brr[105];
int N;
int main() {
    scanf("%d",&N);
    memset(matrix, true, sizeof(matrix));
    int sum = (N*(N+1)) / 2;
    int base, e;
    printf("%d\n",N*(N-1)/2 - N/2);
    if (N % 2) {
        base = N;
        e = N - 1;
    } else {
        base = N + 1;
        e = N;
    }

    for (int i = 1; i <= e; i++) {
        matrix[i][base - i] = matrix[base - i][i] = false;
    }
     for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (i == j || !matrix[i][j])
                continue;
            printf("%d %d\n",i, j);
            matrix[i][j] = matrix[j][i] = false;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,i;
	int a[150];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	int sum=0;
	for(i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			sum+=a[i]*a[j];
		}
	}
	printf("%d",sum);
}

Measured memory_bytes: 760
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

struct distance
{
    long dis;
    long town;
    distance(long dis1, long town1){
    dis=dis1;
    town=town1;
  }
  bool operator<( const distance &another ) const {
        return dis<another.dis;
  }
};

int main(){
    long N,M;
    std::cin >> N >> M;
    std::vector<long> X;
    for(long i=0; i<M; i++){
        long temp;
        std::cin >> temp;
        X.push_back(temp);
    }
    std::sort(X.begin(),X.end());
    if(M<=N){
        std::cout << 0 << std::endl;
        return 0;
    }
    std::vector<distance> dist;
    for(long i=1; i<M; i++){
        dist.push_back(distance(X[i]-X[i-1],i));
    }
    std::sort(dist.begin(),dist.end());
    

    long sum=X[M-1]-X[0];
    for(long i=0;i<N-1; i++){
        sum-=dist[(M-2)-i].dis;
    }

        std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 6164
#include <bits/stdc++.h>
#include <string.h> 
using namespace std;
#define ll long long 
const int maxn=1e6+7; 
const int mod=1e9+7; int main(){
    ll x1,y1,x2,y2,x3,y3,x4,y4,i,j;
    cin >> x1 >> y1 >> x2 >> y2;
    x3=x2-(y2-y1);
    y3=y2+(x2-x1);
    x4=x3-(y3-y2);
    y4=y3+(x3-x2);
    printf("%lld %lld %lld %lld",x3,y3,x4,y4);
    return 0; 
    }

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,x=map(int,input().split())

A=[0]+list(map(int,input().split()))

ans=0

for i in range(N):
    temp=A[i+1]+A[i]
    ans+=max(temp-x,0)
    A[i+1]=A[i+1]-max(temp-x,0)

print(ans)

Measured memory_bytes: 14540
#include<stdio.h>
int main(void)
{
    int i=0,j=0;
    char s[11],t[11];
    scanf("%s",s);
    while(s[i]!='\0'){
        if((s[i]=='0')||(s[i]=='1')){
            t[j]=s[i];
            j++;
        }
        else if(s[i]=='B'){
            if(j!=0){
                j--;
                t[j]='\0';
            }
        }
        i++;
    }
    t[j]='\0';
    printf("%s\n",t);
    return 0;
}

Measured memory_bytes: 1648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

int main(){
	int N;
	std::cin >> N;
	int a[10];
	for(int i=1; i<=9; i++){
		a[i] = i*111;
	}
	for(int i=1; i<=9; i++){
		if (N <= a[i]){
			std::cout << a[i] <<std::endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int maxn = 2005;
const int maxm = 250005;
const int mod =  10009;
const ll inf = 1e18 + 7;
//head
int main() {
    int a, b;
    cin >> a >> b;
    cout << a + b/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const long MOD = 1e9 + 7;
const long dx[] = {1, -1, 0, 0};
const long dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long n;
	cin >> n;
	ll A[n + 1], B[n + 1];
	ll sum = 0;
	for(long i = 0; i < n; i++)
	{
		cin >> A[i];
		B[i] = A[i] - (i + 1);
	}
	sort(B, B + n);
	if(n % 2 == 1)
	{
		long b = B[n / 2];
		long ans = 0;
		for(long i = 0; i < n; i++)
			ans += abs(B[i] - b);
		cout << ans << endl;
	}
	else
	{
		long b1 = B[n / 2];
		long b2 = B[n / 2 + 1];
		long ans1 = 0, ans2 = 0;
		for(long i = 0; i < n; i++)
		{
			ans1 += abs(B[i] - b1);
			ans2 += abs(B[i] - b2);
		}
		cout << min(ans1, ans2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3328