akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

ll di[10000010];

int main() {
    ll n; cin >> n;
    ll ans = 0;
    Rep(i, 1, n){
        // for(int j = i; j <= n; j += i) ans += j;
        ll r = n/i;
        ans += r*(r+1)*i/2;
    }

    co(ans);


    return 0;
}


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

int main(){
	long long S; cin >> S;
	int A = 1e9 , B = S / 1e9 + (S % 1000000000 ? 1 : 0) , C = 1 , D = (long long) A * B - S;
	printf("%d %d %d %d %d %d" , 0 , 0 , A , D , C , B);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    pair<string,P> book[n];
    rep(i,n){
        string city; int point;
        cin >> city >> point;
        book[i] = make_pair(city,make_pair(point*-1,i));
    }
    sort(book,book+n);
    rep(i,n){
        cout << book[i].second.second + 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      
        int x = sc.nextInt();
     
        int count = 0;
      
        for (int i=1; i < x+1; i++) {
          count = count + i;
          //System.out.println("count is " + count);
        }
        System.out.println(count);
	} 
}

Measured memory_bytes: 23636
import java.util.*;
import java.math.BigInteger;
class Main{

     public static void main(String []args){
      Scanner scan = new Scanner(System.in);
      String s = scan.next();
      int size =s.length()-2 ;
      System.out.println(s.charAt(0)+""+size+""+s.charAt(s.length()-1));
    }
}

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

