akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
 
using namespace std;
 
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
 
typedef vector<int> vi;
typedef pair<int,int> pii;
 
int main(void) {
  int i,j;
  string s;
  cin>>s;
  vi v(3,0);
  rep(i,s.size()){
    if(s[i]=='a')v[0]++;
    if(s[i]=='b')v[1]++;
    if(s[i]=='c')v[2]++;
  }
  sort(all(v));
  if(v[2]-v[0]<=1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
const int inf=1<<30;
int i,j,k,m,n;
int a[200000],s1[200000],s2[200000];
char s[200000];
int main()
{
	scanf("%d",&n);
	scanf("%s",&s);
	memset(s1,0,sizeof(s1));
	for(int i=0;i<n;i++) 
	{
		if(s[i]=='.') a[i+1]=0,s1[i+2]=s1[i+1];
		else a[i+1]=1,s1[i+2]=s1[i+1]+1;
	}
	s2[n+1]=0;
	for(int i=n;i>=1;i--) 
	{
		if(!a[i]) 
			s2[i]=s2[i+1]+1;
		else
		    s2[i]=s2[i+1];
	}
	int ans=inf;
	for(int i=1;i<=n+1;i++)
	{
		if(s1[i]+s2[i]<ans) ans=s1[i]+s2[i];
	}
	printf("%d",ans);
}

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

int main(){
  string s;
  std::cin >> s;
  int n = s.length();
  if(n == 1){
    std::cout << 0 << std::endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    vector<string> substr;
    vector<int> alpha(26, 0);
    for (int j = 0; j < n - i + 1; j++) {
      substr.push_back(s.substr(j, i));
    }
    for (int j = 0; j < substr.size(); j++) {
      vector<bool> flag(26, false);
      for (int k = 0; k < i; k++) {
        flag[substr[j][k] - 'a'] = true;
      }
      for (int k = 0; k < 26; k++) {
        alpha[k] += flag[k];
      }
    }
    for (int j = 0; j < 26; j++) {
      if(alpha[j] == n - i + 1){
        std::cout << i - 1 << std::endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	vector<vector<int>> vec(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> vec[i][j];
		}
	}
	
	vector<int> a(3);
	vector<int> b(3);
	a[0] = 0;
	for (int i = 0; i < 3; i++) b[i] = vec[0][i] - a[0];
	for (int i = 1; i < 3; i++) a[i] = vec[i][0] - b[0];
	
	int count = 0;
	bool is_ok = true;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (vec[i][j] == a[i] + b[j]) count++;
			else is_ok = false;
		}
	}
	if (is_ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main(){ 
  string S,T;
  cin >> S >> T;
  int N = S.size();
  
 for(int i =0; i<N; i++){ 
  if(1+ S.size() != T.size() || S.at(i) != T.at(i)){
  cout << "No" << endl;
    break;
  }
   if(i==N-1){
   cout << "Yes" << endl;
   }
 }

 }

Measured memory_bytes: 3632
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();
    boolean[][] taiou = new boolean[26][26];
    int[] countS =new int[26];
    int[] countT =new int[26];
    int check =0;
    for (int i =0; i<S.length(); i++) {
      taiou[(int)S.charAt(i) - 'a'][(int)T.charAt(i) - 'a'] = true;
    }
    for (int i =0; i<26; i++) {
      for (int j =0; j<26; j++) {
        if (taiou[i][j]) countS[i]++;
        if (taiou[j][i]) countT[i]++;
      }
      if (countS[i] >= 2) check++; 
      if (countT[i] >= 2) check++;
    }
    if (check >= 1) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 41324
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderSucks
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<double> nbrs = Console.ReadLine().Split().ToList().ConvertAll(double.Parse);
            double sum = 0;
            bool a = false;
            for (int i = 0; i < nbrs.Count;)
            {
                sum += nbrs.Min();
                
                if (a)
                {
                    sum /= 2;
                }
                nbrs.Remove(nbrs.Min());
                a = true;
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13280
n = int(input())
l = list(map(int,input().split()))
count = 0
if l[0] == 1:
  l[1] = l[0]
  count += 1
for i in range(1,n):
  if l[i] == i+1:
    if i != n-1:
      if l[i+1] == i+2:
        l[i],l[i+1] = l[i+1],l[i]
        i+=1
    else:
      l[i] = l[i-1]
    count += 1
print(count)

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

int main() {

	int n; cin >> n;
	map<string, int> mp;
	bool can = true;
	for (int i = 0; i < n; i++) {
		char last;
		string w; cin >> w;
		mp[w]++;
		if (i != 0 && last != w[0]) {
			can = false;
		}
		last = w.back();
	}
	for (auto u : mp) {
		if (2 <= u.second) can = false;
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> num(N * 3);
    rep(i,N * 3)cin >> num[i];
    sort(all(num));
    ll ans = 0;
    for(ll i = 0;i < N;i++){
        ans += num[N * 3 - 2 - i * 2];
    }
    cout << ans << endl;
}
//7 3 4


Measured memory_bytes: 5576
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    let x: Vec<i32> = it.map(|s| s.parse().unwrap()).collect();
    let mut ans = std::i32::MAX;
    for y in 0..101 {
        let mut sum = 0;
        for &x in x.iter() {
            let d = x - y;
            sum += d * d;
        }
        ans = std::cmp::min(ans, sum);
    }
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
using namespace std;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
bool find(string s,int a,int b,int c){
  for(int i = a;i<b;i++){
    if(s[i]==alpha[c]) return true;
  }
  return false;
}
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans,tem;
  ans = 0;
  for(int i = 1;i<n-1;i++){
    tem = 0;
    for(int j = 0;j<alpha.size();j++){
      if(find(s,0,i,j) && find(s,i,n,j)) tem++;
    }
    ans = max(ans,tem);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] inputDays = br.readLine().split(" ");
            int fineDayBeforeOfbestByDate = Integer.parseInt(inputDays[0]);
            int boughtDayBeforeOfBestByDate = Integer.parseInt(inputDays[1]);
            int ateDayAfterOfBoughtDay = Integer.parseInt(inputDays[2]);
            
            String statusOfFood = "";
            if (boughtDayBeforeOfBestByDate - ateDayAfterOfBoughtDay >= 0) {
                statusOfFood = "delicious";
            } else if (boughtDayBeforeOfBestByDate - ateDayAfterOfBoughtDay + fineDayBeforeOfbestByDate >= 0) {
                statusOfFood = "safe";
            } else {
                statusOfFood = "dangerous";
            }

            System.out.println(statusOfFood);

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 25044
import itertools

n=int(input())
a=list(map(int,input().split()))
s=[0]+list(itertools.accumulate(a))

dp=[[10**20]*(n+1) for _ in range(n)]
for l in range(n):
    dp[l][l+1]=0
for d in range(2,n+1): 
    for k in range(1,d):
        for i in range(n-d+1):
            j=i+d
            S=s[j]-s[i]
            dp[i][j]=min(dp[i][i+k]+dp[i+k][j]+S,dp[i][j])

print(dp[0][n])

Measured memory_bytes: 44064
import sys
import time
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    X = int(readline())
    r = int(X**0.5)
    ans = 1
    for i in range(r,0,-1):
        tmp = i
        if i ==1:
            break
        while tmp<=X:
            ans = max(ans,tmp)
            tmp *=i
    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
# coding: utf-8

def pHead(S):
    if S[0] != "A": return False
    return True

def getMid(S):
    return S[2:-1]

def pMid(S):
    mid = getMid(S)
    if "C" not in mid: return False
    if mid.count("C") > 1: return False
    return True

def getRest(S):
    mid = getMid(S)
    tmp = S[1] + mid.replace("C", "") + S[-1]
    return tmp

def solve(S):
    if not pHead(S):
        return "WA"
    if not pMid(S):
        return "WA"
    if not getRest(S).islower():
        return "WA"
    return "AC"

if __name__ == "__main__":
    S = input()
    print(solve(S))


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
long long a[2000100];
int main()
{
	long long n,c=0,c1=0;
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		c+=a[i];
	}
	long long mn=c;
	for(long long i=1;i<=n;i++)
	{
		c1=c1+a[i];
		if(abs(c1-(c-c1))<=mn)
		{
			mn=abs(c1-(c-c1));
		}
	}
	printf("%lld",mn);
	return 0;
}


Measured memory_bytes: 1664
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	int n;
	
	while(cin>>n,n!=0){
		vector<long long> p(n);
		vector<bool> a(1000000);
		for(int i=0;i<n;i++){
			cin>>p[i];
			a[p[i]]=true;
		}
		long long s=p[0];
		bool b=false;
		for(long long i=s;i<=p[n-1]+1;i++){
			if(!a[i]&&s!=-1){
				long long f=i-1;
				if(!b){
				if(s==f){
					cout<<s;
				}
				else{
					cout<<s<<"-"<<f;
				}
					b=true;
				}
				else{
					if(s==f){
					cout<<" "<<s;
				}
				else{
					cout<<" "<<s<<"-"<<f;
				}
				}
				s=-1;
			}
			else if(a[i]&&s==-1)
				s=i;
		}
		
		cout<<endl;
	}
	
}

Measured memory_bytes: 1324
s = input()
s = s + "R"
tmp = []
rcnt = 0
lcnt = 0
for i in range(len(s)):
  if s[i] == "R" :
    if lcnt >= 1:
      for j in range(lcnt):
        if j == 0:
          tmp.append(lcnt)
        else:
          tmp.append(0)
      lcnt = 0
    rcnt += 1
  else:
    if rcnt >= 1:
      for j in range(rcnt):
        if j == rcnt-1:
          tmp.append(rcnt)
        else:
          tmp.append(0)
      rcnt = 0
    lcnt += 1

ans = []
skip = False
for i in range(len(tmp)):
  if tmp[i] == 0:
    ans.append(0)
  else:
    if skip == False:
      ans.append(tmp[i]//2 + tmp[i]%2 + tmp[i+1]//2)
      ans.append(tmp[i]//2 + tmp[i+1]//2 + tmp[i+1]%2)
      skip = True
    else:
      skip = False
      continue
print(" ".join(map(str, ans)))

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
int n,w;
int arr[100][2];
long long dp[100][100000];
long long inf;
long long go(int i , int sum){
    if(sum > w)
        return -inf;
    if(i == n)
        return 0;
    long long &ans = dp[i][sum];
    if(ans)
        return ans;

    ans = max(arr[i][1] + go(i+1 , sum + arr[i][0]) , go(i+1,sum));
    return ans;
}
int main(){
    cin >> n >> w;
    inf = 5 * 100000000000000;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < 2 ; j++)
            cin >> arr[i][j];
    long long res = go(0,0);
    if(res > 0)
        cout<<res;
    else
        cout<<0;
}


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

int main() {
    int N;
    char c;
    cin >> N;
    rep(i, N) {
        cin >> c;
        if (c == 'Y') {
            cout << "Four\n";
            return 0;
        }
    }
    cout << "Three\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int n, k, q, a[100005], tmpx;
int main() {
	cin >> n >> k >> q;
	for(int i= 1; i <= q; i++) cin >> tmpx, ++a[tmpx];
	for(int i= 1; i <= n; i++) {
		if(k - q + a[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios	      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
      
      ios
      int a,b,c,d;
      cin >> a >> b >> c >> d;
      int i=1;
      while(i){
            
            if(i%2!=0){
                  c = c-b;
                  if(c<=0){
                        cout << "Yes" <<"\n";
                        break;
                  }      
            }
            else{
                  a=a-d;
                  if(a<=0){
                        cout << "No" <<"\n";
                        break;
                  }      
            }
            i++;
      }

      return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int pp = sc.nextInt();
      int days = sc.nextInt();
      int x = sc.nextInt();
      int cost = 0;
      for(int i = 0; i < pp; i++)
        cost += (days - 1) / sc.nextInt() + 1;

      System.out.println(cost + x);
  }
}

Measured memory_bytes: 21844
import sys
N, K = map(int, input().split())

if K == 0:
    print(N ** 2)
    sys.exit()

ans = 0
for b in range(1, N + 1):
    able_div = N // b
    able_div_nums = able_div * max(0, b - K)
    remainders = max(0, (N % b) - K + 1)
    #print(f'able_div_nums: {able_div_nums}')
    #print(f'remainders: {remainders}')
    ans += able_div_nums + remainders
print(ans)

Measured memory_bytes: 3060
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
#OutH = print(' '.join(map(str, lst)))
OutV = lambda x: print(*x, sep='\n')
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

## 数値リストを与えるとそのxorを計算する
## xors([1,2,3]) = 0
def xors(num_lst):
  xor = 0
  for i in range(len(num_lst)):
    xor = xor ^ num_lst[i]
  return xor

N = iIn()
A = iInLH()

allxor = xors(A)
lst = []
for i in range(N):
    eachxor = allxor ^ A[i]
    lst.append(eachxor)

print(' '.join(map(str, lst)))


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int c[3][3];
  rep(i, 3) rep(j, 3) cin >> c[i][j];

  string res = "No";
  rep(k, 101) rep(m, 101) rep(n, 101) {
    int a[3], b[3];
    a[0] = k, a[1] = m, a[2] = n;
    b[0] = c[0][0] - a[0], b[1] = c[1][1] - a[1], b[2] = c[2][2] - a[2];
    rep(i, 3) if (b[i] < 0) continue;
    int cnt = 0;
    rep(i, 3) rep(j, 3) {
      if (c[i][j] != a[i] + b[j]) break;
      cnt++;
    }
    if (cnt == 9) {
      res = "Yes";
      break;
    }
  }

  cout << res << endl;
}

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

using namespace std;
typedef long long ll;
#define mp make_pair

typedef pair<int, int> pii;

const int N = 1e5 + 10;
vector<pii> segm;
int r, c;

int to_int(int x, int y) {
	if (x == 0)
		return y;
	if (y == c)
		return x + c;
	if (x == r)
		return r + c + (c - y);
	return c + r + c + (r - x);
}

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	cin >> r >> c;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (x1 > 0 && x1 < r && y1 > 0 && y1 < c)
			continue;
		if (x2 > 0 && x2 < r && y2 > 0 && y2 < c)
			continue;
		int t1 = to_int(x1, y1);
		int t2 = to_int(x2, y2);
		if (t1 == t2)
			continue;
		if (t1 > t2)
			swap(t1, t2);
		segm.push_back(pii(t1, t2));
		segm.push_back(pii(t1 + 2 * r + 2 * c, t2 + 2 * r + 2 * c));	
	}
//	for (auto p : segm) {
//		cout << p.first << " " << p.second << endl;
//	}
	sort(segm.begin(), segm.end());
	stack<int> d;
	for (int i = 0; i < (int)segm.size(); i++) {
		while (!d.empty() && segm[i].first > d.top())
			d.pop();
		if (!d.empty() && d.top() < segm[i].second) {
			cout << "NO" << endl;
			return 0;
		}
		d.push(segm[i].second);
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 2420
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
typedef long long ll;
typedef pair<int, int>P;
#define int long long

int p[200000];
signed main() {
	int n; scanf("%lld", &n);
	rep(i, n) {
		scanf("%lld", &p[i]); p[i]--;
	}
	int cnt = 0;
	rep(i, n - 1) {
		if (p[i] == i) {
			cnt++; swap(p[i], p[i + 1]);
		}
	}
	if (p[n - 1] == n - 1)cnt++;
	cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<ll> sum(n + 1, 1);
    if(n == 1) {
        cout << 1 << endl;
        return 0;
    }
    for(int i = 2; i <= n; i++) {
        int k = i;
        while(k <= n) {
            sum[k]++;
            k += i;
        }
    }
    ll ans = 0;
    rrep(i, n) {
        ans += i * sum[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 81344
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[210];
	for (int i=1;i<=2*n;i++)
	  cin>>a[i];
	sort(a+1,a+1+2*n);
	int sum=0;
	for (int i=1;i<=n*2;i+=2)
	  sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int Y,X,N;
VV<int> x2ys;
int main(){
	cin>>X>>Y>>N;
	x2ys.resize(X+1);
	rep(i,N){
		int x,y;
		cin>>x>>y;
		y--,x--;
		x2ys[x].pb(y);
	}
	x2ys[X].pb(0);
	rep(x,X) sort(all(x2ys[x]));
	int h = 0;	//<=h -> end
	rep(x,X){
		if(x2ys[x+1].empty()){
			h++;
			continue;
		}
		int y = x2ys[x+1][0];
		if(y<=h){
			cout<<x+1<<endl;
			return 0;
		}
		if(y != h+1) h++;
	}
	assert(false);
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    int A, B, K; cin >> A >> B >> K;
    int ans=min(A, B)+1;
    int i=0;
    while(i < K) {
        ans--;
        if(A % ans == 0 && B % ans == 0) i++;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using vi = std::vector<int>;

template<class T>
using max_heap = priority_queue<T>;
template<class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long H, long long A){
    ll ans = H / A + ( H % A > 0  ? 1 : 0);
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
  	cin >> a[i];
  }
  int len=0;
  sort(a.begin(),a.end());
  for(int i=n-1;i>=n-k;i--){
  	len+=a[i];
  }
  cout << len << endl;
}



Measured memory_bytes: 3628
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
max_s = -10**9
min_s = s[0]
for i in range(1, n):
    max_s = max(max_s, s[i] - min_s)
    min_s = min(min_s, s[i])

print(max_s)


Measured memory_bytes: 13588
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d  long double
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (int)1e18
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

 
signed main()
{
    haha
   int n,m1;
   cin>>n>>m1;
   int f=0;
   map<int,int> m;
   int arr[n];
   memset(arr,0,sizeof(arr));
   int p=0;
   set<int> s;
   arr[0]=1;
  
   if(m1==0 )
   {
       if(n==1)
       cout<<0;
       else if(n==2)
       cout<<10;
       else
       cout<<100;
       return 0;
   }
   for(int i=0;i<m1;i++)
   {
       int x,y;
       cin>>x>>y;
       if(x==1 && y==0 && n>1)
       f=1;
      
       if(s.find(x)!=s.end())
       {
           if(m[x]!=y)
           f=1;
       }
       else
       {
       m[x]=y;
       s.insert(x);
       }
       arr[x-1]=y;
   }
  
   if(f==1)
   cout<<-1;
   else
   {
       int x=0;
       for(int i=n-1;i>=0;i--)
       {
           x+=arr[i]*pow(10,(n-1-i));
       }
      cout<<x;
   }
   
    
    
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << (a + b + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [H] = r.nn()
    const [W] = r.nn()
    const [N] = r.nn()

    return Math.ceil(N / Math.max(H, W))
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}


Measured memory_bytes: 7500
#include<iostream>
#define m 52000
using namespace std;

bool ba[m+1] = { true };
void cp() {
	int co = 0;
	for (int i = 0; i < m+1; i++) {
		ba[i] = { true };
	}
	for (int i = 2; i*i <= 52000; i++) {
		if (ba[i]) {
			for (int j = i*i; j <= 52000; j += i) {
				ba[j] = { false };
			}
		}
	}
	
	return ;
}

int main() {
	int n;
	cp();
	while (cin >> n,n) {
		int c = 0;
		for (int i = 2;i <= n / 2;i++) {
			int j = n - i;
			if (ba[i]==true && ba[j]==true)c++;
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
int main(){
  int N;cin>>N;vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  long long ans=0;
  for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)for(int k=j+1;k<N;k++)if(A[i]+A[j]>A[k]&&A[i]+A[k]>A[j]&&A[k]+A[j]>A[i])ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 3228
#include<stdio.h>
#include<math.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int INF=0x7f7f7f7f;
int min(int x,int y){return(x<y)?x:y;}
int main(void)
{
  int N,M,X,check,cost,C[12]={0},A[12][12]={0},skill[12]={0},total=INF;
  check=scanf("%d %d %d",&N,&M,&X);
  rep(i,N){check=scanf("%d",&C[i]);rep(j,M)check=scanf("%d",&A[i][j]);}
  for(int bit=pow(2,N)-1;~bit;bit--)
  {
    cost=0;rep(i,M)skill[i]=0;
    rep(i,N)if(bit&(int)pow(2,i)){cost+=C[i];rep(j,M)skill[j]+=A[i][j];}
    check=1;rep(i,M)if(skill[i]<X){check=0;break;}
    if(check)total=min(total,cost);
  }
  return printf("%d\n",total==INF?-1:total),0;
}

Measured memory_bytes: 2484
[N, X, Y] = [int(item) for item in input().split()]
X -= 1
Y -= 1
count=[0 for _ in range(N)]
for i in range(N):
    for j in range(i,N):
        count[min(abs(i-j),abs(i-X)+1+abs(Y-j),abs(i-Y)+1+abs(X-j))]+=1
#print(array)


for i in range(1,N):
        print(count[i])

#print(count)

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r1 = scan.nextInt();
		int r2 = scan.nextInt();
		int r3 = scan.nextInt();
		boolean flg = false;
		//String str = scan.nextLine();
		//String[] substr = str.split(" ", 0);
		if (r1 == r2 ) {
			flg = true;
		}
		String ans = "Yes";
		if (flg ) {
			if (r1 == r3) {
				ans = "No";
			}
		} else {
			if (r1 == r3 || r2 == r3) {
				ans = "Yes";
			} else {
				ans = "No";
			}
		}
		//int ans = 0;
		//for (int i=c1; i<c2+1;i++) {
		//}
		System.out.println(ans);
	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;
const int mod = 1e9+7;

int main(){
    int a, b;
    cin >> a >> b;
    vector<int> p(1000, 0);
    p[0] = 1;
    rep1(i, 1000) p[i] = p[i-1] + i + 1;
    int idx = b-a;
    cout << p[idx-1] - b << endl;


}

Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;

 int main()
 {
   double a;
   while(cin>>a)
   {
     double sum=a;
     for(int i=1;i<=9;i++)
     {
       if(i%2==1) a*=2;
       else a/=3;
       sum+=a;      
     }        
     printf("%.8lf\n",sum);     
   }
   //while(1);
   return 0;
 }

Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>

using namespace std;

#define REP(i, b, e) for(int i = (int)(b); i < (int)(e); i++)
#define rep(i, n) REP(i, 0, n)


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


int main(){
	int n;
	cin>>n;
	vi t(n);
	int sum = 0;
	rep(i, n) cin>>t[i], sum += t[i];
	int ans = 1e9;
	int m;
	cin>>m;
	rep(i, m){
		int p, x;
		cin>>p>>x;
		cout<<sum - (t[p-1] - x)<<endl;
	}
}

Measured memory_bytes: 256
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    LD ans;
    if (N % 2 == 0) {
        ans = 0.5;
    } else {
        ans = (LD)(N + 1)/(2*N);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i=0;i<N;i++) {
			d[i] = sc.nextInt();
		}
		
		int total = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				total += d[i]*d[j];
			}
		}
		System.out.println(total);
		
		sc.close();
	}
}

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

using namespace std;
#define int long long
int n, m, x[105], y[105], h[105], val[105];

signed main() {
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> x[i] >> y[i] >> h[i];
    for(int i = 0; i <= 100; i++) {
        for(int j = 0; j <= 100; j++) {
            int ok = 0;
            for(int k = 1; k <= n; k++) {
                if(h[k] != 0)
                    ok = 1;
            }
            if(ok == 0) {
                int mx = LLONG_MAX;
                for(int k = 1; k <= n; k++) {
                    val[k] = abs(x[k] - i) + abs(y[k] - j);
                    mx = min(mx, val[k]);
                }
                cout << i << " " << j << " ";
                cout << mx << "\n";
                exit(0);
            }
            else {
                for(int k = 1; k <= n; k++) {
                    if(h[k] == 0) continue;
                    val[k] = abs(x[k] - i) + abs(y[k] - j);
                }
                int pick;
                for(int k = 1; k <= n; k++) {
                    if(h[k] == 0) continue;
                    pick = h[k] + val[k];
                    break;
                }
                ok = 0;
                for(int k = 1; k <= n; k++) {
                    if(max(pick - abs(i - x[k]) - abs(j - y[k]), 0ll) != h[k])
                        ok = 1;
                }
                if(ok == 0) {
                    cout << i << " " << j << " ";
                    cout << pick;
                    exit(0);
                }
            }
        }
    }
}


Measured memory_bytes: 256
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
#define non __builtin_popcount
#define ml map<ll, ll> 
#define ms map<string , ll> 
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	
	ll n,l,i,j,x=inf, ans=0, an;
	cin>>n>>l;
	for(i=0; i<n; i++)
	{
		ans+= (l+i);
		ll kk= abs(l+i);
		if(kk< x)
		{
			x= kk;
			an= l+i;
			//cout<<x<<" ";
		}
	}
	ans-= an;
	//cout<<endl;
	cout<<ans;//<<" "<<x;
    return 0;
}























Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<math.h>
using namespace std;

int main(){
    
    int K;
    string S;
    cin >> K;
    cin >> S;
    
    //cout << N << endl;
    
    if(S.size()>K){
        for(int i=0; i<K; i++){
            cout << S[i];
        }
        cout << "..." << endl;
    }else{
        for(int i=0; i<S.size(); i++){
            cout << S[i];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3560
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int gcd(int one, int two) {
	while (one != 0 && two != 0) {
		if (one > two) {
			one = one % two;

		}
		else {
			two = two % one;
		}

	}

	return std::max(one, two);

}
int main()
{
	using namespace std;
	int a = 0, b = 0, c = 0, d = 0, e = 0, maxy = 0, max = 0, ans = 0, count = 0, size = 0, n = 0,m=0,x=0,y=0;
	int sa[10000] = {}, xwant[101] = {}, ywant[101] = {};
	int yoko = 0, tate = 0;
	std::string output,output2,output3,output4;
	char changer;
	char changer2;
	bool okada = false;

	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; i++) {
		cin >> xwant[i];
		if (i == 0) {
			max = xwant[i];
		}
		else if(max<xwant[i]){
			max = xwant[i];
		}
	}

	for (int j = 0; j < m; j++) {
		cin >> ywant[j];
		if (j == 0) {
			maxy = ywant[j];
		}
		else if (maxy > ywant[j]) {
			maxy = ywant[j];
		}
	}
	if (maxy > max) {

		{
			for (int j = x+1 ; j <= y; j++) {
				if (max < j&&j <= maxy) {
					okada = true;
					
					break;
				}
			}
		}
	
	}
	else {
		okada = false;
	}
	if (okada) {
			cout << "No War" << endl;
		}
		else {
			cout << "War" << endl;
		}
}






Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MOD=1000000007;
const int MAXBIT=70;

ll xx;
int x[MAXBIT],nx;

int ways[MAXBIT+1][2][2]; // ways[i][eq][c] = #ways to choose uj and vj for j<i such that for u+v<a if eq=0 and u+v=x if eq=1 (up to here), assuming it gets c carry


void run() {
	scanf("%lld",&xx);
	nx=0; for(ll i=xx;i!=0;i/=2) x[nx++]=i%2; reverse(x,x+nx);
	//REP(i,na) printf("%d",a[i]);

	memset(ways,0,sizeof(ways));
	ways[0][1][0]=1;
	REP(i,nx) REP(eq,2) REP(c,2) if(ways[i][eq][c]!=0) REP(ui,2) REP(vi,2) REP(nc,2) {
		bool can=false;
		REP(ai,2) REP(bi,2) {
			if((ai+bi+nc)%2!=vi) continue;
			if((ai^bi)!=ui) continue;
			if((ai+bi+nc)/2!=c) continue;
			can=true;
		}
		if(!can) continue;
		if(eq&&vi>x[i]) continue;
		int neq=eq&&vi==x[i]?1:0;
		//printf("ways[%d][%d][%d]=%d -> ways[%d][%d][%d]\n",i,eq,c,ways[i][eq][c],i+1,neq,nc);
		ways[i+1][neq][nc]+=ways[i][eq][c]; if(ways[i+1][neq][nc]>=MOD) ways[i+1][neq][nc]-=MOD;
	}
	int ret=ways[nx][0][0]+ways[nx][1][0]; if(ret>=MOD) ret-=MOD;
	printf("%d\n",ret);

	//set<pair<int,int> > chk; FORE(v,0,xx) FORE(a,0,v) chk.insert(MP(v,a^(v-a))); printf("want=%d\n",SZ(chk));
}

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


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl;
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define endl "\n"
#define y() cout<<"Yes"<<endl
#define Y() cout<<"YES"<<endl
#define n() cout<<"No"<<endl
#define N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vs = vector<st>;
using vb = vector<bool>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
bool graph[node][node];
bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

/************************************************************************/
int n, m;

void dfs(int v) {
	visited[v] = true;
	f(v2, 0, n) {
		if (graph[v][v2] == false)continue;
		if (visited[v2] == true)continue;
		dfs(v2);
	}
}


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

	cin >> n >> m;
	vi a(m), b(m);
	link(a, b, m);
	LL ans = 0;
	f(i, 0, m) {
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
		f(j, 0, n) {
			visited[j] = false;
		}
		dfs(0);
		bool bridge = false;
		f(j, 0, n) {
			if (visited[j] == false)bridge = true;
		}
		if (bridge)ans += 1;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
def tail(x):
	s = str(x)
	a = int(s[0]); d = len(s)
	return x - a * 10 ** (d - 1)

def K1(N):
	s = str(N)
	a = int(s[0]); d = len(s)
	res = 9 * (d - 1) + a
	return res

def K2(N):
	s = str(N)
	a = int(s[0]); d = len(s)
	res = (d - 1) * (d - 2) // 2 * 81
	res += (a - 1) * (d - 1) * 9
	res += K1(tail(N))
	return res
	
def K3(N):
	s = str(N)
	a = int(s[0]); d = len(s)
	res = (d - 1) * (d - 2) * (d - 3) // 6 * 729
	res += (a - 1) * (d - 1) * (d - 2) // 2 * 81
	res += K2(tail(N))
	return res

N = int(input())
K = int(input())
if K == 1:
	ans = K1(N)
elif K == 2:
	ans = K2(N)
elif K == 3:
	ans = K3(N)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
typedef struct{
	double x;
	double y;
}Point;
double get_area(Point p1,Point p2,Point p3)
{
	double area;
	area = (p1.x*p2.y+p2.x*p3.y+p3.x*p1.y-p2.x*p1.y-p3.x*p2.y-p1.x*p3.y)/2;
	if(area<0)
	{
		area = -area;
	}
	return area;
}
int main()
{
	Point pp[3];
	Point t;
	double area,area1,area2,area3;
	while(cin>>pp[0].x)
	{
		cin>>pp[0].y>>pp[1].x>>pp[1].y>>pp[2].x>>pp[2].y>>t.x>>t.y;
		area = get_area(pp[0],pp[1],pp[2]);
		area1 = get_area(pp[0],pp[1],t);
		area2 = get_area(pp[0],pp[2],t);
		area3 = get_area(pp[1],pp[2],t);
		if(area==(area1+area2+area3))
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
n = gets.to_i
cnt = 0
ans = false
n.times do
  d1, d2 = gets.split.map(&:to_i)
  if d1 == d2
    cnt += 1
    ans = true if cnt >= 3
  else
    cnt = 0
  end
end
if ans
  puts 'Yes'
else
  puts 'No'
end


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    int odp = 0;
    for (int i = 0; i < k; ++i)
        odp += a[i];
    cout << odp;
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
int main(void) {
	int a, b, c,f=0;
	scanf("%d%d%d", &a, &b, &c);
	if (a + b == c) f++;
	else if (a + c == b) f++;
	else if (b + c == a) f++;
	if (f == 1) printf("Yes\n");
	else printf("No\n");
    return 0;
}	

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using namespace atcoder;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int op(int a,int b){
  return max(a,b);
}
int e(){
  return 0;
}

int main()
{
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  segtree<int,op,e> seg(300005);
  REP(i,N){
    int l=max(0,A[i]-K);
    int r=min(300005,A[i]+K+1);
    int x=seg.prod(l,r);
    seg.set(A[i],x+1);
  }

  cout << seg.prod(0,300005) << endl;
}


Measured memory_bytes: 9624