akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import sys
n=int(input().strip())
v=list(map(int, input().strip().split()))
counterO=defaultdict(int)
counterE=defaultdict(int)
for i in v[::2]:
    counterO[i]+=1
for i in v[1::2]:
    counterE[i]+=1
cOO=sorted(counterO.items(),key=lambda x:x[1],reverse=True)
cEE=sorted(counterE.items(),key=lambda x:x[1],reverse=True)
iO,iE=0,0
if cOO[iO][0]!=cEE[iE][0]:
    ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
else:
    iO2=iO+1
    iE2=iE+1
    ans1=sum(x[1] for x in cOO[:iO2]+cOO[iO2+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
    ans2=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE2]+cEE[iE2+1:])
    ans=min(ans1,ans2)
print(ans)

Measured memory_bytes: 21568
#include <bits/stdc++.h>
using namespace std;
int main(){
int h,w;
cin>>h>>w;
char buf[305][305];

for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
        cin>>buf[i][j];
        
        
    }
}

char a[305][305] = {};
for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
        a[i][j] = 48;
    }
}


for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
        if(buf[i][j]=='#'){
           
           a[i+1][j] +=1;
           a[i+1][j-1]+=1;
           a[i+1][j+1]+=1;
           a[i][j-1]+=1;
           a[i][j+1]+=1;
           a[i-1][j]+=1;
           a[i-1][j-1] +=1;
           a[i-1][j+1]+=1;
           
        }
    }
}

for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
       if(buf[i][j]=='#'){
           a[i][j]='#';
       }
        if(j%w==0){
            cout<<endl;
        }
        cout<<a[i][j];
    }
}
return 0;
}




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

#define INF 100000000
#define min(a,b) (a>b?b:a)

int dist(int a, int b, int x) {
  return abs((b/x)-(a/x)) + abs((b%x)-(a%x));
}

int main() {
  int n, a, b, c, d, ans=INF;
  cin >> n >> a >> b >> c >> d; --a, --b, --c, --d;
  for(int i=1; i<=n; ++i) {
    ans = min(ans, dist(a, b, i) + dist(c, d, i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
  int n,l,r,cnt=0,ind;
  cin >> n>>l>>r;
  while(n!=0){
    int a[n];
    cnt=0;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    for(int i=l;i<=r;i++){
      ind=-1;
      for(int j=0;j<n;j++){
        if(i%a[j]==0){
          ind=j+1;
          break;
        }
      }
      if(ind==-1){
        if(n%2==0)cnt++;
      }else{
        if(ind%2!=0)cnt++;
      }
    }
    cout << cnt << endl;
    cin >> n >> l >> r;
  }
}



Measured memory_bytes: 3076
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;

int main(){
    double a,b,c,s,l,h,rad;
    double PI=acos(-1);
    cin>>a>>b>>c;
    rad=c*PI/180.0;
    s=a*b*sin(rad)/2.0;
    l=a+b+sqrt(a*a+b*b-2.0*a*b*cos(rad));
    h=2.0*s/a;
    printf("%f\n%f\n%f\n",s,l,h);

    return 0;
}


Measured memory_bytes: 3452
N, C = map(int, input().split())
S = []
for i in range(N):
    S.append(list(map(int, input().split())))
S.sort()
R = [[] for i in range(C)]
for i in range(N):
    c = S[i][2] - 1
    if R[c]:
        if R[c][-1][1] == S[i][0]:
            R[c][-1][1] = S[i][1]
            continue
    R[c].append(S[i][:])
D = [0]*100001
for r in R:
    for s in r:
        for i in range(s[0], s[1]+1):
            D[i] += 1
print(max(D))    

Measured memory_bytes: 35680
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] != l[j] and l[j] != l[k] and l[i] != l[k] and l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[i] + l[k] > l[j]:
                ans += 1
print(ans)

Measured memory_bytes: 9208
N = int(input())

ball_position = []
for _ in range(N):
    i, j = map(int, input().split())
    ball_position.append((i, j))

    
def tup2_diff(a, b):
    ai, aj = a
    bi, bj = b
    return ((ai - bi, aj - bj))
  
calculation_list = []
for i in range(len(ball_position)):
    for j in range(len(ball_position)):
        if i == j:
            continue
        else:
            x , y = tup2_diff(ball_position[i], ball_position[j])
            if x > 0 or (x == 0 and y > 0):
                calculation_list.append((x, y))
           
import collections

c = collections.Counter(calculation_list).most_common(1)
if N == 1:
    print(1)
else:
    print(N - calculation_list.count(c[0][0]))

Measured memory_bytes: 39536
// EducationalDpContest.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, h;
	std::vector<int> heights;

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h;
		heights.push_back(h);
	}

	vector<int> m(n, 0);
	m[0] = 0;
	m[1] = abs(heights[1] - heights[0]);

	for (int i = 2; i < n; ++i)
	{
		m[i] = min(m[i - 2] + abs(heights[i] - heights[i - 2]), m[i - 1] + abs(heights[i] - heights[i - 1]));
	}

	cout << m[n - 1];
}



