akhauriyash/Code-Regression huggingface dataset:
n,m = gets.split.map(&:to_i)
array = Array.new(m,0)
parray = Array.new(m,0)
cnt = 0
n.times do |i|
  parray = gets.split.map(&:to_i)
  parray.delete_at(0)
  parray.each {|num|
    array[num-1] += 1
  }
end
# p array
array.each {|num|
  if num == n
    cnt += 1
  end
}
puts cnt


Measured memory_bytes: 1788
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Control.Monad
import Data.Char
import Data.Array.Unboxed
import Data.Array.ST

solve ::  Int -> Int -> VU.Vector Int -> UArray (Int, Int, Int) Int
solve a n xs =
    runSTUArray $ do
        -- i: i番目のカード
        -- j: j個まで選ぶ
        -- k: 合計値がkになる
        dp <- newArray ((0,0,0), (n,n,a*n)) 0
        writeArray dp (0,0,0) 1
        forM_ [0..n-1] $ \i ->
            forM_ [0..n] $ \j ->
                forM_ [0..a*n] $ \k -> do
                    let x = xs VU.! i
                    curr <- readArray dp (i,j,k)
                    if (j == n)
                        then do
                            dest1 <- readArray dp (i+1,j,k)
                            writeArray dp (i+1,j,k) $ curr + dest1
                        else if (x + k <= a*n)
                            then do
                                dest1 <- readArray dp (i+1,j,k)
                                writeArray dp (i+1,j,k) $ curr + dest1
                                dest2 <- readArray dp (i+1,j+1,k+x) 
                                writeArray dp (i+1,j+1,k+x) $ curr + dest2
                            else do
                                dest1 <- readArray dp (i+1,j,k)
                                writeArray dp (i+1,j,k) $ curr + dest1
        return dp

main = do
    [n, a] <- map read . words <$> getLine :: IO [Int]
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    let dp = solve a n xs
    print $ sum $ map (\i -> dp ! (n,i,a*i)) [1..n]

Measured memory_bytes: 52220
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [][] a = new int[3][105];
		int []presum = new int[105];
		int []sufsum = new int[105];
		for(int i = 1; i <= n; i++) a[1][i] = sc.nextInt();
		for(int i = 1; i <= n; i++) a[2][i] = sc.nextInt();
		for(int i = 1; i <= n; i++) presum[i] = presum[i-1] + a[1][i];
		for(int i = n; i >= 1; i--) sufsum[i] = sufsum[i+1] + a[2][i];
		int ans = 0;
		for(int i = 1; i <= n; i++)
			ans = Math.max(ans, presum[i]+sufsum[i]);
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int main() {
	int k;
	string s;
	cin>>k>>s;
	int n=s.size();
	if(k>=n)
	cout<<s;
	else {
		for(int i=0;i<k;i++){
			cout<<s[i];
		}	
		cout<<"...";
	}
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int MAX = 1000000000;

int main() {
  ll s;
  cin >> s;
  ll x1, x2, x3, y1, y2, y3;
  x1 = 0; y1 = 0;
  x2 = MAX, y2 = 1;
  x3 = (MAX - s % MAX) % MAX, y3 = (s + MAX - 1) / MAX;
  cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;

}

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

int main(){
	int tc,a[100];
	while(cin>>tc){
		for(int i=0;i<tc;i++){
			cin>>a[i];
		}
		sort(a,a+tc);
		int ans=0;
		for(int i=0;i<tc;i++)ans+=(a[i]/2+(i!=tc-1)*a[i]/2);
		cout<<ans<<endl;
	}
} 

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


#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)
#define sp(n) setprecision(n)
#define mkp make_pair
#define mkt make_tuple
#define pi 3.14159265358979323846264
#define d7 1000000007
#define l7 998244353

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);}}}
    return C[n][k];
 }

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

ll expmod(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}

//some definitions and global variables >>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<
vector<ll> primes;
void storePrime(ll n){
    fori(n){
        if(isPrime(i+1)&&(n%(i+1)==0)){primes.push_back(i+1);}
    }
}

void srihrg(){
    //code starts
    ll n,k;
    cin>>n>>k;
    ll a[n];
    fori(n) cin>>a[i];
    ll sum=0;
    fori(n) sum+=a[i];
    ll cn=0;
    fori(n){
        if(a[i]*4*k>=sum){cn++;}
    }
    if(cn<k){cout<<"No";}
    else{cout<<"Yes";}
    
    //code ends
}

