akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>  
using namespace std;
long long mod = (long long)(1e9 + 7);
long long  a[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
long long b[168];
int main()
{
	long long  p, n;
	while (cin >> n)
	{
		for (int p = 1; p <= n; p++)
		{
			for (long long i = 0; i < 168; i++)
			{
				int num = 0;
				int temp = p;
				while (temp%a[i] == 0)
				{
					temp /= a[i];
					num++;
				}
				b[i] += num;
			}
		}
		long long sum = 1;
		for (int i = 0; i < 168; i++)
		{
			if (a[i] != 0)
				sum *= (b[i] + 1) % mod;
			sum %= mod;
		}
		cout << sum << '\n';
	}
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
string s;
ll int n;
ll int dp[400000][102][2];
ll int ans(ll int ind,ll int tight,ll int sum,ll int d)
{if(ind==n)
{return sum%d==0;}
if(dp[ind][sum][tight]!=-1)
	return dp[ind][sum][tight];
 dp[ind][sum][tight]=0;
if(tight==0)
{for(ll int i=0;i<=9;i++)
{dp[ind][sum][tight]=(dp[ind][sum][tight]%mod+ans(ind+1,0,(sum+i)%d,d)%mod)%mod;

	}


}
else if(tight==1)
{ll int num=s[ind]-'0';
for(ll int i=0;i<=num;i++)
{if(i==num)
dp[ind][sum][tight]=(dp[ind][sum][tight]%mod+ans(ind+1,1,(sum+i)%d,d)%mod)%mod;
else
dp[ind][sum][tight]=(dp[ind][sum][tight]%mod+ans(ind+1,0,(sum+i)%d,d)%mod)%mod;
}
}
return dp[ind][sum][tight];
}
int main()
{
   
 memset(dp,-1,sizeof dp);
ll int d;
cin>>s>>d;
n=s.length();
ll int f=(ans(0,1,0,d));

cout<<((f-1+mod)%mod)<<endl;




}

Measured memory_bytes: 638720
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vec vector<ll>
#define p pair<ll,ll>
#define vecp vector<p>
#define f(i,k,n,l) for(ll i=k;i<n;i+=1)
#define fn(i,k,n,l) for(ll i=k;i<=n;i+=1)
#define in(p) scanf("%lld",&p)
#define out(p) printf("%lld\n",p)
#define outs() printf("\n")
using namespace std;
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    vec v;
    ll a,b,c,d,e,f,g,h;

    cin>>a>>b>>c>>d;

    e=a*c;
    ll maxx=e;
    v.pb(e);
    f=a*d;
    v.pb(f);
    g=b*c;
    v.pb(g);
    h=b*d;
    v.pb(h);
    f(i,0,v.size(),1)
    {
        maxx=max(maxx,v[i]);
    }
    cout<<maxx<<endl;


}




Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner in =new Scanner(System.in);
        int N=in.nextInt();
        HashMap<Integer,Integer> d=new HashMap<>();
        int[] result=new int[N];
        int[] A=new int[N-1];
        int[] B=new int[N-1];
        ArrayList<Integer>[] aaa=new ArrayList[N];
        for(int i=0;i<N;i++){
            aaa[i]=new ArrayList<Integer>();
        }

        int[] c=new int[N];
        for(int i=0;i<N-1;i++){
            int a=in.nextInt()-1;
            A[i]=a;
            int b=in.nextInt()-1;
            B[i]=b;
            aaa[a].add(b);
            aaa[b].add(a);

        }
        boolean[] already=new boolean[N];
        for(int i=0;i<N;i++){
            c[i]=in.nextInt();
            already[i]=false;
        }
        Arrays.sort(c);
        Stack<Integer> pos=new Stack<>();
        Stack<Integer> index=new Stack<>();
        int p=0;
        int i=0;
        pos.add(0);
        index.add(0);
        int r=0;
        already[0]=true;

        while(!pos.empty()){
            if(aaa[p].size()==i){
                result[p]=c[r];
                r++;
                p=pos.pop();
                i=index.pop()+1;
                continue;
            }
            if(already[aaa[p].get(i)]){
                i++;
                continue;
            }
            pos.push(p);
            p=aaa[p].get(i);
            already[p]=true;
            index.push(i);
            i=0;
        }

        int sum=0;
        for(int t=0;t<N-1;t++){
            sum+=c[t];
        }
        StringBuilder bu=new StringBuilder("");
        bu.append(sum);
        bu.append("\n");
        for(int t=0;t<N;t++) {
            bu.append(result[t]);
            bu.append(" ");
        }
        System.out.println(new String(bu));

    }
}


