akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main(){
	int n;
  	cin >> n;
	int g[15][15];
  	rep(i, n)rep(j, n) g[i][j] = -1;
  	rep(i, n){
    	int a;
      	cin >> a;
      	rep(j, a){
        	int x, y;
          	cin >> x >> y;
          	x--;
          	g[i][x] = y;
        }
    }
	
  	int ans = 0;
  	rep(i, 1<<n){
    	vector<int> d(n);
      	rep(j, n) if(i>>j&1){
        	d[j] = 1;
        }
      	
      	bool ok = true;
      	rep(j, n){
        	if(d[j]){
            	rep(k, n){
                	if(g[j][k] == -1) continue;
                  	if(g[j][k] != d[k]) ok = false;
                }
            }
        }
      
      	if(ok) ans = max(ans, __builtin_popcount(i));
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>

int main(){
    int x,y;
    while(3000){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0)break;
        if(x<y){
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}


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

int main(){
  int q;cin>>q;
  vector<int> prime(2e5,1);
  prime[0]=0,prime[1]=0;
  for(int i=2;i<2e5;i++){
    if(prime[i]){
      for(int j=i*2;j<2e5;j+=i)prime[j]=0;
    }
  }
  vector<int> a(2e5);
  rep(i,2e5){
    if(i%2==0)continue;
      if(prime[i]&&prime[(i+1)/2])a[i]=1;
    }
  vector<int> vec(2e5+1);
  rep(i,2e5)vec[i+1]=vec[i]+a[i];
  rep(i,q){
    int l,r;cin>>l>>r;
    r++;
    cout<<vec[r]-vec[l]<<endl;
  }
}

Measured memory_bytes: 5592
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
    while(b){
        ll t = a / b;
        a -= b * t;
        swap(a, b);
    }
    return a;
}

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        ll a, b, c, d;
        scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

        if (a < b || d < b) printf("No\n");
        else if (c >= b - 1) printf("Yes\n");
        else{
            ll g = gcd(b, d);
            ll k = (a - (c + 1 - b)) / g;
            if (a - k * g >= 0) printf("Yes\n");
            else printf("No\n");
        }
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
//R 82 L 76
	static int v[]=new int[501];
	static long D=0;
	public static void main(String[] args) {
			int n=sc.nextInt();
			Map<String, Integer> map = new HashMap<String, Integer>(n);
			int ans=0;
			for(int i=0;i<n;i++) {
				String a=sc.next();
				
				if(map.containsKey(a)) {
					
				}else {
					map.put(a, 1);
					ans++;
				}
			}
			p(ans);
			//String S=sc.next();
			
			//int a[]=new int[N];
			//for(int i=0;i<N;i++) {}
	}
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	//static int memo[][]=new int[501][1000];
	

	

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define all(a) (a).begin(), (a).end()

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  vector<int> hoge(5);
  rep(i,5)cin>>hoge[i];
  int k;cin>>k;
  sort(all(hoge));
  cout<<(hoge[4]-hoge[0]<=k ? "Yay!":":(")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)


int main(void){
	long double a,b;
	cin >> a >> b;
	a *=b;
	printf("%lld",(lld)a);
	return 0;
}


Measured memory_bytes: 3780
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  bool n = S.find('N') != S.npos;
  bool e = S.find('E') != S.npos;
  bool w = S.find('W') != S.npos;
  bool s = S.find('S') != S.npos;
  cout << (n == s && w == e ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
# coding=utf-8


class Dice(object):

    def __init__(self, label):
        self.label = label

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def match(self, top, front):
        iTop = self.label.index(top) + 1
        topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
        self.rotate(topRot[iTop])

        iFront = self.label.index(front) + 1
        frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
        self.rotate(frontRot[iFront])


def main():
    d = Dice(map(int, raw_input().split()))
    n = input()
    for _ in xrange(n):
        top, front = map(int, raw_input().split())
        d.match(top, front)
        print d.getLabel(3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int x,i=1;
		while(true){
			x=scan.nextInt();
			if(x==0) break;
			System.out.printf("Case %d: %d\n",i++,x);
		}
		scan.close();
	}
}

Measured memory_bytes: 53624
#include<stdio.h>
int main(void){
int a,b,c,d,e,f,g;
d=0;

scanf("%d %d",&a,&b);
for(c=0;c<b;c++){
    scanf("%d",&e);
  d=d+e;
}
if(d>a){
printf("-1");
}else{
    printf("%d",a-d);
}
}

Measured memory_bytes: 1736
import sys

def input():
    return sys.stdin.readline().rstrip('\n')


def calc(N, L):
    d = {}
    for l in L:
        d[l] = (d[l] if l in d else 0) + 1
    M = list(d.keys())
    M.sort(key = lambda x: -x)
    ans = 0
    for i in range(len(M)):
        for j in range(i + 1, len(M)):
            for k in range(j + 1, len(M)):
                if M[i] < M[j] + M[k]:
                    ans += d[M[i]] * d[M[j]] * d[M[k]]
    return ans


N = int(input())
L = [int(s) for s in input().split()]
print(calc(N, L))

Measured memory_bytes: 68484
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;



int main(){
	vi taro, hanako;
	int n, m;
	while(cin >> n >> m, n+m){
		vi taro, hanako;
		vi ans;
		int taroTotal = 0, hanakoTotal = 0;
		bool isPossible = false;
		int minSwap = 10000;
		
		for(int i=0; i < n; i++){
			int input;
			cin >> input;
			taro.push_back(input);
			taroTotal += input;
		}
		for(int i=0; i < m; i++){
			int input;
			cin >> input;
			hanako.push_back(input);
			hanakoTotal += input;
		}
		for(int i=0; i < n; i++){
			for(int j=0; j < m; j++){
				if(taroTotal-taro[i]+hanako[j] == hanakoTotal-hanako[j]+taro[i]){
					if(taro[i]+hanako[j] < minSwap){
						ans.clear();
						ans.push_back(taro[i]);
						ans.push_back(hanako[j]);
						minSwap = taro[i]+hanako[j];
						isPossible = true;
					}
				}
			}
		}
		if(isPossible) cout << ans[0] << " " << ans[1] << endl;
		else cout << -1 << endl;
		ans.clear();
	}
}

Measured memory_bytes: 1220
import sys

def InputData():

    data_len = int(input())
    # data = input().split()
    data = list(map(int, input().split()))

    searchdata_len = int(input())
    # searchdata = input().split()
    searchdata = list(map(int, input().split()))

    # data = int(data)
    # searchdata = int(searchdata)

    return data_len, data, searchdata_len, searchdata

def Liner_Search(data, key):

    contained_cnt = 0
    # for i in range(searchdata_len):
    for i in range(len(data)):
        if key == data[i]:
            return 1
    
    # return contained_cnt
    return "NOT_FOUND"

def PrintOut(contained_cnt):
    print(int(contained_cnt))

def main():
    [data_len, data, searchdata_len, searchdata] = InputData()
    count = 0
    for i in searchdata:
        if Liner_Search(data, i)  != "NOT_FOUND":
            count += 1
    
    PrintOut(count)

if __name__=='__main__':
    main()


Measured memory_bytes: 6556
#include<iostream>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

char name[]={'M','A','R','C','H'};
li v[]={0,0,0,0,0};

int main(){
  int n; cin >>n;
  rep(i,n){
    string s; cin >>s;
    if(df) print(s[0]);
    rep(j,5)
      if(s[0]==name[j]) v[j]++;
  }
  li ans=0;
  rep(i,3) repa(j,i+1,4) repa(k,j+1,5) ans+=v[i]*v[j]*v[k];
  if(df)rep(i,5) print(v[i]);
  print(ans);
}


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

const int N = 100100;
int n, a[N];
map<int,int> Pos;
int b[N];

int main()
{
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            b[i]=a[i];
        }
        sort(b+1,b+n+1);
        for(int i=1;i<=n;i++){
            Pos[b[i]]=i;
        }

        int cnt=0;
        for(int i=1;i<=n;i++){
            int mod1=Pos[a[i]]%2;
            int mod2=i%2;
            if (mod1!=mod2) cnt++;
        }
        cout<<cnt/2;
}   


Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<string.h>
#include<set>
#include<map>
#include<algorithm>
#include<iterator>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)