int main(int argc, const char * argv[]) {
#ifdef KR1shna
    cout<<"||ओ३म्||"<<endl;
#endif
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
// code now

    ll t=1;
    //cin>>t;
    ll nt=1;
    while(t--){
        //cout<<"Case #"<<nt<<": ";
        srihrg();
        //nt++;
        cout<<endl;
    }
    
//code ends
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[][] lens = new int[n+1][];
			boolean[][] wipes = new boolean[n+1][];
			
			for(int i = 0; i <= n; i++){
				final int m = sc.nextInt();
				lens[i] = new int[m-1];
				wipes[i] = new boolean[m-2];
				
				int prev_x = Integer.MIN_VALUE;
				int prev_y = Integer.MIN_VALUE;
				int prev_dx = Integer.MIN_VALUE;
				int prev_dy = Integer.MIN_VALUE;
				for(int j = 0; j < m; j++){
					if(j == 0){
						prev_x = sc.nextInt();
						prev_y = sc.nextInt();
					}else{
						final int x = sc.nextInt();
						final int y = sc.nextInt();
						
						final int dx = x - prev_x;
						final int dy = y - prev_y;
						
						lens[i][j-1] = dx * dx + dy * dy;
						if(j != 1){
							int dot = prev_dx * dy - prev_dy * dx;
							
							if(dot < 0){
								wipes[i][j - 2] = true;
							}else{
								wipes[i][j - 2] = false;
							}
						}
						
						prev_x = x;
						prev_y = y;
						prev_dx = dx;
						prev_dy = dy;
					}
				}
			}
			
			for(int i = 1; i <= n; i++){
				if(lens[0].length != lens[i].length){
					continue;
				}
				
				//System.out.println(i);
				//System.out.println(Arrays.toString(lens[i]));
				//System.out.println(Arrays.toString(wipes[i]));
				
				
				boolean flag = true;
				for(int j = 0; j < lens[0].length; j++){
					if(lens[0][j] != lens[i][j]){
						flag = false;
						break;
					}else if(j > 0 && wipes[0][j-1] != wipes[i][j-1]){
						flag = false;
						break;
					}
				}
				
				if(flag){
					System.out.println(i);
					continue;
				}
				
				flag = true;
				for(int j = lens[0].length - 1;  j >= 0; j--){
					//System.out.println((j - 1) + " " + (lens[0].length - j - 1));
					if(lens[0][lens[0].length - 1 - j] != lens[i][j]){
						flag = false;
						break;
					}else if(j > 0 && wipes[0][lens[0].length - j - 1] == wipes[i][j-1]){
						flag = false;
						break;
					}
				}
				
				if(flag){
					System.out.println(i);
					continue;
				}
			}
			
			System.out.println("+++++");
		}
		
		
	}

}

Measured memory_bytes: 29324
#include <stdio.h>

