akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include<queue>

//const int mod = 1000000007;
const int mod = 998244353;


int main() {
	int N;
	scanf("%d", &N);
	int*D = new int[N];
	int maxd = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", D + i);
		if (D[i] > maxd)maxd = D[i];
	}
	int*cnt = new int[N];
	for (int i = 0; i < N; i++)cnt[i] = 0;
	for (int i = 0; i < N; i++) {
		cnt[D[i]]++;
	}
	long long res = 1;
	if (D[0] != 0 || cnt[0] != 1)res = 0;
	for (int i = 1; i <= maxd; i++) {
		for (int j = 0; j < cnt[i]; j++) {
			res *= cnt[i - 1];
			res %= mod;
		}
	}
	printf("%lld", res);
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 2005, mod = 1e9 + 7;
int n, m, f[maxn][maxn], s[maxn];
int power(long long x, int k) {
	if(k < 0) return 1;
	int ans = 1;
	while(k) {
		if(k & 1) ans = ans * x % mod;
		x = x * x % mod, k >>= 1;
	} 
	return ans;
}
int main() {
	scanf("%d %d", &n, &m);
	f[0][n+1] = 1; 
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n+1; ++j) s[j] = ((long long)s[j-1] + f[i-1][j]) % mod;
		for(int j = 1; j <= n+1; ++j) f[i][j] = j <= n - i + 1 ? ((long long)s[n+1] - s[j-1] + mod) % mod : 0;
	}
	printf("%d\n", ((long long)f[m][1] - f[m-1][1] + mod) % mod * power(2, n-m-1) % mod);
	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long long l=0,a[100010]={0},u=0,v=0;
	bool L=false;
	while(v!=s.size())
	{
		if(!L)
		{
			u=s.find('L',l);
			v=s.find('R',u);
			if(v==-1)
			{
				v=s.size();
			}
			if((v-l)%2==0)
			{
				a[u]+=(v-l)/2;
				a[u-1]+=(v-l)/2;
			}
			else
			{
				if((v-u)>(u-l))
				{
					a[u-1]+=(v-l-1)/2;
					a[u]+=(v-l-1)/2+1;
					if((v-u)%2==0)
					{
						int temp;
						temp=a[u-1];
						a[u-1]=a[u];
						a[u]=temp;
					}
				}
				else
				{
					a[u]+=(v-l-1)/2;
					a[u-1]+=(v-l-1)/2+1;
					if((u-l)%2==0)
					{
						int temp;
						temp=a[u-1];
						a[u-1]=a[u];
						a[u]=temp;
					}
				}
			}
			L=true;
			l=u; 
		}
		else
		{
			u=s.find('R',l);
			L=false;
			l=u;
		}
	}
	for(int j=0;j<s.size();j++)
	{
		cout<<a[j]<<" ";
	}
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

typedef long long llint;

const int MAXN = 100005;

int n, m, cnt;
llint sum, sol=100000000700000007LL;
int l[MAXN], a[MAXN], b[MAXN], val[MAXN], p[MAXN];

struct event {
	int kome, ind, tip;
	event () {
	}
	event (int _kome, int _ind, int _tip) {
		kome=_kome; ind=_ind; tip=_tip;
	}
};

bool cmp (event e1, event e2) {
	return e1.ind<e2.ind;
}

vector <event> v;

int dist (int x, int y) {
	if (x<=y) return y-x;
	return m-x+y;
}

int main () {
	cin >> n >> m;
	for (int i=0; i<n; i++) {
		cin >> l[i];
	}
	for (int i=0; i<n; i++) {
		int nxt=(i+1)%n;
		a[i]=l[i]; b[i]=l[nxt];
		val[i]=dist(a[i], b[i]);
	}
	for (int i=0; i<n-1; i++) {
		sum+=min(val[i], b[i]);
		if (val[i]>=b[i]) {
			p[i]=1;
			cnt++;
		}
		if (b[i]==m) v.push_back(event(i, 1, 0)); else v.push_back(event(i, b[i]+1, 0));
		if (val[i]<=b[i]) v.push_back(event(i, b[i]-val[i]+1, 1)); else v.push_back(event(i, dist(val[i], b[i])+1, 1));
	}
	sort(v.begin(), v.end(), cmp);
	int pos=0;
	for (int i=1; i<=m; i++) {
		if (i!=1) sum-=cnt;
		while (v[pos].ind==i) {
			int kome=v[pos].kome;
			int ind=v[pos].ind;
			int tip=v[pos].tip;
			//if (i==2) cout << "event " << kome << " " << ind << " " << tip << endl;
			if (tip==0) {
				if (i!=1) sum+=val[kome];
				if (i!=1) cnt--;
				if (i!=1) p[kome]=0;
			} else {
				if (p[kome]==0) {
					p[kome]=1;
					cnt++;
				}
			}
			pos++;
		}
		//cout << i << " " << sum << " " << cnt << endl;
		sol=min(sol, sum);
	}
	cout << sol;
	return 0;
}





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



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }




    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        string s = sc.str;
        string t = sc.str;

        for(int i = 0; i < s.Length; ++i)
        {
            string u = s.Substring(0, i);
            string v = s.Substring(i);
            if (t == v + u)
            {
                wr.wri("Yes");
                return ;
            }
        }
        wr.wri("No");
    }
}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 11092
from itertools import combinations
hito = {c:0 for c in "MARCH"}
N = int(input())
for _ in range(N):
    S = input()
    if S[0] in "MARCH":
        hito[S[0]] += 1