Measured memory_bytes: 46256
n = gets.chomp.to_i
a = gets.chomp.to_i
b = gets.chomp.to_i

maxv = b - a
minv = (a < b) ? a :b
(n-2).times{
  j = gets.chomp.to_i
  maxv = (maxv > j -minv) ? maxv : j - minv
  minv = (minv < j) ? minv : j
}

puts maxv

Measured memory_bytes: 8860
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
ll ara[Max+10];

ll dp[3002][3002];

ll call(ll i,ll j)
{
    if(i>j)
        return 0;

    ll &ret=dp[i][j];


      if(~ret)
        return ret;




       ret=max(ara[i]-call(i+1,j),ara[j]-call(i,j-1));



       return ret;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;


       cin>>n;

       input(ara,n);

       memset(dp,-1,sizeof(dp));

       cout<<call(0,n-1)<<endl;





}

Measured memory_bytes: 74156
#include<bits/stdc++.h>
using namespace std;
int dp[2001][2001];
const int mod=1e9+7;
int main(){
	int n,m,s[2000],t[2000];
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<m;i++)
		cin>>t[i];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0||j==0)
				dp[i][j]=1;
			else{
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
				if(s[i-1]!=t[j-1])
					(dp[i][j]+=mod-dp[i-1][j-1])%=mod;
			}
		}
	}
	cout<<dp[n][m]<<endl;
}


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

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    int a = x,b = y,c = z;
    swap(a,b);
    swap(a,c);
    cout << a << " " << b << " " << c << endl;

}

Measured memory_bytes: 256
#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);
    int n;
    cin>>n;
    int ans=(n-2)*180;
    cout<<ans<<"\n";



	return 0;
}

Measured memory_bytes: 256
r,g,b,n = map(int, input().split())
res = 0
for i in range(int(n/r) + 1):
  for j in range(int((n - i * r) / g) + 1):
    if (n - i * r - j * g) % b == 0 or n - i * r - j * g == 0:
      res = res + 1
print(res)

Measured memory_bytes: 3060
#C traveling salesman around lake

k,n = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if a[i+1] - a[i] > ans:
        ans = a[i+1] - a[i]

last = a[0] + k - a[n-1]
if last > ans:
    ans = last

print(k-ans)

Measured memory_bytes: 26444
# coding: utf-8
l, r = map(int, input().split())
mod = 2019
ans = 2*10**9
for i in range(l, r+1):
    i_mod = i % mod
    if i_mod == 0:
        print(0)
        exit()
    for j in range(i+1, r+1):
        j_mod = j % mod
        if j_mod == 0:
            print(0)
            exit()
        ans = min(ans, (i*j)%mod)
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <string>

using namespace std;

int main(void){
    char taro_tmp[500], hanako_tmp[500];
    string taro, hanako;
    int n, p_taro, p_hanako;
  
    p_taro = p_hanako = 0;

    scanf(" %d", &n);
    
    for (int i = 0; i < n; i++){
        scanf(" %s %s", taro_tmp, hanako_tmp);
        taro = taro_tmp;
        hanako = hanako_tmp;

        if (taro > hanako){
            p_taro += 3;
        }
        else if (taro < hanako){
            p_hanako += 3;
        }
        else if (taro == hanako){
            p_hanako++;
            p_taro++;
        }   
    }
    
    printf("%d %d\n", p_taro, p_hanako);
    
    return 0;
}

Measured memory_bytes: 1064
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }.map { it-1 }
    val b = readLine()!!.split(" ").map { it.toInt() }
    val c = readLine()!!.split(" ").map { it.toInt() }

//    var chain = mutableMapOf<Pair<Int, Int>, Int>()
//    for ( i in 0 until c.size) {
//        chain[Pair(i, i+1)]
//    }

    var sum = 0
    var pre = -2
    for ( i in 0 until a.size) {
        sum += b[a[i]]
        if (a[i] - pre == 1) {
            sum += c[pre]
        }
        pre = a[i]
    }

    println(sum)

}