Measured memory_bytes: 1144
def main():
    K = int(input())

    check_list = set()
    check = 7 % K
    res = 1
    while check % K != 0:
        check = 10*check + 7
        check %= K
        res += 1
        if check not in check_list:
            check_list.add(check)
        else:
            print(-1)
            exit()
    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 200448
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), acum(N);
    REP(i, N) cin >> A[i];

    map<ll, ll> count;
    REP(i, N) {
        if(i==0) acum[i] = A[i];
        else acum[i] = A[i] + acum[i-1];
        count[acum[i]]++;
    }

    ll ans = count[0];
    for(auto x : count) {
        ans += x.second*(x.second-1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
  public static void print(String s, int a, int b) {
    System.out.println(s.substring(a, b + 1));
  }
  public static String reverse(String s, int a, int b) {
    String[] arr = s.split("");
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < a; i++) {
      sb.append(arr[i]);
    }
    for(int i = b; i > a - 1; i--) {
      sb.append(arr[i]);
    }
    for(int i = b + 1; i < s.length(); i++) {
      sb.append(arr[i]);
    }
    return sb.toString();
  }
  public static String replace(String s, String p, int a, int b) {
    String q = s.substring(0, a);
    String r = s.substring(b + 1);
    return q + p + r;
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int q = sc.nextInt();
    for(int i = 0; i < q; i++) {
      String order = sc.next();
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(order.equals("print")) {
        print(str, a, b);
      } else if(order.equals("reverse")) {
        str = reverse(str, a, b);
      } else {
        String p = sc.next();
        str = replace(str, p, a, b);
      }
    }
  }
}



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

int returnVal (char x)
{
    return (int) x - 97;
}

int main() {
    string S, T;
    cin >> S >> T;
    vector<vector<int>> repetitions(28, vector<int>(28));

    for (int i = 0; i<repetitions.size();i++)
    {
        for (int j = 0;j<repetitions.size();j++)
        {
            repetitions[i][j] = 0;
        }
    }
    for (int i = 0; i < S.size(); i++)
    {
        repetitions[returnVal(T[i])][returnVal(S[i])]++;
    }

    int counter;
    for (int i = 0; i<repetitions.size();i++)
    {
        counter = 0;

        for (int j = 0;j<repetitions.size();j++)
        {
            if (repetitions[i][j] > 0)
            {
                counter++;
            }
            if (counter > 1)
            {
                cout << "No";
                return 0;
            }
        }
    }

    for (int i = 0; i<repetitions.size();i++)
    {
        counter = 0;

        for (int j = 0;j<repetitions.size();j++)
        {
            if (repetitions[j][i] > 0)
            {
                counter++;
            }
            if (counter > 1)
            {
                cout << "No";
                return 0;
            }
        }
    }

    cout << "Yes";

    return 0;
}


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

