akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n,m,k; cin >> n >> m >> k;

    vector<vector<ll>> fr(n,vector<ll>(0));
    vector<vector<ll>> bl(n,vector<ll>(0));

    rep(i,m){
        //fr
        ll a,b; cin >> a >> b;
        a--; b--;
        fr.at(a).push_back(b);
        fr.at(b).push_back(a);
    }

    rep(i,k){
        //bl
        ll c,d; cin >> c >> d;
        c--; d--;
        bl.at(c).push_back(d);
        bl.at(d).push_back(c);     
    }

    vector<ll> cls(n,0);

    vector<ll> ans(n,0);

    for(int i=0;i<n;i++){
        if(cls.at(i)!=0) continue;
        set<ll> s2;
        set<ll> s3;        
        queue<ll> q;
        s2.insert(i);
        cls.at(i) = 1;
        q.push(i);
        while(q.size()){
            ll x = q.front();
            q.pop();
            for(auto y:fr.at(x)){
                if(cls.at(y)==1) continue;
                s2.insert(y);
                q.push(y);
                cls.at(y) = 1;
            }
        }
        //for(auto y:s2) cout << y << " " ; cout << endl;
        /*
        for(auto y:s2){
            s3 = s2;
            for(auto bb:fr.at(y)) s3.erase(bb);
            for(auto aa:bl.at(y)) s3.erase(aa);
            ans.at(y) = s3.size() - 1;
        }
        */

        for(auto y:s2){
            ll count = 0;
            for(auto ff:fr.at(y)){
                if(s2.count(ff)) count++;
            }
            for(auto bb:bl.at(y)){
                if(s2.count(bb)) count++;
            }
            ans.at(y) = (ll)s2.size() - 1 - count;            
        }
    }

    rep(i,n){
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 19956
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		System.out.println(Math.max(Math.min(B, D)- Math.max(A, C) , 0));

	}

}


