akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[]) {
  string str, command, p;
  int q, a, b, i;
  cin >> str >> q;

  for (i = 0; i < q; i++) {
    cin >> command >> a >> b;
    if (command == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (command == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    } else {
      reverse(str.begin() + a, str.begin() + b + 1);
    }
  }

  return 0;
}



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

bool ng[600];
vector<ll> yoko[600];
ll dp[111][11];
const ll MOD=1e9+7;

int main(){
    ll h,w,kk;cin>>h>>w>>kk;
    if(w==1){
        cout<<1<<endl;
        return 0;
    }
    for(ll i=1;i<(1<<(w-1));i++){
        rep(j,0,w-1){
            if(i&(1<<j))yoko[i].push_back(j+1);
        }
    }
    for(ll i=1;i<(1<<(w-1));i++){
        if(yoko[i].size()==1)continue;
        rep(j,1,yoko[i].size()){
            if(yoko[i][j]-yoko[i][j-1]==1)ng[i]=1;
        }
    }
    dp[0][1]=1;
    rep(i,1,h+1){
        for(ll j=1;j<(1<<(w-1));j++){
            if(j==1){
                rep(k,1,w+1){
                dp[i][k]+=dp[i-1][k];
                }
            }
            if(ng[j])continue;
            bool senari[10];
            rep(k,1,w+1){
                senari[k]=0;
            }
            rep(k,0,yoko[j].size()){
                senari[yoko[j][k]]=1;
                senari[yoko[j][k]+1]=1;
                dp[i][yoko[j][k]+1]+=dp[i-1][yoko[j][k]];
                dp[i][yoko[j][k]]+=dp[i-1][yoko[j][k]+1];
                dp[i][yoko[j][k]+1]%=MOD;
                dp[i][yoko[j][k]]%=MOD;
            }
            rep(k,1,w+1){
                if(!senari[k])dp[i][k]+=dp[i-1][k];
            }
        }
    }
    cout<<dp[h][kk]%MOD<<endl;
}

    









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

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i = 0;i < ty - sy;++i)cout << "U";
	for (int i = 0;i < tx - sx;++i)cout << "R";
	for (int i = 0;i < ty - sy ;++i)cout << "D";
	for (int i = 0;i < tx - sx+1;++i)cout << "L";
	for (int i = 0;i < ty - sy + 1;++i)cout << "U";
	for (int i = 0;i < tx - sx + 1;++i)cout << "R";
	cout << "D";cout << "R";
	for (int i = 0;i < ty - sy+1;++i)cout << "D";
	for (int i = 0;i < tx - sx+1 ;++i)cout << "L";
	cout << "U" << endl;
	return 0;
}

Measured memory_bytes: 256
//競技プログラミング　テンプレ
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
	cin >> n;
  vector <long long int> a(100);
  a[0]=2;
  a[1]=1;

  int i=2;
  while(i<=n){
    a[i]=a[i-1]+a[i-2];
    i++;
  }
  cout <<a[i-1] << endl;


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    string o, e;
    cin >> o >> e;
    for(unsigned int i = 0; i < e.size(); i++){
        cout << o[i] << e[i];
    }
    if(o.size() != e.size()) cout << o[o.size()-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Map<String, Integer> treeMap = new TreeMap<>();
    
    for(int i=0; i<N; i++){
      String S =sc.next();
      if(!treeMap.containsKey(S)){
        treeMap.put(S, 1);
      }else{
        treeMap.put(S, treeMap.get(S) + 1);
      }
    }
    int max = 0;
    for(String key: treeMap.keySet()){
      if(max < treeMap.get(key)){
        max = treeMap.get(key);
      }
    }
    for(String key: treeMap.keySet()){
      if(treeMap.get(key) == max){
        System.out.println(key);
      }
    }
  }
}
    

Measured memory_bytes: 77160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


ll imos[410];
ll dp[410][410];

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n); {
		rep(i, n) cin >> a[i];
	}
	rep(i, n) imos[i + 1] = imos[i] + a[i];

	rep(i, 410)rep(j, 410) dp[i][j] = INFF;
	rep(i, n) dp[i][i] = 0;

	reps(window, 2, n + 1)rep(i, n) {
		int l = i;
		int r = l + window - 1;
		for (int k = l; k < r; ++k) {
			if (dp[l][k] == INFF) continue;
			if (dp[k + 1][r] == INFF) continue;
			dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + imos[r + 1] - imos[l]);
			// printf("dp[%d][%d](%lld) + dp[%d][%d](%lld) = %lld\n", l, k, dp[l][k], k + 1, r, dp[k + 1][r], dp[l][r]);
		}
	}

	printf("%lld\n", dp[0][n - 1]);
	return 0;
}


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

