akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int h, w;
vector<vector<char>> s(51, vector<char>(51));
vector<vector<char>> ans(51, vector<char>(51));

void cnt(int i, int j) {
  if (ans.at(i).at(j) == '#')
    ans.at(i).at(j) = '1';
  else
    ans.at(i).at(j)++;
}

int main() {
  cin >> h >> w;

  REP(i, h) {
    REP(j, w) {
      cin >> s.at(i).at(j);
      if(s.at(i).at(j)=='#')ans.at(i).at(j) = '#';
      else
        ans.at(i).at(j) = '0';
    }
  }

  REP(i, h) {
    REP(j, w) {
      if (s.at(i).at(j) == '.') {
        if (i > 0) {
          if (s.at(i - 1).at(j) == '#') cnt(i , j);
        }
        if (i < h - 1) {
          if (s.at(i + 1).at(j) == '#') cnt(i, j);
        }
        if (j > 0) {
          if (s.at(i).at(j - 1) == '#') cnt(i, j);
        }
        if (j < w - 1) {
          if (s.at(i).at(j + 1) == '#') cnt(i, j);
        }
        if (i > 0 && j > 0) {
          if (s.at(i - 1).at(j - 1) == '#') cnt(i, j);
        }
        if (i > 0 && j < w - 1) {
          if (s.at(i - 1).at(j + 1) == '#') cnt(i, j);
        }
        if (i < h - 1 && j > 0) {
          if (s.at(i + 1).at(j - 1) == '#') cnt(i, j);
        }
        if (i < h - 1 && j < w - 1) {
          if (s.at(i + 1).at(j + 1) == '#') cnt(i, j);
        }
      }
    }
  }
  REP(i, h) {
    REP(j, w) { cout << ans.at(i).at(j); }
    cout  << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
count = 0
for i in range(1, n+1):
    if i%2 == 0:
        continue
    else:
        yak_count = 0
        for j in range(1, n+1):
            if i%j == 0:
                yak_count += 1
        if yak_count == 8:
            count += 1
print(count)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 1000000000000000000
#define imin -1000000000000000000
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
int p5(int a)
{
    return a*a*a*a*a;
}

 
void nhi_degi()
{
    int n;cin>>n;
    int a[n+4];
    map<int,int>m1,m2;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        m1[i+a[i]]++;
        m2[i-a[i]]++;
    }
    int count=0;
    repit(m1)
    {
        int x=it->ff;
        int y=it->ss;
        int z=m2[x];
        count+=(y*z);
    }
    cout<<count;el
}
signed main()
{
    // cases(t)
    // {
        nhi_degi();
    // }
}

Measured memory_bytes: 39356
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.1415926535897932384626433
const ll mod = 1e9 + 7;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*down, up, right, left*/
int main()
{
	MOAE;
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's')
	{
		cout << s << "es" << endl;
	}
	else
	{
		cout << s << "s" << endl;
	}
	ok;
}

Measured memory_bytes: 3656
package main
import (
  "fmt"
)
func main() {
  var N int
  fmt.Scan(&N)
  A := make([]int, N)
  B := make([]int, N)
  C := make([]int, N-1)
  for i, _ := range A {
    fmt.Scan(&A[i])
  }
  for i, _ := range B {
    fmt.Scan(&B[i])
  }
  for i, _ := range C {
    fmt.Scan(&C[i])
  }
  
  res := 0
  for _, v := range B {
    res += v
  }
  for i, _ := range C {
    if A[i] + 1 == A[i+1] {
      res += C[A[i]-1]
    }
  }
  fmt.Println(res)
}


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

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

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

	Arrays.sort(a);
	if(a[2] == a[1]+a[0]){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
    }
}


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

int main() {
  string S;
  cin >> S;
  int A = S[0] -'0';
  int B = S[1] -'0';
  int C = S[2] -'0';
  int D = S[3] -'0';
  if(A+B+C+D == 7) cout << A << '+' << B << '+' << C<< '+' << D <<'=' << 7 << endl;
  else if(A-B+C+D == 7) cout << A << '-' << B << '+' << C<< '+' << D <<'=' << 7 << endl;
  else if(A+B-C+D == 7) cout << A << '+' << B << '-' << C<< '+' << D <<'=' << 7 << endl;
  else if(A+B+C-D == 7) cout << A << '+' << B << '+' << C<< '-' << D <<'=' << 7 << endl;
  else if(A-B-C+D == 7) cout << A << '-' << B << '-' << C<< '+' << D <<'=' << 7 << endl;
  else if(A+B-C-D == 7) cout << A << '+' << B << '-' << C<< '-' << D <<'=' << 7 << endl;
  else if(A-B+C-D == 7) cout << A << '-' << B << '+' << C<< '-' << D <<'=' << 7 << endl;
  else if(A-B-C-D == 7) cout << A << '-' << B << '-' << C<< '-' << D <<'=' << 7 << endl;
}


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

