akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;

typedef pair<int, int> ii;      
typedef vector<ii> vii;      
typedef vector<int> vi;   
#define DFS_WHITE -1 
#define DFS_BLACK 1
vector<vi> AdjList;
vi dfs_num;     // this variable has to be global, we cannot put it in recursion
vi dfs_discover;
int numCC;
int count = 0;

int dfs(int u) {          // DFS for normal usage: as graph traversal algorithm
//  printf(" %d", u);                                    // this vertex is visited
  	dfs_num[u] = DFS_BLACK;      // important step: we mark this vertex as visited
  	int ans = 1;
  	for (int j = 0; j < (int)AdjList[u].size(); j++) {
    	int v = AdjList[u][j];                      // v is a (neighbor, weight) pair
    	if (dfs_num[v] == DFS_WHITE)         // important check to avoid cycle
      		ans += dfs(v);      // recursively visits unvisited neighbors v of vertex u
 	}
	return  ans; 
}

 
int main(){
	int n, m;
	cin>>n>>m;
	AdjList.assign(n + 1, vi());
	dfs_num.assign(n + 1, DFS_WHITE);
	for (int i=0; i<m; i++){
		int x, y;
		cin>>x>>y;
		AdjList[x].push_back(y);
		AdjList[y].push_back(x);
	}
	int ans = 0;
	for (int i=1; i<=n; i++){
		if(dfs_num[i] == DFS_WHITE){
			ans = max(ans,dfs(i));
		}
	}
	cout<<ans;
}

Measured memory_bytes: 24256
#include<bits/stdc++.h> 
#include<random> 
#define int long long 
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back 
#define mod 1000000007 
using namespace std; 
void fastio() 
{ 
    #ifndef ONLINE_JUDGE 
    freopen("INPUT.txt","r",stdin); 
    freopen("OUTPUT.txt","w",stdout); 
    #endif 
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL) ; 
    cout.tie(NULL); 
}

signed main() 
{ 
    fastio(); 
    int t=1;
   // cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       int a[n];
       for(int i=0;i<n;i++)
       cin>>a[i];
       int c=0,m=0;
       for(int i=1;i<n;i++)
       {
           if(a[i]<=a[i-1])
           c++;
           else
           {
               if(c>m)
               m=c;
               c=0;
           }
       }
       if(c>m)
       m=c;
       cout<<m;
    }
}


Measured memory_bytes: 4440
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 998244353
//#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=3050;
//↑templete
signed main(){
    int N;
    cin>>N;
    ll ans=0;
    for(ll i=1;i<=N;i++){
        if(i%3!=0 && i%5!=0)
            ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] x = new long[n];
		long[] y = new long[m];
		for(int i=0;i<n;i++) x[i] = sc.nextLong();
		for(int i=0;i<m;i++) y[i] = sc.nextLong();
		sc.close();

		long div = (long)Math.pow(10, 9)+7;
		/*
		long sum = 0;
		for(int i=1;i<n;i++){
			for(int j=1;j<m;j++){
				long dx = x[i]-x[i-1];
				long dy = y[j]-y[j-1];
				sum += dx*dy*(n-i)*i*(m-j)*j;
				sum %= div;
			}
		}
		*/
		long xsum = 0;
		for(int i=0;i<n;i++){
			xsum += (2*i-n+1)*x[i];
		}
		xsum %= div;
		long ysum = 0;
		for(int i=0;i<m;i++){
			ysum += (2*i-m+1)*y[i];
		}
		ysum %= div;
		long sum = xsum*ysum;
		System.out.println(sum%div);
	}

}

Measured memory_bytes: 94920
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
cum = a[0]
ans = abs(total - 2*cum)
for i in range(1,len(a)-1):
    cum += a[i]
    if abs(total - 2*cum) < ans:
        ans = abs(total - 2*cum)
print(ans)

Measured memory_bytes: 24832
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

  private static class Magic {

    int attackPoint;
    int cost;

    Magic(int attackPoint, int cost) {
      this.attackPoint = attackPoint;
      this.cost = cost;
    }
  }

  private static int minCost;
  private static List<Magic> magicsInAscendingOrderOfCost = new ArrayList<>();

  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    int hitPoint = scanner.nextInt();
    final int numberOfMagic = scanner.nextInt();
    final List<Magic> magics = new ArrayList<>();

    minCost = Integer.MAX_VALUE;
    for (int i = 0; i < numberOfMagic; i++) {
      Magic magic = new Magic(scanner.nextInt(), scanner.nextInt());
      magics.add(magic);

      if (minCost > magic.cost) {
        minCost = magic.cost;
      }
    }
    magicsInAscendingOrderOfCost = magics.stream()
        .sorted(Comparator.comparingInt(magic -> magic.cost))
        .collect(Collectors.toList());

    System.out.println(getCost(hitPoint));
  }

  private static long getCost(int hitPoint) {
    final int attackPointOfMinCost = magicsInAscendingOrderOfCost.get(0).attackPoint;
    if (hitPoint <= attackPointOfMinCost) {
      return minCost;
    }

    long[] minCosts = new long[hitPoint + 1];
    for (int i = 0; i <= attackPointOfMinCost; i++) {
      minCosts[i] = minCost;
    }

    for (int currentHitPoint = attackPointOfMinCost + 1; currentHitPoint <= hitPoint;
        currentHitPoint++) {

      long minCostCandidate = Long.MAX_VALUE;
      for (Magic magic : magicsInAscendingOrderOfCost) {
        int remainingHitPoint = currentHitPoint - magic.attackPoint;

        long candidate =
            remainingHitPoint > 0 ? minCosts[remainingHitPoint] + magic.cost : magic.cost;

        if (candidate < minCostCandidate) {
          minCostCandidate = candidate;
        }
      }

      minCosts[currentHitPoint] = minCostCandidate;
    }

    return minCosts[hitPoint];
  }
}

