akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
typedef long long ll;
int Q;
vector<ll> a;
vector<ll> b;
vector<int> type;
int main() {
    cin >> Q;
    a.assign(Q, 0);
    b.assign(Q, 0);
    type.assign(Q, 0);
    rep(i, 0, Q) {
        cin >> type[i];
        if(type[i] == 1) {
            cin >> a[i] >> b[i];
        }
    }
    priority_queue<ll> mae;
    priority_queue<ll, vector<ll>, greater<ll>> ato;
    ll bsum = 0;
    ll maesum = 0;
    ll atosum = 0;
    rep(i, 0, Q) {
        if(type[i] == 1) {
            bsum += b[i];
            if(mae.size() > ato.size()) {
                // atoに追加
                int top = mae.top();
                if(a[i] >= top) {
                    ato.push(a[i]);
                    atosum += a[i];
                } else {
                    ato.push(top);
                    atosum += top;
                    maesum -= top;
                    mae.pop();
                    mae.push(a[i]);
                    maesum += a[i];
                }
            } else {
                // maeに追加
                if(mae.empty()) {
                    mae.push(a[i]);
                    maesum += a[i];
                } else {
                    int top = ato.top();
                    if(a[i] <= top) {
                        mae.push(a[i]);
                        maesum += a[i];
                    } else {
                        mae.push(top);
                        maesum += top;
                        atosum -= top;
                        ato.pop();
                        ato.push(a[i]);
                        atosum += a[i];
                    }
                }
            }

        } else {
            long long m = mae.top();
            long long res =
                (m * mae.size() - maesum) - (m * ato.size() - atosum) + bsum;
            cout << m << " " << res << endl;
        }
    }
}


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

using namespace std;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {
    ZERO_IQ
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long >> input;
    long long summ = 0;
    for (int i = 0; i < n; ++i) {
        long long q, qq;
        cin >> q >> qq;
        input.push_back({q, qq});
        summ += qq;
    }
    vector<vector<long long >> dp(n, vector<long long>(summ + 1, 1e18));
    long long maxx = 0;
    for (int j = 0; j < n; ++j) {
        dp[j][0] = 0;
        for (int i = 1; i <= summ; ++i) {
            if (!j) {
                if (i == input[j].second)dp[j][i] = input[j].first;
            } else if (input[j].second > i) {
                dp[j][i]=min(dp[j-1][i],dp[j][i]);
            } else {
                dp[j][i] = min(dp[j - 1][i], dp[j - 1][i - input[j].second] + input[j].first);
            }
        }
    }
    for (int i = 0; i <= summ; i++) {
        if (dp[n - 1][i] <= m) {
            maxx = i;
        }
    }
    cout << maxx << endl;
    return 0;
}

