akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0 };
		while (n-- > 0) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a > b && a < 6) {
				a = 15 - a;
			}
			while (true) {
				System.out.print(x[a]);
				if (x[a] == b) {
					break;
				}
				System.out.print(' ');
				if (a == x.length - 1) {
					a = 1;
				} else {
					a++;
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 17184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
  ll N;
  cin>>N;
  string A[N+1];
  string M="MARCH";
  ll X[6]={0};
  rep(i,N){
    cin>>A[i];
    rep(j,5) if(A[i][0]==M[j]) X[j]++;
  }
  ll ans=0;
  rep(i,3) rep(j,3-i) rep(k,3-i-j) ans+=X[i]*X[i+j+1]*X[i+j+k+2];
  cout<<ans<<endl;
}

Measured memory_bytes: 6144
n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]

p=[0]*(n+1)
for i in a:
    p[i]+=1

for i in range(1,n+1):
    if(k-q+p[i] > 0):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8636
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
    string N;   cin >> N;
    int L = N.size();
    reverse(N.begin(), N.end());
    vector<int> a(L + 2);
    for (int i = 0; i < L; i++) {
        a[i] = N[i] - '0';
        //printf("a[%d]=%d ", i, a[i]);
    }

    vector<int> dp(L + 1);
    for (int i = 0; i <= L; i++) {
        if (a[i] < 5) dp[i] = a[i];
        else if (a[i] == 5) {
            dp[i] = 5;
            if (a[i + 1] >= 5) a[i + 1]++;           
        }
        else {
            dp[i] = 10 - a[i];
            a[i + 1]++;
            //a[i + 1] %= 10;
        }
    }
    /*
    cout << endl << 0;
    for (int i = L - 1; i >= 0; i--) {
        cout << N[i];
    }
    cout << endl;
    */
    ll ans = 0;
    for (int i = L; i >= 0; i--) {
        //cout << dp[i];
        ans += dp[i];
    }

    //cout << endl;
    cout << ans << endl;
}


Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  // int numPd = count(s.cbegin(), s.cend(), 'PD');
  // int numD = count(s.cbegin(), s.cend(), 'D');
  // int numQ = count(s.cbegin(), s.cend(), '?');
  // cout << numPd + numD + numQ << endl;
  cout << regex_replace(s, regex("\\?"), "D") << endl;
}

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

using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    map<char, int> a;
    if(s.length() < 26){
        for(int i = 0; i < s.length(); i++){
            a[s[i]]++;
        }
        for(int i = 0; i < 26; i++){
            if(a['a' + i] == 0){
                char b = 'a' + i;
                cout << s + b << endl;
                return 0;
            }
        }
    }else{
        for(int i = s.length()-1; i > 0; i--){
            if(s[i] > s[i-1]){
                for(int j = 0; j <= i-1; j++){
                    a[s[j]]++;
                }

                for(int j = 0; j < 26; j++){
                    if(a['a' + j] == 0 && 'a' + j > s[i-1]){
                        char b = 'a' + j;
                        for(int k = 0; k < i-1; k++){
                            cout << s[k];
                        }
                        cout << b << endl;
                        return 0;
                    }
                }
            }
        }
        cout << -1 << endl;
    }
    return 0;
}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

 
int main() {
  int n, ans=0;
  cin >> n;
  VI p(n);
  REP(i,n) {
    cin >> p.at(i);
  }
  REP(i,n-2) {
    int a = p.at(i)-p.at(i+1);
    int b = p.at(i+2) - p.at(i+1);
    if(a*b < 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>
#include <utility>
#include <map>
#include <set>
using namespace std;

int r, d, x;


int main() {

	cin >> r >> d >> x;

	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}


	return 0;
}

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

typedef unsigned long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;
    vector<ll> B(N);
    ll prev = INT_MAX;
    ll total = 0;

    REP(i,N-1){
       ll b;
       cin >> b;
       if( prev > b ){
          total += b;
       }else{
          total += prev;
       }
       prev = b;
    }

    total += prev;
    cout << total << endl;
}


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

bool betemp(string sleft, string sright, int left, int right) {
    if (sleft == sright)
        return (right - left) % 2 == 1;
    else
        return (right - left) % 2 == 0;
}

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

    string vac = "Vacant";
    string sleft, sright, str;
    int left = 0, right = N / 2;

    cout << left << endl;
    cin >> sleft;
    if (sleft == vac) return 0;
    cout << right << endl;
    cin >> sright;
    if (sright == vac) return 0;

    if (!betemp(sleft, sright, left, right)) {
        swap(sleft, sright), left = right, right = N;
    }

    while (right - left > 1) {
        int mid = (left + right) / 2;
        cout << mid << endl;
        cin >> str;
        if (str == vac) return 0;
        if (betemp(sleft, str, left, mid)) {
            sright = str, right = mid;
        } else {
            sleft = str, left = mid;
        }
    }
}

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

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const int INF=1e9;
const double eps=0.0000000001;