int main() {
	// your code goes here
	int n, k;
	cin >> n >> k;
	int ans;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		ans += 2*min(x, k-x);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
//
//    static void print(int[][] a) {
//        System.out.println("============");
//        for (int[] z : a) {
//            System.out.println(Arrays.toString(z));
//        }
//    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        String[] board = new String[n];
        for (int i = 0; i < n; i++) {
            board[i] = scan.next();
        }
        int[][] horizontal = new int[n][m];
        for (int i = 0; i < n; i++) {
            int start = 0;
            int end = -1;
            for (int j = 0; j < m; j++) {
                if (board[i].charAt(j) == '#') {
                    for (int k = start; k <= end; k++) {
                        horizontal[i][k] = end - start + 1;
                    }
                    start = j + 1;
                    end = j;
                } else {
                    end = j;
                }
            }
            for (int k = start; k <= end; k++) {
                horizontal[i][k] = end - start + 1;
            }
        }

        int[][] vertical = new int[n][m];
        for (int i = 0; i < m; i++) {
            int start = 0;
            int end = -1;
            for (int j = 0; j < n; j++) {
                if (board[j].charAt(i) == '#') {
                    for (int k = start; k <= end; k++) {
                        vertical[k][i] = end - start + 1;
                    }
                    start = j + 1;
                    end = j;
                } else {
                    end = j;
                }
            }
            for (int k = start; k <= end; k++) {
                vertical[k][i] = end - start + 1;
            }
        }

        int output = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                output = Math.max(output, horizontal[i][j] + vertical[i][j] - 1);
            }
        }
        System.out.println(output);
    }
}

Measured memory_bytes: 66620
import java.util.Scanner;

