akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

void swap(int *x, int *y)
{
  int tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(void)
{
  int x, y;

  while (1) {
    scanf("%d %d", &x, &y);
    if (x == 0 && y == 0) {
      break;
    } else {
      if (x > y) swap(&x, &y);
      printf("%d %d\n", x, y);
    }
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

ll nP2(ll n){
  return (n * (n - 1)) / 2;
}

int main() {
  ll n;
  //string s;
  ll ans = 0;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  map<ll, ll> m; //初めてmapを使う。社員名とその時給とかを1対1で紐づける。
  //※※※at()を使わない。[]を使う。※※※
  
  rep(i, n) m[a.at(i)]++;
  for(auto itr = m.bg; itr != m.ed; ++itr) ans += nP2(itr->second);//イテレータってのでなんかやってる(順列の総和)。
  rep(i, n) cout << ans - m[a.at(i)] + 1 << endl;
}

Measured memory_bytes: 12416
import math


def distance(N, D, X):
    distance_list = list()

    for n in range(N - 1):
        for i in range(n + 1, N):
            tmp = 0
            for d in range(D):
                tmp += (abs(X[n][d] - X[i][d])) ** 2
            distance_list.append(math.sqrt(tmp))

    return distance_list


def main():

    N, D = map(int, input().split())
    X = list()

    for _ in range(N):
        X.append(list(map(int, input().split())))

    distance_list = distance(N, D, X)

    ans = 0

    for i in distance_list:
        if i.is_integer():
            ans += 1

    print(ans)

    return


if __name__ == "__main__":
    main()


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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) REP (i, 0, n)
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

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

int main() {
	int a[4], b[4];
	while (cin >> a[0]) {
		rep (i, 3) cin >> a[i + 1];
		rep (i, 4) cin >> b[i];

		int hit = 0, blow = 0;
		rep(i, 4) {
			rep(j, 4) {
				if (a[i] == b[j]) blow++;
			}
			if (a[i] == b[i]) {
				hit++;
				blow--;
			}
		}
		cout << hit << " " << blow << endl;
	}
}

Measured memory_bytes: 1160
X, K, D = map(int, input().split())
 
k = abs(int(X / D))
k = min(k, K)
if X > 0:
  x = X - k * D
else:
  x = X + k * D
 
diff = K - k
if diff % 2 == 0:
	print(abs(x))
else:
  x_plus = x + D
  x_minus = x - D
  print(min(abs(x_plus), abs(x_minus)))

Measured memory_bytes: 61768
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if( a == b+c || b == a+c || c == a+b)
		printf("Yes\n");
	else 
		printf("No\n");
	
	return 0;
 } 

Measured memory_bytes: 128
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let c: String = read();
    let vowel = "aiueo";
    let ans = if vowel.contains(c.chars().next().unwrap()) { "vowel" } else { "consonant" };
    println!("{}", ans);
}

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

using namespace std;

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

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int n, m;
int a[112345];
int aic[2][112345], adc[2][112345];
ll dc[2][112345], sum[112345];