int main(){
  int n,k;
  cin >> n >> k;
  long long int ma,mi,ans;
  ans=ma=mi=0;
  for(int i = 0; i < k; i++){
    ma+=n-i;
    mi+=i;
  }
  for(int i =k; i <= n+1; i++){
    ans+=(ma-mi+1)%1000000007;
    ans%=1000000007;
    ma+=n-i;
    mi+=i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3188
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int K = sc.nextInt();
		long[] A = new long[K];
		for(int i=0; i<K; i++) {
			A[i] = sc.nextLong();
		}
		if(A[K-1] != 2) {
			System.out.println(-1);
			return;
		}
		long minnow = A[K-1];
		for(int i=K-2; i>=0; i--) {
			if(A[i] >= minnow * 2) {
				System.out.println(-1);
				return;
			}
			minnow = A[i] * ((minnow - 1) / A[i] + 1);
		}
		long maxnow = A[K-1];
		for(int i=K-2; i>=0; i--) {
			maxnow = A[i] * ((maxnow + A[i+1] - 1) / A[i]);
		}
		maxnow += A[0] - 1;
		if(maxnow < minnow) {
			System.out.println(-1);
			return;
		}
		System.out.println(minnow + " " + maxnow);
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


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

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vector<vector<int>> ans(h, vector<int>(w)); 
    int now_color_idx = 0;
    int color_paint_cnt = 0;
    rep(i, h) rep(j, w) {
        int now_masu_y = i;
        int now_masu_x = ( i % 2 == 0 ) ? j : w - 1 - j;
        ans[now_masu_y][now_masu_x] = now_color_idx + 1;
        ++color_paint_cnt;
        if ( color_paint_cnt < a[now_color_idx] ) {
            continue;
        }
        else {
            ++now_color_idx;
            color_paint_cnt = 0;
        }
    }

    rep(i, h) {
        rep(j, w) {
            if ( j != 0 ) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define uns unsigned
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int s = 0;
    for (int i = 1; i <= n; i++)
        if (i % 5 == 0 || i % 3 == 0)
            continue;
        else
            s += i;
    cout << s << endl;
    GAME_OVER;
}

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

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

using namespace std;

/////////////////////////////////////////////////////
ll N, M;
vector<ll> abv[1010];
ll i, j, k;
ll ans[2020],mk[1010];

bool dfs(ll a,ll p,ll d){
    if(mk[a]){
        if(a==p)
            return true;
        return false;
    }
    if (d == 0){
        return false;
    }
    mk[a] = 1;
    ll i = 0, f = 0;
    fornum(i,0,abv[a].size()){
        ll b = abv[a][i];
        if(dfs(b,p,d-1)){
            ans[d - 1] = a;
            return true;
        }
    }
    return false;
}
bool bs(ll a)
{
    ll i, j;
    fornum(i,0,N){
        fornum(j,0,N){
            mk[j + 1] = 0;
        }
        if(dfs(i+1,i+1,a)){
            return true;
        }
    }
    return false;
}

int main(){
    scanf("%lld%lld", &N, &M);
    fornum(i,0,M){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        abv[a].push_back(b);
    }
    ll l = 0, r = 2001;
    while(l<r){
        ll c = (l + r) / 2;
        if(bs(c)){
            r = c;
        }else{
            l = c+1;
        }
    }
    if(r==2001){
        printf("-1");
    }else{
        printf("%lld\n", r);
        fornum(i,0,r){
            printf("%lld\n", ans[i]);
        }
    }
    return 0;
}


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

int main() {
	int check = 0;
	do {
		string word;
		cin >> word;
		int num = word.size() - 1;
		if (!(word[0] == '-')) {
			int m;
			cin >> m;
			vector<int> h(m);
			for (int i = 0; i < m; ++i) {
				cin >> h[i];
			}
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < h[j]; ++k) {
					char str = word[0];
					for (int l = 0; l < word.size() - 1; ++l) {
						word[l] = word[l + 1];
					}
					word[num] = str;
				}
			}
			cout << word << endl;
		}
		else {
			check = 1;
		}

	} while (check == 0);
	return 0;
}

Measured memory_bytes: 3160
#include<iostream>
using namespace std;
int main(){
  int n;
  int offset;
  cin>>n>>offset;
  int left=offset;
  int right=offset+n-1;
  int sum=0;
  for(int i=left;i<=right;i++){
    sum+=i;
  }
  if(right<=0){
    sum-=right;
  }else if(left>=0){
    sum-=left;
  }
  cout<<sum<<endl;
  return(0);
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
	int n,k;
	cin>>n>>k;
	if(k==1)cout<<"0\n";
	else cout<<n-k<<"\n";


	return 0;
}


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

int main() {

    int a,b,c,d;

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    
    int mysum=0;
    
    if(a<=b){
        mysum+=a;
    }else {
        mysum += b;        
    }

    if (c <= d) {
        mysum += c;
    } else {
        mysum += d;
    }
    
    printf("%d",mysum);
    
    return 0;

}


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

class Dice{
public:
  vector<int> d;
  void spin(string s){
    if(s == "S"){
      swap(d[0],d[4]);
      swap(d[4],d[1]);
      swap(d[4],d[5]);
    }
    if(s == "E"){
      swap(d[0],d[3]);
      swap(d[2],d[3]);
      swap(d[3],d[5]);
    }
    if(s == "N"){
      swap(d[0],d[1]);
      swap(d[1],d[5]);
      swap(d[4],d[5]);
    }
    if(s == "W"){
      swap(d[0],d[2]);
      swap(d[2],d[5]);
      swap(d[3],d[5]);
    }
    if(s == "C"){
      swap(d[1],d[3]);
      swap(d[2],d[3]);
      swap(d[4],d[3]);
    }
  }
};


int main(){

  Dice saikoro;
  vector<int> in(6);
  for(int i=0; i<6; i++){
    cin >> in[i];
  }
  saikoro.d = in;

  map<pair<int,int>,int > cashe; // ????????? --> ???
  
  string s = "CCCCECCCCECCCCECCCCSCCCCSSCCCC";
  for(int i=0; i<s.size(); i++){
    cashe[make_pair(saikoro.d[0],saikoro.d[1])] = saikoro.d[2];
    //    cout <<saikoro.d[0] << " "  << saikoro.d[1] << " " <<  saikoro.d[2] << endl;
    saikoro.spin(s.substr(i,1));
  }  
  int q; cin >> q;
  for(int i=0; i<q; i++){
    int a,b; cin >> a >> b;
    cout << cashe[make_pair(a,b)] << "\n";
  }

}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  string s="";
  cin >> N;
  while(N!=0){
    if(N%2==0){
      s="0"+s;
    }else{
      N--;
      s="1"+s;
    }
    N/=-2;
  }
  if(s=="") s='0';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int n = sc.nextInt();
		int count=0;
		for(int i=0;i<n;i++){
			String s = sc.next();
			s = s.concat(s);
			if(s.indexOf(str)!=-1) count++;
		}
		System.out.println(count);
	}
	
}



Measured memory_bytes: 26284
s = int(input())

def f(n):
    if n % 2 == 0:
        return n//2
    else:
        return 3*n+1

a = [s]
i = 0

while len(a) == len(set(a)):
    a.append(f(a[i]))
    i += 1

print(i+1)

