akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def solve(a, b, c):
    if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
        return 0

    a2 = a // 2
    b2 = b // 2
    c2 = c // 2

    return solve(b2 + c2, a2 + c2, a2 + b2) + 1


def main():
    A, B, C = map(int, input().split())
    if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
        print(0)
        return
    if A == B == C:
        print(-1)
        return

    print(solve(A, B, C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import math 

nd = input().split()
nd = [int(x) for x in nd]
n=nd[0]
d=nd[1]

x_list =[]
y_list =[]

# n = 4
# d = 5

# x_list =[0,-2,3,4]
# y_list =[5,4,4,-4]



def count(x_list,y_list,d,n):
    cnt =0
    for i in range(n):
        # print(math.sqrt(x_list[i]**2 +y_list[i]**2),d)
        if math.sqrt(x_list[i]**2 +y_list[i]**2) <=d:
            cnt +=1
        
    return cnt


for i in range(n):
    xy = input().split()
    xy = [int(k) for k in xy]
    x_list.append(xy[0])
    y_list.append(xy[1])

print(count(x_list,y_list,d,n))


Measured memory_bytes: 24856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, M;
    cin >> N >> M;
    VP r(M);
    rep(i, 0, M) cin >> r[i].second >> r[i].first;
    sort(ALL(r));
    ll ans = 0, head = -1;
    rep(i, 0, M){
        if(head < r[i].second){
            head = r[i].first - 1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=0;
int n,k,x,t,a,b;
string s,s1;
vector<int>v;
int main(){

	cin >> s >> s1;
	n = s.length(),k=s1.length();
	vector<vector<int>>dp;
	v.resize(3005,0);
	dp.resize(3005,v);
	for(int i =1;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(s[i-1]==s1[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			}else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}	
	}
	string ans="";

	while(n>0&&k>0){
		if(dp[n][k] == dp[n-1][k]){
			n--;
			continue;
		}
		if(dp[n][k] == dp[n][k-1]){
			k--;
			continue;
		}
		if(dp[n][k]==0)break;
		n--,k--;
		ans+=s[n];
	}
	if(ans.length())
		reverse(all(ans));
	cout << ans;
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;



    int a[210000];
    int main(){
        int n, k;
        std::cin >> n >> k;
        std::vector<int> h(n);
        rep(i, n) std::cin >> h[i];
        sort(h.begin(), h.end());
        k = min(n, k);
        ll ans = 0;
        rep(i, k){
            h.pop_back();
        }
        rep(i, h.size()) ans += h[i];
        std::cout << ans << "\n";
        return 0;
    }


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;

    ll ans = (I / 2 + J / 2 + L / 2) * 2 + O;

    if(I&&J&&L) {
        I--; J--; L--;
        smax(ans, 3 + (I / 2 + J / 2 + L / 2) * 2 + O);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const int N = 1e5 + 18;



int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {

        int n; cin >> n;
        string s;
        cin >> s;
        int sum = 0;
        for (int i = 0; s[i]; i++) {
            if (s[i] == 'R')
                sum++;
        }
        int cnt = 0;
        for (int i = 0; i < sum; i++) {
            if (s[i] == 'R')
                cnt++;
        }
        cout << sum - cnt;

    }
    return 0;

}



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

int main() {
  int n,q;
  cin >> n >> q;
  int dp[n][2];
  memset(dp,0,sizeof(dp));
  dp[0][0]=dp[1][1]=1;
  while(q--) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    swap(dp[x][0],dp[y][0]);
    swap(dp[x][1],dp[y][1]);
    if(y>0) {
      dp[y-1][1]|=dp[y][0];
      dp[y][1]|=dp[y-1][0];
    }
    if(y+1<n) {
      dp[y+1][1]|=dp[y][0];
      dp[y][1]|=dp[y+1][0];
    }
    if(x>0) {
      dp[x-1][1]|=dp[x][0];
      dp[x][1]|=dp[x-1][0];
    }
    if(x+1<n) {
      dp[x+1][1]|=dp[x][0];
      dp[x][1]|=dp[x+1][0];
    }
  }
  int ans=0;
  for(int i=0; i<n; i++) {
    int f=dp[i][0]|dp[i][1];
    if(i) f|=dp[i-1][0];
    if(i+1<n) f|=dp[i+1][0];
    ans+=f;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const double PI = acos(-1);

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

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

int main() {
	int n, d;

	cin >> n >> d;

	int cnt = 0;

	int x[10][10];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			int num;
			cin >> num;
			x[i][j] = num;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			double num = 0.0;
			for (int k = 0; k < d; k++) {
				num += pow(abs(x[i][k] - x[j][k]), 2);
			}
			num = sqrt(num);
			if (ceil(num) == floor(num)) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void)
{
  int h, w;
  cin >> h >> w;
  vec<vec<int> > a(h, vec<int>(w, - 1));
  queue<pair<int, int> > q;
  rep(i, h) rep(j, w) {
    char get;
    cin >> get;
    if (get == '#') {
      q.push(make_pair(i, j));
      a[i][j] = 0;
    }
  }

  while(!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    rep(i, 4) {
      int x = p.first + dx[i];
      if (x >= h || x < 0) continue;
      int y = p.second + dy[i];
      if (y >= w || y < 0) continue;
      if (a[x][y] >= 0) continue;
      a[x][y] = a[p.first][p.second] + 1;
      q.push(make_pair(x, y));
    }
  }

  int ans = 0;
  rep(i, h) rep(j, w) {
    if (ans < a[i][j]) ans = a[i][j];
  }

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




Measured memory_bytes: 12032
def main():
    k = int(input())
    a, b = input_list()

    for i in range(a, b+1):
        if i % k == 0:
            print('OK')
            exit()
    print('NG')


def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61724
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
   input! {
      n: usize,
      k: usize,
      mut a: [usize; n],
   }
   if n <= k {
      for _ in 0..n {
         print!("{} ", n);
      }
      println!("");
      return;
   }

   for _ in 0..k {
      let mut bit = vec![0; n + 1];
      for i in 0..n {
         if i >= a[i] {
            bit.add(i - a[i], 1);
         } else {
            bit.add(0, 1);
         }
         if i + a[i] < n - 1 {
            bit.add(i + a[i] + 1, -1);
         }
      }
      let mut flag = true;
      for i in 0..n {
         a[i] = bit.sum(i) as usize;
         if a[i] != n {
            flag = false;
         }
      }
      if flag {
         break;
      }
   }
   for i in 0..n {
      print!("{} ", a[i]);
   }
   println!("");
}

use std::ops::{AddAssign, Sub};
trait BIT<T: Copy + Clone + Sub + AddAssign> {
   fn add(&mut self, idx: usize, w: T);
   fn sum(&self, idx: usize) -> T;
   fn range(&self, l: usize, r: usize) -> T;
}
impl<T: Copy + Clone + Sub<Output = T> + AddAssign> BIT<T> for [T] {
   /// let mut bit = vec![0; n+1];
   /// for i in 0..q {
   ///    bit.add(i, w[i]);
   /// }
   fn add(&mut self, idx: usize, w: T) {
      let mut j = (idx + 1) as i64;
      while j < self.len() as i64 {
         self[j as usize] += w;
         j += j & -j;
      }
   }
   /// [0, r]
   fn sum(&self, idx: usize) -> T {
      let mut i = (idx + 1) as i64;
      let mut sum = self[0];
      while i != 0 {
         sum += self[i as usize];
         i -= i & -i;
      }
      sum
   }
   /// [l, r)
   fn range(&self, l: usize, r: usize) -> T {
      match (l, r) {
         (0, _) => self.sum(r - 1),
         _ => self.sum(r - 1) - self.sum(l - 1),
      }
   }
}


Measured memory_bytes: 5520
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <map>
#include <array>

using namespace std;

#define MAX_N 100

int main()
{
    int N, D, X, A;
    string s;
    map<string, int> mp;

    scanf("%d %d %d", &N, &D, &X);

    for (int i = 0; i < N; i++)
    {
        scanf("%d", &A);
        X += D / A + 1;
        if (D % A == 0)
            X--;
    }

    printf("%d\n", X);

    return 0;
}


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


// Watch, 0 <= S <= 86400, HH:mm:ss
int main(){
	int h, m, s, S;

	cin >> S;

	h = floor(S/3600);
	S = S % 3600;

	m = floor(S/60);
	S = S % 60;

	s = S;

	cout << h << ':' << m << ':' << s << endl;
	return 0;
}


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

int main() {
  int N,A,B;
  cin >> N >> A >>B;
  
  int sum = 0;
  int i = 1;
  while(i <= N){
    int Q = i;
    int R = 0;
    int C = 0;
    
    while(true){
      if(Q == 0){
        break;
      }
      R = Q%10;
      Q = Q/10;
      C += R;
    }
    if(C >= A && C <= B){
      sum += i;
    }
    i++;
  }
    cout << sum << endl;
  }
    
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(), (obj).end()


int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	int mx = min(A, B);
	int s = N - A;
	int mn = max(0, B - s);
	printf("%d %d\n", mx, mn);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
	ll l,r;
	cin>>l>>r;
	if(r-l>=2019)
	{
		cout<<0;
		return;
	}
	ll ans=2018;
	for(ll i=l;i<=r;i++)
	{
		for(ll j=i+1;j<=r;j++)
			ans=min(ans,((i*j)%2019));
	}
	cout<<ans;
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <algorithm>

using namespace std;

const long long mod = 998244353;
const long long del = 93000;
long long n;
long long a[1200];
long long dp[2][191000][4];
long long ans;
long long ksm ( long long f , long long x ) {
	long long s = 1;
	while ( x ) {
		if ( x % 2 ) s = s * f % mod;
		f = f * f % mod; x = x / 2;
	}
	return s % mod;
}
void work () {
	long long i , j , k , s;
	scanf ( "%lld" , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%lld" , &a[i] );
	}
	s = 0;
	dp[0][del][0] = 1;
	for ( i = 0 ; i < n ; i++ ) {
		s += a[i+1];
		for ( j = -s ; j <= s ; j++ ) {
			for ( k = 0 ; k <= 3 ; k++ ) {
				dp[(i+1)%2][del+j][k] = 0;
			}
		}
		for ( j = -s ; j <= s ; j++ ) {
			for ( k = 0 ; k <= 3 ; k++ ) {
				dp[(i+1)%2][del+j+a[i+1]][k] = (dp[(i+1)%2][del+j+a[i+1]][k] + dp[i%2][del+j][k]) % mod;
				dp[(i+1)%2][del+j-a[i+1]][k|1] = (dp[(i+1)%2][del+j-a[i+1]][k|1] + dp[i%2][del+j][k]) % mod;
				dp[(i+1)%2][del+j-a[i+1]][k|2] = (dp[(i+1)%2][del+j-a[i+1]][k|2] + dp[i%2][del+j][k]) % mod;
			}
		}
	}
	ans = ksm ( 3 , n );
	ans = (ans - ksm ( 2 , n ) * 3 + ksm ( 1 , n ) * 3 ) % mod;
	ans = (ans + mod) % mod;
	for ( i = 0 ; i <= s ; i++ ) {
		ans = (ans - dp[n%2][del+i][3]*3) % mod;
	}
	ans = (ans + mod) % mod;
	printf ( "%lld\n" , ans );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 11776
import java.util.ArrayList;
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 = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    }

}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
 
int main()
{
  cin>>n>>a>>b;
  if(a==0) cout<<0;
  else
  {
    if(n>a+b)
    {
     ll s=a+b;
     ll d=n/s;
     ll r=n - d*s;
      if(r>a) r=a;
      cout<<d*a+r;
    }
    else 
    {
      if(n>=a) cout<<a;
      else cout<<n;
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<vector<ll> >mat;
ll mod = 1000000007;
mat e;
void makee(int n)
{
	e.clear();
	e.resize(n);
	for (int i = 0; i<n; i++)
	{
		for (int j = 0; j<n; j++)
		{
			e[i].push_back(i == j);
		}
	}
}
mat tim(mat a, mat b)
{
	mat ret;
	ret.resize(a.size());
	for (int i = 0; i<a.size(); i++)ret[i].resize(b[0].size());
	for (int i = 0; i<a.size(); i++)
	{
		for (int j = 0; j<b[0].size(); j++)
		{
			for (int k = 0; k<a[0].size(); k++)
			{
				ret[i][j] += a[i][k] * b[k][j];
				if (k == ((k >> 3) << 3))ret[i][j] %= mod;
			}
			ret[i][j] %= mod;
		}
	}
	return ret;
}
mat po(mat a, ll b)
{
	if (b == 0)return e;
	mat z = po(a, b / 2);
	z = tim(z, z);
	if (b % 2 == 1)z = tim(z, a);
	return z;
}
int main()
{
	makee(3);
	mat m = e;
	m[0][0] = 2, m[0][1] = 2, m[0][2] = 1;
	m[1][0] = 1, m[1][1] = 1, m[1][2] = 1;
	m[2][0] = 1, m[2][1] = 0, m[2][2] = 1;
	mat n = e;
	n[0][0] = 1, n[0][1] = 2, n[0][2] = 1;
	n[1][0] = 0, n[1][1] = 1, n[1][2] = 1;
	n[2][0] = 0, n[2][1] = 0, n[2][2] = 1;
	int num, ban;
	scanf("%d%d", &num, &ban);
	int now = 0;
	mat r;
	r.push_back(vector<ll>(1, 0));
	r.push_back(vector<ll>(1, 0));
	r.push_back(vector<ll>(1, 1));
	for (int i = 0; i <= ban; i++)
	{
		int t;
		if (i == ban)t = num;
		else scanf("%d", &t);
		mat z = po(m, t - now);
		now = t + 1;
		r = tim(z, r);
		if (i != ban)r = tim(n, r);
	}
	printf("%lld\n", r[0][0]);
}

Measured memory_bytes: 384
#include<stdio.h>
 
int main(void){
 
int a,b,c,d,e;
int k;	//check
int less=0;
 
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
  scanf("%d",&k);
//E
  if(e-d>k)
      less=1;
  if(e-c>k)
    less=1;
  if(e-b>k)
    less=1;
  if(e-a>k)		
    less=1;	
  //D
  if(d-c>k)
      less=1;
  if(d-b>k)
    less=1;
  if(d-a>k)
      less=1;	
   //C
    if(c-b>k)
      less=1; 
  if(c-a>k)
      less=1;	
  //B
  	if(b-a>k)
      less=1;	
  
  if(less==1)
      printf(":(\n");  
  else if(less==0)
         printf("Yay!\n");
 
return 0;
 
}

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

int main()
{
    long long  a,b,c;
    cin >> a;
    long long count=1;
   for(int i=1;i<100000;i++){
       if(i*i>a){
           break;
       }
       count=i*i;
   }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t A, B;
	cin >> A >> B;

	int32_t res = A + B;
	res = max(res, A - B);
	res = max(res, A * B);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    ll n, m, k;
    cin>>n>>m>>k;
    ll a[n];
    lp(0,n) cin>>a[i];
    ll b[m];
    lp(0,m) cin>>b[i];
    bool fl1=false, fl2=false;
    ll op1=0, op2=0, ans=0;
    
    lp(1,n){
        a[i] += a[i-1];
    }
    
    lp(1,m){
        b[i] += b[i-1];
    }
    ans = lower_bound(b, b+m, k)-b;
    if(ans<m and b[ans]==k){
        ans++;
    }
    
    ll i=0;
    while(i<n and a[i]<=k){
        ll rem = k-a[i];
        if(rem==0){
            ans = max(ans, i+1);
            break;
        }
        if(rem<0){
            ans = max(ans, i);
            break;
        }
        ll p = lower_bound(b, b+m, rem)-b;
        
        if(p<m and b[p]==rem){
            p++;
        }
        
        ans = max(i+1+p, ans);
        i++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6748
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    ans = 0
    for p in range(K,N+2):
        ans += p*(N-p+1) + 1
        ans %= MOD
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 63224
main(){
  int i,m,d,a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
  char s[7][10]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
  for(;;){
    scanf("%d%d",&m,&d);
    if(m==0)
      break;
    for(i=0;i<m-1;i++)
      d+=a[i];
    printf("%s\n",s[d%7]);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;
 
 
 
/*void SieveOfEratosthenes(int n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 

    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++) 
    if (prime[p]) 
        cout << p << " "; 
} */

int main() 
{ 
    string s;
    cin>>s;
    int n=s.size(),count=0;
    pan(i,n/2){
        if(s[i]!=s[n-1-i]) {count++;
//cout<<s[i]<<" ";
        }
    }
    cout<<count;
} 


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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int64_t N, K;
    cin >> N >> K;

    vector<int64_t> list(N);
    vector<int64_t> route(N + 1);
    vector<bool> arrived(N, false);

    for (int64_t i = 0; i < N; i++)
    {
        cin >> list[i];
        list[i]--; 
    }
    int64_t now = 0;
    int64_t roop, amari; //何回周期か
    arrived[0] = true;
    route[0] = 0;

    for (int64_t i = 0; i < N; i++)
    {
        now = list[now];
        route[i + 1] = now;
        //訪問済み
        if(arrived[now])
        {
            for (int64_t j = 0; j <= i; j++)
                if (route[j] == now)
                {
                    amari = j;
                    roop = i - j + 1;
                }       
            break;
        }
        else
            arrived[now] = true;
    }

    if (amari + roop <= K)
    {
        K -= amari;
        K %= roop;
        K += amari;
    }

    now = 0;

    for (int64_t i = 0; i < K; i++)
    {
        now = list[now];
    }
    cout << now + 1;
}

Measured memory_bytes: 6376
N, A, B = map(int, input().split())
if (B-A) % 2 == 0:
    print(int((B-A) // 2))
else:
    first = (A-1) + 1 + int((B-A-1)//2)
    last = (N-B) + 1 + int((B-A-1)//2)

    print(min(first, last))

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>
#include <chrono>

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	REP(i,3){
		int h1, m1, s1, h2, m2, s2, h, m, s;
		cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
		s = (s2 - s1 + 60) % 60;
		if (s2 < s1) m2 -= 1;
		m = ((m2 + 60)%60 - m1 + 60) % 60;
		if (m2 < m1) h2 -= 1;
		h = ((h2 + 24)%24 - h1 + 24) % 24;
		print(h, m, s);
	}

	return 0;
}



Measured memory_bytes: 3088
n = int(input())
a = list(map(int, input().split()))
 
if n % 2 == 0:
    for i in reversed(range(1, n, 2)):
        print(a[i],end=" ")
    for i in range(0,n-1,2):
        print(a[i],end=" ")
elif n % 2 == 1:
    for i in reversed(range(0, n, 2)):
        print(a[i],end=" ")
    for i in range(1, n, 2):
        print(a[i],end=" ")

Measured memory_bytes: 93908
#include <iostream>
#include <cmath>

using namespace std;

int main(void){
    int h, m, s;
    
    cin >> s; cin.ignore();
    h = s/3600; s -= 3600*h;
    m = s/60; s -= 60*m;
    cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define INF (~(1 << 31))
using namespace std;

int f(vector< int > &v){
	int res = 0;
	
	for(vector< int >::iterator it = v.begin(); it != v.end(); ++it){
		res = res * 10 + (*it);
	}
	
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int p[8];
	int m[8] = {4, 1, 4, 1, 2, 1, 2, 1};
	vector< int > c(m, m + 8);
	
	while(cin >> p[0] >> p[1] >> p[2] >> p[3] >> p[4] >> p[5] >> p[6] >> p[7]){
		
		int min = INF;
		int res = INF;
		stringstream ss;
		string str;
		
		REP(i, 8){
			int r = 0;
			rotate(c.begin(), c.begin() + 1, c.end());
			
			REP(j, 8){
				r += (p[j] - c[j] < 0 ? 0 : p[j] - c[j]);
			}
			
			if(r < min){
				min = r;
				res = f(c);
			}else if(r == min){
				if(f(c) < res){
					res = f(c);
				}
			}
		}
		
		REP(i, 8){
			ss << (i ? " " : "") << (res % 10);
			res /= 10;
		}
		
		str = ss.str();
		reverse(ALL(str));
		
		cout << str << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

double p[200010];
double sum[200010];
int main()
{
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < N; i++) {
		sum[i + 1] = sum[i] + (double)(p[i] * (p[i] + 1.0) / 2) / p[i];
		//cout << sum[i + 1] << endl;
	}
	double ans = 0.0;
	for (int i = 0; i <= N - K + 1; i++) {
		ans = max(ans, sum[i + K] - sum[i]);
	}
	printf("%.7f\n", ans);
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll x,y;
  cin >>x >>y;
  put(x+y/2);
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    map<string,int>m;
    m["SUN"]=7;
    m["MON"]=6;
    m["TUE"]=5;
    m["WED"]=4;
    m["THU"]=3;
    m["FRI"]=2;
    m["SAT"]=1;
    string s;
    cin>>s;
    cout<<m[s]<<endl;
    return 0;
}


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

public class Main {
 public static void main(String[] args) {
	final Map<Character, Integer> map = new HashMap<Character, Integer>();
	map.put(Character.valueOf('I'), Integer.valueOf(1));
	map.put(Character.valueOf('V'), Integer.valueOf(5));
	map.put(Character.valueOf('X'), Integer.valueOf(10));
	map.put(Character.valueOf('L'), Integer.valueOf(50));
	map.put(Character.valueOf('C'), Integer.valueOf(100));
	map.put(Character.valueOf('D'), Integer.valueOf(500));
	map.put(Character.valueOf('M'), Integer.valueOf(1000));
	Scanner in = new Scanner(System.in);
	while (in.hasNext()) {
	 char[] q = in.next().toCharArray();
	 int val = 0;
	 int pre = 0;
	 for (int i = q.length - 1; i >= 0; i--) {
		int cVal = map.get(Character.valueOf(q[i])).intValue();
		if (cVal >= pre) {
		 val += cVal;
		} else {
		 val -= cVal;
		}
		pre = cVal;
	 }
	 System.out.println(val);
	}
 }
}

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

int main() {
    int d = 0, e = 0, f = 0, g, h;
    char a, b, c;
    cin >> a >> b >> c;

    if (a == 'o') {
        d = 1;
    }

    if (b == 'o') {
        e = 1;
    }

    if (c == 'o') {
        f = 1;
    }

    g = d + e + f;

    h = 700 + 100 * g;

    cout << h;

    return 0;
}

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

int MAX = 100000;
vector<vector<pair<int,int>>> g(MAX, vector<pair<int,int>>(0));
int farthest_end;
int diameter;

void bfs(int start) {
    vector<int> d(MAX, -1);
    int max_d = -1;
    queue<int> q;
    q.push(start);
    d[start] = 0;
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        rep(i, g[cur].size()) {
            int adj = g[cur][i].first;
            if (d[adj] == -1) {
                q.push(adj);
                d[adj] = d[cur] + g[cur][i].second;
                // printf("始点%dから点%dまでの距離は%d\n", start, adj, d[adj]);
                if (d[adj] > max_d) {
                    max_d = d[adj];
                    farthest_end = adj;
                    diameter = max_d;
                }
            }
        }
    }
    // printf("始点%dから最も遠い点は%dでその距離は%d\n", start, farthest_end, max_d);
}

int main() {
    int n;
    scanf("%d", &n);
    rep(i, n-1) {
        int s, t, w;
        scanf("%d %d %d", &s, &t, &w);
        g[s].push_back({t,w});
        g[t].push_back({s,w});
    }
    bfs(0);
    bfs(farthest_end);
    printf("%d\n", diameter);
}


Measured memory_bytes: 9708
N,M = map(int,input().split())
if M % 2 == 1:
    for i in range(M // 2):
        print(1 + i, M - i)
    for i in range(M - M // 2):
        print(M + 1 + i, 2 * M + 1 - i)
else:
    for i in range(M // 2):
        print(1 + i, M + 1 - i)
        print(M + 2 + i, 2 * M + 1 - i)

Measured memory_bytes: 9276
#include<stdio.h>
int main(void)
{
	while(1){
		int s[5],s1,s2,p=0,i,j,m=0;
		for(i=0;i<5;i++){
			scanf("%d %d",&s1,&s2);
			s[i]=s1+s2;
			if(s[i]>m){
				m=s[i];
				j=i;
			}
			if(s1==0&&s2==0){
				p=1;
				i=99;
			}
		}
		if(p!=0){
			break;
		}
		if(j==0){
			printf("A %d\n",m);
		}
		else if(j==1){
			printf("B %d\n",m);
		}
		else if(j==2){
			printf("C %d\n",m);
		}
		else if(j==3){
			printf("D %d\n",m);
		}
		else{
			printf("E %d\n",m);
		}
	}
	return 0;
}

Measured memory_bytes: 600
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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


ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}



int main(){fastio
    ll N=100005;
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll rui[N];rui[0]=rui[1]=0;
    rep(i,2,N-1)rui[i]=bunbo(i);
    rep(i,3,N-1)Add(rui[i],rui[i-1]);
    
    ll ans=0;
    rep(i,0,n-1){
        ll sum=1+rui[i+1]+rui[n-i];
        //cout<<i<<":"<<sum<<endl;
        Add(ans,sum*a[i]);
    }
    rep(i,1,n)ans=mod(ans*i);
    cout<<mod(ans)<<endl;
    
    return 0;
}


Measured memory_bytes: 1792
//ynymxiaolongbao is a really pro!
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
struct Manju {
	short k[10];
};
bool operator< (const Manju& m1, const Manju& m2) {
	for (int i = 0; i < 10; i++) {
		if (m1.k[i] < m2.k[i])return true; if (m1.k[i] > m2.k[i])return false;
	}
	return false;
}
vector<Manju>dp[11][11], S;//dp[end][sum]
map<pair<int, Manju>, int>M;
void init() {
	Manju MM; for (int i = 0; i < 10; i++)MM.k[i] = 0; dp[0][0].push_back(MM);
	for (int i = 0; i < 9; i++) {
		for (int j = 0; j <= 10; j++) {
			for (int k = 0; k < dp[i][j].size(); k++) {
				for (int l = 0; l <= 10; l++) {
					int SUM = j + l*(i + 1); Manju P = dp[i][j][k];
					if (SUM > 10)continue;
					P.k[i + 1] = l; dp[i + 1][SUM].push_back(P);
				}
			}
		}
	}
	S = dp[9][10];
}
int manju(int pos, Manju T) {
	if (pos == S.size())return 0;
	if (M[make_pair(pos, T)] != 0)return M[make_pair(pos, T)];
	int maxn = 0, cnt = 0; Manju U = T;
	while (true) {
		maxn = max(maxn, manju(pos + 1, U) + cnt);
		for (int i = 0; i < 10; i++) { U.k[i] -= S[pos].k[i]; }
		bool flag = true; for (int i = 0; i < 10; i++) { if (U.k[i] < 0)flag = false; }
		if (flag == false)break;
		cnt++;
	}
	M[make_pair(pos, T)] = maxn;
	return  maxn;
}
int main() {
	init(); int n;
	while (true) {
		cin >> n; M.clear(); if (n == 0)break; Manju A; for (int i = 0; i < 10; i++)A.k[i] = 0; int adv = 0;
		for (int i = 0; i < n; i++) { int W; cin >> W; if (W >= 1 && W <= 9)A.k[W]++; if (W == 10)adv++; }
		for (int i = 1; i < 5; i++) { int WW = min(A.k[10 - i], A.k[i]); A.k[10 - i] -= WW; A.k[i] -= WW; adv += WW; }
		adv += A.k[5] / 2; A.k[5] %= 2;
		cout << manju(0, A) + adv << endl;
	}
	return 0;
}

Measured memory_bytes: 63796
#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int b[205][205];

int main()
{
    int i,j,m,n,k,h,w;
    cin>>h>>w;
    for(i=0;i<10;i++)
        for(j=0;j<10;j++)
            cin>>a[i][j];
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
            cin>>b[i][j];
    for(k=0;k<10;k++)
        for(i=0;i<10;i++)
            for(j=0;j<10;j++)
                a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    int ans=0;
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
            if(b[i][j]>=0) ans += a[ b[i][j] ][1];
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	
	string ans = "";
	int n;
	cin>>n;
	for(int i = 0;i<n;i++){
		ans += "ACL";
	}

	cout<<ans;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
int main(){
    long long d, g;
    cin >> d >> g;
    vector<long long> p(d), c(d), score(d);
    for(int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
        score[i] = (i + 1) * 100;
    }
    long long ans = INF;
    for(int bit = 0; bit < (1 << d); bit++){
        long long G = g;
        long long res = 0;
        vector<int> flag(d, 1);
        for(int i = 0; i < d; i++){
            if(bit & (1 << i)) {
                G -= p[i]*score[i] + c[i];
                flag[i] = 0;
                res += p[i];
            }
        }
        int t = -1;
        for(int j = 0; j < d; j++){
            if(flag[j] == 1) t = j;
        }
        if(G > 0 && G <= p[t] * score[t] + c[t]){
            res += min(p[t], (G + score[t] - 1) / score[t]);
            ans = min(res, ans);
        }
        else if(G <= 0) ans = min(res, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define reps(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)
typedef long long int ll;
using namespace std;


struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;



int main(){
    int N,M;
    cin>>N>>M;
    int A[N];
    rep(i,N){
        cin>>A[i];
    }
    vector<pair<int,int>> BC(M);
    
    rep(i,M){
        cin>>BC[i].second>>BC[i].first;

    }
    sort(A,A+N);
    sort(BC.begin(),BC.end());
    int imabasho=0;
    int now = M-1;
    while(now<M && imabasho<N && A[imabasho]<BC[now].first){
        int count = 0;
        while(count<BC[now].second && A[imabasho]<BC[now].first){
            A[imabasho]=BC[now].first;
            imabasho++;
            count++;
        }
        now--;
    }

    long long int sum = 0;
    rep(i,N){
        sum+=A[i];
    }
    cout<<sum<<endl;


    return 0;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline

import copy

def main(): 

    row = list(input().split())
    row = list(map(int,row[0]))

    S = copy.deepcopy(row)
    count = 0
    for i in range(1,len(S)):
        if S[i-1] == S[i]:
            if S[i-1] == 1: S[i] = 0
            else: S[i] = 1
            count+=1

    S = copy.deepcopy(row)
    count2 = 1
    if S[0] == 1: 
        S[0] = 0
    else: 
        S[0] = 1
    for i in range(1,len(S)):
        if S[i-1] == S[i]:
            if S[i-1] == 1: S[i] = 0
            else: S[i] = 1
            count2+=1
    print(min(count,count2))

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 5920
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,N,M;
  cin >> N >> M;
  vector<int>DP(N,INF),Ct(N,0);
  rep(i,0,N)cin >> Ct[i];
  DP[0]=0;
  rep(i,0,N)rep(j,1,M+1){
    if(i+j>N-1)continue;
    chmin(DP[i+j],DP[i]+abs(Ct[i]-Ct[i+j]));
  }
  Out(DP[N-1]);
}

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

int main() {
  int a,b,c,E,W;
  int count = 0;
  cin >> a >> b >> c;
  W = b-a;
  for(int i = 0; i < W+1; i++){
      E = c%(a+i);
      if(E == 0){
          count++;
      }
  }
  cout << count << endl;
  
}


Measured memory_bytes: 3108
n,q  = map(int,input().split())

s = input()
t = [0]*(n+1)
for i in range(n):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC"  else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])

Measured memory_bytes: 7748
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 400001
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};


main(){
    ll n=lin();
    priority_queue<ll> p1;
    priority_queue<ll,vector<ll>,greater<ll>> p2;
    ll ans=0;
    ll d=0;
    ll l=lin(),r=lin();
    ll mid=l+r;
    ll length=r-l;
    p1.push(mid);
    p2.push(mid);
    rep(i,n-1){
        l=lin();r=lin();
        d+=length+r-l;
        length=r-l;
        mid=l+r;
        ll n1=p1.top()-d,n2=p2.top()+d;
        if(mid<=n1){
            p2.push(n1-d);
            p1.pop();
            p1.push(mid+d);p1.push(mid+d);
            ans+=p2.top()+d-mid;
        }
        else if(n1<mid&&mid<=n2){
            p1.push(mid+d);
            p2.push(mid-d);
        }
        else{
            p1.push(n2+d);
            p2.pop();
            p2.push(mid-d);p2.push(mid-d);
            ans+=mid-(p1.top()-d);
        }
    }
    cout<<ans/2;
}

Measured memory_bytes: 2036
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   int n,x;
   cin>>n>>x;
   vector<int> l(n);
   for(int i=0;i<n;i++)cin>>l[i];
   
   int ans=1;
   int sum=0;
   for(int i=0;i<n;i++){
       sum+=l[i];
       if(sum<=x)ans++;
   }
   cout<<ans<<endl;
}

   


Measured memory_bytes: 888
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll a,b,c ;
	cin >> a >> b >> c ;
	if(a==b&&b==c){
		if(a&1) cout << 0 << endl ;
		else cout << -1 << endl ;
	}else{
		ll ans = 0 ;
		while(a%2==0&&b%2==0&&c%2==0){
			ans++ ;
			ll sum = a+b+c ;
			a = (sum-a)/2 ;
			b = (sum-b)/2 ;
			c = (sum-c)/2 ;
		}
		cout << ans << endl ;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////

int N,x;
vector<int> a;
int ref;

int main(){
    scanf("%d%d",&N,&x);
    for(int i=0;i<N;i++){
        int aa;
        scanf("%d",&aa);
        a.push_back(aa);
    }
    sort(a.begin(),a.end());

    for(auto ai=a.begin();ai!=a.cend();ai++){
        x-=*ai;
        if(x<0)
            break;
        ref++;
    }
    if(0<x)
        ref--;
    printf("%d\n",ref);

    return 0;
}

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

int main(){
  int N; cin >> N;
  int A[110];
  for(int i = 0; i < N; i++) cin >> A[i];
  
  sort(A, A + N, greater<int>());
  
  int Alice = 0;
  int Bob = 0;
  
  for(int i = 0; i < N; i++){
    if(i % 2 == 0){
      Alice += A[i];
    }else{
      Bob += A[i];
    }
  }
  cout << Alice - Bob << endl;
  
}

Measured memory_bytes: 256
import itertools

N,M,Q = map(int,input().split())
abcd = [list(map(int,input().split())) for i in range(Q)]
nums = []
maxp = 0

for i in range(M):
    nums.append(i+1)

for retsu in itertools.combinations_with_replacement(nums, N):
    p = 0
    for i in range(Q):
        a = abcd[i][0]-1
        b = abcd[i][1]-1
        c = abcd[i][2]
        d = abcd[i][3]
        if retsu[b]-retsu[a] == c:
            p += d
    maxp = max(p,maxp)
    
print(maxp)

Measured memory_bytes: 9220
n,*s=map(str,open(0).read().split())
mydict={}
for i in set(s):
    mydict[i]=1
for i in s:
    mydict[i]+=1
    """
    if s[i] in mydict:
        mydict[s[i]]+=1
    else:
        mydict[s[i]]=1
    """
v_max=max(mydict.values())
for i in sorted([kv[0] for kv in mydict.items() if kv[1]==v_max]):
    print(i)

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

int main() {
    ll a, b, n, x, ans;
    cin >> a >> b >> n;
    if (n >= b) x = b - 1;
    else x = n;
    ans = floor(a * x / b) - a * floor(x / b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
//
// Created by ss250251 on 2/16/2020.
//

#include<bits/stdc++.h>
using namespace std;
#define INF 1e18L + 7
template <typename T>
void max_self(T&a,T b){
    a = max(a,b);
}
template <typename T>
void min_self(T&a,T b){
    a = min(a,b);
}
int dfs(vector<vector<int>>&g, int u, vector<int>&dp){
    if(dp[u] != -1)return dp[u];
    int mx = 0;
    for(auto &v: g[u]){
        mx = max(mx, 1 + dfs(g, v, dp));
    }
    dp[u] = mx;
    return mx;
}

int main(){
    int n,e;
    cin>>n>>e;
//    vector<pair<int, int>> edges(e);
    vector<vector<int>>g(n,vector<int>());
    for(int i=0;i<e;i++){
        int u,v;
        cin>>u>>v;
        u--,v--;
        g[u].push_back(v);
    }
    int ans = 0;
    vector<int> dp(n,-1);
    for(int i=0;i<n;i++){
        max_self(ans, dfs(g,i, dp));
    }
    cout<<ans;
}

Measured memory_bytes: 8832