Measured memory_bytes: 79488
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 要素数
		int K = sc.nextInt();
		//加算数
		int N = sc.nextInt();
		//配列
		int l [] = new int[K]; 
		int sum = 0;
		for(int i = 0; i < K; i++){
		    l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		for(int j = (K-1); j >= K-N; j--){
		    sum += l[j];
		}
		System.out.println(sum);
	
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600123456
typedef pair<long,int> P;

int main(){
  int n,m,r,q;
  cin>>n>>m>>r>>q;

  vector<int> a(m),b(m),c(m);
  rep(i,m) cin>>a[i]>>b[i]>>c[i];
  rep(i,m) a[i]--,b[i]--;

  vector<vector<P>> rev(n);
  rep(i,m) rev[b[i]].pb(mp(c[i], a[i]));

  vector<vector<long>> vec(n,vector<long>(r, INF));

  rep(i,r){
    priority_queue<P, vector<P>, greater<P>> pq;
    for(int j=i; j<n; j+=r){
      vec[j][i] = 0;
      pq.push(mp(0,j));
    }
    while(!pq.empty()){
      auto p = pq.top(); pq.pop();
      long cost = p.fi;
      int v = p.se;
      if(vec[v][i] < cost) continue;
      for(auto to : rev[v]){
        long ncost = cost + to.fi;
        int nv = to.se;
        if(vec[nv][i] > ncost){
          vec[nv][i] = ncost;
          pq.push(mp(ncost, nv));
        }
      }
    }
  }
//rep(i,n) dbg(vec[i]);
  long ans = 0;
  rep(_,q){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    long get = 0;
    rep(i,r){
      long cost = vec[x][i] + vec[y][i];
      get = max(get, z-cost);
    }
    ans += get;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 21656
n, q = gets.split(" ").map(&:to_i)
s = gets.chomp
lr = []
q.times { lr.push(gets.split(" ").map(&:to_i)) }

sum = Array.new(n + 1, 0)
(0..(n - 2)).each do |i|
  sum[i + 2] = sum[i + 1] + (s[i, 2] == 'AC' ? 1 : 0)
end

lr.each do |_lr|
  l, r = _lr
  puts sum[r] - sum[l]
end

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

int main(void)
{
    int n;
    vector<int> h, dp;
    scanf("%d", &n);
    h.assign(n, 0);
    dp.assign(n, 0);

    for (auto &hi : h)
    {
        scanf("%d", &hi);
    }

    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    printf("%d\n", dp[n - 1]);

    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  ll K;
  cin >> K;
  ll ans = 0;
  rep2(i, 1, K+1){
    rep2(j, 1, K+1){
      rep2(k, 1, K+1){
        ans += euclidean_gcd(i, euclidean_gcd(j, k));
      }
    }
  }
  cout << ans << endl;
}

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

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#define _GLIBCXX_DEBUG
#else
#define debug(_) 0
#endif // LOCAL

vector<long long> as(1, 1);
vector<long long> ps(1, 1);

long long solve(long long level, long long x){
    if (level == 0) {
        return x;
    } else if (x >= as[level]) {
        return ps[level];
    } else {
        if (x <= 1) {
            return 0;
        } else if (x <= as[level - 1] + 1) {
            return solve(level - 1, x - 1);
        } else if (x == as[level - 1] + 2) {
            return solve(level - 1, as[level - 1]) + 1;
        } else {
            return solve(level - 1, as[level - 1]) + 1 + solve(level - 1, x - as[level - 1] - 2);
        }
    }
}

int main(){
    long long N, X;

    for (int i = 0; i < 50; i++) {
        as.push_back(as[i] * 2 + 3);
        ps.push_back(ps[i] * 2 + 1);
    }

    cin >> N >> X;

    cout << solve(N, X) << '\n';

    return 0;
}

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

#define pb push_back
#define fst first
#define snd second
#define INF 0x7fffffff
#define INFLL 0x7FFFFFFFFFFFFFFF
#define lenA(ar) sizeof(ar)/sizeof(*ar)
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(int i=x;i<y;i++)
#define foreI(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sl "\n";
#define ii pair<ll,ll>
#define mk make_pair


typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const int MAXN = 1e5+10;
vector<vector<int>> gp(MAXN);
ll dp[MAXN];
ll solve(int u){
    if(gp[u].size()==0){dp[u]=1;return 1;}
    ll &r=dp[u];
    if(r!=-1)return r;
    for(auto e: gp[u]){
        r=max(r,solve(e)+1);
    }
    return r;
}
int main() {FIN;
    
    memset(dp,-1,sizeof(dp));
    int n,m;cin>>n>>m;
    fore(i,0,m){
        int a,b;cin>>a>>b;
        gp[a-1].pb(b-1);
    }
    ll ans=0;
    fore(i,0,n){
        if(dp[i]==-1){
            ans=max(ans,solve(i));
        }
    }cout<<ans-1<<sl;
    return 0;
}




Measured memory_bytes: 11528
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N, K; cin >> N >> K;
    int a[110]; rep(i, N) cin >> a[i];
    bool dp[100100];
    dp[0] = false;
    rep1(i, K) {
        dp[i] = false;
        rep(j, N) {
            if(i - a[j] >= 0) {
                if(dp[i - a[j]] == false) {
                    dp[i] = true;
                }
            }
        }
    }
    if(dp[K]) {
        cout << "First" << endl; return 0;
    } else {
        cout << "Second" << endl;
    }
	return 0;
}

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

void solver() {
  long long n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a;
    cin >> a;
    n -= a;
  }

  if (n < 0) cout << "-1" << "\n";
  else cout << n << "\n";
}

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


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int a, b, c;
	string s;
	cin >> a >> b;
	cout << a * b - (a + b) + 1 << "\n";
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n; //数列要素数
		int q; //クエリの数
		int com;//クエリタイプ
		int x;
		int y;
		n = scan.nextInt();
		q = scan.nextInt();
		int a[] = new int[n];
		int min;
		//初期化
		for (int i = 0; i < n; i++) {
			a[i] = (int) (Math.pow(2, 31) - 1);
		}
		for (int i = 0; i < q; i++) {
			com = scan.nextInt();
			x = scan.nextInt();
			y = scan.nextInt();
			if (com == 0) {
				if (x < a.length) {
					//update
					a[x] = y;
				}
			} else if (com == 1 ) {
				//find
				min = (int) (Math.pow(2, 31) - 1);
				for (int j = x; j <= y; j++) {
					if (j == x) {
						min = a[j];
					} else if (a[j] < min) {
						min = a[j];
					}
				}
				System.out.println(min);
			}
		}
		scan.close();
	}
}


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

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

