akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <unordered_map>
#define int long long int
#define double long double
#define endl "\n"
#define PI 3.141592653589793238462643383279502884
#define sp(x)   setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define LCM(a,b)    (a*b)/__gcd(a,b)
#define all(v)  v.begin(),v.end()
#define alls(s,v)  s.begin(),s.end(),v
#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)
#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)
#define base ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define exit return 0;
#define is(x) cout << #x << " = " << x << endl;
using namespace std;
const int N=500000;
bool prime[N];
void sieve(){
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<100000000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<100000; i += p)
                prime[i] = false;
        }
    }
}
int nxt(){int x;cin >> x;return x;}
int32_t main(){
    base
    map<char,int>mp;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)mp[s[i]]++;
    bool flag=0;
    for(int i=0;i<s.size();i++)if(mp[s[i]]%2==1)flag=1;
    if(!flag)cout<<"Yes";
    else cout<<"No";
    exit
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int jud(int x){
	int a1=x%10,a2=(x/10)%10,a3=(x/100)%10;
	if (a1!=a2) return 0;
	if (a2!=a3) return 0;
	if (a1!=a3) return 0;
	return 1;
}
int main(){
	int n;
	scanf("%d",&n);
	for (int i=n;i<=999;i++){
	if (jud(i)) {printf("%d\n",i);return 0;}}
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    N, M = [int(x) for x in input().split()]
    # s, c = [], []
    num = list(range(10 ** (N-1), 10 ** N))
    if N == 1:
        num.append(0)
    sat = [True] * len(num)
    for i in range(M):
        s, c = [int(x) for x in input().split()]
        for j in range(len(num)):
            if not sat[j]:
                continue
            xx = num[j]
            x = num[j]
            keta = []
            for k in range(N):
                keta.append(x % 10)
                x //= 10
            if not c == keta[-s]:
                sat[j] = False

    ret = []
    for i in range(len(num)):
        if sat[i]:
            ret.append(num[i])

    return -1 if len(ret) == 0 else sorted(ret)[0]


if __name__ == "__main__":
    print(main())

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char , char> pcc;
#define pb push_back
#define mp make_pair
#define ft first
#define se second
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)


int main()
{
	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	ll n;
  	cin >> n;
  	ll arr[n+5][3];
  	ll dp[n+5][3];
  	for(ll i=1;i<=n;i++)
  	{
  		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
  		dp[i][0]=0;
  		dp[i][1]=0;
  		dp[i][2]=0;
  	}
  	dp[n][0]=arr[n][0];
  	dp[n][1]=arr[n][1];
  	dp[n][2]=arr[n][2];
  	for(ll i=n-1;i>0;i--)
  	{
  		for(ll j=0;j<3;j++)
  		{
  			for(ll k=0;k<3;k++)
  			{
  				if(j!=k)
  				{
  					dp[i][j]=max(arr[i][j]+dp[i+1][k],dp[i][j]);
  				}
  			}
  		}
  	}
  	cout << max(dp[1][0],max(dp[1][1],dp[1][2])) << endl;
	return 0;

}

Measured memory_bytes: 4992
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = (A + B) / 2;

		if (A % 2 == 0 && B % 2 == 0) {
			System.out.println(K);
		} else if (A % 2 == 1 && B % 2 == 1) {
			System.out.println(K);
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 21844
N,T=map(int,raw_input().split())
A=map(int,raw_input().split())
m=A[0]
maxDif=0
c=0
for i in xrange(1,len(A)):
  if A[i]-m>maxDif:
    maxDif=A[i]-m
    c=1
  elif A[i]-m==maxDif:
    c+=1
  m=min(m,A[i])
print c

Measured memory_bytes: 11304
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <unordered_map>

using namespace std;

#define ll long long
#define rep(i, n) for (i = 0; i < n; i++)

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a)
    cin >> i;
  unordered_map<int, int> mp;
  ll ans{};
  for (int i = 0; i < n; i++)
  {
    mp[a[i] + i]++;
  }
  for (int i = 0; i < n; i++)
  {
    ans += mp[i - a[i]];
  }
  cout << ans << endl;
}