ans = 0
values = list(hito.values())
indexes = [0, 1, 2, 3, 4]
for comb in combinations(indexes, 3):
    # print(comb)
    res = 1
    for initial in comb:
        res *= values[initial]
    ans += res
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
// #include <unordered_map>
// #include <bitset>
// #include <iomanip>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-9
#define LL_INF 0x3fffffffffffffff
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;
// #define DBG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
// #else
// #define DBG(...) 42
// #endif
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 0, 1,-1};
const int dy4[6] = {1, -1, 0,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};

void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}
 
ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 1e5 + 15;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
#define mst(x, a) memset(x, a, sizeof(x))
/*************************************************************************/




int main()
{   

    //  ios::sync_with_stdio(false);
    //  cin.tie(nullptr);
    ll n;
    SLLA(n);
    ll res = 1;
    ll sur = 1;
    ll cnt = 1;
    REPP(i,1,n) {
        res = res*10%mod;
        cnt = cnt*9%mod;
        sur = sur*8%mod;
    }
    printf("%lld\n", ((res - 2*cnt%mod + sur) % mod + mod ) %mod);
    return 0;
 
}


Measured memory_bytes: 3252
N, M = map(int, input().split())
connects = []
for _ in range(M):
    connect = list(map(int, input().split()))
    connects.append(connect[1:])

P = list(map(int, input().split()))

def check(state):
    is_ok = True
    for connect,p in zip(connects, P):
        switch_count = 0
        for switch in connect:
            shift = switch - 1
            switch_bit = 1<<shift
            if (switch_bit & state) > 0:
                switch_count +=1

        if switch_count % 2 != p:
            is_ok = False
            break

    return is_ok


full_state = 2**N

count = 0
for state in range(full_state):
    if check(state):
        count += 1


print(count)





Measured memory_bytes: 40048
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(factrial(n));
    }
    static long factrial(Long n){
        if(n==0)return 1;
        return n*factrial(n-1);
    }
}

Measured memory_bytes: 17160
inp = input()
n = int(input())
for i in range(n):
    od = input().split()
    #print(od)
    inp = list(inp)

    if (od[0] == "replace"):
        inp[int(od[1]):int(od[2])+1] = od[3]
        #print(inp)
    if (od[0] == "reverse"):
        ss = inp[int(od[1]):int(od[2])+1].copy()
        ss.reverse()
        #print(ss)
        inp[int(od[1]):int(od[2])+1] = ss
        #print(inp)

    if (od[0] == "print"):
        print("".join(inp[int(od[1]):int(od[2])+1]))


