akhauriyash/Code-Regression huggingface dataset:
from collections import deque

H, W = map(int,input().split())
sh, sw = map(int,input().split())
gh, gw = map(int,input().split())
sh, sw, gh, gw = sh-1, sw-1, gh-1, gw-1
S = [input() for _ in range(H)]

INF = 10**9
ans = [[INF] * W for _ in range(H)]
ans[sh][sw] = 0

Q = deque([[sh,sw]])
while Q:
    h, w = Q.popleft()

    for nh, nw in [[h,w+1],[h,w-1],[h+1,w],[h-1,w]]:
        if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w]:
            ans[nh][nw] = ans[h][w]
            Q.appendleft([nh, nw])

    for nh in range(h-2,h+3):
        for nw in range(w-2,w+3):
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w] + 1:
                ans[nh][nw] = ans[h][w] + 1
                Q.append([nh,nw])

if ans[gh][gw] == INF:
    print(-1)
else:
    print(ans[gh][gw])

Measured memory_bytes: 113352
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  xmod=[y%m for y in x]
  from collections import Counter
  cx=dict(Counter(x))
  cxmod=dict(Counter(xmod))
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()



Measured memory_bytes: 37436
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	static Map<String,Integer>map=new TreeMap<>();
	static String ans="";
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int min=1001;
    int max=-1;
    for(int i=0;i<a;i++) {
    	int b=sc.nextInt();
    	min=Math.min(min, b);
    	max=Math.max(max, b);
    }
     System.out.println(max-min);
    }
}

Measured memory_bytes: 22736
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
struct LazySegmentTree {
private:
	int n;
	vector<int> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, INT_MAX);
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return INT_MAX;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};
long long mod = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int n, l;
	cin >> n >> l;
	int sum = 0;
	int ans = 100000000;
	for (int i = 1; i <= n; i++) {
		sum += l + i - 1;
	}
	for (int i = 1; i <= n; i++) {
		int tmp = sum - (l + i - 1);
		if (abs(ans - sum) > abs(tmp - sum)) {
			ans = tmp;
		}
	}
	cout << ans;
}

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;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    string S;
    cin >> S;
    int next = 0;
    if(S == "SUN"){
        next = 7;
    }else if(S == "MON"){
        next = 6;
    }else if(S == "TUE"){
        next = 5;
    }else if(S == "WED"){
        next = 4;
    }else if(S == "THU"){
        next = 3;
    }else if(S == "FRI"){
        next = 2;
    }else if(S == "SAT"){
        next = 1;
    }
    cout <<next<< "\n";
}

Measured memory_bytes: 768
N = int(input())
p = list(map(int,input().split()))


count=0
for i in range(N):
    if p[i]==i+1:
        continue
    else:
        dammy = p[i]
        num = p.index(i+1)
        p[i]=p[num]
        p[num] = dammy
        count+=1

if count==0 or count==1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int k, ans;
int cur[10], res[10];

void search(int depth, int count){
	if(depth==k){ ans = min(ans, count); return ; }
	int diff = (res[depth]-cur[depth]+10)%10;
	int tmp[10];
	for(int i=0;i<k;i++) tmp[i] = cur[i];
	if(diff == 0){
		search(depth+1, count);
	} else {
		for(int	i=depth;i<k;i++){
			cur[i] = (cur[i]+diff)%10;
			search(depth+1, count+1);
		}
		for(int i=0;i<k;i++) cur[i] = tmp[i];
	}
	return ;
}