int main() {
	cin >> n >> m;
	REP(i, n) scanf("%d", a + i);
	
	REP(i, n - 1) {
		int idx = a[i] >= a[i + 1];
		
		int aa = a[i] + 1;
		int bb = a[i + 1];
		
		if (aa == m + 1) aic[1][1]++;
		else aic[0][aa]++;
		adc[idx][bb]++;
		dc[idx][bb] += (a[i + 1] - a[i] + m) % m - 1;
	}
	
	ll now = 0, aa = 0, p = 1;
	
	REP(i, 2 * m) {
		now += aa;
		sum[p] += now;
		
		int idx = i >= m;
		aa += aic[idx][p] - adc[idx][p];
		now -= dc[idx][p];
		
		p++;
		if (p > m) p = 1;
	}
	
	pll ma(-INF, 0);
	FOR(i, 1, m + 1) chmax(ma, pll(sum[i], i));
	
	int c = ma.se;
	ll ans = 0;
	
	REP(i, n - 1) {
		ll now = INF;
		
		chmin(now, (a[i + 1] - a[i] + m) % m);
		chmin(now, 1 + (a[i + 1] - c + m) % m);
		
		ans += now;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3840
import java.util.Scanner;
public class Main{
    public static void main(String[]args){

        Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc. nextInt();
	if(a > b){
	    System.out.println("a > b");
	}else if(a < b){
	    System.out.println("a < b");
	}else if(a == b){
	    System.out.println("a == b");
	}
    }
}

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const ll mod=1e9+7;

int main()
{
    cin.tie( 0 );
    ios::sync_with_stdio( false );
	
	int n;
	cin>>n;
	VI v;
	REP(i,n){
		int p;cin>>p;
		v.push_back(p);
	}

	int ans=0;
	REP(i,n-2){
		if(v[i]<=v[i+1]&&v[i+1]<v[i+2])ans++;
		if(v[i]>v[i+1]&&v[i+1]>=v[i+2])ans++;
	}
	cout << ans << endl;
    return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> k(m);
    vector<int> r;
    for(int i=0;i<m;i++){
        cin>>k.at(i);
        for(int j=0;j<k.at(i);j++){
            int a;
            cin>>a;
            r.push_back(a);
        }
    }
    vector<int> p(m);
    for(int i=0;i<m;i++){
        cin>>p[i];
    }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        vector<int> s(n,0);
        for(int l=0;l<n;l++){
            if(i & (1<<l)){
                s[l]=1;
            }
        }
        int head=0;
        int flag=0;
        for(int j=0;j<m;j++){
            int count=0;
            for(int x=0;x<k[j];x++){
                if(s[r[head+x]-1]==1) count++;
            }
            if(count%2==p[j])flag++;
            head+=k[j];
        }
        if(flag==m) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
 
  
#  "B%(A-1)==1" だとB=1をケアできないので注意。
if (B-1)%(A-1) == 0:
  print(int((B-1)/(A-1)))
else:
  print((B-1)//(A-1) +1)

Measured memory_bytes: 9132
#(i,j)→（i+1,j+2）をx回、(i,j)→（i+2,j+1）がy回あるとすると
#x=(2Y-X)//3,y=(2X-Y)//3、となる
#これが整数or非負なら(x+y)Cxを求めればいい

X,Y=list(map(int,input().split()))
import sys
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
  print(0)
  sys.exit()
if (2*Y-X)<0 or (2*X-Y)<0:
  print(0)
  sys.exit()

  
#それ以外なら存在する
x=(2*Y-X)//3
y=(2*X-Y)//3
#(x+y)Cxを求める

fac=[0 for i in range(x+y+1)]
inv=[0 for i in range(x+y+1)]
finv=[0 for i in range(x+y+1)]
#初期条件
fac[0]=fac[1]=1
inv[1]=1
finv[0]=finv[1]=1
p=1000000007
for i in range(2,x+y+1):
  fac[i]=(fac[i-1]*i)%p
  #p=(p//a)*a+(p%a) pの世界で　a^(-1)=-(p//a)*inv[p%a]
  inv[i]=(-(p//i)*inv[p%i])%p
  finv[i]=(finv[i-1]*inv[i])%p

print((fac[x+y]*finv[x]%p)*finv[y]%p)



Measured memory_bytes: 88068
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {
    static StringBuilder sb;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sb = new StringBuilder();

        BitSet bs = new BitSet(64);

        long q = sc.nextLong();

        for (int i = 0; i < q; i++) {
            int type = sc.nextInt();
            switch (type) {
                case 0:
                    if (bs.get(sc.nextInt())) sb.append(1).append("\n");
                    else sb.append(0).append("\n");
                    break;
                case 1:
                    bs.set(sc.nextInt());
                    break;
                case 2:
                    bs.clear(sc.nextInt());
                    break;
                case 3:
                    bs.flip(sc.nextInt());
                    break;
                case 4:
                    if (bs.cardinality() == 64) sb.append(1).append("\n");
                    else sb.append(0).append("\n");
                    break;
                case 5:
                    if (!bs.isEmpty()) sb.append(1).append("\n");
                    else sb.append(0).append("\n");
                    break;
                case 6:
                    if (bs.isEmpty()) sb.append(1).append("\n");
                    else sb.append(0).append("\n");
                    break;
                case 7:
                    sb.append(bs.cardinality()).append("\n");
                    break;
                case 8:
                    sb.append(toBitInteger(bs)).append("\n");
                    break;
                default:
                    return;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.print(sb);
        out.flush();
        
        sc.close();
    }

    public static BigInteger toBitInteger(BitSet bs) {
        BigInteger rst = BigInteger.ZERO;
        BigInteger weight = BigInteger.ONE;
        BigInteger two = BigInteger.valueOf(2);
        for (int i = 0; i < 64; i++) {
            if (bs.get(i)) rst = rst.add(weight);
            weight = weight.multiply(two);
        }
        return rst;
    }
}



Measured memory_bytes: 109100
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[N][N], B[N][N];
    rep(i, N) {
        rep(j, N){
            cin >> A[i][j]; 
            B[i][j] = A[i][j];
        }
    }
    rep(k, N) {
        rep(i ,N) {
            rep(j, N) {
                B[i][j] = min(B[i][j], B[i][k] + B[k][j]);
            }
        }
    }
    ll ans = 0;
    rep(i, N) {
        for (int j = i+1; j < N; j++) {
            ans += A[i][j];
            if (B[i][j] < A[i][j]) {
                cout << "-1" << endl;
                return 0;
            }
            rep(k, N) {
                if (k != i && k != j && B[i][j] == (B[i][k] + B[k][j])) {
                    ans -= A[i][j];
                    break;
                }  
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
ans = [0 for _ in range(10001)]

for i in range(1,101):
  for j in range(1,101):
    for k in range(1,101):
      v = i*i + j*j + k*k + i*j + j*k + k*i
      if v < 10001:
        ans[v] += 1

for i in range(n):
  print(ans[i+1])

Measured memory_bytes: 69104
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
else
  class UnionFind
    def initialize(n)
      @size = Array.new(n + 1, 1)
      @parent = []

      n.times do |i|
        @parent[i] = i
      end
    end

    def find(x)
      if @parent[x] == x
        x
      else
        @parent[x] = find(@parent[x])
      end
    end

    def unite(x, y)
      x = find(x)
      y = find(y)
      return if x == y

      @parent[y] = x
      @size[x] += @size[y]
    end

    def same?(x, y)
      find(x) == find(y)
    end

    def size(x)
      @size[find(x)]
    end
  end

  N = gets.to_i
  cities = Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
  temp = Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
  coords = N.times.map.with_index(1) do |i|
    coord = gets.split.map(&:to_i)

    cities[coord[0]][coord[1]] << i
    temp[coord[0]][coord[1]] << i

    coord
  end

  x_order = coords.sort_by { |x, _y| x }
  y_order = coords.sort_by { |_x, y| y }

  edges = []

  x_order.each_cons(2) do |(x1, y1), (x2, y2)|
    cost = x2 - x1

    c1 = temp[x1][y1].pop
    c2 = temp[x2][y2].last
    next if c1 == c2

    edges << [c1, c2, cost]
  end

  y_order.each_cons(2) do |(x1, y1), (x2, y2)|
    cost = y2 - y1

    c1 = cities[x1][y1].pop
    c2 = cities[x2][y2].last
    next if c1 == c2

    edges << [c1, c2, cost]
  end

  edges.sort_by! { |_from, _to, cost| cost }
  uf = UnionFind.new(N)

  ans = 0

  edges.each do |from, to, cost|
    unless uf.same?(from, to)
      uf.unite(from, to)
      ans += cost
    end
  end

  puts ans
end


Measured memory_bytes: 152464
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n), ans(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        ans[i] = abs(a * 1000 - (t * 1000 - h[i] * 6));
    }
    int min = ans[0];
    int minIndex = 0;
    for (int i = 1; i < n; i++) {
        if (ans[i] < min) {
            min = ans[i];
            minIndex = i;
        }
    }
    cout << minIndex + 1 << endl;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vpii        vector< pii >
#define vi          vector<ll>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			1'010'000'000'000'000'017LL
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define sz(x)       (ll)x.size()
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )

using namespace std;

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


void Main()
{
	ll N;
	cin >> N;
	vvi ABC(3, vi(N + 10, 0));
	rep(i, 0, N) {
		cin >> ABC[0][i] >> ABC[1][i] >> ABC[2][i];
	}
	vvi dp(3, vi(N + 10, 0));

	rep(i, 0, N) {
		rep(y, 0, 3) { // yesterday
			rep(t, 0, 3) { // today
				if (y == t) continue;
				chmax(dp[t][i + 1], (dp[y][i] + ABC[t][i]));
			}
		}
	}

	cout << max(dp[0][N], max(dp[1][N], dp[2][N])) << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	Main();
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int a[4];
    for (int i = 0; i < 4; i++)
    {
        a[i] = s[i] - '0';
    }

    int ans;
    for (int i = 0; i < 8; i++)
    {
        ans = a[0];
        for (int j = 0; j < 3; j++)
        {
            if(i & (1 << j)) ans += a[j + 1];
            else ans -= a[j + 1];
        }
        if(ans == 7){
            cout << a[0];
            for (int j = 0; j < 3; j++)
            {
                if(i & (1 << j)) cout << "+" << a[j + 1];
                else cout << "-" << a[j + 1];
            }
            break;
        }
    }
    cout << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
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; }

const int MOD=1000000007;
int INF=100100100100100;
int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}

int beki(int a,int b)
{
	if(b==0)return 1;
	int x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

int inv(int a)
{
	return beki(a,MOD-2);
}

int kaijou(int a)
{
	int ans=1;
	for(int i=1;i<=a;i++)
	{
		ans=(ans*i)%MOD;
	}			
	return ans;
}

/*int combi(int a,int b)
{
	int ret=1;
	for(int i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}*/
/*
const int MAX_a=200010;
int cb[MAX_a+1]
void combi(int a,int b)
{
    int ret=1;
    cb[0]=1;
    for(int i=1;i<=b;i++)
    {
	ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
        cb[i]=ret;
    }
	
}*/

vector<P> prime_factorize(int N)
{
	vector<P> res;
	for(int a=2;a*a<=N;a++)
	{
		if(N%a!=0)continue;
		int ex=0;
		while(N%a==0)
		{
			ex++;N/=a;
		}
		res.push_back(P(a,ex));
	}
	if(N!=1)res.push_back(P(N,1));
	return res;
}

//ここから書く
signed main(){
  int n;cin>>n;
  cout<<n*800-(n/15)*200<<endl;
  return 0;
}

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

typedef pair<int,int> P;
const int INF = 500000000;

int main(){
    int n;
    cin >> n;
    vector<char> v(n);
    ll R=0,G=0,B=0;
    for (int i = 0; i < n; i++){
        cin >> v[i];
        if (v[i] == 'R') R++;
        else if (v[i] == 'G') G++;
        else if (v[i] == 'B') B++;
    }
    ll ans = R*G*B;
    for (int i = 1; i < n; i++){
        for (int j = 0; j+i+i < n; j++){
            if (v[j] != v[j+i] && v[j] != v[j+i+i] && v[j+i] != v[j+i+i]){
                ans -= 1;
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3628
#include <cstdio>
const int MOD = 998244353;
const int MAXN = 10000000;
int sub(int x, int y) { return x - y < 0 ? x - y + MOD : x - y; }
int pow_mod(int b, int p) {
	int ret = 1;
	while (p) {
		if (p & 1) ret = 1LL * ret * b % MOD;
		b = 1LL * b * b % MOD;
		p >>= 1;
	}
	return ret;
}
int pw2[MAXN + 5], fct[MAXN + 5], ifct[MAXN + 5];
void init() {
	pw2[0] = 1;
	for (int i = 1; i <= MAXN; i++)
		pw2[i] = 2LL * pw2[i - 1] % MOD;
	fct[0] = 1;
	for (int i = 1; i <= MAXN; i++)
		fct[i] = 1LL * fct[i - 1] * i % MOD;
	ifct[MAXN] = pow_mod(fct[MAXN], MOD - 2);
	for (int i = MAXN - 1; i >= 0; i--)
		ifct[i] = 1LL * ifct[i + 1] * (i + 1) % MOD;
}
int comb(int n, int m) {
	return 1LL * fct[n] * ifct[m] % MOD * ifct[n - m] % MOD;
}
int main() {
	init(); int N;
	scanf("%d", &N);
	int ans = pow_mod(3, N);
	for (int i = N / 2 + 1; i <= N; i++)
		ans = sub(ans, 2LL * comb(N, i) * pw2[N - i] % MOD);
	printf("%d\n", ans);
} 


Measured memory_bytes: 117376
#include <bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
	int m,d;
	cin >> m >> d;
	int sum=0;
	for(int i=4;i<=m;i++){
		for(int j=22;j<=d;j++){
			int a=j/10,b=j%10;
			if(b<2) continue;
			if(a*b==i)
			sum++;
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val aTime = readLine()!!.toInt()
    val bTime = readLine()!!.toInt()
    val cTime = readLine()!!.toInt()
    val dTime = readLine()!!.toInt()
    val eTime = readLine()!!.toInt()

    val timeList = mutableListOf(aTime, bTime, cTime, dTime, eTime)
    val maxTime = timeList.filter{
        it % 10 != 0
    }.maxBy {
        10 - it % 10
    }


    var decided = false
    val computed = timeList.map {
        if (it == maxTime && !decided) {
            decided = true
            it
        } else {
            if (it%10 == 0) it else it + 10 - it%10
        }
    }

    print(computed.sum())

}

Measured memory_bytes: 33788
#include <stdio.h>
#include <stdlib.h>

int xxx(int a, int b){
    if(b==0) return a;
    return xxxx(b, a%b);
}
int xxxx(int a, int b){
    while(b!=0){
        int t;
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}
int main()
{
    int a, b;

    scanf("%d%d",&a,&b);
    int t = xxx(a, b);
    printf("%d\n",t);
    return 0;
}



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "} ";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;


int32_t main(){
	ios::sync_with_stdio(false);
    string a;
    cin>>a;
    if(a.size()==2){
        if(a[0]==a[1]){
            cout<<1<<" "<<2<<"\n";
        }
        else{
            cout<<-1<<" "<<-1<<"\n";
        }
        return 0;
    }
    int f=0;
    for(int i=0;i<(a.size()-2);i++){
        if(a[i]==a[i+1] || a[i]==a[i+2] || a[i+1]==a[i+2]){
            cout<<i+1<<" "<<i+3<<"\n";
            return 0;
        }
    }
    if(f==0){
        cout<<"-1 -1\n";
    }



	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        int v[] = new int[n];
        int c[] = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();

        }
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();

        }

        for (int i = 0; i < n; i++) {
            if (v[i] > c[i]) {
                ans += v[i];
                ans -= c[i];
            }
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

struct UF{
	int par[100010],r[100010];
	void init(){
		rep(i,100010){
			par[i] = i;
			r[i] = 0;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
	void unit(int x,int y){
		if(same(x,y))return;
		x = find(x);
		y = find(y);
		if(r[x] < r[y]){
			par[x] = y;
		}
		else {
			par[y] = x;
			if(r[x] == r[y]){
				r[x] ++;
			}
		}
	}
}uf;

int main(){
	static int n,m;
	static int p[200010],q[200010],c[200010];
	scanf("%d%d",&n,&m);
	rep(i,m){
		scanf("%d%d%d",&p[i],&q[i],&c[i]);
	}
	
	vector<int> Z;
	rep(i,m){
		Z.pb(c[i]);
	}
	sor(Z);
	uniq(Z);
	rep(i,m){
		c[i] = lb(Z,c[i]) - Z.begin();
	}
	
	static vector<P> G[300010];
	static vector<P> r[200010];
	static vector<int> s[200010];
	rep(i,m){
		r[c[i]].pb(P(p[i],q[i]));
		s[c[i]].pb(p[i]);
		s[c[i]].pb(q[i]);
	}
	static vector<int> vec[100010];
	uf.init();
	int t = 1;
	rep(i,Z.size()){
		rep(j,r[i].size()){
			uf.unit(r[i][j].fr,r[i][j].sc);
		}
		rep(j,s[i].size()){
			vec[uf.find(s[i][j])].pb(s[i][j]);
		}
		rep(j,s[i].size()){
			if(vec[s[i][j]].size() == 0)continue;
			rep(k,vec[s[i][j]].size()){
				G[vec[s[i][j]][k]].pb(P(n+t,1));
				G[n+t].pb(P(vec[s[i][j]][k],0));
			}
			vec[s[i][j]].clear();
			t ++;
		}
		rep(j,s[i].size()){
			uf.par[s[i][j]] = s[i][j];
			uf.r[s[i][j]] = 0;
		}
	}
	
	static int cost[300010];
	static bool used[300010];
	static priority_queue<P,vector<P>,greater<P>> que;
	rep(i,300010){
		cost[i] = INF;
		used[i] = false;
	}
	cost[1] = 0;
	que.push(P(0,1));
	while(!que.empty()){
		P p = que.top(); que.pop();
		if(!used[p.sc]){
			used[p.sc] = true;
			rep(i,G[p.sc].size()){
				P ed = G[p.sc][i];
				if(cost[ed.fr] > p.fr + ed.sc){
					cost[ed.fr] = p.fr + ed.sc;
					que.push(P(cost[ed.fr],ed.fr));
				}
			}
		}
	}
	
	if(cost[n] == INF)puts("-1");
	else cout << cost[n] << endl;
}



Measured memory_bytes: 52212
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,f,g,h,i;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
    bool s =false;
    bool t=false;
    bool u =false;
    bool w =false;
    if(b-a==e-d&&e-d==h-g)s=true;
    if(c-a==f-d&&f-d==i-g)t=true;
    if(d-a==e-b&&e-b==f-c)u=true;
    if(g-a==h-b&&h-b==i-c)w=true;
    if(s&&t&&u&&w)cout<<"Yes"<<endl;
    else {
    cout<<"No"<<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 vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  cin >> N;
  vi A(N);
  vi v;
  rep(i,N) {
    cin >> A[i];
    if(i>A[i]) v.push_back(i-A[i]);
  }
  sort(v.begin(),v.end());
  
  ll ans=0;
  rep(i,N)
    ans+=upper_bound(v.begin(),v.end(),i+A[i])-lower_bound(v.begin(),v.end(),i+A[i]);
  
  cout << ans << endl;
}

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

int main()
{
	auto& in = cin;
	const int numBits = 30;
	int N;
	in >> N;
	vector<unsigned int> A(N);
	vector<int> bitCount(numBits);
	for (int i = 0; i < N; ++i) {
		in >> A[i];
		for (int j = 0; j < numBits; ++j)
			if ((A[i] >> j) & 0x1)
				++bitCount[j];
	}
	vector<unsigned int> Out(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < numBits; ++j) {
			unsigned int bit = (bitCount[j] % 2 == 0) ? ((A[i] >> j) & 0x1) : (~(A[i] >> j) & 0x1);
			Out[i] |= (bit << j);
		}
	}
	cout << Out[0];
	for (int i = 1; i < N; ++i) {
		cout << " " << Out[i];
	}

	return 0;
}


Measured memory_bytes: 4708
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
const int INF = INT_MAX / 2;

typedef long long ll;

int N, M;
int fld[2][100][100];

bool IsOutside(int x, int y)
{
	return x < 0 || N <= x || y < 0 || N <= y;
}

void RotateField()
{
	int fld_c[100][100];
	for(int i = 0; i < M; i++)
	{
		for(int j = 0; j < M; j++)
		{
			fld_c[M - 1 - j][i] = fld[1][i][j];
		}
	}
	for(int i = 0; i < M; i++)
	{
		for(int j = 0; j < M; j++)
		{
			fld[1][i][j] = fld_c[i][j];
		}
	}
}

bool IsAgreement(int x0, int y0, int &x1, int &y1)
{
	x1 = -1;
	for(int i = 0; i < M; i++)
	{
		for(int j = 0; j < M; j++)
		{
			if(fld[1][i][j] == -1) continue;
			if(IsOutside(x0 + j, y0 + i) || fld[0][y0 + i][x0 + j] != fld[1][i][j]) return false;
			if(x1 == -1)
			{
				x1 = x0 + j; y1 = y0 + i;
			}
		}
	}
	return true;
}

int main(){
	while(cin >> N >> M, N || M)
	{
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < N; j++)
			{
				cin >> fld[0][i][j];
			}
		}
		for(int i = 0; i < M; i++)
		{
			for(int j = 0; j < M; j++)
			{
				cin >> fld[1][i][j];
			}
		}

		int x, y;
		int ax = -1, ay;
		for(int i = 0; i < 4; i++)
		{
			/*puts("");
			for(int j = 0; j < M; j++)
			{
				for(int k = 0; k < M; k++)
				{
					if(fld[1][j][k] == -1) printf(" O");
					else printf(" X");
				}puts("");
			}puts("");*/

			for(int j = -M; j < N; j++)
			{
				for(int k = -M; k < N; k++)
				{
					if(!IsAgreement(k, j, x, y)) continue;
					if(ax == -1 || ay > y || (ay == y && ax > x)) ax = x, ay = y;
				}
			}
			RotateField();
		}

		if(ax == -1) puts("NA");
		else printf("%d %d\n", ++ax, ++ay);
	}
	return 0;
}

Measured memory_bytes: 1232
N, P = map(int, input().split())
S = list(map(int,list(input())))
U = [0 for i in range(N+1)]
POW = [1 for i in range(N)]

for i in range(N-1):
    POW[i+1] = (POW[i]*10) % P

for i in range(N):
    U[N-(i+1)] = (U[N-i] + S[N-1-i] * POW[i]) % P
    
def solve(U,S):
    if P == 2 or P == 5:
        return solve1(S)
    else:
        return solve2(U)
    
def solve1(S):
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i+1
    return ans

def solve2(U):
    ans = 0
    cnt = [0 for i in range(P)]
    for i in range(N+1):
        cnt[U[i]] += 1
    for i in range(P):
        p = cnt[i]
        ans += (p * (p-1)) // 2
    return ans

print(solve(U,S))

Measured memory_bytes: 20112
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

const int Maxn = 200010;
const int MOD = (int) 1e9 + 7;

class unionfind {
    int num;
    vector<int> par;
public:
    explicit unionfind(int n) : num(n), par(n, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        num--;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size() { return num; }

    int size(int x) { return -par[find(x)]; }
};

int n, m, k;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    unionfind uf_t(n), uf_r(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf_r.unite(a, b);
    }
    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf_t.unite(a, b);
    }

    map<P, int> mp;
    for (int i = 0; i < n; ++i) {
        int root_r = uf_r.find(i), root_t = uf_t.find(i);
        mp[P(root_r, root_t)]++;
    }
    for (int i = 0; i < n; ++i) {
        if (i != 0) cout << " ";
        int root_r = uf_r.find(i), root_t = uf_t.find(i);
        cout << mp[P(root_r, root_t)];
    }
    cout << endl;
}


Measured memory_bytes: 13568
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int B[] = new int[N - 1];
      	int A[] = new int[N];
        int count = 0;
      	int i = 0;
      	for(i = 0;i < N - 1;i++){
          B[i] = sc.nextInt();
        }
      	A[0] = B[0];
      	for(i = 1;i < N - 1; i++){
          if(B[i - 1] < B[i]){
            A[i] = B[i - 1];
          }else if(B[i - 1] >= B[i]){
          	A[i] = B[i];
          }
        }
      	A[N - 1] = B[N - 2];
      	for(i = 0;i < N; i++){
          count += A[i] ;
        }
        System.out.println(count);   
    }
}

Measured memory_bytes: 35844
#include <bits/stdc++.h>
using namespace std; 
#define loop for(int i=0;i<n;i++)
#define pb push_back
#define int long long int
#define mod 1000000007
int32_t main()
{
	int k,a,b;
	cin>>k>>a>>b;
	bool flag=false;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			flag=true;
		}
	}
	if(flag)
	puts("OK");
	else
	puts("NG");
}


Measured memory_bytes: 3632
D = int(input())
cs = list(map(int, input().split()))
#s = [input().split() for l in range(D)]
S=0
l=[]
for d in range(D):
    s=list(map(int, input().split()))
    max_value = max(s)
    max_index = s.index(max_value)
    l.append(max_index+1)
    S+=max_value
    

for i in range(D):
    print(l[i])

Measured memory_bytes: 9012
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

long  long MOD = 1e9 + 7;

int main() {
    int N, cnt = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            cnt++;
            a /= 2;
        }
    }
    cout << cnt << endl;

    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    string s, t; std::cin >> s >> t;
    int a, b; std::cin >> a >> b;
    string u; std::cin >> u;
    if (s == u) a--;
    else if (t == u) b--;
    std::cout << a << " " << b << "\n";
}


Measured memory_bytes: 256
class Node
  attr_reader :id, :siblings
  attr_accessor :state, :started_at, :finished_at

  def initialize(id)
    @id = id
    @siblings = []
    @state = :white
    @started_at = nil
    @finished_at = nil
  end

  def <<(sibling)
    @siblings << sibling
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  temp = Hash.new {|hash, id| hash[id] = Node.new(id) }

  n.times do
    id, _, *sibling_ids = gets.chomp.split.map(&:to_i)

    node = temp[id]

    sibling_ids.each do |sibling_id|
      node << temp[sibling_id]
    end
  end

  nodes = temp.values.sort_by(&:id)

  time = 0

  nodes.each do |node|
    next unless node.state == :white

    stack = [node]

    node.state = :gray

    time += 1
    node.started_at = time

    until stack.empty?
      current = stack.last
      sibling = current.siblings.sort_by(&:id).find {|s| s.state == :white }

      if sibling
        sibling.state = :gray
        time += 1
        sibling.started_at = time
        stack << sibling
      else
        stack.pop
        current.state = :black
        time += 1
        current.finished_at = time
      end
    end
  end

  nodes.each do |node|
    puts [node.id, node.started_at, node.finished_at].join(' ')
  end
end

Measured memory_bytes: 8848
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

int K;
long long *A;
long long low, high;
long long nextL, nextH;

int main() {
	low = 2;
	high = 2;


	cin >> K;
	A = new long long[K];

	for (int i = 0; i < K; i++) {
		cin >> A[i];

	}

	for (int i = K - 1; i >= 0; i--) {
		if (low%A[i] != 0) {
			nextL = (A[i] - low % A[i]) + low;
		}
		else {
			nextL = low;
		}
		nextH = high - high % A[i] + A[i] - 1;

		if (nextL > high || high - high % A[i]<low) {
			cout << -1 << endl;
			return 0;
		}
		
		low = nextL;
		high = nextH;
	}

	cout << low << " " << high << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

const long long MOD = 1000000007;

int main(){
	int k,a,b;
	cin >> k >> a >> b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class289
    {
        static void Main()
        {
            long N = long.Parse(Console.ReadLine());
            int ans = N.ToString().Length;
            for(int i = (int)Math.Sqrt(N) + 1; i >= 1; i--)
            {
                if (N % i == 0)
                {
                    ans = Math.Min(ans, Math.Max(i.ToString().Length, (N / i).ToString().Length));
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

ans = int(input())

def gcd(n, m):
    n, m = max(n, m), min(n, m)
    if m == 0:
        return n
    return gcd(m, n % m)


for _ in range(N - 1):
    t = int(input())
    ans = (ans * t) // gcd(ans, t)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  string s;
  cin>>n>>s;
  map<char,int> er;
  for(int i=0;i<n;++i)
    ++er[s[i]];
  if(er['W']==0||er['R']==0)
    return cout<<0<<endl,0;
  for(int i=0;i<er['R'];++i)
    if(s[i]=='W')
      ++ans;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3676
// abc179_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

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

    if (N <= M){
        ll a = X;
        ll ans = 0;
        REP(i, N){
            ans += a;
            a = (a * a) % M;
        }
        print(ans);
        return 0;
    }

    ll a = X;
    vector<int> loop(M, -1);
    loop[a] = 0;
    int cycle = 0;

    REP(i, M){
        a = (a * a) % M;
        if (a == 0 || loop[a] != -1){
            cycle = i+1 - loop[a];
            break;
        } else {
            loop[a] = i+1;
        }
    }

//    print(a, cycle, loop[a], loop);

    ll res = 0;
    ll sm = 0;
    REP(i, M){
        if (loop[i] == -1) {
            continue;
        } else if (loop[i] < loop[a]){
            res += i;
        } else {
            sm += i;
        }
    }

    ll ans;
    if (a == 0){
        ans = res + sm;
    } else {
        ans = res + sm * ((N - loop[a]) / cycle);

        int r = (N - loop[a]) % cycle;
        REP(i, r){
            ans += a;
            a = (a * a) % M;
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3716
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
      String s = sc.next();
      int count  = 0;
      for(int i = 0;i<n-2;i++){
         if(s.charAt(i)=='A'&&s.charAt(i+1)=='B'&&s.charAt(i+2)=='C'){
            count++;
         }        
      }
      System.out.println(count);            
   }
}

Measured memory_bytes: 35676
A, B, C, D, E, F = map(int, input().split())
con = -1
ans0 = -1
ans1 = -1

for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if 100*sugar/(water+sugar)>con:
                    con = 100*sugar/(water+sugar)
                    ans0 = water+sugar
                    ans1 = sugar

print(ans0, ans1)

Measured memory_bytes: 43756
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {

  int ans=0;
  string s;

  cin >> s;
  for (int i=0; i<3; i++) {
    if (s[i] == '1') {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC033_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int h = int.Parse(strs[0]);
            int w = int.Parse(strs[1]);

            int[,] bw = new int[h, w];


            int[] counts = new int[2000];

            int count = 0;

            for (int i = 0; i < h; ++i)
            {
                string str = Console.ReadLine();

                bool found = false;

                for (int j = 0; j < w; ++j)
                {
                    if (str[j] == '#')
                    {
                        found = true;
                        count = 0;
                    }
                    else
                    {
                        if (found)
                        {
                            bw[i, j] = count;
                        }
                        else
                        {
                            bw[i, j] = 10000;
                        }
                    }

                    ++count;
                }

                found = false;

                for (int j = w - 1; j >= 0; --j)
                {
                    if (str[j] == '#')
                    {
                        found = true;
                        count = 0;
                    }
                    else
                    {
                        if (found)
                        {
                            if (bw[i, j] > count)
                            {
                                bw[i, j] = count;
                            }
                        }
                    }

                    ++count;
                }

                if (i >= 1)
                {
                    for (int j = 0; j < w; ++j)
                    {
                        int prevCount = bw[i - 1, j] + 1;
                        if (bw[i, j] > prevCount)
                        {
                            bw[i, j] = prevCount;
                        }
                    }
                }
            }

            for (int i = h - 2; i >= 0; --i)
            {
                for (int j = 0; j < w; ++j)
                {
                    int prevCount = bw[i + 1, j] + 1;
                    if (bw[i, j] > prevCount)
                    {
                        bw[i, j] = prevCount;
                    }
                }

            }

            int maxCount = 0;

            for (int i = 0; i < h; ++i)
            {
                for (int j = 0; j < w; ++j)
                {
                    if (bw[i, j] > maxCount)
                    {
                        maxCount = bw[i, j];
                    }
                }
            }

            Console.WriteLine("{0}", maxCount);
        }
    }
}


Measured memory_bytes: 20956
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(500):
    x=math.cos(2*math.pi*i/500)
    y=math.sin(2*math.pi*i/500)
    ax=0
    ay=0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)


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

int A, B, C, D, E, F;

int main() {
   cin >> A >> B >> C >> D >> E >> F;

   // 砂糖、水をそれぞれ独立して作る
   set<int> waterSet, sugarSet;

   // 水
   for (int i = 0; i <= 33; i++) {
      for (int j = 0; j <= 33; j++) {
         int w = 100*A*i + 100*B*j;
         if (w <= F) waterSet.insert(w);
      }
   }

   // 砂糖
   for (int i = 0; i < 3010; i++) {
      for (int j = 0; j < 3010; j++) {
         int s = C*i + D*j;
         if (s <= F) sugarSet.insert(s);
      }
   }
  
   const double nLim = (double)E/(100+E); // 濃度の限界値
   double noudo = -1; // 初期値を-1にしないと一度も更新されなくなってしまう
   int ans1 = 0, ans2 = 0;
   for (int s : sugarSet) {
      for (int w : waterSet) {
         int sum = s + w; // 砂糖水
         if (sum == 0) continue; // 0除算を防ぐため
         double x = (double)s/sum; // 作った砂糖水の濃度
         if (sum <= F && x <= nLim && x > noudo) { // 条件を満たす && 濃度が最大値
            noudo = x;
            ans1 = sum, ans2 = s;
         }
      }
   }
   printf("%d %d\n", ans1, ans2);

   return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k;
    string s;
    cin>>k;
    cin>>s;
    if(s.length()<=k) cout<<s<<endl;
    else {
        for(int i=0;i<k;i++) cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

  int n, a, b;
  cin >> n >> a >> b;
  if ((a + b) % 2 == 0) {
    cout << abs(a - b) / 2 << endl;
    return 0;
  } else {
    cout << min(a, n - b + 1) + ((b - a - 1) >> 1);
    return 0;
  }

  return 0;
}

Measured memory_bytes: 3640