akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n; cin>>n;
    int ans = 0;
    int p_a,p_b;cin>>p_a>>p_b;
    for(int i=0;i<n-2; i++){
        int p_c; cin >> p_c;
        if((p_a<p_b&&p_b<p_c)||(p_c<p_b&&p_b<p_a)) ans ++;
        p_a=p_b;p_b=p_c;
    }
    cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  rep(i, 3) {
    if (s[i] == t[i]) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
num=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(num[K-1])

Measured memory_bytes: 38384
ans=10**8
h,w,K=map(int,input().split())
s=[]
import copy
def two(x):
	return "0"*(h-1-len(bin(x)[2:]))+bin(x)[2:]
for i in range(h):
	s.append(input())
for i in range(2**(h-1)):
	r=two(i)
	pre_ans=r.count("1")
	d=[0]*(pre_ans+1)
	dd=copy.copy(d)
	cnt=0
	for j in range(w):
		now=0
		for k in range(h):
			if s[k][j]=="1":
				d[now]+=1
			if k!=h-1:
				if r[k]=="1":
					now+=1
		if max(d)>K:
			e=[]
			for x in range(len(d)):
				e.append(d[x]-dd[x])
			d=copy.copy(e)
			cnt+=1
		if max(d)>K:
			cnt=10**7
		dd=copy.copy(d)
	pre_ans+=cnt
	ans=min(ans,pre_ans)
print(ans)

Measured memory_bytes: 62044
#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 Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define x first
#define y second
#define pb push_back
#define PB pop_back()
#define iOS ios_base::sync_with_stdio(false)
#define sqr(a) (((a) * (a)))
#define all(a) a.begin() , a.end()
#define error(x) cerr << #x << " = " << (x) <<endl
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define umap unordered_map
#define double long double
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef complex<double> point;
template <typename T> using os =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int maxn = 2e5 + 100, mod = 1e9 + 7;
int fact[maxn];
inline int power(int a, int b){
	if(!b)	return 1;
	int c = power(a, b >> 1);
	c = (1LL * c * c) % mod;
	if(b & 1)
		c = (1LL * c * a) % mod;
	return c;
}
inline int C(int n, int r){
	if(r > n)	return 0;
	int ans = fact[n];
	ans = (1LL * ans * power(fact[r], mod-2)) % mod;
	ans = (1LL * ans * power(fact[n-r], mod-2)) % mod;
	return ans;
}
inline int way(int x, int y, int a, int b){
	int dx = a-x;
	int dy = b-y;
	return C(dx+dy, dx);
}
int main(){
	iOS;
	fact[0] = 1;
	For(i,1,maxn)	fact[i] = (1LL * i * fact[i-1]) % mod;
	int ans = 0;
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	int i = n-a;
	For(j,b,m){
		ans = (ans + 1LL * way(0,0,i-1,j) * way(i,j,n-1,m-1)) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    YES((n+1)/2>=k);
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math, core.stdc.stdio;

int f(int x) {
    string s = x.to!string;
    int r = 1, n = cast(int) s.length;
    foreach(i, c; s) {
        r &= s[i] == s[n-1-i];
    }
    return r;
}

void main() {
    int a, b;
    scanf("%d %d", &a, &b);

    int ans;
    foreach(x; a..b+1)
        ans += f(x);
    ans.writeln;
}

Measured memory_bytes: 1276
#include <iostream>
#include <cstdio>
#include <queue>
#define N 505
#define F first
#define S second
using namespace std;

int n, p, r, c, ans, a[N][N], vt[N][N];
int dr[4] = {1, -1, 0, 0};
int dc[4] = {0, 0, 1, -1};
queue<pair<int,int>> qu;

int main() {
	int i, j, tr, tc, cnt;
	cin >> n;
	for(i=0; i<n; i++) for(j=0; j<n; j++) {
		a[i][j] = min(min(i, n-1-i), min(j, n-1-j));
	}
	for(i=0; i<n*n; i++) {
		scanf("%d", &p);
		p--;
		r = p/n, c = p%n;
		ans += a[r][c];
		vt[r][c] = 1;
		qu.push({r,c});
		while(!qu.empty()) {
			r = qu.front().F; c = qu.front().S; qu.pop();
			cnt = a[r][c];
			if(!vt[r][c]) cnt++;
			for(j=0; j<4; j++) {
				tr = r + dr[j];
				tc = c + dc[j];
				if(tr<0 || tr>=n || tc<0 || tc>=n || a[tr][tc]<=cnt) continue;
				a[tr][tc] = cnt;
				qu.push({tr, tc});
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5640
n = int(input())
a = list(map(int,input().split()))
b = list((x,i) for i,x in enumerate(a))
b.sort(reverse=True)
dp = [[0]*(n+1-i) for i in range(n+1)]
for i in range(n):
    x,idx = b[i]
    for j in range(i+1):
        k = i-j
        if dp[j+1][k] < dp[j][k] + x*(idx-j):
            dp[j+1][k] = dp[j][k] + x*(idx-j)
        if dp[j][k+1] < dp[j][k] + x*((n-1-k)-idx):
            dp[j][k+1] = dp[j][k] + x*((n-1-k)-idx)
ans = 0
for i in range(n+1):
    if ans < dp[i][n-i]:
        ans = dp[i][n-i]
print(ans)


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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    if(A+B<C+D){
        cout << "Right" << endl;
    }else if(A+B>C+D){
        cout << "Left" << endl;
    }else{
        cout << "Balanced" << endl;
    }

    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n);
    rep(i,0,n){
        cin>>a.at(i);
    }
    sort(all(a));
    ll ng=-INF;
    ll ok=INF;
    while(ok-ng>1){
        ll x=(ok+ng)/2;
        ll s=0, t=0;
        rep(i,0,n){
            if(a.at(i)>0){
                int ok2=-1, ng2=n;
                while(ng2-ok2>1){
                    int m=(ok2+ng2)/2;
                    if(a.at(i)*a.at(m)<=x)ok2=m;
                    else ng2=m;
                }
                s+=ok2+1;
            }
            else if(a.at(i)<0){
                int ng2=-1, ok2=n;
                while(ok2-ng2>1){
                    int m=(ok2+ng2)/2;
                    if(a.at(i)*a.at(m)<=x)ok2=m;
                    else ng2=m;
                }
                s+=n-ok2;
            }
            else if(x>=0)s+=n;
            if(a.at(i)*a.at(i)<=x)t++;
        }
        ll num=(s-t)/2;
        if(num>=k)ok=x;
        else ng=x;
    }
    cout<<ok<<endl;
return 0;
}

Measured memory_bytes: 1792
import copy

n=int(input())
B=list(map(int,input().split()))

ans = B[0]
bef = 0
for i in range(0,len(B)):
    if(i == len(B) - 1):
        ans += B[i]
    else:
        ans += min(B[i], B[i+1]) 

print(ans)
    


Measured memory_bytes: 3444
import numpy as np
import collections

N,K,Q=map(int,input().split(' '))
A=[]
for i in range(Q):
  A.append(int(input()))

c = collections.Counter(A)
for i in range(1,N+1):
  if K+c[i]-Q>0:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 20564
#include <bits/stdc++.h>
    using namespace std;
 
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 1000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #define rep(i,a,b) for(int i=a;i<b;++i)
    #define repr(i,a,b) for(int i=a;i>=b;--i)
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
 
    typedef long long ll;
    typedef pair<ll,ll> pii;
    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi;

    int main(){
        
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    // #endif  

        fast; 
        int n,ans=0;
        string s;
        cin>>n>>s;
        rep(i,0,n-2) if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
        cout<<ans;
        return 0;  
    }   
 
 
    //keep it simple stupid


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

int arr[100007];
int main(){
	Lancer();
	ll t, res = 0;
	string str;
	cin >> str;
	for (int i = str.length() - 2; i >= 0; i--){
		if (i % 2 != 0){
			bool ch = true;
			int k = i;
			for (int j = i / 2; j >= 0; j--){
				if (str[j] != str[k--]){
					ch = false;
					break;
				}
			}
			if (ch){
				res = i + 1;
				break;
			}
		}
	}
	cout << res;
	cout << endl;
	return 0;
}


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

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

  if (a+w<=b) {
    cout << b-(a+w) << endl;
  } else if (a>b+w) {
    cout << a-(b+w) << endl;
  } else {
    cout << 0 << endl;
  }
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b&&b==c)
        cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
}

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

main(){
  int D;
  cin >> D;
  if(D==25)cout << "Christmas" << endl;
  else if(D==24)cout << "Christmas Eve" << endl;
  else if(D==23)cout << "Christmas Eve Eve" << endl;
  else if(D==22)cout << "Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w; cin >> h >> w;
    vector<vector<int> > c(10, vector<int>(10));
    rep (i, 10) rep (j, 10) cin >> c[i][j];
    rep (k, 10) rep (i, 10) rep (j, 10) chmin(c[i][j], c[i][k] + c[k][j]);
    map<int, int> m;
    rep (i, h) {
        rep (j, w) {
            int a; cin >> a;
            if (a != -1 && a != 1) m[a]++;
        }
    }
    ll ans = 0;
    for (P p : m) ans += p.second * c[p.first][1];
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
/*  I won't be silenced                       */
/*  You can't keep me quiet                   */
/*  Won't tremble when you try it             */
/*  All I know is I won't go speechless       */
/*  'Cause I'll breathe                       */
/*  When they try to suffocate me             */
/*  Don't you underestimate me                */
/*  'Cause I know that I won't go speechless  */

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll mod=1000000007;


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

ll t=1;
//cin>>t;
while(t--)
{

ll x;
cin>>x;

ll ans=0;

ans+=1000*(x/500);
x%=500;
ans+=5*(x/5);



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
















Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    if(a == b && b == c){
            int bal = 1;
        printf("%d", bal);
    }else if(a == b || b == c || a == c){
        int bal = 2;
        printf("%d", bal);
    }else{
        int bal = 3;
        printf("%d", bal);
    }
    return 0;
}


Measured memory_bytes: 1720
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
ll int MOD=998244353;
#define N 3000000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n;
    cin>>n;
    int a[N];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    if(a[0]+1<a[n-1]){
        cout<<"No"; return 0;
    }
    if(a[0]==a[n-1]){
        if(a[0]==n-1||a[0]<=n/2) {cout<<"Yes"; return 0;}
        cout<<"No"; return 0;
    }
    int s=0,t=0;
    rep(i,n){
        if(a[i]==a[0])s++;
        else t++;
    }
    if(a[0]+1<=s+t/2&&a[0]+1>s){
        cout<<"Yes"; return 0;
    }
    cout<<"No"; return 0;
    
    return 0;
}

Measured memory_bytes: 2432
//#include<bits/stdc++.h>
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

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


ULL gcd(ULL a,ULL b)
{
    return b==0?a:gcd(b,a%b);
}

int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif
    //ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ULL ans=1;
    while(n--)
    {
        ULL now;
        cin>>now;
        now/=gcd(ans,now);
        ans*=now;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int itemCount = int.Parse(Reader.ReadLine());
        score = new int[itemCount];

        for (int i = 0; i < itemCount; i++) {
            score[i] = int.Parse(Reader.ReadLine());
        }
        int ans = GetAns(0, 0);
        Console.WriteLine(ans);

    }
    private Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int, int>>();

    private int GetAns(int idx, int subtotal) {
        if(idx>=score.Length) {
            if(subtotal%10!=0) {
                return subtotal;
            } else {
                return 0;
            }
        }
        if(!dic.ContainsKey(idx)) {
            dic.Add(idx, new Dictionary<int, int>());
        }
        if(dic[idx].ContainsKey(subtotal)) {
            return dic[idx][subtotal];
        }
        int max = 0;
        max = GetAns(idx + 1, subtotal + score[idx]);
        max = Math.Max(max, GetAns(idx + 1, subtotal));
        dic[idx][subtotal] = max;
        return max;
    }

    private int[] score;



    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


3
10
20
30


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 30176
#include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+5;
int n,ans;
int a[MAX];
map<int,int> ma;
bool use[MAX];
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
        scanf("%d",&a[i]),++ma[a[i]];
    sort(a+1,a+1+n);
    for(int i=31; i>=1; --i)
    {
        for(int j=1; j<=n; ++j)
            if(ma[a[j]])
            {
                int x=(1<<i)-a[j];
                if(x<=0) break;
                if(x!=a[j])
                {
                    if(ma[x]) ++ans,--ma[x],--ma[a[j]];
                }
                else
                {
                    if(ma[x]>=2) ++ans,ma[x]-=2;
                }
            }
    }
    return printf("%d",ans),0;
}


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

MOD = 998244353
fact = [1]
rfact = [1]
for i in range(1, N+1):
    fact.append(fact[i-1]*i%MOD)
    rfact.append(pow(fact[i], MOD-2, MOD))

def C(n, m):
    return fact[n]*rfact[m]*rfact[n-m]%MOD

res = 0
for k in range(K+1):
    res = (res + C(N-1, k) * M * pow(M-1, N-k-1, MOD)) % MOD
print(res)

Measured memory_bytes: 98032
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
vector<ll> res(0);
void yakusuu(ll n){
	for(ll i=1;i*i<=n;i++){
	    if(n%i==0){
            res.pb(i);
            if(i!=n/i) res.pb(n/i);
	    }
	}
	return ;
}
int main(){
  ll n;
  cin>>n;
  ll ans=0;
  vll a(0);
  yakusuu(n-1);
  ans+=sz(res)-1;
  res=a;
  yakusuu(n);
  rep(i,sz(res)){
    if(res[i]==1) continue;
    ll j=n;
    while(j%res[i]==0){
      j/=res[i];
    }
    if(j%res[i]==1) ans++;
  }
  COUT(ans);
}

Measured memory_bytes: 3636
w = input()
l = list(w)
wl = sorted(l)

flag = True
for i in range(0, len(wl), 2):
    if len(wl) % 2 == 1:
        print('No')
        flag = False
        break
    else:
        if wl[i] != wl[i + 1]:
            print('No')
            flag = False
            break
if flag:
    print('Yes')

Measured memory_bytes: 3060
import math
A, B, H, M = map(int, input().split())
hour_rad = math.pi / 2 - 2 * math.pi * (60 * H + M) / 720
hour_x = A * math.cos(hour_rad)
hour_y = A * math.sin(hour_rad)
min_rad = math.pi / 2 - 2 * math.pi * M / 60
min_x = B * math.cos(min_rad)
min_y = B * math.sin(min_rad)
print("{:.15f}".format(math.sqrt((hour_x - min_x) ** 2 + (hour_y - min_y) ** 2)))

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



def main():
    S = input()
    
    p = 0
    c = 0

    for i, s in enumerate(S):
        if s == 'W':
            c += 1
            p += i

    print(p - c*(c-1)//2)



if __name__ == '__main__':
    main()


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

int main() {
  string S;
  cin >> S;
  int Ssize = S.size();
  vector<char> n(Ssize);
  for(int i = 0; i < Ssize; i++) n.at(i) = S.at(i);

  int counter = 0;
  for(int i = 1; i < Ssize; i++) {
    if(n.at(i) == n.at(i - 1)) {
      n[i] = n[i] == '0' ? '1' : '0';
      counter++;
    }
  }
  cout << counter << endl;
}


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

#define MOD 1000000007

using ll = long long;

int main() {
    char S[100005];
    scanf("%s\n", S);
    ll N = strlen(S);

    ll mod13[13];
    mod13[0] = 1;
    int exponent = 1;

    for (int i = 0; i < N; i++) {
        ll mod13_buf[13] = {0};
        int c = (S[N - i - 1] == '?') ? -1 : S[N - i - 1] - '0';
        if (c == -1) {
            for (int n = 0; n < 10; n++) {
                int m = n * exponent % 13;
                for (int r = 0; r < 13; r++) {
                    mod13_buf[(r + m) % 13] += mod13[r];
                }
            }
        } else {
            for (int r = 0; r < 13; r++) {
                int m = c * exponent % 13;
                mod13_buf[(r + m) % 13] += mod13[r];
            }
        }
        exponent = exponent * 10 % 13;
        for (int j = 0; j < 13; j++) {
            mod13[j] = mod13_buf[j] % MOD;
        }
    }
    printf("%lld\n", mod13[5]);
}


Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

vector<P> f(ll n) {
  vector<P> res;
  for (ll i = 2; i * i <= n; ++i) {
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      ++cnt;
    }
    if (cnt > 0) {
      res.eb(i, cnt);
    }
  }
  if (n > 0) res.eb(n, 1);
  return res;
}

vector<ll> divisors(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.pb(i);
      if (i != n/i) res.pb(n / i);
    }
  }
  return res;
}