Measured memory_bytes: 35820
#include<bits/stdc++.h>
#define ll   long long int   
#define pb push_back
using namespace std;
const int M=1e9 + 7;

int main()
{   
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int* a=new int[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    int mx1=INT_MIN;
    int j=1;
    for(int i=1;i<=n;i++)
    {
			if(a[i]>mx1)
			{
				mx1=a[i];
				j=i;
			}
	}
	int mx2=INT_MIN;
	for(int i=1;i<=n;i++)
	{
		if(i==j)continue;
		 if(a[i]>mx2)
		 {
		 	mx2=a[i];
		 }
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==mx1)
		{
			cout<<mx2<<endl;
		}else{
			cout<<mx1<<endl;
		}
	}
	return 0;
}
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 2432
x,y = map(int, input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls ro<<1
#define fi first
#define se second
#define rs ro<<1|1
#define ll long long
#define pb push_back
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define lson ro<<1,l,mid
#define umap unordered_map
#define uset unordered_set
#define rson ro<<1|1,mid+1,r
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;
const int N=1e6+10;

int a[N];

int cmp(int a,int b) {
	return a>b;
}

signed main() {
	IOS;
	int n,k;
	cin>>n>>k;
	for(int i=0; i<n; i++) {
		cin>>a[i];
	}
	sort(a,a+n,cmp);
	int sum=0;
	for(int i=0; i<n; i++) {
		if(k) {
			k--;
			continue;
		} else {
			sum+=a[i];
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const ll mod=1e9+7;
long long factors(int x){
    long long f=0;
    for(int i=1;i<=(int)sqrt(x);i++){
        if(x%i==0 && i!=(x/i)) f+=2;
        else if(x%i==0 && i==(x/i)) f++;
    }
    return f;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif
    
    int n;
    cin>>n;
    n--;
    long long ans=0;
    while(n>0){    
        ans+=factors(n);
        //cout<<ans<<"\n";
        n--;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
using namespace std;
constexpr int mod = 1'000'000'000 + 7;

void calc(vector<int>& v, int a, int b, int C) {
    v.assign(C+1, 0);
    v[0] = b-a+1;
    for (int x = a; x <= b; ++x) {
        long long term = 1;
        for (int e = 1; e <= C; ++e) {
            term = term * x % mod;
            v[e] = (v[e] + term) % mod;
        }
    }
}

int main() {
    int N, C;
    cin >> N >> C;
    vector<int> A(N), B(N);
    copy_n(istream_iterator<int>(cin), N, A.begin());
    copy_n(istream_iterator<int>(cin), N, B.begin());
    vector<int> ans(C+1);
    calc(ans, A[0], B[0], C);
    for (int i = 1; i != N; ++i) {
        vector<int> temp(C+1), r(C+1);
        calc(r, A[i], B[i], C);
        for (int j = 0; j <= C; ++j)
            for (int k = 0; k <= C; ++k)
                if (j+k <= C) {
                    temp[j+k] += static_cast<long long>(ans[j])*r[k] % mod;
                    temp[j+k] %= mod;
                }
        copy(temp.begin(), temp.end(), ans.begin());
    }
    cout <<  ans[C] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX=100005;

int dp[MAX];
int main(){
    int N,K;
    cin >> N >> K;
    int i,j;
    int h[N];
    for(i=0;i<N;i++)cin >> h[i];
    for(i=1;i<N+5;i++)dp[i]=1e9+7;
    for(i=0;i<N;i++)for(j=1;j<K+1;j++)if(dp[i+j]>abs(h[i+j]-h[i])+dp[i])dp[i+j]=abs(h[i+j]-h[i])+dp[i];
    cout << dp[N-1] << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int sum =0;
    
  for(int i = A;i <= B;i++){
    if(i / 10000 == i % 10 && i / 1000 % 10 == i % 100 /10){
      sum += 1;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    static class Sushi implements Comparable<Sushi> {
        int t;
        int d;
        boolean dup;

        Sushi(int t, int d, boolean dup) {
            this.t = t;
            this.d = d;
            this.dup = dup;
        }

        public int compareTo(Sushi other) {
            return other.d - d;
        }
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        Sushi a[] = new Sushi[N];
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            int d = sc.nextInt();
            a[i] = new Sushi(t, d, false);
        }
        Arrays.sort(a);
        boolean[] selected = new boolean[N + 1];
        for (int i = 0; i < N; i++) {
            if (selected[a[i].t]) {
                a[i].dup = true;
            }
            selected[a[i].t] = true;
            //System.out.printf("%d %d %b\n", a[i].t, a[i].d, a[i].dup);
        }
        long s = 0;
        long x = 0;
        selected = new boolean[N + 1];
        for (int i = 0; i < K; i++) {
            s += a[i].d;
            if (!selected[a[i].t]) {
                x += 1;
                selected[a[i].t] = true;
            }
        }
        //System.out.printf("s = %d, x = %d, %d\n", s, x, s + x*x);
        long smax = s + x * x;
        int q = K - 1; // 捨てるところポインタ
        while (q >= 0 && !a[q].dup) {
            q -= 1;
        }
        int p = K; // 追加する寿司ポインタ
        while (q >= 0) {
            // 次の新しい寿司を探す
            while (p < N && selected[a[p].t]) {
                p += 1;
            }
            if (p >= N) break;
            s = s - a[q].d + a[p].d;
            x += 1;
            selected[a[p].t] = true;
            if (s + x * x > smax) {
                smax = s + x * x;
            }
            // System.out.printf("s = %d, x = %d, %d\n", s, x, s + x*x);
            // 捨てるポインタ更新
            q -= 1;
            while (q >= 0 && !a[q].dup) {
                q -= 1;
            }
        }
        System.out.printf("%d\n", smax);
    }
}


Measured memory_bytes: 89316
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    cards=[]
    sorted_cards=[]
    n = int(input())
    cards=list(map(int,input().split()))
    sorted_cards=sorted(cards,reverse=True)
    alice=0
    bob=0

    for idx,card in enumerate(sorted_cards):
        if idx%2==0:
            alice+=card
        else:
            bob+=card
    print(alice-bob)

if __name__=="__main__":
    main()

Measured memory_bytes: 9180
#include <cassert>
#include <vector>
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  long long ok = 0, ng = 1e10;
  vector<long long> W(N+1);
  while(ng-ok > 1){
    long long m = (ok+ng)/2;
    W[0] = m*2;
    for(int i = 1; i <= N; ++i){
      W[i] = (A[i-1] - W[i-1]/2)*2;
    }
    if(W[0] <= W[N]){
      ok = m;
    }else{
      ng = m;
    }
  }
  long long m = (ok+ng)/2;
  W[0] = m*2;
  for(int i = 1; i <= N; ++i){
    W[i] = (A[i-1] - W[i-1]/2)*2;
  }
  assert(W[0] == W[N]);
  //cerr << ok << " " << ng << endl;
  //cout << ok << endl;
  cout << W[0];
  for(int i = 1; i < N; ++i) cout << " " << W[i];
  cout << endl;
}


Measured memory_bytes: 2944
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new MyInputStream(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(MyInputStream cin)
        {
            Write("ABC");
            WriteLine(cin.ReadInt());
        }
    }

    public class MyInputStream
    {
        private readonly System.IO.TextReader _stream;
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(System.IO.TextReader s, char separator = ' ')
        {
            this.separator = separator;
            this._stream = s;
            inputStream = new Queue<string>();
        }
        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return _stream.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}



Measured memory_bytes: 13268
#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <cmath>
#include<cstring>
#include <cstdio>
#include <stack>
#include<iomanip>
#include<queue>
#include<functional>
#include<iterator>
#include<new>
#include<cstdlib>
using namespace std;
#define INF 2000000000
#define scll(x) scanf("%lld",&x);
#define sci(x)  scanf("%d",&x);
#define scc(x)  scanf("%c", &c);
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a*b / gcd(a, b);
}

ll q, h, s, d, n, ans = 0;

int main() 
{
	cin >> q >> h >> s >> d >> n;
	if (2 * q < h)
		h = 2 * q;
	if (2 * h < s)
		s = 2 * h;
	if (2 * s < d)
		d = 2 * s;
	ans += (n / 2)*d;
	n = n % 2;
	ans += n*s;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int M = 1e5 + 10;
int a[M] , b[M] , ha[M] , hb[M];
bool vis[M] , have[M];
vector<int>vc[M];
void dfs(int u) {
    vis[u] = true;
    int len = vc[u].size();
    for(int i = 0 ; i < len ; i++) {
        int v = vc[u][i];
        if(vis[v]) continue;
        dfs(v);
    }
}
int main() {
    int n;
    cin >> n;
    a[0] = 0;
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        a[0] ^= a[i];
        ha[i] = a[i];
    }
    ha[0] = a[0];
    b[0] = 0;
    for(int i = 1 ; i <= n ; i++) {
        cin >> b[i];
        b[0] ^= b[i];
        hb[i] = b[i];
    }
    hb[0] = b[0];
    sort(ha , ha + n + 1);
    sort(hb , hb + n + 1);
    for(int i = 0 ; i <= n ; i++) {
        if(ha[i] != hb[i]) {
            cout << -1 << endl;
            return 0;
        }//这里是判断能否通过操作得到。
    }
    for(int i = 0 ; i <= n ; i++) {
        a[i] = lower_bound(ha , ha + 1 + n , a[i]) - ha;
        b[i] = lower_bound(hb , hb + 1 + n , b[i]) - hb;
    }//离散一下由于a[i],b[i]太大了。当然用map就不用这样操作了。
    int ans = 0;
    memset(have , false , sizeof(have));
    memset(vis , false , sizeof(vis));
    for(int i = 0 ; i <= n ; i++) {
        if(a[i] != b[i] || i == 0) {
            if(i) ans++;
            have[a[i]] = true , have[b[i]] = true;
            vc[a[i]].push_back(b[i]);
        }
    }
    for(int i = 0 ; i <= n ; i++) {
        if(!vis[i] && have[i]) {
            dfs(i) , ans++;
        }
    }
    ans--;//这里的ans--是减去第0位点被算进去的情况
    ans = max(ans , 0);
    cout << ans << endl;
    return 0;
}

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

vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) {// 0からsqrt(max)まで調べる
      if(IsPrime[i]) {// iが素数ならば
        for(size_t j=2; i*j<=max; ++j) {// (max以下の)iの倍数は
          IsPrime[i*j] = false;      // 素数ではない
        }
      }
    }
}

int main() {
  //input
  int A, B;
  cin >> A >> B;
  //calc
  int M = max(A, B);
  sieve(M);
  int64_t answer = 1;
  int a = A;
  int b = B;
  rep(i,M+1) {
    if ( IsPrime[i] ) {
      while (true) {
        if ( a % i == 0 ) {
          a = a / i;
          if ( b % i == 0 ) {
            b = b / i;
          }
          answer *= i;
        }
        else if ( b % i == 0 ) {
          b = b / i;
          answer *= i;
        }
        else {
          break;
        }
      }
    }
    if ( a == 1 && b == 1 ) {
      break;
    }
  }
  //output
  cout << answer << endl;
}

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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;

int main(){
    CIN1(a)
    if(a==1){
        cout << "Hello World" << endl;
    }else{
        CIN2(x,y)
        cout << x+y << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxk=1e4+5, maxd=1e2+5, mod=1e9+7;
ll d,k,dp[maxk][maxd][2];
string s;
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>s>>d;
    k=s.size();
    dp[k][0][0]=dp[k][0][1]=1;
    per(i,0,k) rep(j,0,d) { 
        rep(h,0,10) dp[i][(j+h)%d][1]+=dp[i+1][j][1];
        rep(h,0,s[i]-'0') dp[i][(j+h)%d][0]+=dp[i+1][j][1];
        dp[i][(j+s[i]-'0')%d][0]+=dp[i+1][j][0];
        dp[i][j][0]%=mod; dp[i][j][1]%=mod;
    }
    ll ans=(dp[0][0][0]-1+mod)%mod;
    cout<<ans<<"\n";
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,mn=INT_MAX;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        mn=min(mn,arr[i]);
    }
    while(1)
    {
        int new_mn=INT_MAX,sk=0;
        for(int i=0; i<n; i++)
        {
            if(arr[i]==mn && !sk)
                sk=1;
            else
            {
                arr[i]%=mn;
                if(arr[i])
                {
                    new_mn=min(new_mn,arr[i]);
                }
            }
        }
        if(new_mn==INT_MAX)
            break;
        mn=new_mn;
    }
    cout<<mn<<endl;



    return 0;
}


Measured memory_bytes: 4040
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] a = new int[100_001];
        for (int i = 0; i < n; i++) {
            int X = in.nextInt(); ++a[X];
            if (X < 100_001 - 1) ++a [X + 1];
            if (X >0) ++a [X -1];
        }
    int wynik = 0;
        for (int b : a) wynik =Math.max(wynik,b);
        System.out.println(wynik);

    }
}














Measured memory_bytes: 50956
import bisect

N = int(input())
L = sorted(([int(x) for x in input().split()]))

count = 0
for i in range(N - 1, -1, -1):
    for j in range(i - 1, -1, -1):
        # L[j] は L[i]以下の集合を降順で参照する
        k = bisect.bisect_left(L, L[i] + L[j])
        # L[i]+L[j] > k > L[j]
        count += k - (i + 1)
print(count)


Measured memory_bytes: 43740
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var A = Number(line[0]);
	var B = Number(line[1]);
	var C = Number(line[2]);
	var X = Number(line[3])/50;

	// 10*A + 2*B + C = X
	var ans = 0;
	for(var a = 0; 10*a <= X && a <= A; a++){
		for(var b = 0; 10*a + 2*b <= X && b <= B; b++){
			if(10*a + 2*b + C >= X) ans++;
		}
	}

	console.log(ans);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
a,b,k = map(int,input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

ans =[]
for x in range(1, gcd(a,b)+1):
    if a%x==0 and b%x==0:
        ans.append(x)
# print(ans)
print(ans[-k])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long num[30];
int main(){
    int n; cin>>n;
    string s; cin>>s;
    rep(i,n) num[s[i]-'a']++;
    long long ans=1;
    rep(i,26){
        ans*=(num[i]+1);
        ans%=MOD;
    }
    ans=(ans+MOD-1)%MOD;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	//sc.Split(bufio.ScanWords)
	r := nextFloat()
	p := math.Pi
	fmt.Printf("%f %f\n", r*r*p, 2*r*p)
}



Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    const int n = 3;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    vi id(n);
    rep(i, n) id[i] = i;
    int ans = 1e9;
    do {
        string &a = s[id[0]], &b = s[id[1]], &c = s[id[2]];
        auto calc = [&](const string& a, const string& b, int i) {
            if(i == a.size()) return true;
            bool f= true;
            rep(j, b.size()) {
                if(i+j < a.size()) {
                    f&= a[i+j] == '?' || b[j] == '?' || a[i+j] == b[j];
                }
            }
            return f;
        };
        vector<int> ab(a.size()+1), ac(a.size()+1), bc(b.size()+1);

        rep(i, a.size()+1) {
            ab[i] = calc(a, b, i);
            ac[i] = calc(a, c, i);
        }
        rep(i, b.size()+1) {
            bc[i] = calc(b, c, i);
        }

        dump(a); dump(b); dumpL(c);
        dumpVL(ab);
        dumpVL(ac);
        dumpVL(bc);

        rep(i, a.size()+1) {
            if(!ab[i]) continue;
            int n = max((int)b.size() + i, int(a.size()));
            REP(j, i, n+1) {
                bool f= true;
                if(j < (int)a.size()) f &= ac[j];
                if(j - i < (int)b.size()) f &= bc[j-i];
                if(f) {
                    chmin(ans, max({(int)c.size()+j, (int)a.size(), n}));
                    dump(i); dump(j); dumpL((int)c.size()+j);
                }
            }
        }
    }while(next_permutation(all(id)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        double p;
        double tmp = 0;
        double max = 0;
        ArrayDeque<Double> deq = new ArrayDeque<>();
        for (int i = 1; i <= N; i++) {
            if (i > K) {
                tmp -= deq.pollFirst();
            }
            p = CalcEx(sc.nextDouble());
            tmp += p;
            if ((i >= K)) {
                if (tmp > max) {
                    max = tmp;
                }
            }
            deq.offerLast(p);
        }

        System.out.println(max);
    }

    public static double CalcEx(double p) {
        double result = 0;
        result = (p + 1) / 2;
        return result;
    }
}

Measured memory_bytes: 163672
from collections import defaultdict

N = int(input())

cnt = defaultdict(int)
for i in range(1, N + 1):
    i = str(i)
    l = i[0]
    r = i[-1]
    cnt[(l, r)] += 1
    cnt[(r, l)] += 0

ans = 0
for (l, r), c in cnt.items():
    ans += cnt[(r, l)] * c

print(ans)


Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=200+3;
int b[N][N];
vector<int> a[N];
string s[N];
int color[N];
bool vis[N];
bool f;
int cnt1=0,cnt2=0;
void dfs(int u,int o=0)
{
      if(vis[u]){
            // cout<<color[u]<<u<<" "<<o<<" ";
            if(color[u]!=o)
            {
                  f=true;
            }
            return;
      }
      vis[u]=true;
      if(o==0) cnt1++;
      else cnt2++;
      // cout<<u<<" ";
      color[u]=o;
      for(auto x:a[u])
      {
            dfs(x,1-o);
      }
}

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int n;
      cin>>n;
      for(int i=0;i<n;i++) cin>>s[i];
      for(int i=0;i<n;i++) 
       for(int j=0;j<n;j++) 
      {
            // cout<<s[i][j]<<" ";
            if(s[i][j]=='1')
            {
                  // cout<<i<<" "<<j<<"\n";
                  b[i+1][j+1]=1;
                  a[i+1].pb(j+1);
                  // a[j].pb(i);
            }
            else b[i+1][j+1]=1e18;
            if(i==j) b[i+1][j+1]=0;
      }
      dfs(1);
      if(f)
      {
            cout<<"-1";
            return 0;
      }
      for(int i=1;i<=n;i++)
      {
            for(int j=1;j<=n;j++)
            {
                  for(int k=1;k<=n;k++)
                  {
                        b[j][k]=min(b[j][k],b[j][i]+b[i][k]);
                  }
            }
      }
      int an=-1;
      for(int i=1;i<=n;i++)
      {
            for(int j=1;j<=n;j++)
            {
                  // cout<<b[i][j]<<" ";
                  an=max(an,b[i][j]);
            }
      }
      cout<<an+1<<"\n";
}
// I never lose. I either win or I learn

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();

        if(s.equals(u)) a--;
        else b--;
        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 21844
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        String str[]=br.readLine().split(" ");
        int arr[]=new int[n+1];
        for(int i=1;i<=n;i++)
        arr[i]=Integer.parseInt(str[i-1]);
        TreeMap<Integer,Integer> tmap=new TreeMap<>();
        long ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=(long)tmap.getOrDefault(i-arr[i],0);
            tmap.put(i+arr[i],tmap.getOrDefault(i+arr[i],0)+1);
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 70924
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
全探索か
途中のD調整が分からない･･･。
逆算方式か。
これかも
3^60通りとかになっちゃう
むず、だめだ
逆算、あまりを+-して、2,3,5のどれかで割るの繰り返ししかありえない
%=0ならそのまま割るしかない
サンプル5行目がTLEだな

これ以上どこを効率化するんだ
bfsじゃなくてdfsで実装すればいい？
直感的にはそのほうがケースへりそうだけど、それだけかな・・・

やりたいことあってた、けど実装力全然足らない･･･。
*/

ll N,A,B,C,D,high=4e18; 
map<ll,ll> M;
ll dfs(ll n){
  if(n==0) return 0;
  if(n==1) return D;
  if(M.count(n)) return M[n];
  M[n]=4e18;
  if(log10(n*D)<18) M[n]=min(M[n],n*D);
  M[n]=min(M[n],dfs(n/2)+A+n%2*D);
  M[n]=min(M[n],dfs(n/2+1)+A+(2-n%2)*D);
  M[n]=min(M[n],dfs(n/3)+B+n%3*D);
  M[n]=min(M[n],dfs(n/3+1)+B+(3-n%3)*D);
  M[n]=min(M[n],dfs(n/5)+C+n%5*D);
  M[n]=min(M[n],dfs(n/5+1)+C+(5-n%5)*D);
  return M[n];
}

int main(){
  ll T; cin>>T;
  for(ll i=0; i<T; i++){
    M.clear();
    cin>>N>>A>>B>>C>>D;
    cout<<dfs(N)<<endl;
  }
}

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

using namespace std;
using ll = long long;


int main()
{
    int a, b;
    string s;
    cin >> a >> b >> s;
    bool res = s[a] == '-';
    cout << (res && count(s.begin(), s.end(), '-') == 1 ? "Yes" : "No") << endl;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f[100005];
int main() {
  int n, x, dup = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    dup += (f[x]++ > 0);
  }
  cout << n - (dup - dup / 2) * 2 << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){


    int N;
    string s;

    cin >> N;
    cin >> s;

    int ans = 1;
    char tmp = s.at(0);

    for(int i=1; i<N; i++){

        if(tmp != s.at(i)){
            ans++;
            tmp = s.at(i);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    ll A[N], B[N];
    for(int i = 0; i < N; i++) cin >> A[i] >> B[i];

    ll ans = 0;
    for(int i = N - 1; i >= 0; i--) {
        A[i] += ans;
        if((A[i] % B[i]) == 0) continue;
        ans += B[i] * ((A[i] + B[i] - 1) / B[i]) - A[i];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;
vector<ll> v[n];
rep(i, n-1)
{
    ll a,b;
    cin >> a>>b;
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
}
ll ge[n]={};
ge[0]=1;
ge[n-1]=2;
queue<ll> f;
queue<ll> s;
ll ff=1 ,ss=1;
f.push(0);
s.push(n-1);
while(ff+ss<n){
    ll fs=f.size();
    ll sss=s.size();
    rep(i,fs){
        ll re;
        re=f.front();
        f.pop();
        rep(j,v[re].size()){
            if(ge[v[re][j]]==0){
                ge[v[re][j]]=1;
                ff++;
                f.push(v[re][j]);
                //cout << v[re][j] << endl;
            }
        }
    }
    rep(i,sss){
        ll re;
        re=s.front();
        s.pop();
        rep(j,v[re].size()){
            if(ge[v[re][j]]==0){
                ge[v[re][j]]=2;
                ss++;
                s.push(v[re][j]);
                //cout << v[re][j] << endl;
            }
        }
    }
    
}
if(ff>ss)cout << "Fennec" << endl;
else cout << "Snuke" << endl;

return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  string s; cin >> s;
  int n = s.size(), ans = 0;
  char c = s[0];
  for(int i = 1; i < n; i++){
    if(c != s[i]){
      ans++;
      c = s[i];
    }
  }
  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 512
N,M = map(int,input().split())
l = list(map(int,input().split()))
if M <= N:
    print('0')
else:
    l.sort()
    li = []
    for i in range(M-1):
        difference  = abs(l[i]-l[i+1])
        li.append(difference)
    li.sort()
    li.reverse()
    dif = 0
    for i in range(N-1):
        dif += li[i]
    print(l[M-1]-l[0]-dif)

Measured memory_bytes: 13968
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n;
char in[12][9];
int m,ans,id[256];
pi co[10];
bool use[10];

void rec(int c,int s)
{
	int big=s,sml=s;
	for(int i=c;i<m;i++)
	{
		if(co[i].first<0)sml+=9*co[i].first;
		else big+=9*co[i].first;
	}
	if(sml>0||big<0)return;
	
	if(c==m)
	{
		ans++; return;
	}
	rep(i,10)if(!use[i]&&!(co[c].second&&i==0))
	{
		use[i]=1;
		rec(c+1,s+co[c].first*i);
		use[i]=0;
	}
}
int main()
{
	while(scanf("%d",&n),n)
	{
		rep(i,n)scanf("%s",in[i]);
		rep(i,256)id[i]=-1;
		rep(i,10)co[i]=mp(0,0),use[i]=0;
		ans=m=0;
		
		rep(i,n)
		{
			int t=i<n-1?1:-1,len=strlen(in[i]);
			for(int j=len-1;j>=0;j--)
			{
				char c=in[i][j];
				if(id[c]<0)id[c]=m++;
				co[id[c]].first+=t;
				if(j==0&&len>1)co[id[c]].second=1;
				t*=10;
			}
		}
		sort(co,co+m,greater<pi>());
		
		rec(0,0);
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){

  int n;
  cin >> n;
  vector<ll> l(n),r(n);
  rep(i,n)cin >> l[i] >> r[i];
  sort(ALL(l));
  sort(ALL(r));
  if(n & 1){
    cout << r[(n)/2]-l[(n)/2]+1 << endl;
  }else{
    long double k = (r[(n-1)/2]+r[(n)/2])/2.0-(l[n/2]+l[(n-1)/2])/2.0;
    k *= 2;
    k = k+1;
    ll res = k;
    cout << res << endl;
  }




  




  return 0;
}


Measured memory_bytes: 6408
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int main() {
    reg ll n = read();
    for (reg int i = sqrt(n); i >= 1; i--) {
        if (n % i) continue;
        reg ll num = (i - 1) + (n / i - 1);
        cout << num << endl; exit(0);
    }
    return 0;
}


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

int main(){

    int a,b;
    cin >> a;
    cin >> b;

    string s;
    cin >> s;
    
    for(int i=0;i<a;i++){
        if(!(s[i] >= '0' && s[i] <= '9'))
        {
            cout << "No";
            return 0;
        }
    }
    if(s[a] != '-')
    {
        cout << "No";
        return 0;
    }
    for(int i=a+1;i<a+b+1;i++){
        if(!(s[i] >= '0' && s[i] <= '9'))
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x, y;
  int i, j;
  int result = -1;
  
  scanf("%d %d", &x, &y);
  
  for(i = 0; i <= x; i++){
    if(i * 2 + 4 * (x - i) == y){
      result = 1;
      break;
    }
  }
  
  if(result == 1)
    puts("Yes");
  else
    puts("No");
  
  return 0;
}

Measured memory_bytes: 1648
//
//  main.cpp
//  B - Golden Apple
//
//  Created by Hashizo on 2019/07/20.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef INT_MAX
#undef INT_MIN

#define INT_MAX	2147483647
#define INT_MIN	(-INT_MAX  -1)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REPLACE(s, f, t) regex_replace(s, regex(f), t)

int main(int argc, const char * argv[]) {
	int n,d;
	cin >> n >> d;

	int knshi = n / (2*d+1);
	
	if ((n % (2*d+1)) != 0) {
		knshi++;
	}
	
	
	cout << knshi << endl;
	return 0;
}


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

int main() {
  int X,A,B;
  cin >> X >> A >> B;
  if (A >= B) {
    cout << "delicious" << endl;
  }
  else if ((B - A) <= X) {
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        
        int S = scan.nextInt();
        int h = 3600;
        int m = 60;
        
                
        System.out.print(S/h +":");
        System.out.print((S%h)/m +":");
         System.out.println((S%h)%m);
                    
    }
}



Measured memory_bytes: 26168
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

pmt = list(itertools.permutations(range(1, N+1)))
pmtP = pmt.index(P)
pmtQ = pmt.index(Q)
print(abs(pmtP - pmtQ))

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

int main(){
    int N,M; cin>>N>>M;
    
    priority_queue<long long>  que;
    for( int i=0 ; i<N; i++){
        long long A; cin>>A; que.push(A);
        
    }
    
    for(int i=0; i<M; i++){
        long long t=que.top();  que.pop();
        que.push(t/2);
    }
    
    long long res=0;
    while(!que.empty()){
        res+=que.top();que.pop();
        
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

struct Point{
    double x, y;

    Point(double x = 0, double y = 0) : x(x), y(y) {}

    Point operator + (Point p){ return Point(x+p.x, y+p.y); }
    Point operator - (Point p){ return Point(x-p.x, y-p.y); }
    Point operator * (double a){ return Point(a*x, a*y); }
    Point operator / (double a){ return Point(x/a, y/a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x*x + y*y; }

    bool operator < (const Point &p) const{
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const{
        return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};

typedef Point Vector;


struct Segment{
    Point p1, p2;
};

typedef Segment Line;


double norm(Point a){
    return a.x * a.x + a.y * a.y;
}

double abs(Point a){
    return sqrt(norm(a));
}

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}


bool isOrthogonal(Vector a, Vector b){
    return equals(dot(a, b), 0.0);
}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
    return isOrthogonal(a1-a2, b1-b2);
}
bool isOrthogonal(Segment s1, Segment s2){
    return equals(dot(s1.p2-s1.p1, s2.p2-s2.p1), 0.0);
}

bool isParallel(Vector a, Vector b){
    return equals(cross(a, b), 0.0);
}
bool isParallel(Point a1, Point a2, Point b1, Point b2){
    return isParallel(a1-a2, b1-b2);
}
bool isParallel(Segment s1, Segment s2){
    return equals(cross(s1.p2-s1.p1, s2.p2-s2.p1), 0.0);
}


Point project(Segment s, Point p){
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / norm(base);
    return s.p1 + base * r;
}



int main(){
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    Segment s({Point(a,b), Point(c,d)});

    int q;
    cin >> q;

    while(q-- > 0){
        double x, y;
        cin >> x >> y;
        Point res = project(s, Point(x,y));
        cout << fixed << setprecision(12) << res.x << " " << res.y << endl;
    }

    return 0;
}


Measured memory_bytes: 3288
from sys import exit
# import copy
# import numpy as np
# from collections import deque
import collections

n, = map(int, input().split())
a = list(map(int, input().split()))
q, = map(int, input().split())
b = [list(map(int, input().split())) for _ in range(q)]

count = [0]*100000
ans = 0
for i in a:
    count[i - 1] += 1
    ans += i

for que in b:
    count[que[1] - 1] += count[que[0] - 1]
    ans += (que[1]-que[0])*count[que[0] - 1]
    count[que[0] - 1] = 0
    print(ans)


Measured memory_bytes: 96980
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    char name[20];
    int vl;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    ll A,B,C;
    scanf("%lld%lld%lld",&A,&B,&C);
    if(A%2==0 || B%2==0 ||C%2==0){
        printf("0");
        return 0;
    }else{
        ;
    }
    ll min1=0,min2=0,min3=0;
    ll total=0;
    total=A*B*C;
    min1=(total-A*B*(C/2));
    min2=(total-A*C*(B/2));
    min3=(total-C*B*(A/2));
    if(min1<min2 && min1<min3){
        printf("%lld",min1-A*B*(C/2));
        return 0;
    }else if(min2<min3){
        printf("%lld",min2-A*C*(B/2));
        return 0;
    }else{
        printf("%lld",min3-C*B*(A/2));
    }
}


Measured memory_bytes: 1660
using System;
using System.Linq;

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var z = read();
		var s = new int[z[0]].Select(_ => read()).ToArray();

		int h = z[1], a = s.Max(x => x[0]), c = 0;
		foreach (var x in s.Select(x => x[1]).Where(x => x > a).OrderBy(x => -x))
		{
			c++;
			if ((h -= x) <= 0) break;
		}
		Console.WriteLine(h <= 0 ? c : c + h / a + (h % a == 0 ? 0 : 1));
	}
}


Measured memory_bytes: 26176
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(void){
    string s,t;
    cin >> s >> t;
    int result=t.compare(0,s.size(),s);
    if(result==0){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 3592
import java.util.*;
public class Main {
    public static void main(String[] args){
        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] l = new int[N];
        int[] r = new int[N];
        for(int i=0;i<N;i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        // 出力
        int sum = 0;
        for(int i=0;i<N;i++){
            sum += r[i]-l[i]+1;
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 25576
#include<bits/stdc++.h>
using namespace std;
int a,b,ge,shi,qian,wan,ans;
inline int read()
{
	int num=0,flag=1;
	char c=getchar();
	for (;c<'0'||c>'9';c=getchar())
	if (c=='-') flag=-1;
	for (;c>='0'&&c<='9';c=getchar())
	num=(num<<3)+(num<<1)+c-48;
	return num*flag;
}
int main()
{
	a=read();
	b=read();
	for (int i=a;i<=b;++i)
	{
		ge=i%10;
		shi=i%100/10;
		qian=i/1000%10;
		wan=i/10000;
		if (ge==wan&&shi==qian) ans++;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256