akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10000)
mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y / 2) ** 2 % mod
    else:
        return power(x, y / 2) ** 2 * x % mod


def div(a, b):
    return mul(a, power(b, mod - 2))


# def gcd(a_gcd, b_gcd):
#     while b_gcd != 0:
#         a_gcd, b_gcd = b_gcd, a_gcd % b_gcd
#     return a_gcd
#
#
# def lcm(a_lcm, b_lcm):
#     return a_lcm * b // gcd(a_lcm, b_lcm)
#
#
# def max_sum(N_max_sum, a_max_sum):
#     dp = [0] * (N_max_sum + 1)
#     for i in range(N_max_sum):
#         dp[i + 1] = max(dp[i], dp[i] + a_max_sum[i])
#     return dp[N]
#
#
# def knapsack(N_knapsack, W, weight, value):
#     inf = float("inf")
#     dp = [[-inf for _ in range(W+1)] for j in range(N_knapsack + 1)]
#     for i in range(W+1):
#         dp[0][i] = 0
#
#     for i in range(N_knapsack):
#         for w in range(W+1):
#             if weight[i] <= w:
#                 dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
#             else:
#                 dp[i+1][w] = dp[i][w]
#     return dp[N_knapsack][W]
#
#
# class UnionFind:
#     def __init__(self, n):
#         self.par = [i for i in range(n+1)]
#         self.rank = [0] * (n+1)
#
#     # 検索
#     def find(self, x):
#         if self.par[x] == x:
#             return x
#         else:
#             self.par[x] = self.find(self.par[x])
#             return self.par[x]
#
#     # 併合
#     def union(self, x, y):
#         x = self.find(x)
#         y = self.find(y)
#         if self.rank[x] < self.rank[y]:
#             self.par[x] = y
#         else:
#             self.par[y] = x
#             if self.rank[x] == self.rank[y]:
#                 self.rank[x] += 1
#
#     # 同じ集合に属するか判定
#     def same_check(self, x, y):
#         return self.find(x) == self.find(y)


# S = input()
# N = int(input())
# A = list(map(int, input().split()))
# X = [int(input()) for _ in range(N)]

N, A, B, C, D = map(int, input().split())
S = input()
block = "#"
ans = "Yes"
if C < D:
    for i in range(A, C):
        if S[i] == block:
            if S[i + 1] == block:
                ans = "No"
                break
    for i in range(B, D):
        if S[i] == block:
            if S[i + 1] == block:
                ans = "No"
                break
else:
    change_frag = False

    for i in range(A, C):
        # print(S[i])
        if S[i] == block:
            if S[i + 1] == block:
                ans = "No"
                break
    for i in range(B-1, D):
        #print(i+1, S[i])
        if S[i] == block:
            if S[i + 1] == block:
                ans = "No"
                break
        elif S[i-1] != block and S[i+1] != block:
                #print(i+1, S[i], "(●・▽・●)")
                change_frag = True

    if not change_frag:
        ans = "No"


print(ans)


Measured memory_bytes: 40060
#include <stdio.h>
#include <stdlib.h>
int GCM(int a,int b)
{
	int r,tmp;
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}
int main(void)
{
	int n,x,X[100001],Y[100001],i,j,tmp,a;
	scanf("%d%d",&n,&x);
	for(i=0; i<n; i++){
		scanf("%d",&X[i]);
		X[i]=abs(X[i]-x);
	}
	a=X[0];
	for(i=1; i<n; i++){
		a=GCM(a,X[i]);
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 512
import java.util.*; 

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

        while(true){ 
            int a = sc.nextInt(); 
            int b = sc.nextInt(); 
            int c = sc.nextInt(); 
            int sum = a + b; 
            if(a == -1 && b == -1 && c== -1){ 
                break; 
            }else if(a == -1 || b == -1){ 
                System.out.println("F"); 
            }else{ 
                if(sum<30){ 
                    System.out.println("F"); 
                }else if(sum<50){ 
                    if(c<50){ 
                        System.out.println("D"); 
                    }else{ 
                        System.out.println("C"); 
                    } 
                }else if(sum<65){ 
                    System.out.println("C"); 
                }else if(sum<80){ 
                    System.out.println("B"); 
                }else{ 
                    System.out.println("A"); 
                } 
            } 
        } 
        sc.close(); 
    } 
}


Measured memory_bytes: 26276
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  bool j = false;
  for (int i=1; i<=b; i++) {
    if ((a*i)%b == c) {
      j = true;
    }
  }
  if (j) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
