akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define pb         push_back
#define mp         make_pair
#define ll         long long
#define PI         acos(-1.0)
#define ALL(A)     ((A).begin(), (A).end())
#define vsort(v)   sort(v.begin(),v.end())
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)


int main(){
    int i, j, times=0;
    string tmp,maxLength,maxTimes;
    map<string, int> sentences;
    maxLength="";
    while(cin>>tmp){
        if(tmp.length()>maxLength.length()){
            maxLength=tmp;
        }
        if(sentences.count(tmp)==0){
            sentences.insert(map<string,int>::value_type(tmp,1));
        }else{
            sentences[tmp]++;
        }
        if(sentences[tmp]>times){
            times=sentences[tmp];
            maxTimes=tmp;
        }
    }
    cout << maxTimes << " " << maxLength << endl;
}

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

vector<int> topological_sort(const vector<vector<int>> &G, vector<int> in) {
    vector<int> ret;
    stack<int> st;
    for(int i = 0; i < in.size(); i++)
        if(in[i] == 0)
            st.push(i);
    while(st.size()) {
        int v = st.top();
        st.pop();
        ret.push_back(v);
        for(auto &nv : G[v]) {
            in[nv]--;
            if(in[nv] == 0)
                st.push(nv);
        }
    }
    return ret;
}

int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> G(V, vector<int>());
    vector<int> in(V);
    rep(i, E) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        in[t]++;
    }
    auto sorted = topological_sort(G, in);
    for(auto x : sorted) {
        cout << x << endl;
    }
    return 0;
}


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

using namespace std;

void solve(int a, int b, int v) {
	if (a == b) {
		printf("%d ", a);
		return;
	}
	int x = ((a ^ b) & (-(a ^ b)));
	v = v ^ x;
	int y = v & (-v);
	solve(a, a ^ y, v);
	solve(a ^ y ^ x, b, v);
}

int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if (__builtin_popcount(a ^ b) & 1) {
		puts("YES");
		solve(a, b, (1 << n) - 1);
	} else {
		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define f(i,x,n) for(ll i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define int ll

template < typename T > using indexed_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
 
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
const int MOD = 1e9+7, INF = INT_MAX, N = 1e5 + 10;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int r;
   cin >> r;
   db ans = 2*PI*r;
   cout << setprecision(14) << fixed << ans << '\n';
   return 0;
}


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

int64_t datas[1223 * 1234];
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);

   int64_t n, k;
   cin >> n >> k;
   //memset(datas, 0, sizeof(datas));
   for (int i = 0; i < n; ++i) {
      int a, b; cin >> a >> b;
      datas[a] += b;
   }

   int64_t cnt = 0; int j = 0;
   while(1) {
      ++j;
      cnt += datas[j];
      if (k <= cnt)
         break;
   }
   printf("%d\n", j);
   return 0;
}

Measured memory_bytes: 1024
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const ll INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
const ll Maxn=1e5;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
bool cmp(double x,double y)
{
    return x>y;
}ll vim[2003],ly[2003];
ll C(int a,int b)
{  if(b==0||a==b)return 1;
if(a<b)return 0;
  return vim[a]*ly[b]%mod*ly[a-b]%mod;
}

void dd()
{ vim[0]=1;
    for(int i=1;i<=2000;i++)
        vim[i]=vim[i-1]*i%mod,ly[i]=kc(vim[i],mod-2);
}
int main()
{ ios::sync_with_stdio(false);
  dd();
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=m;i++)
  {
      cout<<C(m-1,i-1)%mod*C(n-m+1,i)%mod<<endl;
  }

}


