akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;


//1547
int main(){
    string s;
    cin >> s;
    int num[4];

    
    for(int i =0; i < 4; i++) num[i] = s[i]- '0';

    bool f[3];
    for(int i =0 ;i < (2 << 2) ;i++){
        int temp =num[0];
        for(int j = 0 ;j <= 2 ;j++){
            if((i >> j) & 1 ) temp+= num[j+1], f[j]=1;
            else temp-= num[j+1], f[j] =0;
        }
        if(temp==7){
            cout << num[0];
            for(int j = 0 ;j <= 2 ;j++){
                f[j]? cout << "+" : cout << "-"; 
                cout << num[j+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll 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;
    }
}

// 二項係数計算
ll 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;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    ll s_len = s.length();
    ll t_len = t.length();
    ll cnt = s_len - t_len + 1;
    ll same = 0;
    ll max_same = 0;
    for(int right = s_len -1; right >= t_len -1; right--){
        int left = right - t_len + 1;
        ll i = 0;
        same = 0;
        for(int k = left; k <= right; k++){
            if(s[k] == t[i]) same++;
            i++;
        }
        max_same = max(same, max_same);
    }

    cout << t_len - max_same << endl;
    return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<cmath>
#include<vector>

int main(){
	int k;
	std::string s;

	std::cin>>k;
	std::cin>>s;

	int len= s.size();

	if(len<=k){
		std::cout<<s<<std::endl;
	}
	else{
		for(int i=0; i< k; i++)
			std::cout<<s[i];

		std::cout<<"..."<<std::endl;
	}


	return 0;	

}

Measured memory_bytes: 3628
sheet = []
b = []

for i in range(3):
    sheet.append(list(map(int, input().split())))

N = int(input())

for i in range(N):
    b.append(int(input()))

for number in b:
    if number in sheet[0]:
        sheet[0][sheet[0].index(number)] = 0
    if number in sheet[1]:
        sheet[1][sheet[1].index(number)] = 0
    if number in sheet[2]:
        sheet[2][sheet[2].index(number)] = 0

if sheet[0][0] == 0 and sheet[0][1] == 0 and sheet[0][2] == 0:
    print("Yes")
elif sheet[1][0] == 0 and sheet[1][1] == 0 and sheet[1][2] == 0:
    print("Yes")
elif sheet[2][0] == 0 and sheet[2][1] == 0 and sheet[2][2] == 0:
    print("Yes")
elif sheet[0][0] == 0 and sheet[1][1] == 0 and sheet[2][2] == 0:
    print("Yes")
elif sheet[0][2] == 0 and sheet[1][1] == 0 and sheet[2][0] == 0:
    print("Yes")
elif sheet[0][0] == 0 and sheet[1][0] == 0 and sheet[2][0] == 0:
    print("Yes")
elif sheet[0][1] == 0 and sheet[1][1] == 0 and sheet[2][1] == 0:
    print("Yes")
elif sheet[0][2] == 0 and sheet[1][2] == 0 and sheet[2][2] == 0:
    print("Yes")
else:
    print('No')


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll mx= 0, max2=0;
    priority_queue<ll> q;
    for(ll i = 0; i< n; i++){
        cin >> a[i];
        q.push(a[i]);
    }
    mx = q.top();
    q.pop();
    
    ll ans = mx;
    ll num;
    if(n % 2 != 0){
        for(ll i = 0; i < (n-1)/2; i++){
        int now = q.top();
        q.pop();
        ans += now*2;
        if(i == (n-1)/2-1){
            ans -= now;
        }
    }
    }else{
        for(ll i = 0; i < (n-1)/2; i++){
            int now = q.top();
            q.pop();
            ans += now*2;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6928
//package Atcoder;
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int x=fs.nextInt();
		if(x==0)
		{
			System.out.println(1);
		}
		else if(x==1)
			System.out.println(0);
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

Measured memory_bytes: 32656
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    string s;
    cin >> s;

    rep(i, 1 << 4) {
        string t;
        if(i & 1) t.push_back('A');
        t += "KIH";
        if(i & 2) t.push_back('A');
        t.push_back('B');
        if(i & 4) t.push_back('A');
        t.push_back('R');
        if(i & 8) t.push_back('A');
        if(t == s) {
            cout << "YES\n";
            return 0;
        }
    }

    cout << "NO\n";

    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
int main(void){
    char s[105],p[105],temp[210];
  
    scanf("%s",s);
    scanf("%s",p);
  
    strcpy(temp,s);
    strcat(temp,s);
  
    if(strstr(temp,p)!=NULL){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
  
    return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>

#define rep(i, a) for(int i = 0; i < a; i++)
#define llint long long int
using namespace std;

const int MAX_x = 100005;
const llint INF = 999999999999999;

int main()
{
    int n, k;
    llint x[MAX_x];
    cin >> n >> k;

    int bgn, end;
    bool pn = false;
    rep(i, n) {
        cin >> x[i];
        if ((!pn && x[i] >= 0) || (i == n - 1 && x[i] < 0)) {
            bgn = i;
            if(bgn + k <= n) end = bgn + k - 1;
            else {      
                bgn = n - k;
                end = n - 1;
            }
            pn = true;
        }
    }

    llint dst, mn = INF;
    do {
        dst = min(abs(x[bgn]) +  abs(x[bgn] - x[end]), 
                    abs(x[end]) +  abs(x[bgn] - x[end]));
        if (dst < mn) mn = dst;
        //printf("%lld %d %d\n", dst, bgn, end);

        --bgn;
        --end;
    } while (bgn >= 0);

    cout << mn << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    int N; cin >> N;
    ll A[100100];
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    ll now = A[N - 1], cnt = 0, ans = 1LL;
    per(i, N - 1) {
        if(now == A[i]) {
            ans *= now;
            now = 0;
            cnt ++;
            if(cnt == 2) break;
        } else {
            now = A[i];
        }
    }
    if(cnt <= 1) ans = 0;
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll

int n,x;
int a[200020];
int cnt=1;
signed main(){
    cin>>n>>x;
    if(x==1 || x==2*n-1){
        cout<<"No"<<endl;
        return 0;
    }
    
    rep(i,0,n*2-1)a[i]=i+1;
    swap(a[x-1],a[n-1]);
    swap(a[0],a[n-2]);
    swap(a[2*n-2],a[n]);
    cout<<"Yes"<<endl;
    rep(i,0,2*n-1)cout<<a[i]<<endl;
}

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

int main()
{
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    string ans = "";
    for(int i = 0; i < n; i++){
        ans += s[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  char A,B;
  cin>>A>>B;
  if((int)A-'0'>(int)B-'0') cout<<">";
  else if((int)A-'0'<(int)B-'0') cout<<"<";
  else cout<<"=";
return 0;}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
 

 ll arr[104];

int main()
{
 	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	//ll tt;	cin>>tt;	while(tt--)
  	{
  		ll n,i,a,x,ans;
  		cin>>n;

  		for(i=1;i<=n;i++)
  		{
  			a=i%10;
  			x=i;
  			while(x>=10)	x/=10;
  			arr[x*10+a]++;
  			//cout<<x*10+a<<endl;
  		}

  		ans=0;
  		for(i=1;i<=n;i++)
  		{
  			a=i%10;
  			x=i;
  			while(x>=10)	x/=10;

  			ans+=arr[a*10+x];
  		}

  		//for(i=0;i<1000;i++)	cout<<arr[i]<<' ';cout<<endl;
  		cout<<ans;

  	}
 	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
    return 0;
  		
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7, K = 20;
vector <int> g[N];
int dp[N][K];
void dfs(int u, int par) {
    for (int v : g[u]) {
        if (v != par) {
            dfs(v, u);
            for (int i = 0; i < K; ++i)
                dp[u][i] += dp[v][i];
        }   
    }   
    int pos = -1;
    for (int i = 0; i < K; ++i)
        if (dp[u][i] > 1)
            pos = i;
    if (pos != -1) {
        for (int i = 0; ; ++i) {
            if (dp[u][i] == 0 && i > pos) {
                dp[u][i] = 1;
                break;
            }   
            dp[u][i] = 0;
        }   
    }   
    else {
        ++dp[u][0];
        int ptr = 0;
        while (dp[u][ptr] == 2) {
            dp[u][ptr] = 0;
            ++dp[u][ptr + 1];
            ++ptr;
        }   
    }   

    #ifdef HOME
    cout << "dp " << u << " : ";
    for (int i = 0; i < K; ++i)
        cout << dp[u][i] << ' ';
    cout << endl;
    #endif
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].app(v); g[v].app(u);
    }   
    dfs(1, 1);
    for (int i = K - 1; ; --i) {
        if (dp[1][i]) {
            cout << i << endl;
            exit(0);
        }   
    }   
}

Measured memory_bytes: 27008
#include<stdio.h>
#include<string.h>

int main()
{
 char s1[100], s2[100];
 int a,i;
 int sumt=0,sumh=0;
  scanf("%d",&a);

  for(i=0;i<a;i++){
  scanf("%s %s", s1, s2);
  if ( strcmp(s1, s2) == 0 ) sumt++,sumh++;
  else if ( strcmp(s1, s2) > 0 ) sumt+=3;
  else if ( strcmp(s1, s2) < 0 ) sumh+=3;
                  }

  printf("%d %d\n",sumt,sumh);
  return 0;
}



Measured memory_bytes: 2044
n=int(input())
p=[int(x) for x in input().rstrip().split()]
l=[i+1 for i in range(n)]
cnt=0
for i in range(n):
  if l[i]!=p[i]:
    cnt+=1
if cnt==2 or cnt==0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 9128
N, K = map(int, input().split())
p = list(map(int, input().split()))

s = 0
 
for i in range(N):
  p[i] = (p[i] + 1) / 2

for j in range(K):
  s += p[j]

x = s
 
for k in range(N - K):
  t = s - p[k] + p[K + k]
  if max(s, x) <= t:
    x = t
  else:
    pass
  s = t

print(x)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
vector<vector<ll> >G(100010);
ll dfs(ll i){
    ll cnt=0;
    ll ma=-1;
    vector<ll>a(0);
    for(auto e:G[i]){
        cnt++;
        ll k=dfs(e);
        a.pb(k);
    }
    sort(all(a));
    rep(i,a.size()){
        if(a[i]>ma){
            ma=a[i];
            continue;
        }
        ma++;
    }
    //cout<<i<<' '<<ma<<endl;
    ll ret=ma+1;
    return ret;
}
int main(){
    ll n;cin>>n;
    ll a;
    rep(i,n-1){
        cin>>a;
        G[a].pb(i+2);
    }
    ll ans=dfs(1);
    cout<<ans<<endl;
}

Measured memory_bytes: 13568
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
wa = 0
n,m = map(int,input().split())
data = [0]*(n+1)
ans = [0]*(n+1)
for i in range(m):
  p,s = input().split()
  p = int(p)
  if s == "WA":
    data[p] += 1
  else:
    if ans[p] == 0:
      wa += data[p]
      ans[p] = 1
print(sum(ans),wa)
  
    

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

int main(){
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  while(1){
    C=C-B;
    if(C<=0){
      cout << "Yes"<<endl;
      break;
    }
    A=A-D;
    if(A<=0){
      cout << "No"<<endl;
      break;
    }
  }

}


Measured memory_bytes: 3640
N = int(input())
N_10 = N
S_N = 0
for i in range(10):
  rem = N_10%10
  S_N += rem
  N_10 //= 10
  if N_10 == 0:
    break
if S_N == 0:
    answer = "No"
else:
    if N%S_N == 0:
        answer = "Yes"
    else:
        answer = "No"
print(answer)


Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
//#define int long long
using namespace std;
#define loop(n) for(int i=0;i<n;i++)
#define endl '\n'
#define OnlineJudgec
#define F first
#define S second
#define  precision(n)  cout << fixed << setprecision(n)
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef vector<int> vi;
void init()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    cout.tie(0);
    #ifdef OnlineJudge
    freopen("commandos.in","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
}
ll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.
ll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}
ll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}
int * LIS_Lengths(vector<int> a) { int* lis = new int[a.size()];int b[a.size()];int maxLength = 1, lowerBound;lis[0] = 1, b[0] = a[0];for (size_t i = 1; i < a.size(); i++) {lowerBound = lower_bound(b, b + maxLength, a[i]) - b;lis[i] = lowerBound + 1;if (lowerBound == maxLength)    b[maxLength++] = a[i];else    b[lowerBound] = a[i];}return lis;}
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dr[] = {0,0,0,1,1,1,-1,-1,-1};
int dc[] ={-1,0,1,-1,0,1,-1,0,1};
/// <<------------------------------------------------------------------------------>>
int n , W;
ll dp[105][100009];
ll w [105],v[105];
ll solve(int i , ll val)
{
    if(i == n)
    {
        if(!val)
            return 0;
        return 1e15;
    }
    ll &rst = dp[i][val];
    if(~rst)
        return rst;
    rst = 1e15;
    if(val - v[i] >= 0)
    {
        rst = min(rst, w[i] + solve(i+1 , val - v[i]));
    }
    rst = min(rst, solve(i+1,val));
    return rst;
}
/// <<------------------------------------------------------------------------------>>
int main()
{
    init();
    cin >> n >> W;
    clr(dp,-1);
    loop(n)
    {
        cin >> w[i] >> v[i];
    }
    for(int i = 100000 ;i >= 0 ;i--)
    {
        ll ans = solve(0,i);
        if(ans <= W)
        {
            cout<<i;
            exit(0);
        }
    }
}


Measured memory_bytes: 82304
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  ll N;
  vector<ll> capacity(5);
  cin >> N;
  for(int i=0; i<5; i++)
    cin >> capacity[i];
  vector<ll>::iterator min_itr = min_element(capacity.begin(), capacity.end());
  ll min_cap = *min_itr;
  ll num = (ll)ceil(1.0 * N / min_cap);
  ll ans = (min_itr - capacity.begin()) + num + (capacity.end() - 1 - min_itr);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
blues=[]
for i in range(n):
    blues.append(input())
m=int(input())
reds=[]
for i in range(m):
    reds.append(input())
m=0
for blue in blues:
    x=blues.count(blue)-reds.count(blue)
    m=max(m,x)
print(m)

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

int main(){
        int n, m, ans=0;
        scanf("%d %d", &n, &m);
        vector<vector<vector<int>>> g(m, vector<vector<int>>(n));
        for(int i=0; i<m; i++){
                int a, b;
                scanf("%d %d", &a, &b);
                for(int j=0; j<m; j++){
                        if(i!=j){
                                g[j][a-1].push_back(b-1);
                                g[j][b-1].push_back(a-1);
                        }
                }
        }

        for(int i=0; i<m; i++){
                vector<bool> used(n);
                for(bool f: used) f=false;
                queue<int> que;
                que.push(0);
                while(!que.empty()){
                        int m = que.front();
                        que.pop();
                        used[m] = true;
                        for(int v: g[i][m]){
                                if(!used[v]) que.push(v);
                        }
                }
                if(!all_of(used.begin(), used.end(), [](bool i){return i;})) ans++;
        }
        printf("%d\n", ans);
        return 0;
}

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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  int r=min(n,k);
  int ans=-1001001001;
  rep(i,r+1){
    rep(j,i+1){
      priority_queue<int, vector<int>, greater<int>> q;
      rep(x,j){
        q.push(a[x]);
      }
      rep(y,i-j){
        q.push(a[n-1-y]);
      }
      int p=k-i;
      while(p--){
        if(q.size()&&q.top()<0){
          q.pop();
        }
      }
      int now=0;
      while(!q.empty()){
        now+=q.top();q.pop();
      }
      ans=max(ans,now);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;
  public class Main {
    public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      String N = scan.next();
      String M = "";
      int cnt = 0;
      for(int i=N.length(); i>0; i--){
        M = N.substring(i-1,i);
        cnt += Integer.parseInt(M);
      }
      if(cnt%9==0){
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }

Measured memory_bytes: 49596
x, y = map(int, input().split())
G = {1: 1, 2: 3, 3: 1, 4: 2, 5: 1, 6: 2, 7: 1, 8: 1, 9: 2, 10: 1, 11: 2, 12: 1}
print('Yes' if G[x] == G[y] else 'No')


Measured memory_bytes: 2940
using System;
using System.Linq;

namespace ALDS1_1
{
    class Program
    {
        private static string Join(int[] a)
        {
            var r = "";
            for(int i = 0; i < a.Length; i++)
            {
                r += a[i].ToString();
                if(i != a.Length - 1) r += ' ';
            }
            return r;
        }

        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            for(int i = 0; i < n; i++)
            {
                int v = a[i], j = i - 1;
                while (j >= 0 && a[j] > v)
                {
                    a[j + 1] = a[j--];
                    a[j + 1] = v;
                }
                Console.WriteLine(Join(a));
            }
        }
    }
}

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

int main() {
   int n;
   cin >> n;
   int a[n];
   for (int i=0; i<n; i++) {
       cin >> a[i];
   }
   sort(a,a+n);
   int m=a[n-1];
   if (m%2==0) {
       int count=m,b=a[0];
       for (int i=0; i<n-1; i++) {
           if (count>abs(a[i]-m/2)) {
               count=abs(a[i]-m/2);b=a[i];
           }
       }
       cout << m << " " << b << endl;
   }
   else {
       int count=m,b=a[0];
       for (int i=0; i<n-1; i++) {
           if (count>min(abs(a[i]-(m-1)/2),abs(a[i]-(m+1)/2))) {
               count=min(abs(a[i]-(m-1)/2),abs(a[i]-(m+1)/2));b=a[i];
           }
       }
       cout << m << " " << b << endl;
   }
}

Measured memory_bytes: 3936
N = int(input())
S = "A" + input()
r, g, b = 0, 0, 0

for s in S[1:]:
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1

pat = r*g*b

for i in range(1, N-1):
    for j in range(i+1, N):
        k = 2*j - i
        if (j+1 <= k <= N) and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            pat -= 1

print(pat)



Measured memory_bytes: 73724
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    string s; cin >> s;
    for(auto &x : s){
        if(x == ',') x = ' ';
    }

    cout << s << endl;

return 0;
}

Measured memory_bytes: 3576
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;
int main()
{
	long long n,max1=-100,max2=-100,i;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=n-1;i>=0;i--)
	{
		if(a[i]==a[i-1])
		{
			max1=a[i];
			break;
		}
	}
	for(i-=2;i>=0;i--)
	{
		if(a[i]==a[i-1])
		{
			max2=a[i];
			break;
		}
	}
	if(max1==-100||max2==-100)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<max1*max2<<endl;
	}
	return 0;
}

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

const int INF=0x3f3f3f3f;
const int MN=12;
const int MM=1005;

int dp[(1<<MN)+5];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int a,b,ci,c;
	int mask=(1<<n)-1;
	memset(dp,INF,sizeof(dp));
	dp[0]=0;
	int ans=INF;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		c=0;
		for(int j=0;j<b;j++)
		{
			scanf("%d",&ci);
			c|=1<<(ci-1);
		}
		for(int j=mask;j>=0;j--)
			dp[j|c]=min(dp[j|c],dp[j]+a);
		ans=min(ans,dp[mask]);
	}
	printf("%d\n",ans>=INF?-1:ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump_line(int *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

ll mypow(ll x,ll n){
	if(n==0) return 1;
	ll res=mypow(x*x,n/2);
	if(n&1) res=res*x;
	return res;
}

ll mod_pow(ll x,ll n,ll mod){
	if(n==0) return 1;
	ll res=mod_pow(x*x%mod,n/2,mod);
	if(n&1) res=res*x%mod;
	return res;
}

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

	int n,a,b;
	cin >> n >> a >> b;
	
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	sort(v.rbegin(),v.rend());
	
	ll head = v[0];
	ll sum=head;
	int num=1;
	int r=0;
	bool single=true;
	for(int i=1;i<n;i++){
		if(i >= a){
			int j=i;
			while(v[j++]==head){
				num++;
				r++;
			}
			ll c=1;
			ll sc=0;
			if(single){
				for(int j=1;j<a;j++){
					c*=num-(j-1);
					c/=j;
		//			cout << c << "\n";
				}
				for(int j=a;j<=min(num,b);j++){
					c*=num-(j-1);
					c/=j;
					sc += c;
		//			cout << c << "\n";
				}
				//iCa ~ iCmin(i,b)
				cout << head << "\n" << sc << "\n";
			}
			else{
				for(int j=1;j<=num-r;j++){
					c*=num-(j-1);
					c/=j;
				}
		//		cout << "ans2\n" << sum/(double)i << "\n" << c << "\n";
				printf("%lf\n%ld\n",sum/(double)i,c);
				//numC(num-r)
			}
		//	cout << "num " << num << "\n";
			return 0;
		}
		if(v[i] == head){
			num++;
		}
		else{
			single=false;
			head = v[i];
			num = 1;
		}
		sum+=head;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;

int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if(s==u) a--;
	else b--;
	cout << a << ' ' << b; 
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long A, long long B, long long C, long long X, long long Y) {
  ll ans = INF;
  rep(c, 0, 2 * max(X, Y) + 1) {
    ll tmp = C * c;
    tmp += max(0ll, X - c / 2) * A;
    tmp += max(0ll, Y - c / 2) * B;
    ans = min(ans, tmp);
  }
  print(ans);
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long X;
  scanf("%lld", &X);
  long long Y;
  scanf("%lld", &Y);
  solve(A, B, C, X, Y);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, W, weight[101];
long long v[101],dp[101][100001];

int main(){
  cin >> N >> W;
  for(int i = 1; i <= N; i++){
    cin >> weight[i] >> v[i];
  }
  for(int w = 0; w <= W; w++)
    dp[0][w] = 0;
  for(int i = 0; i <= N; i++)
    dp[i][0] = 0;
  for(int i = 1; i <= N; i++){
    for(int w = 0; w <= W; w++){
      if(weight[i] <= w){
        dp[i][w] = max(dp[i-1][w], dp[i-1][w - weight[i]] + v[i]);
      }
      else{
        dp[i][w] = dp[i-1][w];
      }
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 79104
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int c[10005];

ll p[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  string s;
  cin>>n>>m>>s;
  if(m==2||m==5){
    ll ret = 0;
    for(int i=0;i<n;i++){
      if((s[i]-'0')%m==0){
        ret+=i+1;
      }
    }
    cout<<ret<<endl;
    return 0;
  }
  p[0]=1;
  for(int i=1;i<=n;i++)p[i] = p[i-1] * 10 %m;
  ll cur = 0;
  for(int i=n-1;i>=0;i--){
    cur = (cur + (s[i]-'0')*p[n-1-i]%m)%m;
    c[cur]++;
  }
  cur = 0;
  ll ret = 0;
  for(int i=n-1;i>=0;i--){
    ret += c[cur];
    cur = (cur + (s[i]-'0')*p[n-1-i]%m)%m;
    c[cur]--;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
const int MOD = 1e9 + 7;
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n+2);
    v[0] = v[n+1] = 0;
    rep(i,n) cin >> v[i+1];
    
    int ans = 0;
    reps(left,0,n)reps(right,left+1,n+1){
        const int JEWELS = left + n+1-right;
        if(JEWELS > k) continue;
        
        priority_queue<int, vector<int>, greater<>> q;
        int value = 0;
        
        for(int i = 0; i <= left; i++){
            value += v[i];
            q.push(v[i]);
        }
        for(int i = n+1; i >= right; i--){
            value += v[i];
            q.push(v[i]);
        }
        
        rep(i,k-JEWELS){
            if(q.empty()) break;
            if(q.top() >= 0) break;
            value -= q.top();
            q.pop();
        }
        
        ans = max(ans, value);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, K = read_h()
    A = read_h()

    cnt = [0] * (N + 1)
    for a in A:
        cnt[a] += 1

    ans = sum(sorted(cnt, reverse=True)[K:])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24740
program ABC176C
    implicit none
    integer(8)::N,ans=0,i
    integer(8),allocatable::A(:)
    read*,N
    allocate(A(N))
    read*,A
    do i=2,N
        if(A(i)<A(i-1))then
            ans=ans+A(i-1)-A(i)
            A(i)=A(i-1)
        end if
    end do

    print'(i0)',ans
end program ABC176C

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    if(n%1000 == 0)cout << 0 << endl;
    else cout << 1000 - (n%1000) << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
typedef long long ll;
#define M 998244353
using namespace std;
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Function to find gcd of array of 
// numbers  
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
ll k;
cin>>k;
ll s=0;
for(ll i=1;i<=k;i++)
{
if(i%3==0||i%5==0)
	continue;
s+=i;
}
cout<<s<<"\n";
return 0;
}

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

pair<pair<string, int>, int> p[110];

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

	for (int i = 0; i < N; i++) {
		string S;
		int P;
		cin >> S >> P;

		p[i] = make_pair(make_pair(S, -P), i + 1);
	}

	sort(p, p + N);

	for (int i = 0; i < N; i++){
		cout << p[i].second << endl;
	}

}

Measured memory_bytes: 3568
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){

  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double x;
  x = abs(M_PI*h/6.0+(M_PI/6.0)*m/60.0 - (2.0*M_PI)*m/60.0);
  x = min(2.0*M_PI-x, x);

  std::cout << std::setprecision(20) <<sqrt(a*a + b*b - 2.0*a*b*cos(x))<<endl;
 return 0;
}

Measured memory_bytes: 4236
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main(){
    
    N := nextInt()
    H := nextInt()
    W := nextInt()
    
    fmt.Println((N-H+1)*(N-W+1))
}

// nとiからdigitSumを計算し、sと一致するかチェックする
func chk(n, i, s int64) bool{
    digitSum := int64(0)
    x := n
	for x > 0 {
		digitSum += x%i
		x /= i
	}
	return digitSum == s
}
 
/* templates */


func Max(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r < a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Min(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r > a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Sum(a []int) (r int) {
    for i := range a {
        r += a[i]
    }
    return r
}
 
func Abs(a float64) float64 {
    if a < 0 {
        return -a
    }
    return a
}
 
type Pair struct {
    a, b int
}
 
type Pairs []Pair
 
func (p Pairs) Len() int {
    return len(p)
}
 
func (p Pairs) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}
 
func (p Pairs) Less(i, j int) bool {
    return p[i].b < p[j].b
}
 
var nextReader func() string
 
func init() {
    nextReader = NewScanner()
}
 
func NewScanner() func() string {
    r := bufio.NewScanner(os.Stdin)
    r.Buffer(make([]byte, 1024), int(1e+11))
    r.Split(bufio.ScanWords)
    return func() string {
        r.Scan()
        return r.Text()
    }
}

func nextString() string {
    return nextReader()
}
 
func nextInt64() int64 {
    v, _ := strconv.ParseInt(nextReader(), 10, 64)
    return v
}
 
func nextInt() int {
    v, _ := strconv.Atoi(nextReader())
    return v
}
 
func nextInts(n int) []int {
    r := make([]int, n)
    for i := 0; i < n; i++ {
        r[i] = nextInt()
    }
    return r
}

func nextStrings(n int) []string {
    r := make([]string, n)
    for i := 0; i < n; i++ {
        r[i] = nextString()
    }
    return r
}

func nextFloat64() float64 {
    f, _ := strconv.ParseFloat(nextReader(), 64)
    return f
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#define inf -2147483647
using namespace std;
struct info
{
    int l,r,d;
}s[400005];
int n,m;
int flag = 1;
int dis[100005],visited[100005];
int first[400005],nexti[400005];
void dfs(int t)
{
    if(!flag)return;
    int k = first[t];
    while(k != -1)
    {
        if(!flag)return;
        if(!visited[s[k].r])
        {
            dis[s[k].r] = dis[s[k].l] + s[k].d;
            visited[s[k].r] = 1;
            dfs(s[k].r);
        }
        else if(s[k].d != dis[s[k].r] - dis[s[k].l])
        {
            flag = 0;
            return;
        }
        k = nexti[k];
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    memset(first,-1,sizeof(first));
    memset(dis,2000000000,sizeof(dis));
    for(int i = 0;i < m;i ++)
    {
        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);
        nexti[i] = first[s[i].l];
        first[s[i].l] = i;
        s[i + m].r = s[i].l;
        s[i + m].l = s[i].r;
        s[i + m].d = -s[i].d;
        nexti[i + m] = first[s[i + m].l];
        first[s[i + m].l] = i + m;
    }
    for(int i = 1;i <= n;i ++)
    {
        if(!visited[i])
        {
            visited[i] = 1;
            dfs(i);
        }
    }
    if(flag)printf("Yes");
    else printf("No");
}


Measured memory_bytes: 9728
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  vector<vector<int>> dp(N + 1, vector<int>(3));
  dp[0][0] = 0, dp[0][1] = 0, dp[0][2] = 0;

  for (int i = 0; i < N; ++i) {
    int a, b, c; cin >> a >> b >> c;
    dp[i + 1][0] = a + max(dp[i][1], dp[i][2]);
    dp[i + 1][1] = b + max(dp[i][2], dp[i][0]);
    dp[i + 1][2] = c + max(dp[i][0], dp[i][1]);
  }
  cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
}


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

int main(void){
    int N;
    cin >> N;
    int d = 0;
    for(int i = 1; i <= N; i = i + 2){
        int c = 0;
        for(int j = 1; j <=i; j++){
            if(i % j == 0){
                c++;
            }
        }
        if(c == 8){
            d++;
        }
    }
    cout << d << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  int num=0;
  for(int i=0;i<4;i++){
    if(s[i]=='+') num++;
    if(s[i]=='-') num--;
  }
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int n = sc.nextInt();

		String a[] = new String[S.length()];

		for(int i=0;i<S.length();i++) {
			a[i] = S.substring(i, i+1);
		}

		int m = 0;
		String sum = "";

		while(m < S.length()) {
			sum = sum + a[m];
			m = m + n;
		}

		System.out.println(sum);


	}
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
# define write1 { puts("Yes"); return 0;}
# define write2 { puts("No"); return 0;}
# define INF 100000000
using namespace std;
int n, sum, minn = INF, maxn = -INF;
int a[110000];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		maxn = max(maxn, a[i]);
		minn = min(minn, a[i]);
	}
	if (maxn - minn >= 2) write2
	if (maxn == minn)
	{
		if (maxn == n - 1) write1
		if (maxn * 2 <= n) write1
		else write2
	}
	for (int i = 1; i <= n; i++) if (a[i] == minn) ++sum;
	if (minn < sum) write2
	if (n - sum < 2 * (maxn - sum)) write2
	else write1
	return 0;
}


Measured memory_bytes: 640
n, w = map(int, input().split())
weight = []
value = []

for i in range(n):
    x, y = map(int, input().split())
    weight.append(x)
    value.append(y)



#dp[i][j] i番目までの品物から価値がjを達成するように選んだときの重さの最小値を保存
dp = [[10 ** 9 + 7 for i in range(sum(value) + 1)] for j in range(n + 1)]

dp[0][0] = 0

for i in range(n):
    for j in range(sum(value) + 1):
        # j -> now value
        if j - value[i] >= 0:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i])

        else:
            dp[i + 1][j] = dp[i][j]

a = sorted(range(sum(value) + 1), reverse = True)

for i in a:
    if dp[n][i] <= w:
        print(i)
        break


Measured memory_bytes: 167728
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    bool flag = true;
    if(s[0] != 'A')
    {
        flag = false;
    }
    int c_count = 0,cap_count = 0;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] >= 'A' && s[i] <= 'Z')
        {
            cap_count++;
        }
        if(i >= 2 && i < s.size() - 1 && s[i] == 'C')
        {
            c_count++;
        }
    }
    if(c_count == 0 || c_count >= 2 || cap_count == 0 || cap_count > 2)
    {
        flag = false;
    }
    if(flag)
    {
        cout << "AC";
    }
    else
    {
        cout << "WA";
    }
    
    return 0;
}

Measured memory_bytes: 256