int main(void){
    int n,i,q,j,temp;
    long long int sum;
    vector<int> num(100010);

    sum = 0;
    temp = 0;

    cin >> n;
    vector<int> a(n);
    for(i=0; i<n; i++){
        cin >> a.at(i);
        sum += a.at(i);
        num.at(a.at(i))++;
    }

    cin >> q;
    vector<int> b(q),c(q);
    vector<long long int> ans(q);



    for(i=0; i<q; i++){
        cin >> b.at(i) >> c.at(i);
        sum += (c.at(i) - b.at(i)) * num.at(b.at(i));
        temp = num.at(b.at(i));
        num.at(b.at(i)) = 0;
        num.at(c.at(i)) += temp;
        temp = 0;
        ans.at(i) = sum;
    }


    for(i=0; i<q; i++){
        cout << ans.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 5508
N=int(input())
S=input()

temp=list(S)
f=True

while f :
    f=False
    L=len(temp)
    for i in range(L-2,-1,-1):
        if  "".join(temp[i:i+2])=="()":
            temp.pop(i+1)
            temp.pop(i)
            f=True

Ltemp=len(temp)
if Ltemp==0:
    print(S)
    exit()
    
if temp[0]=="(":
    add=")"*len(temp)
    ans=S+add
else:
    cnt1=0
    cnt2=0
    for i in range(Ltemp):
        if temp[i]==")":
            cnt1+=1
        else:
            cnt2+=1
        add1="("*cnt1
        add2=")"*cnt2
    ans=add1+S+add2


print(ans)

Measured memory_bytes: 3064
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7
class UnionFind:
  def __init__(self,n):
    self.n=[-1]*n
    self.r=[0]*n
  def find_root(self,x):
    if self.n[x]<0:
      return x
    else:
      self.n[x]=self.find_root(self.n[x])
      return self.n[x]
  def unite(self,x,y):
    x=self.find_root(x)
    y=self.find_root(y)
    if x==y:return
    elif self.r[x]>self.r[y]:
      self.n[x]+=self.n[y]
      self.n[y]=x
    else:
      self.n[y]+=self.n[x]
      self.n[x]=y
      if self.r[x]==self.r[y]:
        self.r[y]+=1
  def root_same(self,x,y):
    return self.find_root(x)==self.find_root(y)
  def count(self,x):
    return -self.n[self.find_root(x)]
N,M = I()
p = l()
ans = 0
u = UnionFind(N)
for i in range(M):
    a,b = I()
    u.unite(a-1,b-1)
for i in range(N):
    if p[i] == i+1:
        ans += 1
    elif u.find_root(i) == u.find_root(p[i]-1):
        ans += 1
print(ans)

Measured memory_bytes: 21440
use whiteread::parse_line;

fn main() {
    let (n, k): (usize, usize) = parse_line().unwrap();
    let s: Vec<u32> = parse_line().unwrap();
    let mut a: Vec<f64> = vec![0.0];
    let mut ans: f64 = 0.0;

    for i in 0..n {
        a.push(a[i] + (1 + s[i]) as f64 / 2.0);
    }

    for i in 0..n - k + 1 {
        ans = ans.max(a[i + k] - a[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4968
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    char sss = '{';
    rep(i,n){
        sss = min(sss,s[i]);
    }
    rep(i,k){
        string t = s;
        reverse(t.begin(),t.end());
        s += t;
        vector<string>v;
        string mi = "{";
        for(int i=0;i<n;i++){
            string p;
            for(int j=i;j<i+n;j++){
                p.push_back(s[j]);
            }
            
            mi = min(mi,p);
        }
        reverse(mi.begin(),mi.end());
        s = mi;
        bool flag = 1;
        rep(i,n){
            if(s[i]!=sss)flag = 0;

        }
        if(flag)break;
    }
    reverse(s.begin(),s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> w(N); rep(i, 0, N) { cin >> w[i]; }
	auto f = [&](int P) {
		int x(0), sum(0), cnt(0);
		while (x < N) {
			while (x < N&&sum+w[x] <= P) {
				sum += w[x++];
			}
			cnt++; sum = 0;
			if (cnt == K + 1)return false;
		}
		return true;
	};
	int r = 100000 * 10000, l = 0;
	// (l,r]
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (f(mid))r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n; cin >> n;
    vector<int> hoge(n);
    for (int i = 0; i < n; i++){
        cin >> hoge[i];
    }
    for (int i = n - 1; i >= 0; i--){
        if (i == 0){
            cout << hoge[i];
            continue;
        }
        cout << hoge[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3124
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(ll i = a; i < b; i++)
#define repj(a,b)for(ll j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int main() {
	int a, b; cin >> a >> b;
	if (a >= 13)cout << b;
	else if (a >= 6)cout << b / 2;
	else cout << "0";
	cout << endl;
	//return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main() {
	int x, y;
	cin >> x ;
	if (x % 4 == 0 || x % 7 == 0) cout << "Yes" << endl;
	else if (x < 4) cout << "No" << endl;
	else {
		int flag = 0;
		int i = 4;
		while (x > i) {
			if ((x - i) % 7 == 0) {
				flag = 1;
				break;
			}
			i += 4;
		}
		if (flag) cout << "Yes" << endl;
		else cout << "No" << endl;
	}


}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N;	cin >> N;
	vector<char> S(N);
	for (int i = 0; i < N; ++i) {
		cin >> S[i];
	}
	bool isY = false;
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'Y') {
			isY = true;
          	break;
		}
	}
	if (isY) {
		cout << "Four" << endl;
		cin >> N;
		return 0;
	}
	cout << "Three" << endl;
	cin >> N;
	return 0;
}

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

const long mod = 1000000007;

long modinv(long a, long m) {
    long b = m, u = 1, v = 0;
    while (b) {
        long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){

    int N,K;
    cin >> N >> K;
    //N++;

    // (2*10^5) * (2*10^5) < 10^100 であるから+アルファ部分は別のものとして考えて良い
    // 選び方 \sum_{i=k}^{n} nCi である。選ぶ個数が違うような組み合わせで和が同じになるということはない
    // nCi = n! / ((n-i)! * i!) ← 間違い 選ぶ個数が同じところでは被りがある
    // i個選ぶときの max - i個選ぶときの min が正しそう

    long patterns = 0, tmp_patterns;

    for(int i=K;i<=N+1;i++){

        //tmp_patterns = 0;
        ////tmp_max_patterns = 0;
        ////tmp_min_patterns = 0;
        //for(long j=0;j<i;j++){
        //   //tmp_max_patterns += N-j;
        //   //tmp_min_patterns += j;
        //   tmp_patterns = (tmp_patterns % mod) + (N-2*j+1)%mod;
        //}
        //(N-i)*i%mod
        ////tmp_patterns = tmp_max_patterns - tmp_min_patterns;
       //
       //
        //cout << N << "C" << i << " : " << tmp_patterns << endl;
        //
        //patterns = ( (patterns % mod) + (tmp_patterns % mod) ) % mod;
        //cout << N << " select " << i << " " <<  ((N-i+1)*i+1) << " " << ((N-i+1)*i+1) % mod << endl;
        patterns = ( (patterns % mod) + (( (((N-i+1)%mod) * (i%mod))%mod +1) % mod) ) % mod;
   } 

    cout << patterns << endl;

    return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const int inf = 1e9 + 7;
const ll inf_ll = 1e18L + 7;

constexpr int mod = 1e9 + 7;

template <typename T>
void mini(T& a, T b) {
  a = min(a, b);
}

template <typename T>
void maxi(T& a, T b) {
  a = max(a, b);
}

void add_it(int& a, int b, int m) {
  a += b;
  if (a >= m) a -= m;
}

int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  vector<string> rows(h);
  for (int i = 0; i < h; ++i) {
    cin >> rows[i];
  }

  vector<vector<int>> dp(h, vector<int>(w, 0));
  dp[0][0] = 1;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      if (rows[i][j] == '.') {
        if (i >= 1) add_it(dp[i][j], dp[i - 1][j], mod);
        if (j >= 1) add_it(dp[i][j], dp[i][j - 1], mod);
      }
  printf("%d", dp[h - 1][w - 1]);
}


Measured memory_bytes: 5248
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N,A,B;
	scanf("%d %d %d",&N,&A,&B);

	int ans = 0,tmp_sum,tmp;

	for(int num = 1; num <= N; num++){

		tmp = num;
		tmp_sum = 0;

		while(tmp > 0){
			tmp_sum += tmp%10;
			tmp /= 10;
		}

		if(tmp_sum >= A && tmp_sum <= B){
			ans += num;
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		char[] S =sc.next().toCharArray();
		boolean flg = true;
		for (int i=0; i<A; i++) {
			if ( !(S[i]<='9' && S[i]>='0') ) {
				flg = false;
				break;
			}
		}
		for (int i=1; i<=B; i++) {
			if ( !(S[A+i]<='9' && S[A+i]>='0') ) {
				flg = false;
				break;
			}
		}
		if  (S[A]!='-') flg = false;
		if (S.length != (A+B+1)) flg = false;
		if (flg) System.out.println("Yes");
		else System.out.println("No");
	}
}


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

int main(){
	int x, y;
	cin >> x >> y;

	int absx = max(x, -x), absy = max(y, -y), rez = 0;

	if((absx > absy && x > 0) ||
		(absx < absy && x < 0)){
		++rez;
		x = -x; }
	const int diff = max(absx-absy, absy-absx);
	x += diff;
	rez += diff;
	if(x != y) ++rez;
	cout << rez << endl;
	return 0; }


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

int main() {
  int n;
  int a, b;
  cin >> n;
  ll sum = 0;
  bool cond = true;
  vector<P> tasks;
  rep(i ,n){
    cin >> a >> b;
    tasks.emplace_back(b, a);
  }
  sort(tasks.begin(), tasks.end());
  for(auto v: tasks){
    sum += v.second;
    if(sum > v.first){
      cond = false;
      break;
    }
  }
  cout << (cond ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 4e18+999999;


int main()
{
    int n;
    cin >> n;
    vector <vector <ll>> dp(n, vector <ll> (n, MOD));
    vector <vector <ll>> sum(n, vector <ll> (n));
    vector <ll> a(n);
    for (int i=0; i<n; ++i)
        cin >> a[i];

    for (int i=0; i<n; ++i)
        sum[i][i] = a[i], dp[i][i] = 0;

    for (int len=1; len<n; ++len)
    {
        for (int i=0; i+len<n; ++i)
        {
            int j = i + len;
            sum[i][j] = sum[i][j-1] + a[j];
            for (int k=i; k<j; ++k)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j]);
            dp[i][j] += sum[i][j];
        }
    }


    cout << dp[0][n-1];
    return 0;
}


Measured memory_bytes: 2816
import java.util.*;

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

Measured memory_bytes: 23124
#include<stdio.h>

int main (){
	int en500,en100,en50,ans,count,i,j,k;
    
        scanf("%d %d %d %d",&en500,&en100,&en50,&ans);
        
        for(i = 0; i <= en500;i++){
            for(j = 0; j <= en100;j++){
                for(k = 0; k <= en50;k++){
                    if(500*i+100*j+50*k == ans){
                        count++;
                    }    
                }
            }    
        }
    
        
    printf("%d",count);
	return 0;
  
}



Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//Union-Find??¨

int main(void){
	int x;
	cin>>x;
	cout<<x*x*x<<endl;
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
using namespace std;
int aa[200005];
int main()
{

    int a,b;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>aa[i];
    }
    sort(aa,aa+a);
    long long sum=0;
    for(int i=0;i<a-b;i++)
    {
        sum+=aa[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int count = 0;
    for (int i = 0; i < n; i++) {
      int d1 = Integer.parseInt(sc.next());
      int d2 = Integer.parseInt(sc.next());
      if (d1 == d2) {
        count++;
      } else {
        count = 0;
      }
      if (count == 3) {
        pw.println("Yes");
        return;
      }
    }
    pw.println("No");
  }
}


Measured memory_bytes: 35620
# C
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
max1 = max(A)#一番手
max_index = A.index(max1)#index
A.remove(max1)
max2 = max(A)

for i in range(N):
    if i==max_index:
        print(max2)
    else:
        print(max1)

Measured memory_bytes: 12512
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
a = [[-1]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if s[i][j] == ".":
      a[i][j] = 1
    dh = [-1,0,1,0]
    dw = [0,-1,0,1]
    for k in range(4):
      ii = i + dh[k]
      jj = j + dw[k]
      if 0 <= ii < H and 0 <= jj < W:
        if s[i][j] == "#" and s[ii][jj] == "#":
          a[i][j] = 1
          a[ii][jj] = 1
flag = True
for i in range(H):
  for j in range(W):
    if a[i][j] != 1:
      flag = False
      break
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 70948
import javax.swing.*;
import javax.swing.plaf.synth.SynthSpinnerUI;
import java.sql.SQLOutput;
import java.util.Scanner;
import java.util.function.DoubleToIntFunction;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        double r = scan.nextDouble();
        System.out.printf("%.10f %.10f",r*r*Math.PI,(2*r)*Math.PI);
    }
}


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

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

class Item{
public:
	int n,c,s,g;
	Item(int n=0,int c=0,int s=0,int g=0):n(n),c(c),s(s),g(g){}
};

class State{
public:
	int x,y,cost,sum,visited;
	State(int x=0,int y=0,int c=0,int s=0,int v=0):x(x),y(y),cost(c),sum(s),visited(v){}
};

int main(){
	int h,w;
	while(cin >> w >> h && h && w){
		int G[20][20], a[20][20], n, ans = 0;
        int n_i[10]; //商品番号を配列の番号に変換
		bool f[20][20][(1<<8)];
		Item item[8];
		queue<State> Q;
		State u,v;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				for(int k=0;k<(1<<8);k++) f[i][j][k] = false;

				char c;
				cin >> c;
				G[i][j] = true;
				a[i][j] = -1;
				if(c == '.') G[i][j] = false;
				else if(c == 'P'){
					u.y = i;
					u.x = j;
					f[i][j][0] = true;
					G[i][j] = false;
				} else a[i][j] = c - '0';
			}
		}

		cin >> n;
		for(int i=0;i<n;i++){
			cin >> item[i].n >> item[i].c >> item[i].s >> item[i].g;
            n_i[item[i].n] = i;
		}

		Q.push(u);
		while(!Q.empty()){
			u = Q.front();
			Q.pop();
            
			for(int i=0;i<4;i++){
				v = u;
				v.y += dy[i];
				v.x += dx[i];
				v.cost++;
				if(v.y >= 0 && v.y < h && v.x >= 0 && v.x < w && !f[v.y][v.x][v.visited]){
                    if(!G[v.y][v.x]){
                        f[v.y][v.x][v.visited] = true;
                        Q.push(v);
                    }
                    else if((v.visited & (1<<a[v.y][v.x])) == 0){
                        if(u.cost >= item[n_i[a[v.y][v.x]]].s && u.cost < item[n_i[a[v.y][v.x]]].g){
                            State v2 = u;
                            f[v2.y][v2.x][v2.visited] = true;
                            v2.visited = v2.visited | (1<<a[v.y][v.x]);
                            f[v2.y][v2.x][v2.visited] = true;
                            v2.sum += item[n_i[a[v.y][v.x]]].c;
                            ans = max(ans,v2.sum);
                            if(v2.visited != ((1<<n)-1)) Q.push(v2);
                        } else if(u.cost < item[n_i[a[v.y][v.x]]].s){
                            //変更点
                            State v2 = u;
                            v2.cost += item[n_i[a[v.y][v.x]]].s - v2.cost;
                            Q.push(v2);
                            //ここまで
                        }
                    }
                }
            }
            
        }
        cout << ans << endl;
    }
}

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

//Do not get frustrated over WA. Check for edge cases and runtime errors :)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> a(n);
    bool ok = true;
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] % 2 == 0 && !(a[i] % 3 == 0 || a[i] % 5 == 0)) ok = false;
    }
    if (ok) {
        cout << "APPROVED";
    }
    else {
        cout << "DENIED";
    }
    return 0;
}


Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.trim().split('\n')
let [N, M] = lines[0].trim().split(' ').map(Number)