Measured memory_bytes: 19340
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mini(vec) return *std::min_element(vec.begin(), vec.end());
#define maxi(vec) return *std::max_element(vec.begin(), vec.end());

int main() {
    string a;
    cin>>a;
    int sum = 700;
    rep(i,3){
        if(a.at(i)=='o'){
            sum+=100;
        }
    }
    cout<<sum<<endl;

}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
 
char a[3][4];
int main()
{
	int i,j;
	for(i=1;i<=2;i++)
	{
		for(j=1;j<=3;j++)
		{
			scanf(" %c",&a[i][j]);
		}
	}
	if(a[1][1] == a[2][3] && a[1][3] == a[2][1] && a[1][2] == a[2][2])
		printf("YES\n");
		else printf("NO\n");
 	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

  ll n, m;
  cin >> n >> m;

  if (n == m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

std::vector<long long int> enum_div(long long int n) {
    std::vector<long long int> ret;
    for(long long int 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);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

int main() {
    long long int n, ans = 0;
    cin >> n;
    if(n == 1) {
        cout << ans << "\n";
    } else {
        vector<long long int> vec = enum_div(n);
        sort(vec.begin(), vec.end());
        for(long long int i = 1; i < vec.size(); ++i) {
            if(n/(vec[i]-1) == n%(vec[i]-1)) {
                ans += vec[i]-1;
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int a=-1,b=-1,c=-1,d;
  for(int i=0;i<10;i++){
    cin>>d;
    if(d>a){
      c=b;
      b=a;
      a=d;
    }else if(d>b){
      c=b;
      b=d;
    }else if(d>c){
      c=d;
    }
  }
  cout<<a<<endl<<b<<endl<<c<<endl;
  return(0);
}

Measured memory_bytes: 3104
def main():
    n,a,b=map(int,input().split())
    mod=10**9+7
    c,d=1,1
    for i in range(1,a+1):
        c=c*pow(i,mod-2,mod)%mod
        c=c*(i+n-a)%mod
    for i in range(1,b+1):
        d=d*pow(i,mod-2,mod)%mod
        d=d*(i+n-b)%mod
    print((pow(2,n,mod)-c-d-1)%mod)
main()

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

int main() {
  int X,N;
  cin >> X >> N;
  set<int>data;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    data.insert(x);
  }
  for(int i=0;i<1000;i++){
    if(!data.count(X-i)){
      cout << X-i;
      return 0;
    }
    if(!data.count(X+i)){
      cout << X+i;
      return 0;
    }
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    int K;
    cin >> K;
    if(K % 2 == 0){
        cout << -1 << endl;
        return 0;
    }
    if(K % 7 == 0){
        K /= 7;
    }
    if(K == 1){
        cout << 1 << endl;
        return 0;
    }
    int mod_all = 1;
    int past_mod = 1;
    for(int i = 2; i <= K; i++){
        int mod = past_mod * 10 % K;
        if((mod_all + mod) % K == 0){
            cout << i << endl;
            return 0;
        }
        past_mod = mod;
        mod_all = (mod_all + mod) % K;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3556
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(" ".join(map(str, A)))


Measured memory_bytes: 5596
#include<stdio.h>

#define LIM 100000
#define EX 2000000000

typedef struct card{
  char pic;
  int num;
}card;

void merge(card *,int,int,int,int);
void mergesort(card *,int,int,int);
int partition(card *,int,int,int);
void quicksort(card *,int,int,int);

card Lef[LIM/2+2],Rig[LIM/2+2];

void merge(card *A,int n,int left,int mid,int right)
{
  int i,j,k;
  int a = mid -left;
  int b = right - mid;
  for(i=0;i<a;i++)
    Lef[i] = A[left+i];
  for(i=0;i<b;i++)
    Rig[i] = A[mid+i];
  Lef[a].num = Rig[b].num = EX;
  i = j = 0;
  for(k = left;k<right;k++) {
    if(Lef[i].num <= Rig[j].num) {
      A[k] = Lef[i++];
    }else{
      A[k] = Rig[j++];
    }
  }
}

void mergesort(card *A,int n,int left,int right)
{
  int mid;
  if(left+1 < right) {
    mid = (left + right) / 2;
    mergesort(A,n,left,mid);
    mergesort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(card *A,int n,int p,int r)
{
  int i,j;
  card t,x;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j].num <= x.num) {
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;
}

void quicksort(card *A,int n,int p,int r)
{
  int x;
  if(p < r) {
    x = partition(A,n,p,r);
    quicksort(A,n,p,x-1);
    quicksort(A,n,x+1,r);
  }
}

int main()
{
  int n,N,i;
  card A[LIM],B[LIM];
  char C[10];
  int judge = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++) {
    scanf("%s%d",C,&N);
    A[i].pic = B[i].pic = C[0];
    A[i].num = B[i].num = N;
  }

  mergesort(A,n,0,n);
  quicksort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    if(A[i].pic != B[i].pic)
      judge = 0;
  }

  if(judge == 1)
    printf("Stable\n");
  else
    printf("Not stable\n");

  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].pic,B[i].num);
  }

  return 0;
}



Measured memory_bytes: 4200
a,b,c,d=map(int,input().split())
# TAKA hp A atk B
# AOKI hp C atk D
# TAKA -> AOKI -> TAKA -> ...
mode = 0
cnt = 0
while True:
	mode ^= 1
	if mode == 0:
		a = a - d
		if a <= 0:
			print("No")
			break
	else:
		c = c - b
		if c <= 0:
			print("Yes")
			break

Measured memory_bytes: 9176
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    using namespace std;
     
    int main() {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        cout << a[n-1]-a[0] <<endl;
        return 0;
    }

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc126B
{
    class Program
    {
        static void Main(string[] args)
        {
            string inp = Console.ReadLine();
            int a = Convert.ToInt32(inp.Substring(0, 2));
            int b = Convert.ToInt32(inp.Substring(2, 2));
            bool atrue = false;
            bool btrue = false;
            int count = 0;

            if (a <= 12 & a != 0)
            {
                atrue = true;
                count++;
            }
            if (b <= 12 & b != 0)
            {
                btrue = true;
                count++;
            }

            if (count == 2)
            {
                Console.WriteLine("AMBIGUOUS");
            }
            if (count == 0)
            {
                Console.WriteLine("NA");
            }
            if (count == 1)
            {
                if (atrue)
                {
                    Console.WriteLine("MMYY");
                }
                else if (btrue)
                {
                    Console.WriteLine("YYMM");
                }
            }
            Console.ReadKey();
        }
    }
}




Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main(void) {
  int n, x;
  while(cin >> n >> x && (n != 0 || x != 0)) {
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= n; j++) {
        for(int k = 1; k <= n; k++) {
          if(i < j && j < k && i + j + k == x) {
            cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main() {
   long n,x,sum=0;
   cin>>n>>x;
   vector<long> v(n);
   for(long i=0;i<n;i++)
   {
    cin>>v[i];   
   }
   sort(v.begin(),v.end());
   for(long i=0;i<n;i++)
   {
    sum+=v[i];   
   }
   
   long p=(x-sum)/v[0];
   cout<<p+n<<"\n";
	return 0;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;

string a;
vector <string> v={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main()
{
	cin>>a;
	int idx=0;
	while(idx<v.size() and v[idx]!=a) idx++;

	int ans=0;
	idx=(idx+1)%v.size();
	while(idx!=0) idx=(idx+1)%v.size(),ans++;
	cout<<ans+1;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int[][] arr = new int[4][13];
		 String[] mark = {"S","H","C","D"};
		for(int i=0; i<4; i++) {
			for(int j=0; j<13; j++){
				arr[i][j] = 0;
			}
		}
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int j=0; j<n; j++){
			String S = scan.next();
			int number = scan.nextInt() - 1;
			
			if(S.equals("S")) {arr[0][number]=1;}
			else if(S.equals("H")) {arr[1][number]=1;}
			else if(S.equals("C")) {arr[2][number]=1;}
			else {arr[3][number]=1;}
		}
		for(int i=0; i<4; i++) {
			for(int j=0; j<13; j++){
				if(arr[i][j] == 0) {System.out.println(mark[i] + " " + (j+1));}
			}
		}
	}
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	while (1) {
		int n,m,k;
		vector<vector<int> > p;
		vector<int> l;
		cin>>n;
		if(!n) return 0;
		p.resize(n);
		for (int i = 0; i < n; i++) {
			cin>>m;
			for (int j = 0; j <m ; j++) {
				int d;
				cin>>d;
				p[i].push_back(d);
			}
		}
		cin>>k;
		for (int i = 0;i < k; i++) {
			int d;
			cin>>d;
			l.push_back(d);
		}

		int o=0;
		int r=0;
		for (int i = 0; i<n; i++) {
			int q=0;
			for(int j=0;j<k;j++){
				if(find(p[i].begin(),p[i].end(),l[j])==p[i].end())
					break;
				q++;
			}
			if(q==k){
				o++;
				r=i;
			}
		}
		if(o==1) cout<<r+1<<endl;
		else cout<<"-1"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  vector<ll> a(2), c(2);
  rep(i, 2) cin >> a[i];
  rep(i, 2) cin >> c[i];
  ll ans = 0;
  if (a[0] >=0 || c[0] >= 0){
    ans = a[1]*c[1];
    if (ans < 0) {
      ans = max(a[0]*c[1], a[1]*c[0]);
    }
  } else {
    ll x = a[0]*c[0];
    ll y = a[1]*c[1];
    ans = max(x, y);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    double T, X;
    cin >> T >> X;
    cout << T / X << endl;
    return 0;
}

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

typedef complex<double> P;

const double eps = 1e-8;

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

bool heikou(P a, P b) {
  return equals(cross(a,b), 0.0);
}

P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b, b1 - a1) / cross(b, a);
}

int ccw(P p, P a, P b) {
  a -= p;
  b -= p;
  if(cross(a,b) > eps) return 1;
  if(cross(a,b) < -eps) return -1;
  if(dot(a,b) < -eps) return 2;
  if(norm(b)-norm(a) > eps) return -2;
  return 0;
}

double getDistanceLP(P s1, P s2, P p) {
  return abs(cross(s2-s1, p-s1))/abs(s2-s1);
}

double W, H, N, R;
vector<P> S, T;

P getP(P a, P b, P c, P d) {
  P s = a - b;
  s /= abs(s);
  P t = d - c;
  t /= abs(t);
  P M = getCrossP(a,b,c,d);
  P st = s + t;
  double H = abs(cross(s, t));
  return M + st * R / H;
}

int main() {
  while(cin >> W >> H >> N >> R) {
    if(W == 0 && H == 0 && N == 0 && R == 0) break;
    S.clear(); T.clear();
    for(int i = 0; i < N; ++i) {
      P a, b;
      double t;
      cin >> a.real() >> a.imag() >> b.real() >> b.imag() >> t;
      P base = b - a;
      P n(-base.imag(), base.real());
      n /= abs(n);
      S.push_back(a + n*t);
      T.push_back(b + n*t);
      S.push_back(b - n*t);
      T.push_back(a - n*t);
    }
    S.push_back(P(0,0));
    T.push_back(P(W,0));
    S.push_back(P(W,0));
    T.push_back(P(W,H));
    S.push_back(P(W,H));
    T.push_back(P(0,H));
    S.push_back(P(0,H));
    T.push_back(P(0,0));
    vector<P> ps;
    for(int i = 0; i < S.size(); ++i) {
      for(int j = i+1; j < S.size(); ++j) {
	if(heikou(T[i]-S[i], T[j]-S[j])) continue;
	ps.push_back(getP(S[i],T[i],S[j],T[j]));
      }
    }

    bool ans = false;
    for(int k = 0; k < ps.size(); ++k) {
      bool flag = true;
      for(int i = 0; i < 2*N; i += 2) {
	bool a, b;
	{
	  double d = getDistanceLP(S[i],T[i],ps[k]);
	  a = (ccw(S[i],T[i],ps[k]) == 1 && (equals(d, R) || d > R));
	}
	{
	  double d = getDistanceLP(S[i+1],T[i+1],ps[k]);
	  b = (ccw(S[i+1],T[i+1],ps[k]) == 1 && (equals(d, R) || d > R));
	}
	if(!a && !b) {
	  flag = false;
	  break;
	}
      }
      for(int i = 2*N; i < S.size(); ++i) {
	double d = getDistanceLP(S[i],T[i],ps[k]);
	bool a = (ccw(S[i],T[i],ps[k]) == 1 && (equals(d, R) || d > R));
	if(!a) {
	  flag = false;
	  break;
	}
      }
      if(flag) {
	ans = true;
	break;
      }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1896
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    LL n;cin>>n;

    LL keta=100;

    for(LL i=1;i<sqrt(n)+10;i++){
        if(n%i != 0){
            continue;
        }

        LL j = n/i;
        //dump(i)
        //dump(j)
        LL k = 0;
        while(j>0){
            k++;
            j/=10;
        }
        keta = min(keta,k);
        //keta = k;
    }
    cout<<keta<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int  main(){
    string s,t;
    cin >> s >>t;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]==t[i]){
            ans +=1;
        }
    }
    cout<<ans;
}

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

int main()
{
	string s;
	cin>>s;
	
	
		if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes"<<endl;
		
		else
		cout<<"No"<<endl;
		
	
	
	return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n, c;
  cin >> n >> c;
  vii d(c, vi(c));
  rep (i, c) {
    rep (j, c) {
      cin >> d[i][j];
    }
  }
  vii a(n, vi(n));
  rep (i, n) {
    rep (j, n) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  vll sum(3, vl(c));
  rep (j, c) {
    rep (k, n) {
      rep (l, n) {
        int i = (k + l) % 3;
        sum[i][j] += d[a[k][l]][j];
      }
    }
  }
  ll ans = INF;
  rep (i, c) {
    rep (j, c) {
      rep (k, c) {
        if (i == j || j == k || k == i) continue;
        chmin(ans, sum[0][i] + sum[1][j] + sum[2][k]);
      }
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final List<Long> list = IntStream.range(0, n)
            .mapToObj(i -> scanner.nextLong())
            .sorted(Comparator.reverseOrder())
            .collect(Collectors.toList());

        final Deque<Long> queue = new ArrayDeque<>();
        queue.add(list.get(0));
        queue.add(list.get(1));
        long sum = list.get(0);
        final Deque<Long> tmp = new ArrayDeque<>();
        for (int i = 2; i < n; i++) {
            if (queue.isEmpty()) {
                queue.addAll(tmp);
                tmp.clear();
            }

            final long a = queue.pollFirst();
            final long b = queue.isEmpty() ? list.get(0) : queue.peekFirst();
            sum += Math.min(a, b);
            final long value = list.get(i);
            tmp.add(a);
            tmp.add(value);
        }

        System.out.println(sum);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

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

using namespace std;
using vi=vector<int>;
using ull=unsigned long long;

typedef long long ll;

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

	int n, k;

	cin >> n >> k;

	cout << (n - k + 1) << "\n";
    
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		String a = reader.next();
		String b = reader.next();
		String c = reader.next();
		solver(a, b, c);
	}

	public static void solver(String a, String b, String c) {
		int ita = 0;
		int itb = 0;
		int itc = 0;
		char player = 'a';
		while (true) {
			switch (player) {
			case 'a':
				if (ita == a.length()) {
					System.out.println("A");
					return;
				}
				player = a.charAt(ita);
				ita++;
				break;
			case 'b':
				if (itb == b.length()) {
					System.out.println("B");
					return;
				}
				player = b.charAt(itb);
				itb++;
				break;
			case 'c':
				if (itc == c.length()) {
					System.out.println("C");
					return;
				}
				player = c.charAt(itc);
				itc++;
				break;
			}
		}
	}

	// Read Class
	static class FS {
		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() { return hasNextByte() ? buffer[ptr++] : -1;}
		private 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 int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

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

int main( void ) {
    
    int a, b, c;
    cin >> a >> b >> c;
    
    if( a > b ) swap( a, b );
    if( a > b ) swap( a, c );
    if( b > c ) swap( b, c );
    
    cout << 3 - ( a == b || b == c ) - ( a == c ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll M;
ll mod_power(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        return mod_power((x * x) % M, n / 2);
    } else {
        return (mod_power((x * x) % M, n / 2) * x) % M;
    }
}

int main() {
    cin >> M;
    int m = 0;
    rep(i, 1000001) {
        m += (7 * mod_power(10, i));
        m %= M;
        if (m == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	const double EPS = 1e-10;
	while (true) {
		ll n; cin >> n;
		if (n == 0) break;

		vd px(n), py(n), pz(n), vx(n), vy(n), vz(n), r(n), vr(n);
		REP(i, n) {
			cin >> px[i] >> py[i] >> pz[i] >> vx[i] >> vy[i] >> vz[i] >> r[i] >> vr[i];
		}

		vector<pair<double, ll>> n_v_time(n);
		REP(i, n) n_v_time[i].first = r[i] / vr[i];
		REP(i, n) n_v_time[i].second = i;
		
		auto n_v_time_sorted = n_v_time;
		sort(ALL(n_v_time_sorted)); reverse(ALL(n_v_time_sorted));

		vb vanished(n, false);
		vd v_time(n);
		while (!n_v_time_sorted.empty()) {
			vector<pair<double, pair<ll, ll>>> collision_time;
			REP(i, n) if (!vanished[i]) REP(j, n) if (!vanished[j] && i != j) {
				double a = pow(vx[i] - vx[j], 2) + pow(vy[i] - vy[j], 2) + pow(vz[i] - vz[j], 2) - pow(vr[i] + vr[j], 2);
				double b = 2.0 * ((px[i] - px[j]) * (vx[i] - vx[j]) + (py[i] - py[j]) * (vy[i] - vy[j]) + (pz[i] - pz[j]) * (vz[i] - vz[j]) + (r[i] + r[j]) * (vr[i] + vr[j]));
				double c = pow(px[i] - px[j], 2) + pow(py[i] - py[j], 2) + pow(pz[i] - pz[j], 2) - pow(r[i] + r[j], 2);
				if (b * b - 4 * a * c < 0) continue;
				if (-EPS < a && a < EPS) continue;
				double t1 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
				double t2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
				double t = [&] {
					if (t1 > 0 && t2 > 0) return t1 < t2 ? t1 : t2;
					return t1 < 0 ? t2 : t1;
				}();
				if (t < EPS) continue;
				if (t > n_v_time[i].first || t > n_v_time[j].first) continue;
				collision_time.push_back({ t, {i, j} });
			}
			sort(ALL(collision_time));

			auto x = n_v_time_sorted.back();
			if (collision_time.empty() || collision_time.front().first > x.first) {
				vanished[x.second] = true;
				v_time[x.second] = x.first;
				n_v_time_sorted.pop_back();
			} else {
				auto y = collision_time.front();
				vanished[y.second.first] = true;
				vanished[y.second.second] = true;
				v_time[y.second.first] = y.first;
				v_time[y.second.second] = y.first;
				n_v_time_sorted.erase(remove(ALL(n_v_time_sorted), n_v_time[y.second.first]), n_v_time_sorted.end());
				n_v_time_sorted.erase(remove(ALL(n_v_time_sorted), n_v_time[y.second.second]), n_v_time_sorted.end());
			}
		}
		REP(i, n) {
			cout << v_time[i] << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 3392
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    if (A % 2 == 0 || B % 2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define EPS 1e-8
#define INF 0x3f3f3f3f3
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;

const ll mod =  998244353;
/*
ll nop = 100;
vi primes(nop+1,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}
*/
ll gcd(ll a,ll b){    //a larger, b smaller
    if(b>a) swap(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}

ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans*num)%mod;
        }
        num = (num*num)%mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    return mexp(a,mod-2);
}


void solve() {
    ll n,a,b;
    cin>>a>>b>>n;
    if(n < b) {
        cout<<(a*n)/b<<endl;
    }
    else {
        cout<<((b-1)*a)/b<<endl;
    }

}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t){
        solve();
        //cout<<"Case #"<<T<<": "<< <<"\n";
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int m;
    cin >> m;

    ll ds = 0, cs = 0;
    REP(i, m){
        ll d, c;
        cin >> d >> c;
        ds += d * c;
        cs += c;
    }

    cout << max(1LL, cs - 1 + Div(ds, 9LL) - 1) << 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 N = sc.nextLine();
		
		for (int i = N.length() - 1; i > 0; i--) {
			if (i % 2 == 1) {
				continue;
			}
			
			String sub = N.substring(0, i);
			if (sub.substring(0, i / 2).equals(sub.substring(i / 2, i))) {
				System.out.println(i);
				return;
			}
		}
	}
}

Measured memory_bytes: 23636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=(1LL<<31)-1;
const ll MOD=1e9+7;

struct segtree{
    vector<ll> dat;
    ll size;
    segtree(int n):dat(2*n-1,0),size(n){};
    void add(int i,ll x){
        i+=this->size-1;
        dat[i]+=x;
        while(i>0){
            i=(i-1)/2;
            dat[i]+=x;
        }
    }
    ll getSum(int s,int t){
        return getsumsub(s,t,0,0,this->size);
    }
    ll getsumsub(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return 0;
        else if(a<=l&&r<=b) return dat[k];
        else{
            ll v1=getsumsub(a,b,k*2+1,l,(l+r)/2);
            ll v2=getsumsub(a,b,k*2+2,(l+r)/2,r);
            return v1+v2;
        }
    }
};
int main(){
    int n,q;cin>>n>>q;
    int N=1;
    while(N<n) N*=2;
    segtree st(N);
    while(q--){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0) st.add(x-1,y);
        else cout<<st.getSum(x-1,y)<<endl;
    }
    return 0;
}


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

int n, p;
string s;
int main() {
  cin >> n >> p >> s;
  if (p == 2 || p == 5) {
    long sum = 0;
    for (int i = 0; i < n; ++i) {
      if ((s[i] - '0') % p == 0) {
        sum += i + 1;
      }
    }
    cout << sum << endl;
  } else {
    long sum = 0;
    map<int, int> mp;
    ++mp[0];
    long now = 0;
    long base = 1;
    for (int i = n - 1; i >= 0; --i) {
      now = (now + (s[i] - '0') * base) % p;
      base = base * 10 % p;
      sum += mp[now];
      ++mp[now];
    }
    cout << sum << endl;
  }
}


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

int main(){
  int n,k;
  cin>>n>>k;
  ll ans=0;
  ll i=k;
  while(i<n+2){
    ans+=(2*n-i+1)*i/2-i*(i-1)/2+1;
    ans%=mod;
    i++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define P ((ll)1e9+7)
using namespace std;

int n;
char s[MAX];
ll f[MAX][15];

int main()
{
	scanf("%s", s+1);
	n = strlen(s+1);
	f[0][0] = 1;
	for(int i = 1; i <= n; i++){
		if(s[i] != '?'){
			for(int j = 0; j < 13; j++){
				(f[i][(j*10+s[i]-'0')%13] += f[i-1][j]) %= P;
			}
			continue;
		}
		for(int k = 0; k <= 9; k++){
			for(int j = 0; j < 13; j++){
				(f[i][(j*10+k)%13] += f[i-1][j]) %= P;
			}
		}
	}
	cout << f[n][5] << endl;
	
	return 0;
}

Measured memory_bytes: 12032
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位



signed main() {
	int N, asum = 0, bsum = 0;
	vector<int> A, B;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		asum += t;
		A.push_back(t);
	}
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		bsum += t;
		B.push_back(t);
	}
	if (asum < bsum) {
		cout << "-1\n";
		return 0;
	}
	vector<int> plus, minus;
	for (int i = 0; i < N; i++) {
		int sabun = A[i] - B[i];
		if (sabun > 0) plus.push_back(sabun);
		else if (sabun < 0) minus.push_back(sabun);
	}
	sort(plus.begin(), plus.end());
	reverse(plus.begin(), plus.end());

	int minSum = 0, ans = 0;
	for (int num : minus) {
		minSum += num;
		ans++;
	}
	
	for (int num : plus) {
		if (minSum >= 0) break;
		minSum += num;
		ans++;
	}
	
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 3316
/*input
6
30 10 60 10 60 50
*/
/**
    Author: Kristopher Paul
    Date Created: 11-01-2020
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

//Uncomment for File I/O
/*
#define cin fin
#define cout fout

ifstream fin("input.in");
ofstream fout("input.out");
*/

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    int arr[n];
    FOR(i,0,n){
        cin >> arr[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    FOR(i,2,n){
        dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    cout << dp[n-1] << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 500010
#define ls (x<<1)
#define rs (x<<1|1)
#define RG register
#define inf 0x3f3f3f3f
using namespace std;
vector<int> son[N];
priority_queue<int> que;
int K,n,tmp,val,goal,p[N],q[N],du[N],tr[N<<2];
inline int query(RG int x,RG int l,RG int r,RG int ll,RG int rr){
    if(l==ll&&r==rr) return tr[x];
    RG int mid=(l+r)>>1;
    if(rr<=mid) return query(ls,l,mid,ll,rr);
    if(ll>mid) return query(rs,mid+1,r,ll,rr);
    return min(query(ls,l,mid,ll,mid),query(rs,mid+1,r,mid+1,rr));
}
inline void add(RG int x,RG int l,RG int r){
    if(l==r){tr[x]=val;return;}
    RG int mid=(l+r)>>1;
    if(goal<=mid) add(ls,l,mid);
    else          add(rs,mid+1,r);
    tr[x]=min(tr[ls],tr[rs]);
}
int main(){
    scanf("%d%d",&n,&K);
    memset(tr,inf,sizeof(tr));
    for (RG int i=1;i<=n;++i){
	scanf("%d",p+i);
	q[p[i]]=i;
    }
    for (RG int i=n;i;--i){
	tmp=query(1,1,n,max(1,q[i]-K+1),q[i]);
	if(tmp<inf) son[q[tmp]].push_back(q[i]),++du[q[i]];
	tmp=query(1,1,n,q[i],min(n,q[i]+K-1));
	if(tmp<inf) son[q[tmp]].push_back(q[i]),++du[q[i]];
	val=i;goal=q[i];add(1,1,n);
    }
    for (RG int i=1;i<=n;++i)
	if(!du[i])
	    que.push(i);
    for (RG int i=n;i;--i){
	p[i]=que.top();que.pop();
	for (RG int j=0;j<(int)son[p[i]].size();++j)
	    if(!--du[son[p[i]][j]])
		que.push(son[p[i]][j]);
    }
    for (RG int i=1;i<=n;++i)
	q[p[i]]=i;
    for (RG int i=1;i<=n;++i)
	printf("%d\n",q[i]);
    return 0;
}

Measured memory_bytes: 45056