akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n=sc.nextInt();
		boolean[] aa = new boolean[201];
		for(int i=0;i<201;i++){
			aa[i]=printDivisors(i);
//			System.out.println(aa[i]+" "+i);
			}
		int cnt=0;
		for(int i=1;i<=n;i+=2)if(aa[i])cnt++;
		System.out.println(cnt);
	}
	static boolean printDivisors(int n)
    {
		int cnt=0;
        for (int i=1;i<=n;i++)
            if (n%i==0)
                cnt++;
        return cnt==8;
    }

}


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

int main(){
    char S[3]; cin >> S;

    if(S[0]==S[1]){
        cout<< "Bad" <<endl;
      return 0;
    }

    if(S[1]==S[2]){
        cout<< "Bad" <<endl;
      return 0;
    }
    
    if(S[2]==S[3]){
        cout<< "Bad" <<endl;
      return 0;
    }
    if(S[3]==S[4]){
        cout<< "Bad" <<endl;
      return 0;
    }

    cout << "Good" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
	int n;cin>>n;
    string s;
    cin>>s;
    int r=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') r++;
    }
    int cnt=0;
    for(int i=0;i<r;i++){
        if(s[i]=='R') cnt++;
    }
    cout<<r-cnt;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

using namespace std;

#define WA(x) #x << " = " << x << '\n'
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define FORT(i, a, b) for(int i = a; i < (int) b; i++)
#define all(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second

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

const ll MOD = 1000000007;

#define MAX 100000

ll binExp(ll a, ll p){
	ll ans = 1;
	while(p){
		if(p&1)
			ans = ans * a % MOD;
		a = a * a % MOD;
		p>>=1;
	}
	return ans;
}


ll comb(ll a, ll b){
	ll mini = min(a-b, b);

	ll f1 = 1;
	for(ll i = 0; i < mini; i++)
		f1 = f1 * (a-i) % MOD;
	ll f2 = 1;
	for(ll i = 1; i <= mini; i++)
		f2 = f2 * i % MOD;
	return f1 * binExp(f2, MOD-2) % MOD;
}

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



	ll n, a, b; cin >> n >> a >> b;
	ll fat = 1;
	for(ll i = 1; i <= n; i++)
		fat = fat*i % MOD;

	ll ans = binExp(2, n)-1;

	ans -= comb(n, a);
	if(ans < 0) ans += MOD;
	ans -= comb(n, b);
	if(ans < 0) ans += MOD;

	cout << ans << '\n';


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
#define MAX_N 200005
typedef long long ll;
typedef pair<int,int> P;
struct data{ll x,a,b;};

int N,Q;
int a,b,c;
vector<int> G[MAX_N];
int p[MAX_N],d[MAX_N],cnt=0;
vector<int> g,flg;


void rec(int pos,int prev,int depth){
  d[pos]=depth;
  p[pos]=g.size();
  g.push_back(pos);

  for(int i=0;i<(int)G[pos].size();i++){
    int w=G[pos][i];
    if(w==prev)continue;
    rec(w,pos,depth+1);
    g.push_back(pos);
  }

}

P dp[MAX_N][26];

int lca(int u,int v){

  u=p[u];
  v=p[v];
  if(u>v)swap(u,v);
  int dist=v-u+1;
  int pos=u;
  P res=P((1<<26),(1<<26));

  for(int I=26;I>=0;I--){
    int i=(1<<I);
    if(dist>=i){
      dist-=i;
      res=min(res,dp[pos][I]);
      pos+=i;
    }
  }

  return g[res.second];
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    scanf("%d",&a);
    for(int j=0;j<a;j++){
      scanf("%d",&b);
      G[i].push_back(b);
    }
  }

  rec(0,-1,0);


  for(int i=0;i<(int)g.size();i++)
    dp[i][0]=P(d[g[i]],i);

  int K=1;
  for(int k=1;k<26;k++){
    for(int i=0;i<(int)g.size();i++){
      dp[i][k]=dp[i][k-1];
      int j=i+K;
      if(j>=(int)g.size())j=g.size()-1;
      dp[i][k]=min(dp[i][k],dp[j][k-1]);
    }
    K*=2;
  }
  
  cin>>Q;


  for(int i=0;i<Q;i++){
    scanf("%d %d",&a,&b);
    printf("%d\n",lca(a,b));
  }

  return 0;
}

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main() {
  int n;
  cin >> n;
  vector<int> v(100,0);
  
  rep(i,n){
    cin >> v[i];
  }
  
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  int A = 0;
  int B = 0;
  rep(i,50){
    A += v[2*i];
    B += v[2*i+1];
  }
  
  cout << A-B << endl;
}

Measured memory_bytes: 3612
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();

		// 計算
		int max = 0;
		for (int i = 1; i < N; i++) {
			String X = S.substring(0, i);
			String Y = S.substring(i);
			String[] split = X.split("");
			HashSet<String> mapX = new HashSet<String>();
			for (int j = 1; j < split.length; j++) {
				mapX.add(split[j]);
			}
			int count = 0;
			for (String charX : mapX) {
				if (Y.contains(charX)) {
					count++;
				}
			}
			if (count > max) {
				max = count;
			}
		}

		// 出力
		System.out.println(max);

		return;
	}
}