Measured memory_bytes: 38072
#include <cstdio>
#include <algorithm>
const int N = 6e3+5;
int n, P, f[N][N<<1], ans; void fix(int &x) { x<P?0:x-=P; }
int main()
{
    scanf("%d%d", &n, &P), n *= 3, f[0][N] = 1;
    for(int i = 0; i < n; ++i) for(int j = -i; j <= i; ++j)
        fix(f[i+1][j+1+N]+=f[i][j+N]), 
        fix(f[i+2][j-1+N]+=f[i][j+N]*(i+1ll)%P),
        fix(f[i+3][j+N]+=f[i][j+N]*(i+1ll)*(i+2ll)%P);
    for(int i = 0; i <= n; ++i) fix(ans+=f[n][i+N]); printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 166916
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int vec[21];
int cont=0;
for(int i=0;i<n;i++){
	cin>>vec[i];
}
for(int i=0;i<n;i++){
	if(i!=0&&i!=n-1){
		if(vec[i]>vec[i-1]&&vec[i]<vec[i+1]||vec[i]<vec[i-1]&&vec[i]>vec[i+1])
		cont++;
	}
}
cout<<cont<<"\n";
    return(0);
}

Measured memory_bytes: 3632
<?php
$A=[];
for($i=0;$i<256;$i++) $A[$i]=0;

while(1){
  $S=trim(fgets(STDIN));
  if(!$S){break;}

  foreach(str_split($S) as $c) ++$A[ord($c)];
}

for($i=97;$i<123;$i++) echo chr($i),' : ',$A[$i]+$A[$i-32],PHP_EOL;

Measured memory_bytes: 15592
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] as = new int[N];

        for (int i = 0; i < N; i++) {
            as[i] = scanner.nextInt();
        }

        int before = 0;
        int temp = 1; // 連続する番号
        int sum = 0;
        for (int i = 0; i < as.length; i++) {
            int a = as[i];
            if (before == a) {
                temp++;
            } else {
                sum += temp / 2;
                temp = 1;
            }
            if (i == as.length - 1) {
                sum += temp / 2;
            }
            before = a;
        }

        System.out.println(sum);
    }
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    long double N;
    cin >> N;
    cout << (ll)((180.0*(N-2.0)/N) * N) << endl;
}

Measured memory_bytes: 3740
#if 0

順序に考えたら、どこに発電機を建てるのか、家はどの発電機に電線を介するのかがわらりづらいです。
計算も相応に複雑になります。
でも、逆に考えたら、もし発電機が無数台もあったら、ちょうど全ての家のすぐそばに発電機を建てば、答えはzeroになります。
そして、発電機が不足(k<n)の時、一台減少すれば、ある二つの家の間に電線を介してする必要があります。
この時、距離が最も近い家を選択すれば、最優解になります。答えの計算も簡単になりました。

#endif // 0

#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 1e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n,k;
int x[MAXN],b[MAXN];

void work(){
    int QvQ; scanf("%d",&QvQ);
    while(QvQ--){
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++){
            scanf("%d",&x[i]);
        }
        int ans=x[n]-x[1];
//        printf("ans = %d\n",ans);
        if(n<=k) printf("%d\n",0);
        else{
            for(int i=2;i<=n;i++) b[i-1]=x[i]-x[i-1];
//            for(int i=1;i<n;i++) printf("%d ",b[i]);
//            printf("\n");
            sort(b+1,b+n);
//            for(int i=n-1;i>=1;i) printf("%d ",b[i]);
//            printf("\n");
            for(int i=1;i<k;i++) ans-=b[n-i];
            printf("%d\n",ans);
        }
    }
}

int main(){
    work();
    return 0;
}






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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

