akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int ggcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,cnt,ans,p;
  cin>>n;
  string s;
  cin>>s;
  
  if(s[0]=='W'){
    cnt=count(s.begin(),s.end(),'W')-1;
  }else{
    cnt=count(s.begin(),s.end(),'W');
  }
  ans=n-cnt-1;
  p=ans;
  for(int i=0;i<s.size()-1;i++){
    
    if(s[i]=='W' && s[i+1]=='W'){
      p++;
    }else if(s[i]=='E' && s[i+1]=='E'){
      p--;
    }
    
    ans=min(p,ans);
  }
  cout<<ans<<endl;
}
///////////////////////////






Measured memory_bytes: 900
/* ex4_3
   Acro  */

#include <stdio.h> 
int stone_monument(int height_w,int height_e);

int main(){
    int height_w,height_e;
    scanf("%d %d",&height_w,&height_e);
    printf("%d\n",stone_monument(height_w,height_e));
    return 0;
}

int stone_monument(int height_w,int height_e){
    int diff,height_true,i;
    height_true = 0;
    /* 差を計算 */
    diff = height_e - height_w;
    /* 元の高さを計算 */
    for(i=1; i < diff; i++){
        height_true += i;
    }
    return height_true - height_w;
}

Measured memory_bytes: 128
r,c = map(int,input().split())
table = [list(map(int,input().split())) for _ in range(r)]

csum = [0 for _ in range(c+1)]
for i in range(r):
    table[i].append(sum(table[i]))
    print(*table[i])
    for j in range(c+1):
        csum[j] += table[i][j]
print(*csum)


Measured memory_bytes: 6224
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    string s;
    cin>>s;
    rep(i,0,s.size()){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    set<int>Set;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        Set.insert(A[i]);
    }
    cout << Set.size()-(N-Set.size())%2 << endl;
    return 0;
}


Measured memory_bytes: 8728
#include <stdio.h>
int linearSearch (int* ,int ,int);
int main()
{
  int i,a=0,same=0;
  int S[10000],T[500],s_num,t_num;
  scanf("%d",&s_num);
  for(i=0;i<s_num;i++)
    { 
      scanf("%d",&S[i]);
      // printf("S %d \n",S[i]);
    }
  scanf("%d",&t_num);
  for(i=0;i<t_num;i++)
    {
      scanf("%d",&T[i]);
      // printf("T %d \n",T[i]);
    }

  for(i=0;i<t_num;i++)
    {
      same+=linearSearch(S,T[i],s_num);
      // printf("aaaaaaaaa\n");
    }
  printf("%d\n",same);
  return 0;
}

int linearSearch(int* S,int key,int s_num)
{
  int i=0;
  for(i=0;i<s_num;i++)
    {
      // printf("bbbbbbbbbb\n");
      if(S[i]==key) return 1;
    }
  return 0;
}

Measured memory_bytes: 640
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int c = sc.NextInt();

        int[][] d = new int[c][];
        for (int i = 0; i < c; i++)
        {
            d[i] = sc.IntArray();
        }

        int[][] cc = new int[n][];
        for (int i = 0; i < n; i++)
        {
            cc[i] = sc.IntArray();
        }

        // %3=i iにしたときの違和感
        int[][] dif = new int[3][];
        for (int i = 0; i < 3; i++)
        {
            dif[i] = new int[c];
        }

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                int m = (i + j) % 3;
                for (int k = 0; k < c; k++)
                {
                    dif[m][k] += d[cc[i][j] - 1][k];
                }
            }
        }

        int ans = int.MaxValue;
        for (int i = 0; i < c; i++)
        {
            for (int j = 0; j < c; j++)
            {
                if(i == j) continue;
                for (int k = 0; k < c; k++)
                {
                    if(i == k || j == k) continue;
                    ans = Math.Min(ans, dif[0][i] + dif[1][j] + dif[2][k]);
                }
            }
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 16580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    ll k, a, b; cin >> k >> a >> b;
    if (k <= a)print(1);
    else if (a - b <= 0)print(-1);
    else print(1 + (k - a + (a - b - 1)) / (a - b) * 2);

    return 0;
}

