akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;
const int INF = 1000100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int toy[4] = {-1, 0, 1, 0};
const int tox[4] = {0, 1, 0, -1};

int main()
{
    int h, w; cin >> h >> w;

    int Bnum = 0;
    int mass[h][w];

    rep(i,h){
        rep(j,w){
            char moji; cin >> moji;
            if(moji == '.'){
                mass[i][j] = 1;
            }else{
                mass[i][j] = 0;
                Bnum++;
            }
        }
    }

    int d[h][w];
    rep(i,h) rep(j,w) d[i][j] = INF;

    d[0][0] = 0;
    queue<P> q;
    q.push(make_pair(0,0));

    while(!q.empty()){
        int uy = q.front().first, ux = q.front().second;
        q.pop();
        rep(i,4){
            int vy = uy + toy[i], vx = ux + tox[i];
            if(vy<0 || vx<0 || vy>=h || vx>=w) continue;
            if(d[vy][vx] == INF && mass[vy][vx] == 1){
                d[vy][vx] = d[uy][ux]+1;
                q.push(make_pair(vy,vx));
            }
        }
    }

    if(d[h-1][w-1] == INF) cout << -1 << endl;
    else cout << h*w-Bnum-d[h-1][w-1]-1 << endl;
}

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

int main(){
  uint64_t A,B,C,tem,ans=0;
  cin >> A >> B >> C;
  if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
    cout << 0 << endl;
    return 0;
  }
  if(A<B){
    tem = A;
    A = B;
    B = tem;}
  if(B<C){
    tem = B;
    B = C;
    C = tem;}
  if(A<B){
    tem = A;
    A = B;
    B = tem;}
  cout << B*C << endl;
}


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

int main(){
  int n;
  cin >> n;
  long long a[n], b[n], ans=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(i!=0){
      b[i] = b[i-1] + a[i];
    } else {
      b[i] = a[i];
    }
    b[i] %= 1000000007;
  }
  for(int i = n-1;i>0;i--){
    ans += a[i] * b[i-1] % 1000000007;
  }
  ans %= 1000000007;
  cout << ans << endl;
}


Measured memory_bytes: 6736
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] a = new int[n];

        for(int i=0;i<n; i++){
            a[i] = sc.nextInt();
        }
        System.out.print(a[n-1]);
        for(int i=n-2; i>=0; i--){
            System.out.print(" " + a[i]);
        }
        System.out.println();    
    }
}


Measured memory_bytes: 26176
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int dir[2][4] = { {1,0,-1,0},{0,1,0,-1} }; //x,y
int cnt;
int h,w;
char s[400][400];
vector< vector<int> > c(400,vector<int>(400,-1));

int search(int i,int j){
  if(c[i][j] != -1) return 0;
  int suc=0;
  for(int k=0;k<4;k++){
    if(j + dir[0][k] >=0 && j + dir[0][k] <w){
      if(i + dir[1][k] >=0 && i + dir[1][k] <h){
        if( s[i][j] != s[ i + dir[1][k] ][ j + dir[0][k] ] ){
          c[i][j]=cnt;
          suc=1;
          search(i + dir[1][k],j + dir[0][k]);
        }
      }
    }
  }

  if(suc == 0){
    return 0;
  }
  else{
    return 1;
  }

}