int main(){
  int h,w;
  cin >> h >>w;
  int n;
  cin >> n;
  int a[100000];
  int cnt=0;
  int d[100000];
  FOR(i,n){
    cin >> a[i];
    FOR(j,a[i]){
      d[cnt]=i+1;
      cnt++;
    }
  }
  cnt=0;
  int ans[1000][1000];
  FOR(i,h){
    if(i%2==0){
      for(int j=0;j<w;j++){
        ans[i][j]=d[cnt];
        cnt++;
      }
    }else{
      for(int j=w-1;j>=0;j--){
        ans[i][j]=d[cnt];
        cnt++;
      }
    }
  }

  FOR(i,h){
    FOR(j,w){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  
  
}

Measured memory_bytes: 2432
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    A, B, C, X, Y = map(int, input().split())

    ans = float('inf')
    for i in range(0, max(X, Y)*2+1, 2):
        ans = min(A*max(X-i//2, 0)+B*max(Y-i//2, 0)+C*i, ans)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if(a%b==0) return b;
  else if(a<b) return gcd(b,a);
  else return gcd(b,a-a/b*b);
}

int gcd(int a, int b, int c){
  return gcd(gcd(a,b),c);
}
int main(){
  int K; cin >> K;
  int64_t ans = 0;
  for(int i=1; i<=K; i++){
    for(int j=1; j<=K; j++){
      for(int k=1; k<=K; k++){
        ans += gcd(i,j,k);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
program ABC081C
    implicit none
    integer(8)::N,K,val_count=0,i,ans=0
    integer(8),allocatable::A(:),C(:)
    read*,N,K
    allocate(A(N))
    allocate(C(N))
    read*,A
    C=0
    do i=1,N
        if(C(A(i))==0)val_count=val_count+1
        C(A(i))=C(A(i))+1
    end do

    if(val_count<=K)then
        print'(i0)',0
    else
        val_count=val_count-K
        call heapsort(N,C)
        do i=1,N
            if(val_count==0)exit
            if(C(i)>0)then
                ans=ans+C(i)
                val_count=val_count-1
            end if
        end do
        print'(i0)',ans
    end if
end program ABC081C

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
end subroutine heapsort

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

/*

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] fruits = new int[n];

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

        Arrays.sort(fruits);

        int ans = 0;

        for (int i = 0; i < k; i++) {
            ans += fruits[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 38712
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e9;
int n,m;
int dp[1001][(1<<12)];
int key[1001];
int cost[1001];
int main(){
    cin >> n >> m;
    int a,b,c;
    rep(i,m+1)rep(j,(1<<12)) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,m){
        cin >> a >> b;
        int can = 0;
        rep(j,b){
            cin >> c;
            c--;
            can = (1<<c)|can;
        }
        key[i] = can;
        cost[i] = a;
    }
    rep(i,m){
        rep(j,(1<<n)){
            chmin(dp[i][j|key[i]],dp[i][j]+cost[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    if (dp[m][(1<<n)-1] == INF) PRINT(-1);
    else PRINT(dp[m][(1<<n)-1]);
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define PII pair<int,int>
#define X first
#define Y second
#define MP make_pair
#define PI acos(-1.0)
#define eps 1e-8
const int maxn=3e5+10;
const int mod=1e9+7;
using namespace std;

int n;
ll dp[maxn],sz[maxn],ans[maxn],facn=1;
vector<int>g[maxn];

ll qpow(ll a,ll b)
{
    long long ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans;
}

void dfs1(int x,int pre)
{
    sz[x]=dp[x]=1;
    for(int i=0;i<g[x].size();i++)
    {
        int y=g[x][i];
        if(y!=pre)
        {
            dfs1(y,x);
            sz[x]+=sz[y];
            dp[x]=dp[x]*dp[y]%mod;
        }
    }
    dp[x]=dp[x]*sz[x]%mod;
}

void dfs2(int x,int pre)
{
    ll tmp=1;
    for(int i=0;i<g[x].size();i++)
    {
        int y=g[x][i];
        if(y!=pre)
        {
            tmp=tmp*dp[y]%mod;
        }
    }
    if(x!=1)
        dp[x]=tmp*dp[pre]%mod*(n-sz[x])%mod*qpow(dp[x],mod-2)%mod;
    // printf("%d %d\n",x,dp[x]);
    ans[x]=qpow(dp[x],mod-2)*facn%mod;
    for(int i=0;i<g[x].size();i++)
    {
        int y=g[x][i];
        if(y!=pre)
        {
            // tmp+=dp[y];
            dfs2(y,x);
        }
    }
    
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) facn=facn*i%mod;
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs1(1,0);
    dfs2(1,0);

    for(int i=1;i<=n;i++)
        printf("%lld\n",ans[i]);
    // system("pause");
    return 0;
}

Measured memory_bytes: 22516
n = int(input())
alist = []
for i in range(n):
    alist.append(int(input()))
mod = 998244353
asum = sum(alist)


asum_half = (asum + 1) // 2
dp = [[0] * (asum_half + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
    for j in range(asum_half + 1):
        inext = i + 1
        dp[inext][j] = (dp[inext][j] + dp[i][j] * 2) % mod
        jsum = min(j + alist[i], asum_half)
        dp[inext][jsum] = (dp[inext][jsum] + dp[i][j]) % mod
dp_sum = dp[n][asum_half] % mod
dp_sum *= 3
dp_sum = dp_sum % mod


dp_dup = [[0] * (asum_half + 1) for _ in range(n + 1)]
dp_dup[0][0] = 1
if asum % 2 == 0:
    for i in range(n):
        for j in range(asum_half + 1):
            inext = i + 1
            dp_dup[inext][j] = (dp_dup[inext][j] + dp_dup[i][j]) % mod
            jsum = j + alist[i]
            if jsum > asum_half:
                continue
            dp_dup[inext][jsum] = (dp_dup[inext][jsum] + dp_dup[i][j]) % mod
dp_dup_sum = dp_dup[n][asum_half]
dp_dup_sum *= 3
dp_dup_sum = dp_dup_sum % mod


ans = pow(3, n, mod)
ans -= dp_sum
ans += dp_dup_sum

print(ans % mod)


Measured memory_bytes: 245256
N, K = map(int, input().split())
S = input()

s = []

cnt = 1
current = S[0]

for i in range(1, N):
    if S[i] == current:
        cnt += 1
    else:
        current = S[i]
        s += [cnt]
        cnt = 1
s += [cnt]

# k: K=∞のときの反転可能回数
if S[0] == '0':
    k = (len(s)+1)//2
else:
    k = len(s)//2

if k <= K:
    print(N)
    
else:
    
    n = len(s)
    
    first = 0
    if S[0] == '0':
        end = K*2
    else:
        end = K*2+1
    m = sum(s[first:end])
    current = m
    
    if S[0] == '0':
        first = 1
    else:
        first = 2
    end += 2
    
    while(end < n):
        current = current - s[first-1] + s[end-2] + s[end-1]
        if first != 1:
            current -= s[first-2]
            
        if m < current:
            m = current
        first += 2
        end += 2
        
    current = sum(s[first:])
    if m < current:
        m = current
        
    print(m)

Measured memory_bytes: 4560
#import sys
#input = sys.stdin.readline
def main():
    N, X = map( int, input().split())
    L = list( map( int, input().split()))
    ans = 1
    now = 0
    for i in range(N):
        now += L[i]
        if now > X:
            break
        ans += 1
    print(ans)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define INF INT_MAX
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll dp[100006];
ll a[100006];
ll n;
ll rec(ll idx)
{
	
	if(idx==n-1)return 0;
	if(dp[idx]!=-1)return dp[idx];
	ll ans=0;
	if(idx<n-2)
	{
		ans=min(abs(a[idx]-a[idx+1])+rec(idx+1),abs(a[idx]-a[idx+2])+rec(idx+2));
	}
	else ans=abs(a[idx]-a[idx+1])+rec(idx+1);
	return dp[idx]=ans;
}
int main()
{
	chutiyaap;
	cin>>n;
	for(ll i=0;i<n;i++)cin>>a[i];
	memset(dp,-1,sizeof(dp));
	cout<<rec(0);
}


Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Factorial II
 */
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			if (n == 0) {
				break;
			}

			int five = 0;
			for (int i = 5; i < n + 1; i += 5) {
				int j = i;
				while (j % 5 == 0) {
					five++;
					j /= 5;
				}
			}
			System.out.println(five);
		}
	}
}

Measured memory_bytes: 16860
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

def main():
    A,B = map(int,input().split())
    if A < 10 and B < 10:
        print(A*B)
    else:
        print(-1)

if __name__ == "__main__":
    main()

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

int d[10][10], dd[10], H;
int main()
{
  while(true)
  {
    cin >> H;
    if(!H)
      break;
    for(int i = 0; i < H; i++)
      for(int j = 0; j < 5; j++)
        cin >> d[i][j];
    bool f = true;
    int p = 0;
    while(f)
    {
      f = false;
      for(int i = 0; i < 10; i++)
        dd[i] = 0;

      for(int y = 0; y < H; y++)
      {
        int n = 0;
        for(int x = 0; x < 3; x++)
          if(d[y][x] && d[y][x] == d[y][x + 1] && d[y][x + 1] == d[y][x + 2])
            n = x + 2;
        if(n > 0)
        {
          f = true;
          for(int x = n; x >= 0; x--)
          {
            p += d[y][x];
            int tmp = d[y][x];
            d[y][x] = 0;
            if(x == 0 || tmp != d[y][x - 1])
              break;
          }
        }
      }

      for(int y = H - 1; y >= 0; y--)
      {
        for(int x = 0; x < 5; x++)
        {
          if(!d[y - dd[x]][x])
            for(; y - dd[x] >= 0 && !d[y - dd[x]][x]; dd[x]++);
          d[y][x] = d[max(0, y - dd[x])][x];
        }
      }
      for(int x = 0; x < 5; x++)
        for(int y = 0; y < dd[x]; y++)
          d[y][x] = 0;
    }
    cout << p << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define INF 1e9
#define MOD 1000000007
#define All(x) (x).begin(),(x).end()
#define Cout(x) cout << (x) << endl
typedef long long ll;
using namespace std;

int main(void){
  int N;cin>>N;
  ll ans=0;
  vector<vector<int>> C(10,vector<int>(10,0));
  for(int i=1;i<=N;i++){
    string c=to_string(i);
    C[c[0]-'0'][c[c.size()-1]-'0']++;
  }
  REP(i,10){
    REP(j,10){
      ans+=C[i][j]*C[j][i];
    }
  }
  cout<<ans<<endl;
}








Measured memory_bytes: 256
//49
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  bool c[3]={true};
  for(char f,t;(cin>>f).ignore()>>t;){
    swap(c[f-'A'],c[t-'A']);
  }
  cout<<char(find(c,c+3,true)-c+'A')<<endl;
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

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

        int x = sc.nextInt();
        int t = sc.nextInt();

        int ret = -1;

        if ( x < t ) {
            ret = 0;
        } else {
            ret = x - t;
        }

        System.out.println( ret );
    }

}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[200010], n;
map<int, ll> mem[200010];
ll dp(int x, int nm){
	if(nm==1){
		if(x>=n)
			return -1e17;
		return a[x];
	}
	if(n-x<(nm-1)*2+1){
		return -1e17;
	}
	if(mem[x].count(nm)){
		return mem[x][nm];
	}
	ll res=a[x];
	res=a[x]+dp(x+2, nm-1);
	// if((n-x-2)>2*(nm-1)){
		res=max(res, a[x]+dp(x+3, nm-1));
	// }
	mem[x][nm]=res;
	return res;
}
int main(){
    while(cin>>n){
        ll ans=0;
        for(int i=0; i<n; ++i){
        	mem[i].clear();
            scanf("%d",a+i);
        }
        ans=max(dp(0, n/2), dp(1, n/2));
        ans=max(ans, dp(2, n/2));
        printf("%lld\n",ans);
    }
  return 0;
}




Measured memory_bytes: 43604
#include<stdio.h>
int main(){
  char a[100],b[100],c[100];
  scanf("%s %s %s",&a,&b,&c);
  if(b[0] == a[strlen(a) - 1] && c[0] == b[strlen(b) - 1]){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}

Measured memory_bytes: 128
/***
 ** " In order to be irreplaceable, one must always be different "
 **     -- Coco Chanel
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: __________
  *  Date:   13.04.2020
  *  Time:   06:55:30
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif

#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int32_t main(int32_t argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","a",stderr);
    #endif
    
    fast;
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')
        puts("Yes");
    else
        puts("No");

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}

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

long long d = pow(10, 18);

int main() {
    ll n, ans = 1;
    cin >> n;
    ll a[100010];
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, n) {
        if (a[i] <= d / ans) {
            ans *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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


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

  if(s == "Sunny"){
    cout << "Cloudy" << endl;
  }else if(s == "Cloudy"){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }

}


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

int main(){
    //freopen("input.txt","r",stdin);
    vector<int> a(5);
    for(int i =0; i<5; i++){
        cin>>a[i];
    }
    int k; cin>>k;
    for(int i = 0; i<4; i++){
        for(int j =1; j<5; j++){
            if(abs(a[j] - a[i]) > k){
                cout<<":(";
                return 0;
            }
        }
    }
    cout<<"Yay!";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = [input() for _ in range(n)]
d = {}
for w in l:
  d[w] = d.get(w,0)+1
m = max(d.values())
lt = sorted(d.items(),key=lambda k:-k[1])
ans = sorted([k for k,v in lt if v==m])
print(*ans,sep='\n')

Measured memory_bytes: 49804
program BITEEATING;
var a:array[1..200] of integer;
    re,sum,i,n,l,k:integer;

begin 
	readln(n,l);
	sum:=0;
	for i:=1 to n do 
	  begin
	    a[i]:=l+i-1;
	    sum:=sum+a[i];
	  end;
	re:=30000; 
	for i:=1 to n do 
	  if re>abs(a[i]) then
	    begin
	      re:=abs(a[i]);
	      if a[i]>0 then k:=1 else k:=-1;
	    end;
	write(sum-re*k);
end.

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	int sum = q * 4 * n;
	sum = min(sum,h*2 * n);
	sum = min(sum, n*s);
	sum = min(sum, (n % 2 == 0 ? (d*(n / 2)) : (d*(n - 1) / 2) + min(s, min(h * 2, q * 4))));
	cout << sum << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<utility>
using namespace std;
int main(){
    int W,H,x0,y0;
    char t[20][20];
    bool visit[20][20];
    const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
    typedef pair<int,int>P;
    queue<P>Q;
    while(cin>>W>>H){
        if(W==0||H==0)break;
        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                cin>>t[i][j];
                if(t[i][j]=='@'){
                    x0=j;
                    y0=i;
                }
                visit[i][j]=true;
            }
        }
        int sum=0;
        Q.push(P(x0,y0));
        visit[y0][x0]=false;
        while(!Q.empty()){
            int srcx=Q.front().first;
            int srcy=Q.front().second;
            Q.pop();
            sum++;
            for(int i=0;i<4;++i){
                int curx=srcx+dx[i];
                int cury=srcy+dy[i];
                if(t[cury][curx]=='#') continue;
                if(curx<0||curx>=W||cury<0||cury>=H) continue;
                if(!visit[cury][curx]) continue;
                visit[cury][curx]=false;
                Q.push(P(curx,cury));
            }
            
        }
        cout<<sum<<endl;
    }
}

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

int main(){

    int x1, x2, x3, x4;
    int y1, y2, y3, y4;
    int sqx, sqy;

    cin >> x1 >> y1 >> x2 >> y2;

    sqx = x1-x2;

    sqy = y1-y2;
        
        x3 = x2 + sqy;
        y3 = y2 - sqx;
        x4 = x3 + sqx;
        y4 = y3 + sqy;
        

    cout << x3 << " " << y3 << " " << x4 << " " << y4 <<endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

// ------ main ------ //

int n, k, w[100000];

bool check(long long value)
{
	long long v = 0;

	int c = 0;

	for (int i = 0; i < n; i++)
	{
		if (c >= k) { return false; }

		if (v + w[i] > value)
		{
			v = 0;

			c++; i--;
		}
		else
		{
			v += w[i];
		}
	}

	if (c > n) { return false; }

	return true;
}

int main()
{
	cin >> n >> k;

	for (int i = 0; i < n; i++) { cin >> w[i]; }

	long long l = 0;
	long long r = (1LL << 60);
	long long m;

	while (r - l > 1)
	{
		m = (l + r) / 2;

		if (check(m) == true)
		{
			r = m;
		}
		else
		{
			l = m;
		}
	}

	cout << r << endl;

	return 0;
}

Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

ll comb(ll fac[], ll ifac[], int n, int k, ll m){
    ll c = fac[n];
    c *= ifac[n-k], c %= m;
    c *= ifac[k], c %= m;
    return c;
}

int main(){
    int N, K;
    cin >> N >> K;
    int a[K];
    rep(i, K) cin >> a[i];
    ll n = N, m = MOD, inv[n+1];
    rep2(i, 1, n){
        inv[i] = 1;
        ll e[31];
        e[0] = i;
        rep2(j, 1, 30) e[j] = (e[j-1]*e[j-1]) % m;
        ll k = m-2;
        int cnt = 0;
        while(k > 0){
            if(k % 2 == 1) inv[i] *= e[cnt], inv[i] %= m;
            k /= 2;
            cnt++;
        }
    }
    ll fac[n+1], ifac[n+1];
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, n){
        fac[i] = (fac[i-1]*i)%MOD;
        ifac[i] = (ifac[i-1]*inv[i])%MOD;
    }
    ll dp[K][N+1];
    rep(i, a[0]+1){
        dp[0][i] = fac[N];
        dp[0][i] *= comb(fac, ifac, N-i, a[0]-i, m);
        dp[0][i] %= m;
        dp[0][i] *= ifac[i], dp[0][i] %= m;
    }
    rep2(i, a[0]+1, N) dp[0][i] = 0;
    rep2(i, 1, K-1) rep(j, N+1){
        dp[i][j] = 0;
        int s = max(0, j-a[i]);
        rep2(k, s, j){
            ll x = j-k;
            ll tmp = dp[i-1][k];
            tmp *= comb(fac, ifac, N-x, a[i]-x, m);
            tmp %= m;
            tmp *= ifac[x], tmp %= m;
            dp[i][j] += tmp, dp[i][j] %= m;
        }
    }
    cout << dp[K-1][N] << endl;
}

Measured memory_bytes: 384
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=501;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b,c;
    a=read(), b=read(), c=read();
    if(c>=a&&c<=b) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#define INF 100000
using namespace std;
int a,b,d,cntA,cntB;

void cal(){
  for(int i=0;i<100000;i++){
    if((a*i)%b==d%b && cntA+cntB>i+abs((a*i)/b-d/b))cntA=i,cntB=abs((a*i)/b-d/b);
    if((b*i)%a==d%a && cntA+cntB>i+abs((b*i)/a-d/a))cntA=abs((b*i)/a-d/a),cntB=i;
  }
}

int main(){
  while(1){
    cin>>a>>b>>d;
    if(!a&&!b&&!d)break;
    cntA=cntB=INF;
    cal();
    cout <<cntA<<" "<<cntB<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	n := scanInt(sc)
	ts := nextIntSlice(sc, n)
	sum := 0
	for i := range loop0(n) {
		sum += ts[i]
	}
	m := scanInt(sc)
	rs := []int{}
	for _ = range loop0(m) {
		p, x := scanInt(sc), scanInt(sc)
		rs = append(rs, sum-ts[p-1]+x)
	}
	for _, v := range rs {
		fmt.Println(v)
	}
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop1(n int) chan int {
	return loop(1, n, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1836
# -*- coding: utf-8 -*-
    
from sys import stdin
    
n,x = [int(i) for i in stdin.readline().split()]
limit = int(x ** (1.0/n)) + 1
    
def devide_counter(x, p):
    count = 1
    x = x // p
    while x % p == 0:
        count += 1
        x = x // p
    return x, count
    
def factorize(x):
    ans = 1
    
    p = 2
    if x % p == 0:
        x, count = devide_counter(x, p)
        if count >= n:
            ans = ans * (p ** (count // n))
    
    for p in range(3, limit, 2):
        if x % p == 0:
            x, count = devide_counter(x, p)
            if count >= n:
                ans = ans * (p ** (count // n))
        if x < p * p:
            break
    return ans
    
if x == 1:
    print(1)
elif n == 1:
    print(x)
else:
    ans = factorize(x)
    print(ans)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scanf("%d %d %d", &A, &B, &C)

	l := 100*A + 10*B + C

	if l%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
typedef long long ll; 
const int N = 110;
struct node{
	ll x,y;
}r[N];
//ll nx[N];

bool cmp(node a,node b)
{
	return atan2(a.y,a.x)<atan2(b.y,b.x);
}
int main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++) cin>>r[i].x>>r[i].y;
	sort(r+1,r+n+1,cmp);
	ll nx[N];//用于循环 
	for(ll i=1;i<=n;i++) nx[i]=i+1;
	nx[n]=1;
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ll X=r[i].x,Y=r[i].y;
		ans=max(ans,X*X+Y*Y);
		for(ll j=nx[i];j!=i;j=nx[j])
		{
			X+=r[j].x;
			Y+=r[j].y;
			ans=max(ans,X*X+Y*Y);
		}
	}
	printf("%.10lf\n",sqrt(ans));
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		double ans = 0;
		for (int i = 1; i <= n; i++) {
			int tmp = i;
			int j = 0;
			for (j = 0; tmp < k; j++)
				tmp *= 2;
			if (j == 0)
				ans += 1 / (double) n;
			else
				ans += Math.pow((double)1 / 2, j) * (1 / (double) n);
		}
		System.out.println(ans);
	}
	public static void main(String[] args) {
		new Main().run();
	}

}


Measured memory_bytes: 21972
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

import Data.Map as Map

main = putStrLn . solve  =<< getLine


solve s = if ans then "Yes" else "No" where
    f []     m = m
    f (x:xs) m = f xs h where
        h = case Map.lookup x m of
            Just c -> Map.insert x (c + 1) m
            Nothing -> Map.insert x 1 m
    ans = all even . Map.elems $ f s Map.empty

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

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (a <= 0 && b >= 0)
	{
		printf("Zero\n");
		return 0;
	}

	if (a > 0)
	{
		printf("Positive\n");
		return 0;
	}

	b = min(b, -1);
	if (!((a - b) & 1)) printf("Negative\n");
	else printf("Positive\n");
};




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 10;
int fa[maxn], mn_val[maxn], val[maxn], idx[maxn];
bool vis[maxn];
int n, m, u, v;

int Find(int x) {
    return fa[x] == x ? x : fa[x] = Find(fa[x]);
}

void Union(int x, int y) {
    int fx = Find(x), fy = Find(y);
    if(fx == fy) return;
    fa[fy] = fx;
    if(mn_val[fy] < mn_val[fx]) {
        mn_val[fx] = mn_val[fy];
        idx[fx] = idx[fy];
    }
}

int main(void) {
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; ++i) {
        idx[i] = fa[i] = i;
        scanf("%d", val + i);
        mn_val[i] = val[i];
    }
    while(m--) {
        scanf("%d%d", &u, &v);
        Union(u, v);
    }
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(fa[i] == i) {
            ++cnt;
            vis[idx[i]] = 1;
        }
    }
    if((cnt - 1) * 2 > n) return 0 * puts("Impossible");
    if(cnt == 1) return 0 * puts("0");
    vector<int> vt;
    ll sum = 0;
    for(int i = 0; i < n; ++i) {
        if(!vis[i]) vt.push_back(val[i]);
        else sum += val[i];
    }
    cnt -= 2;
    sort(vt.begin(), vt.end());
    for(int i = 0; i < cnt; ++i) sum += vt[i];
    printf("%lld\n", sum);
}

Measured memory_bytes: 2556
#include "bits/stdc++.h"
using namespace std;
int main(){
    int A,B,K,i;
    cin >> A >> B >> K;
    for(i=1;i<=K;i++){
        if(i%2){
            A /= 2;
            B += A;
        }else{
            B /= 2;
            A += B;
        }
    }
    cout << A << " " << B << endl;
    return 0;
}

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

int main(){
  while(1){
    string s;
    cin>>s;
    if(s=="-"){
      break;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
      int h;
      cin>>h;
      s=s.substr(h)+s.substr(0,h);
    }
    cout<<s<<endl;
  }
  return 0;
}




Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	long double a, b;
	cin >> a >> b;
	if (a > b) {
		cout << "GREATER" << endl;
	}
	else if (a < b) {
		cout << "LESS" << endl;
	}
	else if (a == b) {
		cout << "EQUAL" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

ll  d, n, r, l, k, ans = 0, ret = M;
bool flag = false, flag2 = false;
string s, t;
ll a, b, c;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vll v(5);
	rep(i, 5) {
		cin >> v[i];
		//cout << v[i] << endl;
	}
	cin >> k;
	if (v[4] - v[0] > k) cout << ":(";
	else cout << "Yay!\n";
	/*ll x, y, z;
	cin >> x >> y >> z >> k;*/

}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[])
{
  using namespace std;
  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++)
    {
      cout << i << "x" << j << "="<< i * j << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int a,b,c,x,y,ans=inf;cin>>a>>b>>c>>x>>y;
    for(int i=0;i<=2*max(x,y);i+=2){
        int k=x-i/2,j=y-i/2;
        if(k<0) k=0;if(j<0) j=0;
        ans=min(ans,a*k+b*j+c*i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        final int M = sc.nextInt();
        
        final Set<Integer>[] friends = new Set[N];
        for (int i = 0; i < N; i++) {
            friends[i] = new HashSet<>();
        }
        
        for (int i = 0; i < M; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            
            friends[a].add(b);
            friends[b].add(a);
        }
        
        TreeSet<Integer> members = new TreeSet<>(
                IntStream.range(0, N).mapToObj(Integer::valueOf).collect(Collectors.toSet()));
        
        int max = 0;
        while (!members.isEmpty()) {
            int m = members.pollFirst();
            Queue<Integer> tmp = new ArrayDeque<>();
            tmp.add(m);
            Set<Integer> group = new HashSet<>();
            
            while (!tmp.isEmpty()) {
                int n = tmp.poll();
                group.add(n);
                friends[n].retainAll(members);
                tmp.addAll(friends[n]);
                members.removeAll(friends[n]);
            }
            
            if (max < group.size()) {
                max = group.size();
            }
        }
        
        System.out.println(max);
    }
}


Measured memory_bytes: 145096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0||c>0){
		c-=b;
		if(c<=0){
			puts("Yes");
			break;
		}
		a-=d;
		if(a<=0){
			puts("No");
			break;
		}
	}
} 

Measured memory_bytes: 3564
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<string,int> MAP1,MAP2;
  int n;cin>>n;
  FOR(i,0,n){
    string s;cin>>s;
    MAP1[s]++;
  }
  int m;cin>>m;
  FOR(i,0,m){
    string s;cin>>s;
    MAP2[s]++;
  }
  // m.firstを言う
  int ans=0;
  for(auto m : MAP1){
	ans=max(ans,m.second-MAP2[m.first]);
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10, mod = 1e9+7;

void solve() {
    int n; cin >> n;

    ll cnt = 0;
    for (int i = 1; i <= n; ++i) {
        cnt += (ll) i * (n - i + 1);
    }

    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;

        if (u > v) {
            swap(u, v);
        }

        cnt -= (ll) u * (n - v + 1);
    }
    cout << cnt << endl;
}   

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; 
    while (t--) solve();
    return 0;
}


Measured memory_bytes: 3648
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        a: [i64;n]
    }

    // 山1 - 山Nを求める
    let mut y1myn = a[0];
    let mut minus = true;
    for i in 1..n - 1 {
        if minus {
            y1myn = y1myn - a[i];
        } else {
            y1myn = y1myn + a[i];
        }
        minus = !minus;
    }
    y1myn *= 2;

    // 山1の雨量を求める (nは奇数！)
    let y1 = (y1myn + 2 * a[n - 1]) / 2;
    print!("{}", y1);

    let mut last = y1;
    for i in 0..n - 1 {
        last = 2 * a[i] - last;
        print!(" {}", last);
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 9596