const g = {}
let ai = 0
const map = {}
for (let i = 1; i <= M; i++) {
    const l = lines[i].trim().split(' ').map(Number)
    if (l.length < 2) {
        dummy++
    }
    const a = l[0]
    const b = l[1]
    if (!map[a] && !map[b]) {
        ai++
        if (a === b) {
            g[ai] = [a]
        } else {
            g[ai] = [a, b]
        }
        map[a] = ai
        map[b] = ai
    } else if (map[a] && map[b]) {
        if (map[a] !== map[b]) {
            if (g[map[a]].length > g[map[b]].length) {
                const _b = map[b]
                g[map[b]].forEach(n => {
                    g[map[a]].push(n)
                    map[n] = map[a]
                })
                delete g[_b]
            } else {
                const _a = map[a]
                g[map[a]].forEach(n => {
                    g[map[b]].push(n)
                    map[n] = map[b]
                })
                delete g[_a]
            }
        }
    } else if (map[a]) {
        g[map[a]].push(b)
        map[b] = map[a]
    } else if (map[b]) {
        g[map[b]].push(a)
        map[a] = map[b]
    }
}

let ans = 1
for (var key in g)  {
    ans = Math.max(ans, g[key].length)
}
console.log(ans)


Measured memory_bytes: 98580
W, H, x, y = map(int, input().split())