/**
 * https://abc065.contest.atcoder.jp/tasks/abc065_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		sc.close();
		
		String ans = "delicious";
		if(A-B<0){
			ans = B-A <=X ? "safe" : "dangerous";
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010

int main(){
    ll h,w,n;
    cin>>h>>w>>n;
    h=max(h,w);
    cout<<(n+h-1)/h<<endl;
}




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

// NOTE TO SELF // try to simplyfy the problem

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

#define ll long long int

//const int mod=1000000007;

using namespace std;




int main()
{

    int n;
    cin>>n;
    
    int a[n];
    rep(i,n)
    cin>>a[i];
    
    const int INF=1e9+5;
    vector<int> dp(n,INF);

    dp[0]=0;
    
    for(int i=0;i<n;i++)
    {
        for(int j:{i+1,i+2})
        {
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
        }
        
    }
    
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

typedef vector<int> vec;
typedef vector<vec> mat;

vec modmul(const mat &A, const vec &v, ll mod){
  vec u(A.size(), 0);
  REP(i, A.size()){
    REP(j, A[0].size()){
      u[i] += A[i][j] * v[j];
      u[i] %= mod;
    }
  }
  return u;
}

mat modmul(const mat &A, const mat &B, ll mod){
  mat C(A.size(), vec(B[0].size(), 0));
  REP(i, A.size()){
    REP(k, A[0].size()){
      REP(j, B[0].size()){
        C[i][j] += A[i][k] * B[k][j];
        C[i][j] %= mod;
      }
    }
  }
  return C;
}

mat modpow(mat A, ll n, ll mod){
  mat res(A.size(), vec(A.size(), 0));
  REP(i, A.size()) res[i][i] = 1;

  while(n > 0){
    if(n & 1) res = modmul(res, A, mod);
    n >>= 1;
    A = modmul(A, A, mod);
  }
  
  return res;
}

int main(){
  int N, M, A, B, C, T;
  
  while(cin >> N >> M >> A >> B >> C >> T && N + M + A + B + C + T > 0){
    vec S0(N);
    REP(i, N) cin >> S0[i];
    mat m(N, vec(N, 0));
  
    REP(i, N){
      if(i > 0){
        m[i][i-1] = A;
      }
    
      m[i][i] = B;
    
      if(i + 1 < N){
        m[i][i+1] = C;
      }
    }

    m = modpow(m, T, M);
    vec S = modmul(m, S0, M);
    REP(i, N) cout << S[i] << (i == N - 1 ? '\n' : ' ');
    
  }
  return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int p1 = sc.nextInt();
		int p2 = sc.nextInt();
		int p3 = sc.nextInt();
		int j1 = sc.nextInt();
		int j2 = sc.nextInt();
		int mp = p1;
		int mj = j1;
		
		if(mp > p2){
			mp = p2;
		}
		if(mp > p3){
			mp = p3;
		}
		
		if(mj > j2){
			mj = j2;
		}
		
		System.out.println(mp + mj - 50);
	}
}

Measured memory_bytes: 26088
n,m=gets.chomp.split(" ").map{|s| s.to_i}
p=[]
s=[]
for i in 0..m-1
  p[i],s[i]=gets.chomp.split(" ")
  p[i]=p[i].to_i
end
t=[]
for i in 0..m-1
  if t[p[i]].nil?
    t[p[i]]=[1,0] if s[i]=="AC"
    t[p[i]]=[0,1] if s[i]=="WA"
  else
    if t[p[i]][0]==0
      if s[i]=="AC"
        t[p[i]][0]=1
      else s[i]=="WA"
        t[p[i]][1]+=1
      end
    end
  end
end

ac=0
wa=0
for i in 0..n
  if !t[i].nil?
    if t[i][0]==1
      ac+=1
      wa+=t[i][1]
    end
  end
end
print "#{ac} #{wa}"

Measured memory_bytes: 16912
#include <iostream>
using namespace std;
const int N = 10;
int main(){
    int n,i,ans,a,b,c;;
    cin >> n;
    while(n--) {
    	ans=1;
    	b=c=-1;
        for(i=0;i<10;i++){
        	cin>>a;
        	if(a>b)
        		b=a;
        	else if(a>c)
        		c=a;
        	else
        		ans=0;
		}
		if(ans) puts("YES");
    	else puts("NO");
    }
}


Measured memory_bytes: 3064
n, k = map(int, input().split())
p = list(map(int, input().split()))

d = []

for v in p:
    d.append((1+v)/2)

x=r=sum(d[:k])
# print(d)

for i in range(1,n-k+1):
    # r=max(r,sum(d[i:i+k]))
    x=x-d[i-1]+d[i+k-1]
    r=max(r,x)
    # print(r,i)

print(r)


Measured memory_bytes: 25060
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  for(int i=0;i<n;i++){
      cout<<s[i]<<t[i];
  }
  cout<<endl;
}

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

n, m = map(int, input().split())

wars = []

for i in range(m):
    wars.append(list(map(int, input().split())))

wars.sort(key=lambda x: x[1])

res = 0
recent_destroyed = -1

for i in range(len(wars)):
    if wars[i][0] <= recent_destroyed and wars[i][1] > recent_destroyed:
        continue
    res += 1
    recent_destroyed = wars[i][1] - 1

print(res)


Measured memory_bytes: 29076
S = input()
N = len(S)
MOD = 10**9+7
dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

base = 1
for i in range(N):
    if S[N-1-i] != '?':
        mi = int(S[N-1-i])*base
        mi %= 13
        for j in range(13):
            dp[i+1][(j+mi)%13] += dp[i][j]
            dp[i+1][(j+mi)%13] %= MOD
    else:
        for j in range(13):
            for k in range(10):
                Ti = base * k
                Ti %= 13
                dp[i+1][(j+Ti)%13] += dp[i][j]
                dp[i+1][(j+Ti)%13] %= MOD
    base *= 10
    base %= 13
print(dp[N][5])

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N;
  string S;
  IN(N);
  IN(S);

  vll LL(N, 0);
  vll LR(N, 0);
  vll RL(N, 0);
  vll RR(N, 0);

  REP(i,N-1){
    LL[i+1] = LL[i];
    LR[i+1] = LR[i];
    if(S[i]=='W') LL[i+1]++;
    else          LR[i+1]++;
  }

  RREP(i,N-2){
    RL[i] = RL[i+1];
    RR[i] = RR[i+1];
    if(S[i+1]=='W') RL[i]++;
    else            RR[i]++;
  }

  REP(i,N){
    fprintf(stderr, "%lld ", LL[i]);
  }
  fprintf(stderr, "\n");
  REP(i,N){
    fprintf(stderr, "%lld ", RR[i]);
  }
  fprintf(stderr, "\n");

  ll ans = INFLL;
  REP(i,N){
    ans = min(ans, LL[i]+RR[i]);
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 12036
#include<stdio.h>
char max2(char a, char b){return a<b?b:a;}
char c, is[26], now, ans;
int main(void){
  is[0]=1;
  is[2]=1;
  is[6]=1;
  is[19]=1;
  while((c=getchar())!=10){
    if(is[c-'A']){
      now++;
      ans = max2(ans, now);
    }else{
      now=0;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        string s,t;
        cin>>s>>t;
        int ans = 0;
        loop(i,0,s.length()-1){
            if(s[i]!=t[i]) ans++;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <string.h>

using namespace std;

long long strint(char f[])
{
    long long a=0,i,b,j,c=1;
    int o=strlen(f);
    for(i=strlen(f)-1; i>=0; i--)
    {
        b=f[i]-48;
        if(i==strlen(f)-1)
        {
            a+=b;
        }

        else
        {
            for(j=0; j<c; j++)
            {
                b*=10;
            }
            a+=b;
            c++;
        }
    }
    return a;
}

int main()
{
	char str[20];
	long long num,lol;
	int sum = 0;
	cin >> str;
	num = strint(str);
	lol = num;
	int len = strlen(str);
	for(int i = 0; i < len; i++)
	{
		sum += num%10;
		num = num/10;
	}
	if (lol%sum == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

typedef long long ll;

int main(){
	ll n;
	while( cin >> n , n ){
		ll sump = 0;
		vector<ll> p(n), J(n-1);
		for(ll i = 0 ; i < n ; i++ ){
			cin >> p[i];
			sump += p[i];
		}
		for(ll i = 0 ; i < n-1 ; i++ ) cin >> J[i];
		
		sort(J.rbegin(), J.rend());
		ll ans = 0;
		for(ll k = 0, t = n, sumj = 0 ; t >= 1 ; k++, t-- ){
			ll v = t * (sump + sumj);
			sumj += J[k];
			ans = max(ans, v);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2056
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
struct UF{
	int par[2000005],ran[2000005];
	void init(){ for(int i=0;i<2000005;i++) par[i] = i, ran[i] = 0; }
	int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
	void unite(int x,int y){
		x = find(x); y = find(y); if(x==y) return;
		if(ran[x] < ran[y]) par[x] = y;
		else{
			par[y] = x;
			if(ran[x] == ran[y]) ran[x]++;
		}
	}
	bool same(int x,int y){ return find(x)==find(y); }
}uf;


ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[2000005],R[2000005];
void make(){
	F[0] = 1;
	for(int i=1;i<2000005;i++) F[i] = F[i-1]*i%mod;
	R[2000004] = modpow(F[2000004], mod-2);
	for(int i=2000003;i>=0;i--) R[i] = R[i+1] * (i+1) % mod;
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
void solve(){
	int n; cin >> n;
	vector<ll>vec(n);;
	rep(i, n) cin >> vec[i];
	ll ans = 0;
	SORT(vec);
	reverse(all(vec));
	for(int i=1;i<n;i++){
		if(i == 1) ans += vec[0];
		else ans += vec[i/2];
	}
	cout << ans << endl;
}

int main(){
	uf.init();
	make();
	solve();
}

Measured memory_bytes: 51840
#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int N;

vector<string> name;
vector<int> score;

int main()
{
	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		string str;
		int scr;

		cin >> str;
		cin >> scr;

		name.push_back(str);
		score.push_back(scr);
	}

	//name을 소트시켜서 비교에 저장
	vector<string> sortedName(name);
	sort(sortedName.begin(), sortedName.end());

	string nowName = "";

	for (int i = 0; i < sortedName.size(); i++)
	{
		if (nowName == sortedName[i]) continue;
		nowName = sortedName[i];
		//i번째 sortedName과 비교해서 같은 name을 찾아
		vector<int> sameNameScore;

		for (int j = 0; j < name.size(); j++)
		{
			if (name[j] == sortedName[i])
			{
				sameNameScore.push_back(score[j]);
			}
		}

		sort(sameNameScore.begin(), sameNameScore.end(), greater<int>());

		for (int k = 0; k < sameNameScore.size(); k++)
		{
			for (int l = 0; l < score.size(); l++)
			{
				if (sameNameScore[k] == score[l])
				{
					printf("%d\n", l + 1);
					break;
				}
			}
		}
	}

	return 0;
}

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

e=[0]*(N+1)

for i in range(N+1):
    cur=i

    for j in range(2,i+1):
        while cur%j==0:
            e[j]+=1
            cur=cur//j

def num(m):
    tmp=0
    for i in range(N+1):
        if e[i]>=m:
            tmp+=1
    return tmp

print(num(74)+num(24)*(num(2)-1)+num(4)*(num(4)-1)*(num(2)-2)//2+num(14)*(num(4)-1))

Measured memory_bytes: 3064
//

fun main() {
    abc170c()
}

fun abc170c() {
    val (x, n) = readLine()!!.split(" ").map { it.toInt() }
    if (n == 0) {
        println(x)
        return
    }
    val p = readLine()!!.split(" ").map { it.toInt() }.toSet()
    for (i in 0..101) {
        if (x - i !in p) {
            println(x - i)
            return
        }
        if (x + i !in p) {
            println(x + i)
            return
        }
    }
}


Measured memory_bytes: 36812
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------
bool color[200001];
//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    bool abc=1;
    for(ll i=s.length()-1;i>=0;){
        
        if(i>=4){
        if(s[i]=='m'&&s[i-1]=='a'&&s[i-2]=='e'&&s[i-3]=='r'&&s[i-4]=='d'){
     
            i-=5;
            continue;
        }
        else if(s[i]=='e'&&s[i-1]=='s'&&s[i-2]=='a'&&s[i-3]=='r'&&s[i-4]=='e'){
           
            i-=5;
            continue;
        }}
        if(i>=5){
            if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='s'&&s[i-3]=='a'&&s[i-4]=='r'&&s[i-5]=='e'){
               
                i-=6;
                continue;
            }
        }
        if(i>=6){
            if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='m'&&s[i-3]=='a'&&s[i-4]=='e'&&s[i-5]=='r'&&s[i-6]=='d'){
               
                i-=7;
                continue;
            }
        }
        abc=0;break;
    }
    if(abc==0)cout<<"NO"<<endl;
    else cout<<"YES"<<Endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------

/*
ll n;cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++)
    cin>>a[i];
 
ll n;cin>>s;
string s;cin>>s;

ll n,m;cin>>n>>m;
vector<ll>a(n),b(m);
for(ll i=0;i<n;i++){
    cin>>a[i];
}
for(ll i=0;i<m;i++){
    cin>>b[i];
}

ll n;cin>>n;
vector<Pll>xy;
for(ll i=0;i<n;i++){
    ll x,y;cin>>x>>y;
    xy.pb({x,y});
}
*/


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

