akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    int ans = 0;
    rep(i, N) {
        ans += A[i] / 2;
        A[i] -= (A[i] / 2) * 2;
        if (i + 1 == N) break;
        if (A[i + 1] >= 1 && A[i] >= 1) {
            A[i]--;
            A[i + 1]--;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
// mitocode
#include <stdio.h>
  
void bomb(int x, int y);
  
char field[10][10];
  
int main(void)
{
    int n, m;
    int i, j;
    int x, y;
      
    m = 0;
    scanf("%d", &n);
    while (m < n){
        for (i = 0; i < 8; i++){
            scanf("%s", field[i]);
        }
          
        scanf("%d %d", &x, &y);
        bomb(x - 1, y - 1);
          
        printf("Data %d:\n", m + 1);
        for (i = 0; i < 8; i++){
            printf("%s\n", field[i]);
        }
        m++;
    }
    return (0);
}
  
  
void bomb(int x, int y)
{
    int i;
      
    field[y][x] = '0';
    for (i = 1; i <= 3; i++){
        if (field[y][x - i] == '1' && x - i >= 0){
            bomb(x - i, y);
        }
        if (field[y][x + i] == '1' && x + i < 8){ 
            bomb(x + i, y);
        }
        if (field[y - i][x] == '1' && y - i >= 0){
            bomb(x, y - i);
        }
        if (field[y + i][x] == '1' && y + i < 8){ 
            bomb(x, y + i);
        }
    }
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if (s[k-1] == 'A')
    {
        s[k-1] = 'a';
    }
    if (s[k-1] == 'B')
    {
        s[k-1] = 'b';
    }
    if (s[k-1] == 'C')
    {
        s[k-1] = 'c';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll k,s,ans=0;

	std::cin >> k >> s;

	repeq(x, 0, k) {
		if (x > s) {
			break;
		}
		repeq(y, 0, k) {
			ll z = s - x - y;
			if (0 <= z && z <= k) {
				ans++;
			}
			else if(x+y>s) {
				break;
			}
		}
	}
	
	outn(ans);
	return 0;

}


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

int main(void){
  string s;
  cin >> s;
  
  int count = 0; //1の数を記録する変数
  
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '1') {
      count++;
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>

using std::map;

const int MAXN=200005;
int n,m;
int D[MAXN],T[MAXN];

map<int,int> mp;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&D[i]);
		++mp[D[i]];
	}
	scanf("%d",&m);
	for(int i=1;i<=m;++i){
		scanf("%d",&T[i]);
		if(!mp.count(T[i]) || mp[T[i]]==0){
			printf("NO");
			return 0;
		}
		else --mp[T[i]];
	}
	printf("YES");
	return 0;
}

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

int main() {
	vector<vector<int>> c(3, vector<int> (3, 0));
	for (int i=0; i<3; i++)
		for (int j=0; j<3; j++)
			cin >>c.at(i).at(j);
	bool Ok=true;
	int cc=c.at(0).at(1)-c.at(0).at(0);
	if (cc!=c.at(1).at(1)-c.at(1).at(0))
		Ok=false;
	if (cc!=c.at(2).at(1)-c.at(2).at(0))
		Ok=false;
	cc=c.at(0).at(2)-c.at(0).at(0);
	if (cc!=c.at(1).at(2)-c.at(1).at(0))
		Ok=false;
	if (cc!=c.at(2).at(2)-c.at(2).at(0))
		Ok=false;
	if (Ok)
		cout <<"Yes" <<endl;
	else
		cout <<"No" <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; string str; cin>>n;
  set<string> st;
  for(int i=1;i<=n;i++){
    cin>>str; st.insert(str);}
  cout<<st.size();
  return 0;
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int num = 0,i;
	for(i=0;i<s.length();i++)
	{
		if(s[i]=='+')
			num++;
		else
			num--;
	}
	cout<<num<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>

using namespace std;
typedef long long Int;
#define REP(i , x) for(int i = 0 ; i < x ; ++i)


int main()
{
	int n;
	while (cin >> n, n){
		int dise[4][3] = { { 0, 5, 0 }, { 4, 1, 3 }, { 0, 2, 0 }, { 0, 6, 0 } };
		int ans(1);
		vector<string> com;
		REP(i, n){
			string a;
			cin >> a;
			com.push_back(a);
		}

		for (auto x : com){
			if (x == "North"){
				int now = dise[2][1];
				dise[2][1] = dise[3][1];
				dise[3][1] = dise[0][1];
				dise[0][1] = dise[1][1];
				dise[1][1] = now;
				ans += now;
			}
			if (x == "East"){
				int now = dise[1][0];
				dise[1][0] = dise[3][1];
				dise[3][1] = dise[1][2];
				dise[1][2] = dise[1][1];
				dise[1][1] = now;
				ans += now;
			}
			if (x == "West"){
				int now = dise[1][2];
				dise[1][2] = dise[3][1];
				dise[3][1] = dise[1][0];
				dise[1][0] = dise[1][1];
				dise[1][1] = now;
				ans += now;
			}
			if (x == "South"){
				int now = dise[0][1];
				dise[0][1] = dise[3][1];
				dise[3][1] = dise[2][1];
				dise[2][1] = dise[1][1];
				dise[1][1] = now;
				ans += now;
			}
			if (x == "Left"){
				int temp = dise[2][1];
				dise[2][1] = dise[1][0];
				dise[1][0] = dise[0][1];
				dise[0][1] = dise[1][2];
				dise[1][2] = temp;
				ans += dise[1][1];
			}
			if (x == "Right"){
				int temp = dise[2][1];
				dise[2][1] = dise[1][2];
				dise[1][2] = dise[0][1];
				dise[0][1] = dise[1][0];
				dise[1][0] = temp;
				ans += dise[1][1];
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1352
n,a,b = map(int,input().split())

if (n%(a+b)) == 0:
    print(((n//(a+b))*a))
else:
    if (n%(a+b)) < a:
        print(((n//(a+b))*a)+(n%(a+b)))
    else:
        print(((n//(a+b))*a)+a)

Measured memory_bytes: 38384
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

x = int(input())
li = [1]
b = 2
for b in range(1,x+1):
    for p in range(2,11):
        if b**p<=x:
            li.append(b**p)
print(max(li))

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

int main() {

	int w{}, h{};
	std::cin >> h >> w;
	std::vector<std::string> v;

	const auto white = '.';

	for (int i{}; i < h; i++) {
		std::string s;
		std::cin >> s;
		auto all_white = std::all_of(std::begin(s), std::end(s)
			, [&](const auto& x) {return white == x; });

		if (!all_white)
			v.emplace_back(std::move(s));
	}

	std::vector<int>wv;
	wv.reserve(w);

	for (int i{}; i < w; i++) {

		bool all_white = true;
		for (auto&e : v) {
			const auto&cs = e;
			all_white &= cs[i] == white;
		}

		if (all_white) {
			for (auto&s : v) 
				for (int wi{ i}; wi+1 < w;wi++)
					s[i] = s[i+1];
			
		} else{
			wv.push_back(i);

		}

	}

	for (const auto& e : v) {
	
		for(auto &we:wv){
			std::cout << e[we];
		}

		std::cout << "\n";
	}
	return 0;
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a[100];
    for(int i=0;i<100;i++)
        a[i]=0;
    int x;
    while(cin >> x){
        a[x-1]+=1;
    }
    int max=0;
    for(int i=0;i<100;i++){
        if(max<a[i])
            max=a[i];
    }
    for(int i=0;i<100;i++){
        if(max==a[i])
            cout << i+1 << endl;
    }

}

Measured memory_bytes: 1156
#include <stdio.h>
#define N 10001
int linearserach(int*,int,int);

int main(){
  int i,n,S[N],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(linearserach(S,n,t))sum++;
  }

  printf("%d\n",sum);

  return 0;
}
int linearserach(int* S,int n,int t){
  int i=0;
  S[n]=t;
  while(S[i]!=t){
    i++;
  }
  if (i==n)return 0;
  return 1;
    
}



Measured memory_bytes: 2712
def main():
    n, x, m = map(int, input().split())

    idx = [-1] * m

    i = 1
    y = x
    while not(~idx[y]):
        idx[y] = i
        y = (y * y) % m
        i += 1
    start = idx[y]
    end = i

    loop_len = end - start  # [start,end)

    ans = 0
    rep = 0

    rep_flg = False
    finish = False

    j = 1
    while j <= n:
        if finish:
            ans += x
        else:
            if j == start or j == end:
                if rep_flg:
                    k = (n - 1 - j) // loop_len
                    ans += (k + 1) * rep
                    j += k * loop_len
                    rep_flg = False
                    finish = True
                    if j == n:
                        break
                else:
                    rep_flg = True
            if rep_flg:
                rep += x
            else:
                ans += x
        x = (x * x) % m
        j += 1

    if not finish:
        ans += rep
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11180
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    double r;
    r = sc.nextDouble();

    System.out.printf("%f %f%n", r * r * Math.PI, 2.0 * r * Math.PI);
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

int main(){
//double a,b,c;
//cin>>a>>b>>c;
//cout<<floor((c+0.5)/a)*b<<endl;


int n,x;
cin>>n;



vector<int>v1,v2;
for(int i=1;i<=2*n;i++){
    int a;
    cin>>a;
    if(i<=n){
        v1.push_back(a);
    }
    else  v2.push_back(a);
}

int ans=0;
  for(int i=0;i<n;i++)
  {

      if(v1[i]>v2[i])
        ans+=v1[i]-v2[i];
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 256
X, Y = list(map(int, input().split()))

if X % Y == 0:
    print(-1)
else:
    count = 2
    while True:
        cand = X * count
        if cand % Y != 0:
            print(cand)
            break
        elif 10**9 < cand:
            print(-1)
            break
        count += 1


Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
int n,a,b;
int main(){
	cin>>n>>a>>b;
	if (abs(a-b)%2==0) cout<<"Alice"<<endl; else cout<<"Borys"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int>x(N);
  vector<int>y(M);
  for(int i=0;i<N;i++)
    cin>>x.at(i);
  for(int i=0;i<M;i++)
    cin>>y.at(i);
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if(x.at(N-1)<Y && X<y.at(0) && x.at(N-1)<y.at(0))
    cout<<"No War"<<endl;
  else
    cout<<"War"<<endl;
  

return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

n,q=map(int,input().split())
c=list(map(int,input().split()))
ques=[]
from collections import defaultdict
ans=defaultdict(int)
for _ in range(q):
    l,r=map(int,input().split())
    ques.append((l,r))

sortques=sorted(ques, key=lambda x:x[1])

good=BIT(n+1)
goodind=[-1]*n
last=0
for x in range(q):
    l,r=sortques[x]
    if last!=r:
        for i in range(last, r):
            if goodind[c[i]-1]==-1:
                goodind[c[i]-1]=i
                good.add(i+1, 1)
            else:
                j=goodind[c[i]-1]
                good.add(j+1, -1)
                goodind[c[i]-1]=i
                good.add(i+1, 1)
    ans[(l,r)]=good.get(l-1,r)
    last=r

for i in range(q):
    print(ans[ques[i]])

Measured memory_bytes: 261632
program calendar
  implicit none
  integer :: n, k, x = 0, i, j
  read(*,*) n, k
  n = n-2
  if (n >= 11) then
    x = n/11*5
    n = mod(n,11)
  end if
  do i = 1, 5
    do j = 1, n
      if(mod(8*j+9*i-2,11) == k) x = x+1
    end do
  end do
  write(*,'(i0)') x
end program calendar

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

int main(){
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    ll cnt= 0;
    ll nL = 0;
    rep(i,N){
        if(S[i] == 'L'){
            nL++;
        }
    }
    ll nR = N - nL;
    //char a = S[0];
    rep(i,N-1){
        if(S[i+1] == S[i]){
            cnt++;
        }
    }
    cout << min(N-1, cnt+2*K) <<endl;

/*
    rep(i,K){
        char a = S[0];
        int rec=-1;
        rep(j,N-1){
            if(S[j+1] == a) continue;
            rec = j+1;
        }
        if(rec == -1){
            cnt=N-1;
            break;
        }
        //char b = S[N-1];
        int rec2=-1;
        bool flag = false;
        rep(j,N){
            if(S[N-1-j] == a){
                flag = true;
                continue;
            }
            if(flag){
                rec2 = N-1-j;
                break;
            }
        }
        if(rec < rec2){
            cnt += 2;
        }else{
            cnt+=1;
        }



    }
    cout << cnt << endl;*/
}


Measured memory_bytes: 512
function Main(input) {
  input = input.split('\n');
  s = input[0].split('');
  t = input[1].split('');
  var n = 0;

  if(s[0] === t[0]){
    n++;
  }
  if(s[1] === t[1]){
    n++;
  }
  if(s[2] === t[2]){
    n++;
  }
  console.log(n);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
N, M = [int(x) for x in input().split()]
P = [[False] * N for m in range(N)]
dict={}
for m in range(M):
  a, b = [int(x) for x in input().split()]
  P[a-1][b-1] = True
  P[b-1][a-1] = True

def dp(x, past):
  past[x] = True
  if (x, tuple(past)) in dict:
    return dict[(x, tuple(past))]
  if False not in past:
    return 1
  ret = 0
  for i,p in enumerate(P[x]):
    if not p or x == i or past[i]:
      continue
    else:
      ret += dp(i, past[:])
  dict[(x, tuple(past))] = ret
  return ret

if M < N - 1:
  print(0)
else:
  print(dp(0, [False] * N))

Measured memory_bytes: 3064
s = list(input())

ans = float("INF")
if len(s) == 1:
    print(1)
    exit()
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        c = max(i+1,len(s)-i-1)
    
        ans = min(ans,c)
if ans == float("INF"):
    print(len(s))
else:

    print(ans)

Measured memory_bytes: 49904
//#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <iostream>


using namespace std;

int main() {
    int a;
    cin >> a;
    string s;
    cin >> s;
    string r = "red";
    if (a >= 3200) {
        printf("%s", s.c_str());
    } else {
        printf("%s", r.c_str());
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  if (n >= 30) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

Measured memory_bytes: 3652
N = int(input())
points = [list(map(int, input().split())) for _ in range(N)]
sum_dist = 0

for i in range(N):
    for j in range(i + 1):
        sum_dist += (
            (points[j][0] - points[i][0]) ** 2 + (points[j][1] - points[i][1]) ** 2
        ) ** 0.5
print(sum_dist * 2 / N)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int m1 = sc.nextInt();
    int d1 = sc.nextInt();
    int m2 = sc.nextInt();
    int d2 = sc.nextInt();
    
    if(d2 == 1)
      System.out.println(1);
    else
      System.out.println(0);
  }
}

Measured memory_bytes: 25044
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

struct UnionFind{
    vector<int> parents;
    vector<int> ranks;
    int N;

    UnionFind(int N): N(N){
        parents = vector<int>(N,-1);
        ranks = vector<int>(N,0);
    }

    int find(int a){
        if(parents[a] == -1)return a;
        int root = find(parents[a]);
        parents[a] = root;
        return root;
    }

    bool connect(int a, int b){
        int root_a = find(a);
        int root_b = find(b);
        if(root_a==root_b)return false;
        if(ranks[a]>ranks[b]){
            parents[root_b] = root_a;
        }else if(ranks[a]<ranks[b]){
            parents[root_a] = root_b;
        }else{
            parents[root_a] = root_b;
            ranks[root_b]++;
        }
        return true;
    }
};
struct Edge{
    int from;
    int to;
    int cost;
};
int main(){
    int N;cin>>N;
    vector<vector<ll>> graph_A(N,vector<ll>(N,0));
    ll INF = 1e15;
    vector<vector<ll>> graph_B(N,vector<ll>(N,0));
    for(int i = 0;i<N;i++){
        for(int j = 0;j<N;j++){
            int a;cin>>a;
            graph_A[i][j]=a;
            graph_B[i][j]=a;
        }
    }
    vector<vector<int>> prev(N, vector<int>(N,-1));
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            prev[i][j]=i;
        }
    }
    for(int k = 0;k < N;k++){
        for(int i = 0;i < N;i++){
            for(int j = 0;j < N;j++){
                if(graph_B[i][j]>=graph_B[i][k]+graph_B[k][j]){
                    if(k==j||i==k)continue;
                    graph_B[i][j] = graph_B[i][k]+graph_B[k][j];
                    prev[i][j]=prev[k][j];
                }
                
            }
        }
    }
    ll res = 0;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            if(prev[i][j] == i){
                res += graph_B[i][j];
            }
        }
    }
    res /= 2;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            // cout<<prev[i][j]<<" ";
            if(graph_B[i][j]!=graph_A[i][j]){
                cout<<-1<<endl;
                return 0;
            }
        }
        // cout<<endl;
    }
    cout<<res<<endl;




}

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

int main()
{
        long long int n;
        cin>>n;
        long long int c=0;
        int arr[n];
        for(int i=0;i<n;i++)
        cin>>arr[i];
        
        sort(arr,arr+n);
        
        for(int i=n-1;i>=1;i--)
        {
            int l=0,r=i-1;
            while (l<r)
            { 
                if(arr[l]+arr[r]>arr[i])
                {
                    c+=r-l;
                    r--;
                    
                }
                else
                l++;
                }
            }
        cout<<c<<endl;
}

Measured memory_bytes: 384
n,m = map(int,input().split())
ac, wa=[False]*n,[0]*n
for i in range(m):
  p,s = input().split()
  p=int(p)
  if s=='AC': ac[p-1]=True
  elif (s=='WA') and (ac[p-1]==False): wa[p-1]+=1

penalty, clear=0,0
for i,tf in enumerate(ac):
  if tf:
    penalty += wa[i]
    clear += 1
print('%d %d'%(clear,penalty))

Measured memory_bytes: 4596
#include <bits/stdc++.h>
typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
int main(void)
{
    int n;
    cin >> n;
    vector<ll> v(n);
    map<ll, ll> mp;
    rep(i, 0, n) cin >> v[i], mp[v[i]]++;
    ll ans = 0;
    for (auto i : mp)
    {
        if (i.first > i.second)
            ans += i.second;
        else if (i.first == i.second)
            continue;
        else
            ans += i.second - i.first;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9992
let prime_p n =
  if n == 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else begin
    let rec doit i =
      if i*i > n then true
      else if n mod i = 0 then false
      else doit (i + 2)
    in
    doit 3
  end

let () =
  let n = read_int () in
  let rec read i cnt =
    if i >= n then cnt
    else read (i + 1) (cnt + (if prime_p (read_int ()) then 1 else 0))
  in
  Printf.printf "%d\n" (read 0 0)

Measured memory_bytes: 3224
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

const int dice[7][10] = {{0},
		{0,3,5,4,2,3,5,4,2,3},
		{0,1,4,6,3,1,4,6,3,1},
		{0,5,1,2,6,5,1,2,6,5},
		{0,5,6,2,1,5,6,2,1,5},
		{0,1,3,6,4,1,3,6,4,1},
		{0,5,3,2,4,5,3,2,4,5}
};

const int vx[] = {1,0,-1,0}, vy[] = {0,1,0,-1};

int topmap[50][50], heightmap[50][50];

void fall( int top, int front , int x, int y){
	int i, j, before=0,nextFront;
	for(i=0; dice[top][i]!=front; i++);
	for(j=i; j<i+4; j++){
		if( dice[top][j] > 3 && heightmap[x][y] > heightmap[x+vx[j-i]][y+vy[j-i]] ){
			if( dice[top][before] < dice[top][j] ){
				before = j;
			}
		}
	}
	if( before != 0 ){
		switch( vx[before-i] ){
			case -1:
				nextFront = 7-top;
				break;
			case 1:
				nextFront = top;
				break;
			case 0:
				nextFront = front;
		}
		fall( dice[top][before+2], nextFront, x+vx[before-i], y+vy[before-i] );
	}else{
		topmap[x][y] = top;
		heightmap[x][y]++;
	}
	return;
}

int main(){
	int n,i,j, t, f,numCnt[7];
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(topmap,0,sizeof(topmap));
		memset(heightmap,0,sizeof(heightmap));
		memset(numCnt,0,sizeof(numCnt));
		for(i=0; i<n; i++){
			scanf("%d %d", &t, &f);
			fall( t, f, 25, 25);
		}
		for(i=0;i<50;i++)
			for(j=0;j<50;j++)
				numCnt[topmap[i][j]]++;
		for(i=1;i<=6;i++)
			printf("%d%c",numCnt[i],(i==6)?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int main(void){

int n;
     int a[101];
     int result=99999999;
     cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
  for(int t=1;t<n;t++){
    int f=0,l=0;
     for(int j=1;j<=t;j++){
        f+=a[j];
     }
     for(int j=t+1;j<=n;j++){
        l+=a[j];
     }
     result=min(abs(l-f),result);
  }
  cout << result;
    













}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
 
#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
 
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
 
int H, W;
VVI dx = {{1,0,-1,-1,-1,0}, {1,1,0,-1,0,1}};
VVI dy = {{0,1,1,0,-1,-1}, {0,1,1,0,-1,-1}};
 
int solve(int x, int y, VVI& xs){
  xs[y][x] = -1;
  int res = 0;
  REP(d,6){
	int tx = x + dx[y%2][d];
	int ty = y + dy[y%2][d];
	if(tx < 0 || W+1 < tx || ty < 0 || H+1 < ty) continue;
	if(xs[ty][tx] == 1) ++res;
	else if(xs[ty][tx] == 0)
	  res += solve(tx, ty, xs);
  }
  return res;
}
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  cin >> W >> H;
 
  VVI xs(H+2, VI(W+2));
  REP(y,H) REP(x,W) cin >> xs[y+1][x+1];
 
  cout << solve(0, 0, xs) << endl;
 
  return 0;
}

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

int main(){
  cout << fixed << setprecision(8);
  const double btc = 380000;
  int n; 
  cin >> n;
  double answer = 0;
  for(int i = 0; i < n; i++){
    double a;
    string s;
    cin >> a >> s;
    if(s == "JPY"){
      answer += a;
    }
    else if(s == "BTC"){
      answer += btc * a;
    }
  }
  cout << answer << endl;
}


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

namespace io {
char buf[1<<21], *p1 = buf, *p2 = buf;
inline char gc() {
    if(p1 != p2) return *p1++;
    p1 = buf;
    p2 = p1 + fread(buf, 1, 1 << 21, stdin);
    return p1 == p2 ? EOF : *p1++;
}
#define G gc

#ifndef ONLINE_JUDGE
#undef G
#define G getchar
#endif

template<class I>
inline void read(I &x) {
    x = 0; I f = 1; char c = G();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = G(); }
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = G(); }
    x *= f;
}
template<class I>
inline void write(I x) {
    if(x == 0) {putchar('0'); return;}
    I tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
        buf[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while(cnt > 0) putchar(buf[--cnt]);
}

#define in(x) read(x)
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')

} using namespace io;

#define ll long long
const int N = 100010;

int main() {
	int a, b; read(a); read(b);
	int ans = max(a+b,a-b);
	ans = max(ans,a*b);
	outn(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*ll t;
cin>>t;
while(t--)
{
    
}*/
ll k;
cin>>k;
ll a,b;
cin>>a>>b;
ll x;
x=(b%k);
ll e;
e=(b-x);
if(e>=a and e<=b)
{
    cout<<"OK"<<endl;
}
else
{
    cout<<"NG"<<endl;
}
    
    return 0;
    
}

Measured memory_bytes: 3608
while True:
  Name=[]
  first=[]
  final=[]
  N,Q =map(int,input().split())
  if N==Q==0:
    break
  else:
    for n in range(N):
      eraname,erabasedyear,westernyear=input().split()
      Name.append(eraname)
      era_first=int(westernyear) - int(erabasedyear) +1
      first.append(int(era_first))
      final.append(int(westernyear))
    for q in range(Q):
        year=int(input())
        count=0
        for n in range(N):
          if first[n] <= year <=final[n]:
            era_year = year -first[n] +1
            print(Name[n],era_year)
            count+=1
        if count==0:
          print("Unknown") 


Measured memory_bytes: 5648
#include<stdio.h>
//#define scanf scanf_s
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
char a[4001];
int main()
{
	int n, i,j,k,l,R,G,B;
	long long sum=0,sum1=0;
	j = k = l =R=G=B=0;
	scanf("%d", &n);
	getchar();
	gets(a);
	for (i = 0; i < n; i++)
	{
		if (a[i] == 'R')R++;
		else if (a[i] == 'G') G++;
		else if (a[i] == 'B') B++;
	}
	for (i = 0; i < n; i++)
	{
		if (a[i] == 'R')  R--, sum += G*B;
		else if (a[i] == 'G')  G--,sum+=R*B;
		else if (a[i] == 'B')  B--,sum+=R*G;	
	}
	for (i = 0; i < n; i++)
	{
		for (j = i+2; j < n; j++)
		{
			if ((i + j) % 2 != 0) continue;
			if (a[i] != a[j] && a[i] != a[(i + j) / 2]&&a[j]!=a[(i+j)/2]) sum--;
		}
	}
	printf("%lld", sum );
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,n1;
    cin >> n;
    n1 = n;
    int d = 0;
    while(n1 > 0)
    {
        d += n1 % 10;
        n1 /= 10;
    }
    if(n % d == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int NN = N;
    int f = 0;
    while (N > 0) {
        f += N % 10;
        N /= 10;
    }
    cout << (NN%f ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
  
struct P{
  int x,y;
  bool operator <(const P &a) const{
    return y<a.y;
  };
};
  
int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[1004101][2];
int l[3];
int j[3];


long long x,y,z,mod=1000000007;
string r;
//char r[1];
vector<int> v[1],v1;
queue<int> q;
stack<int> s;
map<string,int> p;
P u[1];
  
bool as(P a,P b)
{
  if(a.x!=b.x)
  return a.x<b.x;
  return a.y<b.y;
}

int f(int n,int m)
{
  if(n==r.size()) return 0;
  if(o[n][m]>=0) return o[n][m];
  if(m)
    o[n][m]=min(f(n+1,1)+9-r[n],f(n+1,0)+r[n]);
  else o[n][m]=min(f(n+1,1)+11-r[n],f(n+1,0)+r[n]);
  return o[n][m];
}

int main()
{
  memset(o,-1,sizeof(o));
  cin>>r;
  for(int t=0;t<r.size();t++)
    r[t]-='0';
  printf("%d",f(0,0));
}


Measured memory_bytes: 56068
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    int ans = max<int>({10*a+b+c, a+10*b+c, a+b+10*c});
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template <typename H> void print(H head) { std::cout << head << std::endl; }
template <typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

ll gcd(ll a, ll b)
{
  while (b > 0) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

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

  ll N, X;
  std::cin >> N >> X;
  std::vector< ll > vx(N+1, 0LL);
  std::vector< ll > vd(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> vx[i];
  }
  vx[N] = X;

  std::sort(vx.begin(), vx.end());

  for (ll i = 1; i <= N; i++) {
    vd[i-1] = std::fabs(vx[i] - vx[i-1]);
  }

  ll ans = vd[0];
  for (auto d : vd) {
    ans = gcd(ans, d);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    axy = [[[],[]] for _ in range(n)]
    for i in range(n):
        a = II()
        for _ in range(a):
            x, y = LI()
            axy[i][y].append(x-1)
    ans = 0
    for i in range(1 << n):
        f = 0
        tmp = 0
        for k in range(n):
            if i & (1 << k):
                tmp += 1
                for x in axy[k][0]:
                    if i & (1 << x):
                        f = 1
                for x in axy[k][1]:
                    if not(i & (1 << x)):
                        f = 1
        if f:
            continue
        ans = max(ans, tmp)
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


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

int main(){
    int x,y,ans;
    cin >> x >> y;
    ans = 0;
    if(x==1 && y==1){
        ans = 1000000;
    }else{
        if (x==1)ans += 300000;
        if (y==1)ans += 300000; 
        if (x==2)ans += 200000;
        if (y==2)ans += 200000;
        if (x==3)ans += 100000;
        if (y==3)ans += 100000;

    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=3005,md=1000000007;
int n,q,i,j,a[N],x[N],y[N],f[N][N],g[N][N],ans,inv2=(md+1)/2;
int main()
{
	scanf("%d%d",&n,&q);
	for(i=1;i<=n;++i)
		scanf("%d",a+i);
	for(i=1;i<=q;++i)
		scanf("%d%d",x+i,y+i);
	for(i=1;i<=n;++i)
		for(j=i+1;j<=n;++j)
			f[i][j]=1;
	for(i=q;i>=1;--i)
	{
		for(j=1;j<=n;++j)
		{
			g[x[i]][j]=f[x[i]][j];
			g[y[i]][j]=f[y[i]][j];
			g[j][x[i]]=f[j][x[i]];
			g[j][y[i]]=f[j][y[i]];
		}
		for(j=1;j<=n;++j)
		{
			if(j!=y[i])
			{
				f[x[i]][j]=1ll*(g[x[i]][j]+g[y[i]][j])*inv2%md;
				f[j][x[i]]=1ll*(g[j][x[i]]+g[j][y[i]])*inv2%md;
			}
			if(j!=x[i])
			{
				f[y[i]][j]=1ll*(g[y[i]][j]+g[x[i]][j])*inv2%md;
				f[j][y[i]]=1ll*(g[j][y[i]]+g[j][x[i]])*inv2%md;
			}
		}
		f[x[i]][y[i]]=f[y[i]][x[i]]=1ll*(g[x[i]][y[i]]+g[y[i]][x[i]])*inv2%md;
	}
	for(i=1;i<=n;++i)
		for(j=i+1;j<=n;++j)
			if(a[i]>a[j])
				ans=(ans+f[i][j])%md;
			else if(a[i]<a[j])
				ans=(ans+f[j][i])%md;
	for(i=1;i<=q;++i)
		ans=ans*2ll%md;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 70656
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int[] b = new int[n], c = new int[n];
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
            if (i < j && a[i] > a[j]) {
                b[j]++;
            }
            if (a[i] > a[j]) {
                c[j]++;
            }
        }


        long MOD = (long)(1e9) + 7;
        long INV2 = (MOD + 1) / 2;
        long cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt = (cnt + k * b[i]) % MOD;
            long mult = k * c[i] % MOD * (k - 1) % MOD * INV2 % MOD;
            cnt = (cnt + mult) % MOD;
        }
        System.out.println(cnt);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

#define LL long long

using namespace std;

bool check(char a){
    char pat[5] = {"ACGT"};
    for (int i = 0; i < 4; i++){
        if(pat[i] == a){
            return true;
        }
    }
    return false;
}


int main(void){
    string s;
    cin >> s;

    int count = 0, result = 0;

    for (int i = 0; i < s.length(); i++){
        if(check(s[i])){
            count++;
        }else{
            if(result < count){
                result = count;
                count = 0;
            }
        }
    }
    if(result < count){
        result = count;
    }

    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int c[100000] = {};
	for (int i = 10000; i < 100000; i++) {
		string s = to_string(i);
		string t = s;
		reverse(s.begin(), s.end());
		if (s == t) {
			c[i] = 1;
		}
	}
	int a, b, sum = 0;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (c[i] == 1) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cctype>
#define SG getchar()
#define S return puts("No"),0
int n,m;
signed main()
{
	scanf("%d%d",&n,&m),SG;
	while(n--)
	{
		if(!isdigit(SG))
		{
			S;
		}
	}
	if(SG-45)
	{
		S;
	}
	while(m--)
	{
		if(!isdigit(SG))
		{
			S;
		}
	}
	return puts("Yes"),0;
}

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

long long n;

long long solve();

int main() {
  cin >> n;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for(int i = 1; i <= n; ++i) {
    if(i % 10 == 0) continue;
    long long now = i, pre = i % 10, suf = i % 10;
    while(now > 0) {
      suf = now % 10;
      now /= 10;
    }
    if(pre == suf) ++res;
    for(long long ten = 10; pre * ten + suf <= n;
        ten *= 10) {
      now = n - pre * ten - suf;
      res += min((long long)ten / 10, now / 10 + 1);
    }
  }
  return res;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN,'%s',$S);
  $array=str_split($S);
  $counta=0;
  $countb=0;
  $countc=0;
  for($i=0;$i<=2;$i++){
    if($array[$i]=='a'){
      $counta++;
    }
    if($array[$i]=='b'){
      $countb++;
    }
    if($array[$i]=='c'){
      $countc++;
    }
  }
  if($counta==1&&$countb==1&&$countc==1){
     echo 'Yes';
  }else{
    echo 'No';
  }
?>


Measured memory_bytes: 3828
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int memo[1 << 16][32];
int pat[32], tac[32];
int n, c;

int in()
{
	int b = 0;
	for (int j = 0; j < 16; j++){
		int t;
		scanf("%d", &t);
		b = b * 2 + t;
	}
	return (b);
}

int popcount(int bit)
{
	if (bit == 0){
		return (0);
	}
	return ((bit & 1) + popcount(bit >> 1));
}

int getMax(int bit, int pos)
{
	if (pos == n){
		return (0);
	}
	if (memo[bit][pos] >= 0){
		return (memo[bit][pos]);
	}
	
	int ans = 0;
	for (int i = 0; i < c; i++){
		int t = popcount(tac[i] & bit);
		ans = max(ans, t + getMax(((bit ^ tac[i]) & bit) | pat[pos + 1], pos + 1));
	}
	return (memo[bit][pos] = ans);
}

int main()
{
	while (scanf("%d %d", &n, &c), n || c){
		for (int i = 0; i < n; i++){
			pat[i] = in();
		}
		
		for (int i = 0; i < c; i++){
			tac[i] = in();
		}
		
		memset(memo, -1, sizeof(memo));
		
		printf("%d\n", getMax(pat[0], 0));
	}
	
	return (0);
}

Measured memory_bytes: 9228
S = input()
L = int(S[:2])
R = int(S[2:])
if (1<=L<=12):
    if (1<=R<=12):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if (1<=R<=12):
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fl first
#define fr second
using namespace std;
  
typedef long long LL;
typedef pair<int, int> pii;

const int N = 200000 + 5;

LL n, m;
LL a[N], sum[N];

int main()
{
    scanf("%lld%lld", &n, &m);
    for (LL i = 1; i <= n; i++) scanf("%lld", &a[i]);
    sort(a + 1, a + n + 1);
    for (LL i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
    LL l = 0, r = 2e5 + 1;
    LL cnt = 0, res = 0, ans = 0;
    while (l <= r)
    {
        LL mid = (l + r) >> 1;
        res = cnt = 0;
        for (LL i = 1; i <= n; i++)
        {
            LL pos = lower_bound(a + 1, a + n + 1, mid - a[i]) - a;
            cnt += n - pos + 1;
            res += sum[n] - sum[pos - 1] + a[i] * (n - pos + 1);
        }
        if (cnt >= m) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    printf("%lld\n", res - (cnt - m) * ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define inf (1<<16)

int main(){
	int n;
	cin>>n;
	int a[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
	vector<int> dp(n+1,inf);
	dp[0]=0;

	for(int i=0;i<=n;++i){
		int DP=dp[i];
		for(int j=0;j<12;++j){
			if(i-a[j]>=0)DP=min(dp[i-a[j]]+1,DP);
		}

		dp[i]=DP;
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int x, y, a , b, c;
   cin >> x >> y >> a >> b >> c;
   vector<int> ad(a);
   vector<int> bd(b);
   vector<int> cd(c);
   vector<int> v(x+y+c);
   long long sum = 0;
   for(int i = 0; i < a; i++)
      cin >> ad[i];
   for(int i = 0; i < b; i++)
      cin >> bd[i];
   for(int i = 0; i < c; i++)
      cin >> cd[i];
   sort(ad.rbegin(), ad.rend());
   sort(bd.rbegin(),bd.rend());
   for(int i = 0; i < x; i++)
      v.push_back(ad[i]);
   for(int i=0; i < y; i++)
      v.push_back(bd[i]);
   for(int i = 0; i < c; i++)
      v.push_back(cd[i]);
   sort(v.rbegin(),v.rend());
   for(int i = 0; i< x+y; i++)
      sum += v[i];


   cout << sum << endl;



}


Measured memory_bytes: 4736
extern crate core;

use std::collections::HashMap;
use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize m:usize)(s:#)(t:#));
    let s = s.chars().collect::<Vec<_>>();
    let t = t.chars().collect::<Vec<_>>();
    let nm_lcm = lcm(m, n);
    let mut s_map = HashMap::new();

    for i in 0..n {
        let a = i * nm_lcm / n;
        s_map.insert(a, s[i]);
    }

    for i in 0..m {
        let a = i * nm_lcm / m;
        if let Some(x) = s_map.get(&a) {
            if t[i] != *x {
                return "-1".to_string();
            }
        }
    }

    nm_lcm.to_string()
}

pub fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

//最小公倍数
pub fn lcm(a: usize, b: usize) -> usize {
    a * b / gcd(a, b)
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3 2\nacp\nae\n" => "6\n",
    test2: "6 3\nabcdef\nabc\n" => "-1\n",
    test3: "15 9\ndnsusrayukuaiia\ndujrunuma\n" => "45\n",
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];

    ll ng = 0, m = INF, sum = 0;
    REP(i,0,N) {
        if(A[i] < 0) ++ng;
        m = MIN(m,abs(A[i]));
        sum += abs(A[i]);
    }

    if(ng % 2 == 0) PR(sum);
    else PR(sum-m*2);


    return 0;
}

/*



*/

Measured memory_bytes: 3992