if (x == 0) or (x == W) or (y == 0) or (y == H) or (H / W * x).is_integer():
    if (x == W / 2) and (y == H / 2):
        print(W * H / 2, 1)
    else:
        print(W * H / 2, 0)
else:
    ans1 = min(x * H, (W - x) * H)
    ans2 = min(W * y, W * (H - y))
    if ans1 == ans2:
        print(ans1, 1)
    else:
        print(max(ans1, ans2), 0)


Measured memory_bytes: 3064
n=int(input())
A,G,C,T,mod,ans=0,1,2,3,pow(10,9)+7,0
dp=[[[[0]*4for k in range(4)]for j in range(4)]for i in range(n+1)]
dp[0][T][T][T]=1
for i in range(1,n+1):
  for j in range(4):
    for k in range(4):
      for l in range(4):
        for m in range(4):
          if(G,A,C)!=(k,l,m)!=(A,C,G)!=(k,l,m)!=(A,G,C)!=(j,l,m)!=(A,G,C)!=(j,k,m):
            dp[i][k][l][m]+=dp[i-1][j][k][l]
            dp[i][k][l][m]%=mod
for j in range(4):
  for k in range(4):
    for l in range(4):
      ans+=dp[n][j][k][l]
print(ans%mod)

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

using namespace std;