int main(void){

  cin>>h;
  cin>>w;

  //vector<string> s(0);

  //cout << h << "," << w << endl;
  for(int i=0;i<h;i++){
    string str;
    cin>>str;

    for(int j=0;j<w;j++){
      s[i][j]=str[j];
      //cout << s[i][j] ;
    }
    //cout << endl;
  }

  //vector< vector<int> > c(h,vector<int>(w,-1));

  cnt=0;

  //c[0][0]=0;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(search(i,j) != 0){
        cnt++;
      }
    }
    //cout << endl;
  }
  ///*
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      //cout << c[i][j] ;
    }
    //cout << endl;
  }
  //cout << cnt << endl;
  //*/
  vector< vector<long long int> > aa(cnt+1,vector<long long int>(2,0));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(c[i][j]==-1) continue;
      if(s[i][j]=='#'){
        aa[c[i][j]][0]++;
      }
      else{
        aa[c[i][j]][1]++;
      }
    }
  }
  long long int ans=0;
  for(int i=0;i<cnt;i++){
    //cout << aa[i][0] << "," << aa[i][1] << endl;
    ans+=aa[i][0]*aa[i][1];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

bool solve(){
	int N; cin >> N;
	V<int> A(N),B(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];

	V<int> AA = A, BB = B;
	sort(all(AA));sort(all(BB));
	rep(i,N) if(AA[i] > BB[i]){
		return false;
	}
	V<int> p(N,-1);
	rep(i,N-1) if(AA[i+1] <= BB[i]) return true;

	using P = pair<int,int>;
	V<P> a(N),b(N);
	rep(i,N) a[i] = P(A[i],i);
	rep(i,N) b[i] = P(B[i],i);
	sort(all(a));sort(all(b));
	rep(i,N) p[a[i].sc] = b[i].sc;
	int x = 0;
	rep(t,N-1){
		x = p[x];
		if(x == 0) return true;
	}
	return false;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	if(solve()) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3840
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, a[N], l[N], r[N];

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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    for (int i = 1; i <= n; i++)cin>>a[i];
    
    for (int i = 1; i <= n; i++){
        l[i] = gcd(l[i-1], a[i]);
        r[n+1-i] = gcd(r[n+2-i], a[n+1-i]);
    }
    
    int mx = 0;
    for (int i = 1; i <= n; i++){
        mx = max((long long)mx, gcd(l[i-1], r[i+1]));
    }
    cout<<mx<<endl;
    
    
    
    return 0;
}



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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long n, a, b;
	cin >> n >> a >> b;
	if(a > b) return cout << 0 << endl, 0;
	if(n == 1 and a == b) return cout << 1 << endl, 0;
	if(n == 1 and a != b) return cout << 0 << endl, 0;
	cout << (a + (n-1)*b) - (b + (n-1)*a) + 1 << endl;

}


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

int main(){
  ll n,m,ans;
  cin >> n >> m;
  ans=0;
  if(n>=1){
    ans+=n*(n-1)/2;
  }
  if(m>=1){
    ans+=m*(m-1)/2;
  }
  cout << ans;
}

Measured memory_bytes: 256
n = gets.to_i
p=gets.chomp
q=gets.chomp

l = p.split(" ").permutation
p = p.delete(" ")
q = q.delete(" ")
count_p = 0
count_q = 0
l.each{|x|
  str = ""
  x.each{|s|
    str += s
  }
  if str < p
    count_p += 1
  end
  if str < q
    count_q += 1
  end
}

if count_p > count_q
  p count_p - count_q
else
  p count_q - count_p
end