using ll = long long;
const int limit = 100010;
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
    depth[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, -1, 0);
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--, y--;
        cout << depth[x] + depth[y] << endl;
    }
    return 0;

}



Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  unordered_map<int, int> mp;

  for (int i = 2; i <= n; ++i)
  {
    int t = i;
    for (int j = 2; j * j <= t; ++j)
    {
      while (t % j == 0)
      {
        t /= j;
        mp[j]++;
      }
    }
    if (t != 1)
      mp[t]++;
  }
  ll cnt = 1;

  for (auto &e : mp)
  {
    cnt = (cnt * (e.second + 1) % MOD);
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
s = raw_input()

count = 0
a = 0
i = 0
l = len(s)
while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue

    if s[i] == 'B' and i < l - 1 and s[i + 1] == 'C':
        count += a
        i += 2
    else:
        a = 0
        i += 1

print count


Measured memory_bytes: 85044
#include<bits/stdc++.h>
using namespace std;
int main(){
    int  x,y;
    cin>>x>>y;
    long long  sum=0;
    for(int i=y+1;i<=x;i++){
        sum=sum+(i-y)*(x/i);
        if(x%i-y>=0)sum=sum+1+x%i-y;
    }
    if(y==0)sum=sum-x;
    cout<<sum<<endl;
    return 0;
}


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

long long n, k, mx, i;
int main()
{
	cin >> k >> n;
	for (i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			if ((n / i) * k <= n) {
				cout << n / i;
				return 0;
			}
			if (i * k <= n) mx = i;
		}
	}
    cout << mx;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;

int main(){

    int n, t, a; cin >> n >> t >> a;

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

    double min = 1e9;
    int index = 0;
    for(int i=0; i<n; i++){
        if(min > abs(a - t + h[i]*0.006)){
            min = abs(a - t + h[i]*0.006);
            index = i;
        }
    }

    cout << index+1;

    return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    ll N,A,B,C,D,E; cin >> N >> A >> B >> C >> D >> E;
    ll mn = min({A,B,C,D,E});
    ll ans = N/mn + 5 - (N%mn==0);
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

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

int main() {

	ll n; cin >> n;
	vector<ll> l(n);
	for (ll i = 0; i < n; i++) {
		cin >> l[i];
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			for (ll k = j + 1; k < n; k++) {
				if (l[i] == l[j]) continue;
				if (l[j] == l[k]) continue;
				if (l[k] == l[i]) continue;
				if (l[i] + l[j] <= l[k]) continue;
				if (l[j] + l[k] <= l[i]) continue;
				if (l[k] + l[i] <= l[j]) continue;
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A < 6)
    cout << 0 << endl;
  else if (A >= 6 && A <13)
    cout << B/2 << endl;
  else
    cout << B << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

string dp[256][128];
string S;

string mins(string s, string t)
{
    int a = SZ(s), b = SZ(t);
    if (a < b)
        return s;
    else if (a > b)
        return t;
    return min(s, t);
};

string f(int i, int depth)
{
    if (depth > 250)
        return string(400, 'a');

    if (i == SZ(S))
        return string(depth, ')');

    string& ans = dp[depth][i];
    if (ans != "a")
        return ans;

    ans = string(400, ' ');
    if (depth < 250)
        ans = mins(ans, "(" + f(i, depth + 1));

    if (depth > 0)
        ans = mins(ans, ")" + f(i, depth - 1));

    if (depth > 0 && S[i] == ')')
        ans = mins(ans, ")" + f(i + 1, depth - 1));

    if (S[i] == '(')
        ans = mins(ans, "(" + f(i + 1, depth + 1));
    return ans;
};

void solveSingleCase(int caseNo)
{
    int N;
    cin >> N;
    cin >> S;

    FOR(i, 0, 256)
        FOR(j, 0, 128)
            dp[i][j] = "a";

    cout << f(0, 0) << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 15872
use std::io;
use std::str::FromStr;

fn drawrectangle(h: i32, w: i32) {

    for i in 0..h {
        for j in 0..w {
            if i == 0 || j == 0 || i == h-1 || j == w-1 {
                print!("#");
            }
            else {
                print!(".");
            }
        }
        println!("");
    }
    println!("");
}

fn main() {

    for i in 1.. {
        let stdin = io::stdin();
        let mut buf = String::new();
        stdin.read_line(&mut buf).ok();
        let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());

        let h = it.next().unwrap() as i32;
        let w = it.next().unwrap() as i32;

        if w == 0 && h == 0 {
            break;
        }
        else {
            drawrectangle(h, w);
        }
    }
}



Measured memory_bytes: 5020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,m,sum;
    cin >> n >> m >> sum;
    for(int i = 0; i < m; i++)
        cout << sum  << ' ';
    if(sum != 1000000000)
        for(int i = m; i < n; i++)
            cout << sum+1 << ' ';
    else
        for(int i = m; i < n; i++)
            cout << sum-1 << ' ';
    return 0;
}


Measured memory_bytes: 3648
A, B = map(int, input().split())

from fractions import gcd
import math
from collections import Counter
from itertools import combinations

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

G = gcd(A, B)
if G == 1:
  print(1)
  exit()

D = [1] + list(Counter(prime_factorize(G)).keys())
print(len(D))

Measured memory_bytes: 5104
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main()
{
    int h[2], m[2], k;
    cin >> h[0] >> m[0] >> h[1]>> m[1] >> k;
    int a, b;
    a = 60 * h[0] + m[0];
    b = 60 * h[1] + m[1];
    cout << b - a -k << endl;
    return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) {return (n==0)?1:10*TEN(n-1);}

int main() {
    int n; ll x;
    cin >> n >> x;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll sm = x;
    for (int i = 0; i < n-1; i++) {
        sm += min(x, a[i+1] - a[i]);
    }
    cout << sm << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

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

  size_t n, m;
  cin >> n >> m;

  priority_queue <ll> q;
  rep (i, n)
  {
    ll a;
    cin >> a;
    q.push (a);
  }

  rep (i, m)
  {
    auto price = q.top ();
    q.pop ();
    price /= 2;
    q.push (price);
  }

  ll sum = 0;
  while (not q.empty ())
  {
    sum += q.top ();
    q.pop ();
  }
  cout << sum << endl;
}


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

using namespace std;

vector<pair<double, double>> v;
vector<int> mov_x;
vector<int> mov_y;

double Area(double t)
{
    double max_x = v[0].first + t*mov_x[0];
    double max_y = v[0].second + t*mov_y[0];
    double min_x = max_x;
    double min_y = max_y;

    for(int i = 1; i < v.size(); i++){
        double a = v[i].first + t*mov_x[i];
        if(a > max_x)
            max_x = a;
        else if(a < min_x)
            min_x = a;

        a = v[i].second + t*mov_y[i];

        if(a > max_y)
            max_y = a;
        else if(a < min_y)
            min_y = a;
    }

    return abs((max_x - min_x) * (max_y - min_y));
}

int main() {

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

    int n;
    cin >> n;

    v = vector<pair<double, double>>(n);
    mov_x = vector<int>(n, 0);
    mov_y = vector<int>(n, 0);

    for (int i = 0; i < n; ++i) {
        double a;
        double b;
        char l;
        cin >> a >> b >> l;

        v[i] = pair<double, double>(a, b);

        if(l == 'R')
            mov_x[i] = 1;
        else if(l == 'L')
            mov_x[i] = -1;
        else if(l == 'U')
            mov_y[i] = 1;
        else
            mov_y[i] = -1;
    }

    double L = 0;
    double R = pow(10, 16);

    for(int i = 0; i < 400; i++) {
        double m1 = L + (R - L)/3;
        double m2 = R - (R - L)/3;

        double a = Area(m1);
        double b = Area(m2);

        if(a > b)
            L = m1;
        else if(a < b)
            R = m2;
        else
            L = m1, R = m2;
    }

    cout.precision(11);
    cout << Area(L);

    return 0;
}

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

#define MAX 100
#define MMAX 5001

int X, Y, Z, A[MAX], V[MAX], E[MAX];

void compute(){
    float P[MMAX][MAX];
    for ( int i = 0; i < MMAX; i++ ){
	for ( int j = 0; j <= Y; j++ ) P[i][j] = 0;
    }
    P[0][0] = 1.0;

    int np, nv;

    for ( int j = 0; j < Y; j++ ){
	for ( int i = 0; i < MMAX; i++ ){
	    if ( P[i][j] == 0 ) continue;

	    for ( int k = 0; k < X; k++ ){
		np = min(Y, j + V[k]);
		nv = i;
		if ( E[np] == 1 ) {
		    np = min(Y, np + A[np]);
		} else if ( E[np] == 2 ){
		    nv = i + A[np];
		} else if ( E[np] == 3 ){
		    nv = max(0, i - A[np]);
		}

		P[nv][np] += P[i][j]*(1.0/X);
	    }
	}
    }

    double ex = 0;
    for ( int i = 0; i < MMAX; i++ ) ex += P[i][Y]*i;
    cout << (int)ex << endl;
}

main(){
    int n, e, a;
    while(1){
	cin >> X >> Y >> Z;
	if ( X == 0 && Y == 0 && Z == 0 ) break;
	for ( int i = 0; i <= Y; i++ ) A[i] = E[i] = 0;
	for ( int i = 0; i < X; i++ ) cin >> V[i];
	for ( int i = 0; i < Z; i++ ){
	    cin >> n >> e >> a;
	    A[n] = a;
	    E[n] = e;
	}
	compute();
    }
}

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

#define SENTINEL 20000000000

void merge(uint64_t A[], uint64_t L[], uint64_t R[], uint64_t n, uint64_t left, uint64_t mid, uint64_t right)
{
    uint64_t n1 = mid - left;
    uint64_t n2 = right - mid;
    for(uint64_t i = 0; i < n1; i++) L[i] = A[left + i];
    for(uint64_t i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    uint64_t i = 0;
    uint64_t j = 0;
    for(uint64_t k = left; k < right; k++)
    {
        if(L[i] <= R[j])
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

void mergeSort(uint64_t A[], uint64_t L[], uint64_t R[], uint64_t n, uint64_t left, uint64_t right)
{
    if(left+1 < right)
    {
        uint64_t mid = (left + right) / 2;
        mergeSort(A, L, R, n, left, mid);
        mergeSort(A, L, R, n, mid, right);
        merge(A, L, R, n, left, mid, right);
    }
}

int main()
{
    uint64_t N, K;
    cin >> N >> K;

    uint64_t h[N];
    uint64_t L[N/2+2];
    uint64_t R[N/2+2];

    for(uint64_t i = 0; i < N; i++) cin >> h[i];

    mergeSort(h, L, R, N, 0, N);

    uint64_t rs = 9999999999;
    for(uint64_t i = 0; i < N-K+1; i++)
    {
        uint64_t ttt = h[i+K-1] - h[i];
        if(ttt < rs) rs = ttt;
    }

    cout << rs << endl;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = sum(a)


def attack(i, j):
    global a
    global b

    if a[i] >= b[j]:
        a[i] -= b[j]
        b[j] = 0
    else:
        b[j] -= a[i]
        a[i] = 0


for i in range(n):
    attack(i, i)
    attack(i + 1, i)

print(total - sum(a))


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, k, s;
    cin >> n >> k >> s;
    for (int i = 0; i < n; ++i) {
        if (i < k) cout << s;
        else cout << (s == 1000000000 ? 1 : 1000000000);
        cout << " \n"[i + 1 == n];
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>

using namespace std;

int u[2000][2000];
int d[2000][2000];
int l[2000][2000];
int r[2000][2000];

int main(){

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++){
        cin >> S[i];
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#'){
                u[i][j] = 0;
            }
            else if(i == 0){
                u[i][j] = 1;
            }
            else{
                u[i][j] = u[i - 1][j] + 1;
            }
        }
    }

    for(int i = H - 1; i >= 0; i--){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#'){
                d[i][j] = 0;
            }
            else if(i == H - 1){
                d[i][j] = 1;
            }
            else{
                d[i][j] = d[i + 1][j] + 1;
            }
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#'){
                l[i][j] = 0;
            }
            else if(j == 0){
                l[i][j] = 1;
            }
            else{
                l[i][j] = l[i][j - 1] + 1;
            }
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = W - 1; j >= 0; j--){
            if(S[i][j] == '#'){
                r[i][j] = 0;
            }
            else if(j == W - 1){
                r[i][j] = 1;
            }
            else{
                r[i][j] = r[i][j + 1] + 1;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#'){
                continue;
            }

            int temp = u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3;
            ans = max(ans, temp);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 66816
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	int n, a[100000], ans = 0;
	bool check[100000] = { false };
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int i = 0;
	while (a[i] != 2) {
		if (check[a[i] - 1] == false) {
			check[a[i] - 1] = true;
			ans++;
			i = a[i] - 1;
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ll long long
using namespace std;

int main(){

    int k,x;
    cin >> k >> x;

    if(k * 500 >= x){

        cout << "Yes" <<endl;
    }else {
        cout << "No" << endl;
    }
    return 0;
}




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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

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

const int N = 11;
bool a[N][N][4];
char c[4] = {'R', 'D', 'L', 'U'};

int main() {
	//ios :: sync_with_stdio(0);

	for(int i = 0; i < 9; i ++) {
		string s; cin >> s;
		if(i & 1) {
			for(int j = 0; j < 5; j ++)
				if(s[j] == '1') {
					a[i / 2][j][1] = 1;
					a[i / 2 + 1][j][3] = 1;
				}
		} else {
			for(int j = 0; j < 4; j ++)
				if(s[j] == '1') {
					a[i / 2][j][0] = 1;
					a[i / 2][j + 1][2] = 1;
				}
		}
	}

	int x = 0, y = 0, d = 0;
	for(;;) {
		d = (d + 3) % 4;
		while(!a[x][y][d])
			d = (d + 1) % 4;
		//cout << x << ' ' << y << ' ' << d << '\n';
		x += dx[d]; y += dy[d];
		cout << c[d];
		if(!x && !y) break;
	}
	cout << '\n';

	return 0;
}

Measured memory_bytes: 3132
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut ans0 = 0;
    let mut sum = 0;
    for (i, &v) in a.iter().enumerate() {
        sum += v;
        if i % 2 == 0 && sum <= 0 {
            ans0 += 1 - sum;
            sum = 1;
        } else if i % 2 == 1 && sum >= 0 {
            ans0 += sum + 1;
            sum = -1;
        }
    }
    let mut ans1 = 0;
    sum = 0;
    for (i, &v) in a.iter().enumerate() {
        sum += v;
        if i % 2 == 1 && sum <= 0 {
            ans1 += 1 - sum;
            sum = 1;
        } else if i % 2 == 0 && sum >= 0 {
            ans1 += sum + 1;
            sum = -1;
        }
    }
    println!("{}", std::cmp::min(ans1, ans0));
}


Measured memory_bytes: 6396
#include<cstdio>
#include<cstring>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

const int N_MAX=3700000;

template<class T>
class Fenwick_tree_dual{
	int n;
	T a[N_MAX];

public:
	void build(int n){
		this->n=n;
		rep(i,n) a[i]=0;
	}

	void add(int i,int j,T v){
		if(i==0){
			for(;j>=0;j=(j&(j+1))-1) a[j]+=v;
			return;
		}
		add(0,j,v);
		add(0,i-1,-v);
	}

	T sum(int i){
		T s=0;
		for(;i<n;i|=i+1) s+=a[i];
		return s;
	}
};

int n;
static ll w[100000];
static int type[100000],x[100000];

Fenwick_tree_dual<ll> F;

void update(int t,int p){
	if(type[p]==0){
		F.add(t+1,t+1,1);
		F.add(t+2,t+2,-1);
		F.add(t+x[p]+1,t+x[p]+1,-1);
		F.add(t+x[p]+2,t+x[p]+2,1);
	}
	else if(type[p]==1){
		F.add(t+1,t+1,1);
		F.add(t+x[p]+1,t+x[p]+1,-x[p]-1);
		F.add(t+x[p]+2,t+x[p]+2,x[p]);
	}
	else{ // type 2
		F.add(t+1,t+1,1);
		F.add(t+2,t+x[p],2);
		F.add(t+x[p]+1,t+x[p]+1,(ll)(x[p]-1)*(x[p]-1)-2LL*x[p]*x[p]);
		F.add(t+x[p]+2,t+x[p]+2,x[p]*x[p]);
	}
}

int main(){
	int q; scanf("%d%d",&n,&q);
	rep(i,n) scanf("%lld%d%d",w+i,type+i,x+i);

	F.build(3700000);
	static int repaired[100000];
	memset(repaired,-1,sizeof repaired);

	int p=0;
	static ll a[3700000],b[3700000],z[3700000]; // a は z の差分, b は a の差分, F は b の差分
	rep(t,3660000){
		while(p<n && w[p]<=z[t]){
			update(t,p);
			repaired[p]=t;
			p++;
		}

		// 女の子が +1 する分
		F.add(t+1,t+1,1);
		F.add(t+2,t+2,-2);
		F.add(t+3,t+3,1);

		b[t+1]=b[t]+F.sum(t+1);
		a[t+1]=a[t]+b[t+1];
		z[t+1]=z[t]+a[t+1];
	}

	rep(i,n){
		if(repaired[i]!=-1 && repaired[i]<=3652425){
			printf("%d\n",repaired[i]);
		}
		else{
			puts("Many years later");
		}
	}
	while(q--){
		int y; scanf("%d",&y);
		printf("%lld\n",z[y]);
	}

	return 0;
}

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

int main() {
    int N, Q;
    long int K;
    scanf("%d %ld %d\n", &N, &K, &Q);

    long int criteria = -1;
    if (K <= Q) {
        criteria = Q - K;
    }

    int i;
    int a;
    int Ni[100001];
    memset(&Ni[0], 0, sizeof(Ni));

    for (i = 0; i < Q; i++) {
        scanf("%d", &a);
        Ni[a]++;
    }

    for (i = 1; i <= N; i++) {
        if (Ni[i] > criteria) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 1024
H, W = map(int, input().split())
S = [0] * H
for i in range(H):
    S[i] = input()

yoko = [[0] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        if yoko[i][j] != 0:
            continue
        elif S[i][j] == "#":
            yoko[i][j] = 0
        else:
            k = 0
            while S[i][j+k] == ".":
                k += 1
                if j+k == W:
                    break
            yoko[i][j:j+k] = [k] * k

tate = [[0] * W for i in range(H)]

for j in range(W):
    for i in range(H):
        if tate[i][j] != 0:
            continue
        elif S[i][j] == "#":
            tate[i][j] = 0
        else:
            k = 0
            while S[i+k][j] == ".":
                k += 1
                if i+k == H:
                    break
            for l in range(k):
                tate[i+l][j] = k

#for i in range(H):
#    print(tate[i])

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, yoko[i][j] + tate[i][j] - 1)

print(ans)

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

using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
char s[310];
int n,k,F[310][310][310];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	k=read();
	for(int i=1;i<=n;i++) F[i][i][0]=1;
	for(int i=1;i<n;i++)
	{
		F[i][i+1][0]=(s[i]==s[i+1])*2;
		F[i][i+1][1]=2;
	}
	for(int i=1;i<=n;i++)
	{
		for(int l=1;l+i-1<=n;l++)
		{
			int r=l+i-1;
			for(int ks=0;ks<=k;ks++)
			{
				if(l>1) F[l-1][r][ks]=max(F[l-1][r][ks],F[l][r][ks]);
				if(l>1&&r<n) F[l-1][r+1][ks]=max(F[l-1][r+1][ks],F[l][r][ks]+(s[l-1]==s[r+1])*2);
				if(r<n) F[l][r+1][ks]=max(F[l][r+1][ks],F[l][r][ks]);
				if(l>1&&r<n) F[l-1][r+1][ks+1]=max(F[l-1][r+1][ks+1],F[l][r][ks]+2);
			}
		}
	}
	int Ans=0; for(int i=0;i<=k;i++) Ans=max(Ans,F[1][n][i]);
	cout << Ans << endl; return 0;
}


Measured memory_bytes: 114560
#include <bits/stdc++.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    cin>>s;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R'){
        cout<<3;
        return 0;
    }
    if((s[0]=='R'&&s[1]=='R')||s[1]=='R'&&s[2]=='R'){
        cout<<2;
        return 0;
    }
    if(s[0]=='R'||s[1]=='R'||s[2]=='R'){
        cout<<1;
        return 0;
    }
    cout<<0;
    return 0;
}


Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N, W;
    cin >> N >> W;
    vl v(N), w(N);
    rep(i, N){
        cin >> v[i] >> w[i];
    }

    vll dp(N+10, vl(W+10));
    //dp[i][j]:=左からi個の品物から、バックの容量がjを超えないように選んだときの価値の合計の最大値
    rep(i, W+1) dp[0][i] = 0;
    
    rep(i, N){
        rep(j, W+1){
            if(j >= w[i]) dp[i+1][j] = max(dp[i+1][j-w[i]]+v[i], dp[i][j]);
            else dp[i+1][j] = dp[i][j];
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 11588
#pragma region header
#define _GLIBCXX_DEBUG 
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
signed main() {
    string S;
    cin>>S;
    
    for(int i=0;i<S.size();i+=2){
        cout<<S[i];
    }
}

Measured memory_bytes: 3680
n = int(input())
sp = []
for i in range(1,n+1):
    s,p = input().split()
    p = int(p)
    sp.append((s,p,i))
items = sorted( sp, key = lambda x:x[1],reverse = True)
items = sorted( items, key = lambda x:x[0])

for i in items:
    print(i[2])

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// Manages Union-Find Forest.
class UnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;

public:
  // Initialize forest.
  // parent_[i]=i, rank_[i]=0, size_[i]=1.
  UnionFindForest(const int &n);
  // Get the number of the root of the node q.
  int Root(const int &q);
  // Return true if the roots of x and y is same.
  bool IsSame(const int &x, const int &y);
  // Unite the tree x and tree y.
  void Unite(int x, int y);
  // Get the number of nodes which are the same group as node q.
  int Size(const int &q);
};
UnionFindForest::UnionFindForest(const int &n) {
  parent_.resize(n);
  rank_.resize(n);
  size_.resize(n);
  for (int i = 0; i < n; i++) {
    parent_[i] = i;
    rank_[i]   = 0;
    size_[i]   = 1;
  }
}
int UnionFindForest::Size(const int &q) {
  return size_[Root(q)];
}

int UnionFindForest::Root(const int &q) {
  if (parent_[q] == q) {
    return q;
  } else {
    return parent_[q] = Root(parent_[q]);
  }
}

bool UnionFindForest::IsSame(const int &x, const int &y) {
  return Root(x) == Root(y);
}

void UnionFindForest::Unite(int x, int y) {
  x = Root(x);
  y = Root(y);
  if (x == y) return;
  if (rank_[x] < rank_[y]) {
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
}

struct Pos{
  int x,y;
  Pos(int a,int b){
    x=a;
    y=b;
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::vector<Pos> ball;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    ball.push_back(Pos(x,y));
  }

  int64_t result=INT32_MAX;

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

  for(int begin_a=0;begin_a<n;begin_a++){
    for(int begin_b=0;begin_b<n;begin_b++){
      if(begin_a==begin_b) continue;
      int64_t p=ball[begin_a].x-ball[begin_b].x;
      int64_t q=ball[begin_a].y-ball[begin_b].y;
      UnionFindForest uf(n);
      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          if(i==j) continue;
          int64_t diff_x=ball[i].x-ball[j].x;
          int64_t diff_y=ball[i].y-ball[j].y;
          if(diff_x==p&&diff_y==q){
            uf.Unite(i,j);
          }
        }
      }

      int64_t count=0;
      for(int i=0;i<n;i++){
        if(i==uf.Root(i)){
          count++;
        }
      }
      result=std::min(result,count);
    }
  }

  cout<<result<<endl;


  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n);
  REP(i, n)
    cin >> a[i];
  
  if((n - k) % (k - 1) == 0)
    cout << (n - k) / (k - 1) + 1 << endl;
  else
    cout << (n - k) / (k - 1) + 2 << endl;
  
}

Measured memory_bytes: 1024
N, A,B,*V = map(int,open(0).read().split())
V = sorted(V)[::-1]
ans1 = sum(V[:A])/A
print(ans1)
f = [1] *51
for i in range(1,51):
  f[i] = f[i - 1] * i
def comb(n,r):
  return f[n]//f[r]//f[n-r]
ans2 = comb(V.count(V[A-1]),V[:A].count(V[A-1]))
if V[0] == V[A-1]:
  for i in range(A+1,B+1):
    ans2 += comb(V.count(V[A-1]),i)
print(ans2)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int n, m, i, count, sum;
    int vote[100];
    cin >> n >> m;
    sum = 0;
    count = 0;
    for (i = 0; i < n; i++)
    {
        cin >> vote[i];
        sum = sum + vote[i];
    }
    for (i = 0; i < n; i++)
    {
        if (vote[i] * 4 * m >= sum)
        {
            count++;
        }
    }
    if (count >= m)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3560
(N,M) = (int(i) for i in input().split(" "))
(N,M)=(min(M,N),max(M,N))
while M%N!=0:
	M=M%N
	(N,M)=(min(M,N),max(M,N))
i = 2
ans = 0
DN = N
while i*i <= DN :
	if N%i==0:
		ans += 1
		while N%i==0:
			N/=i
	i+=1
if i <= N:
	ans +=1
print(ans+1)

Measured memory_bytes: 3064