int n,sum=0;
int a[1000+10],b[1000+10],c[1000+10];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        c[i]=b[i]-a[i]+1;
    }
    for(int i=1;i<=n;i++)
    {
        sum=sum+c[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mxn(1e1 + 10), mxm(4e5 + 10);
const long long modl(1e9 + 7);
int nm, n, m, p, t, k, ans, l, r;
int a[mxn], b[mxn], h[mxn];
int main() {
  ios_base::sync_with_stdio(false);
//  freopen("in.txt", "r", stdin);///////////////////////////
//  cin >> nm;
  string s;
  while (cin >> s) {
    cout << s;
    if (*s.rbegin() == 's') cout << "e";
    cout << "s";
//    cout << ans;
    cout << endl;
  }
  return 0;
}
////////////////////////////////////////////////////////////////////////////////


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

const int MAX = 100005;
const int nil = -1;

int n, pos; // pre配列のみている位置
vector<int> pre, in, post;

void rec(int l, int r){
    if(l >= r) return;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), root));
    rec(l, m);
    rec(m+1, r);
    post.push_back(root);
}

void solve(){
    pos = 0;
    rec(0, pre.size());
    for(int i=0; i<n; ++i){
        if(i) cout << ' ';
        cout << post[i];
    }
    cout << endl;
}

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

    for(int i=0; i<n; ++i){
        cin >> k;
        pre.push_back(k);
    }

    for(int i=0; i<n; ++i){
        cin >> k;
        in.push_back(k);
    }

    solve();

    return 0;
}


Measured memory_bytes: 3168
import sys
import numpy as np
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
MOD = 10 ** 9 + 7
lcm = 1
for a in A:
    lcm *= a // gcd(lcm, a)

A = np.array(A)
B = lcm // A
answer = np.sum(B) % MOD
print(answer)


Measured memory_bytes: 272076
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <map>
#include <cmath>
#include <tuple>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;
ll LARGE = 1000000;


int main() {
	string n;
	cin >> n;
	ll sum = 0;
	vector<int> s(n.size());
	for (ll i = 0; i < n.size(); ++i) {
		s[i] = n[i] - '0';
	}
	for (ll i = 0; i < n.size(); ++i) {
		ll ii = n.size() - i - 1;
		int x = s[ii];
		if (ii == 0) {
			if (5 < x) {
				sum += 10 - x + 1;
			}
			else {
				sum += x;
			}
			break;
		}
		if (x == 5) {
			if (5 <= s[ii - 1]) {
				sum += 10 - x;
				++s[ii - 1];
			}
			else {
				sum += x;
			}
			continue;
		}
		if (5 < x) {
			sum += 10 - x;
			++s[ii - 1];
		}
		else {
			sum += x;
		}
	}
	cout << sum;
	return 0;
}
//
//int main() {
//	ll n, k;
//	cin >> n >> k;
//	vector<ll> a(n);
//	for (ll i = 0; i < n; ++i) {
//		cin >> a[i];
//	}
//	vector<ll> b(n * (n - 1) / 2);
//	ll cnt = 0;
//	for (ll i = 0; i < n - 1; ++i) {
//		for (ll j = i + 1; j < n; ++j) {
//			b[cnt] = a[i] * a[j];
//			++cnt;
//		}
//	}
//	sort(b.begin(), b.end());
//
//	cout << b[k - 1] << endl;
//	return 0;
//}