int main() {
    uint64_t L, R;
    std::cin >> L >> R;

    if ((R - L) >= 2019) {
        printf("0\n");
        return 0;
    }

    uint64_t min = UINT64_MAX;
    for (size_t i = L; i < R; ++i) {
        for (size_t j = L + 1; j <= R; ++j) {
            min = std::min(min, (i * j) % 2019); 
        }
    }

    std::cout << min << std::endl;

    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N;
        ArrayList<Integer> a = new ArrayList<Integer>();
        int count = 0;
        int temp, minIndex;

        N = sc.nextInt();

        for(int i = 0; i < N; i++){
            a.add(sc.nextInt());
        }

        for(int i = 0; i < N; i++){
            minIndex = i;
            for(int j = i + 1; j < N; j++){
                if(a.get(j) < a.get(minIndex)){
                    minIndex = j;
                }
            }
            if(i != minIndex){
                temp = a.get(i);
                a.set(i, a.get(minIndex));
                a.set(minIndex, temp);
                count++;
            }
        }

        for(int i = 0; i < a.size(); i++){
            System.out.print(a.get(i));
            if(i != a.size() - 1) System.out.print(" ");
        }
        System.out.println("\n" + count);

        sc.close();
    }
}


Measured memory_bytes: 26476
program main
  implicit none
  integer :: n, i, t, l, r, numq, cnt(26, 500)
  character(500000) :: s
  character(100) :: q
  character(1) :: c
  read *, n
  read *, s
  call prep
  read *, numq
  do i = 1, numq
    read *, t, l, q
    if (t == 1) then
      read (q, *) c
      call type1(l, c)
    else
      read (q, *) r
      call type2(l, r)
    end if
  end do
  contains

  subroutine prep()
    integer :: i, j, b
    cnt(:, :) = 0
    do i = 1, n
      j = iachar(s(i:i)) - iachar("a") + 1
      b = i_to_bin(i)
      cnt(j, b) = cnt(j, b) + 1
    end do
  end subroutine prep

  subroutine type1(i, c)
    integer, intent(in) :: i
    character(1), intent(in) :: c
    integer :: b, j
    b = i_to_bin(i)
    j = iachar(s(i:i)) - iachar("a") + 1
    cnt(j, b) = cnt(j, b) - 1
    s(i:i) = c(1:1)
    j = iachar(s(i:i)) - iachar("a") + 1
    cnt(j, b) = cnt(j, b) + 1
  end subroutine type1

  subroutine type2(l, r)
    integer, intent(in) :: l, r
    integer :: scnt(26), b, tot, a
    scnt(:) = 0
    do b = 1, 1000
      scnt(:) = scnt(:) + query(b, l, r)
    end do
    tot = 0
    do a = 1, 26
      if (scnt(a) > 0) tot = tot + 1
    end do
    print "(i0)", tot
  end subroutine type2

  pure integer function i_to_bin(i)
    integer, intent(in) :: i
    i_to_bin = (i - 1) / 1000 + 1
  end function i_to_bin

  pure integer function b_to_i(b)
    integer, intent(in) :: b
    b_to_i = (b - 1) * 1000 + 1
  end function b_to_i

  function query(b, l, r)
    integer :: query(26)
    integer, intent(in) :: b, l, r
    integer :: i, j, k, ic
    query(:) = 0
    i = b_to_i(b)
    j = i + 1000 - 1
    if (r < i) return
    if (l > j) return
    if (l <= i .and. j <= r) then
      query(:) = cnt(:, b)
    else
      do k = max(i, l), min(j, r)
        ic = iachar(s(k:k)) - iachar("a") + 1
        query(ic) = query(ic) + 1
      end do
    end if
  end function query