Measured memory_bytes: 38384
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x = I()
if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
elif 1800 <= x <= 1999:
    print(1)


Measured memory_bytes: 10448
c= [list(map(int, input().split())) for i in range(3)]
if c[1][0]-c[0][0]==c[1][1]-c[0][1]==c[1][2]-c[0][2] and c[1][0]-c[2][0]==c[1][1]-c[2][1]==c[1][2]-c[2][2]:
    print("Yes")
else:
    print("No")

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

int main()
{
    int n;
    cin>>n;
    vector<int > v;
    for(int i=0;i<n;i++)
    {
        int t;  cin>>t;
        v.push_back(t);
    }
    
    int c;
    cin>>c;
    while(c--)
    {
        int q;
        cin>>q;
        if(binary_search(v.begin(),v.end(),q))
        cout<<1<<endl;
        else cout<<0<<endl;
    }
}


Measured memory_bytes: 3540
def fromAdjRow(xs, n)
  a = []
  1.upto(n) do |i|
    a.unshift(i) if xs[i-1] == 1
  end
  a
end

def toAdj(g, n)
  g.map do |xs|
    a = [0]*n
    unless xs[1] == 0
      xs[2..-1].each do |x|
        a[x-1] = 1
      end
    end
    a
  end
end

if __FILE__ == $0
  n = gets.to_i
  g = toAdj(n.times.map{ gets.split.map(&:to_i) }, n)

  discoveredTimeStamp = Array.new(n, 0)
  finishedTimeStamp   = Array.new(n, 0)
  discoveredVertexes  = Array.new(n, false)
  stack = [1]
  time = 1

  until stack.empty?
    v = stack.pop
    vs = fromAdjRow(g[v-1], n).select{ |x| !discoveredVertexes[x-1] }

    if discoveredVertexes[v-1]
      if finishedTimeStamp[v-1].zero?
        finishedTimeStamp[v-1] = time
      else
        next
      end
    else
      discoveredVertexes[v-1] = true
      discoveredTimeStamp[v-1] = time
      stack.push(v)
    end
    
    vs.each{ |x| stack.push(x) }
    time+=1

    # スタックが空になったら、未到達のノードがあるか探す。ある場合はスタックに積む.
    if stack.empty?
      v = discoveredVertexes.index(false)
      unless v.nil?
        stack.push(v+1)
      end
    end
  end

  1.upto(n) do |x|
    puts sprintf("%d %d %d", x, discoveredTimeStamp[x-1], finishedTimeStamp[x-1])
  end
end

Measured memory_bytes: 6212
import sys
S = input()

for i, s in enumerate(S):
    if i%2==0:
        if s not in ["R", "U", "D"]:
            print("No")
            sys.exit()
    else:
        if s not in ["L", "U", "D"]:
            print("No")
            sys.exit()

print("Yes")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	string s,t;
	cin>>s;
	cin>>t;
	int ls=s.size();
	int lt=t.size();
	if(lt!=ls+1)
	{
		cout<<"No";
		return 0;
	}
	int flag=0;
	for(int i=0;i<ls;i++)
	{
		if(s[i]!=t[i])
		{
			flag=1;
			break;
		}
	}
	if(flag)
	{
		cout<<"No";
		return 0;
	}
	cout<<"Yes";
	
	return 0;
} 

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>

#include <atcoder/convolution>
#include <atcoder/modint>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

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

	bool fi = true;
	for (int x: atcoder::convolution<998244353>(a, b)) {
		if (!fi)cout << ' ';
		cout << x;
		fi = false;
	}
	cout << endl;
	

	return 0;
}


Measured memory_bytes: 19004
// 5/8 過去問ガリガリ
#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 dp[1000000010];

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

    // memset(dp, 0, sizeof(dp));

    // bool ans = true;

    map<int, int> mp;

    rep(i, N) {
        int a;
        cin >> a;

        // if (dp[a]) {
        //     ans = false;
        //     break;
        // } else {
        //     dp[a]++;
        // }
        if (mp[a]) {
            cout << "NO" << endl;
            return 0;
        } else {
            mp[a]++;
        }
    }

    cout << "YES" << endl;
    return 0;

    // if (ans) cout << "YES" << endl;
    // else cout << "NO" << endl;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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 (b<a) { a=b; return 1; } return 0; }
 
int N, M, Q;

vector<vector<int>> ars; 