Measured memory_bytes: 5252
// https://paiza.hatenablog.com/entry/2015/01/21/%E3%80%90%E7%B4%AF%E7%A9%8D%E5%92%8C%E3%80%81%E3%81%97%E3%82%83%E3%81%8F%E3%81%A8%E3%82%8A%E6%B3%95%E3%80%91%E5%88%9D%E7%B4%9A%E8%80%85%E3%81%A7%E3%82%82%E8%A7%A3%E3%82%8B%E3%82%A2%E3%83%AB%E3%82%B4
function main(N, K) {
  const MOD = 1000000007;

  // 0 ,1, 2, 3
  const rui = [0];

  // 累積和
  for (let i = 0; i < N + 1; i++) {
    rui.push(i + rui[i]);
  }
  //console.log(rui);

  let res = 0;

  for (let i = K; i <= N + 1; i++) {
    //    console.log('i:', i);
    const min = rui[i] - rui[0];
    const max = rui[rui.length - 1] - rui[rui.length - 1 - i];

    res += max - min + 1;

    //    console.log(min, max);
  }

  console.log(res % MOD);
}

const input = require('fs').readFileSync('/dev/stdin', 'utf8').replace('\n', '').split(' ');
const N = parseInt(input[0]);
const K = parseInt(input[1]);

main(N, K);


Measured memory_bytes: 38624
//Keep Working Hard
  // I__Like__Food  

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define tracel5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)

const int N = 2005;

const int MOD = 1000000007;
int arr[N];

int32_t main()
{


    IOS


 int n;
  cin >> n;
  vector<int> color(9, 0);

  for(int i = 0; i < n; i++)
  {

   	int a;
    cin >> a;
    int b = min(a/400, 8LL);
    color[b]++;
  }

  int counter = 0;
  for(int i = 0; i < 8; i++)
  {
    if(color.at(i) != 0) counter++;
  }
  cout << max(1LL, counter) << ' ' << counter + color.at(8) << endl;






    return 0;
}




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

int main() {

	ll n; cin >> n;
	vector<ll> dp(n + 1, 100000000);
	dp[0] = 0;
	vector<ll> cost;
	cost.push_back(1);
	ll tmp;
	tmp = 6;
	while (tmp <= n) {
		cost.push_back(tmp);
		tmp *= 6;
	}
	tmp = 9;
	while (tmp <= n) {
		cost.push_back(tmp);
		tmp *= 9;
	}
	sort(cost.begin(), cost.end());
	for (ll i = 1; i <= n; i++) {		
		for (int j = 0; j < cost.size(); j++) {
			if (i < cost[j]) continue;
			dp[i] = min(dp[i], dp[i - cost[j]] + 1);			
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3868
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	vector<int> sum(1001);
	for (int i = 1; i <= 1000; i++)
		sum[i] = sum[i - 1] + i;
	vector<int> a(1001);
	for (int i = 0; i <= 1000; i++)
		for (int j = i + 2; j <= 1000; j++) {
			int x = sum[j] - sum[i];
			if (x <= 1000) a[x]++;
		}
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		cout << a[N] << endl;
	}
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < W + 2;i++){
        cout << "#";
    }
    cout << endl;
    string s;
    for (int i = 0; i < H;i++){
        cin >> s;
        cout << "#" << s << "#" << endl;
    }
    for (int i = 0; i < W + 2; i++)
    {
        cout << "#";
    }
    cout << endl;
}

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

typedef short sh;
typedef unsigned short ush;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef unordered_set<int> usi;
typedef string str;
#define INF 1000000000
#define mv 1000000007
#define ln '\n'
#define max(a,b) ((a>=b)?a:b)
#define min(a,b) ((a<=b)?a:b)
#define itrip(s1,n) for(int i=s1;i<n;i++)
#define jtrip(s2,m) for(int j=s2;j<m;j++)
#define irip(s1,n) for(int i=s1;i>n;i--)
#define jrip(s2,m) for(int j=s2;j>m;j--)
#define pb push_back

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//cout<<fixed;
	//cout<<setprecision(6);

	int n;
	cin>>n;
	set<int> s;
	itrip(0,n) {
		int temp;
		cin>>temp;
		s.insert(temp);
	}
	vector<set<int>::iterator> v;
	vi v2;
	set<int>::iterator it,it2;
	//cout<<s.size();
	while(s.size()>1) {

		//cout<<s.size();
		it=s.begin();
		it2=s.begin();
		it2++;
		while(it2!=s.end()) {
			v2.pb((*it2)%(*it));
			v.pb(it2);
			it2++;
		}
		itrip(0,v.size()) {
			s.erase(v[i]);
			if(v2[i])
				s.insert(v2[i]);
		}
		v.clear();
		v2.clear();
	}
	it=s.begin();
	cout<<*it<<ln;
	return 0;
}