int main() {
	int n;
	cin >> n;
	int count = 0;
	for(int i = 1; i <= n; i += 2) {
		if(yakusu(i) == 8) count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
c, d = (int(i) for i in input().split())  
a = [int(i) for i in input().split()]
b = a.copy()
 
k = 0
for i in a:
    b[k] = abs(i - d)
    k += 1
 
m = min(b) 
 
def dec():
 
    i = m
    while i > 0:
        if m% i == 0: 
            k = 0
            for j in b:
                if j%i ==0:
                    k +=1
                if k==len(b):
                    return i
                
            if i == m:
                i -= i//2
                
        i -=1
 
 
 
 
                
print(dec())

Measured memory_bytes: 14224
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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(){
  cout << fixed << setprecision(15);

  int n; cin >> n;
  vector<int> nums(n);
  rep(i, n) cin >> nums[i];

  //ll ans = 0;
  string ans = "";

  map<int, int> numm;
  rep(i, n) numm[nums[i]]++;
  if (numm.size() != n) ans = "NO";
  else ans = "YES";
  
  cout << ans << endl;
  

  return 0;
}
//

Measured memory_bytes: 10368
// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;

const int MOD=1e9+7;

int search(int b[], int m, int s){
	int start=0,end=m-1;
	bool flag=false;
	while(start<=end){
		int mid=(start+end)/2;
		if(b[mid]==s){
			flag=true;
			return mid;
		}
		else if(b[mid]>s) end=mid-1;
		else if(b[mid]<s) start=mid+1;
	}
	if(flag==false) return m;
}

long long int pow(long long int a, long long int b){
	if(b==0) return 1;
	long long int res=pow(a,b/2);
	if(b%2 ==1) return res*res*a;
	else if(b%2 ==0) return res*res;
}

int main(){

	string s,t;
	cin>>s;
	cin>>t;

	bool flag=true;
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i]){
			flag=false;
			break;
		}
	}

	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
} 

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

using namespace std;
bool sorta(pair<string, string> &a,pair<string, string> &b){
    return a.second=="dominant"||a.second=="non-existent"||a.second=="recessive";
}
int main() {
    int t;
    cin >> t;
   int freq[300]={0};
   char charcter[5]={'M','A','R','C','H'};
    while(t--){
        string s;cin>>s;
        if(s[0]=='M'||s[0]=='A'||s[0]=='R'||s[0]=='C'||s[0]=='H'){
            freq[s[0]]++;
        }
    }
    long long answer=0;
    for (int i = 0; i < 5; ++i) {
        for (int j = i+1; j <5 ; ++j) {
            for (int k = j+1; k <5 ; ++k) {
                answer+=((long long)freq[charcter[i]]*(long long)freq[charcter[j]]*(long long)freq[charcter[k]]);
            }
        }
    }
    cout<<answer;


    return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vll vector<ll>

const int N = 100005;

int a[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#endif
    int n,k;
    cin >> n >> k;
    int id;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        if (a[i] == 1) id = i;
    }
    if (k == 2) {
        cout << n-1;
        return 0;
    }
    int r = (n-1)%(k-1);
    if (r == 0) cout << (n-1)/(k-1);
    else cout << (n-1)/(k-1) + 1;
}


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

