akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>

using namespace std;

const int INF = 100000;

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

	char field[h][w];
	int nb=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> field[i][j];
			if(field[i][j] == '#') nb++;
		}
	}

	int dis[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			dis[i][j] = INF;
		}
	}
	dis[0][0] = 0;

	int vx[4] = {1,0,-1,0}, vy[4] = {0,-1,0,1};
	int nx,ny;
	queue<pair<int,int>> q;
	pair<int,int> x_y;
	q.push(make_pair(0,0));
	while(q.size() != 0){
		x_y = q.front();
		q.pop();
		for(int k=0;k<4;k++){
			nx = x_y.first + vx[k];
			ny = x_y.second + vy[k];
			if(0<=nx && nx<w && 0<=ny && ny<h && field[ny][nx] == '.'){
				q.push(make_pair(nx,ny));
				dis[ny][nx] = min(dis[ny][nx],dis[x_y.second][x_y.first] + 1);
				field[ny][nx] = '#';
			}
		//cout << bfs[i][j] << " ";
		}
	}
	//cout <<"\n";
	//cout << h*w << " " << bfs[h-1][w-1] << " " << nb << "\n";
	
//	for(int i=0;i<h;i++){
//		for(int j=0;j<w;j++){
//			cout << dis[i][j];
//		}
//		cout << "\n";
//	}
	if(dis[h-1][w-1] > h*w) cout << -1 << "\n";
	else cout << h*w-(dis[h-1][w-1]+1) - nb << "\n";
	return 0;
}


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

using namespace std;

int solve(int n, int k, int s)
{
  if(n < 0 || k < 0 || s < 0) return 0;
  if(n == 0 && k == 0 && s == 0) return 1;
  return solve(n-1, k-1, s-n) + solve(n-1, k, s);
}

int main()
{
  int n, k, s;
  while(cin >> n >> k >> s, n || k || s){
    cout << solve(n, k, s) << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
n, m = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
ys = gets.split.map(&:to_i)

MOD = 10**9+7

xd, yd = [], []
(n - 1).times do |i|
    xd[i] = xs[i+1] - xs[i]
end
(m - 1).times do |i|
    yd[i] = ys[i+1] - ys[i]
end


xsum = 0
(n - 1).times do |i|
    up = n - 1 - i
    down = i + 1
    pattern = up * down % MOD
    xsum = (xsum + pattern * xd[i]) % MOD
end

ysum = 0
(m - 1).times do |i|
    up = m - 1 - i
    down = i + 1
    pattern = up * down % MOD
    ysum = (ysum + pattern * yd[i]) % MOD
end

puts xsum * ysum % MOD

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

long long N, K, A[100009], maxn = 0;

long long gcd(long long p, long long q) {
	if (q == 0) return p;
	return gcd(q, p%q);
}

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) { cin >> A[i]; maxn = max(maxn, A[i]); }
	long long G = A[1];
	for (int i = 2; i <= N; i++) G = gcd(G, A[i]);
	if (K%G != 0 || maxn < K) cout << "IMPOSSIBLE" << endl;
	else cout << "POSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a,b,c[1001],d[1101],i,m=1001;
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%d %d",&c[i],&d[i]);
		if(d[i]<=b){
			if(c[i]<m){
				m=c[i];
			}
		}
	}
	if(m==1001){
		printf("TLE");
	}else{
		printf("%d",m);
	}
	return 0;
}

Measured memory_bytes: 128
s = input()
a = 1
b = 0
c = 0
if s[0] == "A":
    a = a * 1
else:
    a = a * 0
if s[1] != "C":
    for i in range(2, len(s) - 1):
        if s[i] == "C":
            b = b + 1
            if c == 0:
                c = i
    if b == 1:
        a = a * 1
    else:
        a = a * 0
else:
    a = a * 0

ss = s[1:c] + s[c + 1:len(s) + 1]
#print(ss)
if ss.islower():
    a = a * 1
else:
    a = a * 0

if a == 1:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3064
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int w,h,ans;
int ga[101][101],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char s[101];

void bfs(int y,int x,int n)
{
	ga[y][x]=0;
	for(int i=0;i<4;i++){
		if(0<=y+dy[i]&&0<=x+dx[i]&&y+dy[i]<h&&x+dx[i]<w&&ga[y+dy[i]][x+dx[i]]==n) bfs(y+dy[i],x+dx[i],n);
	}
	return;
}

int main()
{while(1){
	scanf("%d %d",&h,&w);
	ans=0;
	if(!h&&!w) return 0;
	memset(ga,0,sizeof(ga));
	for(int i=0;i<h;i++){
		scanf("%s",s);
		for(int j=0;j<w;j++){
			if(s[j]=='@') ga[i][j]=1;
			else if(s[j]=='#') ga[i][j]=2;
			else ga[i][j]=3;
		}
	}
	for(int i=0;i<w;i++) for(int j=0;j<h;j++){
		if(ga[j][i]) {ans++; bfs(j,i,ga[j][i]);}
	}
	cout<<ans<<endl;
}}

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