Measured memory_bytes: 24020
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,N;
  cin>>H>>N;
  int A[N];
  REP(i,N)cin>>A[i];
  lint S=0;
  REP(i,N)S+=A[i];
  cout<<(S>=H?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
int modexp(int x, int y)
{
	int mod = MOD,res = 1;
    x = (x % mod + mod) % mod;
    while(y)
    {
        if(y & 1)res = (res*x) % mod;
        y >>= 1;
        x = ((x%mod)*(x%mod)) % mod;
    }
    return res; 
}
int modInverse(int x)
{
	return modexp(x,MOD-2)%MOD;
}

int choose(int n,int r)
{
  const int mod = MOD;
  int a = 1, b = 1;
  
 for(int i = 0; i < r; i++)
 {
   a = ((a%mod)*((n-i)%mod))%mod;
   b = ((b%mod)*((1+i)%mod))%mod;
 }
  
  int ans = ((a%mod)*((modInverse(b)%mod)%mod))%mod;
  
  return ans%mod;
}
  
int32_t main()
{
  
  int n,a,b;
  cin >> n >> a >> b ;
  
  int ans = (modexp(2,n)%MOD - 1)%MOD;
  	
  int ans1 = (choose(n,a)%MOD + choose(n,b)%MOD)%MOD;
  ans = (ans%MOD- ans1%MOD)%MOD;
  
  cout << (ans + MOD)%MOD;
  
  
  
}

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

int main(){
	int n;
	cin >> n;
	long long int  a[n];
	long long int pref[n+1];
	pref[0] = 0;
	for(int i = 0;i<n;i++){
		cin >> a[i];
		pref[i+1] = pref[i] + a[i];
	}

	long long int dp[n][n];
	memset(dp,0x3f,sizeof(dp));
	for(int i =0;i<n;i++){
		dp[i][i] = 0;
	}

	for(int l = 2;l<=n;l++){
		for(int i = 0;i<n-l+1;i++){
			int j = i+l-1;
			for(int k = i;k<j;k++){
				dp[i][j] = min(dp[i][j],(dp[i][k]+dp[k+1][j])+(pref[k+1]-pref[i] + pref[j+1]-pref[k+1]));
			}
		}
	}

	// for(int i =0;i<n;i++){
	// 	for(int j = 0;j<n;j++){
	// 		cout << dp[i][j] << " ";
	// 	}cout << endl;
	// }
	cout << dp[0][n-1] << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
const int N=200500;

ll a[32][32];
ll dp[1<<16];
int main(){FIN;
	int n;cin>>n;
	fore(i,0,n)fore(j,0,n)cin>>a[i][j];
	fore(m,0,1<<n){
		ll s=0;
		fore(i,0,n)if(m&(1<<i))
			fore(j,i+1,n)if(m&(1<<j)){
				s+=a[i][j];
		}
		dp[m]=s;
		for(int s=0;s=(s-m)&m;){
			if(s==m)continue;
			dp[m]=max(dp[m],dp[s]+dp[m^s]);
		}
	}
	cout<<dp[(1<<n)-1]<<"\n";
}

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

using namespace std;

int main()
{string x;
char y[10];
cin>>x;int s=0;
for(int i=0;i<x.size();i++)
{if(x[i]=='0'||x[i]=='1')
{
    y[s]=x[i];
    s++;
}
else
{for(int j=s-1;j>=0;j--)
if(y[j]=='0'||y[j]=='1')
    {y[j]='l';break;cout<<"lll";}
}
    
}
for(int i=0;i<x.size();i++)
if(y[i]=='0'||y[i]=='1')
cout<<y[i];
cout<<endl;
return 0;
}


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

int main() {
  int count = 0;
  char a[3];
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  char b[3];
  for(int i = 0; i < 3; i++){
    cin >> b[i];
  }
  for (int i=0; i<3; i++) {
    if(a[i] == b[i]){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*--------------------------------------------------------------------*/


signed main(){
  int n;
  cin>>n;
  vi x(n),y(n);
  rep(i,n) cin>>x[i]>>y[i];
  
  map<pii,int> cnt;
  rep(i,n)rep(j,n){
    if(i==j) continue;
    pii k=make_pair(x[i]-x[j],y[i]-y[j]);
    if(k.first<0){
      // k.first*=-1;
      // k.second*=-1;
    }
    cnt[k]++;
  }
  int mx=0;
  for(auto pi:cnt){
    if(pi.second>mx){
      mx=pi.second;
    }
  }
  cout<<n-mx<<endl;


  return 0;
}


Measured memory_bytes: 3620
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;
    long INF = 1L << 60;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt(), m = sc.nextInt();
        Edge[] es = new Edge[m];
        for (int i = 0; i < m; i++) {
            es[i] = new Edge(sc.nextInt() - 1, sc.nextInt() - 1, -sc.nextInt());
        }

        Optional<Long> ans = bellmanFord(n, es, 0, n - 1);

        out.println(ans.map(x -> "" + (-x)).orElse("inf"));

        out.flush();
    }

    Optional<Long> bellmanFord(int n, Edge[] es, int src, int dst) {
        boolean[] updated = new boolean[n];

        long[] d = new long[n];

        Arrays.fill(d, INF);
        d[src] = 0;

        for (int i = 0; i < n - 1; i++) {
            for (Edge e : es) {
                if (d[e.t] > d[e.f] + e.c) {
                    d[e.t] = d[e.f] + e.c;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (Edge e : es) {
                if (d[e.t] > d[e.f] + e.c) {
                    d[e.t] = d[e.f] + e.c;
                    updated[e.t] = true;
                }
                if (updated[e.f]) {
                    updated[e.t] = true;
                }
            }
        }

        if (updated[dst])
            return Optional.empty();
        return Optional.of(d[dst]);
    }



    class Edge {
        int f, t;
        long c;
        Edge(int f, int t, long c) {
            this.f = f;
            this.t = t;
            this.c = c;
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

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

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

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

  vi a(n);
  ll sum = 0;
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }

  ll ans = linf, cur = 0;
  rep(i, n-1){
    cur += a[i];
    ans = min(ans, abs(sum-cur-cur));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,a,b = map(int, input().split())
    if (b-a) % 2 == 0:
        print((b-a)//2)
    else:
        if b-a == 1:
            print(min(b-1, n-a))
        else:
            print(min(a-1+(b-a+1)//2, n-b+(b-a+1)//2))

if __name__ == '__main__':
    main()

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

const int INF =pow(10,9);

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin >> A[i] >> B[i];
  }

  vector<vector<int>> dp(N+1,vector<int>(10001,INF));//dp[i][j]を0~i-1までの魔法でj削る時の魔力の最小値とする
  
  for(int i=0;i<H+1;i++){
    dp[0][i]=10000000;
  }
    dp[1][0]=0;
  for(int i=1;i<H+1;i++){
    dp[1][i]=(1+(i-1)/A[0])*B[0];
  }
  
  // cout << dp[1][1] << endl;

  for(int i=1;i<N;i++){
    for(int j=0;j<10001;j++){
      if(j>=A[i])
    dp[i+1][j]=min(dp[i][j],dp[i+1][j-A[i]]+B[i]);
      else
    dp[i+1][j]=min(dp[i][j],B[i]);
    }
  }
  
  cout << dp[N][H] << endl;
  
}


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

int main()
{
  string s;
  string t;
  cin>>s>>t;
  int count=0;
  for(int i=0;i<s.length();i++)
  {
     if(s[i]!=t[i])
     {
       count++;
     }
  }
  cout<<count;
}

Measured memory_bytes: 3916
N, *A = map(int, open(0).read().split())

idx = {A[i]: i for i in range(N)}

ans = 0
idx_l, idx_r = list(range(N + 2)), list(range(N + 2))
for a in range(N, 0, -1):
    i = idx[a]
    l, r = idx_l[i], idx_r[i]
    ans += a * (i - l + 1) * (r - i + 1)
    idx_l[r + 1], idx_r[l - 1] = l, r

print(ans)

Measured memory_bytes: 46864
fn main() {
  let (n, k): (usize, usize) = read_tuple();
  let xys: Vec<(i64, i64)> = read_tuples(n);
  
  let xs = xys.iter().map(|p|p.0).collect::<Vec<_>>();
  let ys = xys.iter().map(|p|p.1).collect::<Vec<_>>();
  let mut ans = i64::max_value();
  for &ix in &xs {
    for &jx in &xs {
      for &iy in &ys {
        for &jy in &ys {
          if ix >= jx || iy >= jy {continue}
          let pin = xys.iter().filter(|&&(x,y)|ix<=x&&x<=jx&&iy<=y&&y<=jy).count();
          if pin >= k {
            ans = std::cmp::min(ans, (jx-ix) * (jy-iy))
          }
        }
      }
    }
  }

  println!("{}", ans)
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_tuples<T1: std::str::FromStr, T2: std::str::FromStr>(n: usize) -> Vec<(T1, T2)> {
  let mut vec: Vec<(T1, T2)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}

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

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

  int h,m,s;
  h=S/3600;
  m=(S/60)%60;
  s=S%60;
  cout<<h<<":"<<m<<":"<<s<<endl;
 return 0;
}



Measured memory_bytes: 3080
#include<stdio.h>
main()
{
    int A,B,C,TIME;
    scanf("%d%d%d",&A,&B,&C);
    if(A>=B && A>=C)
    {
        TIME=B+C;
    }
    else if(B>=A && B>=C)
    {
        TIME=A+C;

    }
    else if (C>=A && C>=B )
    {
        TIME=A+B;
    }
    printf("%d\n",TIME);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int mat[50][50];
int val[50][50];
int tmp[50][50];
int v[50];
int main(){
	int a,b,c,d,e,f;
	while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f),a){
		for(int i=0;i<a;i++)scanf("%d",v+i);
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				mat[i][j]=val[i][j]=tmp[i][j]=0;
		for(int i=0;i<a;i++)mat[i][i]=1;
		for(int i=0;i<a;i++){
			if(i)val[i][i-1]=c;
			val[i][i]=d;
			if(i<a-1)val[i][i+1]=e;
		}
		while(f){
			if(f%2){
				for(int i=0;i<a;i++)
					for(int j=0;j<a;j++)
						tmp[i][j]=0;
				for(int i=0;i<a;i++)
					for(int j=0;j<a;j++)
						for(int k=0;k<a;k++)
							tmp[i][k]=(tmp[i][k]+mat[i][j]*val[j][k])%b;
				for(int i=0;i<a;i++)
					for(int j=0;j<a;j++)
						mat[i][j]=tmp[i][j];
			}
			f/=2;
			for(int i=0;i<a;i++)
				for(int j=0;j<a;j++)
					tmp[i][j]=0LL;
			for(int i=0;i<a;i++)
				for(int j=0;j<a;j++)
					for(int k=0;k<a;k++)
						tmp[i][k]=(tmp[i][k]+val[i][j]*val[j][k])%b;
			for(int i=0;i<a;i++)
				for(int j=0;j<a;j++)
					val[i][j]=tmp[i][j];
		}
		for(int i=0;i<a;i++){
			if(i)printf(" ");
			int ret=0;
			for(int j=0;j<a;j++)ret=(ret+mat[i][j]*v[j])%b;
			printf("%d",ret);
		}
		printf("\n");
	}
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

vector<pint> vp[100001];
int d[100001];
int mx;
void dfs(int s,int par,int dt){
    d[s]=dt;
    if(d[mx]<d[s]) mx=s;
    rep(i,vp[s].size()){
        if(vp[s][i].second!=par){
            dfs(vp[s][i].second,s,dt+vp[s][i].first);
        }
    }
}
int main(){
    int n,sr,ds,co;
    cin>>n;
    rep(i,n-1){
        cin>>sr>>ds>>co;
        vp[sr].pb(mp(co,ds));
        vp[ds].pb(mp(co,sr));
    }
    dfs(0,-1,0);
    memset(d,0,sizeof(d));
    dfs(mx,-1,0);
    cout<<d[mx]<<endl;
    return 0;
}

Measured memory_bytes: 15172
n = int(input())
t, a = map(int,input().split())
h = list(map(int,input().split()))
s = 0
d = t-a
m = abs(d - h[0]*0.006)
for i in range(1,n):
    if m > abs(d - h[i]*0.006):
        s = i
        m = abs(d - h[i]*0.006)
print(s+1)

Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int N,A,B;
  cin >> N;
  if(N==1){
      cout << "Hello World" << endl;
  }if(N==2){
      cin >> A >> B;
      cout << A+B << endl;
  }
 
}

Measured memory_bytes: 256
#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 ALL(n) begin(n), end(n)

int main()
{
    int n;
    cin >> n;
    int x;
    x = n % 10;

    if (x == 3)
    {
        cout << "bon" << endl;
        return 0;
    }

    if (x == 0 || x == 1 || x == 6 || x == 8)
    {
        cout << "pon" << endl;
        return 0;
    }

    cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005
using namespace std;
struct edge{
	int k,next;
}e[N<<1];
int n,home[N],cnt=-1,f[N];
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
void dfs(int k,int F){
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		dfs(e[i].k,k);
		f[k]^=f[e[i].k]+1;
	}
}
int main(){
	memset(home,-1,sizeof(home));
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	if(f[1]) puts("Alice");
	else puts("Bob");
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

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







int main() {
  int n,k;
  cin >> n >> k;
  ll sum = 0;
  if (n==1){
    sum = k;
  }
  else{
  rep (i,n){
   
    if(i==0) sum = k;
    else
    sum *= k-1;
  }
  }
cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

struct node{
    int parent, left, right;
};

void setdepth(node *T, int *d, int id, int depth){
    d[id] = depth;
    if(T[id].left != -1) setdepth(T, d, T[id].left, depth+1);
    if(T[id].right != -1) setdepth(T, d, T[id].right, depth+1);
    return;
}

int setheight(node *T, int *h, int id){
    int hl = 0, hr = 0;
    if(T[id].left != -1){
        hl = setheight(T, h, T[id].left) + 1;
    }
    if(T[id].right != -1){
        hr = setheight(T, h, T[id].right) + 1;
    }

    return h[id] = max(hl, hr);
}

int getsibling(node *T, int id){
    if(T[id].parent == -1) return -1;
    if(T[T[id].parent].left == id) return T[T[id].parent].right;
    else return T[T[id].parent].left;
}

int getdegree(node *T, int id){
    int deg = 0;
    if(T[id].left != -1) deg++;
    if(T[id].right != -1) deg++;
    return deg;
}

string gettype(node *T, int id){
    if(T[id].parent == -1) return "root";
    else if(T[id].left == -1 && T[id].right == -1) return "leaf";
    else return "internal node";
}

int main(void){
    int n, *d, *h, r;
    cin >> n;
    node *T = new node[n];
    d = new int[n];
    h = new int[n];
    rep(i, 0, n){
        T[i].parent = -1;
    }
    rep(i, 0, n){
        int id;
        cin >> id;
        cin >> T[id].left >> T[id].right;
        if(T[id].left != -1) T[T[id].left].parent = id;
        if(T[id].right != -1) T[T[id].right].parent = id;
    }
    rep(i, 0, n){
        if(T[i].parent == -1){
            r = i;
            break;
        }
    }
    setdepth(T, d, r, 0);
    setheight(T, h, r);

    rep(i, 0, n){
        cout << "node " << i << ": parent = " << T[i].parent << ", sibling = " << getsibling(T, i) << ", degree = " << getdegree(T, i) << ", depth = " << d[i] << ", height = " << h[i] << ", " << gettype(T, i) << endl;
    }   
    return 0;
}


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

int main()
{

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

    if(a>=1 && a<=20 && b>=1 && b<=20){
        if(b%a==0) printf("%d\n",a+b);
        else printf("%d\n",b-a);
    }

    return 0;
}


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

using namespace std;
int main(){
   int x;
   cin>>x;
   if(x%2==0){
     int y=x/2;
     cout<<y*y<<endl;
  }else{
     int y=(x-1)/2;
     cout<<y*(y+1)<<endl;
  }
return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <unordered_set>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define DBG1(a) cerr<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define y1 frgrwegreg

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;

const double PI = acos(-1.0);
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 131072;

string s;
int k;


int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios::sync_with_stdio(0);

	cin >> s >>  k;
	FOR (i,0,s.length())
	{
		//cout << k << " "<<'z'-s[i]+1<<endl;
		if (s[i] == 'a') continue;
		if ('z'-s[i]+1 <= k)
		{
			int num = ('z'-s[i])+1;
			k -= num;
			s[i] = 'a';
		}
		//cout << k << endl;
 	}
	k %= ('z'-'a'+1);
	FOR (i,0,k)
	{
		if (s[SZ(s)-1] == 'z') s[SZ(s)-1] = 'a';
		else s[SZ(s)-1]++;
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

double s[210][22];
double h[210][22];

signed main(){
    
    double n, m; cin >> n >> m;
    vector<int> k(n);
    
    for(int i = 0; i < n; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j] >> h[i][j];
        }
    }
    
    double ans = 0.0;

    for(int ii = 0; ii < n; ii++){

        vector<vector<double> > dp(n + 1, vector<double> (m + 1, -1.0));
        dp[0][0] = 0.0;
        for(int i = 0; i < n; i++){
        
            if(ii == i){
                for(int j = 0; j <= m; j++) dp[i + 1][j] = dp[i][j];
                continue;
            }


            for(int j = 0; j <= m; j++){
                if(dp[i][j] < 0.0) continue;

                int nj = j;
                dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j]);
                double val = 0.0;
                for(int l = 0; l < k[i]; l++){
                    // とるぜ
                    nj += s[i][l] * h[i][l];
                    val += h[i][l];
                    if(nj <= m) dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + val); 
                }
            }
        }
        
        for(int j = 0; j <= m; j++){
            
            double rest = m - j;
            double high = 0.0;

            for(int l = 0; l < k[ii]; l++){
                if(rest >= s[ii][l] * h[ii][l]){
                    rest -= s[ii][l] * h[ii][l];
                    high += h[ii][l];
                }else{
                    high += rest / s[ii][l];
                    break;
                }
            }
            
            if(dp[n][j] != -1.0) ans = max(ans, dp[n][j] + high);
        }

    }

    printf("%.10f\n", ans);

    return 0;
}




Measured memory_bytes: 3488
package main;

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

func main() {
	sc := NewScanner()
	_, _ = sc.NextInt(), sc.NextInt()
	A := sc.NextIntArray()
	mn := A[0]
	diff := 0
	diffCount := 0
	mx := A[0]
	for _, v := range A {
		flag := false
		if mn > v {
			mn = v
			flag = true
			mx = mn
		}
		if mx < v {
			mx = v
			flag = true
		}
		if flag {
			if diff < mx - mn {
				diff = mx - mn
				diffCount = 1
			} else if diff == mx - mn {
				diffCount++
			}
		}
	}
	fmt.Println(diffCount)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;

const int N = 5005;
const int K = 5005;

int n, k;
int a[N];
int dp1[N][N], dp2[N][N];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  dp1[0][0] = 1;
  dp2[0][0] = 1;
  for (int i = 0, j = n - 1; i < n; i++, j--) for (int s = 0; s < K; s++) {
    if (s + a[i] < K) dp1[i + 1][s + a[i]] |= dp1[i][s];
    dp1[i + 1][s] |= dp1[i][s];
    if (s + a[j] < K) dp2[i + 1][s + a[j]] |= dp2[i][s];
    dp2[i + 1][s] |= dp2[i][s];
  }
  for (int i = 0; i < n; i++) for (int j = 1; j < K; j++) dp2[i][j] += dp2[i][j - 1];
  int ans = 0;
  for (int i = 0; i < n; i++) for (int j = 0; j < K; j++) {
    if (dp1[i][j] == 0) continue;
    int x = k - a[i] - j;
    int y = k - 1 - j;
    if (y < 0) break;
    if (dp2[n - i - 1][y] - (x - 1 >= 0 ? dp2[n - i - 1][x - 1] : 0) == 0) continue;
    ans++;
    break;
  }
  printf("%d\n", n - ans);
  return 0;
}

Measured memory_bytes: 195840
using System;
using System.Collections.Generic;

namespace AtcoderProgram
{

    class Program
    {
        static Dictionary<int, int> fib = new Dictionary<int, int>();

        static void createfib(int n)
        {
            fib.Add(-1, 1);
            fib.Add(0, 1);
            fib.Add(1, 1);
            fib.Add(2, 2);
            for(int i=3; i<n;i++)
            {
                int a, b;
                fib.TryGetValue(i - 1, out a);
                fib.TryGetValue(i - 2, out b);
                fib.Add(i, a + b);
            }
        }

        static void Main(string[] args)
        {
            string[] nm = Console.ReadLine().Split(' ');
            int n = int.Parse(nm[0]);
            int k = int.Parse(nm[1]);

            if (k==1 || n == k)
            {
                Console.WriteLine(0);
                return;
            }

            Console.WriteLine(n-k);
        }
    }
}


Measured memory_bytes: 13152
using System;
using System.Collections.Generic;

public class Hello{
	public static void Main(){
		
		var line = System.Console.ReadLine();
		var charList = new List<Character> ();
		for(var i = 0;i< line.Length;i++){
			bool countFlag = false;
			foreach(var chara in charList){
				if (chara.c == line [i]) {
					chara.count++;
					countFlag = true;
				}
			}
			if(countFlag == false){
				var newChara = new Character ();
				newChara.c = line [i];
				newChara.count++;
				charList.Add (newChara);
			}

		}
		string beawrifulStrings = "Yes";
		foreach(var chara in charList){
			if(chara.count % 2 != 0){
				beawrifulStrings = "No";
			}
		}

		System.Console.WriteLine(beawrifulStrings);
	}
}

public class Character{
	public char c;
	public int count;
	public Character(){
	}
}



Measured memory_bytes: 2776
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
 
int main(){
  ll K; cin>>K;
  ll ans;
  int x = 7 % K;
  set<int> s; //ランダム・アクセスが必要なくて、データ追加が動的に何度も行われ、平行して検索するような場合は vector よりも set
  int i = 1;
  while(s.count(x) == 0){ //0以外だったらループに入っている
    if(x == 0){ //割り切れたら
      cout<<i;
      return 0;
    }
    s.insert(x);
    x = (x*10+7) % K;
    i++;
  }
  cout<<-1;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
#define int ll

void read() {
	int n, k;
	cin >> n >> k;
	n %= k;
	set<int> have;
	while (true) {
		if (have.count(n)) {
			break;
		}
		have.insert(n);
		n = abs(n - k);
	}
	cout << *have.begin();
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << max({a+b,a-b,a*b}) << endl;
  return 0;
}


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

int main(int argc, const char * argv[]) {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int a, b;
    cin >> a >> b;
    int c = 0;
    for (int i=0; i<b-a+1; i++){
        if(((a+i)/10000 == (a+i)%10) &&
           (((a+i)/1000)%10 == ((a+i)/10)%10) ){
            c++;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
hlist = []
wlist = []
a = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            hlist.append(i)
            wlist.append(j)
for i in set(hlist):
    for j in set(wlist):
        print(a[i][j], end ="")
    print()

Measured memory_bytes: 4724
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
char ss[105];
int K;
ll solve1(char *s){
    ll res = 0;
    int n = strlen(s);
    res += 9ll * (n - 1);
    res += s[0] - '0';
    return res;
}
ll solve2(char *s){
    ll ans = 0;
    int n = strlen(s);
    for (int i = 1; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            ans += 81ll;
    // 开头还挺小
    for (int i = 1; i < s[0] - '0'; ++i)
        for (int j = 1; j < n; ++j)
            ans += 9ll;
    // 开头定下
    int t = 1;
    while (t < n && s[t] == '0')
        ++t;
    if (t < n)
        ans += solve1(s + t);
    return ans;
}
ll solve3(char *s){
    ll ans = 0;
    int n = strlen(s);
    for (int i = 1; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            for (int k = j + 1; k < n; ++k)
                ans += 729ll;
    // 开头还挺小
    for (int i = 1; i < s[0] - '0'; ++i)
        for (int j = 1; j < n; ++j)
            for (int k = j + 1; k < n; ++k)
                ans += 81ll;
    // 开头不变了
    int t = 1;
    while (t < n && s[t] == '0')
        ++t;
    if (t < n){
        ans += solve2(s + t);
    }
    return ans;
}
void init(){
    scanf("%s", ss);
    assert(ss[0] != '0');
    K = read();
}
void solve(){
    ll ans = 0;
    if (K == 1) ans = solve1(ss);
    if (K == 2) ans = solve2(ss);
    if (K == 3) ans = solve3(ss);
    printf("%lld\n", ans);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll a,b,c,d,e,ans=0;
ll x[100005],y[100005],z[100005];
float st;
stack <ll> ana;


ll digi(ll x){
	ll nono=0;
	while(x>0){
		nono += x%10;
		x/=10;
	}
	return nono;
}
int main(){
	cin>>n;
	x[1]=1;
	st=INF;
	for(i=1000000000000000;i>=1;i--){
		//pe("調べ中");p(i);
		if((float)(i*1.000/digi(i))<=st){
			ana.push(i);
			st = i*1.000/digi(i);
		}
		if(i>=100000000000000 && i%1000000000000==999999999999)i-=999999999999;
		if(i>=1000000000000 && i%10000000000==9999999999)i-=9999999999;
		if(i>=10000000000 && i%100000000==99999999)i-=99999999;
		if(i>=100000000 && i%1000000==999999)i-=999999;
		if(i>=1000000 && i%10000==9999)i-=9999;
		if(i>=10000 && i%100==99)i-=99;
	}
	while(n>0){
		p(ana.top());
		ana.pop();
		n--;
	}
	return 0;
}

Measured memory_bytes: 5248
#include<iostream>

using namespace std;

int main(){
    unsigned long long n;
    cin >> n;
    char s[n];
    unsigned long long ans = 0;
    for(int i=0;i<n;i++){
        cin >> s[i];
        if(s[i]=='E')ans++;
    }

    if(s[0]=='E')ans--;
    
    unsigned long long tmp = ans;
    for(int i=1;i<n;i++){
        if(s[i-1]=='W')tmp++;
        if(s[i]=='E')tmp--;
        if(tmp<ans)ans = tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
loop do
    h,w = gets.split(" ").map do |i| i.to_i end
    if h + w == 0 then
        break
    else
        (1..h).each do |high|
            (1..w).each do |wide|
                if high == 1 || high == h || wide == 1 || wide == w then
                    print "#"
                else
                    print "."
                end
            end
            puts ""
        end
        puts ""
    end
end

Measured memory_bytes: 8740
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()

void Main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    cout << a[2] << " " << a[0] << " " << a[1] << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5];
int main()
{
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	int ans=0,num=1;
	for(int i=0;i<2;++i)
	{
		ans+=(a[2]-a[i])/2;
		a[i]+=(a[2]-a[i])/2*2;
		if(a[i]==a[2]) ++num;
	}
	if(num==1) ++ans;
	else if(num==2) ans+=2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc082b()
}

fun abc082b() {
    val (s, t) = (1..2).map { readLine()!! }

    val answer =
        if (s.toCharArray().sorted().joinToString() < t.toCharArray().sortedDescending().joinToString()) "Yes" else "No"

    println(answer)
}


Measured memory_bytes: 35852
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG



int main() {
  ll N;
  cin >> N;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));
  
  ll ans = 0;

  for (ll i = 1; i<=N; i++){
    if(i % 3 != 0 && i % 5 !=0 ){
      ans += i;
    }
  }
  cout << ans << endl;

  return 0;
}


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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String input = br.readLine();
			
			if(input.equals("#")){
				break;
			}
			
			String result = solve(input);
			
			System.out.println(result);
		}
	}
	
	public static String solve(String str){
		str = str.replaceAll("north", "n");
		str = str.replaceAll("west", "w");
		
//		System.out.println(str);
		
		int numer;
		if(str.charAt(str.length()-1) == 'n'){
			numer = 0;
		}
		
		else {
			numer = 90;
		}
		int denomi = 1;
		for(int i = str.length() - 2; i >= 0 ; i--){
			numer *= 2;
			denomi *= 2;
			
			if(str.charAt(i)=='n'){
				if(numer != 0){
					numer -= 90;
				}
			}
			else {
				if(numer != denomi*90){
					numer += 90;
				}
			}
			
			
			
//			System.out.println("current angle "+numer+"/"+denomi);
		}
		
		//?´????
		while(denomi > 1){
			if(numer % 2 == 0){
				numer /= 2;
				denomi /= 2;
			}
			else {
				break;
			}
		}
		
		if(denomi == 1){
			return ""+numer;
		}
		String result = numer+"/"+denomi;
		return result;
	}

}

Measured memory_bytes: 24332
N = int(input())
A = {}
S = 0
MS = 0
for i in range(2):
    A[i] = list(map(int,input().split()))
for i in range(N):
    S = 0
    for j in range(i+1):
        S += A[0][j]
    for k in range(N-i):
        S += A[1][N-k-1]
    if S > MS:
        MS = S
print (MS)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int i,j,ans,N,k,m;
cin>>N;
ans=0;
for(i=0;i<N;i++){
	if(4*i>N)break;
	for(j=0;j<N;j++){
		if(7*j>N) break;	
k=4*i+7*j;
if(k>N) break;
if(k==N) ans++;
}
}
if(ans>0)
cout <<"Yes"<<endl;else cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 256
N = input()
t, a = map(int, raw_input().split())
for i in xrange(N-1):
    new_t, new_a = map(int, raw_input().split())
    d = max((t-1)/new_t+1, (a-1)/new_a+1, 1)
    t, a = new_t*d, new_a*d
print t+a


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

using namespace std;

const int N=2e5+10;
const int mod=1e9+7;
typedef long long ll;

ll a[N],b[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll sum=0,ans=0;
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=b[i-1]+a[i];
		b[i]%=mod;
	}
	for (int i=1;i<=n;i++)
	{
		ll temp=(b[n]+mod-b[i])%mod;
		ans=(ans+temp*a[i])%mod;
	}
	cout<< ans;
	return 0;
} 

Measured memory_bytes: 6748
#include<stdio.h>
#include<algorithm>
using namespace std;
#define max 1000000000
int main()
{
	int m,n;
	int dp[1100][1100],dis[1100],weather[1100];
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&dis[i]);
	} 
	for(int j=1;j<=m;j++){
		scanf("%d",&weather[j]);
	}
	for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++){
			if(i<=m-n&&j==0) {dp[i][j]=0;}
			else if(i<j) {dp[i][j]=max;}
			else if(i-j>=n) {dp[i][j]=max;}
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
		dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+weather[i]*dis[j]);
		}
	}
	printf("%d\n",dp[m][n]);
	return 0;
}

Measured memory_bytes: 5740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const LL P = 1e9+7;
const int N = 205;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
char g[N][N];
bool v[N];
int group[N];

bool check(int x, int gp){
	group[x] = gp;
	v[x] = true;
	rep(i,1,n) if(g[x][i]) {
		if(group[i]==group[x]) return false;
		if(!v[i] && !check(i,1-gp)) return false;
	}
	return true;
}

int bfs(int x){
	queue<ar2> Q;
	Q.push({x,1});
	memset(v,0,sizeof v);
	v[x] = true;
	int res;
	while(!Q.empty()){
		ar2 y = Q.front();
		res = y[1];
		Q.pop();
		rep(i,1,n) if(!v[i] && g[y[0]][i]){
			Q.push({i,y[1]+1});
			v[i] = true;
		}
	}
	return res;
}

int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%s",g[i]+1);
	rep(i,1,n)rep(j,1,n)g[i][j]-='0';
	//rep(i,1,n)rep(j,1,n)printf("%d%c",g[i][j],j==n?'\n':' ');
	memset(v,0,sizeof v);
	memset(group,-1,sizeof group);
	rep(i,1,n)if(!v[i] && !check(i,0)){
		cout<<"-1\n";
		return 0;
	}
	int ans = 0;
	rep(i,1,n){
		ans = max(ans, bfs(i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
alp = {"a": 0, "b": 0, "c": 0, "d": 0, "e": 0, "f": 0, "g": 0, "h": 0, "i": 0, "j": 0,
       "k": 0, "l": 0, "m": 0, "n": 0, "o": 0, "p": 0, "q": 0, "r": 0, "s": 0, "t": 0, 
       "u": 0, "v": 0, "w": 0, "x": 0, "y": 0, "z": 0}
while True:
    try:
        s = input()
    except EOFError:
        break

    for i in s:
        if alp.get(i.lower()) != None:
            alp[i.lower()] += 1

for key, value in alp.items():
    print(key,':', value)


Measured memory_bytes: 5576
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
b_stock = 0
gekitai = 0

for i in range(n):
    if b_stock <= a[i]:
        gekitai += b_stock
        a[i] -= b_stock
        b_stock = 0
    else:
        gekitai += a[i]
        b_stock = 0
        a[i] = 0

    if b[i] <= a[i]:
        gekitai += b[i]

    else:
        gekitai += a[i]
        b_stock += b[i] - a[i]


if b_stock <= a[n]:
    gekitai += b_stock
else:
    gekitai += a[n]


print(gekitai)


Measured memory_bytes: 19648
#include <stdio.h>
using namespace std;
int main() {
	int a, b;
	int c[9];
	c[0] = 0;
	c[1] = 10;
	for(int i = 2; i < 10; i++) {
		c[i] = c[i - 1] * 10;
	}
	while(scanf("%d %d", &a, &b) != EOF) {
		int i = 0;
		while(a + b >= c[i]) i++; 
		printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 1028