Measured memory_bytes: 21844
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;
char s[MAXN];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	int ans=0;
	for(int i=0;i<(len+1)/2;i++)
	{
		if(s[i]=='p')
			ans--;
	}
	for(int i=(len+1)/2;i<len;i++)
	{
		if(s[i]=='g')
			ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using lli =  long long int ; using namespace std;
bool isprime(lli n); lli gcd(lli a, lli  b);
lli lcm(lli n, lli m); lli fact(lli n);
double dgr(double a); int fixMod(int a, int b);
long long  ncr(int n, int r); void fast();
int main() {
	fast();
	lli a; cin >> a;
	if (a > 2)
		cout << lcm(a, 2);
	else cout << lcm(2, a);
	
}
void fast() { ios::sync_with_stdio(false); cin.tie(0);// cout.tie(0);
#ifndef ONLINE_JUDGE //freopen("input.in", "r", stdin); //freopen("output.out", "w", stdout);
#endif 
}

bool isprime(lli n)
{
	if (n == 0 || n == 1)return 0; if (n == 2 || n == 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
	for (int i = 5; i <= sqrt(n); i += 6) if (n%i == 0 || n % (i + 2) == 0) return 0;  return 1;
}
lli gcd(lli a, lli  b) { if (b == 0)return a; else return gcd(b, a%b); }
lli lcm(lli n, lli m) { return n*m / gcd(n, m); }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>

using namespace std;

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

    long long sum1 = 0;
    long long sum2 = 0;
    long long total = 0;

    for (long long i = 0; i < K - 1; i++) {
        sum1 += N - i;
        sum2 += i;
    }

    for (long long i = K; i < N + 2; i++) {
        sum1 += N - i + 1;
        sum2 += i - 1;
        total += (sum1 - sum2) + 1;
    }
    cout << total%(1000000000+7) << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int ans = 0;
	vector<int> s(5);
	rep(i, 5){
		int in;
		cin >> in;
		s.at(i) = in;
		if(in % 10 != 0){
			in /= 10;
			in *= 10;
			in += 10;
		}
		// cerr << in << endl;
		ans += in;
	}
	int aa = 1001001001;
	rep(i, 5){
		int add = ans;
		int now = s.at(i);
		if(now % 10 != 0){
			now /= 10;
			now *= 10;
			now += 10;
		}
		add -= now;
		add += s.at(i);
		aa = min(aa, add);
	}

	cout << aa << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    string S, T;
    cin >> S >> T;

    bool yes = false;
    if (S.size() + 1 == T.size())
    {
        if (S == T.substr(0, S.size()))
        {
            yes = true;
        }
    }
    if (yes)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string ans="IMPOSSIBLE";
  int n,m,a,b;
  cin>>n>>m;
  vector<int> s(n+1,0),g(n+1,0);
  for(int i=0;i<m;i++){
    cin>>a>>b;
    if(a==1){s[b]=1;}
    else if(b==n){g[a]=1;}
  }
  for(int i=2;i<n;i++){
    if(s[i]*g[i]){ans="POSSIBLE";break;}
  }
  cout<<ans;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define int long long
#define endl '\n'
const int N = 200005;
int n, m, k, q;
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a*b));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >>n >> m;
    ll a[n];
    rep(i, n) cin >> a[i];
   // int b[m];
    map<ll, ll> B;
    //B[10000000] = 1;
    //cout << B[10000000] << endl;
   // memset(b, 0, sizeof(b));
    ll cur_sum = 0;
    rep(i, n) {
        cur_sum += a[i];
        cur_sum %= m;
        //char a = char(cur_sum - 1000000000);
        B[cur_sum] ++;
    }
    //char bb = char(-1000000000);
    ll ans = 0;
    ans += B[0];
    //cout << B[0] << endl;
    for(auto i:B){
        if(i.second % 2 == 0) {
            ll g = i.second / 2;
            ans += g * (i.second - 1);
        }else{
            ll g = (i.second - 1) / 2;
            ans += g * i.second;
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
int main(void)
{
    int i, a[3];
    char x, y;
    a[0]=1;
    a[1]=a[2]=0;
    while (scanf("%c,%c\n", &x,&y) != EOF) {
        int t = a[x-'A'];
        a[x-'A'] = a[y-'A'];
        a[y-'A']=t;
    }
    for (i=0; i<3; ++i) if (a[i]) printf("%c\n", 'A'+i);
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    int ans = 0;
    rep(i, S.size()) {
        if (S[i] != T[i]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3912
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADigitsSum solver = new ADigitsSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADigitsSum {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int min = Integer.MAX_VALUE;
            for (int i = 1; i < n; i++) {
                min = Math.min(min, sumdigit(i, n - i));
            }
            out.print(min);
        }

        private int sumdigit(int a, int b) {
            int sum = 0;
            while (a != 0) {
                sum += a % 10;
                a = a / 10;
            }
            while (b != 0) {
                sum += b % 10;
                b = b / 10;
            }
            return sum;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

ll go(ll n,vector<ll> &h,vector<ll> &dp,ll pos=0)
{
  	if(pos>=n)
      return INT_MAX;
  	if(pos==n-1)
      return 0;
     if(dp[pos]!=-1)
     return dp[pos];
  	ll res1=abs(h[pos+1]-h[pos])+go(n,h,dp,pos+1);
  	ll res2=abs(h[pos+2]-h[pos])+go(n,h,dp,pos+2);
  	return dp[pos]=min(res1,res2);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin>>n;
  vector<ll> h(n);
  for(auto &i:h)
    cin>>i;
  vector<ll> dp(n+1,-1);
  cout<<go(n,h,dp)<<endl;
  return 0;
  
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,ret=0; cin>>a>>b>>c;
	if (a==b) ret++;
	if (b==c) ret++;
	if (c==a) ret++;
	cout<<(ret==1?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,maxl=0,l=0;string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='I')l++;
		else{
			maxl=max(maxl,l);
			l--;
		}
	}
	cout<<max(maxl,l)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;
int main() {
	cin >> N;
	map < LL, LL> m;
	for (int i = 0; i < N; i++) {
		cin >> L;
		auto itr = m.find(L);
		if (itr != m.end()) {
			cout << "NO" << endl;
			return 0;
		}
		m[L] = 0;
		
	}
	cout << "YES"<< endl;
	return 0;
}



Measured memory_bytes: 12800
import java.io.*;

class Main{
    
        public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        }

        public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        }

    public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                for(int i = 0; i < N; i++){
                    System.out.print(a[i]);
                    if(i != (N - 1)){
                        System.out.print(" ");
                    }
                }
                System.out.println();

                System.out.println(count);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24360
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    for (int i = 1; i <= 9; i++)
    {
        if(1<=a/i&&a/i<=9&&a%i==0){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		
		int N=Integer.parseInt(s[0]);
		int M=Integer.parseInt(s[1]);
		int a[] = new int[N];
		
		double totvot=0,x=0,c=0;
		
		s=br.readLine().split(" ");
		for(int i=0;i<N;i++)
		{
			a[i]=Integer.parseInt(s[i]);
			//out.println(a[i]);
			totvot+=a[i];
		}
		
		x=(int)ceil((1.0/(4.0*M))*totvot);
		//out.println(x);
		
		for(int i=0;i<N;i++)
		{
			if(a[i]>=x)
				c++;
		}
		
		if(c>=M)
			out.println("Yes");
		else
			out.println("No");
		
		
	}
	
	
}




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

int main() {
  int N;
  cin >> N;
  int L, maxL = 0, total = 0;
  for (int i = 0; i < N; i++) {
    cin >> L;
    maxL = max(maxL, L);
    total += L;
  }
  cout << (maxL < (total - maxL) ? "Yes" : "No") << endl;
}

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

int n, q, m;
int A[20];

int solve(int i, int m) {
    if(m == 0) return true;
    if(i >= n) return false;
    bool res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
    }
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> m;
        if(solve(0, m)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3124
import sys
import math

from collections import Counter

# input処理を高速化する
input = sys.stdin.readline

N=int(input())
Keihin =[]
for i in range(N):
    syouhin = input()
    Keihin.append(syouhin)

c=Counter(Keihin)
print(len(list(c.keys())))

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N; cin >> N;
  long long A[N];
  long long minusCount = 0;
  bool isZeroContained = false;
  long long sum = 0, minAbsNum = (long long)1e18;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    if(A[i] < 0) minusCount++;
    else if(A[i] == 0) isZeroContained = true;
    sum += abs(A[i]);
    minAbsNum = min(minAbsNum, abs(A[i]));
  }
  if(isZeroContained || minusCount % 2 == 0) {
    cout << sum << endl;
  } else {
    cout << sum-2*minAbsNum << endl;
  }


  return 0;
}


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

int main(){

  ll a,b,N;
  
  cin>>a>>b>>N;
  
  ll k=min(N,b-1);
  
  ll s=a*k;
  s=s/b;
  ll s2=k/b;
  
  cout<<s-a*s2<<endl;

}

Measured memory_bytes: 3592
import java.util.*;
import java.io.*;

// Template for atcoder
public class Main {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        long[] a = nextLongArr(n);
        long[] b = nextLongArr(m);
        long[] prefA = new long[1 + n];
        for (int i = 1; i <= n; i++) {
            prefA[i] = prefA[i - 1] + a[i - 1];
        }
        long[] prefB = new long[1 + m];
        for (int i = 1; i <= m; i++) {
            prefB[i] = prefB[i - 1] + b[i - 1];
        }

        int res = 0;
        for (int i = 0; i <= n; i++) {
            long left = k - prefA[i];
            if (left < 0) {
                continue;
            }
            int low = 0;
            int high = m + 1;
            while (low < high) {
                int mid = (low + high) / 2;
                if (prefB[mid] <= left) {
                    low = mid + 1;
                } else {
                    high = mid;
                }
            }
            low--;
            res = Math.max(res, i + low);
        }
        outln(res);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public Main() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new Main();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


Measured memory_bytes: 67464
#include <random>
#include <vector>
#include <cstdio>
#include <iostream>
#include <tuple>
#include <stdexcept>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <numeric>
#include <unordered_map>
#include <bitset>
#include <queue>

#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
#define mod LL(1e9 + 7)
#define mp make_pair
#define pb push_back
#define sqr(xx) ((xx)*(xx))

const int sz = 2e6;

ll a[int(3e5) + 20], ans;
pair<ll, ll> g[int(3e5) + 20];
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    n = (1 << n);
    for (int i = 1; i <= n; i++) {
        cin >> a[i - 1];
    }
    for (int mask = 1; mask < n; mask++) {
        ll mx1 = 0, mx2 = 0;
        mx1 = a[0];
        for (int nmask = mask; nmask >= 1; nmask = (nmask - 1) & mask) {
            if (a[nmask] > mx1) {
                mx2 = mx1;
                mx1 = a[nmask];
            } else if (a[nmask] > mx2) {
                mx2 = a[nmask];
            }
        }
        ans = max(ans, mx1 + mx2);
        cout << ans << "\n";
    }
//
//    for (int mask = 1; mask < n; mask++) {
//        for (int nmask = mask; nmask > 0; nmask = (nmask - 1) & mask) {
//
//        }
//        cout << ans << "\n";
//    }
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int a,b; cin>>a>>b;
	bool flag = true;
	FOR(i,1,1010){
		if(i*8/100==a&&i*10/100==b){
			cout<<i<<endl;
			flag = false;
			break;
		}
	}
	if(flag) cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import defaultdict

"""
・trie木
・各ノードから、アルファベットごとの子ノードの番号
・親ノードの番号
"""

N = int(readline())
data = tuple(read().split())
S = data[:N]
Q = int(data[N])
query_target = list(map(int,data[N+1::2]))
query_order = data[N+2::2]

class Node():
    def __init__(self,parent):
        self.parent=parent
        self.child = defaultdict(int)
        self.is_word_node = False
        self.Nword = 0 # 部分木にあるword_nodeの個数
        
    def __repr__(self):
        return 'parent:{}\nchild:{}\nNword:{}'.format(self.parent,self.child,self.Nword)

def add(word):
    n = 0
    next_idx = len(nodes)
    for x in word:
        nodes[n].Nword += 1
        c = nodes[n].child[x]
        if c == 0:
            c = next_idx
            nodes[n].child[x] = c
            nodes.append(Node(n))
            next_idx += 1
        n = c
    nodes[n].is_word_node = True
    nodes[n].Nword += 1

def solve(word):
    """
    ・wordに沿って進む。
    ・「char1<char2ならば自身より弱い文字列1個」という情報を調べる・
    ・自身のprefixの個数も調べる
    """
    data = defaultdict(int)
    prefix = 0
    n = 0
    for x in word:
        # 進む前に、他のルートの文字列数も確認する
        for k,v in nodes[n].child.items():
            if k == x:
                continue
            data[1000*k+x] += nodes[v].Nword # k<xのときの加算量
        # prefixを見つけたら加算
        if nodes[n].is_word_node:
            prefix += 1
        # 進む
        n = nodes[n].child[x]
    return data, prefix

root = Node(0)
nodes = [root]

for word in S:
    add(word)

# 同じ文字列に対するクエリを一括処理
word_to_query = [[] for _ in range(N)]
for i,x in enumerate(query_target):
    word_to_query[x-1].append(i)

answer = [0]*Q
for n,word in enumerate(S):
    if not word_to_query[n]:
        continue
    data,pref = solve(word)
    for q in word_to_query[n]:
        order = query_order[q]
        alphabet_rank = {x:i for i,x in enumerate(order)}
        rank = pref+1
        for x,v in data.items():
            a,b = divmod(x,1000)
            if alphabet_rank[a] < alphabet_rank[b]:
                rank += v
        answer[q] = rank

print('\n'.join(map(str,answer)))

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

typedef long long ll;

signed main() {
    string geo; cin >> geo;
    ll length = geo.size();
    ll sum = 0;
    stack<ll> s;
    stack< pair<ll,ll> > ans2;
    for( ll i = 0; i < length; i++ )
    {
        if(geo.at(i) == '\\') { s.push(i); }
        else if(geo.at(i) == '/' && !s.empty())
        {
            ll j = s.top(); s.pop();
            sum += i - j;
            ll a = i - j;
            while( !ans2.empty() && ans2.top().first > j )
            {
                a += ans2.top().second; ans2.pop();
            }
            ans2.push(make_pair(j,a));
        }
    }

    vector<ll> ans;
    while( !ans2.empty() ) { ans.push_back(ans2.top().second); ans2.pop(); }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++ )
    {
        cout << ' ' << ans.at(i);
    }
    cout << endl;
    return 0;
}



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

typedef long long ll;

const int N = 1e5 + 5;
int n, m, k, res, sum, cnt, zcnt, kcnt, l;
string s;
int a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    cin >> s;

    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            ++cnt;
            if (zcnt != 0) {
                a[m++] = -zcnt;
                zcnt = 0;
            }
        } else {
            ++zcnt;
            if (cnt != 0) {
                a[m++] = cnt;
                cnt = 0;
            }
        }
    }
    if (cnt != 0) {
        a[m++] = cnt;
    }
    if (zcnt != 0) {
        a[m++] = -zcnt;
    }
    for (int i = 0; i < m; ++i) {
        sum += abs(a[i]);
        if (a[i] < 0) {
            ++kcnt;
        }
        while (kcnt > k) {
            int lv = a[l++];
            if (lv < 0) kcnt--;
            sum -= abs(lv);
        }
        res = max(res, sum);
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 4080
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, vector<int>>> light(M);
    vector<int> cond(M);
    int k, s, p;
    for (int i = 0; i < M; i++) {
        cin >> k;
        light[i].first = k;
        for (int j = 0; j < k; j++) {
            cin >> s;
            light[i].second.push_back(s);
        }
    }
    for (int i = 0; i < M; i++) {
        cin >> p;
        cond[i] = p;
    }

    int ans = 0, all_on = (1 << N) - 1;
    int ok, cnt;
    for (int i = 0; i <= all_on; i++) {
        ok = 1;
        for (int j = 0; j < M; j++) {
            cnt = 0;
            for (int k = 0; k < light[j].first; k++) {
                if (i & (1 << (light[j].second[k] - 1))) cnt += 1;
            }
            if (cnt % 2 != cond[j]) {
                ok = 0;
                break;
            }
        }
        ans += ok;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

// int f(int n, int m) {
//     return Div(Mul(m + 2, C(m + n + 2 , m + 2)) - n - 1 + mod, n + 1);
// }
int f(int n, int m) {
    if(m == 1) return Div(Mul(n, n + 3), 2);
    return (C(m + n + 2, m + 1) - m - n - 2 + mod) % mod;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact();
    int r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    // REP(i, r1, r2) {
    //     REP(j, c1, c2) {
    //         cout << f(i, j) << " ";
    //     }
    //     cout << endl;
    // }
    cout << (f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1) + mod*2) % mod << endl;

    return 0;
}


Measured memory_bytes: 16640
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i(0);i<n;i++)
typedef long long ll;

int main(){
	int N;
    cin >> N;
    string ans = "APPROVED"; // APPROVED, DENIED

    rep(i,N){
        int a;
        cin >> a;
        if(a%2==0){
            if(a%3 != 0 && a%5 != 0) ans = "DENIED";
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main() {
	fast_io;
	ll h,w;
	cin>>h>>w;
	ll ans = h*w;
	if(h==1 || w==1){cout<<1;
		return 0;}
	if(ans%2){ans++;}

	ans = ans/2;
	cout<<ans;
    return 0;
}

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

int main(){
  int tenbosu=0;
  cin>>tenbosu;
  vector<long long> takasa(tenbosu ,0);
  int pathC=0;
  cin>>pathC;
  int a,b;
  vector<int> ToF(tenbosu,0);
  for(int i=0;i<tenbosu;i++){
    cin>>takasa[i];
  }
  for(int i=0;i<pathC;i++){
    cin>>a;
    cin>>b;
    if(takasa[a-1]>=takasa[b-1]){
      ToF[b-1]=1;
    }
    if(takasa[a-1]<=takasa[b-1]){
      ToF[a-1]=1;
    }
  }

  int c=0;
  for(int i=0;i<tenbosu;i++){
    if(ToF[i]==0){
      c++;
    }
  }
  cout<<c;
}


Measured memory_bytes: 4576
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
int mod = 1e9 + 7;

vector<bool> isPrime(2000, true);
vector<int> p;
map<int,int> numPrime;
void addDiv(int);

int main()
{
	int sx, sy, tx, ty, dx, dy;
	cin >> sx >> sy >> tx >> ty;
	dx = tx - sx; dy = ty - sy;
	rep(i, dx) cout << 'R';
	rep(i, dy) cout << 'U';
	rep(i, dx) cout << 'L';
	rep(i, dy) cout << 'D';

	cout << 'D';
	rep(i, dx + 1)cout << 'R';
	rep(i, dy + 1)cout << 'U';
	cout << 'L';
	cout << 'U';
	rep(i, dx + 1)cout << 'L';
	rep(i, dy + 1)cout << 'D';
	cout << 'R';
	
	return 0;
}

Measured memory_bytes: 256
import core.stdc.stdio;
import std.algorithm;

void main(){
	int s,t;
	scanf("%d%d",&s,&t);
	char[] x = new char[s+1],y=new char[t+1];
	scanf("%s%s",x.ptr,y.ptr);
	int[][][] dp = new int[][][](2,s+1,t+1);
	foreach(d;dp[0])
		d[]=-1145141919;
	foreach(i;0..s+1)
		foreach(j;0..t+1){
			if(i<s)
				if(x[i]=='I')
					dp[0][i+1][j]=max(dp[0][i+1][j],dp[1][i][j]+1);
				else
					dp[1][i+1][j]=max(dp[1][i+1][j],dp[0][i][j]+1);
			if(j<t)
				if(y[j]=='I')
					dp[0][i][j+1]=max(dp[0][i][j+1],dp[1][i][j]+1);
				else
					dp[1][i][j+1]=max(dp[1][i][j+1],dp[0][i][j]+1);
		}
	int ans=0;
	foreach(ds;dp[0])
		foreach(d;ds)
			ans=max(ans,d);
	printf("%d\n",ans);
}

Measured memory_bytes: 34152
#include<bits/stdc++.h>
#define ll 	 long long
#define pb push_back
#define mp make_pair
using namespace std;


int main()
{

int n; cin>>n;

int a[n+9];

for(int i=0; i<n; i++) cin>>a[i];

vector<int> dp(n+9, INT_MAX);

dp[0]=0;

if(n==1)
{
	cout<<dp[0]<<endl;
	return 0;
}
dp[1]= abs(a[0]-a[1]);

if(n==2)
{
		cout<<dp[1]<<endl;
	return 0;
}

for(int i=2; i<n; i++)
{
	dp[i] = min(( abs(a[i-1]-a[i]) + dp[i-1]), ( abs(a[i-2]-a[i]) + dp[i-2]));
}

cout<<dp[n-1]<<endl;

     return 0;
 }

Measured memory_bytes: 4064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = [input() for _ in range(N)]
M = INT()
t = [input() for _ in range(M)]
dic_s = defaultdict(int)
dic_t = defaultdict(int)
for st in s:
	dic_s[st] += 1
for st in t:
	dic_t[st] += 1

ans = 0
for st in dic_s:
	ans = max(ans, dic_s[st]-dic_t[st])
print(ans)

Measured memory_bytes: 5204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int dp[5010][5010];

int main() {
  int n;
  string s;
  cin >> n >> s;
  for(int i = n-1; i >= 0; --i) {
    for(int j = n-1; j >= 0; --j) {
      if(s[i] != s[j]) dp[i][j] = 0;
      else dp[i][j] = dp[i+1][j+1] + 1;
    }
  }

  int ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(i >= j) continue;
      int now = min(dp[i][j], j-i);
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 98048
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    X = int(input())
    if X <= 599:
        print(8)
    elif X <= 799:
        print(7)
    elif X <= 999:
        print(6)
    elif X <= 1199:
        print(5)
    elif X <= 1399:
        print(4)
    elif X <= 1599:
        print(3)
    elif X <= 1799:
        print(2)
    else:
        print(1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62132
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxCake = n / 4;
		boolean answer = false;
		for (int i = 0; i <= maxCake; i++) {
			if ((n - i * 4) % 7 == 0) {
				answer = true;
				break;
			}
		}

		if (answer) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 24020
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2 * n - 1) {
        cout << "No" << endl;
    } else if (n == 2) {
        cout << "Yes" << endl;
        cout << 1 << endl;
        cout << 2 << endl;
        cout << 3 << endl;
    } else {
        cout << "Yes" << endl;
        set<int> used;
        vector<int> ans(2 * n - 1);
        if (x == 2) {
            ans[n - 2] = x + 1;
            ans[n - 1] = x - 1;
            ans[n] = x;
            ans[n + 1] = x + 2;
            used.insert(x + 1);
            used.insert(x - 1);
            used.insert(x);
            used.insert(x + 2);
        } else {
            ans[n - 2] = x - 1;
            ans[n - 1] = x;
            ans[n] = x + 1;
            ans[n + 1] = x - 2;
            used.insert(x + 1);
            used.insert(x - 1);
            used.insert(x);
            used.insert(x - 2);
        }

        int j = 1;
        for (int i = 0; i < 2 * n - 1; ++i) {
            if (ans[i] == 0) {
                while (used.count(j)) {
                    ++j;
                }
                ans[i] = j;
                used.insert(j);
            }
        }

        for (int k : ans) {
            cout << k << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 12972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int x, y; cin >> x >> y;

  int ans = 0;
  if (x == 1) ans += 300000;
  else if (x == 2) ans += 200000;
  else if (x == 3) ans += 100000;
  
  if (y == 1) ans += 300000;
  else if (y == 2) ans += 200000;
  else if (y == 3) ans += 100000;

  if (x == 1 && y == 1) ans += 400000;

  cout << ans << endl;

  return 0;
}


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

int main() {
    int n, k, c;
    cin >> n >> k >> c;

    string s;
    cin >> s;

    vector<int> greedy(n, 0);
    int count = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'o') {
            count++;
            greedy[i] = count;
            i += c;
            if(count == k) break;
        }
    }
    // for(int i = 0; i < n; i++) cout << greedy[i];
    // cout << endl;
    vector<bool> ans(n, false);
    for(int i = n - 1; i >= 0; i--) {
        if(s[i] == 'o') {
            greedy[i] -= count;
            if(greedy[i] == 0) ans[i] = true;
            i -= c;
            count--;
            if(count == 0) break;
        }
    }

    for(int i = 0; i < n; i++) {
        if(ans[i]) cout << i + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 2564
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int main()
{
  int N, K, R, S, P;
  std::cin >> N >> K >> R >> S >> P;
  std::string T;
  std::cin >> T;
  std::vector<std::array<int, 3>> dp(N);
  auto getScore = [R, S, P](char c)
  {
    switch(c)
    {
    case 'r':
      return std::make_tuple(0, 0, P);
    case 's':
      return std::make_tuple(R, 0, 0);
    default:
      return std::make_tuple(0, S, 0);
    }
  };
  for(int i = 0; i < K; ++i)
  {
    auto score = getScore(T[i]);
    dp[i][0] = std::get<0>(score);
    dp[i][1] = std::get<1>(score);
    dp[i][2] = std::get<2>(score);
  }
  for(int i = K; i < N; ++i)
  {
    char c = T[i];
    dp[i][0] = std::max(dp[i - K][1], dp[i - K][2]);
    dp[i][1] = std::max(dp[i - K][0], dp[i - K][2]);
    dp[i][2] = std::max(dp[i - K][0], dp[i - K][1]);
    switch(c)
    {
    case 'r':
      dp[i][2] += P;
      break;
    case 's':
      dp[i][0] += R;
      break;
    default:
      dp[i][1] += S;
      break;
    }
  }
  int ans = 0;
  for(int i = 0; i < K; ++i)
  {
    auto& s = dp[N - i - 1];
    ans += std::max(s[0], std::max(s[1], s[2]));
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 4592
#include <iostream>
#include <cstdint>

int main() {
	std::int64_t n, m;
	std::cin >> n >> m;
	if (n >= m / 2)
		std::cout << m / 2 << std::endl;
	else
		std::cout << n + (m - n * 2) / 4 << std::endl;
}

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

typedef long long ll;

const ll mod=1e9+7;
const int maxn=2e5+5;

vector<pair<int,int> > v;

char s[maxn];

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	int tmp=1;
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1]){
			if(s[i-1]=='L') v.push_back({tmp,1});
			else v.push_back({tmp,2});
			tmp=1;
		}
		else tmp++;
	}
	if(s[n-1]=='L') v.push_back({tmp,1});
	else v.push_back({tmp,2});
	for(int i=1;i<v.size();i+=2){
		if(k==0) break;
		v[i].second=v[i-1].second;	
		k--;
	}
	tmp=v[0].first;
	int ans=0;
	for(int i=1;i<v.size();i++){
		if(v[i].second!=v[i-1].second){
			ans+=tmp-1;
			tmp=v[i].first;
		}
		else tmp+=v[i].first;
	}
	ans+=tmp-1;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1528
#include<stdio.h>
int a,b;
int aa[4],bb[4];
int main(void){
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0 && b==0){
			break;
		}
		int kake=1000,cnt=0;
		while(cnt!=4){
			aa[cnt]=a/kake;
			bb[cnt]=b/kake;
			a-=aa[cnt]*kake;
			b-=bb[cnt]*kake;
			cnt++;
			kake/=10;
		}
		int i,j;
		/*for(i=0;i<4;i++){
			printf("%d %d\n",aa[i],bb[i]);
		}
		printf("\n");*/
		int h=0,b=0;
		for(i=0;i<4;i++){
			if(aa[i]==bb[i]){
				h++;
				aa[i]=9999;
				bb[i]=9999;
			}
		}
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(aa[i]==bb[j] && aa[i]!=9999 && bb[j]!=9999){
					b++;
					//printf("%d %d\n",aa[i],bb[j]);
					aa[i]=9999;
					bb[j]=9999;
				}
			}
		}
		printf("%d %d\n",h,b);
	}
	return 0;
}

Measured memory_bytes: 1028
//kruskal tree
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n;
	double x,y,z,r;
	for(;cin>>n,n;){
		vector<vector<double> >v;
		for(i=0;i<n;i++)cin>>x>>y>>z>>r,v.push_back({x,y,z,r});
		for(i=0;i<n;i++)parent[i]=i;
		for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
			for(x=k=0;k<3;k++)x+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			x=sqrt(x)-v[i][3]-v[j][3];
			if(x<=0)unite(i,j);
			else a[m]=i,b[m]=j,node[m].first=x,node[m++].second=m;
		}
		sort(node,node+m);
		for(x=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first;
		cout<<fixed<<setprecision(3)<<x<<endl;
	}
}

Measured memory_bytes: 1508
#include <bits/stdc++.h>
#define isFile 0
#define NAME "taskA"
#define scan 1
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;

#define mp make_pair
#define pb push_back
#define fr first
#define sc second

#define ins insert
#define all(v) v.begin(), v.end()
#define rep(i,a,n) for (int i=a;i<n;i++)
#define bit(n, i) (n >> i) & 1
#define bpc(x) __builtin_popcountll(x)
#define rev(a) reverse(all(a))
#define skip continue
#define read(a) for(auto &i : a) cin >> i
#define print(a) for(auto i : a) cout << i << ' '
#define unique(a) sort(all(a));    a.resize(unique(all(a)) - a.begin())

//                D  R  U   L
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void faster() {
    if (isFile) {
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    if (scan) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
}

const ll  INF = 1e18;
const int inf = 2e9;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ld  PI = acos(-1);
const ld  EPS = 3E-16;
const int ALPHA = 27;
const int N = (int)3e3 + 5;
const int M = 123;

int n;
double dp[N];

void solve() {
    cin >> n;
    dp[0] = 1;
    for(int i = 0; i < n; i++) {
        double p_heads;
        cin >> p_heads;
        for(int j = i + 1; j >= 0; j--) {
            dp[j] = (j == 0 ? 0 : dp[j - 1]) * p_heads + dp[j] * (1 - p_heads);
        }
    }

    double ans = 0;
    for(int i = 0; i <= n; i++) {
        if (i > (n - i)) {
            ans += dp[i];
        }
    }

    cout.precision(10);
    cout << fixed << ans << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define true 1
#define false 0
int ramu(int);
int main ()
{
  int remu,subaru,emiria,i,j=0;
  int beako[10000];
  
  scanf("%d",&remu);

  for(i=0;i<remu;i++){
    scanf("%d",&beako[i]);
  
  if(ramu(beako[i])==1)
    j++;
  }
  
  printf("%d\n",j);

  return 0;
}

int ramu(int x)
{
  int i=3;
  
   if(x==2){
    return true;
   }
  
  if(x<2 || x%2==0){
    return false;
  }
 
  
  while(i<=sqrt(x)){

    if(x%i==0){
      return false;
    }
  
    i=i+2;
    }

    return true;
}
    
    
      



Measured memory_bytes: 2044