end program main


Measured memory_bytes: 1980
n,a,b=map(int,input().split())
mod=10**9+7
ans=pow(2,n,mod)-1
p=1
for i in range(a):
    p*=n-i
    p*=pow(i+1,mod-2,mod)
    p%=mod
p2=1
for i in range(b):
    p2*=n-i
    p2*=pow(i+1,mod-2,mod)
    p2%=mod
print((ans-p-p2)%mod)


Measured memory_bytes: 3064
def runlen(a):
    n = len(a)
    result = []
    count = 1
    for i in range(n):
        if i == n - 1 or a[i] != a[i + 1]:
            result.append((count, a[i]))
            count = 1
        else:
            count += 1
    return result

S = input()
K = int(input())

rl = runlen(S)

if len(rl) == 1:
    result = (len(S) * K) // 2
else:
    result = rl[0][0] // 2 + rl[-1][0] // 2 + K * sum(map(lambda i: rl[i][0] // 2, range(1, len(rl) - 1)))
    if rl[0][1] == rl[-1][1]:
        result += (K - 1) * ((rl[0][0] + rl[-1][0]) // 2)
    else:
        result += (K - 1) * (rl[0][0] // 2 + rl[-1][0] // 2)

print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <thread>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll x[2], ans;
int main() {
	cin >> x[0] >> x[1];
	REP(i, 2) {
		if (x[i] == 1)ans += 300000;
		if (x[i] == 2)ans += 200000;
		if (x[i] == 3)ans += 100000;
	}
	if (x[0] == 1 and x[1] == 1)ans += 400000;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////


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

	vector<ll> H(N + 1);
	repn(i, N) cin >> H[i];

	vector<vector<ll>> g(N + 1);

	repn(i, M) {
		ll a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	ll ans = 0;
	
	repn(v, N) {
		ll b = 1;
		for (ll w : g[v]) {
			if (H[v] <= H[w]) { b = 0; }
		}
		ans += b;
	}
	
	cout << ans << endl;
	
	system("PAUSE");
}


Measured memory_bytes: 10072
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;


int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    cout<<((s[1]==s[2])&&(s[0]==s[1] || s[2]==s[3])?"Yes":"No");
    
    return 0;
    
}

Measured memory_bytes: 256
n,q = map(int,input().split())

root = [[] for i in range(n)]
for _ in range(n-1):
    a, b = (int(x) for x in input().split())
    root[b-1].append(a-1)
    root[a-1].append(b-1) 


dp = [0]*n
for _ in range(q):
    p, x = (int(x) for x in input().split())
    dp[p-1] += x

stack=[0]
check = [-1]*n
check[0] = 0

while len(stack):
    v = stack.pop()
    for i in root[v]:
        if i != check[i]:
            dp[i] += dp[v]
            check[i]=i
            stack.append(i)

print(' '.join(map(str,dp)))


Measured memory_bytes: 129704
#include <stdio.h>

int main(void)
{
	int n, q, count;
	int S[100000], T[50000];
	int pl, pr, pc;
	int i;


	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &S[i]);
	
	scanf("%d", &q);
	for (i = 0; i < q; i++)
		scanf("%d", &T[i]);

	count = 0;
	for (i = 0; i < q; i++){
		pl = 0;
		pr = n - 1;
		do {
			pc = (pl + pr) / 2;
			if (S[pc] == T[i]){
				count++;
				break;
			}
			else if (S[pc] < T[i])
				pl = pc + 1;
			else
				pr = pc - 1;
		} while (pl <= pr);
	}

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

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define ll long long 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)

int main()
{
    fast;
    float a,b; cin>>a>>b;
    
    if(b<2*a) cout<<"No\n";
    else{
    float y=((b-(2*a))/2);
    float x=a-y;
    
    if(x>= 0 && y>=0 && x==int(x) && y==int(y))
    cout<<"Yes\n";
    else cout<<"No\n";
    }
}


   



            
        


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int x,t;
  cin>>x>>t;
  int sum=x-t;
  if(sum<0) sum=0;
  cout<<sum<<'\n';
  return 0;
}


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

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

    int d, t, s;
    cin >> d >> t >> s;

    if(s*t >= d) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include <math.h>