Measured memory_bytes: 3616
x, k, d = map(int, input().split())

k_i = abs(x)//d

if k >= k_i+1:
    if k%2==0:
        if k_i%2==0:
            print(abs(abs(x)-d*k_i))
        else:
            print(abs(abs(x)-d*(k_i+1)))
    else:
        if k_i%2==0:
            print(abs(abs(x)-d*(k_i+1)))
        else:
            print(abs(abs(x)-d*k_i))
else:
    print(abs(x)-k*d)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int A,B,M;
  int a[110000], b[110000], x[110000], y[110000], c[110000];
  int res=0;
  cin >> A>>B>>M;

  rep(i,A) cin >> a[i];
  rep(i,B) cin >> b[i];

  rep(i,M){
    cin >> x[i] >> y[i] >> c[i];
    x[i]--; y[i]--;
  }

  int minA = INF;
  rep(i,A) {
    minA = min(minA, a[i]);
  }
  int minB = INF;
  rep(i,B) {
    minB = min(minB, b[i]);
  }

  res = minA + minB;

  rep(i,M){
    res = min(res, a[x[i]] + b[y[i]] - c[i]);
  }

  cout << res << endl;
}


Measured memory_bytes: 2432
N = int(input())
A = [int(i) for i in input().split()]
count = 1
status = 0

for i in range(N-1):
  if (A[i+1] - A[i]) == 0:
    continue
  elif (A[i+1] - A[i]) > 0:
    if status == 0 or status == 1:
      status = 1
      continue
    else:
      count += 1
      status = 0
      
  elif (A[i+1] - A[i]) < 0:
    if status == 0 or status == -1:
      status = -1
      continue
    else:
      count += 1
      status = 0
print(count)

Measured memory_bytes: 14228
n, m = list(map(int, input().split()))
a = []
for i in range(m):
    a.append(int(input()))

mod = 1000000007

memo = [-1]*(n+1)
memo[0] = 0

for k in range(m):
    memo[a[k]] = 0

for i in range(1, n+1):
    if memo[i] != -1:
        pass 
    elif i <= 2:
        memo[i] = memo[i-1] + 1
    else:
        memo[i] = memo[i-1] + memo[i-2]
print(memo[-1]%mod)

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  ll k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i]--;
  dump(a);
  vvi jp(60, vi(n, -1));
  int j = 1;
  rep(j, 60) {
    if (j == 0) {
      rep(i, n) {
        jp[j][i] = a[i];
      }
    } else {
      rep(i, n) {
        jp[j][i] = jp[j - 1][jp[j - 1][i]];
      }
    }
    dump(j, jp[j]);
  }
  int ans = 0;
  rep(j, 60) {
    if (k & (1LL << j)) {
      if (ans == jp[j][ans]) break;
      ans = jp[j][ans];
      if (ans < 0) {
        dump(j, ans);
        break;
      }
      dump(j, ans);
    }
  }
  cout << ans + 1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 51776