Measured memory_bytes: 256
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 for(int t = 1; t <= T; t++){
		 int32_t a,b,total;
		 cin >> a >> b >> total;
		 int64_t res = 0;
		 for(int i = a; i <= total; i += a){
			 res += b;
		 }
		 cout << res << "\n";
	 }
}



Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <cstring>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n){
		cin >> a[i];
	}
	ll suma = accumulate(a.begin(),a.end(),(long long)0);
	ll sumope = (long long)n*(n+1)/2;
	if(suma % sumope != 0){
		cout << "NO" << endl;
		return 0;
	}else{
		vector<ll> b(n);
		REP(i,n-1)b[i] = a[i+1]-a[i];
		b[n-1] = a[0]-a[n-1];
		ll numope = suma / sumope;
		REP(i,n){
			b[i] -=numope;
			if(b[i] > 0 || (-b[i]) % n != 0){
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll ans = 700;
  for (int i = 0; i < 3; i++) {
    char c;
    cin >> c;
    if (c == 'o') ans += 100;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
eat = max(0, a[0] - x)
ans += eat
a[0] -= eat
for i in range(1, n):
    eat = max(0, a[i - 1] + a[i] - x)
    a[i] -= eat
    ans += eat
print(ans)

Measured memory_bytes: 14132
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const LL mods=1000000007LL;
const int MAXN=1000000;
struct M{
	LL x;
	M(){
		x=0;
	}
	M(LL angka){
		if(angka>=mods||angka<=-mods)
			angka%=mods;
		if(angka<0)
			angka+=mods;
		x=angka;
	}
	
	M operator + (const M &other) const{
		return M(x+other.x);
	}
	M operator - (const M &other) const{
		return M(x-other.x);
	}
	M operator * (const M &other) const{
		return M(x*other.x);
	}
	M operator - () const{
		return M(-x);
	}
};
int n;
M fakt[MAXN+5],invfakt[MAXN+5],pways[MAXN+5],ans;
M DnC(M angka,LL pangkat){
	if(pangkat==0)
		return 1;
	M ret=DnC(angka,pangkat>>1);
	ret=ret*ret;
	if(pangkat&1)
		ret=ret*angka;
	return ret;
}
M inv(int n,int k){
	//cout<<"ngeinv "<<n<<" "<<k<<endl;
	M ret;
	int i,j;
	for(int ulang=0;ulang<2;ulang++)
	{
		if(ulang==0)
			i=n-2*k,j=k;
		else
			i=n-2*k+1,j=k-1;
		if(!(i>=0&&j>=0))
			continue;
		ret=ret+fakt[i+j]*invfakt[i]*invfakt[j];
	}
	return ret;
}
M ways(int i){
	return inv(n-3,(n-1)-i);
}
void isipways(){
	M substract;
	for(int i=2;i<=n-1;i++)
	{
		//cout<<"untuk "<<i<<" caranya "<<ways(i).x<<endl;
		pways[i]=ways(i)*fakt[i]-substract;
		substract=substract+pways[i];
		substract=substract*(n-i-1);
		//cout<<"pways "<<i<<" "<<pways[i].x<<endl;
	}
}
int main()
{
	cin>>n;
	if(n==2)
	{
		cout<<1<<endl;
		return 0;
	}
	if(n==3)
	{
		cout<<4<<endl;
		return 0;
	}
	fakt[0]=1;
	invfakt[0]=1;
	for(int i=1;i<=n;i++)
	{
		fakt[i]=fakt[i-1]*i;
		invfakt[i]=DnC(fakt[i],mods-2);
	}
	isipways();
	for(int i=2;i<=n-1;i++)
		ans=ans+pways[i]*fakt[n-1-i]*i;
	printf("%lld\n",ans.x);
}


Measured memory_bytes: 23680
import sys
sys.setrecursionlimit(100000000)




def main():
    n, m, x = map(int, input().split())
    c = []
    a = []
    for i in range(n):
        s = list(map(int, input().split()))
        c.append(s[0])
        a.append(s[1:])

    res_money = 1_000_000_000_000
    for i in range(2 ** n):
        op = [0] * n  # あらかじめ ["-", "-", "-"] というリストを作っておく
        for j in range(n):
            if ((i >> j) & 1):
                op[n - 1 - j] = 1  # フラグが立っていた箇所を "+" で上書き
        s = [0] * m
        money = 0
        for k in range(n):
            if op[k] == 0:
                continue
            money += c[k]
            for l in range(m):
                s[l] += a[k][l]
        ng = False
        for p in range(m):
            if s[p] < x:
                ng = True
                break
        if not ng:
            if res_money > money:
                res_money = money

    if res_money != 1_000_000_000_000:
        print(res_money)
    else:
        print(-1)



main()


Measured memory_bytes: 9248
n,m=map(int,input().split())
s=[]
for i in range(n):
    s.append(int(input()))
for i in range(2,m+1):
    for j in range(n-1):
        a=s[j]%i
        b=s[j+1]%i
        if a>b:
            s[j],s[j+1]=s[j+1],s[j]
for i in range(n):
    print(s[i])
    



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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    vector<long long> arr;

    long long n,k;
    cin>>n>>k;

    long long ans=abs(n-k);
    bool loop=false;
    while(loop==false) {
        if(find(arr.begin(),arr.end(),n)!=arr.end()) {
            loop=true;
        }
        if(n>k) {
            arr.push_back(n%k);
            n=n%k;
        }
        else{
            arr.push_back(abs(n-k));
            n=abs(n-k);
        }
         for(int i=0;i<arr.size();i++) {
         }
        ans=min(ans,n);
    }

    cout<<ans<<endl;

    
}




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

int main(){
    int n;
    std::cin >> n;

    std::vector<int> abses(n);
    int val;
    for(int i = 0; i < n; ++i){
        std::cin >> abses.at(i);
    }
    for(int i = 0; i < n; ++i){
        std::cin >> val;
        abses.at(i) = std::abs(abses.at(i) - val);
    }

    double sum = std::accumulate(abses.begin(), abses.end(), 0.0);
    double squaredSum = std::accumulate(abses.begin(), abses.end(), 0.0, [](int first, int second){return first + std::pow(second, 2);});
    long long cubedSum = std::accumulate(abses.begin(), abses.end(), 0.0, [](long first, long second){return first + std::pow(second, 3);});
 
    std::cout << std::fixed;
    std::cout << sum << std::endl;
    std::cout << std::sqrt(squaredSum) << std::endl;
    std::cout << std::cbrt(cubedSum) << std::endl;
    std::cout << *std::max_element(abses.begin(), abses.end()) << std::endl;

    return 0;
}


Measured memory_bytes: 3472
#include <stdio.h>
#include <stdlib.h>
#define MAX 25

int n, i, id, num;
int use[MAX];
typedef struct pp
{
    int see_it;
    int parent;
    int left, right;
}g;
g Q[MAX];

void dfs(int q, int d)
{
    if(Q[q].left !=-1)
    {
        Q[Q[q].left].parent = q;
        dfs(Q[q].left, d+1);
    }
    if(Q[q].right !=-1)
    {
        Q[Q[q].right].parent = q;
        dfs(Q[q].right, d+1);
    }
}

void pre(int q)
{
    if(Q[q].see_it == -1) Q[q].see_it = num;
    num++;
    if(Q[q].left != -1) pre(Q[q].left);
    if(Q[q].right != -1) pre(Q[q].right);
}

void ino(int q)
{
    if(Q[q].left != -1) ino(Q[q].left);
    if(Q[q].see_it == -1) Q[q].see_it = num;
    num++;
    if(Q[q].right != -1) ino(Q[q].right);
}

void pos(int q)
{
    if(Q[q].left != -1) pos(Q[q].left);
    if(Q[q].right != -1) pos(Q[q].right);
    if(Q[q].see_it == -1) Q[q].see_it = num;
    num++;
}

void init()
{
        for(int j=0; j<MAX; j++)
    {
        Q[j].see_it = -1;
        num = 0;
    }
}

void res(int x)
{
    if(x==0)
    {
        printf("Preorder\n");
        for(int k=0; k<n; k++)
        {
            for(int l=0; l<n; l++) if(Q[l].see_it == k)printf(" %d", l);
        }
        printf ("\n");
    }
    else if(x==1)
    {
        printf("Inorder\n");
        for(int k=0; k<n; k++)
        {
            for(int l=0; l<n; l++) if(Q[l].see_it == k)printf(" %d", l);
        }
        printf ("\n");
    }
    else
    {
        printf("Postorder\n");
        for(int k=0; k<n; k++)
        {
            for(int l=0; l<n; l++) if(Q[l].see_it == k)printf(" %d", l);
        }
        printf ("\n");
    }
}
int main()
{
    //init
    for(int j=0; j<MAX; j++)
    {
        use[j] = 0;
        Q[j].parent = -1;
    }
    //input
    scanf("%d", &n);
    while(1)
    {
        if((scanf("%d", &id)) == EOF) break;
        scanf("%d", &Q[id].left);
        scanf("%d", &Q[id].right);
        use[Q[id].left] = 1;
        use[Q[id].right] = 1;
    }
    for(int j=0; j<MAX; j++)
    {
        if(use[j] == 0) 
        {
            dfs(j, 0);
            init();
            pre(j);
            res(0);
            init();
            ino(j);
            res(1);
            init();
            pos(j);
            res(2);
            break;
        }
    }
    //output results

    return 0;
}


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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i=0; i<m; i++) cin >> b[i];
  int count = 0;
  for(int i=0; i<n; i++) {
    int wa = 0;
    for(int j=0; j<m; j++) {
      int x;
      cin >> x;
      wa += x*b[j];
      if(j == m-1 && wa+c > 0)
        count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    char[] a=sc.next().toCharArray();
    char[] b=sc.next().toCharArray();
    String ans=null;
    if(a.length>b.length){
      ans="GREATER";
    }else if(a.length<b.length){
      ans="LESS";
    }else{
      for(int i=0;i<a.length;i++){
        if(a[i]>b[i]){
          ans="GREATER";
          break;
        }else if(a[i]<b[i]){
          ans="LESS";
          break;
        }
      }
    }
    if(ans==null){
      System.out.println("EQUAL");
    }else{
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 22740
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void)
{
    int n, count;
    count = 0;
    double p;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        if (i % 2 != 0)
        {
            count++;
        }
    }
    printf("%.7lf\n",(double)count/(double)n);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef pair<LL, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}

const int N = 1e5 + 100;

LL a[N];
LL d[N];
int main() {
	int n;
	cin >> n;
	LL sum = 0;
	for(int i = 0; i < n; i ++) scanf("%lld", &a[i]);
	for(int i = 0; i < n; i ++) {
		sum += a[i];
		d[i] = a[i] - a[(i - 1 + n) % n]; 
	}
	if(sum % ((1 + n) * 1LL * n / 2) ) return puts("NO") * 0;
	LL K = sum / ((1 + n) * 1LL * n / 2);
	LL c = 0;
	for(int i = 0; i < n; i ++) {
		int t = (K - d[i]) / n;
		if(t < 0 || (K - d[i]) % n) return puts("NO") * 0;
		c += (K - d[i]) / n;
	}
	if(c == K) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Integer> mochis = new ArrayList<Integer>();
		for(int i=0; i<n; ++i) {
			int mochi = scan.nextInt();
			if(!mochis.contains(mochi)) {
				mochis.add(mochi);
			}
		}
		scan.close();
		System.out.println(mochis.size());
	}

}


Measured memory_bytes: 21844
#include <cstdio>
#include <stdio.h>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;

    string str = a + b;
    int num = stoi(str);

    int sqrt = static_cast<int>(std::sqrt(num));
    if(sqrt * sqrt == num) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())


def factori(num):
    l = set()
    for i in range(1, int(num ** 0.5) + 1):
        if not num % i:
            l.add(i)
            l.add(n // i)
    return l


ans = 0
for m in factori(n):
    m -= 1
    if m > 0 and n == (n // m) * (m + 1):
        ans += m
print(ans)


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

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

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

	int n; cin >> n;

	int ans = INT_MIN;
	int MIN; cin >> MIN;

	for (int i = 1;i < n;i++){
		int tmp; cin >> tmp;
		ans = max(ans,tmp-MIN);
		MIN = min(MIN,tmp);
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef long long LL;
typedef pair<pair<int,int>,pair<LL,LL>> pr;

const int maxn=20;

int n;
LL a[maxn];

map<pr,LL> f;
LL dfs(int l,int r,LL x,LL y)
{
	if (l+1>=r) return 0;
	pr now=make_pair(make_pair(l,r),make_pair(x,y));
	if (f.count(now)) return f[now];
	LL re=5e18;
	fo(i,l+1,r-1)
		re=min(re,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+a[i]*(x+y));
	return f[now]=re;
}

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%lld",&a[i]);
	
	printf("%lld\n",dfs(1,n,1,1)+a[1]+a[n]);
}

Measured memory_bytes: 22656
// 2011/06/17 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int d;
		cin >> d;
		if(cin.eof())
			break;

		int sum = 0;
		for(int i=1; i<600/d; i++)
			sum += i*d*i*d*d;

		cout << sum << endl;
	}

	return 0;
}

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

int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  a = a-1;
  long f = __gcd(c,d);
  long long k=a-(a/c+a/d-a/(c*d/f));
  long long l=b-(b/c+b/d-b/(c*d/f));
  cout << l-k << endl;
}

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