void makeArray(int n, int cnt, vector<int> c)
{    
    if(cnt>=N)
    {
        ars.push_back(c);
        return;
    }

    for(int i=n; i<=M; i++)
    {
        vector<int> v;
        copy(c.begin(), c.end(), back_inserter(v));
        v.push_back(i);
        makeArray(i, cnt+1, v);
    }
}


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

    cin >> N >> M >> Q;

    for(int i=1; i<=10; i++)
    {
        vector<int> c;
        c.push_back(i);
        makeArray(i, 1, c);
    }
    
    int abcd[Q][4];
    rep(i, Q)
    {
        cin >> abcd[i][0] >> abcd[i][1] >> abcd[i][2] >> abcd[i][3];  
        abcd[i][0]--; abcd[i][1]--;
    }
 
    priority_queue<ll, vector<ll>, greater<ll>> q;
    q.push(0);

    rep(i, ars.size())
    {
        ll tmp=0;
        rep(j, Q)
        {
            int b=(ars[i][abcd[j][1]]);
            int a=(ars[i][abcd[j][0]]);

            if(b-a==abcd[j][2])
            {
                tmp+=abcd[j][3];
            }
        }
        q.push(tmp);
        q.pop();   
    }

    cout<< q.top() << endl;



    return 0;
}



Measured memory_bytes: 9828
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};



int main(){
    int h,w;cin >> h >> w;
    vector<string> s(h);
    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sy--,sx--,gy--,gx--;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    deque<pair<P,int>> dq;
    dq.push_front({{sy,sx}, 0});
    vector<vector<int>> dp(h, vector<int> (w, INF));
    dp[sy][sx] = 0;
    while(not dq.empty()){
        P p = dq.front().fs;
        int c = dq.front().sc;
        dq.pop_front();
        int y = p.fs, x = p.sc;
        if(dp[y][x]>c) continue;
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i], nx = x + dx[i];
            if(0<=ny&&ny<h&&0<=nx&&nx<w&&s[ny][nx]=='.'){
                if(chmin(dp[ny][nx],c)){
                    dq.push_front({{ny,nx},c});
                }
            }
        }
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                int ny = y + i, nx = x + j;
                if(0<=ny&&ny<h&&0<=nx&&nx<w&&s[ny][nx]=='.'){
                    if(chmin(dp[ny][nx], c+1)){
                        dq.push_back({{ny,nx},c+1});
                    }
                }
            }
        }
    }
    if(dp[gy][gx] == INF){
        puts("-1");
    }
    else{
        cout << dp[gy][gx] << endl;
    }
    return 0;
}



Measured memory_bytes: 9716
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e10)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int N,K;


long long ans=0;



int main()
{
  cin>>N>>K;
  double p = 0.0;
  REP(i, 1,N+1 )
  {
    double tmp=1.0/N;
    int now = i;
    while (now<K){
      now *= 2;
      tmp /= 2.0;
    }
    p += tmp;
  }
  printf("%.12f\n",p);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
 ll A,B;
  vector<bool>ans(3,true);
 
  cin>>A;
  ans[A-1]=false;
  cin>>B;
  ans[B-1]=false;
  
  rep(i,3){
    if(ans[i]){
cout<<i+1<<endl;
      break;
    }
  }

}

  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

const int NIL = -1;

struct Node {
  int parent, left, right;
};
vector<Node> T;
int n;

void preParse(int u) {
  if (u == NIL) return;
  cout << " " << u;
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u) {
  if (u == NIL) return;
  inParse(T[u].left);
  cout << " " << u;
  inParse(T[u].right);
}

void postParse(int u) {
  if (u == NIL) return;
  postParse(T[u].left);
  postParse(T[u].right);
  cout << " " << u;
}

int getRoot() {
  int u = 0;
  while (T[u].parent != NIL) {
    u = T[u].parent;
  }
  return u;
}