int main(){
	while(cin >> k, k){
		long long c, a;
		cin >> c >> a;
		for(int i=0;i<k;i++){
			cur[i] = c%10; c /= 10;
			res[i] = a%10; a /= 10;
		}
		ans = k;
		search(0,0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 876
package main

import (
	"strconv"
	"fmt"
	"bufio"
	"os"
)
const INF = 1 << 21
var scanner = bufio.NewScanner(os.Stdin)

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


func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
	}

	for i := 0;i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			adj[u][v] = c
		}
	}

	// for i := range adj {
	// 	fmt.Println(adj[i])
	// }

	dist := make([]int, n)
	prev := make([]int, n)
	visited := make([]bool, n)
	dijkstra := func(start int, size int) {
		for i := 0; i < size; i++ {
			dist[i] = INF
			prev[i] = -1
			visited[i] = false
		}
		dist[start] = 0
		for {
			u := -1
			tmp_min := INF
			for i := 0; i < size; i++ {
				if visited[i] == false && dist[i] < tmp_min {
					tmp_min = dist[i]
					u = i
				}
			}
			if u == -1 {
				break
			}
			visited[u] = true
			for i := 0; i < size; i++ {
				if adj[u][i] > 0 {
					w := adj[u][i]
					newlen := dist[u] + w
					if newlen < dist[i] {
						dist[i] = newlen
						prev[i] = u
					}
				}
			}
		}
	}
	dijkstra(0, n)
	for i, cost := range dist {
		fmt.Printf("%d %d\n", i, cost)
	}
}


Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n,m,f[N],d[N],ld;
double ans,Pi=acos(-1.0);
struct dot{
	int x,y;
	dot(int _x=0,int _y=0){ x=_x,y=_y;}
}a[N],b[N],S,T;
bool cmp(dot p,dot q){ return p.x<q.x||(p.x==q.x&&p.y<q.y);}
int main()
{
	int i,l,r,mid;
	scanf("%d %d %d %d",&S.x,&S.y,&T.x,&T.y);
	if(S.x>T.x) swap(S,T);
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d %d",&a[i].x,&a[i].y);
	if(S.y>T.y){
		S.y=-S.y,T.y=-T.y;
		for(i=1;i<=n;i++)
			a[i].y=-a[i].y;
	  }
	for(i=1;i<=n;i++)
		if(a[i].x>=S.x&&a[i].x<=T.x&&a[i].y>=S.y&&a[i].y<=T.y)
			b[++m]=a[i];
	sort(b+1,b+m+1,cmp);
	for(i=1;i<=m;i++){
		l=0,r=ld+1;
		while(r-l>1){
			mid=(l+r)>>1;
			if(b[i].y>d[mid]) l=mid;
			else r=mid;
		  }
		f[i]=l+1;
		if(l==ld) d[++ld]=b[i].y;
		else d[l+1]=min(d[l+1],b[i].y);
	  }
	ans=(T.y-S.y+T.x-S.x)*100.0;
	ans+=ld*(5*Pi-20);
	if(ld==min(T.y-S.y,T.x-S.x)+1)
		ans+=5*Pi;
	printf("%.14lf",ans);
	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b,mi=1e9+7;
long long sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		sum+=a;
		if(a>b)
			mi=min(mi,b);
	}
	if(mi==1e9+7)
	{
		printf("0\n");
		return 0;
	}
	else 
	{
		printf("%lld\n",sum-mi);
		return 0;
	}
	return 0;
}
			

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;



int main(){
	int n;
	cin >> n;
	vector<pair<int, int> > town(n);
	for (int i = 0; i < n; i++){
		cin >> town[i].first >> town[i].second;
	}

	double ans = 0;
	for (int i = 0; i < n-1 ; i++){
		for (int j = i+1; j < n; j++){
			ans += sqrt((town[i].first - town[j].first)*(town[i].first - town[j].first) + (town[i].second - town[j].second)*(town[i].second - town[j].second));
		}
	}
	cout <<  setprecision(10) << ans*2/n << endl;
	return 0;
}

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