int main()
{
  string s;
  cin >> s;
  int len = s.size();
  int count = 0;
  for (int i = 0; i < len / 2; i++) {
    if (s[i] != s[len - i -1])
      count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int A[][] = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < m; i++) {
			b[i] = scanner.nextInt();
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				c[i] = A[i][j] * b[j] + c[i];
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.println(c[i]);
		}

	}
}



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

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    Graph G(n);
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }

    vector<pair<int, int>> dis(n, make_pair(-1, -1));
    queue<int> que;

    // calc Takahashi distance
    que.push(u);
    dis.at(u).first = 0;
    while (!que.empty()) {
        int cur = que.front(); que.pop();
        for (int x : G.at(cur)) {
            if (dis.at(x).first != -1) {
                continue;
            }
            dis.at(x).first = dis.at(cur).first + 1;
            que.push(x);
        }
    }
    // calc Aoki distance
    que.push(v);
    dis.at(v).second = 0;
    while (!que.empty()) {
        int cur = que.front(); que.pop();
        for (int x : G.at(cur)) {
            if (dis.at(x).second != -1) {
                continue;
            }
            dis.at(x).second = dis.at(cur).second + 1;
            que.push(x);
        }
    }

    int ans = -1;
    for (int i=0; i<n; i++) {
        if (dis.at(i).first < dis.at(i).second) {
            ans = max(ans, dis.at(i).second - 1);
        }
    }

    int tmp = -1;
    bool onlyone = true;
    for (int i=0; i<n; i++) {
        if (dis.at(i).first == 1) {
            if (tmp != -1) {
                onlyone = false;
                break;
            } else {
                tmp = i;
            }
        }
    }
    if (onlyone && dis.at(tmp).second == 0) {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    long long int i,arr[10000];

   for(i=0;i<10;i++)
       cin>>arr[i];
       sort(arr,arr+10);
   for(i=9;i>=7;i--)
       cout<<arr[i]<<endl;

}

Measured memory_bytes: 1180
n = int(input())
d = dict()

for _ in range(n):
    s = input()

    if s in d:
        d[s] += 1
    else:
        d[s] = 1


items = list(d.items())
max_num = max([v[1] for v in items])
ans = []

for k,v in items:
    if max_num == v:
        ans.append(k)

ans.sort()

for v in ans:
    print(v)


Measured memory_bytes: 45660
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

long long K;

void dfs(int v, const std::vector<std::vector<int>>& edges, std::vector<bool>& memo, long long& ans)
{
  memo[v] = false;
  for (int i = 0; i < edges[v].size() - 1; ++i)
  {
    long long val = K - i - 2;
    ans *= val;
    ans %= MOD;
  }
  if (ans == 0)
    return;
  for (auto u: edges[v])
  {
    if (memo[u])
    {
      dfs(u, edges, memo, ans);
    }
  }
}