void solve() {
  ll n, m; cin >> n >> m;
  vector<ll> v = divisors(m);
  ll ans = 1;
  each(x, v) {
    if (x == 1) continue;
    ll cnt = 0;
    ll y = m;
    while (y % x == 0) {
      y /= x;
      ++cnt;
    }
    if (cnt >= n) chmax(ans, x);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
LL N;
int main()
{
	//freopen(".in","r",stdin);
	scanf("%lld",&N);
	for(RG LL h=1;h<=3500;h++)
	 for(RG LL n=1;n<=3500;n++)
	 {
		LL mu=4*h*n-N*n-N*h, zi=N*h*n;
		if(mu>0 && zi%mu==0 ) 
		{
			printf("%lld %lld %lld",h,n,zi/mu);
			return 0;
		}
	 }
	return 0;
}

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

int main(){
  int n;
  long long max = -1000000;
  long long min = 1000000;
  long long sum = 0;

  cin >> n;

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

    sum += a;
    if( a > max ) max = a;
    if( a < min ) min = a;
  }
  cout << min << " " << max << " " << sum << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;

#define rep(i, s, t) for (auto i = s; i < (t); ++i)
#define per(i, s, t) for (auto i = s; i >= (t); --i)
#define sz(x) ((int) (x).size())
#define mp make_pair
#define pb push_back

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return 1;
    }
    return 0;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return 1;
    }
    return 0;
}