vector<vector<int>> combination (vector<int> nums, int k) {
    vector<vector<int>> ret;
    if (k == 1) {
        REP (i, (signed)nums.size())
        ret.push_back (vector<int> (1, nums[i]));
    } else {
        REP (i, (signed)nums.size() - k + 1) {
            vector<int> cur (&nums[i + 1], &nums[nums.size()]);
            vector<vector<int>> rows = combination (cur, k - 1);
            REP (j, (signed)rows.size()) {
                rows[j].insert (rows[j].begin(), nums[i]);
                ret.push_back (rows[j]);
            }
        }
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<int> d (N, 0);
    REP (i, N) cin >> d[i];
    int ans = 0;
    for (auto&& lst : combination (d, 2)) {
        ans += lst[0] * lst[1];
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
     int n;
     cin >> n;
     map<int,int>m;
     long long ans = 0;
     for(int i = 0;i < n;i++){
          int a;
          cin >> a;
          m[a]++;
          ans += a;
     }
     int q;
     cin >> q;
     for(int i = 0;i < q;i++){
         int b,c;
         cin >> b >> c;
         int bc = m[b];
         m[c] += bc;
         m[b] = 0;
         ans += (c - b) * bc;

         cout << ans << endl;
     }
}

Measured memory_bytes: 7908
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> a(n);

    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    } 

    sort(a.begin(), a.end(), greater<int>());
    int count = 0, tmp = -1;

    for(int i = 0; i < n; i++){
        if(a.at(i) != tmp){
            count++;
            tmp = a.at(i);
        }
    }
    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

void solve(long long N, std::vector<long long> x){
    vector<mint> inv(N - 1);
    REP(i, N - 1){
        inv.at(i) = mint(i + 1).inv();
    }

    vector<mint> inv_cs(N - 1);
    inv_cs.at(0) = inv.at(0);
    for(ll i = 1; i < inv_cs.size(); ++i){
        inv_cs.at(i) = inv.at(i) + inv_cs.at(i - 1);
    }

    mint f = 1;
    for(ll i = 1; i < N; ++i){
        f *= i;
    }

    mint ans = 0;
    REP(i, N - 1){
        ans += inv_cs.at(i) * (x.at(i + 1) - x.at(i));
    }
    ans *= f;
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, std::move(x));
    return 0;
}


Measured memory_bytes: 2560
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 10000, MAXI = 10000;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 10;
//     cout << tc << "\n";
//     while (tc--)
//     {
//         int n = rand()%N+1;
//         cout << n << " ";
//         cout << rand()%n + 1 << "\n";
//         for(int i=1;i<=n;i++)
//             cout << rand()%MAXI + 1 << " ";
//         cout << "\n";
//         cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
 
 
 
 
 
 
 
//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 
int vis[N], a[N], last[N];
int n, k, ti = 0, ans;
vector<int> v;

void fun(int cur)
{
	if(k==0){
		ans = cur;
		return;
	}
	if(vis[cur]==1){
		vector<int> x;
		for(int i=last[cur];i<v.size();i++)
			x.push_back(v[i]);

		int len = x.size();
		int pos = k%len;
		ans = x[pos];
		return;
	}
	v.push_back(cur);
	vis[cur] = 1;
	last[cur] = ti++;
	k--;
	fun(a[cur]);
}
 
// Driver code to test above functions
int32_t main()
{
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
 
    cin >> n >> k;

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



    fun(1);

    cout << ans;

    return 0;
 
} 

Measured memory_bytes: 21980
#include <bits/stdc++.h>
using namespace std;
#define INF (1 << 29)

struct edge { int to, cost; };
typedef pair<int, int> P;   // firstは最短距離、secondは頂点の番号

const int MAX_V=1000;

int V;
vector<int> G[MAX_V];
int d[MAX_V];
int cnt=0;

void dfs(int s, bool f[], int d){
    //cout << s <<" "<< d << endl;
    if(d==V-1){
        bool F=true;
        for(int i=0; i<V; i++){
            if(f[i]==false){
                F = false;
            }
        }
        if(F) cnt++;
        return;
    }
    
    for(int i=0; i<G[s].size(); i++){
        if(f[G[s][i]]!=true){
            f[G[s][i]]=true;
            dfs(G[s][i], f, d+1);
            f[G[s][i]]=false;
        }
    }
}