Measured memory_bytes: 5636
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    vi a(n),b(n);
    rep(i,0,n-1) cin>>a[i];
    rep(i,0,n-1) cin>>b[i];
    set<pii> ss;
    rep(i,0,n-1){
        if(a[i]!=b[i]) ss.insert({b[i],i});
    }
    ll ans=0;
    while(!ss.empty()){
        pii temp=*(ss.rbegin());
        ss.erase(temp);
        ll prev=(temp.S-1+n)%n;
        ll next=(temp.S+1)%n;
        ll curr=b[prev]+b[next];
        ll step=(b[temp.S]-a[temp.S])/(curr);
        if(step==0){
            cout<<"-1";
            return;
        }
        ans+=step;
        b[temp.S]-=step*(curr);
        if(b[temp.S]!=a[temp.S]) ss.insert({b[temp.S],temp.S});
        // cout<<temp.F<<" "<<temp.S;
        // return;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

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

    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
        mp[a] %= 2;
    }

    int m = mp.size();
    int k = 0;
    for(auto v : mp) {
        if (v.second == 0) k++;
    }
    k %= 2;
    cout << m-k << endl;
    
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  stack<int> ans;
  int pnt=0;
  while(1){
    bool flag=false;
    for(int i=pnt+m;i>pnt;i--){
      if(s[i]=='0'){
	//	cout<<i<<endl;
	ans.push(i-pnt);
	pnt=i;
	flag=true;
	break;
      }
    }
    if(!flag){cout<<-1<<endl;return 0;}
    else if(pnt==s.size() - 1) break;
  }
  while(!ans.empty() ){
    cout<<ans.top();
    ans.pop();
    if(!ans.empty() ) cout<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
int a[4][4],b[4][4],c[4][4];
int main(){
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<3;i++){
    for(int j=0;j<2;j++){
      b[i][j]=a[i][j+1]-a[i][j];
    }
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<3;j++){
      c[i][j]=a[i+1][j]-a[i][j];
    }
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<3;j++){
      if(b[i][j]!=b[i+1][j]){
        //cout<<b[i][j]<<" "<<b[i+1][j]<<endl;
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  for(int i=0;i<3;i++){
    for(int j=0;j<2;j++){
      if(c[i][j]!=c[i][j+1]){
        //cout<<i<<" "<<j<<" "<<c[i][j]<<" "<<c[i][j+1]<<endl;
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


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

ll gcd(ll a, ll b){
    if(b == 0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}

int main(){
    int N;cin>>N;
    ll s = 1LL;
    for(int i = 0; i < N ; i++){
        ll t;cin>>t;
        s = lcm(s,t);
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
int main() {
	std::vector<int> w(10), k(10);
	for (int i = 0; i < 10; i += 1)
		std::cin >> w[i];
	for (int i = 0; i < 10; i += 1)
		std::cin >> k[i];
	std::sort(w.begin(), w.end());
	std::sort(k.begin(), k.end());
	std::cout << w[7] + w[8] + w[9] << " "<< k[7] + k[8] + k[9] << std::endl;
	return 0;
}

Measured memory_bytes: 3052
#include<stdio.h>
int N,A[101],t,i,l,r,m,a;

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<N;i++)
			scanf("%d",&A[i]);

		scanf("%d",&t);
		for(l=0,r=N-1,a=0;l<=r;)
		{
			m=(l+r)/2;
			a++;
			if(A[m]==t)break;
			if(A[m]<t)l=m+1;
			else r=m-1;
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int x,a;
	cin>>x>>a;;
	if(x<a)cout<<0<<endl;
	else cout<<10<<endl;
	return 0;
}


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

int main() {
  int a;
  cin >> a;
  vector<int> data(a);
  for (int i = 0; i < a; i++) {
    cin >> data.at(i);
  }
  
  int count = 0;
  int s;
  for (int i = 0; i < a; i++) {
    for (int j = i + 1; j < a; j++) {
      s = data.at(i)*data.at(j);
      count += s;
    }
  }
  
  cout << count <<endl;
      
}


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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


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

    for(int i=1; i<=N; i++){
        double f = i*1.08;
        int a = floor(f);
        //DEBUG2(f,a);
        if(a == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program{
	static void Main(){
		int s=int.Parse(Console.ReadLine());
		int[] arr=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int a=0;

		for(int i=1;i<s;i++){
			if(arr[i-1]==arr[i]){a++;i++;}
		}
		Console.WriteLine("{0}",a);
	}
}

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

int main(){
  int N,K;
  cin >> N >> K;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
   cin >> vec.at(i);
  }

  vector<int64_t> sum(N);
  for (int i = 0; i < N; i++) {
    sum.at(i)=0;
    if (i==0) {
      for (int j = 0; j < K; j++) {
         sum.at(i)+=vec.at(j);
      }
    }
    else if(i+K-1<N){
      sum.at(i)=sum.at(i-1)-vec.at(i-1)+vec.at(i+K-1);
    }
  }

  sort(sum.begin(), sum.end());
  reverse(sum.begin(), sum.end());

  double E;
  E=(sum.at(0)+K)*0.5;
  cout << fixed << setprecision(12) << E << endl;
}

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

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

    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    rep(i,M) cin >> B[i];

    int c = 0;
    rep(i,N) {
        int sum = 0;
        rep(j,M) {
            int A;
            cin >> A;
            sum += A * B[j];
        }
        if (sum + C > 0) c++;
    }

    cout << c << endl;
    
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=1000050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int H,W;
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			string S;
			cin>>S;
			if(S=="snuke"){
				cout<<(char)(j+'A')<<i+1<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
s = input()

can = True
if s[0] != "A":
    can = False
else:
    cntc = 0
    for c in s[2:-1]:
        if c == "C":
            cntc += 1
    if cntc != 1:
        can = False
    else:
        cntup = 0
        for c in s:
            if c.isupper():
                cntup += 1
        if cntup != 2:
            can = False

if can:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string i2s(int x){
  stringstream ss;
  ss<<x;
  return ss.str();
}
int a[10][10]={};
bool check(string s){
  int k=0;
  for(int j=0;j<5;j++) k=a[k][s[j]-'0'];
  return !k;
}
int main(){
  int ans=0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<10000;i++){
    string s=i2s(i);
    while(s.size()<4) s="0"+s;
    int k=0;
    for(int j=0;j<4;j++){
      k=a[k][s[j]-'0'];
    }
    s+=(char)(k+'0');
    int f=0;
    for(int j=0;j<5;j++){
      string b=s;
      for(int l=0;l<10;l++) b[j]=(char)(l+'0'),f+=check(b);
    }
    for(int j=0;j<4;j++){
      if(s[j]==s[j+1]) continue;
      swap(s[j],s[j+1]);
      f+=check(s);
      swap(s[j],s[j+1]);
    }
    ans+=f!=5;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
    string s;
    string t;
    cin >> s >> t;
    string ans = "Yes";
    rep(i,s.length()){
        if(s[i] != t[i]) ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int k;
	int a,b,a1,b1;
	cin>>k>>a>>b;
	a1=a;
	b1=b;
	a/=k;
	b/=k;
	int flag = 0;
	for(int i = a; i<=b; i++)
		if(i*k>=a1 && i*k<=b1)
			flag = 1;
	if(flag)
		cout<<"OK"<<endl;
	else
		cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>

using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	int d,r;
	double f;
	r=int(a%b);
	d=a/b;
	f=double(a)/double(b);
	printf("%d %d %.5f",d,r,f);
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int idx = b - a - 1;
    int h = idx * (idx + 1) / 2;
    cout << h - a << endl;
}

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

int main(){
	int n,l;
	cin>>n>>l;
	map<string,int> s;
	for(int i = 0;i<n;i++){
		string a;
		cin>>a;
		s[a]++;
	}
	
	for(auto &e:s){
		for(int i = 0;i < e.second;i++){
			cout<<e.first;
		}
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())

P=[i for i in range(N+1)]
size=[1 for i in range(N+1)]


def find(x):
    if P[x]==x:
        return x
    else:
        return find(P[x])
        
def union(y,z):
    Y=find(y)
    Z=find(z)
    if Y!=Z:
        if size[Y]>=size[Z]:
            P[Z]=P[Y]
            size[Y]+=size[Z]
        else:
            P[Y]=P[Z]
            size[Z]+=size[Y]

for i in range(M):
    x,y,z=map(int,input().split())
    if find(x)!=find(y):
        union(x,y)
#print(P)
ans=0
for i in range(1,N+1):
    if i==P[i]:
        ans+=1
print(ans)

Measured memory_bytes: 7856
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b)) cout<<"A"<<endl;
    else cout<<"B"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int A, B;
    scanf("%d %d", &A, &B);

    int x;
    if (13 <= A) {
        x = B;
    } else if (6 <= A) {
        x = B / 2;
    } else {
        x = 0;
    }
    
    printf("%d\n", x);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
l = tuple(map(int,input().split()))
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]:
        continue
      ll = [l[i],l[j],l[k]]
      ll.sort()
      if ll[2] < ll[0]+ll[1]:
        #print(ll)
        ans += 1
print(ans)

Measured memory_bytes: 68336
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
using namespace std;
typedef long long ll;

ll N, A, B;


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

  if (N < A+B-1 || N > A*B) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> res(N);
  vector<int> a(A);
  ll n = N;
  a[0] = B;
  n -= B+A-1;
  for (int i = 1; i < A; ++i) {
    a[i] = 1 + min(n, B-1);
    n -= a[i]-1;
  }

  int e = 0;
  for (int i = 0; i < A; ++i) {
    for (int j = e; j <= e+a[i]-1; ++j) res[j] = a[i]+2*e-j;
    e += a[i];
  }

  for (int i = 0; i < N; ++i) {
    printf("%d%c", res[i], i != N-1 ? ' ' : '\n');
  }

}


Measured memory_bytes: 4096
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100010];
int main ()
{
	int n;
	cin>>n;
	memset(a,0,sizeof(a));
	int sum=0;
	for(int i=1;i<=n;i++)
	{		
		cin>>a[i];
	} 
	sort(a+1,a+1+n);
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[i+1])
		{
			a[i]=0;
			a[i+1]=0;
		}
		
		
		
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=0)
		{
			sum++;
		}
	}
	
	
	
	
	
	
	cout<<sum<<endl;	
 } 

Measured memory_bytes: 640
N=int(input())
a=[0]*N
b=[0]*N
genzai=0
AB=[]
for i in range(N):
    A,B=map(int,input().split())
    a[i]=A
    b[i]=B
    AB.append([B,A])
AB.sort()
for i in range(N):
    genzai+=AB[i][1]
    if genzai>AB[i][0]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 38828
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.rbegin(), a.rend());

  ll ans = 0;
  rep(i, 0, (n + 1) / 2) ans += a[i];
  ans *= 2;
  ans -= a[0];
  if (n % 2 == 1) ans -= a[n / 2];

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

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 185;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    for (int i = 0; i < n; ++i)
        cin >> s[i];
    int f[N][N][N + 1] = {};
    for (int c = m - 1; c >= 0; --c) {
        for (int r1 = 0; r1 < n; ) {
            int r2 = r1;
            while (r2 < n && s[r1][c] == s[r2][c])
                ++r2;
            for (int i = r1; i < r2; ++i)
                for (int j = i; j < r2; ++j)
                    f[i][j][c] = 1 + (c < m - 1 && s[i][c] == s[i][c + 1] ? f[i][j][c + 1] : 0);
            r1 = r2;
        }
    }
    int ans = 0;
    while (f[0][n - 1][0] != m) {
        ++ans;
        for (int c = 0; c < m; ++c) {
            for (int r1 = 0; r1 < n; ++r1) {
                for (int r2 = n - 1, i = n - 1; r2 >= r1; --r2) {
                    f[r1][r2][c] += f[r1][r2][c + f[r1][r2][c]];
                    if (r1 == r2)
                        continue;
                    if (i < r2)
                        ++i;
                    while (i > r1 + 1 && f[r1][i - 1][c] < f[i][r2][c]) {
                        f[r1][r2][c] = max(f[r1][r2][c], min(f[r1][i - 1][c], f[i][r2][c]));
                        --i;
                    }
                    f[r1][r2][c] = max(f[r1][r2][c], min(f[r1][i - 1][c], f[i][r2][c]));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int c=0,i;
	string a,b;
	cin>>a>>b;
	for(i=0;i<a.size();i++) 
		if(a[i]!=b[i])
		c++;
		cout<<c<<endl;
		return 0; 
 } 


Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
int a[100],b[100];
int count_1,count_2,count_3,count_4;

for(int i = 0; i < 3; ++i){
    cin >> a[i] >> b[i];
    if(a[i]==1||b[i]==1) count_1++;
    if(a[i]==2||b[i]==2) count_2++;
    if(a[i]==3||b[i]==3) count_3++;
    if(a[i]==4||b[i]==4) count_4++;
}
if(count_1==2||count_2==2||count_3==2||count_4==2) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;








}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

long int lcm(long int x, long int y){
    long int t;
    while (x != 0){
        t = y % x;
        y = x;
        x = t;
    }
    return y;
}

long int gcd(long int x, long int y){
    long int ans = (x * y) / lcm(x, y);
    return ans;
}

int main(){
    long int a, b;
    scanf("%ld %ld", &a, &b);

    printf("%ld\n", gcd(a,b));

}

Measured memory_bytes: 128
x, n = map(int, input().split())
if n > 0:
    p = [int(i) for i in input().split()]
else:
    p = [0]

y = []
for i in range(102):
    if i not in p:
        y.append(i)

m = 102
ans = -1
for i in y:
    if abs(x-i) < m:
        m = abs(x-i)
        ans = i

print(ans)



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

const int MOD = 1e9+7;

const int INF = 1e10;




int32_t main()
{
    
    IOS
    string s;
    cin>>s;
    deque<char>d;
    for(int i=0;i<s.length();i++){
        d.push_back(s[i]);
    }
    bool ori=true;
    int q;
    cin>>q;
    
    while(q--){
        int t;
        cin>>t;
        if(t==1){
            ori=!ori;
        }else{
            int f;
            char c;
            cin>>f>>c;
            if(f==1){
                if(ori)
                    d.push_front(c);
                else{
                    d.push_back(c);
                }
            }else{
                if(!ori)
                    d.push_front(c);
                else{
                    d.push_back(c);
                }
            }
        }
    }
    if(ori){
        //cout<<"AS";
        while(!d.empty()){
            cout<<d.front();
            d.pop_front();
        }
    }else{
        while(!d.empty()){
            cout<<d.back();
            d.pop_back();
        }
    }

    return 0;
}


Measured memory_bytes: 976
# coding: utf-8
# Your code here!
 
S = input()
count = 0
count_max = 0
 
for i in S : 
    if (i == "A" or i == "T" or i == "G" or i == "C") :
        count += 1
        count_max = max(count_max, count)
    else : 
        count = 0
        
print(count_max)

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

#define    ll     long long int

const ll N = 200005;
ll ara[N];
ll lft[N];
ll rgt[N];

int main( )
{
    ll k, n;
    ll s1 = 0, s2 = 0;
    ll i, j;
    cin >> k >> n;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
    }
    lft[1] = 0;
    for (i = 2; i <= n; i++) {
        lft[i] = lft[i - 1] + abs(ara[i] - ara[i - 1]);
    }
    rgt[n] = 0;
    for (i = n - 1; i >= 1; i--) {
        rgt[i] = rgt[i + 1] + abs(ara[i] - ara[i + 1]);
    }
    ll ans = min(lft[n], abs(k - ara[n]) + ara[1] + rgt[2]);
    for (i = 2; i <= n; i++) {
        ll l = rgt[1] - rgt[i] + abs(k - ara[n]) + ara[1] + rgt[i + 1];
        ll r = lft[n] - lft[i] + abs(k - ara[n]) + ara[1] + lft[i - 1];
        ans = min(ans, min(l, r));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define fst first
#define snd second

using namespace std;


typedef long long ll;
const int maxn = 2e5 + 10;
pair<ll,ll> a[maxn], b[maxn];
int ca, cb;

bool cmp(pair<ll,ll> a, pair<ll,ll> b) {
	if(a.fst == 0&&b.fst == 0) return a.snd < b.snd;
	return a.fst * b.snd + a.fst > b.fst * a.snd + b.fst;
}
ll dp[2][32];

int main() {
	int n, t;
	scanf("%d%d", &n, &t);
	for(int i = 1;i <= n;++i) {
		scanf("%d%d", &a[i].fst, &a[i].snd);
	}

	sort(a + 1,a + 1 + n, cmp);
	memset(dp, - 1,sizeof dp);
	dp[0][0] = 0;
	int now = 0,last = 1, idx = n + 1;
	for(int i = 1;i <= n;++i) {
		if(!a[i].fst) {
			idx = i;
			break;
		}
		swap(now, last);
		memcpy(dp[now], dp[last], sizeof(dp[now]));
		for(int j = 1;j < 32;++j) {
			if(dp[last][j-1] != -1) {
				ll to = a[i].fst * (dp[last][j-1] + 1) + a[i].snd + dp[last][j-1] + 1;
				if(to > t) continue;
				if(dp[now][j] == -1) dp[now][j] = to;
				else dp[now][j] = min(dp[now][j], to);
			}
		}
	}
	int ans = 0;
	for(int i = 31;i >= 0;--i) if(dp[now][i] != -1) {
		int tmp = i;

		for(int j = idx;j <= n;++j) {
			if(dp[now][i] + a[j].snd + 1 <= t) ++tmp, dp[now][i] += a[j].snd + 1;
			else break;
		} 
		ans = max(ans, tmp);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin>>n;
    rep(i,n){
      rep(j,n){
        if(i*4+j*7==n){
          cout<<"Yes"<<endl;
          return 0;
        }
      }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,asum=0;cin>>n>>m;
  lvector A(n,0);rep(i,n) {cin>>A[i];asum+=A[i];}
  double lim=asum/(4.0*m);
  ll ans=0;
  rep(i,n) if(A[i]>=lim) ans++;
  if(ans<m) puts("No");else puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int M; cin >> M; 
	long long D[200010] = {}; 
	long long C[200010] = {}; 
	long long sum = 0LL; 
	long long digit = 0; 
	for(int i = 0; i < M; i++){
		cin >> D[i] >> C[i]; 
		sum += D[i] * C[i]; 
		digit += C[i]; 
	}
	long long ans = digit - 1; 
	ans += (sum - 1)/ 9; 
	cout << ans << endl; 
}	

Measured memory_bytes: 3328
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())

C = Counter(S)
print(C["+"] - C["-"])

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  ll res1 = 0, res2 = 0;
  rep(i, m) {
    ll a;
    cin >> a;
    if (a < x) res1++;
    else res2++;
  }
  cout << min(res1, res2) << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))
x = float("inf")

dp = [x] * n
dp[0] = 0
for i in range(1, n):
    for j in range(max(0, i - k), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))

print(dp[n - 1])


Measured memory_bytes: 55008
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import qualified Data.Vector as V
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x
-------------------------------------------------------------
main = do
    s <- getLine
    let ss = sort s
    if (ss == "abc")
    then putStrLn "Yes"
    else putStrLn "No"
    

Measured memory_bytes: 380
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	int h, r;
	cin >> h >> r;
	if (h <= 0) {
		if (abs(h) == r) {
			cout << 0 << endl;
		}
		else if(abs(h) > r){
			cout << -1 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	else {
		cout << 1 << endl;
	}
}


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

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(auto &i:a)cin >> i;
	ll ans = 0;
	for(int i = 1;i<=min(k,n);i++)//kこ取り出す時
	{
		for(int r = 0;r<=i;r++)//右からr個取り出す
		{
			ll sum = 0;
			vector<ll> now;
			for(int j =0;j<r;j++)
			{
				now.push_back(a[j]);
			}
			for(int j = 0;j<i-r;j++)
			{
				now.push_back(a[n-1-j]);
			}
			int s = k-i;
			sort(now.begin(),now.end());
			//if(i==3){//for(auto i:now)cout<<i<<' ';cout<<endl;}
			for(int j = 0;j<now.size();j++)
			{
				if(j<s)
				{
					if(now[j]>0)sum += now[j];
				}
				else
				{
					sum += now[j];
				}
			}
			ans = max(sum,ans);
			//if(i==k)cout<<sum<<endl;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define vii vector<int>
#define vll vector<ll>
#define vip vector<pair<int,int> >
#define pb push_back


int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //#ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w",stdout);
    //#endif

    /*int tc;
    cin>>tc;
    while(tc--)
    {

    }*/
    map<int,int> m;bool f=1;
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        int x;
        cin>>x;
        ++m[x];
        if(m[x]>1) f=0;
    }
    cout<<(f?"YES\n":"NO\n");
    return 0;
}


Measured memory_bytes: 9600
N=int(input())
suma=N
for i in range(1,N):
    factor_n1 = [int(x) for x in list(str(i))] 
    s1=sum(factor_n1)
    factor_n2 = [int(y) for y in list(str(N-i)) ]
    s2=sum(factor_n2)
    if(s1+s2<suma):
        suma=s1+s2
print(suma)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

N = int(input())
array1 = []
array2 = []
for i in range(N):
    s = input()
    x1 = 0
    x2 = 0
    x3 = 0
    flag = True
    for j in range(len(s)):
        if s[j] == "(":
            if flag:
                x3 = 1
            else:
                x3 += 1
            flag = False
            x1 += 1
        elif s[j] == ")":
            x1 -= 1
            if flag:
                x2 += 1
            else:
                x3 -= 1
    if x3 < 0:
        x2 = x2 - x3
    if x1 >= 0:
        array1.append((-x2,x1))
    else:
        array2.append((x2+x1,-x2,x1))
array1.sort(reverse = True)
array2.sort(reverse = True)
sum = 0
ans = True
for i in range(len(array1)):
    if sum + array1[i][0] >= 0:
        sum += array1[i][1]
    else:
        ans = False
        break
for i in range(len(array2)):
    if sum + array2[i][1] >= 0:
        sum += array2[i][2]
    else:
        ans = False
        break
if sum != 0:
    ans = False
if ans:
    print("Yes")
else:
    print("No")


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0;
  long long cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 0 && sum <= 0) {
      cnt1 += 1 - sum;
      sum = 1;
    } else if (i % 2 == 1 && sum >= 0) {
      cnt1 += 1 + sum;
      sum = -1;
    }
  }
  sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 1 && sum <= 0) {
      cnt2 += 1 - sum;
      sum = 1;
    } else if (i % 2 == 0 && sum >= 0) {
      cnt2 += 1 + sum;
      sum = -1;
    }
  }
  cout << min(cnt1, cnt2) << endl;
  return 0;
}