int main() {
  vector<int> a(5);
  int k;

  for (int i = 0; i < 5; i++) {
    cin >> a.at(i);
  }
  cin >> k;

  for (int i = 0; i < 4; i++) {
    for (int j = 1; j < 5; j++) {
      if (abs(a.at(i) - a.at(j) ) > k) {
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
}


Measured memory_bytes: 256
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
b=[0,0,0]
ans=1
for i in a:
  ans*=b.count(i)
  for j in range(3):
    if b[j]==i:
      b[j]+=1
      break
print(ans%mod)

Measured memory_bytes: 83944
#include <stdio.h>

int main(void)
{
	int a,b,c;
	int goukei1,goukei2,goukei3;
	
	scanf("%d %d %d",&a,&b,&c);
	
	goukei1 = a+b;
	goukei2 = a+c;
	goukei3 = b+c;
	
	if(goukei1 < goukei2 && goukei1 < goukei3){
		printf("%d\n",goukei1);
	}
	else if(goukei2 < goukei1 && goukei2 < goukei3){
		printf("%d\n",goukei2);
	}
	else if(goukei3 < goukei2 && goukei3 < goukei1){
		printf("%d\n",goukei3);
	}
	else if(goukei1 == goukei2 || goukei1 == goukei3 || (goukei1 == goukei2 && goukei1 == goukei3)){
		printf("%d\n",goukei1);
	}
	else if(goukei2 == goukei3){
		printf("%d\n",goukei2);
	}
	
	return(0);
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+100;
char s[maxn];
void solve()
{
	int n;scd(n);
	scanf("%s",s+1);
	int len=strlen(s+1);
	rep1(i,len){
		s[i]='A'+(((s[i]-'A')+n)%26);
	}
	puts(s+1);
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Math;

class C
{
	static void Main()
	{
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long h = a[0], w = a[1];

		if (h % 3 == 0 || w % 3 == 0) { Console.WriteLine(0); return; }
		var m = Min(h > 3 ? w : long.MaxValue, w > 3 ? h : long.MaxValue);
		m = Min(m, Divide(h, w));
		m = Min(m, Divide(w, h));
		Console.WriteLine(m);
	}

	static long Divide(long h, long w)
	{
		var h2 = h / 2;
		var m = long.MaxValue;
		for (long v = (w + 1) / 2, v2 = w - v; v > 0; v--, v2++)
		{
			var ss = new[] { h * v, h2 * v2, (h - h2) * v2 };
			Array.Sort(ss);
			m = Min(m, ss[2] - ss[0]);
		}
		return m;
	}
}


Measured memory_bytes: 15572
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>

using namespace std;


int main(){
    long long int n;
    cin >> n;
    vector<long long int> v;
    long long int t = 0;
    long long int start = 0;
    while(1){
        if(t == n){
            break;
        }
        if(start == 0){
            long long int mod =  n % 2;
            if(mod == 0){
                v.push_back(0);
            }else{
                v.push_back(1);
                t += 1;
            }
        }
        else{
            long long int mod = n % (int)(pow(2, start + 1));
            if(mod == pow(-2, start) + t || mod ==  -1 * pow(-2, start) + t){
                v.push_back(1);
                t += pow(-2, start);
            }else{
                v.push_back(0);
            }
        }
        start++;
    }
    reverse(v.begin(), v.end());
    bool check = false;
    if(n == 0){
        cout << 0;
    }else{
        for(int i = 0; i < v.size(); i++){
            if(v[i] == 1){
                check = true;
            }
            if(check){
                cout << v[i];
            }
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}
signed main() {
	int n,a;
	vector<int> vec, ans;
	cin >> n;
	rep(i, n) {
		cin >> a;
		vec.push_back(a);
	}
	while (!vec.empty()) {
		for (int i = vec.size() - 1; i >= 0; i--) {
			if (vec[i] == i + 1) {
				ans.push_back(i + 1);
				vec.erase(vec.begin() + i);
				goto ioi;
			}
		}
		cout << -1 << endl;
		ggr;
	ioi:;
	}
	reverse(ans.begin(), ans.end());
	for (int i : ans)cout << i << endl;
	ggr;
}

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

signed main(){
    int A,B;
    cin>>A>>B;
    if(A>B) swap(A,B);
    int l=0,r=1e9;
    while(l+1<r){
        int m=(l+r)/2;
        if(abs(A-m)>abs(B-m)) r=m;
        else l=m; 
    }
    if(abs(A-l)==abs(B-l)) cout<<l<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll gya(ll n,ll p,ll m){
	ll b=1;
	while(p){
		if(p%2)b=(b*n)%m;
		n=(n*n)%m;
		p/=2;
	}
	return b;
}
ll num[214514];
int main(){
	ll n,m,k;
	cin>>n>>m>>k;
	ll ans=0,mod=998244353;
	num[0]=1;
	for(int i=1;i<=n-1;i++)num[i]=(num[i-1]*i)%mod;
	for(int i=0;i<=k;i++){
		ll x=m*gya(m-1,n-i-1,mod);
		x%=mod;
		x=(((x*num[n-1])%mod*gya(num[i],mod-2,mod))%mod*gya(num[n-1-i],mod-2,mod))%mod;
		ans=(ans+x)%mod;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5160
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e8;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, l, r;
  while (cin >> n >> l >> r) {
    if (n == 0 && l == 0 && r == 0) break;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    loop(i, l, r + 1) {
      bool flag = true;
      rep(j, n) {
        if (i % a[j] == 0) {
          if ((j + 1) % 2 == 1) ans++;
          flag = false;
          break;
        }
      }
      if (flag && n % 2 == 0) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3100
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val N, M = sc.nextInt()
  val graph = Array.fill[List[Int]](N+1)(Nil)
  for (_ <- 1 to M) {
    val a, b = sc.nextInt()
    graph(a) = b :: graph(a)
    graph(b) = a :: graph(b)
  }

  if(dfs(1, 0))
    println("POSSIBLE")
  else
    println("IMPOSSIBLE")

  def dfs(node: Int, cnt: Int): Boolean = {
    if (node == N)
      true
    else {
      if(cnt == 2)
        false
      else
        graph(node).map(dfs(_, cnt+1)).exists(identity)
    }
  }
}


Measured memory_bytes: 131196
#include<bits/stdc++.h>
using namespace std;
/**
 * 细节+阅读理解题
 * [main description]
 * @return [description]
 */
int main(){
	int n;
	cin>>n;
	int k;
	int mp[10];
	int f=0;
	int cnt=0;	
	for(int i=1;i<=8;++i)mp[i]=0;
	for(int i=1;i<=n;++i){
		cin>>k;
		if(k>=1&&k<=399){
			mp[1]++;
		}
		if(k>=400&&k<=799){
			mp[2]++;
		}
		if(k>=800&&k<=1199){
			mp[3]++;
		}
		if(k>=1200&&k<=1599){
			mp[4]++;
		}
		if(k>=1600&&k<=1999){
			mp[5]++;
		}
		if(k>=2000&&k<=2399){
			mp[6]++;
		}
		if(k>=2400&&k<=2799){
			mp[7]++;
		}
		if(k>=2800&&k<=3199){
			mp[8]++;
		}
		if(k>=3200){
			f++;
		}
	}
	for(int i=1;i<=8;++i){
		if(mp[i]!=0)cnt++;
	}
	if(f==0&&cnt!=0){
		printf("%d %d\n",cnt,cnt);
	}
	else if(f!=0&&cnt==0){
		printf("%d %d\n",1,f);	
	}
	else if(f!=0&&cnt!=0){
		printf("%d %d\n",cnt,cnt+f);
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        Set<Integer> added = new HashSet<>();
        for (int i = n.length - 1; i >= 0; i--) {
            int sum = 0;
            for (int x = 2; (i + 1) * x <= N; x++) {
                if (added.contains((i + 1) * x)) {
                    sum++;
                }
            }
            if (n[i] == 1) {
                if (sum % 2 == 0) {
                    added.add(i + 1);
                }
            } else {
                if (sum % 2 == 1) {
                    added.add(i + 1);
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int i: added) {
            sb.append(i);
            sb.append(' ');
        }
        System.out.println(added.size());
        System.out.println(sb.toString().trim());
    }

}


Measured memory_bytes: 79860
n = int(input())
d = {}
for i in range(n):
    s = input()
    try:
        d[s] += 1
    except:
        d[s] = 1

m = int(input())
for i in range(m):
    t = input()
    try:
        d[t] -= 1
    except:
        d[t] = -1

max_num = 0
for item in d.items():
    if item[1] > max_num:
        max_num = item[1]

print(max_num)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	res := "A"
	str := "abcdefghijklmnopqrstuvwxyz"
	if strings.Contains(str, s) {
		res = "a"
	}

	
	

	fmt.Println(res)
}


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

typedef long long LL;

const int N = 1e5 + 10;

int n, a[N], x, y;
LL ans;

int main(){
    while(~scanf("%d", &n)){
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
        }
        sort(a, a+n);
        LL ans = a[n-1] - a[0];
        x = a[0];
        y = a[n-1];
        int j = 1, k = n - 2;
        while(j <= k){
            if(y - a[j] < a[k] - x){
                ans = ans + a[k] - x;
                x = a[k];
                k--;
            } else {
                ans = ans + y - a[j];
                y = a[j];
                j++;
            }
            if(x > y)   swap(x, y);
        }
        printf("%lld\n", ans);
    }
	return 0;
}


Measured memory_bytes: 640
IDENTIFICATION DIVISION.
PROGRAM-ID. 096C.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 INP     PIC  X(30).
01 A       PIC  9(4) COMP.
01 B       PIC  9(4) COMP.
01 C       PIC  9(4) COMP.
01 X       PIC  9(6) COMP.
01 Y       PIC  9(6) COMP.
01 SA      PIC  9(6) COMP.
01 BIG     PIC  9(4) COMP.
01 MAX     PIC  9(10) COMP.
01 CNT     PIC  9(10) COMP.
01 OUT     PIC  Z(9)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO A B C X Y. 
*>
  COMPUTE MAX = A * X + B * Y.
  IF (X >= Y)
    MOVE A TO BIG
    COMPUTE SA = X - Y
  ELSE
    MOVE B TO BIG
    COMPUTE SA = Y - X
  END-IF
*>
  IF (A + B <= C * 2)
    MOVE MAX TO CNT
  ELSE
    COMPUTE CNT = MAX - (A + B - C * 2) * FUNCTION MIN(X, Y)
  *> 
    IF (BIG > C * 2)
      COMPUTE CNT = CNT - (BIG - C * 2) * SA
    END-IF 
  END-IF. 
*>---
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 636
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int a[3];
  int i,sum=0;
  for(i=0;i<3;i++)
  {
    scanf("%d",&a[i]);
  }
  for(i=0;i<3;i++)
  {
    sum=sum+a[i];
  }
  if(sum<22)
  {
      printf("win");
  }
  else
    {
        printf("bust");
    }
}


Measured memory_bytes: 128
import sys

str = input()
char_list = list(str)
i = 0
for item in char_list:
    i += 1
    if (i % 2 == 0 and item == 'R'):
        print("No")
        sys.exit()
    if (i % 2 == 1 and item == 'L'):
        print("No")
        sys.exit()
print("Yes")
    	

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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18L+9
#define inf 1e9L+9
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()

const int mod=1e9L+7; 
const int nax=1e5L+5; 

void solve(){
  int n; cin>>n; 
  vector<int> v(n), c1(nax,0), c2(nax,0); 
  for(int i=0;i<n;i++) {
    cin>>v[i]; 
    if(i&1) c1[v[i]]++; 
    else c2[v[i]]++; 
  }
  int f1=0,f2=0,s1=0,s2=0; 
  int a,b; 
  for(int i=0;i<nax;i++){
    if(c1[i]>f1) {
      s1=f1; f1=c1[i]; 
      a=i; 
    }
    else if(c1[i]>s1) {
      s1=c1[i]; 
    }
    if(c2[i]>f2){
      s2=f2; f2=c2[i]; 
      b=i; 
    }
    else if(c2[i]>s2){
      s2=c2[i]; 
    }
  }
  if(a!=b){
    cout<<n-(f1+f2)<<endl; 
  }
  else {
    cout<<n-(max(f1+s2,f2+s1))<<endl; 
  }
}

int main()
{
	fast_io;
	clock_t beg=clock(); 
	solve(); 
	clock_t end=clock(); 
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
	return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end



int main(){
   int h,w; scanf("%d%d",&h,&w);
   int cnt=0;
   rep(i,0,h)rep(j,0,w){
      char c; cin>>c;
      if(c=='#')cnt++;
   }
   if(cnt==h+w-1)puts("Possible");
   else puts("Impossible");
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    char b, c[128];
    cin >> b;
  
    c['A'] = 'T';
    c['G'] = 'C';
    c['C'] = 'G';
    c['T'] = 'A';
 
    cout << c[b] << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
using namespace std;
int x;

int main()
{
    scan(x);
    double kyu=8-(((double)x-599)/200);
    cout<<floor(kyu)<<endl;

}


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

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};



int main() {
    int N;
    cin >> N;
    int count = 0;
    vector< vector<int> > p(N, vector<int>(N));
    vector< vector<int> > b(N, vector<int>(N));
    rep(i,ceil((double)N/2)){
        for(int j=i;j<N-i;j++){
            p[i][j] = i;
            p[j][i] = i;
            p[N-i-1][j] = i;
            p[j][N-i-1] = i;
        }
    }
    queue<P> q;

    rep(k,N*N){
        int t;
        cin >> t;
        int i = (t-1) / N;
        int j = (t-1) % N;
        
        count += p[i][j];
            

        b[i][j] = 1;
        q.push(make_pair(i,j));
        // cout << "exit:" << i << j << endl;
        while(!q.empty()){
            P pr = q.front();
            rep(s,4){
                int nx = pr.first + dx[s];
                int ny = pr.second + dy[s];
                if(nx>=0 && nx < N && ny >= 0 && ny < N){
                    if(p[pr.first][pr.second] < p[nx][ny] && b[pr.first][pr.second] == 1){
                        p[nx][ny] = p[pr.first][pr.second];
                        q.push(make_pair(nx,ny));
                        // cout << nx << ny << endl;
                    }else if(p[pr.first][pr.second]+1 < p[nx][ny] && b[pr.first][pr.second] == 0){
                        p[nx][ny] = p[pr.first][pr.second] + 1;
                        q.push(make_pair(nx,ny));
                        // cout << nx << ny << endl;
                    }
                }
            }
            // p[pr.first][pr.second]
            q.pop();
        }
        // rep(x,N){
        //     rep(y,N){
        //         cout << p[x][y];
        //     }
        //     cout << endl;
        // }
    }


    cout << count << endl;
    return 0;
}

Measured memory_bytes: 5544
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<stack>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
#define MAX 510000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;


int main(){
  ll X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  
  vector<ll> P,Q,PQR;
  
  REP(i,A){
    ll a;
    cin>>a;
    P.push_back(a);
  }
  
  REP(i,B){
    ll a;
    cin>>a;
    Q.push_back(a);
  }
  
  REP(i,C){
    ll a;
    cin>>a;
    PQR.push_back(a);
  }
  
  SORT(P);
  REVERSE(P);
  
  SORT(Q);
  REVERSE(Q);
  
  REP(i,X) PQR.push_back(P.at(i));
  REP(i,Y) PQR.push_back(Q.at(i));
  
  SORT(PQR);
  REVERSE(PQR);
  
  ll ans=0;
  REP(i,X+Y) ans+=PQR.at(i);
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7536
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793

/*int main()
{
    ll n;
    ll k;
    cin >> n;
    cin >> k;
    vector<ll> a(n+1);
    rep(cnt, 1, n) {
        cin >> a[cnt];
    }
    vector<ll>load;
    load.push_back(1);
    rep(cnt, 0, n-1) {
        load.push_back(a[load[cnt]]);
    }
    rep(cnt, 0, load.size()) {
        cout << load[cnt] << endl;
    }


    return 0;
}*/

int main()
{
    ll n;
    ll m;
    ll x;
    cin >> n;
    cin >> m;
    cin >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    vector<ll>check(n);
    
    ll min = -1;
    ll money = 0;
    rep(i, 0, n) {
        cin >> c[i];
        rep(j, 0, m) {
            cin >> a[i][j];
        }
    }

    for (ll cnt = 1; cnt <= pow(2, n);cnt++) {
        vector<ll>learn(m, 0);
        money = 0;
        ll p = cnt;
        rep(i, 0, n) {
            check[i] = p % 2;
            p /= 2;
        }
        rep(i, 0, n) {
            if (check[i] == 1) {
                money += c[i];
                rep(j, 0, m) {
                    learn[j] += a[i][j];
                }
            }
        }
        sort(learn.begin(), learn.end());
        if (learn[0] >= x ) {
            if (min == -1) {
                min = money;
            }
            else if (min > money) {
                min = money;
            }

        }
        
    }
    cout << min << endl;

    return 0;
}

Measured memory_bytes: 4108
use proconio::*;
use proconio::marker::Usize1;

#[fastout]
fn run() {
    input! {
        n: usize,
        p: [Usize1; n - 1],
    }
    let mut size = vec![0; n];
    for &p in p.iter() {
        size[p] += 1;
    }
    for s in size {
        println!("{}", s);
    }
}

fn main() {
    run();
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int ans=-1*inf;

  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10, 0));
  vector<vector<int>> p(n, vector<int>(11, 0));
  for (int i=0; i<n; i++) {
    for (int j=0; j<10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<11; j++) {
      cin >> p[i][j];
    }
  }

  for (int i=1; i<(1<<10); i++) {
    int sum=0;
    for (int j=0; j<n; j++) {
      int cnt=0;
      for (int k=0; k<10; k++) {
        if ((i>>k&1)==1 && f[j][k]==1) {
          cnt++;
        }
      }
      sum+=p[j][cnt];
    }
    ans = max(ans, sum);
  }

  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> a(q);
    for(int i=0;i<q;i++){
        int ai;
        cin>>ai;
        a[i]=ai-1;
    }
    vector<int>memo(n,k-q);
    for(int i=0;i<q;i++){
        memo[a[i]]++;
    }
    for(int i=0;i<n;i++){
       if(memo[i]>0){
           cout<<"Yes"<<endl;
       } else{
           cout<<"No"<<endl;
       }
    }
    return 0;
}

Measured memory_bytes: 1408
n,t = map(int, input().split())
ls = [list(map(int, input().split())) for i in range(n)]
t-=1
dp1 = [[0 for _ in range(t+1)] for _ in range(n+1)]
for i in range(n+1):
    for j in range(t+1):
        if i>0 and j>=ls[i-1][0]:
                dp1[i][j] = max(dp1[i-1][j-ls[i-1][0]] + ls[i-1][1] ,dp1[i-1][j])

        elif i>0:
            dp1[i][j] = dp1[i-1][j]

dp2 = [[0 for _ in range(t+1)] for _ in range(n+1)]
for i in range(n, -1, -1):
    for j in range(t+1):
        if i<n and j>=ls[i][0]:
                dp2[i][j] = max(dp2[i+1][j-ls[i][0]] + ls[i][1] ,dp2[i+1][j])

        elif i<n:
            dp2[i][j] = dp2[i+1][j]

ans=0
for i in range(n):
    for j in range(t):
        ans = max(dp1[i][j] + dp2[i+1][t-j] + ls[i][1],ans)


print(ans)

Measured memory_bytes: 194564
a=[True]*104743
p=[]
for i in range(2,int(104743**0.5)+1):
    if a[i]:
        for j in range(i*i,104743,i):a[j]=False
for i in range(2,104730):
    if a[i]:p.append(i)
while 1:
    n=int(input())
    if n==0:break
    print(sum(p[:n]))

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

int main()
{
    int a[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int k;
    scanf("%d",&k);
    printf("%d\n",a[k-1]);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//-10 8 2 1 2 6
//4だとして？
//40,31,22,13,04で取れる。
//3個とって１個戻せる
// (4-1)/2=1まで戻す可能性ある。5個とるなら２個戻すとか。
//そんなことないか。4/2=2個もどすか　5/2=2か
//50個の１００通りなら全探索できそう
//全部の累積和とって、6 4 なら２個ずつ引く。
//３個とって戻すなら？累積和から３とって、一番低い要素を1個抜く
//-10 8 2 1 2 6 -20 8 3 4 2 1
//12 8とか
//8とるか、7とって１戻すか、6とって２戻すか、5とって３戻すか、４とって４戻すか。
//50,100だと
//100とる?、50とって50=0戻す、49とって51=1戻す..
//50C1+50C2+...50!くらいありえる。大きすぎるかも
//違うか。とりかたはせいぜい50通り+50とか。
//とったら、つどsortしてlower?
//負だけ取り除く感じ。
//最小は、Kは偶数だったら0、奇数だったら1
//全探索でまにあっちゃうかな
//再帰で全通り可能？めもりたらなそう
//左からなんこ、右からなんことって、なんこもどす、みたいな。
//戻す数？50100だったら、25個もどすとかか50個もどす、までか。
//50 30なら？30/2=15個まで
//sortしておしりからとってくるかんじ？本当に原始的すぎて･･･
//5,6 4個しかとれないN-K)%2が重要か
//5,8なら5,6とおなじ 5,10も5,12も。
//-1 -2 -3 -4 5 -6 -7 -8 -9 -10
//問題読み違えていた。K回まで操作を行うことが出来ます･･･。
int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> base(N,0);
  for(int i=0; i<N; i++){
    ll V; cin>>V; base[i]=V;
  }
  ll ans=0, back=min(N,K/2);
  for(int i=0; i<=back; i++){//戻す数
    ll take=min(N,K-i);
    for(int t=i; t<=take; t++){
      for(int lft=0; lft<=t; lft++){//左からとる個数
        ll tmp=0;
        vector<ll> W(0,0);
        for(int j=0; j<lft; j++){
          W.emplace_back(base[j]);
          tmp+=base[j];
        }
        for(int j=0; j<t-lft; j++){
          W.emplace_back(base[N-1-j]);
          tmp+=base[N-1-j];
        }
        sort(W.begin(), W.end());
        for(int j=0; j<i; j++)
          tmp-=W[j];
        ans=max(ans,tmp);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
// Pencils 2018/12/27

#include <cstdio>
using namespace std;

int main() {
    int N, A, B, C, D;
    int x, y;

    scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);

    x = (N / A) * B;
    if (N % A) x += B;

    y = (N / C) * D;
    if (N % C) y += D;

    if (x <= y) printf("%d\n", x);
    else printf("%d\n", y);

    return 0;
}


Measured memory_bytes: 2736
# 2019/04/23
# AtCoder Beginner Contest 115 - C

# Input
n, k = map(int, input().split())
h = list()

for i in range(n):
    h.append(int(input()))

h.sort()

minh = h[n-1]
for i in range(n - k + 1):
    rng = h[i+k-1] - h[i]
    if rng < minh:
        minh = rng

print(minh)


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

int main() {
	int K,i=0,amari=0;
	int count = 0;
	cin >> K;
	
	while (i <= 1000000) {
		count++;
		amari = (amari*10+7)% K;
		if (amari == 0) {
			cout << count << endl;
			return 0;
		}
		
		i++;
		
	}
	cout << "-1" << endl;

	return 0;

}

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

const int maxn = 100, P = 1000000007;
int n, a[maxn], f[maxn][maxn][maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= 2 * n - 1; i++) {
        scanf("%d", &a[i]);
    }
    sort(a + 1, a + 2 * n);
    for (int i = 0; i <= 2 * n - 1; i++) {
        for (int j = 0; j <= 2 * n - 1; j++) f[1][i][j] = 1;
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= 2 * n - 1; j++) {
            for (int k = 0; k <= 2 * n - 1; k++) {
                int nj = j + (a[i] != a[i - 1]);
                int nk = k + (a[2 * n - i] != a[2 * n - i + 1]);
                f[i][j][k] = f[i - 1][nj][nk];
                for (int l = 1; l <= nj; l++) {
                    (f[i][j][k] += f[i - 1][nj - l][nk + 1]) %= P;
                }
                for (int l = 1; l <= nk; l++) {
                    (f[i][j][k] += f[i - 1][nj + 1][nk - l]) %= P;
                }
            }
        }
    }
    printf("%d\n", f[n][0][0]);
    return 0;
}

Measured memory_bytes: 5744
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

x=ii()

if x>=30:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10484
def odd_solve(n):
    return (n + 1) // 2 % 2

def solve(n):
    if n % 2 == 1:
        return odd_solve(n)
    else:
        return odd_solve(n + 1) ^ (n + 1)

a, b = map(int, input().split())
ans = solve(b) ^ solve(a - 1)
print(ans)


Measured memory_bytes: 2940
# import sys
N = int(input())
S,T = input().split()

# if not ( 1 <= N <= 100 ): sys.exit()
# if not ( len(S) == len(T) and len(S) == N ): sys.exit()
# if not ( S.islower() and T.islower() ): sys.exit()

for I in range(N):
    print(S[I],end='')
    print(T[I],end='')

Measured memory_bytes: 9068
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int M1 = scn.nextInt(), D1 = scn.nextInt(), M2 = scn.nextInt();
		System.out.println((M1==M2)?0:1);
	}

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n];
	vector<ll> b(m);
	for (int i = 0; i < n; ++i)
	{
		scanf("%lld", &a[i]);
	}
	for (int i = 0; i < m; ++i)
	{
		scanf("%lld", &b[i]);
	}
	for (int i = 1; i < m; ++i)
	{
		b[i] += b[i-1];
	}
	ll sum = 0;
	ll ans;
	auto it = upper_bound(b.begin(),b.end(),k);
	ans = it-b.begin();
	for (int i = 0; i < n; ++i)
	{
		sum += a[i];
		if(sum>k)
			break;
		it = upper_bound(b.begin(),b.end(),k-sum);
		ll e = i+1+it-b.begin();
		ans = max(ans,e);
	}
	printf("%lld\n", ans);
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 6500
class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 10 ** 9 + 7
mc = ModComb(200010, mod=mod)

H, W, A, B = map(int, input().split())

x, y, a = H - A - 1, W + A - 2, A - 1
print(sum(mc.nCk(x + i, i) * mc.nCk(y - i, a) for i in range(B, W)) % mod)


Measured memory_bytes: 27080
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;

int n,m,a[81][81],b[81][81];
bool dp[81][81][13010];

int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>b[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==1&&j==1){
				dp[1][1][6500+a[1][1]-b[1][1]]=1;
				dp[1][1][6500+b[1][1]-a[1][1]]=1;
				continue;
			}
			if(j>=2){
				for(int l=0;l<=13000;l++){
					if(l+a[i][j]-b[i][j]>=0&&l+a[i][j]-b[i][j]<=13000) dp[i][j][l]|=dp[i][j-1][l+a[i][j]-b[i][j]];
					if(l-a[i][j]+b[i][j]>=0&&l-a[i][j]+b[i][j]<=13000) dp[i][j][l]|=dp[i][j-1][l-a[i][j]+b[i][j]];
				}
			}
			if(i>=2){
				for(int l=0;l<=13000;l++){
					if(l+a[i][j]-b[i][j]>=0&&l+a[i][j]-b[i][j]<=13000) dp[i][j][l]|=dp[i-1][j][l+a[i][j]-b[i][j]];
					if(l-a[i][j]+b[i][j]>=0&&l-a[i][j]+b[i][j]<=13000) dp[i][j][l]|=dp[i-1][j][l-a[i][j]+b[i][j]];
				}
			}
		}
	}
	int minv=INF;
	for(int i=0;i<=13000;i++) if(dp[n][m][i]) minv=min(minv,abs(6500-i));
	cout<<minv<<endl; 
	return 0;
}

Measured memory_bytes: 82560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1]) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    s1 = s[:n]
    s2 = s[n:][::-1]
    d1 = collections.defaultdict(int)
    d2 = collections.defaultdict(int)
    ii = [2**_ for _ in range(n)]
    for i in range(2**n):
        t = t2 = t3 = t4 = ','
        for j in range(n):
            if ii[j] & i:
                t += s1[j]
                t3 += s2[j]
            else:
                t2 += s1[j]
                t4 += s2[j]
        d1[t+t2] += 1
        d2[t3+t4] += 1
    r = 0
    for k in d1.keys():
        r += d1[k] * d2[k]

    return r


print(main())


Measured memory_bytes: 154424
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] A = new int[2][n];
        int[] sum1 = new int[n];
        int[] sum2 = new int[n];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                A[i][j] = sc.nextInt();

                if (i == 0) {
                    sum1[j] = A[i][j];
                    if (j > 0) sum1[j] += sum1[j-1];
                }
                if (i == 1) {
                    sum2[j] = A[i][j];
                    if (j > 0) sum2[j] += sum2[j-1];
                }
            }
        }

        int max = 0;
        for (int i = 0; i < n; i++) {
            int tmp = sum1[i] + sum2[n-1];
            if (i > 0) tmp -= sum2[i-1];
            max = Math.max(max , tmp);
        }

        System.out.println(max);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI  3.14159265358979323846

ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
ll lcm(ll x,ll y)
{
    ll P=x*y;
    P/=gcd(x,y);
    return P;
}
int main()
{
    ll i,n,M;
    cin>>n>>M;
    ll A[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }
    ll res=A[0]/2;
    A[0]/=2;
    for(i=1;i<n;i++)
    {
        A[i]/=2;
        res=lcm(res,A[i]);
    }
    ll ok=1;
    for(i=0;i<n;i++)
    {
        ll u=A[i];
        ll y=res/u;
        if(y%2==0)
        {
            ok=0;
            break;
        }
    }
    if(ok==1)
    {
    ll g=M/res;
    if(g==0)
    {
        cout<<0;
    }
    else
    {
        if(g%2==0)
        {
            cout<<g/2;
        }
        else
        {
            cout<<(g/2)+1;
        }
    }
    }
    else
    {
        cout<<0;
    }

}



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

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int N;
vector<P> G[100001];
bool visit[100001];
int ans[100001];

void dfs(int v, int c) {
  visit[v] = true;
  ans[v] = c;
  REP(i, G[v].size()) {
    if (visit[G[v][i].first]) continue;
    if (G[v][i].second == 0)
      dfs(G[v][i].first, c);
    else
      dfs(G[v][i].first, c ^ 1);
  }
}

int main() {
  cin >> N;
  REP(i, N - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u - 1].push_back(P(v - 1, w % 2));
    G[v - 1].push_back(P(u - 1, w % 2));
  }
  dfs(0, 0);
  REP(i, N) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 8448
N=int(input())
P= list(map(int, input().split()))
Q= list(map(int, input().split()))
if P==Q:
  print(0)
  exit()
dic=[]
Pn=0
Qn=0
import itertools
import numpy
l=numpy.arange(1,N+1,1,int)
for v in itertools.permutations(l, N):
  dic.append(v)
for i in range(len(dic)):
  if list(dic[i])==P:
    Pn=i
  elif list(dic[i])==Q:
    Qn=i
  elif Pn!=0 and Qn!=0:
    break
print(abs(Pn-Qn))

Measured memory_bytes: 31892
package main

import (
	"fmt"
	"container/heap"
)

const infinity int64 = 1000 * 1000 * 1000 * 1000

func main() {
	var n, m int64
	fmt.Scanf("%d %d", &n, &m)
	uvs := make([]uv, m)
	for i := range iter(0, m) {
		fmt.Scanf("%d %d", &(uvs[i].u), &(uvs[i].v))
		uvs[i].u -= 1
		uvs[i].v -= 1
	}
	var s, t int64
	fmt.Scanf("%d %d", &s, &t)

	edgess := make([][]edge, n*3)
	for _, uv := range uvs {
		for i := range iter(0, 3) {
			from := uv.u + n*i
			edge := edge{
				from: from,
				to:   uv.v + n*((i+1)%3),
				cost: 1,
			}
			edgess[from] = append(edgess[from], edge)
		}
	}
	ans := dijkstra(n*3, edgess, s-1, t-1)
	if ans == infinity {
		fmt.Println(-1)
	} else {
		fmt.Println(ans / 3)
	}
}

type uv struct {
	u int64
	v int64
}

func dijkstra(n int64, edgess [][]edge, start int64, goal int64) int64 {
	pq := make(priorityQueue, 0)
	heap.Init(&pq)
	for _, edge := range edgess[start] {
		e := qElem{
			priority: edge.cost,
			content:  edge,
		}
		heap.Push(&pq, &e)
	}
	shortests := make([]int64, n)
	for i := range iter(0, n) {
		shortests[i] = infinity
	}
	shortests[start] = 0
	for pq.Len() > 0 {
		elem := heap.Pop(&pq).(*qElem)
		edge := elem.content.(edge)
		if shortests[edge.to] != infinity {
			continue
		}
		shortests[edge.to] = shortests[edge.from] + edge.cost
		if edge.to == goal {
			break
		}
		for _, nextEdge := range edgess[edge.to] {
			e := qElem{
				priority: shortests[edge.to] + nextEdge.cost,
				content:  nextEdge,
			}
			heap.Push(&pq, &e)
		}
	}
	return shortests[goal]
}

type edge struct {
	from int64
	to   int64
	cost int64
}

type qElem struct {
	priority int64
	content  interface{}
}

type priorityQueue []*qElem

func (pq priorityQueue) Len() int { return len(pq) }
func (pq priorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}
func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*qElem))
}