int main() {
  ll n;
  cin>>n;
  vector<ll> h(n);
  rep(i,n)cin>>h[i];
  ll dp[n+1];
  rep(i,n+1)dp[i]=INF;
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  rep(i,n-1){
    dp[i+2]=min(dp[i+2],dp[i+1]+abs(h[i+2]-h[i+1]));
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));

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


Measured memory_bytes: 4844
#include <stdio.h>
#include<string>
#include<string.h>
#include <math.h>
#include<iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
using namespace  std;


/*
//my header
#include "define.h"
#include "geometry.h"*/

#define MyAbs(a) ((a)>0?(a):-(a))
#define MyEqualDoule(a,b) (MyAbs(a-b)<1e-6)

#define foreach(i,n) for(i=0;i<n;++i)
#define foreachd(i,n) for(int i=0;i<n;++i)
#define printfInt1(n) printf("%d\n",n)
#define scanfInt1(n) scanf("%d",&n)
#define scanfInt2(a,b) scanf("%d%d", &a, &b)
#define scanfInt3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scanfFloat2(a,b) scanf("%f%f", &a,&b)


void init()
{
#ifdef _WIN32
	freopen("1.txt", "r", stdin);
#endif
}

void func();

int main()
{
	init();
	func();

	return 0;
}

int gcd(int a,int b)
{
	int t;
	while (b) {
		t = a % b;
		a = b;
		b = t;
	}
	return a;
}
int lcm(int a,int b)
{
	return a / gcd(a,b) * b;
}