Measured memory_bytes: 640
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N-2):
        if S[i:i+3]=='ABC':
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if a * b > c * d {
		fmt.Println(a * b)
	} else if a * b < c * d {
		fmt.Println(c * d)
	} else {
		fmt.Println(a * b)
	}
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int b[1000001]={};
int main()
{
	int n,i,j,k,l,p,o,s;
	cin>>n;
	for(i=2;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[a[i]]++;
	}
	for(i=1;i<=n-1;i++)
	cout<<b[i]<<' ';
	cout<<b[n];
	return 0;
}

Measured memory_bytes: 5332
#include <stdio.h>
   
   int e;
   
   int x, y, z;
   int m;
   
   int main(void)
   {
      while(1) {
          m = 1000000;
          y = 0;
          z = 0;
          scanf("%d", &e);
          if (e == 0) break;
          while (z * z * z <= e) {
              while (y * y <= e - z * z * z) {
                  x = e - y * y - z * z * z;
                  if (m > x + y + z) {
                      m = x + y + z;
                  }
                  y++;
              }
              y = 0;
              z++;
          }
          printf("%d\n", m);
      }
  }
            

Measured memory_bytes: 1028
// https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
using namespace std;

int N, k;
int dp[100005];
int arr[100005];

void mini(int &a, int b) {
	a = min(a, b);
}