int main()
{
  int N;
  std::cin >> N >> K;
  std::vector<std::vector<int>> edges(N);
  for(int i = 0; i < N - 1; ++i)
  {
    int a, b;
    std::cin >> a >> b;
    --a;
    --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  long long ans = K;
  std::vector<bool> memo(N, true);
  memo[0] = false;
  for (int i = 0; i < edges[0].size(); ++i)
  {
    long long val = K - i - 1;
    ans *= val;
    ans %= MOD;
  }

  for (auto v: edges[0])
  {
    dfs(v, edges, memo, ans);
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 11520
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = 10 ** 9
for i in range(N - K + 1):  # iからi+K-1の範囲
    if x[i] >= 0:
        ans1 = 10 ** 9
        ans2 = x[i + K - 1]
    elif x[i + K - 1] <= 0:
        ans1 = abs(x[i])
        ans2 = 10 ** 9
    else:
        ans1 = abs(x[i]) * 2 + x[i + K - 1]
        ans2 = abs(x[i]) + x[i + K - 1] * 2
    ans = min(ans, ans1, ans2)
print(ans)


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];

    unordered_map<string, ll> dic;
    for (int i = 0; i < N; ++i) {
        string s = S[i];
        sort(s.begin(), s.end());
        dic[s] += 1;
    }
    ll ans = 0;
    for (auto p : dic) {
        if (p.second > 1) {
            ans += (p.second * (p.second - 1)) / 2;
        }
    }
    cout << ans << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 16164
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, n) = (v[0], v[1]);
    let mut items = vec![];
    for i in 0..n {
        let v = read_vec::<usize>();
        let (v, w) = (v[0], v[1] as i64);
        items.push((v, w));
    }

    let mut dp = vec![std::i64::MAX; h + 1];
    dp[0] = 0;
    for i in 0..n {
        for cur_h in 0..h {
            if dp[cur_h] == std::i64::MAX {
                continue;
            }
            let idx = min(cur_h + items[i].0, h);
            dp[idx] = min(dp[cur_h] + items[i].1, dp[idx]);
        }
    }
    println!("{}", dp[h]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
n=int(input())
A=list(map(int, input().split()))
if len(A)%2==0:
    for i in range(len(A)-1,0,-2):
        print(A[i], end=' ')
    for i in range(0,len(A),2):
        print(A[i], end=' ')
if len(A)%2==1:
    for i in range(len(A)-1,-1,-2):
        print(A[i], end=' ')
    for i in range(1,len(A),2):
        print(A[i], end=' ')


Measured memory_bytes: 26180
#include <iostream>
#include <algorithm>

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

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(string s) {
  bool pred = (find(ALL(s), 'C') - s.begin()) +
                  (find(s.rbegin(), s.rend(), 'F') - s.rbegin()) <
    (int)s.size();
  cout << (pred ? YES : NO) << endl;
}

int main() {
  string s;
  cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; (i) < (n); ++(i))
#define REP3(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;

int solve(int n, vector<int> & a) {
    sort(ALL(a));
    unordered_set<int> index;
    REP (i, n) index.insert(a[i]);

    int answer = 2;
    unordered_map<ll, int> used;
    REP (i, n) {
        REP3 (j, i + 1, n) {
            int d = a[j] - a[i];
            if (not index.count(a[i] + 2 * d)) continue;
            auto key = ((ll)(a[i] % d) << 32) | d;
            if (used.count(key) and a[j] <= used[key]) continue;
            int len = 2;
            while (index.count(a[i] + len * d)) {
                ++ len;
            }
            used[key] = a[i] + (len - 1) * d;
            answer = max(answer, len);
        }
    }

    return answer;
}

signed main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    cout << solve(n, a) << endl;
    return 0;
}



Measured memory_bytes: 84932
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>

using  ll = long long;
using ull = unsigned long long;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
constexpr ll kINF = 1152921504606846976;//2^60
constexpr double kEPS = 1e-6;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define rep(i,n) REP(i,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep(i,n) RREP(i,n)
#define mp make_pair
#define fi first
#define sc second

using P = pair<ll,ll>;
using Q = pair<P,P>;

map<Q, double> memo;

ll N;
ll a[300];

double rec(Q q) {
  if (memo.find(q) != memo.end()) return memo[q];

  double ret = 0.0;

  ll i = q.first.first;
  ll j = q.first.second;
  ll k = q.second.first;
  ll l = q.second.second;

  double p = (double)i / (i + j + k + l);

  if (j > 0) ret += rec(Q(P(i+1,j-1),P(k,l))) * (double)j / (j + k + l) + 1 / (1 - p) / (1 - p) * ((double)j / (i + j + k + l));
  if (k > 0) ret += rec(Q(P(i,j+1),P(k-1,l))) * (double)k / (j + k + l) + 1 / (1 - p) / (1 - p) * ((double)k / (i + j + k + l));
  if (l > 0) ret += rec(Q(P(i,j),P(k+1,l-1))) * (double)l / (j + k + l) + 1 / (1 - p) / (1 - p) * ((double)l / (i + j + k + l));

  return memo[q] = ret;
}

double dp[310][310][310];

int main(void) {
  cin >> N;
  rep (i, N) cin >> a[i];

  ll c[4];
  rep(i,4)c[i] = 0;
  rep(i, N) {
    c[a[i]]++;
  }

  rep(l, N+1) {
    rep(k, N+1) {
      if (l + k > N) break;
      rep(j, N+1) {
        ll i = N - j - k - l;
        if (i < 0) break;
        if (i == N) {
          dp[j][k][l] = 0.0f;
          continue;
        }
        dp[j][k][l] = 1.0;
        if (j > 0) dp[j][k][l] += dp[j-1][k][l]   * (double)j / N;
        if (k > 0) dp[j][k][l] += dp[j+1][k-1][l] * (double)k / N;
        if (l > 0) dp[j][k][l] += dp[j][k+1][l-1] * (double)l / N;
        double p = (double)i / N;
        dp[j][k][l] /= (1 - p);
      }
    }
  }

  printf("%.15f\n", dp[c[1]][c[2]][c[3]]);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  int ans = 0, K = 1;
  for (int i = 1; i < N; i++) {
    if (A.at(i) == A.at(i - 1)) {
      K++;
    }
    else {
      ans += K / 2;
      K = 1;
    }
  }
  ans += K / 2;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();

		long ans = Long.MAX_VALUE;

		for(int k=0; k<2; k++) {
			if(k==1) {
				int tmp = h;
				h=w;
				w=tmp;
			}
			//初めに縦
			for(int i=1; i<w; i++) {

				if(w>=3){
					//縦縦
					long w1 = i;
					long w2=(w-w1)/2;
					long w3=w2;
					if((w-w1)%2!=0) {
						w3++;
					}
					long h1=h;
					long h2=h;
					long h3=h;

					ans = Math.min(ans, calc(w1*h1, w2*h2, w3*h3));
				}

				{
					//縦横
					long w1 = i;
					long w2 = (w-w1);
					long w3 = w2;

					long h1=h;
					long h2=h/2;
					long h3=h2;
					if(h%2 != 0) {
						h3++;
					}

					ans = Math.min(ans, calc(w1*h1, w2*h2, w3*h3));
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}


	private long calc(long v1, long v2, long v3) {
		long smax = v1;
		long smin = v1;
		smax = Math.max(smax, v2);
		smax = Math.max(smax, v3);
		smin = Math.min(smin, v2);
		smin = Math.min(smin, v3);
		return smax-smin;
	}
}


Measured memory_bytes: 36116
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int dp[100010];
int n, a[100010];

int lis(){
    fill(dp, dp + n, INF);
    for(int i = 0; i < n; i++){
        *lower_bound(dp, dp + n, a[i]) = a[i];
    }
    return lower_bound(dp, dp + n, INF) - dp;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    cout << lis() << endl;
}

Measured memory_bytes: 4776
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
#define N 1000010
multiset<int> s;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,a[N],tot;
int b[N],bn;
int main(){
	n=read();
	tot=1<<n;
	for(int i=1;i<=tot;i++){
		a[i]=read();
		s.insert(a[i]);
	}
	b[++bn]=(*--s.end());
	s.erase(s.find(b[bn]));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=(1<<(i-1));j++){
			if(*s.begin()>=b[j]){
				cout<<"No"<<endl;
				return 0;
			}
			b[++bn]=(*--s.lower_bound(b[j]));
			s.erase(s.find(b[bn]));
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

int main(){
    int n;cin>>n;
    int i=1,x=1;
    while(i<=n){
        x=i;
        if(x%3==0) cout<<" "<<i;
        else if(x%10==3) cout<<" "<<i;
        else{
            while(x!=0&&x%10!=3) x/=10;
            if(x!=0&&x%10==3) cout<<" "<<i;
        }
        i++;
    }
    cout<<endl;    
}


Measured memory_bytes: 3088
package main

import (
	"fmt"
	"math"
)

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func keta(n int) int {
	cnt := 1
	for n / 10 > 0 {
		n /= 10
		cnt++
	}
	return cnt
}
func main() {
	var n int
	fmt.Scan(&n)

	m := 10
	for i:=1; i<=int(math.Sqrt(float64(n))); i++ {
		if n % i == 0 {
			k := max(keta(i), keta(n/i))
			if m > k {
				m = k
			}
		}
	}

	fmt.Println(m)
}

Measured memory_bytes: 512
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

long long int N, M, a[364364], r;

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(long long int &x){int k;x=0;for(;;){k=gc();if(48<=k&&k<=57){x=k-48;break;}}for(;;){k=gc();if(k<48||k>57)break;x=x*10+k-48;}}

int main(){
    read(N);
    M = N + (N << 1);
    for(int i = 0; i ^ M; ++i){
        read(a[i]);
    }
    sort(a, a + M, greater<long long int>());
    for(int i = 0; i ^ N; ++i){
        r += a[i * 2 + 1];
    }
    printf("%lld", r);
    return 0;
}


Measured memory_bytes: 2560
import sys
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
b=[int(input()) for i in range(n)]
c=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(n):
  for j in range(3):
    for k in range(3):
      if a[j][k]==b[i]:
        c[j][k]=1

if sum(c[0])==3 or sum(c[1])==3 or sum(c[2])==3:
  print('Yes')
  sys.exit()
if c[0][0]+c[1][0]+c[2][0]==3 or c[0][1]+c[1][1]+c[2][1]==3 or c[0][2]+c[1][2]+c[2][2]==3:
  print('Yes')
  sys.exit()
if c[0][0]+c[1][1]+c[2][2]==3 or c[0][2]+c[1][1]+c[2][0]==3:
  print('Yes')
  sys.exit()
print('No')

Measured memory_bytes: 38384
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int getnum(const vector<int>&as, int K) {
	int ans = 0;
	for (int l = 0; l <= as.size() - K; ++l) {
		int num = 1;
		for (int i = l; i < l + K; ++i) {
			num *= as[i];
		}
		ans = max(ans, num);
	}
	return ans;
}

int main() {
	while (1) {
		int N, K; cin >> N >> K;
		if (!N)break;
		vector<int>ns(N);
		for (int i = 0; i < N; ++i)cin >> ns[i];
		sort(ns.begin(), ns.end());
		int ans = 0;
		for (int i = 0; i < N; ++i) {
			int rest = K - ns[i]+1;
			auto it = lower_bound(ns.begin() + i + 1, ns.end(),rest);
			ans += ns.end() - it;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3144
// CppPractice.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n, L[5000], ans;
	ans = 0;
	cin >> n;
	
	cout << n * n * n << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

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

	int a, b;
	cin >> a >> b;
	int answer = max(a+b, a-b);
	answer = max(answer, a*b);
	cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.*;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		char[] S = in.readLine().toCharArray();
		Deque<Character> deque = new ArrayDeque<>();
		deque.addLast(S[0]);
		for (int i = 1; i < N; ++i) {
			if (S[i] != deque.getLast()) {
				deque.addLast(S[i]);
			}
		}
		System.out.println(deque.size());
	}
}


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

int main(){
  double X, i, Y = 100;
  ll ans = 0;
  cin >> X;
  while(1){
    if(Y >= X){
      break;
    }
    Y *= 1.01;
    Y = ll(Y);
    ans++;
  }

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

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int n;
cin >> n;
vi s(n);
rep(i,n) cin >> s[i];

int sum = 0;
int m = INF;

rep(i,n){
    if(s[i] % 10 != 0){
        sum += s[i];
        m = min(m,s[i]);
    }
}

if(sum == 0){
    cout << sum << endl;
    return 0;
}

if(sum % 10 != 0){
    rep(i,n) if(s[i] % 10 == 0) sum += s[i];
}else{
    sum -= m;
    rep(i,n) if(s[i] % 10 == 0) sum += s[i];
}

cout << sum << endl;

return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}
const int N=2E5+1;
ll f[N];
int n;

ll cr(int m){
    ll den = (f[n-m] * f[n-m-1]%MOD) * (f[m] * f[m] %MOD);
    return powmod(den,MOD-2,MOD);
}
int main() {
    READ(0);
    int k;cin>>n>>k;
    f[0]=f[1]=1;
    for(int i=2;i<=n;++i) f[i] = (f[i-1]*i)%MOD;
    ll f_n = f[n]*f[n-1]%MOD;
    ll ret=0;
    for(int m=1;m<min(k+1,n);++m){
        ret += cr(m);
        if (ret>=MOD) ret -= MOD;
    }
    ret = ret * f_n %MOD;
    if (++ret==MOD) ret=0;
    cout << ret;

    return 0;
}



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

int main()
{
	string S;
	int K;
	
	cin >> K;
	cin >> S;
	
	if(S.length() > K)
	{
		for(int i=0; i<K; i++)
		{
			cout << S[i];
		}
		cout << "...";
	}
	else
	{
		cout << S;
	}
	
	return 0;
}

Measured memory_bytes: 3620
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int a, b;
    cin >> a >> b;
    if(a == 1 && b == 1){
        cout << "Draw" << endl;
    } else if(a == 1){
        cout << "Alice" << endl;
    } else if(b == 1){
        cout << "Bob" << endl;
    } else if(a > b){
        cout << "Alice" << endl;
    } else if(a < b){
        cout << "Bob" << endl;
    } else {
        cout << "Draw" << endl;
    }
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c = inpl()
K = inp()
for i in range(8):
    for j in range(8):
        for k in range(8):
            if i+j+k > K: 
                continue
            na = a*2**i
            nb = b*2**j
            nc = c*2**k
            if nb > na and nc > nb:
                print('Yes')
                quit()
print('No')

Measured memory_bytes: 10496
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
#define PI 3.1415926535897932384626433832795
#define coutfix(i) cout << fixed << setprecision(i)
using namespace std;

int main()
{
	string ss;
	cin >> ss;
	int64 aa = 0;
	for(int64 ii = 0;ii < ss.length();ii++)
	{
		if((ss[ii] - '0') == ii % 2)
		{
			aa++;
		}
	}
	cout << min(aa, (int64)ss.length() - aa) << endl;
}


Measured memory_bytes: 3720
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        String S=sc.next();
        if (S.equals("abc") || S.equals("acb") || S.equals("bac") || S.equals("bca") || S.equals("cab") || S.equals("cba")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
	int N, K;
	string S;
	cin >> N >> K >> S;

	char A = S.at(K-1);
	char B = tolower(A);
	S.at(K - 1) = B;

	cout << S << endl;


}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

bool judge_prime(int a){
  for (int i = 2; i <= sqrt(a); ++i)
  {
    if(a%i==0) return false;
  }
  return true;
}

int main()
{
  int q;
  std::vector<int> prime;
  for (int i = 3; i <= 1e5; i+=2)
  {
    if(judge_prime(i) && judge_prime((i+1)/2)){
      prime.emplace_back(i);
    }
  }
  cin>>q;
  for (int i = 0; i < q; ++i)
  {
    int l,r;
    cin>>l>>r;
    auto U=upper_bound(prime.begin(), prime.end(),r);
    auto L=lower_bound(prime.begin(), prime.end(),l);
    cout<<U-L<<endl;
  }
}

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

#define pb push_back
using namespace std;

using ll = long long;

constexpr int N = 200111;
constexpr double PI = 22.0 / 7.0;

int n, arr[N], t;

int main(){
    cin >> t;
    cout << fixed << setprecision(20);
    cout << 2.0 * t * (22.0 / 7.0) << endl;
}

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

int main(void) {
    int W,a,b;
    int move;

    cin >> W >> a >> b;

    move = (a > b) ? a-(b+W):b-(a+W);
    if(move < 0)move = 0;

    cout << move << "\n";

    return 0;
}


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


int main(void) {
  int x, y;
  cin >> x >> y;

  vector<vector<int>> v = {{1, 3, 5, 7, 8, 10 , 12},
  {4, 6, 9, 11},
  {2}};

  int xg, yg;
  rep(j, v.size()) {
    rep(i, v[j].size()) {
      if (v[j][i] == x) xg = j;
      if (v[j][i] == y) yg = j;
    }
  }

  if (xg == yg) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    char x,y;cin>>x>>y;
    if(x>y){
        cout<<">"<<endl;
    }else if(x<y){
        cout<<"<"<<endl;
    }else{
        cout<<"="<<endl;
    }
    return 0;
}


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

const int MAX_N=1005;
int n;
bool boo[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	for(int i=2;i<=40;++i)
		for(int j=i*i;j<MAX_N;j*=i)
			boo[j]=true;
	boo[1]=true;	
	while(cin>>n){
		while(n){
			if(boo[n]==true){
				cout<<n<<endl;
				break;
			}
			n--;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import accumulate
MOD = 10**9+7
  
n, k = map(int, input().split())
S = set()
i = 1
while i * i <= n:
  S.add(i)
  S.add(n//i)
  i += 1
L = [0] + sorted(S)
l = len(L) - 1
num = [0]*l
for i in range(l):
  num[i] = L[i+1] - L[i]
dp = [0]*l
dp[0] = 1
for _ in range(k):
  A = list(accumulate(dp))
  for i in range(l):
    dp[i] = A[l-1-i] * num[i]
    dp[i] %= MOD
ans = sum(dp) % MOD
print(ans)

Measured memory_bytes: 121172
#include<iostream>
#include<algorithm>
#include<vector>
#include<fstream>
#include<string>
#include<queue>

using namespace std;
#define REP(m,n) for(int i=m;i<n;++i)
#define REP(j,m,n) for(int j=m;j<n;++j)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair


int main() {
	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	if (a == f&&b == e&&c == d) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum^=a[i];
	}
	for(int i=1;i<=n;i++){
		cout<<(sum^a[i])<<" ";
	}
}

Measured memory_bytes: 4392
a, b, k = list(map(int, input().split()))

for i in range(k):
    if i%2 == 0:
        if a%2 == 1:
            a -= 1
        a = a//2
        b += a
    if i%2 == 1:
        if b%2 == 1:
            b -= 1
        b = b//2
        a += b
print(a, b)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] a = new int[5];
    for (int i = 0; i < 5; i++) {
      a[i] = sc.nextInt();
    }
    Main abc123B = new Main();
    System.out.println(abc123B.solve(a));
  }

  public int solve(int[] a) {
    int ans = 0;
    int max_diff = 0;
    for(int i = 0; i < 5; i++ ){
      int diff = tenDiff(a[i]);
      ans += a[i] + diff;
      if(diff > max_diff){
        max_diff = diff;
      }
    }
    return ans - max_diff;
  }

  private int tenDiff(int a) {
    if (a % 10 == 0) {
      return 0;
    } else {
      return 10 - (a % 10);
    }
  }
}


Measured memory_bytes: 23508
A, B, C, D = map(int, input().split())

if A%D == 0:
    n_T = A//D
else:
    n_T = A//D+1

if C%B == 0:
    n_A = C//B
else:
    n_A = C//B + 1

if n_T >= n_A:
    print("Yes")

else:
    print("No")

Measured memory_bytes: 9164
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int x, xs=0, y, ys=0, n;
    cin >> x >> y >> n;
    for(int i=0;i<n;i++) {
        int a, b, c;
        cin >> a>>b>>c;
        switch(c) {
            case 1:
                if(xs<a) xs=a;
                break;
            case 2:
                if(x>a) x=a;
                break;
            case 3:
                if(ys<b) ys=b;
                break;
            case 4:
                if(y>b) y=b;
                break;
        }
        if(ys>=y || xs>=x) {
            cout << 0;
            return 0;
        }
    }
    cout << (x-xs)*(y-ys);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
vector<pair<ll,int>> v;
vector<int> fa,siz;
vector<vector<int>> G;
ll tot;
void dfs(int u,int par,ll d){
    tot += d;
    for(int v : G[u]){
        if(v == par) continue;
        dfs(v,u,d + 1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>n;
    v.resize(n + 1);
    fa.resize(n + 1);
    siz.resize(n + 1);
    G.resize(n + 1);
    fill(fa.begin(),fa.end(),0);
    fill(siz.begin(),siz.end(),1);
    for(int i = 1; i <= n; i++) {
        cin>>v[i].first;
        v[i].second = i;
    }
    sort(v.begin() + 1,v.end(),[](auto x,auto y){ return x.first > y.first;});
    for(int i = 1; i < n; i++){
        ll d = v[i].first;
        int sz = siz[v[i].second];
        ll d_nxt = d - n + 2 * sz;
        int lo = i + 1, hi = n;
        int ans_pos = 0;
        while(lo <= hi){
            int mid = lo + hi >> 1;
            if(v[mid].first > d_nxt){
                lo = mid + 1;
            }
            else if(v[mid].first < d_nxt){
                hi = mid - 1;
            }
            else {
                ans_pos = mid;
                break;
            }
        }
        if(ans_pos == 0){
            cout<<-1<<endl;
            exit(0);
        }
        int u = v[i].second;
        int f = v[ans_pos].second;
        fa[u] = f;
        G[f].emplace_back(u);
        G[u].emplace_back(f);
        siz[f] += siz[u];
    }
    dfs(v[n].second,0,0);
    if(tot != v[n].first){
        cout<<-1<<endl;
        exit(0);
    }
    for(int i = 1; i < n; i++){
        cout<<v[i].second<<" "<<fa[v[i].second]<<endl;
    }

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    ll sum = 0;
    rep(i,n) {
        sum += a.at(i);
        sum %= MOD; 
    }
    ll ans = 0;
    rep(i,n) {
        sum -= a.at(i);
        while (sum < 0) sum += MOD;
        ans += (ll) sum * a.at(i);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const ll N=1e5+5;

int n,m,mem[N];

vector<int>adj[N];

int dp(int pos)
{
    if (mem[pos]!=-1)return mem[pos];
    int ans=0;
    for (auto X:adj[pos])
    {
        ans=max(ans,1+dp(X));
    }
    return mem[pos]=ans;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin >> n >> m;
    for (int i=0;i<m;i++)
    {
        int u,v;cin >> u >> v;
        adj[u].pb(v);
    }
    int ans=0;
    for (int i=1;i<=n;i++)
    {
        ans=max(ans,dp(i));
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> task(n);
    for (int i = 0; i < n; i++) cin >> task[i].second >> task[i].first;
    sort(task.begin(), task.end());
    int now = 0;
    for (int i = 0; i < n; i++){
        now += task[i].second;
        if (now > task[i].first){
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1792
d,n = gets.split(" ").map(&:to_i)
t = Array.new(d)
for i in 0...d
	t[i] = gets.to_i
end
a = Array.new(n)
b = Array.new(n)
c = Array.new(n)
for i in 0...n
	a[i],b[i],c[i] = gets.split(" ").map(&:to_i)
end
dp = Array.new(n)
for i in 0...n
	if a[i] <= t[0] && t[0] <= b[i]
		dp[i] = 0
	else
		dp[i] = -1
	end
end
for i in 1...d
	dpw = Array.new(n,0)
	for j in 0...n
		if a[j] <= t[i] && t[i] <= b[j]
			dpw[j] = 0
			for k in 0...n
				if dp[k] >= 0
					dpw[j] = [dpw[j],dp[k] + (c[k] - c[j]).abs].max
				end
			end
		else
			dpw[j] = -1
		end
	end
	for j in 0...n
		dp[j] = dpw[j]
	end
end
all = 0
for i in 0...n
	all = [all, dp[i]].max
end
print(all,"\n")

Measured memory_bytes: 8836
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 1<<17;

int parent[MAX], weight[MAX];
vector<int> E[MAX];

int main(void) {
  int N;
  scanf("%d", &N);
  FOR(i, 1, N) {
    scanf("%d %d", &parent[i], &weight[i]);
    --parent[i];
    E[parent[i]].push_back(i);
  }

  llint lo = 0, hi = 1e18;
  while (lo < hi) {
    llint mid = lo + (hi - lo) / 2;

    static vector<pair<llint, llint>> S[MAX];

    for (int i = N-1; i >= 0; --i) {
      S[i].clear();

      if (E[i].size() == 0) { // leaf
        S[i] = {make_pair(weight[i], weight[i])};
      } else {
        int x = E[i][0], y = E[i][1];
        if (S[x].size() > S[y].size()) swap(x, y);

        vector<pair<llint, llint>> tmp1, tmp2;
        
        int k = 0;
        for (int j = 0; j < (int)S[x].size(); ++j) {
          while (k < (int)S[y].size() && S[x][j].second + S[y][k].first <= mid) k++;
          if (k > 0) tmp1.push_back({S[x][j].first, S[y][k-1].second});
        }

        k = 0;
        for (int j = 0; j < (int)S[x].size(); ++j) {
          while (k < (int)S[y].size() && S[x][j].first + S[y][k].second > mid) k++;
          if (k < (int)S[y].size()) tmp2.push_back({S[y][k].first, S[x][j].second});
        }
        
        S[i].resize(tmp1.size() + tmp2.size());
        merge(tmp1.begin(), tmp1.end(), tmp2.begin(), tmp2.end(), S[i].begin());

        int sz = 0;
        llint minb = 1e18;
        for (auto& p: S[i]) {
          p.first += weight[i], p.second += weight[i];
          if (p.second < minb) {
            minb = p.second;
            S[i][sz++] = p;
          }
        }
        S[i].resize(sz);
      }
    }
    
    if (S[0].size()) hi = mid;
    else lo = mid + 1;
  }

  cout << lo << endl;
  return 0;
}


Measured memory_bytes: 36792
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
string u;
int n; int out;
//今の文字列を受け取って、i番目を左端とするダイヤルの回し方をしようとしている
//3番目の引き数として操作回数を持っている
void ans(string s, int i,int k) {
	if (i == n) {
		out = min(k, out);
		return;
	}
	int a1 = u[i] - '0'; int a2 = s[i] - '0';
	int c = (a1 - a2 + 10) % 10;
	if (c == 0) {
		ans(s, i + 1, k); return;
	}
	string nex = s;
	Rep(j, i, n) {
		int x = s[j] - '0';
		x = (x + c) % 10;
		nex[j] = '0' + x;
		ans(nex, i + 1, k + 1);
	}
}
void solve(string s) {
	out = 500;
	ans(s, 0, 0);
	cout << out << endl;
}
int main(){
	while (cin >> n, n) {
		string s;
		cin >> u>>s;
		solve(s);
	}
	return 0;
}


Measured memory_bytes: 3012
#include <iostream>
using namespace std;
int main(void){
    // 入力
    char b;
    cin >> b;
    
    //塩基ｂと対になる塩基をansに入れる
    char ans;
    if (b == 'A') ans = 'T';
    if (b == 'T') ans = 'A';
    if (b == 'C') ans = 'G';
    if (b == 'G') ans = 'C';
    
    //出力
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6;
int aa[N+2],bb[N+2],cc[N+2],dd[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  deque<char>dq;string s;cin>>s;
  for(int i=0;i<s.size();i++)dq.push_back(s[i]);

  int f=0,q;cin>>q;
  while(q--)
  {
    int ty;cin>>ty;
    if(ty==1)f^=1;
    else
    {
      char c;cin>>ty>>c;
      if(ty==1)
      {
        if(!f)dq.push_front(c);
        else dq.push_back(c);
      }
      else
      {
        if(f)dq.push_front(c);
        else dq.push_back(c); 
      }
    }
  }
  while(dq.size())
  {
    if(!f)
    {
      cout<<dq.front();dq.pop_front();
    }
    else
    {
      cout<<dq.back();dq.pop_back(); 
    }
  }
  cout<<"\n";
  return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  vector<ll> H(N);
  for(ll i=0;i<N;i++) {
cin>>H[i];
  }
  
  ll ans=0;
  for(ll i=0;i<N-1;i++) {
  if(H[i]>=H[i+1]) {
ll count=1;
    for(ll j=i+1;j<N-1;j++) {
if(H[j]>=H[j+1]) {
count++;
}
   else {
i=j;
     break;
   }
     if(j==N-2) {
i=j;
     }
    }
    ans=max(ans,count);
  }
  }



cout<<ans<<endl;
}
    
    
    
      
      
      
      
      
 
      
      
      
    
    
    
    
    
    
    
    
    


Measured memory_bytes: 4040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		Set<Integer> d = new HashSet<>();

		for (int i = 0; i < N; i++) {
			d.add(Integer.parseInt(br.readLine()));
		}

		System.out.println(d.size());
	}

}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include "boost/multiprecision/cpp_int.hpp"

using ll = long long;
using ull = unsigned long long;
namespace mp = boost::multiprecision;

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	int R, G, B, N; std::cin >> R >> G >> B >> N;

	int ans = 0;

	for (int r = 0; r <= 3000; r++) {
		for (int g = 0; g <= 3000; g++) {
			int tmp = N - r * R - g * G;
			if (tmp >= 0 && tmp % B == 0)ans++;
		}
	}

	std::cout << ans;

	return 0;

}

Measured memory_bytes: 256
#coding:UTF-8
num = int(input())
max=0
for i in range(1,num+1):
  count=0
  work=i
  while work%2==0:
    work=work//2
    count = count+1
#    print("i:{} count:{} max:{}".format(i,count,max))
  if max<count:
    max=count
    ans=i
if(max==0):
  print(1)
else:
  print(ans)
    

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

int div_num(int n) {
  int rt = 0;

  for ( int i = 1; i <= n; i++ ) {
    if ( n%i == 0 ) { rt++; }
  }

  return rt;
}

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

  int ans = 0;
  for ( int i = 1; i <= n; i+=2 ) {
    if ( div_num(i) == 8 ) { ans++; }
  }

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


Measured memory_bytes: 256