//
//  main.cpp
//  A
//
//  Created by Hashizo on 2020/04/26.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	
	
	ll s,w;
	cin >> s >> w;

	if (s <= w) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort((c).begin(),(c).end())
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


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

	cout << B + min(A + B + 1, C) << endl;
	
    return 0;
}


Measured memory_bytes: 256
D=int(input())
c=list(map(int,input().split()))
c.insert(0,0)
s=[0]*(D+1)
t=[0]*(D+1)
for i in range(1,D+1):
	s[i]=list(map(int,input().split()))
for i in range(1,D+1):
	t[i]=int(input())

def last(d,i):
	for j in range(d, 0, -1):
		if t[j]==i: return j
	return 0

S=0
for d in range(1, D+1):
	cd = sum((c[i] * (d - last(d, i)) for i in range(1, 27)))
	S += s[d][t[d]-1] - cd
	print(S)

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

int main(){
	string str;
	cin>>str;
	string anotherstr=str;
	reverse(str.begin(),str.end());
	for(int i=0;i<str.size();i++){
		if(str[i]=='b'){
			str[i]='d';
		}else
		if(str[i]=='d'){
			str[i]='b';
		}else
		if(str[i]=='p'){
			str[i]='q';
		}else
		if(str[i]=='q'){
			str[i]='p';
		}
	}
	if(str==anotherstr){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
/*
	*#*#*#* Author GaryMr *#*#*#*
########################################################################
	是否可以简化问题：
	抓住数据范围哪里小
	dfs or bfs
	是否可以化具体为抽象
	字符串问题是否可以用数学模拟递归过程（取c[i]或不取来算结果）
	二分？左闭右开？
	long long？
	逆向思维？
	dp？
	贪心？
	树的直径:随便找一点再走到它最远的点A，再从A最远的点走到最远B的点。AB就是树的直径
	匹配括号 左减右>=0
	字符串赋值字符加单引号
	double> printf("%lf")输出小数点6位，%.16lf输出后十六位
	多组数据清空？
	dp优化用g？
	线段树：大小为n的8倍
	线段树：左闭右开！
	线段树：find： if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k];
	线段树：满二叉树 
	循环跳出条件 
	代数设出每个值寻找关系？
	优先队列：priority_queue<类型> q;   
	priority_queue<类,vector<类>, less<类> > pq1; 　　　 // 使用递减	
	priority_queue<类，vector<类>, greater<类> > pq2; 　　// 使用递增
	判断括号，判断是否长度为偶数
	1<<ceil(log2(double(n)))
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL long long
#define IT iterator
#define FIR first
#define SEC second
using namespace std;
const int MAX=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,rec=0,t1,t2,t3;
string s;
int main(){
	scanf("%d",&n);
	rb(j,1,n){
		cin>>s;
		int len=s.length();
		if(s[0]=='B'){
			if(s[len-1]=='A'){
				t1++;
			}
			else{
				t2++;
			}
		}
		if(s[len-1]=='A'){
			if(s[0]!='B') t3++;
		}
		for(int i=0;i<len-1;i++){
			if(s[i]=='A'&&s[i+1]=='B') rec++;
		}
	}
	if(t1){
		rec+=t1-1;
	}
	if(t1){
		if(t2){
			t2--;
			rec+=1;
		}
		if(t3){
			t3--;
			rec+=1;
		}
	}
	rec+=min(t2,t3);
	printf("%d\n",rec);
	return 0;
}
   

Measured memory_bytes: 256
import Control.Monad
import Data.Function

solve2 list = map addStr list
  where
    addStr (i,x) = "Case " ++ (show i) ++ ": " ++ show x

input = loop 0 []
  where
    loop :: Int -> [Int] -> IO [Int]
    loop x list = do
      x' <- readLn
      if x' == 0
        then return list
        else do
        loop x' (list ++ [x'])

main = do
  list <- input
  let list' = zip [1..] list
  mapM_ putStrLn $ solve2 list'


Measured memory_bytes: 7024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int a[n+2];
  for(int i=0;i<n;i++)cin>>a[i];
  vector<int>v(n,INT_MAX);
  v[0]=0;
  for(int i=0;i<=n-1;i++){
    for(int j=i+1;j<=i+k;j++){
      if(j<n)v[j]=min(v[j],v[i]+abs(a[j]-a[i]));
     }
  }
  cout<<v[n-1]<<endl;
  return 0;
}

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

#define int long long
#define all(V) (V).begin(),(V).end()
#define umap unordered_map
#define uset unordered_set
#define br cout<<"\n";

const int MAXN=1e5+10, MOD=1e9+7;
int n,m;
int arr[MAXN];
int t[5*MAXN],lazy[5*MAXN];

int doit(int a,int b){
	return (a+b);
}

void build(int start,int end,int index=1){
	if(start==end){
		t[index]=0;
		return ;
	}
	int mid = start+end >> 1;
	build(start,mid,index << 1);
	build(mid+1,end,index<<1|1);
	t[index] = doit(t[index<<1], t[index<<1|1]);
}

void propagate(int start,int end,int index){
	t[index] += (end-start+1)*lazy[index];
	// bcz leaf not hv childs
	if(start!=end){
		lazy[index<<1] += lazy[index];
		lazy[index<<1|1] += lazy[index];
	}
	lazy[index]=0;
}

int Query(int start,int end,int l,int r,int index=1){

	if(lazy[index]!=0){
		propagate(start,end,index);
	}
	// out range
	if(r<start or end<l){
		return 0;
	}
	// in Raange
	if( l<=start and end<=r){
		return t[index];
	}
	int mid = start+end >>1;
	return doit(Query(start,mid,l,r,index<<1), Query(mid+1,end,l,r,index<<1|1));
}

void pUpdate(int start,int end,int point,int val,int index=1){
	if(start==end){
		t[index]=val;
		return ;
	}
	int mid = start+end>>1;
	if(point <= mid){
		pUpdate(start,mid,point,val,index<<1);
	}
	else{
		pUpdate(mid+1,end,point,val,index<<1|1);
	}
	t[index] = doit(t[index <<  1] , t[index << 1 | 1]);
}


void rangeUpdate(int start,int end,int l,int r,int val,int index){
	if(lazy[index]!= -1){
		propagate(start,end,index);
	}
	if(l>end or r<start){
		return;
	}
	// in range
	if(l<=start and end<=r){
		lazy[index]=val;
		propagate(start,end,index);
		return;
	}
	int mid = start+end>>1;
	rangeUpdate(start,mid,l,r,val,index<<1);
	rangeUpdate(mid+1,end,l,r,val,index<<1|1);
	t[index] = doit(t[index<<1],t[index<<1|1]);
}




signed main()
{
// 	#ifndef ONLINE_JUDGE
// 		freopen("./input.txt","r",stdin);
// 		freopen("./output.txt","w",stdout);
// 	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin>>n>>m;
	memset(lazy,0,sizeof lazy);
	build(0,n-1);
	for(int i=1; i<=m; i++){
		int q; cin>>q;
		if(q==1){
			int s,t; cin>>s>>t;
			cout<<Query(0,n-1,s-1,t-1,1); br;
		}
		else{
			int s,t,x; cin>>s>>t>>x;
			rangeUpdate(0,n-1,s-1,t-1,x,1);
		}
	}	

}


Measured memory_bytes: 9180
// serval
// srrva
// rrrv
// rrr

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    Map<Character, List<Integer>> map = new HashMap<>();
    for (int i = 0; i < S.length(); i++) {
      char c = S.charAt(i);
      List<Integer> list = map.get(c);
      if (list == null) {
        list = new ArrayList();
        map.put(c, list);
      }
      list.add(i);
    }
    
    int ans = 1000;
    for (List<Integer> list : map.values()) {
      int diffMax = 0;
      int prev = -1;
      for (int idx : list) {
        int diff = prev == -1 ? idx : idx-prev-1;
        diffMax = Math.max(diffMax, diff);
        prev = idx;
      }
      diffMax = Math.max(diffMax, S.length()-1-list.get(list.size()-1));
      ans = Math.min(ans, diffMax);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
while True:
    h, w = input().split()
    h = int(h)
    w = int(w)
    if (h != 0) or (w != 0):
        if (h == 1) and (w == 1):
            print("#")
        else:
            for i in range(h // 2):
                print("#." * (w // 2) + "#" * (w % 2))
                print(".#" * (w // 2) + "." * (w % 2))
            if h % 2 != 0:
                print("#." * (w // 2) + "#" * (w % 2))
        print() 
    else:
        break


Measured memory_bytes: 5612
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let n = io.read::<usize>();
    let mut ans = 0;
    for i in 1..n + 1 {
        let kosu = n / i;
        ans += i * (kosu * (kosu + 1) / 2);
    }
    io.writeln(ans);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2172
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main () {
	cin.tie(0);
	cin.sync_with_stdio(0);

	string s;
	cin >> s;
	int n = s.size();
	vector<bool> a(n+1);
	a[0] = true;
	for(int i = 0; i < n; ++i) {
		if(a[i] || i == 0) {
			if(s.substr(i, 5) == "dream") a[i + 5] = true;
			if(s.substr(i, 7) == "dreamer") a[i + 7] = true;
			if(s.substr(i, 5) == "erase") a[i + 5] = true;
			if(s.substr(i, 6) == "eraser") a[i + 6] = true;
		}
	}
	cout << (a.back() ? "YES" : "NO") << flush;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) FOR(i,0,n)
 
char f[55][55];

int main(){
	
	int n,k;cin>>n>>k;
	int ans = 1;
	rep(loop,n)
	{
		if(ans < k) ans*=2;
		else ans += k;		
	}
	cout << ans <<endl;
	
}

//cout << ans << endl;

Measured memory_bytes: 256
n, q = gets.chomp.split(" ").map(&:to_i)
strings = gets.chomp.chars
questions = []
q.times do
  f, s = gets.chomp.split(" ").map(&:to_i)
  questions.push([f, s])
end
exists = []
answers = []
count = 0
strings.each_with_index do |string, index|
  if string == "A" && strings[index + 1] == "C"
    count += 1
  end
  exists.push(count)
end

questions.each do |question|
  if question[0] == 1
    answers.push(exists[question[1] - 2])  
  else
    answers.push(exists[question[1] - 2] - exists[question[0] - 2])
  end
end

puts answers

Measured memory_bytes: 18296
object Main extends App {
  var input = readLine
  
  val N = input.split(" ")(0).toLong
  val A = input.split(" ")(1).toLong
  val B = input.split(" ")(2).toLong 
  var tuika: Long = 0
  
  if (N % (A+B) <= A) {
    tuika = N %  (A+B)
    //println(tuika)
  } else if (N % (A+B) > A) {
    tuika = A
    //println(tuika)
  }
  
  println( (N / (A+B)) * A + tuika )

}

Measured memory_bytes: 27332
import java.util.*;
import java.util.Map.Entry;
 
 

class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
   public static void main(String[] args) {
   
       Scanner sc = new Scanner(System.in);
       String s = sc.next();
       String t = sc.next();

       int[][] list = new int[26][2*s.length()];
       int[] lcnt = new int[26];
    		   
       for (int i=1;i<=s.length();i++) {
    	   int tmp=(int)s.charAt(i-1)-97;
    	   list[tmp][lcnt[tmp]]=i;
    	   lcnt[tmp]++;
       }
       for(int i=0;i<26;i++) {
    	   for(int j=0;j<lcnt[i];j++) {
        	   list[i][j+lcnt[i]]=list[i][j]+s.length(); 		   
    	   }
       }
       
       long cnt=0;
       int tmpcnt=0;
       for(int i=0;i<t.length();i++) {
    	   int tmp=(int)t.charAt(i)-97;
    	   if(lcnt[tmp]==0) {
    		   System.out.println(-1);
    		   return;
    	   }
    		   
    	   int right=2*lcnt[tmp];
    	   int left=-1;
    	   while(right-left>1) {
    		   int mid=left+(right-left)/2;
    		   if(list[tmp][mid]>tmpcnt) right=mid;
    		   else left=mid;
    	   }
    	   cnt=cnt+list[tmp][right]-tmpcnt;
    	   tmpcnt=(int) (cnt%s.length());
       }
       
    System.out.println(cnt); 	
              		
   }

}

Measured memory_bytes: 58460
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int n, r;
	cin >> n >> r;
	if (n>=10)
		cout << r << endl;
	else
		cout << r + (100 * (10 - n)) << endl;
	return (0);
}


Measured memory_bytes: 3628
n=int(input())
a=list(map(int,input().split()))
j=0
ans=1
for i in range(n-1):
    if j==0 and a[i]<a[i+1]:
        j=1
    elif j==0 and a[i]>a[i+1]:
        j=-1
    elif j*(a[i+1]-a[i])<0:
        j=0
        ans +=1
print(ans)

Measured memory_bytes: 14228
#include <string>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
int H, W, R, C; string s[1000], t[1000]; unsigned long long power[1001], h1[1000][1000], h2[1000];
int main() {
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) cin >> s[i];
	scanf("%d%d", &R, &C);
	for (int i = 0; i < R; i++) cin >> t[i];
	power[0] = 1;
	for (int i = 1; i <= 1000; i++) power[i] = power[i - 1] * 257;
	for (int i = 0; i < H; i++) {
		unsigned long long val = 0;
		for (int j = 0; j < C; j++) val = val * 257 + s[i][j]; h1[i][0] = val;
		for (int j = C; j < W; j++) val = val * 257 + s[i][j] - power[C] * s[i][j - C], h1[i][j - C + 1] = val;
	}
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) h2[i] = h2[i] * 257 + t[i][j];
	}
	for (int i = 0; i <= H - R; i++) {
		for (int j = 0; j <= W - C; j++) {
			bool flag = true;
			for (int k = i; k < i + R; k++) {
				if (h1[k][j] != h2[k - i]) {
					flag = false; break;
				}
			}
			if (flag) {
				printf("%d %d\n", i, j);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 12360
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

int n,a;
map<int,int> c;

int main(){
	cin>>n;
	rep(i,1,n){
		cin>>a;
		c[a]++;
	}
	if(c.size()==1&&c[0])return puts("Yes"),0;
	if(c.size()==2){
		int a=c.begin()->fi,Ca=c.begin()->se;
		int b=(--c.end())->fi,Cb=(--c.end())->se;
		if(!b)swap(a,b),swap(Ca,Cb);
		if(Ca*2==Cb&&a==0)puts("Yes");
		else puts("No");
		return 0;
	}
	if(c.size()!=3)return puts("No"),0;
	int las=c.begin()->se;
	int w[5],cur=0;
	for(auto x:c){
		if(x.se!=las)return puts("No"),0;
		w[cur++]=x.fi;
	}
	if((w[0]^w[1])==w[2])puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k)
    {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k)
    {
        return (-data[find(k)]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    vector<set<int>> block(N), fr(N);
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
        fr[a].insert(b);
        fr[b].insert(a);
    }
    rep(i, K)
    {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        block[c].insert(d);
        block[d].insert(c);
    }
    rep(i, N)
    {
        int num = uf.size(i) - 1 - fr[i].size() - block[i].size();
        for (auto j : block[i])
        {
            if (i != j and !uf.same(i, j))
                num++;
        }
        cout << num << " ";
    }
    return 0;
}

Measured memory_bytes: 29312
using System;
using System.Collections.Generic;

namespace beginer
{
    class Program
    {
        static void Main(string[] args)
        {
            var buf=Console.ReadLine().Trim().Split();
            int N=int.Parse(buf[0]);
            int M=int.Parse(buf[1]);
            List<List<int>> edges=new List<List<int>>();

            for(int k=0;k<N;k++){
                edges.Add(new List<int>());
            }

            List<bool> is_searched=new List<bool>();
            for(int i=0;i<N;i++){
                is_searched.Add(false);
            }

            for(int i=0;i<M;i++){
                buf=Console.ReadLine().Trim().Split();
                int a=int.Parse(buf[0])-1;
                int b=int.Parse(buf[1])-1;
                edges[a].Add(b);
                edges[b].Add(a);

            }


            int res=0;

            for(int j=0;j<N;j++){
                if(!is_searched[j]){
                    res++;
                    search_connection(j,is_searched,edges);
                }
            }

            Console.WriteLine(res-1);

        }

        static void search_connection(int num,List<bool> is_searched,List<List<int>> edges){
            is_searched[num]=true;
            var edgebuf=edges[num];
            int count=edgebuf.Count;

            if(count==0){
                is_searched[num]=true;
                return;
            }

            for(int i=0;i<count;i++){
                int n=edgebuf[i];
                if(!is_searched[n]){
                    search_connection(n,is_searched,edges);
                }
            }
            
            return;

        }
    }
}


Measured memory_bytes: 47316
#include <bits/stdc++.h>
using namespace std;
int MOD = 2019;
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<int> d(N);
  for (int i = 0; i < N; i++){
    d[i] = S[i] - '0';
  }
  for (int i = N; i > 0; i--){
    d[i - 1] = (d[i] + d[i - 1] * modpow(10, N - i)) % MOD;
  }
  d.push_back(0);
  N++;
  long long ans = 0;
  map<int, int> M;
  for (int i = 0; i < N; i++){
    if (M.count(d[i])){
      ans += M[d[i]];
    }
    M[d[i]]++;
  }
  cout << ans << endl;
}

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

int main()
{
	long long h;
	cin >> h;
	long long cont=1;
	long long suma=1;
	while(h>1)
	{
		h/=2;
		cont*=2;
		suma+=cont;
	}
cout << suma;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env fsharpi

open System;

let readIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let readInt1 ( str : string ) =
    readIntN str |> fun arr -> arr.[0]

let readInt2 ( str : string ) =
    readIntN str |> fun arr -> (arr.[0],arr.[1])

let readInt3 ( str : string ) =
    readIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let rec parse ( v: char list) =
    match v with
    | 'd'::'r'::'e'::'a'::'m'::'e'::'r'::'d'::remain -> parse ('d'::remain)
    | 'd'::'r'::'e'::'a'::'m'::'e'::'r'::'e'::remain -> parse ('e'::remain)
    | 'd'::'r'::'e'::'a'::'m'::'e'::'r'::[] -> parse []
    | 'e'::'r'::'a'::'s'::'e'::'r'::remain -> parse remain
    | 'd'::'r'::'e'::'a'::'m'::remain -> parse remain
    | 'e'::'r'::'a'::'s'::'e'::remain -> parse remain
    | [] -> ""
    | _ -> "."

Console.ReadLine()
|> Seq.toList
|> fun s -> if (parse s) = "" then "YES" else "NO"
|> Console.WriteLine


Measured memory_bytes: 9816
import java.util.Scanner;
import java.lang.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    sc.nextLine();//改行を取り除く
    String line = sc.nextLine();
    int M = sc.nextInt();
    String[] lineArray = line.split(" ", 0);
    int[] T = new int[N]; 
    int[] P = new int[M];
    int[] X = new int[M];
    for(int i=0; i<N; i++){
      T[i] = Integer.parseInt(lineArray[i]);
    }
    for(int i=0; i<M; i++){
      P[i] = sc.nextInt();
      X[i] = sc.nextInt();
    }
    for(int i=0; i<M; i++){
      int sum = 0;
      for(int j=0; j<N; j++){
        if(P[i]-1 == j){
          sum += X[i];
        }else{
          sum += T[j];
        }
      }
      System.out.println(sum);
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	int count[3] = { 0, 0, 0 };
	for (auto i = 0; i < N; ++i)
	{
		long long a;
		cin >> a;
		if (a % 4 == 0)
		{
			++count[2];
		}
		else if (a % 2 == 0)
		{
			++count[1];
		}
		else
		{
			++count[0];
		}
	}

	auto result = "Yes";
	if (count[1] == 0)
	{
		if (count[0] > count[2] + 1)
		{
			result = "No";
		}
	}
	else
	{
		if (count[0] > count[2])
		{
			result = "No";
		}
	}

	cout << result << endl;

	return 0;
}

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

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

  double ave=0;
  vector<double> arr;
  for (int i = 0; i < n; i++) {
    double tmp;
    cin>>tmp;
    arr.push_back(tmp);
    ave += tmp/n;
  }

  double min=10000;
  int min_frame=0;
  for (int i = 0; i < n; i++) {
    if(abs(arr[i]-ave)<min){
      min=abs(arr[i]-ave);
      min_frame=i;
    }
  }

  cout<<min_frame<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define up 1000

void insertionSort(int A[], int N){
    int i = 0;
    int j = 0;
    int v = 0;
    int l = 0;
    int k = 0;
    
    
    for(i = 1; i < N + 1; i++){
        for(l = 0; l < N; l++){
            k = N - 1;
            if(l == k){
                printf("%d\n", A[l]);
             }else{
                printf("%d ", A[l]);
            }
        }
        if(i != 0){
            v = A[i];
            j = i - 1;
            while(j >= 0 && A[j] > v){
                A[j+1] = A[j];
                j--;
            }
            A[j+1] = v;
        }
        
    }

}

int main(void){
    int N = 0;
    int A[up] = {};
    int i = 0;
    
    scanf("%d", &N);
    if(1 > N || 100 < N){
        printf("Error\n");
        scanf("2:%d", &N);
    }

    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
    
    insertionSort(A, N);
    
    return 0;
}

Measured memory_bytes: 604
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 220000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
vi dp(1000,-1);
int f(int a){
	if(dp[a]+1)return dp[a];
	return dp[a]=powmod(fact[a],MOD-2,MOD);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin>>n>>m;
	int t=1;
	bool x=0,y=0;
	vi in(n);
	rep(i,n){
		int a;cin>>a;
		in[i]=a;
		if(a/2%2)x=1;
		else y=1;
		t=lcm(t,a/2);
		if(t>m){
			cout<<0<<endl;
			return 0;
		}
	}
	bool h=true;
	rep(i,n)if((t-in[i]/2)%in[i])h=false;
	if(h)cout<<(m+t)/(t*2)<<endl;
	else cout<<0<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1e9+7;
const int maxn=100001;
const double pi = acos(-1.0);
const int mod=1e9+7;
using lb=long double;
int n;
int a[maxn];
int main()
{
    cin>>n;
    int num=0;
    int temp=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            num++;
        else if(a[i]%2==0)
            temp++;
    }
    num+=temp/2;
    if(num>=n/2)
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';
    return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
a=[list(input()) for _ in range(n)]
b=[list(input()) for _ in range(m)]

f=False
for i in range(n-m+1):
    for j in range(n-m+1):
        sc=0
        for k in range(m):
            for l in range(m):
                if a[k+i][l+j]==b[k][l]:
                    sc+=1
        if sc==m*m:
            f=True
print("Yes" if f else "No")


Measured memory_bytes: 40688
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn cmb(n: u64, r: u64) -> u64 {
    if n == 0 {
        0
    } else if r == 1 {
        n
    } else {
        (n * cmb(n - 1, r - 1)) / r
    }
}

fn solve(v: &Vec<u64>, a: i32, b: i32, n: i32) -> (f64, u64) {
    let ave: f64;
    let c: u64;
    if v[0] == v[(a - 1) as usize] {
        ave = v[0] as f64;
        let mut cnt: i32 = 0;
        for i in 0..n {
            if v[i as usize] == v[0] {
                cnt += 1;
            }
        }
        let mut ret: u64 = 0;
        for i in a..(b + 1) {
            ret += cmb(cnt as u64, i as u64);
        }
        c = ret;
    } else {
        let mut sum: u64 = 0;
        let va = v[(a - 1) as usize];
        let mut cnt1: i32 = 0;
        for i in 0..a {
            sum += v[i as usize];
            if v[i as usize] == va {
                cnt1 += 1;
            }
        }
        ave = (sum as f64) / (a as f64);
        let mut cnt2 = cnt1;
        for i in a..n {
            if v[i as usize] == va {
                cnt2 += 1;
            }
        }
        c = cmb(cnt2 as u64, cnt1 as u64);
    }
    (ave, c)
}

fn sort(v: &mut Vec<u64>,n:i32) {
    for i in 0..n{
        let mut j = i-1;
        while j>=0 && v[j as usize]<v[(j+1) as usize]{
            let tmp = v[(j+1) as usize];
            v[(j+1) as usize] = v[j as usize];
            v[j as usize] =tmp;
            j-=1;
        }
    }
}

fn main() {
    let v: Vec<i32> = read_vec();
    let n = v[0];
    let a = v[1];
    let b = v[2];

    let mut v: Vec<u64> = read_vec();
    //v.sort_unstable_by(|a, b| b.cmp(a));
    sort(&mut v,n);
    let (ave, cmb) = solve(&v, a, b, n);
    println!("{}", ave);
    println!("{}", cmb);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
int R, G, B, N;

int Ans() {
  int cnt = 0;
  int r = 0;
  while (r * R <= N) {
    int g = 0;
    int NN = N - (r * R);
    while (g * G <= NN) {
      if (((NN - (g * G)) % B) == 0) { ++cnt; }
      ++g;
    }
    ++r;
  }
  return cnt;
}

signed main() {
  cin >> R >> G >> B >> N;

  auto ans = Ans();

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i ,a, n) for (long long int i=a;i<=n;i++)
#define pb  push_back
#define mp make_pair
#define fp first
#define sp second
#define be(v) v.begin(),v.end()
typedef long long ll;
typedef vector<ll> vi ;
typedef vector<pair<ll , ll > >  vpi ;
const int ma1=3e5+5;
string no="NO",yes="YES";
#define MOD 1000000007
int max_char=26;
ll dp[100005][3]={0};
ll max1=1e15;
vector<ll> v;
int main()
{
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        ll a[n+1][2];
        for(int i=1;i<=n;i++)
        {
            cin>>a[i][0]>>a[i][1];
        }
        ll dp[n+1][100005];
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=100004;j++)
                dp[i][j]=max1;
        }
        dp[0][0]=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=100004;j++)
            {
                 dp[i][j]=dp[i-1][j];
                if(j-a[i][1]>=0)
                {
                    dp[i][j]=min(a[i][0]+dp[i-1][j-a[i][1]],dp[i-1][j]);
                }

            }
        }
        ll ans=0;
        for(int i=100000;i>=0;i--)
        {
            if(dp[n][i]<=m)
            {
                ans=i;
                break;
            }
        }
        cout<<ans;
    }
    return 0;
}
















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

int main() {
  ll h,w,k,kind=1;
  char s;
  cin >> h >> w >> k;
  vector<vector<ll>>a(h,vector<ll>(w));
  rep(i,h) rep(j,w){
  	cin >> s;
  	if(s=='#') { 
  		a.at(i).at(j)=kind;
  		kind++;
  	}
  }
  rep(i,h){
  	ll ind=0;
  	rep(j,w){
  		if(a.at(i).at(j)!=0){
  			for(ll k=ind;k<j;k++) a.at(i).at(k)=a.at(i).at(j);
  			ind=j+1;
  		}
  		else if(j==w-1){ for(ll k=max((ll)0,ind-1);k<w;k++) a.at(i).at(k)=a.at(i).at(max((ll)0,ind-1));
  		}
  	}
  }
  rep(i,h){
  	rep(j,w){
  		if(a.at(i).at(j)==0 && i!=0) a.at(i).at(j)=a.at(i-1).at(j);
  	}
  }
  rep(i,h){
  	rep(j,w){
  		if(a.at(h-1-i).at(j)==0 && h-1-i!=h-1) a.at(h-1-i).at(j)=a.at(h-i).at(j);
  	}
  }
  rep(i,h){
  	rep(j,w) cout << a.at(i).at(j) << " ";
  	cout << endl;
  }
}


Measured memory_bytes: 1536
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}

int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif

	ll n,x;
	cin>>n>>x;
	ll arr[n];
	ll s = 0;
	ll count = 0 ;
	for (int i = 0; i < n ; i++){
		cin>>arr[i];
		s += arr[i];
		if (s <= x){
			count++;
		}
	}
	cout<<count + 1<<endl;
}

Measured memory_bytes: 3564
// Shiritori

#include <stdio.h>
#include <string.h>
int main() {
	char A[11], B[11], C[11];
	scanf("%s %s %s", A, B, C);
	int lastA = strlen(A) - 1, lastB = strlen(B) - 1;
	if (A[lastA] == B[0] && B[lastB] == C[0]) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
typedef complex<ftype> point;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

const int MAXN = 2e5+5;
const int MOD = 1e9+7;

int N,Q;
vector<int> edges[MAXN];
int in[MAXN], out[MAXN];
int cur = -1;
int C[MAXN];

void dfs(int u, int p) {
    in[u] = ++cur;
    for(int v: edges[u]) {
        if(v != p) {
            dfs(v,u);
        }
    }
    out[u] = cur;
}

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> Q;
    fori(i,N-1) {
        int u,v;
        cin >> u >> v;
        edges[u].pb(v);
        edges[v].pb(u);
    }

    dfs(1,0);

    fori(q,Q) {
        int p,x;
        cin >> p >> x;
        C[in[p]] += x;
        C[out[p]+1] -= x;
    }

    int c = 0;
    fori(i,N) {
        //cout << i << ' ' << C[i] << endl;
        c += C[i];
        C[i] = c;
    }

    fore(i,1,N) cout << C[in[i]] << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 25088
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    // int T;cin>>T;while(T--) 
    {
        int a[5];
        ifr(i, 0, 5) cin>>a[i];
        ifr(i, 0, 5) if(!a[i]) {
            cout<<i+1<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include <math.h>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;
    // スペース区切りの整数の入力
    int d;
  cin >> d;
  int data[n][d];
  int a;
  for(int i = 0;i<n;i++){
      for(int j = 0;j<d;j++){
    cin >> a;
    data[i][j] = a;
  	}  
  }
  
  int count = 0;
  for(int i = 0;i< n ;i++){
      for(int j = i+1;j<n;j++){
        double sum =0;
         for(int m = 0;m<d;m++){
    sum += (data[i][m] - data[j][m])*(data[i][m] - data[j][m]);
         }
        
        
    double d =  sqrt(sum);
    int f = (int)d;
  	if(d==(double)f) count++;
      }  //
  }
  
  cout<<count;
    return 0;
}

Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll inf=1e18;

int n;
ll wag[nax];
ll wytrz[nax];
ll faj[nax];

int dos[nax];

ll dp[nax];

bool mniej(int a, int b)
{
    return min(wytrz[a], wytrz[b]-wag[a])<min(wytrz[b], wytrz[a]-wag[b]);
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld%lld%lld", &wag[i], &wytrz[i], &faj[i]);
		dos[i]=i;
	}
	sort(dos+1, dos+1+n, mniej);
	reverse(dos+1, dos+1+n);
	for (int h=1; h<=n; h++)
	{
		int i=dos[h];
		debug() << i;
		for (int j=wytrz[i]; j>=0; j--)
		{
			dp[j+wag[i]]=max(dp[j+wag[i]], dp[j]+faj[i]);
		}
	}
	ll wyn=0;
	for (int i=0; i<nax; i++)
		wyn=max(wyn, dp[i]);
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 8576
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    import math
    s = math.sqrt(n)
    i = 1
    mi_ = float('inf')
    while i <= s:
        if n % i == 0:
            mi_ = min(mi_,i + n//i - 2)
        i+=1
    print(mi_)
if __name__ == '__main__':
  main()


Measured memory_bytes: 3060