void func()
{
	int a, b;
	while(~scanfInt2(a,b))
	{
		printf("%d %d\n", gcd(a,b), lcm(a,b));
	}
}

Measured memory_bytes: 1188
import java.util.*;

 // Compiler version JDK 11.0.2

 class Main
 {
   public static void main(String args[])
   { 
    Scanner sc= new Scanner(System.in);
    long n = sc.nextLong();
    int m = sc.nextInt();
    int a[]= new int[m];
    long sum =0;
    for(int i =0;i<m;i ++)
    {
      a[i]= sc.nextInt();
      sum= sum + a[i];
      
    }
    if(n>=sum)
    System.out.println(n-sum);
    else
    System.out.println("-1");
    
   }
 }


Measured memory_bytes: 46284
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int mod=1000000007;
long long gcd(long long a, long long b){
   if(a>b) return gcd(b,a);
   if(b%a==0) return a;
   return gcd(b%a, a);
}
long long pow(long long b, long long p){
   long long ans = 1;
   while(p!=0){
      if(p%2==1){
         ans *=b;
      }
      ans %=mod;
      b*=b;
      b%=mod;
      p/=2;
   }
   return ans;
}
int main(){
   int N;
   cin >> N;
   vector<pair<long long, long long>> F;
   long long GroupA=0;
   long long GroupB=0; 
   long long GroupZ=0;
   map<pair<long long, long long>, int> Cnt;
   Cnt.clear();
   for(int i = 0 ; i< N; i++){
      long long A,B;
      cin >> A >> B;
      F.emplace_back(make_pair(A,B));
      if(A==0&&B==0)GroupZ++;
      else if(A==0)GroupA++;
      else if(B==0)GroupB++;
      else{
         // ensure A,B>0 or A<0<B
         if(A<0&&B<0){
            A=-A;
            B=-B;
         }
         else if(B<0){
            A=-A;
            B=-B;
         }
         long long g = gcd(abs(A),abs(B));
         A/=g;
         B/=g;
         //cout << A << B<< endl;
         Cnt[make_pair(A,B)]++;
      }
   }
   long long ans =0;
   ans += GroupZ;
   long long tmp = 1;
   //cout << "Group" << GroupA <<" " << GroupB << endl;
   tmp*=(pow(2LL,GroupA)+pow(2LL,GroupB)-1)%mod;
   tmp%=mod;
   //cout << tmp << endl;
   for(auto it = Cnt.begin(); it != Cnt.end(); it++){
      pair<long long, long long> p = it->first;
      //cout << " now" << p.first << ", " << p.second << Cnt[p] << endl;
      if(Cnt[p]==0) continue;
      pair<long long, long long> q = make_pair(-p.second, p.first);
      if(q.second<0){
         q.first*=-1;
         q.second*=-1;
      }
      if(p.first < 0 && Cnt[q]!=0) continue;
      else{
         //cout << 2<< "**" << p.second << "+" << 2 << "**" << Cnt[q] << -1 << endl;
         tmp *= (pow(2LL, (long long)Cnt[p])+pow(2LL, (long long)Cnt[q])-1)%mod;
         tmp %= mod;
         //cout << tmp << endl;
      }
   }
   ans += tmp;
   ans %= mod;
   ans += mod-1;
   ans %= mod;
   cout << ans << endl;

   return 0;
}


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