int main() {
  cin >> n;
  T.resize(n);
  rep(i, n) T[i].parent = T[i].left = T[i].right = NIL;
  rep(i, n) {
    int id, left, right;
    cin >> id;
    cin >> left >> right;
    if (left != NIL) {
      T[id].left = left;
      T[left].parent = id;
    }
    if (right != NIL) {
      T[id].right = right;
      T[right].parent = id;
    }
  }
  int root = getRoot();
  cout << "Preorder" << endl;
  preParse(root);
  cout << endl;
  cout << "Inorder" << endl;
  inParse(root);
  cout << endl;
  cout << "Postorder" << endl;
  postParse(root);
  cout << endl;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define endl "\n"
#define loop(i,s,e) for(int i=s;i<e;i++)
#define int long long
#define mp make_pair
#define pii pair<int,int>
#define mset(a,f)  memset(a , f , sizeof(a))
#define pb push_back
const int N = 2e6 + 6;
const int M = 1e9 + 7;
int A[N];
int n;

void solve()
{
	int n ,k;
	cin >>  n >> k;

	int r = (n/k);

	if(n%k == 0)
	{
		cout << 0;
		return;
	}
	else 
	{
		cout << min({abs(k*r-n) , n , abs(k*r+k-n)});
	}
}
 
int32_t main()
{
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
    

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


Measured memory_bytes: 256
N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))
if N >= M:
    print(0)
else:
    gap = []
    for i in range(M-1):
        gap.append(abs(X[i+1]-X[i]))
    gap = sorted(gap,reverse = 1)
    print(sum(gap[N-1:]))