void read() {
	cin >> N >> k;
	for (int i= 1; i <= N; i++) cin >> arr[i];
}

void solve() {
	dp[1] = 0;
	for (int i = 2; i <= N; ++i) {
		dp[i] = INT_MAX;
		for (int j = 1; i-j > 0 and j <= k; ++j) {
			mini(dp[i], abs(arr[i]-arr[i-j])+dp[i-j]);
		}
	}
}

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

	read();
	solve();

	cout << dp[N] << endl;

	return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

class MOD {
    static long[] fac,inv,finv;
    static int mod = 1000000007;

    public static long getPowMod(long a, long x,long mod){
        long res = 1;
        while(x > 0){
            if((x&1)==1){
                res = (res*a)%mod;
            }
            x>>=1;
            a = (a*a)%mod;
        }
        return res;
    }
    public static long getFactorialMod(long n,long mod){
        if(n==0){
            return 1;
        }else{
            return (n*getFactorialMod(n-1, mod))%mod;
        }
    }

    public static long nCkMod(long n,long k,long mod){
        if(n < k){
            return 0;
        }else{
            long nMod = getFactorialMod(n, mod);
            long kinvMod = getPowMod(getFactorialMod(k, mod), mod-2, mod);
            long n_kinvMod = getPowMod(getFactorialMod(n-k, mod), mod-2, mod);
            long x = (nMod*kinvMod)%mod;
            return (x*n_kinvMod)%mod;
        }
    }