Measured memory_bytes: 6516
n = int(input())
s_dict = {}

for _ in range(n):
  s = input()
  if s_dict.get(s, -1) == -1:
    s_dict[s] = 1
  else:
    s_dict[s] += 1

if len(s_dict) == 1:
  print(list(s_dict.keys())[0])
  exit()
  
s_dict2 = sorted(s_dict.items(), key=lambda x:x[1], reverse=True)
s_list = []
i = 0

while s_dict2[i][1] == s_dict2[0][1]:
  s_list.append(s_dict2[i][0])
  i += 1
  if i == len(s_dict2):
    break

s_list.sort()
for i in range(len(s_list)):
  print(s_list[i])


Measured memory_bytes: 45788
#include <stdio.h>

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int i,count = 0;
    
    for(i=a;i<b+1;i++){
        if(c%i==0){
            count+=1;
        }
    }
    printf("%d\n",count);
}


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

using namespace std;
vector<pair<char,long long> > siz;
int main(){
    string s;
    cin>>s;
    int l=(int)s.length();
    char now=s[0];long long num=1;
    for(int i=1;i<l;i++){
        if(s[i]==now){
            num++;
        }else{
            siz.push_back({now,num});
            now=s[i];
            num=1;
        }
    }
    siz.push_back({now,num});
    long long ans=0;
    int all=(int)siz.size();
    for(int i=1;i<all;i++){
        if(siz[i].first=='>'&&siz[i-1].first=='<'){
            ans+=max(siz[i].second,siz[i-1].second);
            long long le=siz[i-1].second-1;
            long long ri=siz[i].second-1;
            ans+=(le*(le+1)/2)+(ri*(ri+1)/2);
        }
    }
    if(siz[0].first=='>') ans+=siz[0].second*(siz[0].second+1)/2;
    if(siz[all-1].first=='<') ans+=siz[all-1].second*(siz[all-1].second+1)/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6904
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n, m;
    while(cin >> n >> m, n || m) {
        vector<pii> v;
        int d, p;
        rep(i,0,n) {
            cin >> d >> p;
            v.pb(pii(p, d));
        }
        sort(v.begin(), v.end(), greater<pii>());
        
        int ans = 0;
        int i = 0;
        while(m > 0 && i<v.size()) m -= v[i++].sc;
        if(m < 0) ans += (-1) * m * v[i-1].fr;
        for(int j=i; j<v.size(); j++) ans += v[j].fr * v[j].sc;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3252
def main():
    N, S = open(0).read().split()
    pre = S.count("E")
    ans = pre
    for Si in S:
        if pre < ans:
            ans = pre
        if Si == "E":
            pre -= 1
        else:
            pre += 1
    print(pre if pre < ans else ans)
    return


main()


Measured memory_bytes: 3572
n=gets.to_i
s=gets.chomp.chars
l=[0]
0.upto(n-1) do |i|
  if s[i]=="#"
    l << l[-1]+1
  else
    l << l[-1]
  end
end
r=[0]
(n-1).downto(0) do |i|
  if s[i]=="."
    r << r[-1]+1
  else
    r << r[-1]
  end
end
r.reverse!
m=1/0.0
0.upto(n) do |i|
  c=l[i]+r[i]
  m=c if m>c
end
puts m


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

using namespace std;

const int N = 1e3 + 5 , M = 12;
int cost[N] , boxes[N] , memo[N][1 << M] , n , m;
int solve (int i , int msk) {
    if (i == m) return msk == (1 << n) - 1 ? 0 : 1e9;
    int &ret = memo[i][msk];
    if (~ret) return ret;
    ret = min(solve(i + 1 , msk) , solve(i + 1 , msk | boxes[i]) + cost[i]);
    return ret;
}

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

    cin >> n >> m;

    for (int i = 0 ;i < m ;i++) {
        int cnt;
        cin >> cost[i] >> cnt;
        while (cnt--) {
            int b;
            cin >> b;
            boxes[i] |= 1 << (b - 1);
        }
    }

    memset(memo , -1 ,sizeof memo);
    int ans = solve(0 , 0);
    if (ans == 1e9) ans = -1;
    cout << ans;
}


Measured memory_bytes: 19768
#include<iostream>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    int n;
    cin >> n;
    int s[n];
    F(i,0,n) cin >> s[i];

    int q;
    cin >> q;
    int t[q];
    F(i,0,q) cin >> t[i];

    int cnt=0;
    F(i,0,q){
        int left=0,right=n-1;
        while(left<=right){
            int middle=(right+left)/2;
            if(t[i]==s[middle]){
                ++cnt;
                break;
            }
            else if(t[i]<s[middle]){
                right=middle-1;
            }
            else{
                left=middle+1;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3664