func (pq *priorityQueue) Pop() interface{} {
	old := *pq
	item := old[len(old)-1]
	old[len(*pq)-1] = nil
	*pq = old[0 : len(old)-1]
	return item
}

func iter(l int64, r int64) chan int64 {
	var i int64 = l
	c := make(chan int64)
	run := func() {
		for i < r {
			c <- i
			i += 1
		}
		close(c)
	}
	go run()
	return c
}


Measured memory_bytes: 41344
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,cnt[4],cnt1[4];
	double migi,hidari;
	for(i=0;i<4;i++) {
		cnt[i]=0;
		cnt1[i]=0;
	}
	while(scanf("%lf %lf",&hidari,&migi)!=EOF) {
		if(hidari>=1.1) cnt[0]++;
		if(hidari<1.1 && hidari>=0.6) cnt[1]++;
		if(hidari<0.6 && hidari>=0.2) cnt[2]++;
		if(hidari<0.2) cnt[3]++;
		if(migi>=1.1) cnt1[0]++;
		if(migi<1.1 && migi>=0.6) cnt1[1]++;
		if(migi<0.6 && migi>=0.2) cnt1[2]++;
		if(migi<0.2) cnt1[3]++;
	}
	for(i=0;i<4;i++) printf("%d %d\n",cnt[i],cnt1[i]);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> candy(2, vector<int>(n)), dp(2, vector<int>(n, 0));
    rep(i, 2) rep(j, n) cin >> candy.at(i).at(j);
    dp.at(0).at(0) = candy.at(0).at(0);
    rep(i, n - 1) dp.at(0).at(i + 1) = dp.at(0).at(i) + candy.at(0).at(i + 1);
    dp.at(1).at(0) = candy.at(0).at(0) + candy.at(1).at(0);
    rep(i, n - 1) dp.at(1).at(i + 1) = max(dp.at(0).at(i + 1), dp.at(1).at(i)) + candy.at(1).at(i + 1);
    cout << dp.at(1).at(n - 1) << endl;
}

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

using namespace std;

#define print(s) cout << (s) << endl;
#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n) 
#define all(a) (a).begin(), (a).end()
#define inf 10000000
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a, b, c; cin>>a >>b>>c;
    transform(all(a), a.begin(), ::toupper);
    transform(all(b), b.begin(), ::toupper);
    transform(all(c), c.begin(), ::toupper);
    cout<<a[0]<<b[0]<<c[0]<<endl;
return 0;
}

Measured memory_bytes: 256