Measured memory_bytes: 1916
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean elapsed = false;
 
    private int minCount = Integer.MAX_VALUE;
 
    private void solve(Scanner sc, PrintWriter out) {
        String s = sc.next();
 
        search(new StringBuilder(s));
 
        out.println(minCount);
    }
    private void search(StringBuilder sb) {
        if (check(sb)) {
            minCount = 0;
            return;
        }
 
        int leftCount = 0;
        boolean bFlg = (sb.charAt(0) == 'B');
        for (int i = 1; i < sb.length(); ++i) {
            if (sb.charAt(i) == 'B') {
                if (!bFlg) {
                    ++leftCount;
                }
                bFlg = true;
            } else if (sb.charAt(i) == 'W') {
                if (bFlg) {
                    ++leftCount;
                }
                bFlg = false;
            }
        }
 
        int rightCount = 0;
        bFlg = (sb.charAt(0) == 'B');
        for (int i = sb.length() - 1; i >= 0; --i) {
            if (sb.charAt(i) == 'B') {
                if (!bFlg) {
                    ++rightCount;
                }
                bFlg = true;
            } else if (sb.charAt(i) == 'W') {
                if (bFlg) {
                    ++rightCount;
                }
                bFlg = false;
            }
        }
 
        minCount = Math.min(leftCount, rightCount);
    }
    private boolean check(StringBuilder sb) {
        boolean bFlg = false;
        boolean wFlg = false;
        for (int i = 0; i < sb.length(); ++i) {
            if (sb.charAt(i) == 'B') {
                bFlg = true;
            } else if (sb.charAt(i) == 'W') {
                wFlg = true;
            }
            if (bFlg && wFlg) {
                return false;
            }
        }
        return true;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

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

typedef long long ll;

int main() {
	ll n, k;
	scanf("%lld %lld", &n, &k);
	long long ans = (long long)((n/k) * (n/k)) * (n/k);
	if(~k&1) {
		ll cnt = 0;
		for(int i = 1; i <= n; i++) {
			if(i % k == k/2) cnt++;
		}
		ans += cnt * cnt * cnt;
	} printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
	int datanum,datamax;
	int maxnumber;
	double maxbmi;
	double maxdiff;
	int number,height,weight;
	double heightm;
	double bmi;
	double diff;
	while(1) {
		scanf("%d",&datamax);
		if(datamax==0)break;
		maxnumber=0;
		maxbmi=0x7fffffff;
		maxdiff=0x7fffffff;
		for(datanum=0;datanum<datamax;datanum++) {
			scanf("%d %d %d",&number,&height,&weight);
			heightm=(double)height/100;
			bmi=(double)weight/heightm/heightm;
			diff=fabs(bmi-22);
			if(diff<maxdiff || (diff==maxdiff && number<maxnumber)) {
				maxdiff=diff;
				maxbmi=bmi;
				maxnumber=number;
			}
		}
		printf("%d\n",maxnumber);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;

    vector<ll> P(m), Y(m);
    rep(i, m) cin >> P[i] >> Y[i];
    
    typedef std::pair<int, int> pair;
    vector<pair> p;
    rep(i, m) p.push_back(pair(i, Y[i]));
    sort(all(p), [](const pair& lhs, const pair& rhs) {
        return lhs.second < rhs.second;
    });

    vector<int> cnt(n);
    vector<int> x(m);
    rep (idx, m) {
        int i = p[idx].first;
        cnt[P[i] - 1]++;
        x[i] = cnt[P[i] - 1];
    }

    rep (i, m) {
        printf("%06Ld%06d\n", P[i], x[i]);
    }

    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)
#define ll long long
#define pr_qu priority_queue
#define vec(name,size,common) vector<ll> (name)((size),(common))
 
 
 
 
 
int main(){

  int a,b;
  cin>>a>>b;
  if(a==1){
    a=100;
  }
  if(b==1){
    b=100;
  }

if(a>b){
  cout<<"Alice";
}else if(a==b){
  cout<<"Draw";
}else{
  cout<<"Bob";
}
}

Measured memory_bytes: 256
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

dp = [float('inf')] * (h+1)
dp[0] = 0

for i in range(h + 1):
    for a, b in ab:
        dp[i] = min(dp[i], dp[max(i - a, 0)] + b)
print(dp[h])


Measured memory_bytes: 74464
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class B {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N;
        int[] A;
        Input(out N);
        InputArray(out A);
        for(int i = 0; i < N; i++) {
            if(A[i] % 2 == 0) {
                if(A[i] % 3 != 0 && A[i] % 5 != 0) {
                    Console.WriteLine("DENIED");
                    return;
                }
            }
        }
        Console.WriteLine("APPROVED");
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 13396
#include <stdio.h>
#include <string.h>
 
void under_s(char a[], int b)
{
int len, i;
len = strlen(a);
for(i = 0; i < b; i++){
a[len + i] = a[i];
}
 
for(i = 0; i < len; i++){
a[i] = a[i + b];
}
a[len] = '\0';
}
 
 
int main(void)
{
char card[500];
int n, i;
int h[128];
 
while(1){
 
scanf("%s",&card);
if( strcmp(card, "-") == 0)
break;
 
scanf("%d",&n);
 
for(i = 0; i < n; i++)
{
scanf("%d", &h[i]);
}
 
for(i = 0; i < n; i++){
under_s(card, h[i]);
}
printf("%s\n", card);
}
return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll MAX = 1e15;

bool solve(ll n, ll b, ll s){
  ll sum = 0;
  while(n > 0){
    sum += (n % b);
    n /= b;
  }
  if(sum == s) return true;
  return false;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n, s; cin >> n >> s;
  if(s == n){
    cout << n + 1 << endl;
    return 0;
  }
  ll ans = MAX;
  // b > sqrt(n), n = pb + q
  // p = (n - s)/b + 1
  for(ll p=(ll)(sqrt(n));p>=1;p--){
    if((n - s) %p != 0) continue;
    ll b = (n - s)/p + 1;
    if(b <= (ll)(sqrt(n))) continue;
    if(solve(n, b, s)){
      ans = min(b, ans);
    }
  }
  // b <= sqrt(n)
  for(ll b=2;b<=(ll)(sqrt(n));b++){
    if(solve(n, b, s)){
      ans = min(b, ans);
    }
  }
  if(ans == MAX){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 384
a, b = [int(i) for i in input().split()]

def gcd(a, b):
    if b==0:
        return a
    return gcd(b, a%b)



g = gcd(a, b)

nof = 1
up = g

for i in range(2, up):
    if i*i > up:
        break
    if g%i == 0:
        nof += 1
        #print(i, nof)
        while g%i == 0:
            g = g//i
if g > 1:
    nof += 1
print(nof)
            


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int h,w,m,hmax = 0,wmax = 0;
    cin >> h >> w >> m;
    int hcnt[h] = {},wcnt[w] = {};
    //hcnt.resize(h),wcnt.resize(w);
    set<pair<int,int>> se;
    for (int i = 0; i < m; ++i) {
        int tmp,tmp2;
        cin >> tmp >> tmp2;
        tmp--,tmp2--;
        hcnt[tmp]++;
        wcnt[tmp2]++;
        se.insert({tmp,tmp2});
    }

    // maxを調べる
    for (int i = 0; i < h; ++i) hmax = max(hmax,hcnt[i]);
    for (int i = 0; i < w; ++i) wmax = max(wmax,wcnt[i]);

    queue<int> qh;
    set<int> sew;
    // maxのやつを全列挙
    for (int i = 0; i < h; ++i) {
        if(hcnt[i] == hmax) qh.push(i);
    }
    for (int i = 0; i < w; ++i) {
        if(wcnt[i] == wmax) sew.insert(i);
    }

    int ans = hmax+wmax;
    // 組み合わせ全部試す
    while(!qh.empty()){
        int htmp = qh.front();
        qh.pop();
        for (auto i:sew) {
            if(!se.count({htmp,i})){
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 35244
#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() {
//   普通に文字列を入力
  string s, t;
  cin >> s >> t;
//   tのbackをpopする＝末尾を削除
  t.pop_back();
  if (s == t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;
#define ll long long
const int N=1e6+5;
int F[N];
bool vis[N];
vector< pair<int,int> >adj[N];
int cnt=0;
vector<int>ans;
int n;
int dfs(int u)
{
    int ret=F[u];
    vis[u]=1;
    for(auto P:adj[u])
    {
        int v=P.first,idx=P.second;
        if(!vis[v])
        {
            int t=dfs(v);
            if(t%2) ans.push_back(idx);
            ret+=t;
        }
    }
    return ret;
}
bool solve(bool f)
{
    F[n+1]=f;
    ans.clear();
    memset(vis,0,sizeof vis);
    bool valid=1;
    for(int i=1;i<=n;i++)
        if(!vis[i]&&dfs(i)%2)
            valid=0;
    return valid;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int m;cin>>n>>m;
    vector< int >val;
    map<int,bool>f;
    val.push_back(0);
    for(int i=0;i<n;i++)
    {
        int x;cin>>x;
        cin>>f[x];
        val.push_back(x);
    }
    sort(val.begin(),val.end());
    for(int i=1;i<=n;i++)
        F[i]=f[val[i-1]]^f[val[i]];
    for(int i=0;i<m;i++)
    {
        int l,r;cin>>l>>r;
        int u=lower_bound(val.begin(),val.end(),l)-val.begin();
        int v=upper_bound(val.begin(),val.end(),r)-val.begin();
        if(u==v) continue;
        adj[u].push_back({v,i});
        adj[v].push_back({u,i});

    }
    if(solve(0)||solve(1))
    {
        sort(ans.begin(),ans.end());
        cout<<(int)ans.size()<<endl;
        for(int i=0;i<(int)ans.size();i++)
        {
            if(i) cout<<" ";
            cout<<ans[i]+1;
        }
        cout<<endl;
        return 0;
    }
    puts("-1");
    return 0;
}


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

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

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
template <class Z> Z rng(Z l, Z r) {
  return uniform_int_distribution<Z>(l, r - 1)(mt);
}

struct chash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ x >> 30) * 0xbf58476d1ce4e5b9;
    x = (x ^ x >> 27) * 0x94d049bb133111eb;
    return x ^ x >> 31;
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t r = rng<uint64_t>(0, 0);
    return splitmix64(x + r);
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  auto $ = [](long long i, long long ci, long long j, long long cj) {
    return i << 29 | ci << 17 | j << 12 | cj;
  };
  gp_hash_table<long long, long long, chash> h;
  auto dfs = [&](auto&& self, int i, int ci, int j, int cj) -> long long {
    if (j - i == 1) {
      return ci * a[i] + cj * a[j];
    }
    auto key = $(i, ci, j, cj);
    if (h.find(key) != end(h)) {
      return h[key];
    }
    long long res = 1e18;
    for (int k = i + 1; k < j; ++k) {
      auto cur = self(self, i, ci, k, ci + cj);
      cur -= (ci + cj) * a[k];
      cur += self(self, k, ci + cj, j, cj);
      res = min(res, cur);
    }
    return h[key] = res;
  };
  cout << dfs(dfs, 0, 1, n - 1, 1) << '\n';
}


Measured memory_bytes: 18924
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  scanf("%d", &n);

  int a[100][2];
  REP(i,n){
    scanf("%d", &a[i][0]);
  }
  REP(i,n){
    scanf("%d", &a[i][1]);
  }

  if(n==1){
    printf("%d\n", a[0][0] + a[0][1]);
    return 0;
  }

  int dp[100][2] = {};
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][0] + a[0][1];
  for(int i = 0; i < n-1; ++i){
    for(int j = 0; j < 2; ++j){
      if(j == 0){
        if(i+1<n)
          dp[i+1][j] = dp[i][j] + a[i+1][j];
      }else{
        dp[i+1][1] = max(dp[i][1], dp[i+1][0]) + a[i+1][j];
      }
    }
  }

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



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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int m; scanf("%d", &m);
	ll cnt = 0;
	for (int i = 0; i < m; i++) {
		ll d, c; scanf("%lld%lld", &d, &c);
		cnt += c * (9 + d);
	}

	ll answer;
	if (cnt <= 18)
		answer = 0;
	else
		answer = (cnt - 10) / 9;
	printf("%lld\n", answer);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int jank(int a){
  char s[4]="spr";
  FOR(3)if(a==s[i])return i;
}
ll x[100000];
int main(void){
  char s[111];
  scanf("%s",s);
  FOR(strlen(s))printf("x");
  PRS("");
}


Measured memory_bytes: 128
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2502
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#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++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int N;
    cin >> N;
    vector<int> s(N+1), l(N+1), p(N+1);
    rep(i, N) cin >> s.at(i+1) >> l.at(i+1) >> p.at(i+1);
    vector<vector<int> > dp(N+1, vector<int>(395, 0));
    rep(i, N){
        rep(j, 394){
            chmax(dp[i+1][j], dp[i][j]);
            rep2(k, s.at(i+1), l.at(i+1)+1){
                if(j-k>=0){
                    chmax(dp[i+1][j], dp[i+1][j-k]+p.at(i+1));
                }
            }
        }
    }
    int M;
    cin >> M;
    vector<int> answer(M);
    rep(i, M){
        int w;
        cin >> w;
        answer.at(i) = dp[N][w];
        if(dp[N][w] == 0){
            cout << -1 <<endl;
            return 0;
        }
    }
    rep(i, M){
        cout << answer.at(i) << endl;
    }

    
}


Measured memory_bytes: 3344
fun main(){
    val n = readLine()!!.split(" ")[0].toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    var total = 0L
    for (i in 1 until n){
        if (a[i] < a[i - 1]){
            val x = a[i - 1] - a[i]
            total += x
            a[i] += x
        }
    }
    println(total)

}

Measured memory_bytes: 65264
import java.util.Scanner;

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

		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double x = sc.nextDouble();

		double angle = 0.0;
		if (a * a * b >= 2 * x) {
			angle = Math.toDegrees(Math.atan((a * b * b) / (2 * x)));
		} else {
			angle = Math.toDegrees(Math.atan((2 * b / a) - (2 * x / (a * a * a))));
		}
		System.out.println(angle);
		sc.close();
	}
}


Measured memory_bytes: 23252
import java.io.*;
 
class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    String[] strAry = str.split(" ");
     
    int x = Integer.parseInt(strAry[0]);
    int y = Integer.parseInt(strAry[1]);

    int d = x/y;
    int r = x % y;
    String f = String.format("%.5f", ((double)x/(double)y));
    System.out.println(d +" "+ r +" "+ f);
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s;cin >>s;
    char key='<';
    vector<ll>cnt;
    ll now=0;
    for (int i = 0; i < s.size(); ++i) {
        if(key==s[i]){
            now++;
        }
        else {
            if(key=='<')key='>';
            else key='<';
            cnt.push_back(now);
            now=1;
        }
    }
    if(now!=0)cnt.push_back(now);
    if(cnt.size()%2==1)cnt.push_back(0);
    vector<ll>sum;
    ll pl=0;
    for (int i = 0; i <=s.size(); ++i) {
        pl+=i;
        sum.push_back(pl);
    }
    ll ans=0;
    for (int i = 0; i < cnt.size(); i+=2) {
        ll mx=max(cnt[i],cnt[i+1]);
        ll mint=min(cnt[i],cnt[i+1]);
        ll tmp=max(0LL,mint-1);
        ans+=sum[mx]+sum[tmp];
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 8696
N,M,Q = list(map(int,input().split()))
A = [i for i in range(1,M+1)]
import itertools
B = list(itertools.combinations_with_replacement(A,N))
Ans = []
C = []
for i in range(Q):
    C.append(list(map(int,input().split())))
for b in B:
    ans = 0
    for c in C:
        if b[c[1]-1] - b[c[0]-1] == c[2]:
            ans+=c[3]
    Ans.append(ans)
print(max(Ans))

Measured memory_bytes: 86224
x=int(input())
# while x>0:
#     if count%2==0:
#         x-=6
#     else:
#         x-=5
#     count+=1
ans=x//11*2
amari=x%11
if amari>6:
    ans+=2
elif amari>0:
    ans+=1
print(ans)

Measured memory_bytes: 38384
n = gets.to_i
t,a = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

ans = -1
dif = 10**9
n.times{|i|
  tmp = t-h[i]*0.006
  if (tmp-a).abs < dif
    ans = i+1
    dif = (tmp-a).abs
  end
}

p ans

Measured memory_bytes: 1788
<?php
/*
    Problem URL : http://abc054.contest.atcoder.jp/tasks/abc054_c

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('error_reporting', E_ALL & ~E_NOTICE);
ini_set('memory_limit', '-1');

$v = array();
$ans = 0;

fscanf(STDIN, "%d %d", $N, $M);

for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $a, $b);
    $v[$a][$b] = 1;
    $v[$b][$a] = 1;
}

// var_dump($v);
// exit;

$arr = array("1");
$base = "1";

for ($i = 0; $i < $N-1; $i++) {
    $newArr = array();
    foreach ($arr as $tmp) {
        $last = substr($tmp, strlen($tmp) - 1);
        // echo "last:{$last}\n";
        // var_dump($v[$last]);
        foreach ($v[$last] as $nex => $dummy) {
            if (!in_array($nex, str_split($tmp))) {
                $newArr[] = $tmp . $nex;
            }
        }
    }
    $arr = $newArr;
}
// var_dump($arr);

foreach ($arr as $x) {
    $arrx = str_split($x);
    $sum = array();
    for ($i = 0; $i < $N; $i++) {
        $sum[$arrx[$i]]++;
    }
    // echo max($sum) . PHP_EOL;
    if (max($sum) == 1) {
        $ans++;
    }
}
echo $ans . PHP_EOL;


Measured memory_bytes: 3704
import itertools
n,m,x=list(map(int,input().split()))
ans=10**18
A=[list(map(int,input().split())) for i in range(n)]
for i, _ in enumerate(A,1):
  for j in itertools.combinations(A,r=i):
    B=list(zip(*j))    
    C=[sum(B[m]) for m in range(m+1)]
    if len([i for i in C[1:] if i>=x ])==m:
      ans=min(ans,C[0])
print(ans) if ans!=10**18 else print(-1)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    string S;
    cin >> S;
    REP(i,S.size()) cout << "x";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	
	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0) break;
			else calc(n,a,b,c,x);
		}
	}
	public void calc(int n, int a, int b, int c, int x){
		int count = 0;
		int y[] = new int[n];
		for(int i = 0; i < n; i++) y[i] = sc.nextInt();
		int i = 0;
		while(i < n){
			if(i == 0 && y[i] == x) i++;
			else{
				count++;
				int t = a * x + b;
				x = t % c;
				if(x == y[i]) i++; 
				if(count > 10000)	{
					count = -1;
					break;
				}
			}
		}
		System.out.println(count);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 31716
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007
const int N = 1000005;

ll lpf[N], mobius[N]; 

void least_prime_factor() {
    for (ll i = 2; i < N; i++) 
        if (!lpf[i]) 
            for (ll j = i; j < N; j += i) 
                if (!lpf[j]) 
                    lpf[j] = i; 
}

void Mobius() {
    for (ll i = 1; i < N; i++) { 
        if (i == 1) 
            mobius[i] = 1; 
        else { 
            if (lpf[i/lpf[i]]==lpf[i]) 
                mobius[i] = 0; 
            else
                mobius[i] = -1*mobius[i/lpf[i]]; 
        } 
    } 
} 
ll gcd_pairs(vector<ll> &a, int n) {
    ll maxi = 0; 
    ll fre[N] = {0}; 
    for (ll i = 0; i < n; i++) { 
        fre[a[i]]++; 
        maxi = max(a[i], maxi); 
    } 
    least_prime_factor(); 
    Mobius(); 
    ll ans = 0; 
    for (ll i = 1; i <= maxi; i++) { 
        if (!mobius[i]) 
            continue; 
        ll temp = 0; 
        for (ll j = i; j <= maxi; j += i) 
            temp += fre[j]; 
        ans += temp*(temp-1)/2*mobius[i]; 
    } 
    return ans; 
} 

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin>>n;
  vector<ll> a(n);
  ll gcd = 0;
  for(ll i=0; i<n; i++){
    cin>>a[i];
    gcd = __gcd(gcd, a[i]);
  }
  ll ans = gcd_pairs(a, n);
  ll cnt = n*(n-1);
  cnt/=2;
  if(ans==cnt)
    cout<<"pairwise coprime\n";
  else if(gcd==1)
    cout<<"setwise coprime\n";
  else
    cout<<"not coprime\n";
  return 0;
}

Measured memory_bytes: 34432
string = input()
a,b,c,d = string[0],string[1],string[2],string[3]

def truth(x):
  count = 0
  if a ==b or a==c or a==d:
    count += 1
  if b ==c or b==d:
    count += 1
  if c ==d:
    count += 1
  if a == b == c or a ==b ==d or a==c==d:
    return False
  return count>1

if truth(a): print("Yes")
else: print("No")
                   


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll x, k, d;
  cin >> x >> k >> d;

  x = abs(x);
  if (k < x / d) {
    cout << x - k * d << '\n';
    return 0;
  }
  k -= x / d;
  x %= d;
  if (k & 1) x = d - x;
  cout << x << '\n';

  
  return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* 多次元デック */template<class T>deque<T> mdeq(size_t a){return deque<T>(a);}template<class T, class... Ts>auto mdeq(size_t a, Ts... ts){return deque<decltype(mdeq<T>(ts...))>(a, mdeq<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  auto H = mdeq<ll>(0);
  rep(i, 0, N){
    ll h;
    cin >> h;
    H.push_front(h);
  }
  rep(i, 0, N-1){
    if(H[i+1] == H[i] + 1) H[i+1]--;
    else if(H[i+1] >= H[i] + 1){
      cout << "No" << rt;
      return 0;
    }
  }
  cout << "Yes" << rt;
}

Measured memory_bytes: 1024
#!/usr/bin/env python

def main():
    N, Y = list(map(int, input().split()))
    for i in range(N+1):
        for j in range(N-i+1):
            tmp = 10000 * i + 5000 * j + 1000 * (N-i-j)
            if tmp == Y:
                print(i, j, N-i-j)
                exit()

    print("-1 -1 -1")

if __name__ == '__main__':
    main()

Measured memory_bytes: 38768
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);

int mod9(int A) {
    int tmp = 0;
    while (A > 0) {
        tmp += A % 10;
        A /= 10;
    }
    return tmp;
}

//番号ズレ注意！！
int main() {
    int N, K;
    cin >> N >> K;
    int l[N];
    REP(i, N) {
        cin >> l[i];
    }
    sort(l, l + N, greater<int>());
    int ans = 0;
    REP(i, K) {
        ans += l[i];
    }
    print(ans);
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
p = int(readline())
a = list(map(int,readline().split()))

MAX = 3000
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact[i] = (fact[i-1]*i) % p

inv = [1]*(MAX+1)
for i in range(2, MAX+1):
    inv[i] = inv[p % i]*(p-p//i) % p

fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % p

def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % p

ans = [0]*p
for i,ai in enumerate(a):
  if ai == 1:
    ans[-1] += 1
    for j in range(p):
      ans[j] -= pow(-i,j,p)*comb(p-1,j)%p
      ans[j] %= p
print(*ans[::-1])

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

int main() {
  int n;
  cin>>n;
  
  int x = n;
  int sum = 0;
  while (x > 0) {
    sum+=x%10;
    x/=10;
  }
  if(n%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> v(n);
  ll ans=0;
  rep(i,n)
    cin >> v.at(i);
  rep(ireru,(k/2)+1){
    rep(hidari,k-ireru+1){
      rep(migi,k-ireru-hidari+1){
        if(hidari+migi<ireru)continue;
        if(hidari+migi>n)continue;
        vector<ll> now;
        rep(i,hidari)
          now.push_back(v.at(i));
        rep(i,migi)
          now.push_back(v.at(n-i-1));
        sort(all(now));
        reverse(all(now));
        ll nowa=0;
        rep(i,hidari+migi-ireru)
          nowa+=now.at(i);
        ans=max(ans,nowa);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    private void solve() {
        long ans = 0;
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i % 3 != 0 && i % 5 != 0) {
                ans += i;
            }
        }
        out.println(ans);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 32980
/*
{
######################
#       Author       #
#        Gary        #
#        2020        #
######################
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int main(){
	fastio;
	int n;
	deque<int> dq;
	R(n);n*=3;
	vector<int> v;
	rb(i,1,n) {
		int ai;
		R(ai);
		v.PB(ai);
	}
	sort(ALL(v));
	reverse(ALL(v));
	rb(i,1,n)
		dq.PB(v[i-1]);
	LL rest=0;
	rb(i,1,n/3){
		dq.pop_front();
		rest+=dq.front();
		dq.pop_front();
		dq.pop_back();
	}
	cout<<rest<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/


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

#define ll long long

ll N;

int f(ll n, bool has_3, bool has_5, bool has_7) {
  if(n>N) {
    return 0;
  }

  int res = 0;
  if (has_3==true && has_5==true && has_7==true) {
    res += 1;
  }

  res += f(n*10+3, true, has_5, has_7);
  res += f(n*10+5, has_3, true, has_7);
  res += f(n*10+7, has_3, has_5, true);

  return res;
}

int main (){
  cin >> N;

  cout << f(0, false, false, false) << endl;

  return 0;
}


Measured memory_bytes: 256