int main() {
    int n,k,R,S,P;
    cin >> n >> k >> R >> S >> P;
    string t;
    cin >> t;
    int ans=0;
    for(int i=0; i<n; ++i){
        if(t[i]=='r'){
            ans+=P;
        }
        if(t[i]=='s'){
            ans+=R;
        }
        if(t[i]=='p'){
            ans+=S;
        }
    }
    for(int i=0; i<n-k; ++i){
        if(t[i]==t[i+k]){
            if(t[i]=='r'){
                ans-=P;
                t[i+k]='a';
            }
            if(t[i]=='s'){
                ans-=R;
                t[i+k]='b';
            }
            if(t[i]=='p'){
                ans-=S;
                t[i+k]='c';
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int a[100000];
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d",&a[i]);
    sort(a,a+N);

    if ((N % 3) != 0) {
        if (a[N-1] != 0) printf("No\n");
        else printf("Yes\n");
    }
    else {
        for (i = 0; i < N/3; i++) {
            if (a[i] != a[0]) {
                printf("No\n");
                return 0;
            }
        }
        for (i = N/3; i < 2*N/3; i++) {
            if (a[i] != a[N/3]) {
                printf("No\n");
                return 0;
            }
        }
        for (i = 2*N/3; i < N; i++) {
            if (a[i] != a[2*N/3]) {
                printf("No\n");
                return 0;
            }
        }
        if ((a[0]^a[N/3]^a[2*N/3]) != 0) printf("No\n");
        else printf("Yes\n");
    }

    return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    vector <int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    cout << a[0] << ' '<< a[1] <<' '<< a[2]<<endl;
    return 0;
}


Measured memory_bytes: 3092
N,M=map(int,input().split())
a,b,c=0,0,0
E=[]
INF=10**12
D=[[INF]*N for i in range(N)]
for i in range(N):
  D[i][i]=0
for i in range(M):
  a,b,c=map(int,input().split())
  a,b=a-1,b-1
  D[a][b]=c
  D[b][a]=c
  E.append((a,b,c))
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j]=min(D[i][j],D[i][k]+D[k][j])
P=0
for i in range(M):
  if D[E[i][0]][E[i][1]]!=E[i][2]:
    P+=1
print(P)

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

int main(){
	int e,y;
	cin >> e >> y;
	if(!e){
		y -= 1867;
		if(y <= 44) cout << "M" << y << endl;
		else{
			y -= 44;
			if(y <= 14) cout << "T" << y << endl;
			else{
				y -= 14;
				if(y <= 63) cout << "S" << y << endl;
				else cout << "H" << y - 63 << endl;
			}
		}
	}else{
		if(e == 1) y += 1867;
		else if(e == 2) y += 1911;
		else if(e == 3) y += 1925;
		else y += 1988;
		cout << y << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def div(target, n):
    while target % n == 0:
        target = target // n
    return target

n = int(input())


ans = len(make_divisors(n-1)) - 1
for c in make_divisors(n):
    if c == 1:
        continue
    if div(n, c) % c == 1:
        ans += 1

print(ans)

Measured memory_bytes: 3188
def run(n, k):
    a = 0
    b = 0
    for i in range(n):
        if (i+1) % k == 0:
            a += 1
        elif (i+1) % k == k/2:
            b += 1
    if k % 2 == 1:
        # return (n//k)**3
        return a**3
    else:
        # a = (n//k)**3
        # b = (((n - k/2)//k)+1)**3
        # return a + b
        return (a**3) + (b**3)


def read_line():
    n, k = map(int, input().split())
    return (n, k)


def main():
    n, k = read_line()
    print(run(n, k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意
long ctoi(char c) {
  if(c>='0' && c<='9'){
    return c-'0';
  }
  return 0;
}

int main(){
  long sum=0,l;
  string n; cin>>n;
  l=n.length();
  
  rep(i,l)sum+=ctoi(n[i]);
  
  
  cout<<(sum%9==0?"Yes":"No")<<endl;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;



int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    rep(i, N) cin >> W[i];

    int min_v = INF;
    rep(i, N) {
        int T1 = 0; 
        int T2 = 0;
        rep(j, N) {
            if(i<j) T1 += W[j];
            else T2 += W[j];
        }
        min_v = min(min_v, abs(T1-T2));
    }
    print(min_v);
    return 0;
}

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

using namespace std;

#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;

const int mn=25;

int n,k,m;
int v;

struct edge{
    int to,dist;
};

vector<edge> g[mn];

unordered_set<int> h[mn];

bool spj(){
    if (n>20||m>60) {
        puts("OLE");
        return 0;
    }
    h[20].insert(0);
    for(int i=19;i;i--){
        for(auto &j:g[i]){
            for(auto &p:h[j.to]){
                if (h[i].count(p+j.dist)){
                    printf("%d %d\n",i,j.to);
                    puts("WA");
                    return 0;
                }
                h[i].insert(p+j.dist);
            }
        }
    }
    return h[1].size()==v;
}

int main() {
#ifdef LOCAL
    freopen("../1.txt","r",stdin);
#endif
    scanf("%d",&k);
    v=k;
    int tv=k;
    n=20;m=0;
    int d=1;
    for(int i=1;i<=19;i++) g[i].pb(edge{i+1,0}),m++;
    for(int i=19;i;i--){
        if (k>1&&k%2==1) tv-=d,g[1].pb(edge{i+1,tv}),m++;
        k/=2;
        if (k==0) break;
        g[i].pb(edge{i+1,d});m++;
        d<<=1;
    }
    printf("%d %d\n",n,m);
    for(int i=1;i<=n;i++) {
        for(auto &j:g[i]) printf("%d %d %d\n",i,j.to,j.dist);
    }
    //if (!spj()) puts("WA");
    //else puts("AC");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int MAX_N=201000;
long long num[MAX_N];
int a[MAX_N];
int main(void){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		num[a[i]]++;
	}
	long long ans=0;
	for(i=1;i<=n;i++){
		if(num[i]>=2)
		ans+=num[i]*(num[i]-1)/2;
	}
	long long res;
	for(i=1;i<=n;i++){
		res=ans;
		res-=num[a[i]]*(num[a[i]]-1)/2;
		res+=(num[a[i]]-1)*(num[a[i]]-2)/2;
		printf("%lld\n",res);
	}
	return 0;
} 

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
bool DEBUG = false;


int main(){
    int A,B,C;
    cin >> A >> B >> C;

    int ans = C - (A - B);
    if(ans < 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
    int N,M;
    std::cin >> N >> M;
    const Int max_size = (1LL << (N));
    const Int inf = (1LL << 60);
    std::vector<Int>dp(max_size,inf);
    std::vector<Int>d(M);
    std::vector<Int>c(M);
    for(Int i = 0; i < M; ++i){
        int c_num;
        std::cin >> d[i] >> c_num;
        Int val = 0;
        for(int j = 0; j < c_num; ++j){
            Int t; std::cin >> t;
            val += (1LL << (t-1));
        }
        c[i]  = val;
    }
    dp[0] = 0;
    for(Int S = 0; S < dp.size(); ++S){
        if(dp[S] == inf)continue;
        for(int j = 0; j < M; ++j){
            if((S | c[j]) > S){
                Int tS = std::min(max_size - 1, S | c[j]);
                dp[tS] = std::min(dp[tS],dp[S] + d[j]);
            }
        }
    }
    std::cout << (dp.back() == inf ? -1 : dp.back()) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main() {
  int k; cin >> k;
  int r = 0;
  for (int i = 0; i < k; i++) {
    r = (r * 10 + 7) % k;
  	if (r == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}

signed main(){
    int x,y;
    cin>>x>>y;
    cout<<gcd(x,y)<<endl;
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = (n + 1) / 2;
    //cout << ans << " " << k << endl;
    if (ans >= k)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	vs := make([]int, n)
	for i := range vs {
		fmt.Scan(&vs[i])
	}
	cs := make([]int, n)
	for i := range cs {
		fmt.Scan(&cs[i])
	}

	var ans int
	for i := 0; i < n; i++ {
		if tmp := vs[i] - cs[i]; tmp > 0 {
			ans += tmp
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
def findKey(C, x):
    for i, c in enumerate(C):
        if c == x:
            return i

    return None
    

N,K = map(int, input().split())
A = list(map(int, input().split()))

C = [None]*(N)

p = 1
c = 0
C[p-1] = c

while True:
    p = A[p-1]
    c += 1

    if C[p-1] != None:
        break

    C[p-1] = c

start = C[p-1]
cycle = c - start

# print(C,c1, c2)

if K <= start:
    print(findKey(C, K)+1)
else:
    print(findKey(C, (K-start)%cycle+start)+1)









Measured memory_bytes: 32372
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

int main(){
    int n, k;
    std::cin >> n >> k;

    std::vector<int> D(10);
    for(int i = 0; i < k; i++) std::cin >> D[i];

    for(int i = n; i <= 10 * n; i++){
        std::string s = std::to_string(i);
        bool ok = true;

        for(int j = 0; j < k; j++){
            if(std::count(s.begin(),s.end(),D[j] + '0')){
                ok = false;
                break;
            }
        }

        if(ok){
            std::cout << i << std::endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

swap = 0

for i in range(n):
    min_num = p[i]
    min_j = i
    for j in range(i, n):
        if min_num > p[j]:
            min_num = p[j]
            min_j = j
    if min_j != i:
        p[i] ,p[min_j] = p[min_j], p[i] 
        swap += 1
    # print(swap)
    # print(p)
if swap <= 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9104
N = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
val = 0
pre = -1
for i in a:
    if pre == i-1:
        val += c[pre-1]
    val += b[i-1]
    pre = i
print(val)


Measured memory_bytes: 3060
#include <iostream>

int stage[20][20];
int w, h;

bool out( int x, int y ) {
	return (x < 0 || y < 0 || x >= w || y >= h);
}

int search( int x, int y, int n ) 
{
	if ( n == 10 ) return 0xfffff;
	int dx[4] = {1, -1, 0, 0};
	int dy[4] = {0, 0, 1, -1};

	int min = 0xfffff;
	for ( int i = 0; i < 4; ++i ) {
		int px = x, py = y;
		if ( out(px+dx[i], py+dy[i]) || stage[py+dy[i]][px+dx[i]] == 1 ) continue;
		for ( int j = 0; (px >= 0 && py >= 0 && px < w && py < h && stage[py][px] == 0); ++j ) {
			px += dx[i]; py += dy[i];
		}
		if (px < 0 || py < 0 || px >= w || py >= h) {
			continue;
		} else {
			if ( stage[py][px] == 3 ) return n+1;
			else {
				stage[py][px] = 0;
				int a = search( px-dx[i], py-dy[i], n+1 );
				min = (min > a) ? a : min;
				stage[py][px] = 1;
			}
		}
	}
	return min;
}

int main(void)
{
	while ( true ) {
		std::cin >> w >> h;
		if ( w == 0 && h == 0 ) break;
		for ( int i = 0; i < 20; ++i ) {
			for ( int j = 0; j < 20; ++j ) {
				stage[i][j] = 0;
			}
		}

		int x, y;
		for ( int i = 0; i < h; ++i ) {
			for ( int j = 0;j < w; ++j ) {
				std::cin >> stage[i][j];
				if ( stage[i][j] == 2 ) {
					stage[i][j] = 0;
					x = j; y = i;
				}
			}
		}

		int res = search(x, y, 0);
		std::cout << ((res == 0xfffff) ? -1 : res) << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3044
flag = true
while line = gets
  if flag
    flag = false
  else puts
  end
  line.chomp!
  nums = line.rjust(5,"0").split("").map(&:to_i);
  nums.each do |n|
    if n<5
      print "*"
    else print " "
    end
  end
  puts
  nums.each do |n|
    if n>=5
      print "*"
    else print " "
    end
  end
  puts
  puts "====="
  a = nums.map{|n| n%5}
  1.upto(5) do |i|
    a.each_with_index do |x,j|
      if i<=x
        print "*"
      else
        print " "
        a[j]=5
      end
    end
    puts
  end
end

Measured memory_bytes: 2468
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N;
char str[10];
double ans;

int main()
{
  scanf( "%d", &N );
  
  rep( i, N )
  {
    double x;

    scanf( "%lf %s", &x, str );

    if( str[0] == 'B' )
      ans += x*380000.0;
    else
      ans += x;
  }

  printf( "%.8f\n", ans );

  return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/////////////////////////
	long long x,y,s,m,d;
	cin >> x >> y;
	s = x+y;
	d = x-y;
	m = x*y;
	cout << max(s,max(d,m));
}

Measured memory_bytes: 256
H,W = map(int, input().split())
N = int(input())
A = [int(x) for x in input().split()]

L = []
for i,a in enumerate(A):
	for j in range(a):
		L.append(i+1)

T = [[0]*W for i in range(H)]

idx = 0
for i in range(H):
	k = 1
	if i%2:
		k = -1
	for j in range(W)[::k]:
		T[i][j] = L[idx]
		idx += 1
for t in T:
	print(*t)

Measured memory_bytes: 3956
from collections import Counter
from math import factorial
n = int(input())
a = list(map(int,input().split()))
t = Counter(a)
ans = 0
for v in t.values():
    ans += v*(v-1)//2
for i in range(n):
    tmp = ans
    tmp = tmp - ((t[a[i]]*(t[a[i]]-1))//2) + (((t[a[i]]-1)*(t[a[i]]-2))//2)
    print(tmp)

Measured memory_bytes: 26780
import math

def main():
    N = int(input())
    x = [0] * N
    y = [0] * N
    for i in range(N):
        x[i], y[i] = map(int, input().split())
    t = 0
    for i in range(N):
        for j in range(N):
            t += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
    print(t / N)

main()


Measured memory_bytes: 38384
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    X = LIST()

    a = N
    b = (-2) * sum(X)
    c = 0
    for x in X:
        c += x**2

    l = int((-1)*b / (2*a))
    r = ceil((-1)*b / (2*a))
    print(min(a * l**2 + b * l + c, a * r**2 + b * r + c))


if __name__ == '__main__':
    main()


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

int main()
{
  int year = 0;
  long X, c;
  cin >> X;

  for(c = 100; c < X; c = long(c * 1.01), year++);
  
  cout << year << endl;
  return 0;
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

cnt = defaultdict(int)
for a in A:
    cnt[a] += 1

sum_cnt = 0
for a in cnt.values():
    sum_cnt += a * (a - 1) // 2

for a in A:
    cnta = cnt[a]
    print(sum_cnt - cnta * (cnta - 1) // 2 + (cnta - 1) * (cnta - 2) // 2)

Measured memory_bytes: 71024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    for (int i = 1; i <= 5; i++) {
        int x; cin >> x;
        if (x == 0) {
            cout << i;
            break;
        }
    }
}

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

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

	int count = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0)
			count++;
	}

	cout << count << endl;
	return 0;
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N[10];

ll i, j, k;

int main(){
    rep(i,0,4){
        scanf("%lld", &N[i]);
    }
    j = 0;
    rep(i,1,3){
        while(N[i-1]>=N[i]){
            ++j;
            N[i] *= 2;
        }
    }
    if(j<=N[i]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int a;
    cin >> a;
    
    cout << a*a << endl;


    return 0;
}

Measured memory_bytes: 256
import bisect

N, K = map(int, input().split())
V = [int(i) for i in input().split()]

ans = 0
for a in range(min(N, K)+1):
    for b in range(min(N, K)-a+1):
        score = 0
        D = sorted(V[:a]+V[N-b:])
        score = sum(D[min(K-(a+b), bisect.bisect_left(D, 0)):])
        # print(score)
        ans = max(ans, score)

print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 100010;
int N, a[MAXN];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    bool win = true, f = true;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i], a[i]--;
    sort(a, a + N);
    if (N - 1 <= a[0] && (N - 1) % 2 == a[0] % 2) {
        win = false;
    }
    for (int i = 1; i < N; i++) {
        if (a[i] == a[i - 1]) {
            f = !f;
            if (f && N - 1 - i == a[i]) win = false;
        } else {
            if (a[i - 1] < N - 1 - i && N - 1 - i <= a[i] && (N - 1 - i) % 2 == a[i] % 2) win = false;
            if (a[i - 1] == N - 1 - i && !f && (N - 1 - i) % 2 == a[i] % 2) win = false;
            f = true;
        }
    }
    cout << (win ? "First\n" : "Second\n");
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  
  std:string r = "";
  if (a > b) {
    for (int i = 0; i < a; i++) {
      r += std::to_string(b);
    }
  } else {
    for (int i = 0; i < b; i++) {
      r += std::to_string(a);
    }
  }
  cout << r << endl;
  return 0;
}

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e3) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)


int main() {
    int N;
    vector<int> D;
    cin >> N;
    REP(i,N){
        int d;
        cin >> d;
        D.push_back(d);
    }
    D.push_back(0);
    D.push_back(24);
    SORT(D);
    REP(s,24){
        vector<int> t = D;
        int i=1;
        while(i<t.size()){
            int dif = abs(t[i]-t[i-1]);
            if(min(dif,24-dif)>=s){
                i++;
            }
            else{
                if(t[i]<12){
                    t.push_back(24-t[i]);
                    t.erase(t.begin()+i);
                    SORT(t);
                }
                else{
                    cout << s-1 << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
N, M = map(int, input().split())
G = [[] for i in range(N + 5)]
for i in range(M):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
ans = []
used = [False] * (N + 5)


def dfs(u):
    global ans
    used[u] = True
    ans.append(u)
    for w in G[u]:
        if not used[w]:
            dfs(w)
            return
    return


dfs(1)
ans = ans[::-1]
ans = ans[:-1]
dfs(1)
print(len(ans))
print(*ans)

Measured memory_bytes: 128928
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
int main()
{
    int n;string s;
    cin>>n>>s;
    ll c[26];
    for(int i = 0; i < 26; i++) c[i] = 1;
    for(int i = 0; i < n; i++) c[s[i] - 'a']++;
    ll sum = 1;
    for(int i = 0; i < 26; i++) {sum *= c[i]; sum %= ll(1e9+7);}
    cout << sum - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	r := readInt()
	if r < 1200 {
		println("ABC")
	} else if r < 2800 {
		println("ARC")
	} else {
		println("AGC")
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[333333],n,l,r;
bool b[333333];
bool check(int l,int r)
{
	int ls=0,rs=0;
	for (int i=l;i<=r;i++)
	{
		if (a[i]<l || a[i]>r) return 0; 
		if (a[i]<i)
		{
			if (a[i]<ls) return 0;
			ls=a[i];
		}
		else if (a[i]>i)
		{
			if (a[i]<rs) return 0;
			rs=a[i];
		}
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) b[i]=(a[i]==i);
	for (int i=1;i<=n;i++)
	{
		if (b[i]) continue;
		l=i;r=i+1;
		while(r<=n && b[r]!=b[r-1]) r++;
		r--;
		if (!check(l,r)) 
		{
			printf("No\n");
			return 0;
		}
		i=r;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1664
# AOJ 0155 Spider Jin
# Python3 2018.6.23 bal4u
# 最短経路問題

MAXLEN = 50
MAX = 100
INF = 0x7ffffffffffffff
x = [0]*(MAX+2)
y = [0]*(MAX+2)
dist = [INF]*(MAX+2)
pre = [0]*(MAX+2)
	
import heapq
def dijkstra(V, to, start, goal):
	global dist
	dist = [INF]*V
	Q = []
	dist[start] = 0
	heapq.heappush(Q, (0, start))
	while len(Q):
		t, s = heapq.heappop(Q)
		if s == goal: break
		if dist[s] < t: continue
		for i in to[s]:
			e, cost = i
			nt = t + cost
			if dist[e] > nt:
				dist[e] = nt
				heapq.heappush(Q, (nt, e))
				pre[e] = s
while 1:
	n = int(input())
	if n == 0: break
	for i in range(n):
		j, x_, y_ = map(int, input().split())
		x[j], y[j] = x_, y_
	n += 1
	to = [[] for i in range(n)]
	for i in range(1, n):
		for j in range(1, n):
			dx, dy = x[i]-x[j], y[i]-y[j]
			dd = (dx**2 + dy**2)**0.5
			if dd <= MAXLEN:
				to[i].append((j, dd))
				to[j].append((i, dd))
	m = int(input())
	for i in range(m):
		s, g = map(int, input().split())
		if s == g: print(s)
		else:
			dijkstra(n, to, s, g)
			if dist[g] == INF: print("NA")
			else:
				ans = []
				ans.append(g)
				while g != s:
					g = pre[g]
					ans.append(g)
				print(*ans[::-1])
	


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

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	string st;
	map<char, int>mp;
	mp['I'] = 0;
	mp['V'] = 1;
	mp['X'] = 2;
	mp['L'] = 3;
	mp['C'] = 4;
	mp['D'] = 5;
	mp['M'] = 6;
	
	vector<int>values{ 1,5,10,50,100,500,1000 };
	while (cin >> st) {
		vector<int>nums;
		for (auto c : st) {
			nums.push_back(mp[c]);
		}
		int sum = 0;
		for (int i = 0; i < nums.size(); ++i) {
			if (i == nums.size() - 1 || nums[i] >= nums[i + 1])sum += values[nums[i]];
			else sum -= values[nums[i]];
		}
		cout << sum << endl;

	}
	return 0;
}

Measured memory_bytes: 3028
#include<stdio.h>
#include<stdlib.h>
int main()
{
	char a, b,c;
	a=getchar();
	b=getchar();
	c = getchar();
	if (a == c)
	{
		printf("H\n");
	}
	else
	{
		printf("D\n");
	}
	system("pause");
}

Measured memory_bytes: 1008
import sys
readline = sys.stdin.readline

A = readline().rstrip()

def nC2(x):
  return (x * (x - 1)) // 2

from collections import defaultdict
dic = defaultdict(int)

for a in A:
  dic[a] += 1
  
ans = nC2(len(A))
for v in dic.values():
  ans -= nC2(v)

print(ans + 1)

Measured memory_bytes: 9376
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> v(m);
  if(n>=m){cout<<0; return 0;}
  else{
    for(int i=0;i<m;i++){
      cin>>v[i];
    }
    sort(v.begin(),v.end());
    vector<int> dist(m-1);
    for(int i=0;i<m-1;i++){
      dist[i]=v[i+1]-v[i];
    }
    sort(dist.begin(),dist.end());
    int sum=0;
    for(int i=0;i<n-1;i++){
      sum+=dist[m-2-i];
    }
    cout<<v[m-1]-v[0]-sum;
  }
}

Measured memory_bytes: 1024
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val n = sc.nextInt()
    abc161b(n)
}

fun abc161b(n:Int) {
   var summ = 0L
    for (i in 0..n){
        if(i%3 != 0 && i%5 != 0) summ += i
    }
    println(summ)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }



Measured memory_bytes: 36600