int main(void)
{
	char s[3][11];
	int i;
	
	scanf("%s %s %s", s[0], s[1], s[2]);
	
	for(i=0; i<3; i++)
		putchar(s[i][0]-32);
	putchar('\n');
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {
  while(1){
    int N;
    string L[55];
    int P[55], A[55], B[55], C[55], D[55], E[55], F[55], S[55], M[55];
    cin>>N;
    if(N==0) break;
    REP(i,0,N){
      cin>>L[i]>>P[i]>>A[i]>>B[i]>>C[i]>>D[i]>>E[i]>>F[i]>>S[i]>>M[i];
    }
    vector< pair<double,string> > v;
    REP(i,0,N){
        int t = A[i]+B[i]+C[i]+ (D[i]+E[i])*M[i];
        int p = (F[i]*S[i])*M[i] - P[i];
        v.push_back(make_pair((double)p/(double)t,L[i]));
    }
    sort(v.begin(), v.end());

    RREP(i,0,v.size()){
      vector<string> sv;
      sv.push_back(v[i].second);
      if(i > 0){
        while(v[i].first == v[i-1].first){
          sv.push_back(v[i-1].second);
          i--;
          if(i == 0) break;
        }
      }
      sort(sv.begin(), sv.end());
      REP(j,0,sv.size()){
        cout<<sv[j]<<endl;
      }
    }
    cout<<"#"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
N, M = map(int, input().split())
#M = int(input())
ab = [list(map(int, input().split())) for _ in range(M)]

from operator import itemgetter
st = sorted(ab, key=itemgetter(1))
last = 0
ans = 0
for s, t in st:
    #print(x, l)
    if s >= last:
        ans += 1
        last = t
print(ans)

Measured memory_bytes: 29980
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let (x, a, b) = (int(), int(), int());
    println!(
        "{}",
        if b <= a {
            "delicious"
        } else {
            if b - a <= x {
                "safe"
            } else {
                "dangerous"
            }
        }
    )
}


Measured memory_bytes: 4352
# coding=utf-8

if __name__ == '__main__':
    S = int(input())
    while True:
        inp = input()
        if inp == '=':
            print(S)
            break
        elif inp == '+':
            inp_number = int(input())
            S += inp_number
        elif inp == '-':
            inp_number = int(input())
            S -= inp_number
        elif inp == '*':
            inp_number = int(input())
            S *= inp_number
        elif inp == '/':
            inp_number = int(input())
            S //= inp_number



Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int dp[250][2400], dp2[2400];
string S[1000], T; int v[1000];
int main() {
	int cnt = 0;
	while (true) {
		int n; cin >> n; if (n == 0)break; cnt++;
		for (int i = 0; i < n; i++)cin >> S[i] >> v[i]; cin >> T;
		for (int i = 0; i < 250; i++) { for (int j = 0; j < 2400; j++)dp[i][j] = 0; }dp[0][0] = 1;
		for (int i = 0; i < 2400; i++) { dp2[i] = 999999999; }dp2[0] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2400 - v[i]; j++) {
				dp2[j + v[i]] = min(dp2[j + v[i]], dp2[j] + (int)S[i].size());
			}
		}
		for (int i = 0; i < T.size(); i++) {
			for (int j = 0; j < 2400; j++) {
				if (dp[i][j] == 0)continue;
				for (int k = 0; k < n; k++) {
					if (i + S[k].size() > T.size())continue;
					if (T.substr(i, S[k].size()) != S[k])continue;
					dp[i + S[k].size()][j + v[k]] = 1;
				}
			}
		}
		int minx = 999999999;
		for (int i = 0; i < 2400; i++) {
			if (dp[T.size()][i] == 1)minx = dp2[i];
		}
		if (minx == 999999999)minx = -1;
		cout << "Case " << cnt << ": " << minx << endl;
	}
	return 0;
}

Measured memory_bytes: 5580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;

/**
 *
 * @author Node2
 */
public class Main {
        Main parent;
        List<Main> children = new ArrayList();
        long num = 0;
        String str;
        static long sum = 0;
        public Main(String instr){
            str = instr;
        }
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String str = in.readLine();
        Main tree = new Main(str);
        

        
        get(tree);
        
        System.out.println(sum);
  
    }
    public static void get(Main node){

        node.makechildren();
        
        if(node.children.isEmpty()){
            sum += node.num;
            return;
        }
        
        for(int i=0;i<node.children.size();i++){
            get(node.children.get(i));
        }
    }
  

        

        
        public void makechildren(){
            for(int i=0;i<str.length();i++){
                String buf = new String(str);
                long a = Long.parseLong(buf.substring(0, i+1));
                Main child = new Main(buf.substring(i+1));
                child.num = a + num;
                child.parent = this;
                this.children.add(child);
            }
        }
        

    
}

Measured memory_bytes: 8660
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<cmath>
typedef long long ll;
using namespace std;
  
int main (){
    ll n,x;
    ll count1,temp,sum,tt,a,b,p;
    scanf("%lld%lld",&n,&x);
    sum=n;a=n-x;b=x;
    if(n-x==x){
        printf("%lld\n",x*3);
        return 0;
    }
    else if(n-x<=x)
        swap(a,b);
    count1=a/b;
    temp=b;
    tt=a;
    while(tt%temp){
        sum+=count1*2*temp;
        p=tt;
        tt=temp;
        temp=p-temp*count1;
        count1=tt/temp;
    }
    printf("%lld\n",sum+count1*2*temp-temp);
    return 0;
}


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