void run();

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}

int ask(int x) {
    cout << x << endl;
    string res;
    cin >> res;
    if (res == "Vacant") {
        exit(0);
    }
    return res == "Male";
}

void run() {
    int n;
    cin >> n;
    int vl = ask(0);
    int vr = ask(n - 1);
    int l = 0;
    int r = n - 1;
    rep(iter, 0, 18) {
        int m = (l + r) / 2;
        int vm = ask(m);
        
        if (((m - l + 1) % 2 == 0) ^ (vl != vm)) {
            r = m;
            vr = vm;
        } else {
            l = m;
            vl = vm;
        }
    }
    
    assert(false);
}


Measured memory_bytes: 852
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 200000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
vi puyopuyo;
int main()
{
	while(1)
	{
		puyopuyo.clear();
		int n;
		cin >> n;
		int ans=n;
		if(n==0)break;
		puyopuyo.pb(-1);
		for(int i=0;i<n;i++)
		{
			int k;
			cin >> k;
			puyopuyo.pb(k);
		}
		puyopuyo.pb(-12);
		for(int i=1;i<=n;i++)
		{
			int tmp=puyopuyo[i];
			int top=i+1;
			int under=i;
			int res=n;
			puyopuyo[under]=puyopuyo[top];
			while(puyopuyo[under]==puyopuyo[top])
			{
				int remove=0;
				int tmp2=puyopuyo[top];
				while(puyopuyo[top]==tmp2)
				{
					top++;
					remove++;
				}
				while(tmp2==puyopuyo[under])
				{
					under--;
					remove++;
				}
				if(remove>=4)
				{
					res-=remove;
				}
				else break;
			}
			ans=min(ans,res);
			top=i;
			under=i-1;
			res=n;
			puyopuyo[top]=puyopuyo[under];
			while(puyopuyo[top]==puyopuyo[under])
			{
				int remove=0;
				int tmp2=puyopuyo[top];
				while(puyopuyo[top]==tmp2)
				{
					top++;
					remove++;
				}
				while(puyopuyo[under]==tmp2)
				{
					under--;
					remove++;
				}
				if(remove>=4)
				{
					res-=remove;
				}
				else break;
			}
			ans=min(ans,res);
                        puyopuyo[i]=tmp;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1320
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//入力
		int n = sc.nextInt();
		String s = sc.next();
		int k = sc.nextInt();

		for(int i=0; i<n; i++) {
			if(s.charAt(k-1) != s.charAt(i)) {
				s = s.replace(s.charAt(i), '*');
			}
		}

		System.out.println(s);

		sc.close();
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(rall(a));
    ll ans = a[0];
    rep(i, n - 2) ans += a[i / 2 + 1];
    cout << ans << endl;
    return 0;
}


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

vector<vector<int>> G;
queue<int> tovisit;
const int INF = 1000000007;

void bfs(vector<int> &step) {
  int cur = tovisit.front();
  tovisit.pop();
  for (int nx : G.at(cur)) {
    if (step.at(nx) != INF) continue;
    step.at(nx) = step.at(cur) + 1;
    tovisit.push(nx);
  }
}

int main() {
  int N; cin >> N;
  G.resize(N);
  for (int i = 0; i < N-1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  vector<int> F(N, INF), S(N, INF);  // 各頂点への距離
  F.at(0) = 0;
  S.at(N-1) = 0;
  tovisit.push(0);
  while (!tovisit.empty()) bfs(F);
  tovisit.push(N-1);
  while (!tovisit.empty()) bfs(S);
  int cnt_F = 0, cnt_S = 0;  // 塗れる個数
  for (int i = 0; i < N; i++) {
    if (F.at(i) <= S.at(i)) cnt_F++;
    else cnt_S++;
  }
  if (cnt_F <= cnt_S) cout << "Snuke" << endl;
  else cout << "Fennec" << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
using namespace std;

void solution(vector<int> num, vector<int> direction)
{
    map<int, int> x;
    map<int, int> y;
    x.insert(make_pair(0, 0));
    y.insert(make_pair(0, 0));

    int minX = 0;
    int maxX = 0;
    int minY = 0;
    int maxY = 0;
    for(unsigned i=0; i<num.size(); ++i){
        if(direction[i] == 0 || direction[i] == 2){
            y[i+1] = y[num[i]];
            if(direction[i] == 0){
                x[i+1] = x[num[i]] - 1;
                minX = min(minX, x[i+1]);
            }else{
                x[i+1] = x[num[i]] + 1;
                maxX = max(maxX, x[i+1]);
            }
        }else{
            x[i+1] = x[num[i]];
            if(direction[i] == 1){
                y[i+1] = y[num[i]] - 1;
                minY = min(minY, y[i+1]);
            }else{
                y[i+1] = y[num[i]] + 1;
                maxY = max(maxY, y[i+1]);
            }
        }
    }

    cout << (maxX-minX+1) << ' ' << (maxY-minY+1) << endl;
}

int main()
{
    int n;
    for(;;){
        cin >> n;
        if(n == 0)
            break;
        vector<int> num(n-1);
        vector<int> direction(n-1);
        for(int i=0; i<n-1; ++i)
            cin >> num[i] >> direction[i];
        solution(num, direction);
    }

    return 0;
}

Measured memory_bytes: 0
import sys

readline = sys.stdin.buffer.readline


def main():
	v, e = map(int, readline().split())
	g = [[1 << 60] * v for _ in range(v)]
	for i in range(v):
		g[i][i] = 0
	for _ in range(e):
		s, t, c = map(int, readline().split())
		g[s][t] = c
	for k in range(v):
		for i in range(v):
			for j in range(v):
				if g[i][j] > g[i][k] + g[k][j]:
					g[i][j] = g[i][k] + g[k][j]
	for i in range(v):
		if g[i][i] < 0:
			print("NEGATIVE CYCLE")
			exit()
	for l in g:
		print(" ".join(["INF" if x > 1 << 40 else str(x) for x in l]))


if __name__ == "__main__":
	main()


Measured memory_bytes: 6160
#include<stdio.h>
#include<stdlib.h>
int main () {
	long long int n, l, min, sum, i;
	scanf("%lld%lld", &n, &l);
	sum = n * (l - 1) + (n * (n + 1))/2;
	min = l;
	for (i = 2; i <= n; i++) {
		if (llabs(l - 1 + i) < llabs(min)) {
			min = l + i - 1;
		}
	}
	sum = sum - min;
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
using namespace std;
 
int main(int argc, char* argv[]) {
  
  long long a, b, c;
  cin >> a >> b >> c;
  
  long long d = c - a - b;
  
  if (d > 0 && 4 * a * b  < d*d) {
   cout << "Yes" << endl; 
  }else {
    cout << "No" << endl; 
  }
  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int ans[N], colors; 
vector < pair < int, int > > edges[N];
void dfs(int x, int p, int color){
	int col = 0;
	for(int i = 0; i < edges[x].size(); i++){
		int to = edges[x][i].first;
		int ind = edges[x][i].second;
		if(to != p){
			++col;
			if(col == color)++col;
			ans[ind] = col; 
			colors = max(colors, ans[ind]);
			dfs(to, x, col);    
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1, a, b; i < n; i++){
		cin >> a >> b;
		edges[a].push_back({b, i});
		edges[b].push_back({a, i});
	}
	dfs(1, 0, -1);
	cout << colors << '\n';
	for(int i = 1; i < n; i++){
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 11648
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double exchangeRate = 380000.0;
		double total = 0.0;
		for(int i = 0; i < N; i++){
			double m = sc.nextDouble();
			String c = sc.next();
			if(c.equals("JPY")){
				total += m;
			}else if(c.equals("BTC")){
				total += (m * exchangeRate);
			}
		}
		System.out.println(total);
	}

}


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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> daice(N,vector<int>(2));
    for(int i=0;i<N;i++){
        cin >> daice.at(i).at(0);
        cin >> daice.at(i).at(1);
    }
    int key = 0;
    for(int i=0;i<N;i++){
        if(key<3){
            if(daice.at(i).at(0) == daice.at(i).at(1)){
                key++;
            }else{
                key = 0;
            }
        }else{
            break;
        }
    }
    if(key < 3){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

//Author: Jiangsu Nanjing Li Zongtai
//强壮标记*10000,手牌*10000,血量10000 lyl+hzj也打不死我哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈~~~~
//注意要不要long long

const long long inf=2147483647;

long long n,m;
vector<long long> adj[111111];
long long used[111111];
bool ok;

void dfs(long long nw)
{
	for(long long i=0;i<adj[nw].size();i++)
	{
		long long tt=adj[nw][i];
		
		if(used[tt]==used[nw])
		{
			ok=1;
			return;
		}
		
		if(used[tt]) continue;
		
		used[tt]=3-used[nw];
		
		dfs(tt);
	}
}

int main()
{
	cin>>n>>m;
	
	for(long long i=1;i<=m;i++)
	{
		long long x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	used[1]=1;
	dfs(1);
	
	if(ok)
	{
		cout<<n*(n-1)/2-m<<endl;
		return 0;
	}
	
	long long num=0;
	long long t=0;
	
	for(long long i=1;i<=n;i++) if(used[i]==1) num++; else if(used[i]==2) t++;
	
	cout<<num*t-m<<endl;
	
	return 0;
}


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

using namespace std;

int hindo[100];

int main()
{
  int n;
  while (scanf("%d ", &n) == 1) {
    hindo[n - 1]++;
  }
  
  int mx = 0;
  for (int i = 0; i < 100; i++) {
    mx = max(hindo[i], mx);
  }
  for (int i = 0; i < 100; i++) {
    if (mx == hindo[i]) {
      printf("%d\n", i + 1);
    }
  }
  return 0;
}

Measured memory_bytes: 0
def resolve():
    n = int(input())
    primel = [2]
    for i in range(3,331):
        k = 0
        for j in range(len(primel)):
            if i % primel[j] == 0:
                break
            else:
                k += 1
            if k == len(primel):
                primel.append(i)

    for i in range(0, 100000):
        k=0
        for j in range(len(primel)):
            if (n+i) == primel[j]:
                print(n + i)
                exit()
            if (n+i) % primel[j] == 0:
                break
            else:
                k += 1
            if k == len(primel):
                print(n + i)
                exit()
resolve()

Measured memory_bytes: 39024
#include<bits/stdc++.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
#define max1 1000001

//long long int mod=1e18 ;


int main(){	
	int n;
	cin>>n;
	int a[n][3];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	int dp[n+1][3];
	dp[1][0]=a[0][0];
	dp[1][1]=a[0][1];
	dp[1][2]=a[0][2];
	for(int i=2;i<=n;i++){
		for(int j=0;j<3;j++){
			dp[i][j]=0;
			dp[i][j]=max(dp[i][j],dp[i-1][(j+1)%3]+a[i-1][j]);
			dp[i][j]=max(dp[i][j],dp[i-1][(j+2)%3]+a[i-1][j]);
		}
	}
	int ans=0;
	for (int i = 0; i < 3; ++i)
	{
		ans=max(ans,dp[n][i]);
	}
	cout<<ans<<endl;


}
	
	
	
	





Measured memory_bytes: 2560
#include <stdio.h>
#define swap(x, y) {int z; z=y; y=x; x=z;}
int main ()
{
	int a, b;
	while(scanf("%d %d", &a, &b))
	{
		if(a == 0 && b == 0)
		{
			break;
		}
		if(a > b)
		{
			swap(a, b);
		}
		printf("%d %d\n", a, b);
	}

	return 0; 
} 


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

int  main()
{
	int  a[4][4],i,j,x,y,z;
	
	for(i=1; i<=3; i++)
    	for(j=1; j<=3; j++)
    	   cin>>a[i][j];
    	   
    x=a[1][1]+a[2][2]+a[3][3];
    y=a[1][2]+a[2][3]+a[3][1];
    z=a[1][3]+a[2][1]+a[3][2];
    
    if(x==y && x==z && y==z)
       cout<<"Yes"<<endl;
    else
       cout<<"No"<<endl;
       
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(void){

    double N,T,A,ans=0,tmp1,tmp2;
    
    cin >> N >> T >> A;
    
    vector<double> vec(N);
    REP(i,N) cin >> vec[i];

    double min = 9999999999;

     REP(i,N){

        tmp1 = T - 0.006*vec[i];    
        
        tmp2 = A-tmp1;
        if(tmp2 < 0)  tmp2 *= -1;
 
        if(min > tmp2){
            min = tmp2;
            ans= i+1;
        }  
    }

    cout << ans << endl;
   
}


Measured memory_bytes: 256
from itertools import combinations
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in combinations(l, 3):
    i = list(i)
    i.sort()
    if i[0]==i[1] or i[1]==i[2]:
        continue
    if i[0]+i[1]>i[2]:
        ans += 1
print(ans)

Measured memory_bytes: 9184
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = System.Console.ReadLine();
            var valAry = line.Split(' ');
            int valA = 0;
            int.TryParse(valAry[0], out valA);

            var result = valA + Math.Pow(valA, 2) + Math.Pow(valA, 3);
            Console.WriteLine((int)result);
        }
    }
}

Measured memory_bytes: 27816
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
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;
}
vector<int> a;
vector<int> b;
vector<int> c;
/*めぐる式二部探索(けんちょん神の記事のコピー)*/
bool isOK(int index, int key) {
	if (a[index] >= key) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return left;
}

bool isOK1(int index, int key) {
	if (c[index] > key) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search1(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)c.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK1(mid, key)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int d;
		cin >> d;
		a.push_back(d);
	}
	for (int i = 0; i < n; i++) {
		int d;
		cin >> d;
		b.push_back(d);
	}
	for (int i = 0; i < n; i++) {
		int d;
		cin >> d;
		c.push_back(d);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	long long int sum = 0;
	for (int i = 0; i < b.size(); i++) {
		long long int ue;
		long long int sita;
		ue = binary_search(b[i]);
		sita = binary_search1(b[i]);
		if (ue == -1 || sita == n) {
			continue;
		}
		else {
			sum = sum + (ue + 1) * (n - sita);
		}
	}
	cout << sum;
}

Measured memory_bytes: 1784
N = int(input())
A = list(map(int, input().split()))

A.sort()
import copy
cum = copy.copy(A)
for i in range(1,N):
    cum[i] = cum[i-1]+A[i]

def solve(A,cum,N):
    ans = 1
    for i in range(N-1,0,-1):
        if A[i]<=cum[i-1]*2:
            # print(A[i],cum[i-1])
            ans += 1
        else:
            break
    return ans
print(solve(A,cum,N))


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

 using namespace std;

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

   vector<int> L(N + 1);
   vector<int> D(N + 2);

   for (int i = 1; i <= N; i++) cin >> L.at(i);

   D.at(1) = 0;
   int ans = 1;
   bool finished = false;

   for (int i = 2; i <= N + 1; i++) {
     D.at(i) = D.at(i - 1) + L.at(i - 1);
     if (D.at(i - 1) <= X && X < D.at(i)) {
       ans = i - 1;
       finished = true;
       break;
     }
   }

   if (!finished) ans = N + 1;


   cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

int W, N;
VI ps, wes;
int cc = 1;

int main(){
	while (cin >> W, W) {
		ps.clear();
		wes.clear();
		cin >> N;
		ps.resize(N);
		wes.resize(N);
		VVI dp(N + 1, VI (W + 1, -1));
		rep(i, N) rep(j, W) dp[i][j] = 0;
		rep(i, N) {
			char c;
			cin >> ps[i] >> c >> wes[i];
		}
		dp[0][0] = 0;
		rep (i, N) {
			rep (j, W + 1) {
				if (dp[i][j] == -1) continue;
				dp[i + 1][j] = max(dp[i + 1][j] ,dp[i][j]);
				if (j + wes[i] <= W) {
					dp[i + 1][j + wes[i]] = max(dp[i + 1][j + wes[i]], dp[i][j] + ps[i]);
				}
			}
		}
		int ans_p = *max_element(all(dp[N]));
		int ans_w = 0;
		rep (i, W + 1) {
			if (dp[N][i] == ans_p) {
				ans_w = i;
				break;
			}
		}
		cout << "Case " << cc++ << ":" << endl;
		cout << ans_p << endl;
		cout << ans_w << endl;
	}
	return 0;
}

Measured memory_bytes: 5028