int main() {
  int ans;
  string s;
  cin >> s;
  if ( s[0] == '1' ) ans++;
  if ( s[1] == '1' ) ans++;
  if ( s[2] == '1' ) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c,x;
	cin>>a>>b>>c;
	
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}
		

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    REP(i,n){
	int a;
	cin >> a;
	bool flg = false;
	for(int j=1;2*j*j+2*j <= a;j++){
	    if((a-j)%(2*j+1) == 0){
		if((a-j)/(2*j+1) >= j){
		    flg = true;
		    break;
		}
	    }else{
	    }
	}
	if(!flg) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1160
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = []
for i in range(len(A)):
    B.append(0)

ok = 0
i = 0
cnt1 = 0
cnt2 = 0
B[0] = 1
while ok == 0:
    i = A[i]-1
    if B[i] == 0:
        B[i] = 1
    else:
        ok = 1
        B[i] = 2
    cnt1 += 1
while ok == 1:
    i = A[i]-1
    if B[i] == 1:
        B[i] = 2
    else:
        ok = 2
    cnt2 += 1

if K > cnt1:
    K -= cnt1
    ok = 3
if K > cnt2 and ok == 3:
    K = K % cnt2

if ok == 2:
    i = 0
    
while K > 0:
    i = A[i]-1
    K -= 1

print(i+1)


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

int main()
{
  int a, b;
  cin >> a >> b;
  
  a--;
  
  int tbl[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  
  int cnt;
  
  for(int i = 0; i < a; i++)
  {
    if((i + 1) <= tbl[i])
    {
      cnt++;
    }
  }
  if(a + 1 <= b)
  {
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
L_list = list(map(int, input().split()))
sum = 0

L_list.sort()

from bisect import bisect_left

for i in range(N):
    for j in range(i+1, N):
        t = L_list[i]+L_list[j]
        idx = bisect_left(L_list, t)
        sum += max(0, idx-(j+1))
        
print(sum)

Measured memory_bytes: 3188
def main():
    N = int(input())
    *A, = map(int, input().split())
    *B, = map(int, input().split())

    ans = 0
    for i, can_beat in enumerate(B):
        beat = min(A[i], can_beat)
        A[i] -= beat
        can_beat -= beat
        ans += beat

        beat = min(A[i + 1], can_beat)
        A[i + 1] -= beat
        ans += beat

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18476
#include <stdio.h>
#include <stdlib.h>

int cmp(const void* x, const void* y) {
	int a = *(const int *)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

int N;
int a[114514];

int tomatuharuka;
int igutiyuka[114514];
int igarasihiromi[114514];

int futigamimai(int fuzitasaki) {
	int l = 0, r = tomatuharuka - 1;
	while (l <= r) {
		int m = l + (r - l) / 2;
		if (igutiyuka[m] == fuzitasaki) return m;
		else if (igutiyuka[m] < fuzitasaki) l = m + 1;
		else r = m - 1;
	}
	exit(2);
	return 0;
}

int main(void) {
	int i;
	int gourikiayame = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
		igutiyuka[i] = a[i];
	}
	qsort(igutiyuka, N, sizeof(*igutiyuka), cmp);
	tomatuharuka = 1;
	for (i = 1; i < N; i++) {
		if (igutiyuka[tomatuharuka - 1] != igutiyuka[i]) {
			igutiyuka[tomatuharuka++] = igutiyuka[i];
		}
	}
	for (i = 0; i < N; i++) {
		igarasihiromi[futigamimai(a[i])]++;
	}
	for (i = 0; i < tomatuharuka; i++) {
		if (igarasihiromi[i] != igutiyuka[i]) {
			if (igarasihiromi[i] > igutiyuka[i]) {
				gourikiayame += igarasihiromi[i] - igutiyuka[i];
			} else {
				gourikiayame += igarasihiromi[i];
			}
		}
	}
	printf("%d\n", gourikiayame);
	return 0;
}


Measured memory_bytes: 1280
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = N % 10
if a in [2, 4, 5, 7, 9]:
    print("hon")
elif a in [0, 1, 6, 8]:
    print("pon")
else:
    print("bon")



Measured memory_bytes: 10044
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#define INF 1000000000;
using namespace std;
int points[100009];
int allp;
pair<int, int>gate;
vector<int>counto;
int main() {
	int n = 0, m = 0;
	cin >>n>> m;
	int ama = 0;
	int	bmi = INF;
	for (int i = 0; i < m; i++) {
		cin >> gate.first >> gate.second;
		ama = max(ama, gate.first);
		bmi = min(bmi, gate.second);
	}
	if (bmi - ama+1 <= 0) {
		cout << '0' << endl;
	}
	else { cout << bmi - ama+1 << endl; }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long ans=0;
	int i,o,f,j,l,s,z,t;
	cin>>i>>o>>f>>j>>l>>s>>z;
	if((i%2)+(j%2)+(l%2)>=2 && i>0 && j>0 && l>0)
        {
          ans+=3;
            i--;
            j--;
            l--;
	  }
	ans+=o;
	ans+=(i/2)*2;
	ans+=(j/2)*2;
	ans+=(l/2)*2;
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

map< int64_t, int > prime_factor(int64_t n) {
    map< int64_t, int > ret;
    for(int64_t i = 2; i * i <= n; i++) {
        while(n % i == 0) {
        ret[i]++;
        n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
        return ret;
}

int main() {
    int n;
    cin>>n;
    cout<<n<<":";
    auto d=prime_factor(n);
    for (auto p:d){
        rep(i,p.second){
            cout<<" "<<p.first;
        }
    }
    cout<<endl;
    

    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

const int MAX = 1e5+5;
const int mod = 1e9+7;

int n;

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//#ifndef ONLINE_JUDGE
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//#endif

	cin >> n;
	int arr[n];

	for (int i = 0; i < n; i++)
		cin >> arr[i];

	sort(arr, arr+n);

	arr[n-1] = arr[n-1]/2;

	int sum = 0;

	for (int i = 0; i < n; i++)
		sum += arr[i];

	cout << sum << endl;
		
	

	return 0;
}


Measured memory_bytes: 256
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

H, W = map(int, input().split())
board = [0]*(H+1)
for i in range(1, H+1):
    board[i] = [0] + list(map(int, input().split()))

#
ans = []
for y in range(1, H+1):
    if y % 2 == 1:
        for x in range(1, W):
            now = board[y][x]
            if now % 2 != 0:
                ans.append((y, x, y, x+1))
                board[y][x+1] += 1
        if y != H:
            now = board[y][W]
            if now % 2 != 0:
                ans.append((y, W, y + 1, W))
                board[y+1][W] += 1
    else:
        for x in reversed(range(2, W+1)):
            now = board[y][x]
            if now % 2 != 0:
                ans.append((y, x, y, x-1))
                board[y][x-1] += 1
        if y != H:
            now = board[y][1]
            if now % 2 != 0:
                ans.append((y, 1, y+1, 1))
                board[y+1][1] += 1

print(len(ans))
for (a, b, c, d) in ans:
    print(str(a) + " " + str(b) + " " + str(c) + " " + str(d))


Measured memory_bytes: 65756
N, C, K = map(int, input().split())
T = sorted([int(input()) for _ in range(N)])
cnt = 0
while T:
    T_min = T[0]
    for _ in range(C):
        if T[0] <= T_min + K:
            T.pop(0)
            if not T:
                break
        else:
            break
    cnt += 1
print(cnt)

Measured memory_bytes: 8280
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 998244353
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MAX_N 400010
#define MOD 998244353
#define int long long
int inv[MAX_N],fac[MAX_N],finv[MAX_N];

void make()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2;i<MAX_N;i++){
		inv[i] = MOD - (long long)inv[MOD%i] * (MOD/i) % MOD;
		fac[i] = (long long)fac[i-1] * i % MOD;
		finv[i] = (long long)finv[i-1] * inv[i] % MOD;
	}
}


long long mod_pow(long long a,long long b)
{
    a %= MOD;
    long long res = 1;
    while(b){
        if(b & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}


int comb(int a,int b)
{
	if(a < b){
		return 0;
	}
	return fac[a] * ((long long)finv[b] * finv[a-b] % MOD) % MOD;
}
ll dp[2000];
ll m,n,k;
signed main(){
    make();
    cin >> m >> n >> k;
    for(int i=1;i<=k;i++){
        if(i==1){
            dp[i] = 1;
        }else{
            dp[i] = mod_pow(i,n);
            for(int j=1;j<i;j++){
                dp[i] += mod-(comb(i,j)*dp[j]%mod)%mod;
                dp[i]%=mod;
            }
        }
    }
    ll sm = mod_pow(m,n);
    ll res = 0;
    ll tmp = 1;
    for(int i=1;i<k;i++){
        tmp *= (m-i+1)%mod;
        tmp %= mod;
        tmp *= inv[i];
        tmp %= mod;
        res += tmp*dp[i]%mod;
        res %= mod;
    }
    cout << (sm + mod - res ) %mod << endl;
    return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int dp[500][500];

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;

  rep (i, M) {
    int L, R;
    cin >> L >> R;
    dp[L - 1][R - 1]++;
  }

  rep (i, N) rep (j, N) {
    if (i - 1 >= 0) dp[i][j] += dp[i - 1][j];
    if (j - 1 >= 0) dp[i][j] += dp[i][j - 1];
    if (i - 1 >= 0 && j - 1 >= 0) dp[i][j] -= dp[i - 1][j - 1];
  }

  rep (i, Q) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    int ans = dp[q][q];
    if (p - 1 >= 0) {
      ans -= dp[p - 1][q];
      ans -= dp[q][p - 1];
      ans += dp[p - 1][p - 1];
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int>v;
	int n;
	cin>>n;
	int a[n+4];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	int k=n;
	while(k>0)
	{
		v.push_back(a[k]);
		k=k-2;
	}
	if(n&1)
	{
		int k=2;
		while(k<=n)
		{
			v.push_back(a[k]);
			k+=2;
		}
	}
	else
	{
		int k=1;
			while(k<=n)
		{
			v.push_back(a[k]);
			k+=2;
		}
	}
	for(int i=0;i<v.size();i++)
	cout<<v[i]<<" ";
	return 0;
}

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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A + B > C + D) {
    	cout << "Left" << endl;
    }
  	else if (A + B == C + D) {
    	cout << "Balanced" << endl;
    }
    else if (A + B < C + D) {
    	cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

static const long long INF = 1000000007;
#define N 10000000

int n, m;
long long bigger, smaller;

long long fact(long long k) {
    long long result = 1;
    for ( long long n = 1; n <= k; n++ ) {
        result *= n % INF;
        result %= INF;
    }
    
    return result;
}

int main() {
    cin >> n >> m;
    
    bigger = smaller = 0;
    bigger = m - n > 0 ? m : n;
    smaller = m - n < 0 ? m : n;
    
    long long ans = 0;
    if ( bigger - smaller > 1 ) {
        ans = 0;
    } else if ( bigger - smaller == 1 ){
        ans = fact(bigger) * fact(smaller) % INF;
    } else {
        ans = fact(bigger) * fact(smaller) * 2 % INF;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>
#include<bitset>

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main(){
    string s;
    char op[3];
    cin >> s;
    int a[4];
    for(int i = 0; i < 4; i++) a[i] = s[i] - '0';
    int ans = 0;
    for(int i = 0; i < (1<<3); i++){ //flag
        int res = a[0];
        for(int j = 0; j < 3; j++){
            if(i>>j&1) {
                res += a[j+1];
                op[j] = '+';
            }
            else {
                res -= a[j+1];
                op[j] = '-';
            }
        }
        if(res == 7){
            printf("%d%c%d%c%d%c%d=7\n",a[0],op[0],a[1],op[1],a[2],op[2],a[3]);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int maxi = 1e6+10;
string s;
// vector<int> v[maxi];
ll n,k;
ll a[maxi];

vector<vector<long long> > comb(int n, int r) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % MOD;
    }
  }
  return v;
}

long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
long long mul(long long a, long long b, long long m) { // これを使えー
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}
long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a = mod(a - mul(t, b, m), m); swap(a, b);
        u = mod(u - mul(t, v, m), m); swap(u, v);
    }
    return mod(u, m);
}

int main () {
  cin >> n >> k;
  std::vector<std::vector<ll> > COMB(n + 1,vector<long long>(n + 1, 0));
   COMB = comb(n,k);
  for(int i = 1; i<=k; i++) {
    ll result = 0;
    result += COMB[k-1][i-1];
    result =  mul(result, COMB[n-k+1][i], MOD);
    cout << result << endl;
  }
}


Measured memory_bytes: 62976
S = gets.chomp
n = S.size
res = Array.new(n) { 0 }
cnt = 0

n.times do |i|
  next cnt += 1 if S[i] == 'R'

  res[i - 1] += (cnt + 1) / 2
  res[i] += cnt / 2
  cnt = 0
end

(n - 1).downto(0) do |i|
  next cnt += 1 if S[i] == 'L'

  res[i + 1] += (cnt + 1) / 2
  res[i] += cnt / 2
  cnt = 0
end

puts res.join(' ')


Measured memory_bytes: 3196
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    long long x; cin >> x;

    auto ans = (x / 11) * 2;
    auto rem = x % 11;

    if (rem > 0) {
        if (rem > 6) {
            ans += 2;
        } else {
            ans += 1;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 888
import java.util.*;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n % 10 == 9 || n / 10 == 9) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define f(i,p,q) for(int i=p;i<q;i++)
using namespace std;
int main()
{
   // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
     double t,x;
       cin>>t>>x;
       cout<<fixed<<setprecision(10)<<t/x;
}


Measured memory_bytes: 256
#include<cstdio>
int tt[200002];
int sm[200002];
int s[100000];
int t[100000];
int c[100000];
int main()
{
	int i, j;
	int mx = 0;
	int aaaa = 0;
	int N;
	int C;

	scanf("%d%d", &N, &C);

	for(i=0;i<N;i++)
	{
		scanf("%d%d%d", &s[i], &t[i], &c[i]);
	}
	for(j=0;j<200002;j++) sm[j] = 0;

	for(i=0; i<=C; i++)
	{
		for(j=0;j<200002;j++) tt[j] = 0;
		for(j=0;j<N;j++) {
			if(c[j]==i) {
				tt[s[j]*2-1]++;
				tt[t[j]*2]--;
			}
		}
		for(j=1;j<200002;j++) {
			tt[j] = tt[j] + tt[j-1];
		}
		for(j=0;j<200002;j++) {
			if(tt[j]>0) {
				sm[j]++;
			}
		}
		aaaa +=1;
	}

	for(j=1;j<200002;j++) {
		if(sm[j]>mx) mx = sm[j];
	}
	printf("%d\n", mx);
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#define all(v) (v).begin(),(v).end()
using namespace std;



int main(){
  	int N;
  	cin >> N;
  	vector<int> a(N);
  	for(int i=0;i<N;i++) cin >> a[i];
  	sort(all(a), greater<int>());
  	int Alice = 0, 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: 3588
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#ifndef bhartiya
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> oset;
// not that imp
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
// #define PI acos(-1)

#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()

#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar,val) memset(ar, val, sizeof(ar))

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) {return fabs(a - b) < 1e-9;}
int gcd(int a, int b){ return b==0 ? a : gcd(b, a%b); }
ll modpow(ll b, ll e) {
	ll ans=1; for(;e;b=b*b%mod,e/=2) if(e&1) ans=ans*b%mod; return ans;}

const int maxn = 1000005;
int a[maxn], b[maxn];

void solve(){
	int n; cin>>n;
	rep(i,n) {
		cin>>a[i];
		b[i] = a[i];
	}
	sort(b, b+n);
	rep(i,n){
		if(a[i] == b[n-1]) {
			cout<<b[n-2]<<endl;
		}
		else cout<<b[n-1]<<endl;
	}
}

signed main() 
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(10); //cout<<fixed;
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    solve();
    end_routine();
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
void Main(){
    ll N,A,B;cin>>N>>A>>B;
    vector<ll> H(N);
    For(i,0,N) cin>>H[i];
    ll diff=A-B;
    ll z=0;
    ll ok=10000000000,ng=0;
    while(true){
        ll center=(ok+ng)/2;
        ll cnt=0;
        For(i,0,N){
            cnt+=max((H[i]-B*center+diff-1)/diff,z);
        }
        if(cnt<=center){
            ok=center;
        }
        else{
            ng=center;
        }
        if(ok-ng==1) break;
        //cout<<"cnt= "<<cnt<<" ok= "<<ok<<" ng= "<<ng<<endl;
    }
    cout<<ok<<endl;
}
int main(){
    Main();
    return 0;
}

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

int main() {
    int N, x, l;
    cin >> N;
    deque<pair<int, int>> A;
    for (int i = 0; i < N; i++) {
        cin >> x >> l;
        A.emplace_back(make_pair(x - l, x + l));
    }

    sort(A.begin(), A.end(), 
        [](const auto &a, const auto &b) {return a.second < b.second;});

    int c = 0;
    int r = -1000000001;
    for (pair<int ,int> p : A) {
        if (p.first >= r) {
            c++;
            r = p.second;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 1024
main :: IO ()
main = do
  xs <- getLine
  let n = length xs
  if n == 0
    then print 0
    else do
      let s0 = '0' : '1' : s0
          s1 = '1' : '0' : s1
          n0 = length $ filter (\(a, b) -> a /= b) $ zip xs s0
          n1 = length $ filter (\(a, b) -> a /= b) $ zip xs s1
      print $ min n0 n1

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

int main(){
  int n; cin>>n;
  vector<int> d(n);
  for(int i=0; i<n; ++i)cin>>d[i];

  sort(d.begin(),d.end());

  cout<<d[n/2]-d[n/2-1]<<endl;
}


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

int main() {
	int N, x1, x2, y1, y2, t1, t2;

	std::cin >> N;

    t1 = 0;
	x1 = 0;
	y1 = 0;

	bool flag = true;

	for(int i = 0; i < N; i++) {
		std::cin >> t2 >> x2 >> y2;
		int dt = t2 - t1;

		int dpos = abs(x2 - x1) + abs(y2 - y1);

		//距離が届くか否か
		if (dpos > dt) {
			flag = false;
			break;
		}

		//距離は届くが、あまりが奇数ならそこにはたどり着かない
		if ((dt - dpos) % 2 == 1) {
			flag = false;
			break;
		} 
		t1 = t2;
		x1 = x2;
		y1 = y2;
	}


	if (flag) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[101010], b[101010];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%lld", &a[i]);
	for (int i = 0; i < num; i++)scanf("%lld", &b[i]);
	ll ne = 0;
	int cnt = 0;
	vector<ll>v;
	for (int i = 0; i < num; i++)
	{
		if (a[i] >= b[i])v.push_back(a[i] - b[i]);
		else ne += b[i] - a[i], cnt++;
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	if (cnt == 0)
	{
		printf("0\n");
		return 0;
	}
	for (int i = 0; i < v.size(); i++)
	{
		ne -= v[i];
		if (ne <= 0)
		{
			printf("%d\n", cnt + i + 1);
			return 0;
		}
	}
	printf("-1\n");
}

Measured memory_bytes: 2808
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    s=chomp(readline())
    z=0
    o=0
    for i in s
        if i=='0'
            z+=1
        else
            o+=1
        end
    end
    println(min(z,o)*2)
end
main()

Measured memory_bytes: 116016
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mode 1000000007
#define inf 1000000000000000007
#define eps 0.00000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll a,b;
    cin>>a>>b;
    if(a<6)
        b=0;
    else if(a<13)
        b/=2;
    cout<<b;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]+str[1]+str[2]);
    System.out.println(a%4==0?"YES":"NO");
  }
}

Measured memory_bytes: 37184
//C

#include <bits/stdc++.h>

using namespace std;

int main(){

	int x, n,temp;
	int check[101];
	memset(check, 0, sizeof check);

	cin >> x >> n;

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

	int minn = -1;

	for (int i = 0; i <= 100; i++){
		if (check[i] == 0){
			if (abs(x-minn) > abs(x-i)){
				minn = i;
			}
		}
	}

	if (abs(x-minn) > abs(x-101)){
				minn = 101;
	}

	cout << minn << endl;

	return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){

  ll n;
  cin>>n;
  vector<ll> a(n+1);
  reps(i,n)cin>>a[i];

  vector<ll> res(n+1);
  for(ll i=n;i>0;--i){
    ll t = 0;
    ll x = i;
    while(x<=n){
      t ^= res[x];
      x += i;
    }
    if(t==a[i])res[i]=0;
    else res[i]=1;
  }

  vector<ll> ans;
  reps(i,n)if(res[i])ans.emplace_back(i);

  cout<<ans.size()<<endl;
  for(auto x:ans)cout<<x<<" ";
  cout<<endl;

}

Measured memory_bytes: 4980
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2005;
int n,m,i,j,k,p[N],l[N],r[N],ans;
char s[N][N];
int main(){
	scanf("%d%d",&n,&m);ans=max(n,m);p[0]=-1;
	for (i=1;i<=n;i++) scanf("%s",s[i]+1); 
	for (i=1;i<n;i++){
		for (j=1;j<m;j++){
			int k=s[i][j]+s[i+1][j]+s[i][j+1]+s[i+1][j+1]-48*4;
			p[j]=(k&1)?0:p[j]+1;
		}
		for (j=1;j<m;l[j]=k,j++)
			for (k=j-1;p[k]>=p[j];k=l[k]);
		for (j=m;j--;r[j]=k)
			for (k=j+1;p[k]>p[j];k=r[k]);
		for (j=1;j<m;j++)
			ans=max(ans,(p[j]+1)*(r[j]-l[j]));
	}
	printf("%d",ans);
}

Measured memory_bytes: 4096
import java.util.*;
public class Main {
	public static int[] val;
	public static int n;
	public static int x;
	public static boolean[] dp;
	public static int[] PrimeTable;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while (true) {
			
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			
			if(n == 0 && x == 0) {
				break;
			}
			
			val = new int[n];
			for (int i = 0; i < n; i++) {
				val[i] = stdIn.nextInt();
			}
			dp = new boolean[x + 1];
			PrimeTable = new int[x + 1];
			dp();
			createPrimeTable(x);
			Arrays.sort(PrimeTable);
			int ans = 0;
			for (int i = x ; i >= 1; i--) {
				if (dp[i] && Arrays.binarySearch(PrimeTable, i) >= 0) {
					ans = i;
					break;
				}
			}
			if (ans != 0) {
				System.out.println(ans);
			} else {
				System.out.println("NA");
			}
		}
	}
	
	public static void dp() {
		dp[0] = true;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j <= x; j++) {
				if(dp[j] == true) {
					
					if(j + val[i] <= x) {
						dp[j + val[i]] = true;
					}
				}
			}
		}
	}
	
	public static void createPrimeTable(int x) {
		//xまでの素数テーブルを作成
		boolean[] isPrime = new boolean[x+1];
		for(int i = 2; i < x+1; i++) {
			isPrime[i] = true;
		}
		int counter = 0;
		for(int i = 2; i < Math.sqrt(x+1); i++) {
			if(isPrime[i]) {
				for(int j = i * 2; j < x+1; j += i) {
					isPrime[j] = false;
				}
			}
		}
		for(int i = 0; i < x+1; i++) {
			if(isPrime[i]) {
				PrimeTable[counter++] = i;
			}
		}
		
	}
	
}

Measured memory_bytes: 166876
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

bool solve(int n, int a, int b, int c, int d, const string &s){
    FOR(i,a,c){
      if(s[i]=='#' and s[i+1]=='#') return false;
    }
    FOR(i,b,d){
      if(s[i]=='#' and s[i+1]=='#') return false;
    }

    if(c<d) return true;

    FORE(i,b,d){
      if((i-1<0 or s[i-1] == '.') and s[i] == '.' and (i+1>=n or s[i+1] == '.')) return true;
    }

    return false;
}

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

  int n,a,b,c,d;
  string s;
  while(cin >> n >> a >> b >> c >> d >> s){
    --a,--b,--c,--d;
    bool ans = solve(n,a,b,c,d,s);

    cout << (ans ? "Yes" : "No") << endl;
  }

  
  return 0;
}


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

int N;

int main(){
    cin >> N;
    for(int x = 0; x < 26; ++x){
        for(int y = 0; y < 15; ++y){
            if(N == 4 * x + 7 * y){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for i in range(len(A)):
    if i > 0 and A[i] - A[i-1] == 1:
        ans += (B[A[i]-1] + C[A[i-1]-1])
    else:
        ans += B[A[i]-1]

print(ans)

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int dp[1005][1005];
char board[1005][1005];
const int MOD = 1000000007;

int main() {
	int h, w;
	scanf("%d%d", &h, &w);
	REP(i, h)scanf("%s", board[i]);
	dp[0][1] = 1;
	REP(i, h) {
		REP(j, w) {
			if (board[i][j] == '.') {
				dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD;
			}
		}
	}
	printf("%d", dp[h][w]);

	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int sx, sy, tx, ty, dx, dy;
  cin >> sx >> sy >> tx >> ty;
  dx=tx-sx;
  dy=ty-sy;
  for (int i=0; i<dx; i++) {
    cout << "R";
  }
  for (int i=0; i<dy; i++) {
    cout << "U";
  }
  for (int i=0; i<dx; i++) {
    cout << "L";
  }
  for (int i=0; i<dy; i++) {
    cout << "D";
  }
  cout << "D";
  for (int i=0; i<dx+1; i++) {
    cout << "R";
  }
  for (int i=0; i<dy+1; i++) {
    cout << "U";
  }
  cout << "L" << "U";
  for (int i=0; i<dx+1; i++) {
    cout << "L";
  }
  for (int i=0; i<dy+1; i++) {
    cout << "D";
  }
  cout << "R" << endl;
}

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

int valuation(char str[]);

int main(){
  int i,result;
  char *c,str[1000];
  c = fgets(str, 10000, stdin);
  str[strlen(str)-1]='\0';
  while(1){
    if(strlen(str)==0) break;
    str[strlen(str)-1]='\0';
    if((result=valuation(str))==0){
      continue;
    }else{
      printf("%d\n",result);
      return 0;
    }
  }
  return 0;
}

//偶数文字列を判定する関数
int valuation(char str[]){
  int i,len;
  len = strlen(str);
  if(len%2==1){
    return 0;
  }
  for(i=0;i<len/2;i++){
    if (str[i]==str[len/2+i]){
      continue;
    }else{
      return 0;
    }
  }
  return len;
}


Measured memory_bytes: 128