akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n;
    cin >> n;
    VVL a(n+1, VL(n+1));
    map<ll, VP> mp;
    rep(i, 0, n){
        rep(j, 0, n){
            cin >> a[i][j];
            if(i >= j) continue;
            mp[a[i][j]].push_back({i,j});
        }
    }

    VVP G(n+1);
    VVL l(n+1, VL(n+1, 1e12));

    ll ans = 0;
    for(auto p : mp){
        for(auto v : p.second){
            ll srt = v.first;   
            VL d(n+1, 1e18);
            /* dijkstra's scope */{
                priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
                que.push({0, srt});
                d[srt] = 0;
                while(!que.empty()){
                    auto q = que.top();
                    que.pop();
                    if(q.first > d[q.second]) continue;
                    for(auto g : G[q.second]){
                        if(d[g.first] <= q.first + g.second) continue;
                        d[g.first] = q.first + g.second;
                        que.push({d[g.first], g.first});
                    }
                }
            }
            if(d[v.second] == p.first) continue;
            if(d[v.second] > p.first){
                G[v.first].push_back({v.second, p.first});
                G[v.second].push_back({v.first, p.first});
                ans += a[v.first][v.second];
            }
            if(d[v.second] < a[v.first][v.second]){
                cout << -1 << endl;
                return 0;
            }
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  if(x>=400&&x<600) cout << "8" << endl;
  else if(x>=600&&x<800) cout << "7" << endl;
  else if(x>=800&&x<1000) cout << "6" << endl;
  else if(x>=1000&&x<1200)cout << "5" << endl;
  else if(x>=1200&&x<1400)cout << "4" << endl;
  else if(x>=1400&&x<1600)cout <<"3" << endl;
  else if(x>=1600&&x<1800)cout << "2" <<endl;
  else if(x>=1800&&x<2000)cout << "1"<< endl;
}

Measured memory_bytes: 3584
import java.util.Scanner;


public class Main{

	static Scanner sc = new Scanner(System.in);
	
	static int tmp, n, w, com;
	static String str[];
	static int a[] = new int[30], b[] = new int[30], line[] = new int[30];
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		w = sc.nextInt();
		n = sc.nextInt();
		
		for(int i = 0; i < n; i++){
			str = sc.next().split(",");
			
			a[i] = Integer.parseInt(str[0]);
			b[i] = Integer.parseInt(str[1]);
		}
		
		return true;
	}
	
	public static void solve(){
		
		for(int i = 0; i < w; i++){
			line[i] = i + 1;
		}
		
		for(int i = 0; i < n; i++){
			tmp = line[a[i]-1];
			line[a[i]-1] = line[b[i]-1];
			line[b[i]-1] = tmp;
		}
		
		for(int i = 0; i < w; i++){
			System.out.println(line[i]);
		}
	}

}