int main() {
	int n;
	cin >> n;
	int v[n], c[n];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		if (0 < v[i] - c[i]) {
			ans += v[i] - c[i];
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main() 
    { 
    long long int a; 
    double b; 
    cin >> a >> b; 
    long long int r = a * (long long int)round(b * 100.0) / 100; 
    cout << r << "\n"; 
    return 0; 
}

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

int main() {

	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a;
	cin >> b;
	cin >> c;

	if ((a + b + c) <= 21) {
		cout << "win";
	}else if((a+b+c)>=22){
		cout << "bust";
	}
	return 0;
}

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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	vector<int> c;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		c.push_back(a);
	}
	sort(c.begin(), c.end(), greater<int>());
	long long int sum = (c[0] + 1) / 2;
	long long int ma = c[0];
	long long int mb = 0;
	for (int i = 1; i < c.size(); i++) {
		if (ma > abs(sum - c[i])) {
			mb = c[i];
			ma = abs(sum - c[i]);
		}
	}
	cout << c[0] << " " << mb;
}

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

int main() {

int A,B=0,k;
  cin>>A;
  string a=to_string(A);
  for(int i=0;i<a.size();i++){
    B+=a.at(i)-'0';}
  if(A%B==0){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define MOD 998244353
using namespace std;
int32_t main()
{
    string a,b;
    cin>>a>>b;
    int m=a.length();
    int n=b.length();
    int dp[3001][3001]={0};
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i-1]==b[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans;
    int i=m,j=n;
    while(i>0 && j>0)
    {
        if(a[i-1]==b[j-1])
        {
            ans+=a[i-1];
            i--;
            j--;
        }
        else if( dp[i][j]==dp[i-1][j])
            i--;
        else
            j--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}
    


Measured memory_bytes: 73932
from itertools import combinations
n = int(input())
i = 1
plus = 1
flg = False
while i <= n:
    if i == n:
        flg = True
        break
    plus += 1
    i += plus
if flg:
    print("Yes")
    res = {i : [] for i in range(plus+1)}
    for i, combi in enumerate(combinations(range(plus + 1), 2), 1):
        res[combi[0]].append(str(i))
        res[combi[1]].append(str(i))
    print(plus + 1)
    for i, val in res.items():
        print(str(plus) + " " + " ".join(val))
else:
    print("No")

Measured memory_bytes: 52700
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  sort(a.begin(),a.end());
  int h1=(a.at(n-1))/2;
  int h2=(a.at(n-1)+1)/2;
  auto m1=upper_bound(a.begin(),a.end(),h1);
  auto m2=lower_bound(a.begin(),a.end(),h2);
  if(m1==a.begin())
    cout<<a.at(n-1)<<" "<<a.at(0)<<endl;
  else
    cout<<a.at(n-1)<<" "<<(h1-*(m1-1)<=*m2-h2?*(m1-1):*m2)<<endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
bool isprime(int x)
{
	if(x<2) return false;
	for(int i=2;i<=sqrt(x);i++)
	{
		if((x%i)==0) return false;
	}
	return true;
}
int main()
{
    ios_base::sync_with_stdio(false);//this works only
    cin.tie(NULL);// when first all inputs are from user
    cout.tie(NULL);//you will see all outputs afterwards
    int x;cin>>x;
    int i=x;
    while(1)
    {
    	if(isprime(i))
    	{
    		cout<<i<<endl;
    		break;
    	}
    	i++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin >> n;
    string s[n];
    for (ll i=0;i<n;i++)cin >> s[i];
    ll c[5];
    fill(c,c+5,0);
    for (ll i=0;i<n;i++){
        if (s[i][0]=='M'){
            c[0]=c[0]+1;
        }else if (s[i][0]=='A'){
            c[1]=c[1]+1;
        }else if (s[i][0]=='R'){
            c[2]=c[2]+1;
        }else if (s[i][0]=='C'){
            c[3]=c[3]+1;
        }else if (s[i][0]=='H'){
            c[4]=c[4]+1;
        }
    }
    ll ans=0;
    for (ll i=0;i<5;i++){
        for (ll j=i+1;j<5;j++){
            for (ll k=j+1;k<5;k++){
                ans+=c[i]*c[j]*c[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

  int  X = N, fx = 0;
  while (X) {
    fx += (X % 10);
    X /= 10;
  }

  cout << (!(N % fx) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 764
#include<iostream>
using namespace std;
int main()
{
    int h,w,n,b[10000+50],a[105][105],i,j,k;
    while(cin>>h>>w>>n)
    {
        k=0;
        for(i=0;i<n;i++)
        {
            cin>>b[i];
        }
        for(i=0;i<h;i++)
        {
            if(i%2==0)
            {
                for(j=0;j<w;j++)
                {
                    a[i][j]=k+1;
                    b[k]--;
                    if(b[k]==0)k++;
                }
            }
            else
            {
                for(j=w-1;j>=0;j--)
                {
                    a[i][j]=k+1;
                    b[k]--;
                    if(b[k]==0)k++;
                }
            }
        }
        for(i=0;i<h;i++)
            for(j=0;j<w;j++)
        {
            cout<<a[i][j];
            if(j==w-1)cout<<endl;
            else cout<<" ";
        }
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int c[100001];
vector<int> G[100001];
bitset<100001> vis;
set<ii> used;
vector<ii> ans;

inline void mark(int u, int v) { ans.emplace_back(u, v), ++c[u], used.emplace(u, v), used.emplace(v, u); }

void dfs(int u, int p) {
    vis[u] = 1;
    for (int v : G[u]) if (v != p && !used.count(ii(u, v))) {
        if (!vis[v]) {
            dfs(v, u);
            if (c[v]&1) mark(v, u);
            else mark(u, v);
        }
        else mark(u, v);
    }
}

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    int N, M; cin >> N >> M;
    if (M&1) {
        cout << -1;
        return 0;
    }
    while (M--) {
        int A, B; cin >> A >> B;
        G[A].push_back(B), G[B].push_back(A);
    }

    dfs(1, 0);
    
    for (ii p : ans) cout << p.f << ' ' << p.s << '\n';
    return 0;
}

Measured memory_bytes: 28632
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265



void f(int n,int m){
  int c[1000000];
  
  rep(i,m){
    cin>>c[i];
  }

  int dp[21000][300]={};
  rep(i,21000){
    rep(j,300){
      dp[i][j]=inf;
    }
  }

  dp[0][128]=0;

  FOR(i,1,n+1){
    int x;
    cin>>x;
    rep(j,256){
      rep(k,m){
        int a = j+c[k];
        a = min(a,255);
        a = max(a,0);
        dp[i][a]=min(dp[i][a],dp[i-1][j]+(x-a)*(x-a));
      }
    }
  }
  int ans = inf;
  rep(i,256){
    ans = min(ans,dp[n][i]);
  }

  cout<<ans<<endl;
}


int main(){
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0) break;
    f(n,m);
  }

  return 0;
}


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

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

using namespace std;

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  map<int, int> mp;
  rep(i, n) {
    mp[a[i]]++;
  }
  int res = 0;
  for (auto m : mp) {
    int x = m.first;
    int cnt = m.second;
    if (cnt < x) {
      res += cnt;
    } else {
      res += cnt - x;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
const int maxn=100000;
char str[maxn];
int main(){
	int w;
	scanf("%s",str);
	scanf("%d",&w);
	if(w==1){printf("%s",str);return 0;}
	for(int i=0;i<strlen(str);i++){
		if(i%w==0){
			putchar(str[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<String>();
		
		while(true){
			String str = br.readLine();
			if("0 0".equals(str)) break;
			list.add(str);
		}
		for(int i = 0 ; i <list.size() ; i++){
			String[] stra = list.get(i).split(" ");
			int h = Integer.parseInt(stra[0]);
			int w = Integer.parseInt(stra[1]);
			for (int j = 0 ; j < h ;j++){
				if( j == 0 || j == h-1 ){
					for(int k = 0 ; k < w ; k++){
						System.out.print("#");
					}
					System.out.println();
				}else{
					System.out.print("#");
					for(int l = 0 ; l < w-2 ; l++){
						System.out.print(".");
					}
					System.out.print("#");
					System.out.println();
				}
			}
			System.out.println();
		}
	}

}

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

int main(){
    int n, l[2000];
    cin >> n;
    for(int i=0;i<n;++i) cin >> l[i];
    sort(l, l+n);
    int64_t ans = 0;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            int left = j, right = n;
            while(right - left > 1){
                int mid = (left+right) / 2;
                if(l[mid] >= l[i]+l[j]) right = mid;
                else left = mid;
            }
            ans += left - j;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

N, Y = map(int, raw_input().split(" "))


def search():

    for i in xrange(0, N + 1):
        for j in xrange(0, N + 1 - i):
            k = N - i - j
            if (i * 10000 + j * 5000 + k * 1000 == Y):
                return i, j, k

    return -1, -1, -1

x, y, z = search()

print("{0} {1} {2}".format(x,y,z))



Measured memory_bytes: 2692
#include <iostream>
#include<cmath>
#include<vector>
#include<string>
#include<cstring>
#include<deque>
#include<queue>
#include<list>
#include<algorithm>

using namespace std;
int main()
{
 //problem e
 string s1,s2;
 cin>>s1>>s2;
 bool flag=false;
 int counter=s1.size();
 for(int i=0 ; i<counter;i++)
 {
    char k= s1.back();
    s1.pop_back();
    s1.insert(s1.begin() ,k);

if(s1==s2){ flag=true; break;}
 }
 if(flag==true)cout<<"Yes";
 else cout<<"No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const Int INF = 9999999999;

int main(){
    Int n,m;cin >> n >> m;
    vector<pair<Int,Int>> vec(n+1);
    for(Int i=0;i<m;i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(vec[p].first==1) continue;
        if(s=="AC") vec[p].first = 1;
        else vec[p].second++;
    }
    Int ans1 = 0;
    Int ans2 = 0;
    rep(i,n){
        if(vec[i].first==1){
            ans1++;
            ans2+=vec[i].second;
        }
        //cout << i << ":" << vec[i].first << " " << vec[i].second << endl;
    }
    //cout << "ans";
    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

#define MAX_NUM 1000000

using namespace std;


int n,m;
char str[MAX_NUM + 1];
bool field[MAX_NUM + 2];
int dp[MAX_NUM + 2];

int ans;

void solve(){
	for(int i = 0;i < MAX_NUM + 2;i++) dp[i] = 0;

	int i = 0;
	while(i < m){
		if(!field[i]){
			while(!field[++i]){
				if(!(i < m))break;
			}
		}

		if(!field[i + 1]){
			if(field[i + 2]){
				dp[i + 2] = dp[i] + 1;
				i++;
			}
			i++;
		}
		else{
			i++;
		}
	}

	ans = 0;
	for(int i = 0;i < m;i++){
		//printf("###%d\n",dp[i]);
		if(dp[i] >= n)ans++;
	}

	return ;
}

int main(){

	while(true){

	scanf("%d",&n);
	if(n == 0)break;
	scanf("%d",&m);
	scanf("%s",str);
	for(int i = 0;i < m;i++){
		if(str[i] == 'O') field[i] = false;
		else field[i] = true;
	}
	
	solve();

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

	}

	return 0;
}

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

ll dp[10002][1002];
ll a[1002],b[1002];

ll solve(ll h, ll n) {
    if(h<=0) return 0;
    if(n<=0) return INT64_MAX;
    if(dp[h][n]<INT64_MAX) return dp[h][n];
    else dp[h][n] = min(solve(h,n-1), b[n] + solve(h-a[n],n)); 
    return dp[h][n];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h,n,i,j;
    cin >> h >> n;
    for(i=1;i<=n;i++) {
        cin >> a[i] >> b[i];
    }
    for(i=0;i<=h;i++) {
        for(j=0;j<=n;j++) dp[i][j]=INT64_MAX;
    }
    cout << solve(h,n) << "\n";
    return 0;
}



Measured memory_bytes: 78848
#include<bits/stdc++.h>
using namespace std;
int ice[100][100],n,m,sum,ans;

int po(int x,int y,int n){

    if(ice[x+1][y]==0&&ice[x-1][y]==0&&ice[x][y+1]==0&&ice[x][y-1]==0)return n;
    else{
    if(ice[x+1][y]==1){
            ice[x+1][y]=0;
            sum=max(sum,po(x+1,y,n+1));
            ice[x+1][y]=1;
    }
     if(ice[x-1][y]==1){
            ice[x-1][y]=0;
            sum=max(sum,po(x-1,y,n+1));
            ice[x-1][y]=1;
    }
     if(ice[x][y+1]==1){
            ice[x][y+1]=0;
            sum=max(sum,po(x,y+1,n+1));
            ice[x][y+1]=1;
    }
     if(ice[x][y-1]==1){
            ice[x][y-1]=0;
            sum=max(sum,po(x,y-1,n+1));
            ice[x][y-1]=1;
    }

    }

    return sum;
}


int main(){

    while(1){
    ans=0;

    cin >> n >> m;
    if(n==0&&m==0)break;

    for(int i=1;i<m+1;i++){
        for(int j=1;j<n+1;j++){
            cin >> ice[j][i];
        }
    }

     for(int i=1;i<m+1;i++){
        for(int j=1;j<n+1;j++){
            if(ice[j][i]==1){
                ice[j][i]=0;
                sum=1;
                ans=max(ans,po(j,i,1));
                ice[j][i]=1;
            }
        }
    }

    for(int i=1;i<m+1;i++){
        for(int j=1;j<n+1;j++){
            ice[j][i]=0;
        }
    }


    cout << ans << endl;

    }


return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(auto&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(auto&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(auto&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(auto&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(auto&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}};
template<typename S,typename T,typename U>
auto& operator<<(auto& o,TRI<S,T,U>& t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 2005;

int t[MAX_N][MAX_N], a[MAX_N][MAX_N];
int h, w;

int calc()
{
	int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
			if(a[i][j]) t[i+1][j] = 0;
			else t[i+1][j] = t[i][j] + 1;
		}
		t[i+1][w] = 0;
		stack<pair<int, int> > st;
		for(int j = 0; j <= w; j++){
			if(st.empty()){
				st.push({j, t[i+1][j]});
				continue;
			}
			pair<int, int> p = st.top();
			if(p.second < t[i+1][j]){
				st.push({j, t[i+1][j]});
			}else if(p.second > t[i+1][j]){
				int pos;
				while(p.second >= t[i+1][j]){
					ans = max(ans, (p.second+1)*(j-(pos=p.first)+1));
					st.pop();
					if(!st.empty()) p = st.top();
					else break;
				}
				st.push({pos, t[i+1][j]});
			}
		}
	}
	return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i,h){
        string s;
        cin >> s;
        rep(j,w){
            t[i][j] = (s[j] == '#');
        }
    }
    h--, w--;
	rep(i,h){
		rep(j,w){
			a[i][j] = (t[i][j]+t[i+1][j]+t[i][j+1]+t[i+1][j+1])%2;
		}
	}
    rep(j,w+1){
        t[0][j] = 0;
    }
	cout << max({h+1, w+1, calc()}) << "\n";
    return 0;
}


Measured memory_bytes: 31616
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> par;
    UnionFind(int N) { par = vector<int>(N, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) { return -par[root(x)]; }
};

int main() {
    int N, M;
    cin >> N >> M;

    UnionFind tree(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        tree.unite(a - 1, b - 1);
    }

    int output = 0;
    for (int i = 0; i < N; i++) {
        if (tree.size(i) > output) {
            output = tree.size(i);
        }
    }
    cout << output << endl;

    return 0;
}


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

signed main(){
	int N, K, i, ans = 0;
	scanf("%lld%lld", &N, &K);
	vector<int> H(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &H[i]);
	}
	sort(H.begin(), H.end());
	for(i = 0; i + K < N; i++){
		ans += H[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
from collections import Counter

N = int(input())
S = []
for _ in range(N):
    tmp = input()
    S.append(tmp)

counter = Counter(S)
c_most = counter.most_common()

# a = {}
# for s in S_unique:
#     a[s] = S.count(s)

maxval = c_most[0][1]

anss = []

for s in c_most:
    if s[1] == maxval:
        anss.append(s[0])
    else:
        break

anss = sorted(anss)

for a in anss:
    print(a)



Measured memory_bytes: 49280