int main(void){
	int a,d[6],i,j,k,n,x,y;
	char c;

	for(i=0;i<6;i++){
		scanf("%d%*c",&d[i] );
	}
	scanf("%d%*c",&n );
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y );
		if((x==d[0] && y==d[1]) || (x==d[1] && y==d[5]) || (x==d[5] && y==d[4]) || (x==d[4] && y==d[0]))
			printf("%d\n",d[2] );
		else if((x==d[1] && y==d[0]) || (x==d[0] && y==d[4]) || (x==d[4] && y==d[5]) || (x==d[5] && y==d[1]))
			printf("%d\n",d[3] );
		else if((x==d[1] && y==d[3]) || (x==d[3] && y==d[4]) || (x==d[4] && y==d[2]) || (x==d[2] && y==d[1]))
			printf("%d\n",d[5] );
		else if((x==d[3] && y==d[1]) || (x==d[4] && y==d[3]) || (x==d[2] && y==d[4]) || (x==d[1] && y==d[2]))
			printf("%d\n",d[0] );
		else if((x==d[0] && y==d[3]) || (x==d[3] && y==d[5]) || (x==d[5] && y==d[2]) || (x==d[2] && y==d[0]))
			printf("%d\n",d[1] );
		else if((x==d[3] && y==d[0]) || (x==d[5] && y==d[3]) || (x==d[2] && y==d[5]) || (x==d[0] && y==d[2]))
			printf("%d\n",d[4] );
	}
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int A[3]{};
  for (auto i = 0; i < N; ++i) {
    int x;
    cin >> x;
    ++A[x - 1];
  }
  static long double F[301][301];
  auto M = A[0] + A[1] * 2 + A[2] * 3;
  for (auto m = 1; m <= M; ++m)
    for (auto i = min(m / 3, A[2]); i >= max(0, m - N * 2 - 1); --i)
      for (auto j = min((m - i * 3) / 2, A[2] + A[1]); j >= max(0, m - N - i * 2); --j) {
        auto k = m - i * 3 - j * 2;
        auto n = i + j + k;
        auto f = F[i][j] * k + N;
        if (i)
          f += F[i - 1][j + 1] * i;
        if (j)
          f += F[i][j - 1] * j;
        F[i][j] = f / n;
      }
  cout << fixed << setprecision(12) << F[A[2]][A[1]] << endl;
  return 0;
}


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