int main(){
    int E;
    int from, to;
    cin >> V >> E;
    for(int i=0; i<E; i++){
        cin >> from >> to;
        G[from-1].push_back(to-1);
        G[to-1].push_back(from-1);
    }
    bool f[8]={0};
    f[0]=true;
    dfs(0, f, 0);
    
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 1e6 + 1;
const ll MOD = 1e9 + 7;

bool isPrime[N];

ll gcd(ll a, ll b, ll &x, ll &y) {
    if (a == 0) {
        x = 0ll;
        y = 1ll;
        return b;
    }
    ll nx, ny;
    ll g = gcd(b % a, a, nx, ny);
    x = ny - (b / a) * nx;
    y = nx;
    return g;
}

ll inv(ll a, ll mod = MOD) {
    ll x, y;
    gcd(a, mod, x, y);
    x = (x % mod + mod) % mod;
    return x;
}

int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);
    vi p;
    forab(i, 2, N + 1) {
        if (!isPrime[i]) {
            p.pb(i);
            if (i * 1ll * i <= N) {
                for (int j = i * i; j <= N; j += i)isPrime[j] = true;
            }
        }
    }
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    map<int, int> deg;
    forn(i, n) {
        cin >> a[i];
        b[i] = a[i];
        ll rt = (ll) sqrt(a[i]);
        map<int, int> fac;
        for (int x : p) {
            if (a[i] == 1 || x > rt) break;
            while (a[i] % x == 0) {
                fac[x]++;
                a[i] /= x;
            }
        }
        if (a[i] > 1) fac[a[i]]++;
        for (const pii &d: fac) deg[d.fst] = max(deg[d.fst], d.snd);
    }
    ll lcm = 1;
    for (const pii &d: deg) forn(i, d.snd) lcm = (lcm * 1ll * d.fst) % MOD;
    ll ans = 0;
    for (ll x : b) ans = (ans + inv(x)) % MOD;
    cout << (ans * lcm) % MOD << "\n";
    return 0;
}

Measured memory_bytes: 2168
import sys
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def dijkstra_heap(v, start, edge):
    """
    ダイクストラ法
    :param v: 走査するグラフの頂点数
    :param start: 始点
    :param edge: 重み付き隣接リスト。[cost, node]の形で渡す
    :return: 始点から各頂点への最短距離
    """
    res = [f_inf] * v
    res[start] = 0
    checked = [False] * v
    checked[start] = True
    edge_list = []
    for u in edge[start]:
        heappush(edge_list, u)
    while len(edge_list):
        min_edge = heappop(edge_list)
        cost, node = min_edge
        if not checked[node]:
            res[node] = cost
            checked[node] = True
            for next_cost, next_node in edge[node]:
                if not checked[next_node]:
                    heappush(edge_list, [next_cost + cost, next_node])
    return res