Measured memory_bytes: 13960
#include <iostream>
using namespace std;
int gcd(int a, int b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a%b);
    }
}
int main() {
    int k, sum=0;
    cin >> k;
    for (int a=1; a<k+1; a++) {
        for (int b=1; b<k+1; b++) {
            for (int c=1; c<k+1; c++) {
                sum += gcd(gcd(a,b), c);
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>

int main(void){
    char S[11];
    int c = 0;
    int small = 0;
    scanf("%s", S);
    for(int i = 1; i < strlen(S) ; i++){
        if((i > 1) && (i < strlen(S)-1) && S[i] == 'C') c += 1;
        else if('a' > S[i] || S[i] > 'z') small += 1;  
    }
    printf("%s\n", (small == 0 && c == 1 && S[0] == 'A') ? "AC" : "WA");
    return 0; 
}


Measured memory_bytes: 128
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define	LEN 204800

char e[LEN];

void main2(int x)
{

	if ( x < 4 ) {
		printf("%d",x);
	} else {
		int x2 = x*2;
		int xq = (int)sqrt(x2);

		memset(e,0,x2);

		for ( int i = 3 ; i < xq ; i += 2 ) {
			if ( e[i] == 0 ) {
				for ( int j = i ; j < x2 ; j += i*2 ) {
					e[j] = 1;
				}
			}
		}
		if ( ( x & 1 ) == 0 )
			x++;
		for ( int i = x ; i < x2 ; i += 2 ) {
			if ( e[i] == 0 ) {
				printf("%d",i);
		break;
			}
		}

	}

}

int main()
{
	int x;
	scanf("%d",&x);
	main2(x);
}


Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

template <long long mod>
long long mod_pow(long long a, long long b) {
    if (b == 0) return 1;
    long long ret = mod_pow<mod>(a, b / 2);
    ret = ret * ret % mod;
    if (b % 2 == 1) ret = a * ret % mod;
    return ret;
}

template <long long mod>
struct Comb {
    int n;
    vector<long long> fact, inv;

    Comb(int n)
        : n(n), fact(n + 1, 0), inv(n + 1, 0) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
        inv[n] = mod_pow<mod>(fact[n], mod - 2);
        for (int i = n; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;
    }

    long long operator()(int m, int k) {
        if (m > n || m < k || k < 0)
            return 0;
        else
            return fact[m] * inv[m - k] % mod * inv[k] % mod;
    }
};

const ll MOD = TEN(9) + 7;
ll n, k;

int main() {
    fastio();

    cin >> n >> k;

    Comb<MOD> comb(n);

    ll ans = 0;
    for (ll i = min(n - 1, k); i >= 0; i--) {
        ans = (ans + comb(n, i) * comb(n - 1, n - i - 1) % MOD) % MOD;
        //cout << i << " " << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    vector<P> r, v;
    REP(i,n) {
        long a, b;
        cin >> a >> b;
        r.push_back(P(a,b));
    }
    REP(i,n) {
        long a, b;
        cin >> a >> b;
        v.push_back(P(a,b));
    }
    sort(r.begin(), r.end(), [](P a, P b){return a.second > b.second;});
    sort(v.begin(), v.end());
    int cnt = 0;
    REP(i,n) {
        REP(j,r.size()) {
            if (v[i].first > r[j].first && v[i].second > r[j].second) {
                cnt++;
                r.erase(r.begin() + j);
                break;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;import java.util.HashMap;
import java.util.Scanner;

public class Main {
	

	
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a[] = new int[n];
		HashMap<Integer,Long> h = new HashMap<>();
		for(int i=0;i<n;i++)
		{
			a[i] = s.nextInt();
			if(h.containsKey(a[i])) {
				h.put(a[i], h.get(a[i])+1);
			}
			else {
				h.put(a[i],1l);
			}
		}
	
		long sum = 0;
		for(int i:h.keySet()) {
			sum+=(h.get(i)*(h.get(i)-1))/2;
		}
		
		for(int i=0;i<n;i++) {
			long a1 = h.get(a[i]);
			long ans = sum-((a1)*(a1-1))/2+((a1-1)*(a1-2))/2;
			System.out.println(ans);
		}
		
		
		
		
	}
}

Measured memory_bytes: 110436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  vector <ll> v(3);
  ll n;
  rep(i, 3) cin >> v.at(i);
  sort(v.begin(), v.end());
  cin >> n;
  rep(i, n) v.at(2) *= 2;
  ll res = 0;
  rep(i, 3) res += v.at(i);
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


struct UnionFind {
	vector<int> par;
  
  UnionFind(int N): par(N){
  	for(int i=0;i<N;i++) par[i] =i;
  }
  
  
};



int main(){
  ios::sync_with_stdio(false);
  
  string S;
  cin>>S;
  if(S[0]==S[1] && S[1] == S[2]){
  	cout<<"No";
  }else{
  	cout<<"Yes";
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

char head[200001];
char tail[200001];

int main(){
  string s;
  int q;
  int hid=0;
  int tid=0;
  cin >> s >> q;
  bool now=true;
  rep(i,q){
    int a;
    cin >> a;
    if (a==1) now = !(now);
    else {
      int b;
      char tmp;
      cin >> b >> tmp;
      if (now== true && b==1) {
        head[hid]=tmp;
        hid++;
      }
      else if (now == true && b== 2) {
        tail[tid]=tmp;
        tid++;
      }
      else if (now==false && b== 1){
        tail[tid]=tmp;
        tid++;
      }
      else {
        head[hid]=tmp;
        hid++;
      }
    }
  }
  if (now){
    for (int i=hid-1;i >= 0;i--){
      printf("%c",head[i]);
    }
    printf("%s",s.c_str());
    for(int j=0;j < tid; j++){
      printf("%c",tail[j]);
    }
    printf("\n");
  }
  else{
    for (int i=tid-1;i >= 0;i--){
      printf("%c",tail[i]);
    }
    for (int w=s.size()-1;w >=0;w--){
      printf("%c",s[w]);
    }
    for(int j=0;j < hid; j++){
      printf("%c",head[j]);
    }
    printf("\n");
  }
 return 0; 
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL){
      y = x;
      if (z->key < x->key) {
          x = x->left;
      } else {
          x = x->right;
      }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node u){
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
    if (u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

int main()
{
    char str[2000];
    cin>>str;
    int a,b,c,d;
    a=b=c=d=0;
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]=='N')
            a=1;
        else if(str[i]=='S')
            b=-1;
        else if(str[i]=='W')
            c=1;
        else if(str[i]=='E')
            d=-1;
    }
    if(a+b==0&&c+d==0)
        cout<< "Yes";
    else
        cout<<"No";
    return 0;
}


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

public class Main {


	
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		
		int n = Integer.parseInt(br.readLine());
		
		Double[] arr = new Double[n];
		
		StringTokenizer st1 = new StringTokenizer(br.readLine());
		
		for(int i = 0 ; i < n ;i++)
			arr[i] = Double.parseDouble(st1.nextToken());
		
		Arrays.sort(arr);
		
		double res = arr[0];
		
		for(int i = 1 ; i < n ; i++)
		{
			res = (res + arr[i])/2.0;
			
		}
		
		out.println(res);
		
		out.flush();
		out.close();
	}
	
	
	


}


Measured memory_bytes: 21332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class DTeleporter {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            long K = Long.parseLong(in.next());
            int[] a = new int[n];
            int ans = 0;

            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next()) - 1;
            }

            int logK = 1;
            while ((1L << logK) < K) logK++;
            int[][] doubling = new int[logK][n];
            for (int i = 0; i < n; i++) {
                doubling[0][i] = a[i];
            }
            for (int k = 0; k < logK - 1; k++) {
                for (int i = 0; i < n; i++) {
                    doubling[k + 1][i] = doubling[k][doubling[k][i]];
                }
            }
            int now = 0;
            for (int k = 0; K > 0; k++) {
                if ((K & 1) == 1) now = doubling[k][now];
                K = K >> 1;
            }
            // 出力
            out.println(now + 1);

        }

    }
}



Measured memory_bytes: 102620
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;
lli n, a, b;
vector<lli> h_vec;

bool enough(lli t);

int main(){
    cin >> n >> a >> b;
    for(lli i = 0; i < n; i++){
        lli h;
        cin >> h;
        h_vec.push_back(h);
    }

    lli leftEdge = 1, rightEdge = 1000000001;
    lli ans = (rightEdge + leftEdge) / 2;
    while(leftEdge < rightEdge - 1){
        if(enough(ans)) rightEdge = ans;
        else leftEdge = ans;

        ans = (rightEdge + leftEdge) / 2;
        
        if((rightEdge - leftEdge + 1) % 2 == 0){
            if(!enough(ans)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

bool enough(lli t){
    lli numRequested = 0;
    for(lli i = 0; i < n; i++){
        if(h_vec[i] > b * t){
            numRequested += (h_vec[i] - b * t) / (a - b) + ((h_vec[i] - b * t) % (a - b) > 0);

            if(numRequested > t) return false;
        }
    }
    return true;
}

Measured memory_bytes: 1400
n = gets.chomp.to_i
prev_t = 0
prev = [0,0]
flag = true

n.times do |i|
  (t,x,y) = gets.chomp.split(' ').map(&:to_i)
  next if !flag

  diff = (prev[0]-x).abs + (prev[1]-y).abs
  if (t-prev_t) >= diff && (t-prev_t)%2 == diff%2
    prev_t = t
    prev = [x,y]
  else
    flag = false
  end
end

if flag
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
import java.util.*;

public class Main {
    private static Scanner scanner;

    public static int[] inputIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = scanner.nextInt();
        }

        return res;
    }

    // public static String[] <T> ToStringArray(T[] arr) {
    // String[] res = new String[arr.length];
    // for(int i = 0; i < arr.length; ++i) {
    // res[i] = String.valueOf(arr[i]);
    // }

    // return res;
    // }

    private static List<Integer> asIntergerList(int[] arr) {
        List<Integer> intList = new ArrayList<Integer>();
        for (int i = 0; i < arr.length; i++) {
            intList.add(arr[i]);
        }

        return intList;
    }

    private static int[][] deepCopy(int[][] arr) {
        int[][] res = new int[arr.length][];
        for (int i = 0; i < arr.length; ++i) {
            res[i] = arr[i].clone();
        }

        return res;
    }

    private static String asString(int[][] arr) {
        String str = new String();

        for (int i = 0; i < 2; ++i) {
            str += "" + arr[i][0] + arr[i][1] + arr[i][2] + arr[i][3];
        }

        return str;
    }

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

        int N = scanner.nextInt();

        int[] A = inputIntArray(N);

        int counter = 0;
        for (int i = 0; i < N; ++i) {
            int minj = i;
            for (int j = i; j < N; ++j) {
                if (A[j] < A[minj])
                    minj = j;
            }
            if (i != minj) {
                A[i] = A[i] ^ A[minj];
                A[minj] = A[i] ^ A[minj];
                A[i] = A[i] ^ A[minj];
                ++counter;
            }
        }
        for (int i = 0; i < N; ++i) {
            System.out.print((i == 0 ? "" : " ") + A[i]);
        }
        System.out.println();
        System.out.println(counter);
    }

    /*
     * public static void main(String[] args) { scanner = new Scanner(System.in);
     * 
     * while (true) { int n, r;
     * 
     * n = scanner.nextInt(); r = scanner.nextInt();
     * 
     * int[] arr = new int[n];
     * 
     * for (int i = 0; i < n; ++i) { arr[i] = n - i; }
     * 
     * 
     * } }
     */
}



Measured memory_bytes: 26248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  ll K;
  cin >> K;
  if (K%2==0 || K%5==0) {
    print(-1);
    return 0;
  }
  ll i=1,r=7;
  while (1) {
    if (r%K == 0) {
      print(i);
      return 0;
    }
    r *= 10;
    r += 7;
    r %= K;
    i++;
  }
  return 0;
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))

from collections import Counter
MOD = 10**9 + 7
c = Counter(a)

ans = 0

if n % 2 == 1:
    for i in range(2, n, 2):
        if c[i] != 2:
            print(0)
            exit()
    if c[0] == 1:
        ans = pow(2, n // 2, MOD)
else:
    for i in range(1, n, 2):
        if c[i] != 2:
            print(0)
            exit()
    ans = pow(2, n // 2, MOD)
print(ans)


Measured memory_bytes: 14692
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

inline char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
inline void read(int &x) {
  static char c; x = 0; int sgn = 0;
  for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
  if (sgn) x = -x;
}

int n, T, t;
long long ans, lst, res;

inline int Max(int a, int b) {
  return a > b ? a : b;
}

int main(void) {
  read(n); read(T); lst = ans = 0;
  for (int i = 1; i <= n; i++) {
    read(t);
    if (lst <= t) {
      ans += T; lst = t + T;
    } else {
      ans += t + T - lst; lst = t + T;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <vector>

using namespace std;

vector<int> e[611];
double dis1[611],dis0[611];
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for (int i=0;i<m;++i)
    {
        int t1,t2;scanf("%d%d",&t1,&t2);
        e[t1].push_back(t2);
    }
    for (int i=0;i<=n;++i) dis0[i]=dis1[i]=0;

    for (int i=n-1;i>0;--i){
        for (int j=0;j<e[i].size();++j){
            dis0[i]+=dis0[e[i][j]];
        }
        if (!e[i].size()) continue;
        dis0[i]/=(1.0*e[i].size());dis0[i]+=1.0;
        dis1[i]=dis0[i];
    }
    double ans=dis0[1];
    for (int i=1;i<n;++i){
        double tmp_max=0;
        if (e[i].size()==1) continue;
        dis1[i]=0;
        for (int j=0;j<e[i].size();++j){
            if (dis1[e[i][j]]>tmp_max)
                tmp_max=dis1[e[i][j]];
            dis1[i]+=dis1[e[i][j]];
        }
        dis1[i]-=tmp_max;
        dis1[i]/=(1.0*e[i].size()-1.0);
        dis1[i]+=1.0;
        for (int j=i-1;j>0;--j){
            dis1[j]=0;
            for (int k=0;k<e[j].size();++k)
                dis1[j]+=dis1[e[j][k]];
            if (!e[j].size()) continue;
            dis1[j]/=(1.0*e[j].size());
            dis1[j]+=1.0;
        }
        if (dis1[1]<ans) ans=dis1[1];
    }
    printf("%.8lf",ans);
}


Measured memory_bytes: 1408
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	int[][] map;
	int n=10;

	void run(){
		sc=new Scanner(System.in);
		map=new int[n][n];
		int[][] small={{0, 1, 0}, {1, 1, 1}, {0, 1, 0}};
		int[][] middle={{1, 1, 1}, {1, 1, 1}, {1, 1, 1}};
		int[][] large={{0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {1, 1, 1, 1, 1},
				{0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}};

		for(; sc.hasNext();){
//		for(int t=0; t<6; t++){
			String[] ss=sc.nextLine().split(",");
			int x=Integer.parseInt(ss[0]);
			int y=Integer.parseInt(ss[1]);
			int s=Integer.parseInt(ss[2]);
			int[][] d;
			if(s==1)
				d=small;
			else if(s==2)
				d=middle;
			else
				d=large;

			int m=d.length/2;
			for(int j=-m; j<=m; j++)
				for(int i=-m; i<=m; i++)
					if(d[j+m][i+m]==1)
						drop(x+i, y+j);
		}
		int max=0;
		int cnt=0;
		for(int j=0; j<n; j++){
			for(int i=0; i<n; i++){
				max=max(max, map[j][i]);
				if(map[j][i]==0)
					cnt++;
			}
		}
		println(cnt+"");
		println(max+"");
		sc.close();
	}

	void drop(int x, int y){
		if(x<0||x>=n||y<0||y>=n)
			return;
		map[y][x]++;
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
n = int(input())

ans = 0
for i in range(1,10) :
  for j in range(i,10) :
    c_a = 0
    c_b = 0
    for k in range(1,n+1) :
      kl = len(str(k))
      if k//(10**(kl-1)) == i and k%10 == j :
        c_a += 1
      if k//(10**(kl-1)) == j and k%10 == i :
        c_b += 1
    if i == j :
      ans += c_a*c_b
    else :
      ans += c_a*c_b*2
      
print(ans)

Measured memory_bytes: 43740