int main(){
  int N;
  string S;
  string ans;
  cin >> N;
  cin >> S;
  int left=0,right=0;
  for(int i=0;i<N;i++){
    if(S[i] == '(' ){
      left++;
      ans = ans+S[i];
    } else {
      if(left > 0){
        left--;
        ans = ans+S[i];
      } else {
        ans = '(' +ans+S[i];
      }
    }
  }
  for(int i = 0; i<left;i++ ) ans = ans+')';
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
  ll N,A[100007],sum=0;cin >> N;
  rep(i,N){
    cin >>A[i];
    if(i>0){
      sum+=abs(A[i]-A[i-1]);
    }
    else{
      sum+=abs(A[i]);
    }
    if(i==N-1){
      sum+=abs(A[i]);
    }
  }
  rep(i,N){
    if(i==0){
      cout << sum-abs(A[1]-A[0])-abs(A[0])+abs(A[1]) << endl;
    }
    else if(i==N-1){
      cout << sum-abs(A[N-1]-A[N-2])-abs(A[N-1])+abs(A[N-2]) << endl;
    }
    else{
      cout << sum-abs(A[i]-A[i-1])-abs(A[i]-A[i+1])+abs(A[i+1]-A[i-1]) << endl;
    }
  }
}

Measured memory_bytes: 2048
sums = Hash.new(0)
overs = Hash.new 
while gets do
  n = $_.to_i
  next if n.zero?
  sums.clear
  overs.clear
  n.times do
    i, p , q = gets.split
    sums[i] += p.to_i * q.to_i
    overs[i] = sums[i] if sums[i] >= 1_000_000
  end
  puts overs.empty? ? "NA" : overs.keys
end