    public static void COMinit(int max){
        fac = new long[max];
        inv = new long[max];
        finv = new long[max];
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for(int i=2;i<max;i++){
            fac[i] = fac[i-1]*i%mod;
            inv[i] = mod-inv[mod%i]*(mod/i)%mod;
            finv[i] = finv[i-1]*inv[i]%mod;
        }
    }
    public static long nCkMod2(int n,int k){
        if(n < k)return 0;
        return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        if((2*y-x)%3==0 && 2*y>=x && 2*x >= y){
            MOD.COMinit((x+y));
            int n= (x+y)/3;
            int k = (2*y-x)/3;
            System.out.println(MOD.nCkMod2(n, k));
        }else{
            System.out.println(0);
        }
        sc.close();
    }
    
}

Measured memory_bytes: 69332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int a[n],mx=0,mn=0,mnx=0;
	rep(i,n){
		cin>>a[i];
		mx=max(a[i],mx);
	}
	rep(i,n){
		int b=min(a[i],mx-a[i]);
		if(mn<b) mnx=a[i];
		mn=max(mn,min(a[i],mx-a[i]));
	}

	cout<<mx<<" "<<mnx<<"\n";
}

Measured memory_bytes: 640
#include<stdio.h>

int linearSearch(int n,int A[],int key){
  int i=0,j=0;
  A[n]=key;
  while(A[i]!=key)i++;
  return i;
}