Measured memory_bytes: 12000
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
map<ll,ll>mp;
int main()
{
	ll n;
	cin>>n;
	ll A[n];
	FOR(i,0,n)cin>>A[i];
	ll ans=0;
	FOR(i,1,n-1) {
		vector<ll>v;v.pb(A[i]);v.pb(A[i-1]);v.pb(A[i+1]);
		sort(all(v));
		if(v[1]==A[i])ans++;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
using namespace std;
// #include "prettyprint.hpp"

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    int MAX = 0;
    int cnt = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> H[i];
        if (MAX <= H[i])
        {
            MAX = H[i];
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;

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


int main() {
	vector<int> result(1000);
	for (int i = 0; i < 1000; ++i) {

		vector< vector<int> > map(21, vector<int>(21, 0));
		vector< vector<int> > map2(21, vector<int>(21, 0));

		int px = 10, py = 10;

		int N;
		cin >> N;

		if (N == 0) {
			break;
		}

		vector<int> tx(N);
		vector<int> ty(N);

		rep(i, N) {
			cin >> tx[i];
			cin >> ty[i];
			map2[ty[i]][tx[i]] = 1;
		}

		int M;
		cin >> M;

		string str;
		int v;

		rep(i, M) {
			cin >> str >> v;

			if (str == "N") {
				for (int i = py; i <= py + v; i++) {
					map[i][px] = 1;
				}
				py += v;
			}
			else if (str == "E") {
				for (int i = px; i <= px + v; i++) {
					map[py][i] = 1;
				}
				px += v;
			}
			else if (str == "S") {
				for (int i = py; i >= py - v; i--) {
					map[i][px] = 1;
				}
				py -= v;
			}
			else if (str == "W") {
				for (int i = px; i >= px - v; i--) {
					map[py][i] = 1;
				}
				px -= v;
			}
			// rep(i,21){
			//     rep(j,21){
			//         cout << map[i][j] << " ";
			//     }
			//     cout << endl;
			// }
			// cout << endl;
		}

		int sum = 0;

		rep(i, 21) {
			rep(j, 21) {
				if (map[i][j] == 0 && map2[i][j] == 1) {
					sum++;
				}
			}
		}

		if (sum == 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		result[i] = sum;

	}

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	int k = 10;

	while(k <= b) k *= 10;

	int n = a * k + b;

	for(int i = 1; i < 320; i++) {
		if(i * i == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

}


Measured memory_bytes: 256
using System;

namespace Poor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] numbers = Console.ReadLine().Split(' ');

            if (numbers[0].ToString() == numbers[1].ToString()
                && numbers[0].ToString() != numbers[2].ToString())
            {
                Console.WriteLine("Yes");
            }
            else if(numbers[0].ToString() == numbers[2].ToString()
                && numbers[0].ToString() != numbers[1].ToString())
            {
                Console.WriteLine("Yes");
            }
            else if(numbers[1].ToString() == numbers[2].ToString()
                && numbers[0].ToString() != numbers[1].ToString())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main (){
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 1; i < n; i++){
        int m;
        cin >> m;
        v[m-1]++;
    }
    for (int i = 0; i < n; i++){
        cout << v[i] << "\n";
    }


}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    long long int x = 0, y = 0;
    x = a[0];
    REP(i, 1, n)
    {
        y += a[i];
    }
    long long int ans = 0x7fffffff;
    if (n == 2)
    {
        ans = abs(a[0] - a[1]);
    }
    REP(i, 1, n - 1)
    {
        x += a[i];
        y -= a[i];
        ans = min(ans, abs(x - y));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string s,t;
int ans=0x3f3f3f3f;
int check(int pos)
{
	int ret=0;
	for(int i=pos,j=0;i<=pos+t.size()-1;i++,j++) if(s[i]!=t[j]) ret++;
	return ret;
}
int main()
{
	cin>>s>>t;
	for(int i=0;i<s.size()-t.size()+1;i++) ans=min(ans,check(i));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h> 
using namespace std;  
#define pb push_back
typedef unsigned long long int  ll;
typedef long double ld;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORE(i,n) for(i=0;i<=n;i++)

vector<ll> a;
vector<ll> f;
ll n,k;

bool poss(ll target){
    ll count = 0;
    for(int i=0;i<n;i++){
        if(a[i]*f[i]>target){
            count += a[i] - target/f[i];
        }
    }
    if(count<=k)return true;
    return false;
}

int main()
{
        ios_base::sync_with_stdio(false);
        cin >> n >> k;
        a.resize(n);
        f.resize(n);
        for(int i=0;i<n;i++)cin>> a[i];
        for(int i=0;i<n;i++)cin >> f[i];
        sort(a.begin(),a.end());
        sort(f.begin(),f.end());
        reverse(f.begin(),f.end());
        ll maxi  = 0;
        for(int i=0;i<n;i++){
            maxi = max(maxi,a[i]*f[i]);
        }
        ll lo = 0;
        ll high = maxi;
        while(lo<high){
            ll mid = lo + (high-lo)/2;
            if(poss(mid)){
                high = mid;
            }
            else lo = mid+1;
        }
        cout << lo << "\n";
        return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[233333];
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i-1]==1&&a[i])ans++,a[i]--;
		ans+=a[i]/2;
		a[i]%=2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int m, n, a[100];
bool check(int x) {
	int pos = 0, r = 0;
	for(int i = 0; i < m; i++) {
		while(pos != n && r + a[pos] <= x) r += a[pos++];
		if(pos == n) return true; r = 0;
	}
	return false;
}
int main() {
	while(scanf("%d%d", &m, &n), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		int l = 0, r = 1500001;
		while(r - l > 1) {
			int m = (l + r) / 2;
			if(check(m)) r = m;
			else l = m;
		}
		printf("%d\n", r);
	}
}

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

int dig(int n){
  int count = 0;
  while(n){
    count++;
    n /= 10;
  }
  return count;
}

int dfs(int n, bool t, bool f, bool s){
  if(dig(n) == dig(N)){
    if(n <= N && t && f && s) return 1;
    else return 0;
  } 
  int a = n + 3*pow(10,dig(n));
  int b = n + 5*pow(10,dig(n));
  int c = n + 7*pow(10,dig(n));
  if(t && f && s) return 1 + dfs(a,true,f,s) + dfs(b,t,true,s) + dfs(c,t,f,true);
  else return dfs(a,true,f,s) + dfs(b,t,true,s) + dfs(c,t,f,true);
}

int main(){
  cin >> N;
  int ans = dfs(3,true,false,false) + dfs(5,false,true,false) + dfs(7,false,false,true);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int A, B;
  cin >> A >> B;
  if(A+B==3) cout << 3 << endl;
  else if(A+B==4) cout << 2 << endl;
  else if(A+B==5) cout << 1 << endl;
}

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

int main() {
    string a, b;
    cin >> a >> b;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<char>());
    bool ans = false;
    int common_len = min(a.size(), b.size());
    for (int i=0;i<common_len;i++) {
        if (a[i] < b[i]) {
            ans = true;
            break;
        }
    }
    if (a[common_len-1] == b[common_len-1] && a.size() < b.size()) {
        ans = true;
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
int a[100090],ss,n,v[100090],u;
map<int,int>f;
int main()
{
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
		++f[a[i]];
		if(f[a[i]]==1){
			v[++ss]=a[i];
		}
	}
	
	if(ss>3){
		puts("No");
		return 0;
	}
	
	if(ss==1){  //n==1
		if(v[1]){
			puts("No");
			return 0;
		}
		puts("Yes");
		return 0;
	}
	
	sort(a+1,a+n+1);
	if(n%3){
		puts("No");return 0;
	}
	u=n/3;
	for(int i=1;i<=u;++i){
		
		if(i>1){
			if(a[i]!=a[i-1]||a[i+u]!=a[i+u-1]||a[i+u+u]!=a[i+u+u-1]){
				puts("No"); return 0;//
			}
		}
		
		if((a[i]^a[i+u])!=a[i+u+u]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 4480
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(void){
	int N;
	int id;
	ll p,q;
	while(cin >> N){
		queue<int> que;
		map<int, ll> map;
		int check = 0;
		if(!N) break;
		for(int i=0; i<N; ++i){
			cin >> id >> p >> q;
			if(map.find(id) == map.end()){
				map[id] = p*q;
				que.push(id);
			} else {
				map[id] += p*q;
			}
		}
		while(que.size()){
			if(map[que.front()] >= 1000000){
				cout << que.front() << endl;
				check = 1;
			}
			que.pop();
		}
		if(check == 0) cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 1288
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {

	int m;
	int f;
	int r;

	while(1){
		cin>>m>>f>>r;
		if( (m==-1&&f==-1)&&r==-1)break;
		if(m==-1||f==-1){
			cout<<"F"<<endl;
		}else if(m+f>=80){
			cout<<"A"<<endl;
		}else if(m+f>=65){
			cout<<"B"<<endl;
		}else if(m+f>=50){
			cout<<"C"<<endl;
		}else if(m+f>=30){
			if(r>=50){
				cout<<"C"<<endl;
			}else{
				cout<<"D"<<endl;
			}
		}else{
			cout<<"F"<<endl;
	    }
	}
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll h, w;
char a[1010][1010];
bool dp[101010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s;
	cin >> s;
	ll n = s.length();
	stack<char>stack;
	rep(i, n) {
		if (s[i] == 'S')stack.push('S');
		else if (s[i] == 'T') {
			if (stack.empty()) {
				stack.push('T');
			}
			else {
				char target = stack.top();
				if (target == 'S')stack.pop();
				else {
					stack.push('T');
				}
			}
		}
	}
	ll ans = stack.size();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3768
import scala.io.StdIn.{readLine,readInt}

object Main {
  def loop(i:Int,s:Int,m:Int):Int =
    if(i==0) m
    else {
      val n = readInt
      val max = if(s+n > m) s+n else if(n>m) n else m
      val sum = if(s < 0 && n > s) n else s+n
      loop(i-1,sum,max)
    }

  def main(args:Array[String]) = {
    var n = 0
    while( {n = readInt;n} != 0 ) println(loop(n,0,-100000))
  }
}

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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n, k;
    in(n);
    in(k);
    ll h[n];
    floop(i, n) in(h[i]);
    ll dp[110000];
    floop(i, 110000) dp[i] = inf;
    dp[0] = 0;
    floop(i, n)
    {
        floop1(j, k)
        {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    out(dp[n - 1]);
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s[3];
int t[3], l[3], tn;

int main() {
	rep(i,3) {
		cin >> s[i];
		l[i] = (int)s[i].length();
	}
	
	while (true) {
		if (t[tn]==l[tn]) {
			if (tn==0) cout << "A" << ln;
			else if (tn==1) cout << "B" << ln;
			else cout << "C" << ln;
			return 0;
		}
		t[tn]++;
		tn = s[tn][t[tn]-1] - 'a';
	}
}

Measured memory_bytes: 256
#bottomかtopか
n=int(input())
a=list(map(int,input().split()))
an=[]
for i in range(1,n):
    if a[i]>a[i-1]:
        an.append(a[i-1])
        if i==n-1:
            an.append(a[i])
        break
pm=0
for j in range(i+1,n):
    #print(pm)
    if pm==0:
        if a[j]>=a[j-1]:
            if j==n-1:
                an.append(a[j])
            continue
        else:
            an.append(a[j-1])
            pm=1
    else:
        if a[j]<=a[j-1]:
            continue
        else:
            an.append(a[j-1])
            pm=0
            if j==n-1:
                an.append(a[j])
#print(an)
ans=1000
k=0
for i in range(len(an)):
    if i%2==0:
        k=ans//an[i]
        ans-=k*an[i]
    else:
        ans+=k*an[i]
        k=0
print(ans)

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

int main(){
  int h, w, d; cin >> h >> w >> d;
  vector<vector<int>> v(d);
  map<int, P> xy;
  rep(i, h)rep(j, w){
    int a; cin >> a;
    xy[a] = P(i, j);
    v[a%d].push_back(a);
  }
  rep(i, d) sort(v[i].begin(), v[i].end());
  map<int, int> idx;
  rep(i, d)rep(j, v[i].size()) idx[v[i][j]] = j;
  vector<vector<int>> s(d);
  rep(i, d){
    s[i].push_back(abs(xy[v[i][0]].first) + abs(xy[v[i][0]].second));
    rep(j, v[i].size()-1){
      s[i].push_back(s[i][j] + abs(xy[v[i][j+1]].first - xy[v[i][j]].first) + abs(xy[v[i][j+1]].second - xy[v[i][j]].second));
    }
  }
  int q; cin >> q;
  rep(i, q){
    int l, r; cin >> l >> r;
    cout << s[r%d][idx[r]] - s[l%d][idx[l]] << endl;
  }
}

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

int main() {

	int n; cin >> n;
	vector<int> a(n), b(n), c(n - 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i];
	}
	int ans = b[a[0]];
	int prev = a[0];
	for (int i = 1; i < n; i++) {
		ans += b[a[i]];		
		if (a[i] == prev + 1) {
			ans += c[prev];
		}
		prev = a[i];
	}	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

import math
#from decimal import Decimal

# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
X = int(input())
#開業されたN個要素を受け付ける
#input_list = [list(map(int, input().split())) for i in range(N)]

#x_co = math.sin(math.radians(30))
#y_co =

#math.sin(math.radians(30))
lcm = (X * 360) / math.gcd(X, 360)

#while(360%X == 0)

print(int(lcm / X))


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

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

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

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

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

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


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





int main() {

	ll N, M;
	cin >> N >> M;

	ll ans = 0;

	ans += min(N, M / 2);

	M -= ans * 2;

	ans += M / 4;

	cout << ans;

	system("PAUSE");
}


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

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

  int n1 = N / 1000;
  int n2 = (N % 1000) / 100;
  int n3 = (N % 100) / 10;
  int n4 = N % 10;
  
  if (n1 == n2 && n2 == n3) cout << "Yes" << endl;
  else if (n2 == n3 && n3 == n4) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

struct Edge {
    int to;
    double cost;
    Edge(int to,double cost):to(to),cost(cost){};
};

ll X[1010],Y[1010],R[1010];
const ll INF = 1e18;
int main() {
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    X[0] = sx;
    X[1] = gx;
    Y[0] = sy;
    Y[1] = gy;
    R[0] = 0;
    R[1] = 0;
    int n;
    cin >> n;
    rep(i,n) {
        int x,y,r;
        cin >> x >> y >> r;
        X[i+2] = x;
        Y[i+2] = y;
        R[i+2] = r;
    }
    vector<vector<Edge>>g(n+2);
    rep(i,n+2) {
        for(int j = i+1;j<n+2;j++) {
            double d = sqrt((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]))-R[i]-R[j];
            if(d<0) d = 0;
            g[i].push_back(Edge(j,d));
            g[j].push_back(Edge(i,d));
        }
    }
    vector<double>dist(n+2,INF);
    dist[0] = 0;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.emplace(0,0);
    while(!pq.empty()) {
        auto p = pq.top();pq.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(auto e: g[v]) {
            if(dist[e.to] > dist[v]+e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pq.emplace(dist[e.to],e.to);
            }
        }
    }
    double ans = dist[1];
    cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 21732
#include <iostream>

using namespace std;

int main(void){
  char od[64], ev[64],*p,*q;
  
  cin >> od >> ev;
  for (p=od,q=ev; *p; p++){
    cout << *p;
    if (*q) cout << *(q++);
  }
  cout << endl;return 0;
}

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

int vst[100010];
int num[100010];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    int ans = 1;
    vst[1] = 1;
    fill(num, num + N + 1, 1);
    while (M --) {
        int x, y;
        cin >> x >> y;
        num[x] --;
        num[y] ++;
        if (vst[x]) {
            if (!num[x]) {
                ans --;
                vst[x] --;
            }
            if (!vst[y]) ans++, vst[y] ++;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4312
#include<stdio.h>
int siryoku(double z){
    if(z >= 1.1) return 1;
    if(z < 1.1 && z >= 0.6) return 2;
    if(z < 0.6 && z >= 0.2) return 3;
    if(z < 0.2) return 4;
}
int main()
{
    double x,y;
    int n;
    int i;
    int migi[5]={0},hidari[5]={0};
    i = 0;
    while(scanf("%lf%lf",&x,&y) != EOF){
        x = siryoku(x);
        y = siryoku(y);
        hidari[(int)x]++;
        migi[(int)y]++;
        i++;
    }
    for(i = 1; i <= 4; i++){
        printf("%d %d\n",hidari[i],migi[i]);
    }
    return 0;
}

Measured memory_bytes: 628
#include<stdio.h>

main()
{
    int a[10000],b[10000],i;
    char op[10000];
    for(i=0;i<=10000;i++)
    {
        scanf("%d %c %d",&a[i],&op[i],&b[i]);
        if(op[i]=='?')
        {
            break;
        }

    }
    for(i=0;i<=10000;i++)
    {
        if(op[i]=='+')
        printf("%d\n",a[i]+b[i]);
        else if(op[i]=='-')
            printf("%d\n",a[i]-b[i]);
        else if(op[i]=='/')
            printf("%d\n",a[i]/b[i]);
        else if(op[i]=='*')
            printf("%d\n",a[i]*b[i]);
        else break;

    }
return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
inline int lowbit(int x) { return (x & (-x));}
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
ll n, r;
int main()
{
	cin >> n >> r;
	if(n >= 10)
		cout << r << endl;
	else
		cout << r + 100 * (10 - n) << endl;
	return 0;
}
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s1,s2;
  cin>>s1>>s2;
	if(s1[0]==s2[2] and s1[1]==s2[1] and s1[2]==s2[0]) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		boolean[] ly = new boolean[3000];
		for (int i = 0; i < ly.length; i++) {
			if ((i % 4) == 0) ly[i] = true;
			else ly[i] = false;
			
			if ((i % 100) == 0) ly[i] = false;
			if ((i % 400) == 0) ly[i] = true;
		}

		int index = 0;
		while (sc.hasNextLine() == true) {
			String[] nico = sc.nextLine().split(" ");
			int a = Integer.parseInt(nico[0]);
			int b = Integer.parseInt(nico[1]);
			
			if ((a == 0) && (b == 0)) break;
			
			if (index > 0) System.out.println();
			
			boolean flag = false;
			for (int i = a; i < (b + 1); i++) {
				if (i <= 0) continue;
				if (i >= 3000) break;
				
				if (ly[i] == true) {
					flag = true;
					System.out.println(i);
				}
			}
			if (flag == false) System.out.println("NA");
			
			index++;
		}
	}
}

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define bits(n) __builtin_popcount(n)

bool snuck[101];

void solve()
{
    memset(snuck,false,sizeof(snuck));
    int n,k;
    cin>>n>>k;

    for(int i=0;i<k;i++)
    {
        int d;
        cin>>d;
        for(int j=0;j<d;j++)
        {
            int a;
            cin>>a;
            snuck[a]=true;
        }
    }
    int c=0;
    for(int i=1;i<=n;i++)
    {
        if(!snuck[i])
        c++;
    }
    cout<<c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

int main()
{
	long long int H, W;
	long long int a, b, c, ans = 10000000000;

	cin >> H >> W;

	for (int h = 1; h <= H; h++) {
		a = W * h;
		if ((W*H - a) % 2 != 0)
			b = ((H - h)* (W / 2));
		else
			b = (W*H - a) / 2;
		c = W*H - a - b;

		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}


	for (int w = 1; w <= W; w++) {
		a = H * w;
		if ((W*H - a) % 2 != 0)
			b = ((W - w)* (H / 2));
		else
			b = (W*H - a) / 2;
		c = W*H - a - b;

		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}


	cout << ans;

	return 0;
}

Measured memory_bytes: 256
def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, m, x[100002];
const LL MOD = 1000000007;

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3]) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = 0;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
	inc(k, 3) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
	
	return;
}

void mat_exp(LL a[3][3], LL b[3][3], LL c) { // a = b ^ c;
	LL t[30][3][3];
	inc(i, 3) {
	inc(j, 3) {
		t[0][i][j] = b[i][j];
	}
	}
	inc(i, 30 - 1) {
		mat_prod(t[i + 1], t[i], t[i]);
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, 30) {
		if(c & (1 << i)) {
			mat_prod(a, a, t[i]);
		}
	}
	
	return;
}

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n;
	
	LL a[3][3] = { { 1, 1, 0 }, { 4, 0, 1 }, { 10, MOD - 3, 3 } };
	LL b[3][3] = { { 0, 1, 0 }, { 0, 0, 1 }, {  1, MOD - 3, 3 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, {  0,       0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		mat_prod(c, b, c);
		mat_exp(d, a, x[i + 1] - x[i] - 1);
		mat_prod(c, d, c);
	}
	
	cout << (c[0][1] + c[0][2] * 4) % MOD << endl;
	
	return 0;
}


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

int main() {
    int x, y, X, Y;
    cin >> x >> y;
    X = max(x, y);
    Y = min(x, y);
    while (1) {
        int Xnew = Y;
        int Ynew = X % Y;
        X = Xnew;
        Y = Ynew;
        if (Y == 0) break;
    }
    cout << X << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
#define int LL
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

PII operator-(const PII &a, const PII &b){
    return PII(a.first - b.first, a.second - b.second);
}
bool operator==(const PII &a, const PII &b){
    return (a.first == b.first) && (a.second == b.second);
}

signed main(){
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << (double)W * H / 2 << " " << (((W == x * 2) and (H == y * 2)) ? 1 : 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;

int main() {
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	
	vector<int> vec = {a1, a2, a3};
	sort(vec.begin(), vec.end(), greater<int>());
	
	cout << vec[0] - vec[2] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

int main(void)
{
  int N,Y;
  cin >> N >> Y;

  for(int i=0; i<=N; i++){
    for(int j=0; j<=N-i; j++){
      if(10000*i+5000*j+1000*(N-i-j) == Y){
        cout << i << ' ' << j << ' ' << N-i-j << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;
}


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

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define FR(i, l, r) for(int i = (l); i <= (r); i++)
#define gcd __gcd 
#define FO(i, a) for(auto & i : a)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <pll> vll;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
template <typename T> inline void out(T x) { cout << x; }

/*********** TEMPLATE ENDS HERE *************/

unordered_map <ll, ll> H;

ll ans;


main()
{
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		sum = (sum + x) % m;
		H[sum]++;
		if(sum % m == 0)
			ans++;
	}
	
	for(auto i : H)
		ans += i.second * (i.second - 1) / 2;
	
	cout << ans;
	
}

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

int main() {
	char c;
	scanf("%c", &c);
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
		printf("vowel");
	else 
		printf("consonant");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
long long dp[2][110][5]={0};
  
int main()
{
  string S;
  cin >> S;
  int K;
  cin >> K;
  dp[0][0][0]=1;
  dp[0][0][1]=(S.at(0)-'0'-1);
  dp[1][0][0]=0;
  dp[1][0][1]=1;
  REP(i,S.size()-1){
    REP(j,K+1){
      dp[0][i+1][j]+=dp[0][i][j];
      if(j+1<=K){
        dp[0][i+1][j+1]+=dp[0][i][j]*9;
      }
      if(S.at(i+1)!='0'){
        dp[0][i+1][j]+=dp[1][i][j];
        if(j+1<=K){
          dp[0][i+1][j+1]+=(S.at(i+1)-'0'-1)*dp[1][i][j];
          dp[1][i+1][j+1]+=dp[1][i][j];
          dp[1][i+1][j]+=0;
        }
      }else{
        dp[1][i+1][j+1]+=0;
        dp[1][i+1][j]+=dp[1][i][j];
      }
    }
  }

  cout << dp[1][S.size()-1][K]+dp[0][S.size()-1][K] << endl;
}

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

//#define yskshi
#if defined yskshi
#define debug(s) cout<<s<<endl
#else
#define debug(s)
#endif

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
int main() {
  ull n;cin>>n;
  ull ans=0;
  if(n%2==0){
    if(n>=10){
      for(ull i=5,m=10;m<=n;i*=5){
        ans+=n/m;
        m=10*i;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let s = get!(i64);
    let mut v = vec![0; 100000];
    v[1] = s;
    for i in 2..v.len() {
        if v[i - 1] % 2 == 0 {
            v[i] = v[i - 1] / 2;
        } else {
            v[i] = v[i - 1] * 3 + 1;
        }
    }
    //eprintln!("{:?}", v);
    let mut ans = v[1];
    'outer: for i in 1..v.len() {
        let tmp = v[i];
        let n = v.iter().filter(|&&x| x == tmp).count();
        //eprintln!("n:{}", n);
        if 2 <= n {
            let mut count = 0;
            for j in 1..v.len() {
                if v[j] == tmp {
                    count += 1;
                    if count == 2 {
                        ans = j as i64;
                        break 'outer;
                    }
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

struct P {
  int id;
  ll x, y;
};

int main2() {
  int N = nextLong();

  vector<P> p;
  REP(i, N) {
    ll x = nextLong();
    ll y = nextLong();
    p.push_back((P){i, x, y});
  }

  atcoder::dsu uf(N);
  {
    sort(ALL(p), [](const P& a, const P& b) {
      return a.x < b.x;
    });
    vector<P> stack;
    REP(i, p.size()) {
      if (stack.empty() || stack.back().y > p[i].y) {
        stack.push_back(p[i]);
      }
      int j = (int)stack.size() - 1;
      while (j >= 0 && stack[j].y < p[i].y) {
        uf.merge(p[i].id, stack[j].id);
        j--;
      }
    }
  }


  REP(i, p.size()) {
    p[i].x = (N+1) - p[i].x;
    p[i].y = (N+1) - p[i].y;
  }

  {
    sort(ALL(p), [](const P& a, const P& b) {
      return a.x < b.x;
    });
    vector<P> stack;
    REP(i, p.size()) {
      if (stack.empty() || stack.back().y > p[i].y) {
        stack.push_back(p[i]);
      }
      int j = (int)stack.size() - 1;
      while (j >= 0 && stack[j].y < p[i].y) {
        uf.merge(p[i].id, stack[j].id);
        j--;
      }
    }
  }


  vector<int> ans(N);

  REP(i, N) ans[i] = uf.size(i);

  REP(i, ans.size()) {
    cout << ans[i] << '\n';
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

const int maxn = 1e5+5;
int N, M;
vector<int> adj[maxn];
int indegree[maxn];

vector<int> topsort() {
    queue<int> q;
    for (int i = 1; i <= N; i++) {
        if (indegree[i] == 0) q.push(i);
    }
    vector<int> res;
    while (!q.empty()) {
        int f = q.front(); q.pop();
        res.push_back(f);
        for (int j: adj[f]) {
            indegree[j]--;
            if (indegree[j] == 0) q.push(j);
        }
    }
    return res;
}

int dp[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        indegree[b]++;
    }
    //topsort
    vector<int> t = topsort();
    int ans = 0;
    while (!t.empty()) {
        int f = t.back();
        t.pop_back();
        for (int j: adj[f]) {
            dp[f] = max(dp[f],1+dp[j]);
        }
        ans = max(ans,dp[f]);
    }
    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 7032
/* #include <bits/stdc++.h> */
#include <iostream>
#include <vector>
using namespace std;
#define _GLIBCXX_DEBUG

struct pos {
  int x, y;
};

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

pos s, g;
int w, h;
int ans = 100;

bool is_same_pos(pos a, pos b){
  return a.x==b.x &&
    a.y==b.y;
}
bool is_out(pos a){
  return a.x<0 || w<=a.x ||
    a.y<0 || h<=a.y;
}

void dfs(pos stone, int cnt, vector<vector<int>> field) {
  for (int i = 0; i < 4; i++) {
    /* cout << "start or return" << endl; */
    pos now = stone;
    for (int j = 0; j < 100; j++) {
      pos next_pos = {now.x + dx[i], now.y + dy[i]};
      /* cout << now.x << now.y <<' '<<i<< endl; */
      if (is_out(next_pos)) {
        /* cout << "out" << endl; */
        break;
      } else if (is_same_pos(next_pos, g)) {
        ans = min(ans, cnt);
        /* cout << "goal" << endl; */
        break;
      } else if (field[next_pos.x][next_pos.y] == 1) {
        if (cnt < 10 && j) {
          field[next_pos.x][next_pos.y] = 0;
          dfs(now, cnt + 1, field);
          field[next_pos.x][next_pos.y] = 1;
        }
        break;
      }
      now = next_pos;
    }
  }
}

int main() {
  while (cin >> w >> h) {
    if (!w && !h)
      break;
    vector<vector<int>> field(w, vector<int>(h));
    ans = 100;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> field[j][i];
        if (field[j][i] == 2) {
          s = {j, i};
        } else if (field[j][i] == 3) {
          g = {j, i};
        }
      }
    }
    /* cout<<s.x<<endl; */
    dfs(s, 1, field);
    cout << ((ans == 100) ? -1 : ans) << endl;
  }
}



Measured memory_bytes: 3220
import java.util.*;
 
public class Main {
    public static void main(String[] args) {	
	Main main = new Main();
    	main.solveA();
    }
    
    private void solveA() {
    	Scanner sc = new Scanner(System.in);
    	long n = sc.nextLong();
	long m = 0;
	int cnt = 0;
	long top = 0;

	while(n > 0){
	    top = n % 10;
	    m += n % 10;
	    n /= 10;
	    cnt ++;
	}
	long ans = top + (cnt-1) * 9 - 1;
	ans = (m > ans ? m : ans);
	System.out.println(ans);
    }
}

Measured memory_bytes: 21844