Measured memory_bytes: 6104
import java.math.BigInteger;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        BigInteger ans = BigInteger.valueOf(a[0]);
        for (int i = 1; i < n; i++) {
            ans = ans.gcd(BigInteger.valueOf(a[i]));
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 51188
let main =
    Scanf.sscanf (read_line()) "%d %d" (
        fun n x ->
            let rec gcd a b =
                if a < b
                then gcd b a
                else if b = 0
                then a
                else gcd b (a mod b)
            in
            print_int (3 * (n - gcd n x));
            print_string "\n"
    )

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long Int;
typedef pair<Int ,Int> P;
vector<P> edge[108000];
Int dep[108000];
Int size[108000];
Int n, a, b, c;
vector<int> maybe;
void dfs(Int x, Int last, Int d){
  dep[x] = d;
  size[x] = 1;
  for(Int i = 0;i < edge[x].size();i++){
    Int to = edge[x][i].first;
    if(to == last)continue;
    Int w = edge[x][i].second;
    dfs(to, x, d + w);
    size[x] += size[to];
  }
}


int main(){
  cin >> n;
  for(Int i = 0;i < n-1;i++){
    cin >> a >> b >> c;a--,b--;
    edge[a].push_back(P(b, c));
    edge[b].push_back(P(a, c));
  }
  dfs(0, -1, 0);
  for(Int i = 0;i < n;i++){
    Int mx = 0;
    Int sum = 0;
    for(Int j = 0;j < edge[i].size();j++){
      Int to = edge[i][j].first;
      if(dep[to] < dep[i])continue;
      sum += size[to];
      mx = max(mx, size[to]);
    }
    mx = max(mx, n - 1 - sum);
    if(mx <= n/2){
      maybe.push_back(i);
    }
  }
  Int res = 0;
  for(int i = 0;i < maybe.size();i++){
    int x = maybe[i];
    dfs(x, -1, 0);
    Int tmp = 0;
    Int last = 1 << 30;
    for(int j = 0;j < n;j++)tmp += dep[j] * 2;
    for(int j = 0;j < edge[x].size();j++){
      int to = edge[x][j].first;
      if(size[to] == n/2 && n % 2 == 0){
	last = edge[x][j].second;
	break;
      }
      last = min(last, edge[x][j].second);
    }
    res = max(res, tmp - last);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 16256
import java.util.*;

public class Main {

        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                try {   
                        int num = sc.nextInt();
                        int len = sc.nextInt();
                        InputStr.len = len;
                        InputStr[] inputStr = new InputStr[num];
                        for (int i = 0; i<num; i++) {
                                inputStr[i] = new InputStr(sc.next());
                        }
                        // 並べ替え
                        Arrays.sort(inputStr);
                        for (int i = 0; i<num; i++) {
                                System.out.print(inputStr[i]);
                        }
                        System.out.println();

                } catch (Exception e) {
                //      e.printStackTrace();
                        System.out.println("入力値が不正です");
                }
        }

        // 入力値をソートするためにcompareToを実装したクラス
        static class InputStr implements Comparable<InputStr> {
                static int len = 0;
                String str = "";
                InputStr(String str) {
                        this.str = str; 
                }

                @Override
                public int compareTo(InputStr nextInput) {
                        for (int i = 0; i<len; i++) {
                                // 同じ文字なら次の文字を比較する
                                if (this.str.charAt(i) == nextInput.str.charAt(i)) {
                                        continue;
                                }
                                return this.str.charAt(i) - nextInput.str.charAt(i);
                        };
                        return 0;
                }

                @Override
                public String toString() {
                        return this.str;
                }

        }
}

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

#define PI pair<long long, long long >

long long game(vector<int> v, int n){
    vector<vector<PI>> dp(n, vector<PI>(n));
    for(int i=0; i<n; i++) dp[i][i].first = v[i], dp[i][i].second = 0;
    for(int l=2; l<=n; l++){
        for(int i=0; i<=(n-l); i++){
            int j=i+l-1;
            if(v[i]+dp[i+1][j].second > v[j]+dp[i][j-1].second){
                dp[i][j].first = v[i]+dp[i+1][j].second;   
                dp[i][j].second = dp[i+1][j].first;
            }else{
                dp[i][j].first = v[j]+dp[i][j-1].second;   
                dp[i][j].second = dp[i][j-1].first;
            }    
        }
    }
    return dp[0][n-1].first-dp[0][n-1].second;
}

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin>>v[i];
    cout<<game(v, n);
    return 0;
}


Measured memory_bytes: 143904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define REP(i,n) FOR(i,0,n)
int main(){
  int n;
  int ans = 0;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  vector<int> C(n);
  REP(i,n)cin >> A[i];
  REP(i,n){
    cin >> B[i];
    ans += B[i];
  }
  REP(i,n-1)cin >> C[i];
  REP(i,n-1){
    if(A[i]+1 == A[i+1])ans += C[A[i]-1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256