int main(){
  int i,n,S[10000+1],q,T,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T);
    if(linearSearch(n,S,T)!=n)sum++;
  }
  printf("%d\n",sum);
  return 0;
}
  



Measured memory_bytes: 2144
N, M = gets.chomp.split.map(&:to_i)
X = gets.chomp.split.map(&:to_i).sort

if M <= N
  puts 0 ; exit
end

distance = X[-1] - X[0]
diff = X.each_cons(2).map{ |a, b| b - a }.sort.reverse

(N - 1).times do |n|
  distance -= diff[n]
end

puts distance

Measured memory_bytes: 14656
from collections import Counter
import heapq
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = list(Counter(A).values())
heapq.heapify(c)
kind = len(c)

cnt = 0
while K < kind:
    kind -= 1
    cnt += heapq.heappop(c)

print(cnt)

Measured memory_bytes: 32556
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
void checkpoint1()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	*/
}
int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	ll a[n],dp[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
		dp[i]=inf;
	}
	dp[0]=0;
	for(ll i=1;i<n;i++)
	{
		for(ll j=1;j<=2;j++)
		{
			if(i-j>=0)
				dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1792
sa = input()
sb = input()
sc = input()
S = [sa, sb, sc]
d = {'a':0, 'b':1, 'c':2}
sidx = {'a':0, 'b':0, 'c':0}
# 次の人
nxt = S[0][0]
sidx[nxt] += 1
while True:
    s = S[d[nxt]]
    idx = sidx[nxt]
    if idx < len(s):
        sidx[nxt] += 1
        nxt = s[idx]
    else:
        print(nxt.upper())
        break
    

Measured memory_bytes: 3064