ll gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main() {
  ll a, b;
  cin >> a >> b;

  cout << a * b / gcd(a, b) << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
S = list(input())
zero = 0
one = 0
ans = 0
for s in S:
    if s == '0':
        zero += 1
        if one > 0:
            zero -= 1
            one -= 1
            ans += 2
    else:
        one += 1
        if zero > 0:
            zero -= 1
            one -= 1
            ans += 2
print(ans)


Measured memory_bytes: 3956
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, t;
    cin >> n >> t;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll mini = a[0];
    ll max_profit = 0;
    for (int i = 1; i < n; ++i) {
        chmax(max_profit, a[i] - mini);
        chmin(mini, a[i]);
    }
    unordered_set<int> cnt;
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        if (cnt.count(a[i] - max_profit) != 0)
            ret++;
        cnt.insert(a[i]);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 5156
#include <stdio.h>

int main(void)
{
	int N;
	int i;
	int a , b , c;
	
	scanf("%d" ,&N);
	
	for( i = 1 ; i <= N ; i++){
		scanf("%d %d %d" , &a ,&b ,&c);
		
		if((a * a) + (b * b) == (c * c)){
		  printf("YES\n");
		}
		
		else if ((a * a) - (c * c) == (b * b)){
			printf("YES\n");
		}
		
		else if((b * b) - (c * c) == (a * a)){
			printf("YES\n");
		}
		
		else{
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=105;

int n;
int a[2][N],dp[N][2];

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=0;i<2;i++) for (j=1;j<=n;j++) scanf("%d",&a[i][j]);
	dp[1][0]=a[0][1];
	for (i=1;i<=n;i++){
		dp[i][1]=max(dp[i][1],dp[i][0]+a[1][i]);
		dp[i+1][0]=max(dp[i+1][0],dp[i][0]+a[0][i+1]);
		dp[i+1][1]=max(dp[i+1][1],dp[i][1]+a[1][i+1]);
	}
	printf("%d\n",dp[n][1]);
	return 0;
} 

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let mut n = input::<i64>();

    let mut s = Vec::new();
    while n != 0 {
        if n % 2 == 0 {
            s.push('0');
        } else {
            n -= 1;
            s.push('1');
        }
        n /= -2;
    }

    if s.is_empty() {
        s.push('0');
    }

    println!("{}", s.iter().rev().map(|&c| c).collect::<String>());
}


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

int main() {
    vector<ll> abc(3);
    cin >> abc.at(0) >> abc.at(1) >> abc.at(2);
    for (int i = 0; i < 3; i++) {
        if (abc.at(i) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    sort(abc.begin(), abc.end());
    cout << abc.at(0) * abc.at(1) << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int h, w;
char m[110][110];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> h >> w;
    rep(i, 0, h) rep(j, 0, w) cin >> m[i][j];
    rep(i, 0, h) {
        rep(j, 0, w) {
            int white = 0;
            rep(k, 0, 4) {
                int nx = i + dx[k], ny = j + dy[k];
                if (m[i][j] == '#' && 0 <= nx && nx < h && 0 <= ny && ny < h && m[nx][ny] == '.')
                    white++;
            }
            if (white == 4) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
/*
 * atcoder/abc121_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * 2 9 = 2 3 4 5 6 7 8 9
 * xor(A, A+1, A+2, ..., B)
 * N, N+1のxorは1に簡約化可能.
 * 1 xor 1 = 0
 * 0 xor 1 = 1
 *
 * i) Aが偶数、かつBが奇数の場合: (B-A+1)/2 % 2
 * ii) Aが偶数、かつBも偶数の場合: ((B-1-A+1)/2 % 2) xor B
 * iii) Aが奇数、かつBが偶数の場合: ((B-2A+1)/2 % 2) xor A xor B
 * iv) Aが奇数、かつBも奇数の場合: ((B-1-A+1)/2 % 2) xor A
 *
 * 2 3 4
 * 1 4
 *
 */
ll A, B;
void solve() {
  cin >> A >> B;
  if (A%2 == 0 and B%2==1) {
    cout << (((B-A+1)/2) % 2) << endl;
    return;
  }

  if (A%2==0 and B%2==0) {
    cout << ((((B-1-A+1)/2) % 2) ^ B) << endl;
    return;
  }

  if (A%2==1 and B%2==0) {
    cout << ((((B-2-A+1)/2)%2) ^ A ^ B) << endl;
    return;
  }

  cout << ((((B-1-A+1)/2) % 2) ^ A) << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    PrintWriter out = new PrintWriter(System.out);

    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    int a = Integer.parseInt(sl[0]);
    int b = Integer.parseInt(sl[1]);
    int c = Integer.parseInt(sl[2]);

    out.println(Math.min(b / a, c));
    out.flush();
  }

}

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

int main()
{
    int n,l;
    cin>>n>>l;
    vector<string> v;
    forn(i,n)
    {
        string s;
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    for(auto i : v)
        cout<<i;
    return 0;
}


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

int main(){

  ll N;
  cin>>N;
  
  ll x,y=0;
  ll t=0;
  
  rep(i,N){

    ll x2,y2,t2;
    cin>>t2>>x2>>y2;
    
    ll tdif,xdif,ydif;
    tdif=t2-t;
    xdif=x2-x;
    ydif=y2-y;
    ll d=abs(xdif)+abs(ydif);
    
    if(tdif<d || tdif%2!=d%2){cout<<"No"<<endl;return 0;}
    
    x=x2;
    y=y2;
    t=t2;
    
  }
  
  cout<<"Yes"<<endl;
   
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A, V = [int(x) for x in input().split()]
    B, W = [int(x) for x in input().split()]
    T = int(input())


    diff = abs(A - B)

    if W > V:
        print("NO")
    else:
        if V == W:
            print("NO")
        elif diff / (V - W) <= T:
            print("YES")
        else:
            print("NO")


if __name__ == '__main__':
    main()



Measured memory_bytes: 9192
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
using namespace std;

int main(void)
{
	int N; cin >> N;
	set<int> S;
	rep(i, 0, N) {
		int tmp; cin >> tmp;
		S.insert(tmp);
	}
	if (N == S.size())cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;

int main(){

  int n;
  cin >> n;

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  for(int i=0; i<n; i++){
    cin >> b[i];
  }

  for(int i=0; i<n; i++){
    cin >> c[i];
  }

  sort(a.begin(), a.end());
  sort(c.begin(), c.end());

  long long int ans=0, k, x, y;

  for(int i=0; i<n; i++){
    k=b[i];
    x=lower_bound(a.begin(), a.end(), b[i])-a.begin();
    y=c.end()-upper_bound(c.begin(), c.end(), b[i]);
    ans+=x*y;
  }

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

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll n, tmp;
    bool flag = true;
    map<ll, ll> m;

    cin >> n;
    for(ll i = 0; i < n; i++) {
        cin >> tmp;
        if(MFIN(m, tmp)) {
            flag = false;
        } else {
            MINS(m, tmp);
        }
    }
    if(flag) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 16088
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

const ll NUM = 1000000;
std::vector<bool> is_prime(NUM+1, true);

void solve()
{
  std::vector<ll> vprime;
  for (ll i = 2; i < NUM; i ++) {
    if (!is_prime[i]) continue;
    for (ll j = i + i; j < NUM; j += i) is_prime[j] = false;
    vprime.push_back(i);
  }

  ll A, B;
  std::cin >> A >> B;
  if (A > B) std::swap(A, B);

  std::vector<ll> vp;

  ll x = gcd(A, B);
  for (auto prime : vprime) {
    if (x % prime == 0) {
      x /= prime;
      vp.push_back(prime);
      while(x % prime == 0) x /= prime;
    }
  }
  if (x != 1) vp.push_back(x);
  vp.push_back(1);

  print(vp.size());
  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  solve();
  return 0;
}



Measured memory_bytes: 1528
function main(input) {
    var s = input[0].split(" ")[0];
    var t = input[0].split(" ")[1];
    var a = input[1].split(" ")[0]-0;
    var b = input[1].split(" ")[1]-0;
    var u = input[2];
    var map = {[s]: a, [t]: b};
    map[u]--;
    console.log(map[s] + " " + map[t]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main()
{
  map<int, int> mp;
  rep(i, 3) {
    int a;
    cin >> a;
    mp[a]++;
  }
  for (auto m: mp) {
    if (m.second==1) cout << m.first << endl;
  }
  return 0;
}

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

int main()
{
    int n;
    while(cin>>n)
    {
        int q=n/500;
        int f=(n-(500*q))/5;
        printf("%d\n",q*1000+f*5);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define inf 1000000009
#define int long long
typedef pair<int, int> P;
map<int, int> M;
int d[200001], t[200001];
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
		M[d[i]]++;
	}
	int m;
	cin >> m;

	int flg = 0;
	for (int i = 0; i < m; i++) {
		cin >> t[i];
	}
	for (int i = 0; i < m; i++) {
		if (M[t[i]] == 0)flg++;
		else M[t[i]]--;
	}
	if (flg)puts("NO");
	else puts("YES");
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans=0,M=0;
    for (;N--;){
        int A,B; cin >> A >> B;
        if (M<A) M=A,ans=A+B;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left
from itertools import accumulate


def read():
    N, K = map(int, input().strip().split())
    A = map(int, input().strip().split())
    return N, K, A


def solve(N, K, A, NMAX=200001):
    bucket = [0 for i in range(NMAX)]
    for a in A:
        bucket[a] += 1
    bucket.sort()
    S = list(accumulate(bucket))
    l = bisect_left(bucket, 1)
    r = NMAX - K
    return S[r-1] - S[l-1]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 19072
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a[10];
  int i,k;
  for(i=0;i<10;i++){
    cin>>a[i];
  }
  for(i=9;i>0;i--){
    for(k=i-1;k>-1;k--){
      if(a[i]<a[k]) swap(a[i],a[k]);
    }
  }
  cout<<a[9]<<endl;
  cout<<a[8]<<endl;
  cout<<a[7]<<endl;
  return 0;
}

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

int a[100003];

int main()
{
    int N;
    cin >> N;
    while (N--)
    {
        int t;
        cin >> t;
        a[t]++;
        a[t + 1]++;
        a[t + 2]++;
    }
    cout << *max_element(a + 2, a + 100000) << endl;
    return 0;
}

Measured memory_bytes: 3408
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int a[maxn];
bool czy;
int i,j,k,l,t,n,m;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	fo(i,1,n)
		if (i+1>a[i+1]){
			if ((a[i]-i)%2==1){
				czy=1;
				break;
			}
			czy=0;
			fo(j,i+1,n)
				if (a[j]==i) czy^=1;else break;
			break;
		}
	if (czy) printf("First\n");else printf("Second\n");
}

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

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int x=100*a+10*b+c;
  if(x==755 || x==575 || x==557) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
main =
  let 
    func = do
      line <- getLine
      let 
        swap [a,b]
          | a > b     = [b,a]
          | otherwise = [a,b]
        [a,b] = swap $ map read $ words line :: [Int]
        in
          if [a,b] == [0,0] 
            then putStr ""
            else do
              putStrLn $ (show a) ++ " " ++ (show b)
              func
    in func



Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 100005;

ll n, ans, l[N], r[N];

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",&l[i],&r[i]);
	}
	sort(l+1, l+1+n);
	sort(r+1, r+1+n);
	reverse(l+1, l+1+n);
	ll ans = 0;
	for(ll i=1;i<=n;i++) {
		l[i] = l[i-1] + l[i];
		r[i] = r[i-1] + r[i];
		ans = max({ans, l[i]-r[i], l[i-1]-r[i], l[i]-r[i-1]});
	}
	printf("%lld\n",2*ans);
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M, Q;
  in(N); in(M); in(Q);

  int x[500][500];
  rep(i, 500) rep(j, 500) {
    x[i][j] = 0;
  }
  rep(i, M) {
    int l, r;
    in(l); in(r);
    ++x[l-1][r-1];
  }
  int sum[500][501];
  rep(i, 500) {
    sum[i][0] = 0;
    rep(j, 500)
      sum[i][j+1] = sum[i][j] + x[i][j];
  }
  rep(i, Q) {
    int p, q;
    in(p); in(q);
    --p; --q;
    int ans = 0;
    loop(j, p, q+1)
      ans += sum[j][q+1] - sum[j][p];

    out(ans);
  }

  return 0;
}


Measured memory_bytes: 2944
n = int(input())
ln =len(str(n))

if ln ==10:
    ln =9

res = 0

from collections import Counter
import itertools
seq =("3","5","7")

for i in range(3,ln+1):
    temp = list(itertools.product(seq, repeat = i))
    for j in temp:
        ja = Counter(j)
        if ja["3"] * ja["5"] * ja["7"] >0:
            jj = ''.join(j)
            tempp = int(jj)
            if tempp <= n:
                res +=1

print(res)

Measured memory_bytes: 12636
#include <stdio.h>

int main(){

    int j,num,counter[1201];
    char ch;

       for (j=0;j<=(int)('z'-'a');j++){
	  counter[j]=0;
     }  
  
     while(scanf("%c",&ch)!=EOF){
		 
  	 if(ch <= 'Z') {
		  num= (int)(ch-'A');
	  }else if (ch<='z'){
		  num=(int)(ch-'a');
	  } 
		  counter[num]++;
	    }
   
     for (j=0;j<=(int)('z'-'a');j++){
	  printf("%c : %d\n",(char)('a'+j),counter[j]);
     }  
    
	return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll res, f[10000001], t;
int N;

ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1) {
			a = a*x%mod998;
		}
		x = x*x%mod998;
		y /= 2;
	}
	return a;
}

ll modinv(ll x) {
	return pw(x, mod998 - 2);
}

ll comb(int n, int r) {
	return f[n] * modinv(f[r] * f[n - r] % mod998) % mod998;
}

int main() {
	cin >> N;
	f[0] = 1;
	for (int i = 1; i <= 10000000; i++) {
		f[i] = f[i - 1] * i%mod998;
	}
	res = pw(3, N);
	for (int i = N / 2 + 1; i <= N; i++) {
		t += comb(N, i)*pw(2, N - i) % mod998;
		t %= mod998;
	}
	t *= 2;
	t %= mod998;
	res += mod998 - t;
	res %= mod998;
	cout << res << endl;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int max=a;
    if(b>max) max=b;
    if(c>max) max=c;
    cout << a+b+c-max << endl;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i, n;
    int arr[100];
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf(" %d", &arr[i]);
    }
    for(i=0;i<n;i++){
        if(i)printf(" ");
        printf("%d", arr[n-i-1]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2084
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	string s,t; cin >> s >> t;
	ll n = s.size();
	ll m = t.size();
	vvl alpha(26);
	rep(i,n){
		alpha[s[i]-'a'].push_back(i+1);
	}
	ll now = 0;
	ll ans = 0;
	rep(i,m){
		auto itr = upper_bound(all(alpha[t[i]-'a']),now);
		if(alpha[t[i]-'a'].empty()){
			puts("-1");
			return 0;
		}
		if(itr == alpha[t[i]-'a'].end()){
			ans += n - now;
			now = alpha[t[i]-'a'][0];
			ans += now;
		}else{
			ans += *itr - now;
			now = *itr;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1724
//#pragma GCC optimize ("O3,unrolled-loops")
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 305;
double dp[N][N][N];

signed main(){
	fastio
	int n;
	cin >> n;
	int a[3];
	memset(a,0,sizeof a);
	for(int i = 0, tmp;i < n;i++){
		cin >> tmp;
		a[tmp-1]++;
	}

	double p = 1.0/n;
	for(int k = 0;k <= n;k++){
		for(int j = 0;j <= n;j++){
			for(int i = 0;i <= n;i++){
				int z = n-i-j-k;
				if(z < 0) break;
				if(z==n) continue;
				double x = 1-z*p;
				if(i) dp[i][j][k] += dp[i-1][j][k]*i*p;
				if(j) dp[i][j][k] += dp[i+1][j-1][k]*j*p;
				if(k) dp[i][j][k] += dp[i][j+1][k-1]*k*p;
				dp[i][j][k] += 1;
				dp[i][j][k] /= x;
			}
		}
	}
	cout << fixed << setprecision(10) <<  dp[a[0]][a[1]][a[2]] << "\n";
}

Measured memory_bytes: 112544
/**
 *    author:  yoseph
 *    created: 28.08.2020 16:45:26      
**/
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	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 - 1; ++i) {
		if (a[i] > a[i+1]) {
			ans += a[i] - a[i+1];
			a[i+1] = a[i];
		}
	}

	cout << ans << "\n";
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    bool flg = false;

    if(s.size()<t.size()) {
        for(int in=0;in<s.size();in++) {
            if(s.at(in)==t.at(in)) ;
            else break;
            if(in==s.size()-1) {
                flg = true;
            }
        }
    }

    for(int in=0;in<min(s.size(), t.size());in++) {
        if(s.at(in)==t.at(in)) continue;
        else if(s.at(in)<t.at(in)) { 
            flg = true;
        }
        else { 
            ;
        }
    }
    
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++){
    cin >> A[i];
  }
  int x = A[n - 1];
  int c = -1;
  for (int i = 0; i < n - 1; i++){
    if (A[i] <= x){
      c++;
      swap(A[c], A[i]);
    }
  }
  swap(A[c + 1], A[n - 1]);
  for (int i = 0; i < n; i++){
    cout << A[i];
    if (i == c + 1){
      cout << ']';
    }
    if (i < n - 1){
      cout << ' ';
    }
    if (i == c){
      cout << '[';
    }
  }
  cout << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int main() {
	int N; cin >> N;
	string S; cin >> S;
	int ans = 1;
	for (int i = 1; i < N; i++) {
		if (S.at(i) != S.at(i - 1)) ans++;
	}
	cout << ans << endl;
}

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


typedef long long ll;
typedef unsigned long long ull;


int n;
const int maxn = 1e5+1;
ll p;
struct Data
{
  ll w, b;
  inline ll evaluate() const
  {
    return (100-p)*w+p*b;
  }
  bool operator<(const Data & r) const
  {
    return evaluate() > r.evaluate();
  }
  inline void read()
  {
    scanf("%lld %lld", &w, &b);
  }
} e[maxn];

int main()
{
  scanf("%d %lld", &n, &p);
  for (int i = 0; i < n; ++i)
    e[i].read();
  sort(e, e+n);
  ll sum = 0;
  for (int i = 0; i < n; ++i)
    sum += e[i].b;
  ll W = 0, B = 0;
  for (int i = 0; i < n; ++i)
    {
      W += e[i].w;
      B += e[i].b;
      if (W*(100-p)+p*B >= p*sum)
	{
	  printf("%d\n", i+1);
	  return 0;
	}
    }
    
    
}


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

const int nil = -1;
struct Node {int p, l, r;};
Node T[1000];
int n;

void preParse(int u) {
    cout << " " << u;
    if (T[u].l != nil) preParse(T[u].l);
    if (T[u].r != nil) preParse(T[u].r);
}

void inParse(int u) {
    if (T[u].l != nil) inParse(T[u].l);
    cout << " " << u;
    if (T[u].r != nil) inParse(T[u].r);
}

void postParse(int u) {
    if (T[u].l != nil) postParse(T[u].l);
    if (T[u].r != nil) postParse(T[u].r);
    cout << " " << u;
}

int main(void) {
    int p, l, r, root;
    cin >> n;
    for (int i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = nil;
    for (int i = 0; i < n; i++) {
        cin >> p >> l >> r;
        T[p].l = l;
        T[p].r = r;
        if (l != nil) T[l].p = p;
        if (r != nil) T[r].p = p;
    }

    for (int i = 0; i < n; i++)
        if (T[i].p == nil) root = i;

    cout << "Preorder" << endl;
    preParse(root);
    cout << endl << "Inorder" << endl;
    inParse(root);
    cout << endl << "Postorder" << endl;
    postParse(root);
    cout << endl;

    return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e10;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;


int main() {
    int n;
    double t, a;
    cin >> n >> t >> a;

    pair<double, int> ans(INF, 0);

    rep(i, n) {
        double h;
        cin >> h;

        double x = t - (h * 0.006);

        double diff = abs(a - x);
        pair<double, int> now(diff, i + 1);
        ans = min(ans, now);
    }

    cout << ans.second << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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 main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  // ll res = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string S;
  cin >> S;
  int N = S.size();
  int P = 2019;
  //   if(P==2||P==5){
  //     long long res=0;
  //     for(int i=0;i<N;i++) if((S[N-i-1]-'0')%P==0) res+=N-i;
  //     return res;
  // }
  vector<long long> val(P, 0);
  long long tenfactor=1;
  long long cur=0;
  val[cur]++;

  for(int i=0;i<N;i++){
      cur=(cur+(S[N-i-1]-'0')*tenfactor)%P;
      tenfactor=(tenfactor*10)%P;
      val[cur]++;
  }
  long long res=0;
  for(int p=0;p<P;p++) res+=val[p]*(val[p]-1)/2; 
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 3740
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1000000007;

int n, m;
vector<ll> x(101010);
vector<ll> y(101010);

int main(){
  cin >> n >> m;
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];

  ll xsum = 0;
  rep(i, n){
    xsum += ((2 * i) - (n - 1)) * x[i];
    xsum = xsum % mod;
  }

  ll ysum = 0;
  rep(i, m) {
    ysum += ((2 * i) - (m - 1)) * y[i];
    ysum = ysum % mod;
  }
  cout << (xsum*ysum) % mod << endl;
  return 0;
}


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

int main(void){
    int i,j,len;
    char S[101],T[101],temp;
    scanf("%s%s",S,T);
    len = strlen(S);
    for(i=0;i<len;i++){
        if(strcmp(S,T)==0){
            printf("Yes\n");
            return 0;
        }
        temp=S[0];
        for(j=0;j<len-1;j++){
            S[j]=S[j+1];
        }
        S[len-1]=temp;
    }
    printf("No\n");
    return 0;
}





Measured memory_bytes: 128
N = list(input())
jud = True
for i in range(0,len(N)):
  if i%2 == 0:
    if N[i] == 'L':
      jud = False
  if i%2 == 1:
    if N[i] == 'R':
      jud = False
if jud:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import sys
from collections import deque
N = int(input())
E = [tuple(map(lambda x: int(x) - 1, sys.stdin.readline().split())) for _ in range(N - 1)]
G = [[] for _ in range(N)]
for a, b in E:
    G[a].append(b)

colornum = len(G[0])
colors = [{} for _ in range(N)]
todo = deque()
for i, p in enumerate(G[0]):
    colors[0][p] = i
    todo.append((0, p))

while todo:
    pp, p = todo.popleft()
    colornum = max(colornum, len(G[p]) + 1)
    c = colors[pp][p]
    for np in G[p]:
        c = (c + 1) % colornum
        colors[p][np] = c
        todo.append((p, np))

print(colornum)
for a, b in E:
    print(colors[a][b] + 1)

Measured memory_bytes: 48128