#![allow(unused)]

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn main() {
    input! {
        n: u64,
    }

    if n % 2 != 0 {
        println!("0");
    } else {
        let mut ans: u64 = 0;
        for i in 1..28 {
            ans += n / (2 * 5_u64.pow(i));
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{
    vi p(3);
    cin_pl(3,p);
    sort(all(p));
    if(p[0]==5&&p[1]==5&&p[2]==7)cout<<"YES";
    else cout<<"NO";
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for(int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}
		System.out.println(set.size());
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
struct Sieve
{
    vector<int> smallest_factor;
    vector<int> smallest_power;
    vector<int> moebius;
    vector<int> totient;
    vector<bool> prime;
    vector<int> primes;
    Sieve(int m) : smallest_factor(m + 1), smallest_power(m + 1), moebius(m + 1), totient(m + 1), prime(m + 1, true)
    {
        moebius[1] = totient[1] = 1;
        prime[0] = prime[1] = false;

        for (int i = 2; i <= m; i++)
        {
            if (prime[i])
            {
                smallest_factor[i] = i;
                smallest_power[i] = 1;
                moebius[i] = -1;
                totient[i] = i - 1;
                primes.push_back(i);
            }

            for (int p : primes)
            {
                if (p > smallest_factor[i] || i * p > m)
                    break;
                prime[i * p] = false;
                smallest_factor[i * p] = p;
                smallest_power[i * p] = smallest_factor[i] == p ? smallest_power[i] + 1 : 1;
                moebius[i * p] = smallest_factor[i] == p ? 0 : -moebius[i];
                totient[i * p] = smallest_factor[i] == p ? p * totient[i] : (p - 1) * totient[i];
            }
        }
    }
};

int main(){
    Sieve sieve(100100);
    vector<int> imos(100100,0);
    for(auto i:sieve.primes){
        if(sieve.prime[(i+1)/2]){
            imos[i] +=1;
        }
    }
    for(int i = 1;i<100100;i++){
        imos[i]+=imos[i-1];
    }
    int q;
    cin >> q;
    rep(t,q){
        int l,r;
        cin >> l >> r;
        cout << imos[r] - imos[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 2688
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    vector<int> A(n);
    for(int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        A[i] = x;
    }
    int mn = A.back() - A.front();
    for(int i = 0; i < n - 1; ++i) {
        mn = min(k - A[i + 1] + A[i], mn);
    }
    cout << mn << "\n";
    return 0;

}



Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L];
int getChar(char ch){
if(ch == 'A') return 1;
else if(ch == 'C') return 2;
else if(ch == 'G') return 3;
else if(ch == 'T') return 4;
else return 0;
}
long long getKey(char str[]){
long long sum = 0, p = 1, i;
for(i = 0; i < strlen(str); i++){
sum += p*(getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M - 1));}
int find(char str[]){
long long key, i, h;
key = getKey(str);
for(i = 0;; i++){
h = (h1(key) + i * h2(key)) % M;
if(strcmp(H[h], str) == 0) return 1;
else if(strlen(H[h]) == 0) return 0;
}
return 0;
}
int insert(char str[]){
long long key, i, h;
key = getKey(str);
for(i = 0;; i++){
h = (h1(key) + i * h2(key)) % M;
if(strcmp(H[h], str) == 0) return 1;
else if(strlen(H[h]) == 0){
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main(){
int i, n, h;
char str[L], com[9];
for(i = 0; i < M; i++) H[i][0] = '\0';
scanf("%d", &n);
for(i = 0; i < n; i++){
scanf("%s %s", com, str);
if(com[0] == 'i'){
insert(str);
}else{
if(find(str)){
printf("yes\n");
}else{
printf("no\n");
}
}
}
return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  int bell[3];
  for (size_t i = 0; i < 3; i++) cin >> bell[i];
  sort(bell, bell+3);

  cout << bell[0]+bell[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

char buf[2000];

string replace(string orig, string from, string to) {
  while (1) {
    int itr = orig.find(from);
    if (itr == string::npos) return orig;
    orig = orig.replace(itr, from.size(), to);
  }
}

int main() {
  fgets(buf, sizeof(buf), stdin);
  string s1 = replace(buf, "peach", "unko");
  string s2 = replace(s1, "apple", "peach");
  string s3 = replace(s2, "unko", "apple");
  printf("%s", s3.c_str());
}

Measured memory_bytes: 2744
n=int(input())
x=[0 for i in range(n+1)]

def find(a,n,x):
  k =0
  l =0
  for j in range(a,n):
    if j % 10!= 0:
      if a%10 == j//(10**(len(str(j))-1)) and j%10 == a//(10**(len(str(a))-1)):
        k+=1
        x[j] = 1
      if a%10 == j%10 and j//(10**(len(str(j))-1)) == a//(10**(len(str(a))-1)):
        l+=1
        x[j] = 1
  if a%10 == a//(10**(len(str(a))-1)):
    return k*l
  return 2*k*l

ans=0
for i in range(1,n+1):
  if x[i] == 0 and i%10!=0:
    ans += find(i,n+1,x)

print(ans)

Measured memory_bytes: 52848
#include <iostream>
using namespace std;
int main(void) {
  int n, a, b, ans = 0;
  cin >> n >> a >> b;
  for (int i = 0; i <= n; i++) {
    int c = i / 10000 + i % 10000 / 1000 + i % 1000 / 100 + i % 100 / 10 + i % 10;
    if (c >= a && c <= b) {
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) > *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

int main(void) {
	char S[11];

	scanf("%s", S);

	bool firstIsA = true;
	bool containsOneC = true;
	bool othersAreaSmall = true;
	size_t cCount = 0;
	for (size_t idx = 0; idx < strlen(S); idx++) {
		if (idx == 0) {
			if (S[idx] != 'A') {
				firstIsA = false;
				break;
			}
		}
		else if (2 <= idx && idx <= strlen(S) - 2) {
			if (S[idx] == 'C') {
				cCount++;
			}
			else {
				if (!('a' <= S[idx] && S[idx] <= 'z')) {
					othersAreaSmall = false;
					break;
				}
			}

			if (idx == strlen(S) - 2) {
				if (cCount != 1) {
					containsOneC = false;
					break;
				}
			}
		}
		else {
			if (!('a' <= S[idx] && S[idx] <= 'z')) {
				othersAreaSmall = false;
				break;
			}
		}
	}

	puts(((firstIsA && containsOneC && othersAreaSmall) ? "AC" : "WA"));

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long int MOD = 1000000007;
const long long  INF = 1LL << 60;

int main(void){
    int N; cin >> N;
    vector<vector<int>> plan(N, vector<int>(3)); for(int i = 0; i < N; i++) for(int j = 0; j < 3; j++) cin >> plan[i][j];
    
    vector<vector<ll>> dp(N+10, vector<ll>(3, 0));
    dp[0] = {0, 0, 0};
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if (j == k) continue;
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + plan[i][j]);
            }
        }
    }
    ll ans = 0; for(int i = 0; i < 3; i++) ans = max(ans, dp[N][i]);
    cout << ans << endl;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

struct edge{ int to,cost; };
vector<int> dikstra(int s,vector<vector<edge>> G){
  typedef pair<int, int> P;
  const int INF = 1LL << 60;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(G.size(),INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  return d;
}

signed main(){

  int n, m; cin >> n >> m;
  vector<vector<edge>> G(n);
  for(int i = 0; i < m; i++){
    int l, r, c; cin >> l >> r >> c;
    l--, r--;
    G[l].push_back({r,c});
  }
  for(int i = 1; i < n; i++){
    G[i].push_back({i-1, 0});
  }
  auto dp = dikstra(0, G);
  cout << (dp[n-1] == INF ? -1 : dp[n-1]) << endl;

  return 0;
}


Measured memory_bytes: 15996
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int f[N];

int power(int a, int b){
	int ans = 1;
	while(b){
		if(b&1)
			ans = (ans*a) % mod;
		b >>= 1;
		a = (a*a) % mod;
	}
	return ans;
}

signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n, m;
	cin >> n >> m;
	if((n+m) % 3 != 0)
		return cout << 0, 0;
	f[0] = 1;
	for(int i = 1; i < N; i++) 
		f[i] = (i*f[i-1]) % mod;	
	if(2*n < m || 2*m < n)
		return cout << 0, 0;
	int one = (2*n-m)/3;
	int zero = (2*m-n)/3;
	int ans = f[zero + one];
	ans = (ans * power(f[zero], mod-2)) % mod;
	ans = (ans * power(f[one], mod-2)) % mod;
	cout << ans;
	return 0;
}

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

int main() {
    double n, x, t;
    cin >> n >> x >> t;

    int ans = ceil(n / x) * t;

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


Measured memory_bytes: 3704
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
ans=1
cap=10**18
if 0 in set(A):
  print(0)
else:
  for a in A:
    ans*=a
    if ans>cap:
      print(-1)
      break
    else:
      continue
  else:
    print(ans)


Measured memory_bytes: 21640
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n,m,num=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=22;j<=m;j++){
			if(j%10>=2&&(j%10)*(j/10)==i){
				num++;
			}
		}
	}
	cout<<num<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c,x,y;

  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

  int min_a = a;
  int min_b = b;
  int min_ab = a+b;

  if (min_a > c*2) {
    min_a = c*2;
  }
  if (min_b > c*2) {
    min_b = c*2;
  }
  if (a+b > c*2) {
    min_ab = c*2;
  }

  int min_xy = x;
  int max_xy = y;

  int flag = 0;
  if (min_xy > max_xy) {
    int t = min_xy;
        min_xy = max_xy;
        max_xy = t;
        flag = 1;
  }

  int ans = 0;

    ans = min_xy * min_ab; 
        
  if (flag == 1 && max_xy != min_xy) {
      ans += (max_xy -min_xy) * min_a;
    } else if (flag == 0 &&  max_xy != min_xy){
      ans += (max_xy -min_xy) * min_b;
    }

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

  return 0;
}


Measured memory_bytes: 128
local x = io.read()
local r, c = 0, 0
for i = 1, #x do
  if x:sub(i, i) == "S" then
    c = c + 1
  else
    if 0 < c then
      c = c - 1
      r = r + 1
    end
  end
end
print(#x - 2 * r)


Measured memory_bytes: 1392
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;
using ll = long long;

int dfs(int v, int N, vector<bool>& visited, const vector<vector<bool>>& Path) {
	// 全部訪問済みなら返す。
	if (all_of(cbegin(visited), cend(visited), [](auto x) {
		return x;
	})) {
		return 1;
	}

	int ans = 0;

	for (size_t i = 0; i < N; i++) {
		// 訪問済みの頂点にはたどらない
		if (visited[i]) {
			continue;
		}
		// 経路がない頂点にはたどらない
		if (!Path[v][i]) {
			continue;
		}

		// 訪問済みとしてから再帰する
		visited[i] = true;
		ans += dfs(i, N, visited, Path);
		// 元に戻す
		visited[i] = false;
	}
	return ans;
}

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

	vector<vector<bool>> Path(N, vector<bool>(N)); // 経路があることを示す表

	for (size_t i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		Path[a - 1][b - 1] = true;
		Path[b - 1][a - 1] = true;
	}

	vector<bool> visited(N);
	visited[0] = true;

	cout << dfs(0, N, visited, Path) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    ll N;
    cin >> N;
    vll T(N);
    rep(i, N){
        cin >> T[i];
    }
    ll ans = T[0];
    rea(i, 1, N){
        ans = T[i] / GCD(ans, T[i]) * ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const int INF = 1e9;
const int MXN = 3e3 + 5;
const int MXV = 0;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);
vector<LL> v;
LL dp[MXN][MXN];

int main()
{
    IOS;
    int n;
    cin >> n;
    v.resize(n + 5);
    FOR(i, 1, n + 1) { cin >> v[i]; }
    FORD(i, n, 0) FOR(j, i, n + 1)
    {
        dp[i][j] = max(v[i] - dp[i + 1][j], v[j] - dp[i][j - 1]);
    }
    cout << dp[1][n] << '\n';
}


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

int howmany(int x,int p){
    if(x<p) return 0;
    return x/p+howmany(x/p,p);
}
int main(){
    int n;
    cin >> n;
    int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    int a=0,b=0,c=0,d=0,e=0;
    for(int i=0; i<15; i++){
        int m=howmany(n,prime[i]);
        if(m>=2) a++;
        if(m>=4) b++;
        if(m>=14) c++;
        if(m>=24) d++;
        if(m>=74) e++;
    }
    int ans=(a-2)*b*(b-1)/2+(b-1)*c+(a-1)*d+e;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
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(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();

    let mut ans = 1;

    for ai in a {
        if ans == ai {
            ans += 1;
        }
    }

    if ans == 1 {
        println!("-1");
    } else {
        println!("{}", n + 1 - ans);
    }
}

Measured memory_bytes: 10492
#include <stdio.h>
signed main(){
    int N, i, j=0, count=0 ,count2=0;
    scanf("%d", &N);

    int A[1003];
    int B[1003];
    for(i=0; i<N; i++){    /*配列 A に N個の整数を入れる*/
        scanf("%d", &A[i]);
    }

    for(i=0; i<N; i++){
        if(A[i] %2 ==0){
            B[j] = A[i];  /*偶数のみをBに入れる*/
            j++;
        }
    }

     for(i=0; i<j; i++){
            if(B[i] % 3==0 || B[i] % 5 ==0){
              count++;
            }else{
                count = count + 100;
            }
        }

    if(j == count){
            printf("APPROVED\n");
        }else{
            printf("DENIED\n");
        }


    return 0;

}

Measured memory_bytes: 1648
#include<iostream>

using namespace std;

int main(){
    int n;
    while (cin >> n){
        int result = 0;
        for (int a = 0; a <= 9; a++){
            for (int b = 0; b <= 9; b++){
                for (int c = 0; c <= 9; c++){
                    for (int d = 0; d <= 9; d++){
                        if (a + b + c + d == n)
                        {
                            result++;
                        }
                    }
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

string s;
int n;
map<string, int> f;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i=0; i < n; ++i) {
        cin >> s;
        f[s]++;
    }
    cout << "AC x " << f["AC"] << endl;
    cout << "WA x " << f["WA"] << endl;
    cout << "TLE x " << f["TLE"] << endl;
    cout << "RE x " << f["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3564
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n;
ll ans;
map<int,int>s;

int main() {
	qr(n);
	for(int i=1,x;i<=n;i++) {
		qr(x); ans+=s[i-x];
		s[i+x]++;
	}
	pr2(ans);
	return 0;
}



Measured memory_bytes: 20516
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
//#inlcude<stringstream>
#define ll long long
#define MODD 1000000007
using namespace std;

int main() {
    //
    int a,b;cin >>a>>b;
    int aa = a+b;
    int bb = a-b;
    int cc = a*b;
    cout<<max(aa,max(bb,cc));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int K = 100;
const int INF = 100000;
const int dx[] = {-1, 0, 1, 0, 1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1};

struct STATE
{
	int x, y, d;
};

bool grid[201][201];
int done[201][201];

int main()
{	
	int t, n;
	while (scanf("%d %d", &t, &n), t + n){
		memset(grid, 0, sizeof(grid));
		for (int i = 0; i <= 200; i++){
			for (int j = 0; j <= 200; j++){
				done[i][j] = INF;
			}
		}
		
		for (int i = 0; i < n; i++){
			int x, y;
			scanf("%d %d", &x, &y);
			grid[x + K][y + K] = true;
		}
		
		int sx, sy;
		scanf("%d %d", &sx, &sy);
		
		queue<STATE> que;
		que.push({sx + K, sy + K, 0});
		while (!que.empty()){
			STATE st = que.front(); que.pop();
			if (done[st.x][st.y] <= st.d || st.d > t) continue;
			
			done[st.x][st.y] = st.d;
			
			for (int dir = 0; dir < 6; dir++){
				int tx = st.x + dx[dir];
				int ty = st.y + dy[dir];
				
				if (done[tx][ty] > st.d + 1 && !grid[tx][ty]){
					que.push({tx, ty, st.d + 1});
				}
			}
		}
		
		int cnt = 0;
		for (int i = 0; i <= 200; i++){
			for (int j = 0; j <= 200; j++){
				cnt += done[i][j] != INF;
			}
		}
		
		printf("%d\n", cnt);
	}
		
	return 0;
}

Measured memory_bytes: 1416
use std::io;

fn main() {
    let mut num_strings = String::new();
    io::stdin().read_line(&mut num_strings).expect("Failed to read line");
    let values: Vec<i32> = num_strings.split(' ').map(|x| x.trim().parse().unwrap()).collect();
    let number =  values[0] * 100 + values[1] * 10 + values[2];
    if number % 4 == 0 {
        println!("YES")
    } else {
        println!("NO")
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int n,cut[3],ans;//0为A 1为B 2为BA
char s[15]; 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		int l=strlen(s+1);
		for(int j=2;j<=l;j++) if(s[j-1]=='A'&&s[j]=='B') ans++;
		if(s[1]=='B'&&s[l]=='A') cut[2]++;
		else if(s[1]=='B') cut[1]++;
		else if(s[l]=='A') cut[0]++;
	}
	ans+=(cut[2]?cut[2]-1:0);
	if(cut[2]&&cut[1]) cut[1]--,ans++;
	if(cut[2]&&cut[0]) cut[0]--,ans++;
	ans+=min(cut[0],cut[1]);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const lint _INFINITY = 1LL << 55;
const int MAXN = 1024;
lint dp[2 * MAXN][MAXN];

void solveSingleCase(int caseNo)
{
    int N, M;
    cin >> N >> M;
    VEC(VEC(Pii)) edges(N);
    FOR(i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges[a].PB(Pii(b, c));
    }

    FOR(i, 0, 2 * MAXN)
        FOR(j, 0, N)
            dp[i][j] = -_INFINITY;

    dp[0][0] = 0LL;
    FOR(i, 0, 2 * MAXN - 1)
        FOR(j, 0, N) {
            for (Pii& pr : edges[j]) {
                int k = pr.FIR, e = pr.SEC;
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + e);
            }
        }

    lint best = -_INFINITY;
    FOR(i, 1, N)
        best = max(best, dp[i][N - 1]);

    FOR(i, N, 2 * MAXN)
        if (dp[i][N - 1] > best) {
            cout << "inf" << endl;
            return;
        }

    cout << best << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 16768
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

struct Edge{
    int src,dst,cost;
    bool isl;
    Edge(int s,int d,int c) : src(s), dst(d), cost(c) {isl = false;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int dist[21];
bool visited[21],isleaf[21],ispar[21];

bool dfs(Graph &g,int v,int d) {
    visited[v] = true;
    dist[v] = d;

    bool leaf = true;
    for(int i=0; i<g[v].size(); ++i) {
        if(visited[g[v][i].dst]) continue;
        leaf = false;
        bool k = dfs(g,g[v][i].dst, d+g[v][i].cost);
        if(k) {
            ispar[v] = true;
            g[v][i].isl = true;
            for(int k=0; k<g[g[v][i].dst].size(); ++k) {
                if(g[g[v][i].dst][k].dst == v)
                    g[g[v][i].dst][k].isl = true;
            }
        }
    }
    return leaf;
}

int main() {
    int N,a,b,t;
    while(cin>>N, N) {
        Graph g(N);
        memset(visited, false, sizeof(visited));
        memset(ispar, false, sizeof(ispar));
        memset(isleaf, false, sizeof(isleaf));

        for(int i=0; i<N-1; ++i) {
            cin>>a>>b>>t;
            a--,b--;
            g[a].push_back(Edge(a,b,t));
            g[b].push_back(Edge(b,a,t));
        }

        dfs(g,0,0);
        int md = 0;
        int ans = 0;
        for(int i=0; i<N; ++i)
            if(ispar[i])
                md = max(dist[i], md);

        for(int i=0; i<N; ++i)
            for(int j=0; j<g[i].size(); ++j)
                if(!g[i][j].isl) {
                    ans += g[i][j].cost;
                    //cout<<g[i][j].src<<" "<<g[i][j].dst<<endl;
                }

        //cout<<ans<<" - "<<md<<endl;
        ans -= md;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int n,m,tage[100],cnt[100],i,j,x;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		cnt[i]=0;
	}
	for(i=1;i<=m;i++){
		scanf("%d",&tage[i]);
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&x);
			if(x==tage[i]){
				cnt[j]++;
			}
			else{
				cnt[tage[i]]++;
			}
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",cnt[i]);
	}
	return 0;
}

Measured memory_bytes: 596
a = list(input())
b = list(input())
c = list(input())
x = "d"
a_idx = 0
b_idx = 0
c_idx = 0
while True:
    if x == "a":
        if a_idx == len(a):
            print("A")
            break
        else:
            x = str(a[a_idx])
            a_idx += 1
    elif x == "b":
        if b_idx == len(b):
            print("B")
            break
        else:
            x = str(b[b_idx])
            b_idx += 1
    elif x == "c":
        if c_idx == len(c):
            print("C")
            break
        else:
            x = str(c[c_idx])
            c_idx += 1
    else:
        x = "a"

Measured memory_bytes: 9092
import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		String x=scan.next();
		int dp[][]=new int[x.length()+2][2];
		dp[0][1]=1;
		for(int i=0;i<x.length();i++)
		{
			if(x.charAt(i)=='0')
			{
				dp[i+1][1]+=dp[i][1];
			}else {
				dp[i+1][0]+=dp[i][1];
				
				dp[i+1][1]=(int) ((dp[i+1][1]+(dp[i][1]*2L))%1000000007);
			}
			dp[i+1][0]=(int) ((dp[i+1][0]+(dp[i][0]*3L))%1000000007);
		}
		int n=x.length();
		System.out.println((dp[n][0]+dp[n][1])%1000000007);
	}
}


Measured memory_bytes: 29992
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

fn main() {
    let mut abc = reads();

    abc.sort();

    let mut res = 0;
    let mut prev = 0;
    for x in abc {
        if x != prev {
            res += 1;
            prev = x;
        }
    }

    println!("{}", res);
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		for(;;){
		int n = scan.nextInt();
		int x = scan.nextInt();
		if(n ==0 && x == 0)
			break;
		int a = 1;
		int b = 1;
		int c = 1;
		int t = 0;
		for(a = 1; a <= n; ++a){
			for(b = 1; b <= n; ++b){
				for(c = 1; c <= n; ++c){
					if(c == b || c == b || b == a)
						break;
					if(c > b || b > a)
						break;
					if(c + b + a == x)
						++t;
						
					}
				}
			}
		System.out.println(t);
		}
	}
}


	

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

int main() {
	string weather;

	cin >> weather;

	if (weather == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (weather == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;, i < n; i++)
#define rep_2(i,n) for(int i=n, i > 0; i--)
using namespace std;
using ln = long long;

int main()
{
    int n;
    cin >> n;
    if(n%2==0)
        cout << n/2 << endl;
    else
        cout << n/2 + 1 << endl;

}

Measured memory_bytes: 3628
/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
typedef long long Long;
void FastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
}

const int N = 1e6;

int main()
{
  FastIO();
  int tc, ca = 0;
  int n;
  cin >> n;
  int d = ceil(double(n)/1000.0);
  d = d*1000;
  cout << d-n << '\n';
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int i=a;i<b;i++)

int main()
{
    char ch[10];
    cin>>ch;
    if(ch[2]==ch[3]&&ch[4]==ch[5])
    {
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }

    return 0;
}



Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC target ("sse2")
#pragma GCC optimize ("Ofast")
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	int n, t, x = 0;
	cin >> n;
	while(n--) cin>>t, x^=t;
	cout << (x ? "No" : "Yes");
}


Measured memory_bytes: 256