def resolve():
    init = 10 ** 15
    n, m, s, t = map(int, input().split())
    edge_en = [[] for _ in range(n)]
    edge_sn = [[] for _ in range(n)]
    for _ in range(m):
        u, v, a, b = map(int, input().split())
        edge_en[u - 1].append([a, v - 1])
        edge_en[v - 1].append([a, u - 1])
        edge_sn[u - 1].append([b, v - 1])
        edge_sn[v - 1].append([b, u - 1])

    cost_en = dijkstra_heap(n, s - 1, edge_en)
    cost_sn = dijkstra_heap(n, t - 1, edge_sn)
    costs = []
    for i in range(n):
        total_cost = cost_en[i] + cost_sn[i]
        costs.append([total_cost, i])

    heapify(costs)
    cost = 0
    now = -1
    for i in range(n):
        while costs and now < i:
            if costs[0][1] < i:
                heappop(costs)
            else:
                cost, now = heappop(costs)
                break
        print(init - cost)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 108272
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args)throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Reader in = new Reader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        RatingGoal solver = new RatingGoal();
        solver.solve(1, in, out);
        out.close();
    }

    static class RatingGoal {
        public void solve(int testNumber, Reader in, PrintWriter out) throws Exception {
            int r = in.nextInt();
            int g = in.nextInt();
            out.println(2 * g - r);
        }

    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public Reader(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg) {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
using namespace std;
int main(void){
    int N = 0;
    int maxHight = 0;
    int canSee = 0;
    cin >> N;
    for(int i = 0;i < N;i++){
        int x;
        cin >> x;
        
        if(maxHight <= x){
            canSee++;
            maxHight = x;
        }
    }
    cout << canSee << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

    string ans = "No";
    if (n % 2 == 0){
        int len = n / 2;
        string l = s.substr(0, len);
        string r = s.substr(len, len);
        if (l == r){
            ans = "Yes";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];

	vector<int> ma(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		ma[a] = max(ma[a], h[b]);
		ma[b] = max(ma[b], h[a]);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (ma[i] < h[i]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
int N,M,Q,a[55],b[55],c[55],d[55],A[10],ans;
void calc()
{
	int point=0;
	for(int i=0;i<Q;i++)if(A[b[i]]-A[a[i]]==c[i])point+=d[i];
	ans=max(ans,point);
}
void dfs(int dep)
{
	if(dep==N)calc();
	else if(dep==0)for(int i=1;i<=M;i++)A[0]=i,dfs(1);
	else for(int i=A[dep-1];i<=M;i++)A[dep]=i,dfs(dep+1);
}
int main()
{
	cin>>N>>M>>Q;
	for(int i=0;i<Q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;b[i]--;
	}
	dfs(0);
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3580
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n=ii()

arr = Counter(list(input())).values()
ans = 1
for i in arr:
  ans *= (i+1)%mod
print((ans-1)%mod)





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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int N;
int D[13];

int rec(int idx, vector<int> v) {
  int res = 100000000;

  if (idx > 12) {
    sort(all(v));
    rep(i, v.size()) {
      int d = abs(v[(i + 1) % v.size()] - v[i]);
      res = min({res, d, 24 - d});
    }
  } else {
    if (D[idx] > 2) {
      return 0;
    } else if (D[idx] == 2) {
      v.eb(idx);
      v.eb((24 - idx) % 24);
      res = rec(idx + 1, v);
    } else if (D[idx] == 1) {
      vector<int> v1 = v, v2 = v;
      v1.eb(idx);
      v2.eb((24 - idx) % 24);
      res = max(rec(idx + 1, v1), rec(idx + 1, v2));
    } else {
      res = rec(idx + 1, v);
    }
  }

  return res;
}

int main() {
  cin >> N;
  rep(i, N) {
    int d;
    cin >> d;
    D[d]++;
  }
  D[0]++;
  cout << rec(0, vector<int>()) << endl;
}


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

using namespace std;

int dp[1001][1001];

int main(){
	int h , w , MOD = 1e9 + 7;
	cin>>h>>w;
	vector<string> in(h);
	for(int i = 0 ; i < h ; i++) cin>>in[i];
	dp[1][1] = 1;
	for(int i = 1 ; i <= h ; i++) for(int t = 1 ; t <= w ; t++) if(!(i == 1 && t == 1) && in[i - 1][t - 1] == '.') dp[i][t] = (dp[i - 1][t] + dp[i][t - 1]) % MOD;
	cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 9420
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	ll a;
	cin >> a;
	string b;
	if (a > 26) {
		while (a > 0) {
			if (a % 26 != 0) b += a % 26 - 1 + 'a';
			else b += 'z', a--;
			a /= 26; 
		} 
	}
	else {
		char c = a % 26 - 1 + 'a';
		if (a < 26) cout << c;
		else cout << 'z';
	}
	reverse(b.begin(), b.end());
	cout << b;
	
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long long q, h, s, d, n, ans = 0;
    cin >> q >> h >> s >> d >> n;
    if(n % 2 != 0){
        ans += min({q*4, h*2, s});
    }
    ans += n/2 * min({q*8, h*4, s*2, d});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

bool topologicalSort(int node, unordered_map<int,
                     vector<int>>& adjs,
                     unordered_set<int>& visited,
                     unordered_set<int>& back,
                     stack<int>& st)
{
    visited.insert(node);
    back.insert(node);

    for (auto& adj : adjs[node])
    {
        if (back.count(adj) != 0) return false;

        if (visited.count(adj) == 0 && !topologicalSort(adj, adjs, visited, back, st))
            return false;
    }

    st.push(node);

    back.erase(node);

    return true;
}

int maxDFS(int node,
    unordered_map<int, vector<int>>&adjs,
    unordered_set<int>& visited,
    unordered_set<int>& back)
{
    visited.insert(node);
    back.insert(node);

    int depth = 0;

    for (auto& adj : adjs[node])
    {
        if (back.count(adj) != 0) return -1;

        if (visited.count(adj) == 0)
        {
            int currDepth = maxDFS(adj, adjs, visited, back);
            if (currDepth == -1)
                return -1;

            depth = std::max(currDepth, depth);
        }
    }

    back.erase(node);

    return 1 + depth;
}

int solve()
{
    int N, A, B;

    std::cin >> N >> A >> B;

    std::cout << std::min(A, B) << " " << std::max(0, A + B - N) << std::endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}


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

int bubleSort(vector<int> &A, int N){
    int count = 0;
    for(int i = 0; i < N; i++){
        for(int j = N - 1; j > i; j--){
            if(A.at(j-1) > A.at(j)){
                //cout << A.at(j) << " " << A.at(j-1) << endl;
                swap(A.at(j), A.at(j-1));
                //cout << A.at(j) << " " << A.at(j-1) << endl;
                count++;
            }
        }


    }
    return count;
}




int main(){
    int N, count;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    count = bubleSort(A, N);

    for(int i = 0; i < N; i++){
        if(i!=0){
            cout << " ";
        }
        cout << A.at(i);
    }
    cout << endl;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3084
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

k, n = map(int, input().split())
d = getInputListInt()

max_dis = 0
reigai = d[0]+(k-d[n-1])
max_dis = max(max_dis, reigai)

for i in range(1, n, 1):
    tmp = d[i]-d[i-1]
    max_dis = max(max_dis, tmp)

print(k-max_dis)



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

typedef long long ll;

int N;
vector<int> a;
vector<int> sum;

void input() {
    cin >> N;
    a = vector<int>(N);
    rep(i, N) {
        int x;
        cin >> x;
        a[x-1]++;
    }
}

inline bool judge(int& ans, int& k) {
    if (ans == 0) return true;
    int index = upper_bound(a.begin(), a.end(), ans) - a.begin();
    int x = sum[index-1] + ans * (N - index);
    if (x >= ans * k) return true;
    return false;
}

int main() {
    input();
    sort(a.begin(), a.end());
    sum = vector<int>(N);
    sum[0] = a[0];
    for (int i = 1; i < N; i++) sum[i] = sum[i-1] + a[i];
    int ans = N;
    for (int k = 1; k <= N; k++) {
        while (!judge(ans, k)) ans--;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3200
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//


int main(void) {

    int N; cin >> N;
    vector<int> s(N);
    rep(i,N) cin >> s[i];
    Sort(s);
    bool flag = true;
    int tmp = 0;
    int ans = 0;
    rep(i,N) {
        ans += s[i];
        if (flag && s[i] % 10 != 0) {
            tmp = s[i];
            flag = false;
        }
    }
    if (ans % 10 == 0) {
        if (!flag) ans -= tmp;
        else ans = 0;
    }
    out(ans);







    


    return 0;
}











Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer
import scala.util.control.Breaks
import scala.math.abs

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  sc.nextLine()

  val array = ArrayBuffer(List(0, 0, 0))

  (1 to n).foreach(_ => array += sc.nextLine().split(" ").map(_.toInt).toList)

  val b = new Breaks
  b.breakable {
    for (i <- (0 to n - 1)) {
      val now = array(i)
      val next = array(i + 1)

      val tn = abs(next(0) - now(0))
      val xn = abs(next(1) - now(1))
      val yn = abs(next(2) - now(2))

      tn - (xn + yn) match {
        case r if r < 0 => println("No"); b.break()
        case r if r % 2 == 0 =>
        case _ => println("No"); b.break()
      }
    }
    println("Yes")
  }

}


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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

string S,T;
void input()
{
    cin>>S>>T;
}

void solve()
{
    int ans=0;
    for(int i=0;i<S.size();++i){
        if(S[i]!=T[i]) ++ans;
    }
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3832
def main():
    n = int(input())
    A = list(map(int, input().split()))

    sum_a = sum(A)

    d = dict()

    for a in A:
        d[a] = d.get(a, 0) + 1

    for _ in range(int(input())):
        b, c = map(int, input().split())
        if d.get(b, 0) != 0:

            temp = d[b]         
            d[b] -= temp
            d[c] = d.get(c, 0) + temp

            sum_a += (c - b) * temp
        print(sum_a)
        
main()


Measured memory_bytes: 21040
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    map<char, int>d;
    for (int i=0; i<N; i++) {
        if (d.count(S[i]) > 0) {
            d[S[i]] = d[S[i]] + 1;
        } else {
            d[S[i]] = 1;
        }
    }

    int a_count = 0;
    for (auto s : d) {
        a_count++;
    }

    int b_count = 0;
    int max_count = 0;
    for (int i=1; i<N; i++) {
        map<char, int> s;
        int count = 0;
        d[S[i-1]] -= 1;
        for (int j=0; j<i; j++) {
            if (s.count(S[j]) > 0) {
                s[S[j]] += 1;
            } else {
                s[S[j]] = 1;
            }
        }

        for (auto b : d) {
            if (b.second > 0 && s.count(b.first) > 0) {
                count += 1;
            }
        }

        if (count > max_count) {
            max_count = count;
        }
    }

    cout << max_count << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int n;
    bool judge = false;
    int cnt = 0;
    int div_cnt;
    
    cin >> n;
    
    for(int i = 1; i <= n; i += 2){
        div_cnt = 0;
        for(int j = 1; j <= i / 2; j++){
            if(i % j == 0){
                div_cnt++;
            }
        }
        div_cnt++;
        if(div_cnt == 8)    cnt++;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
n =int(input())
a =list(map(int, input().split()))
b =list(map(int, input().split()))
c =list(map(int, input().split()))
c.append(0)

diff = [a[i+1] - a[i] == 1 for i in range(n-1)]
diff.append(False)

ans = sum(b)
for i in range(n):
    if diff[i]:
        ans += (c[a[i]-1])
print(ans)

Measured memory_bytes: 3064
from math import floor

n = int(input())
tax = 1.08
no_tax = floor(n / tax)

if floor(no_tax * 1.08) == n:
  print(no_tax)
elif floor((no_tax+1) * 1.08) == n:
  print(no_tax+1)
else:
  print(":(")


Measured memory_bytes: 2940
#include<stdio.h>
#include <string.h>
int main(){
    int n, m, ans=0;
    scanf("%d %d",&n,&m);
    if(n>1){ ans+=n*(n-1)/2; }
    if(m>1){ ans+=m*(m-1)/2; }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define FASTIO                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);
#define ll long long
#define debug(x) cout << #x << " = " << x << endl
void solve()
{
  map<int, int> fx, fy;
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> s;
  for (int i = 0; i < m; i++)
  {
    int x, y;
    cin >> x >> y;
    s.insert({x, y});
    fx[x]++;
    fy[y]++;
  }
  int mx_x = 0, mx_y = 0;
  for (auto it : fx)
    mx_x = max(mx_x, it.second);

  for (auto it : fy)
    mx_y = max(mx_y, it.second);

  vector<int> xx, yy;
  for (auto it : fx)
    if (it.second == mx_x)
      xx.emplace_back(it.first);
  for (auto it: fy)
    if (it.second == mx_y)
      yy.emplace_back(it.first);
       for (auto x : xx)
    {
        for (auto y : yy)
        {
            if (s.find({x, y}) == s.end())
            {
                cout << mx_x + mx_y;
                return ;
            }
        }
    }
    cout << mx_x + mx_y - 1;
}
int main()
{

  FASTIO
  long long int t;
  t=1;
  while (t--)
    solve();
  return 0;
}


Measured memory_bytes: 49580
def  nnp1(n)
    a=((n*2)**(0.5)).to_i
    return a*(a+1)==n*2
end

def  nnp(n)
    a=((n*2)**(0.5)).to_i
    return a
end

n=gets.strip.to_i

if nnp1(n) == false 
    puts 'No'
    exit
end
puts 'Yes'
a=nnp(n)
x=Array.new(a+1).map{Array.new(a)}
c=1
puts a+1
(0..a-1).each{|i|
    
    cc=c
    (i..a-1).each{|j|
        x[i][j]=cc
        cc+=1
    }

    cc=c
    (i+1..a).each{|j|
        x[j][i]=cc
        cc+=1
    }
    c=cc
}

x.each do |i|
    print a.to_s + " "
    puts i.join(" ")

end

Measured memory_bytes: 4604