akhauriyash/Code-Regression huggingface dataset:
H,W = map(int,input().split())
A = [[0 for _ in range(W+1)]]
sumA = 0
for _ in range(H):
  row = [0] + list(map(int,input().split())) 
  A.append(row)
  sumA = sum(row)



c_num = 0
pros = []
for j in range(1,H+1):
  for i in range(1,W):
    if A[j][i]%2==1:
      pros.append([j,i, j,i+1])
      c_num += 1
      A[j][i] -= 1
      A[j][i+1] += 1
 
for j in range(H,1,-1):
  if A[j][W]%2==1:
    pros.append([j,W,j-1,W])
    c_num += 1
    A[j][W] -= 1
    A[j-1][W] += 1

print(c_num)
[print(*pro) for pro in pros]

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,H,W;
  cin>>N>>H>>W;
  cout<<(N-H+1)*(N-W+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main(void)
{
   int n;
   cin >> n;
   vector<int> v(n), c(n);
   rep(i, n) cin >> v[i];
   rep(i, n) cin >> c[i];

   int sum = 0;
   rep(i, n) {
       if(v[i] > c[i]) sum += v[i] - c[i];
   }
    cout << sum << endl;
    return 0;
}

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

int main(){
    ll a , b  ;
    cin >> a >> b ;
    vector<int> A(1001,0) ;
    rep(i,1000){
        A.at(i+1) = A.at(i) + (i+1) ;
        if(A.at(i+1) - A.at(i) == b - a ) cout << A.at(i) - a << endl;
    } 
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(){
  int a[10000],n,i,count=0;
int judge(int);
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
      count+=judge(a[i]);
    }
  printf("%d\n",count);
}
int judge(int a){
  int i;
  if(a<2) return 0;
  else if(a==2) return 1;
  if(a%2==0) return 0;
  for(i=3;i*i<=a;i+=2){
    if(a%i==0) return 0;
  }
  return 1;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

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

int main() {
    ll n, q, a, b, c, sum;
    sum += 0;
    ll cnt[100005];
    m0(cnt);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a;
        cnt[a]++;
        sum += a;
    }
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> b >> c;
        sum += (c - b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

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

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

    int max = 0, maxIdx = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > max) {
            max = a[i];
            maxIdx = i;
        }
    }
    int sec = 0, secIdx = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > sec && i != maxIdx) {
            sec = a[i];
            secIdx = i;
        }
    }

    for (int i = 0; i < n; i++) {
        if (i == maxIdx) cout << sec << endl;
        else cout << max << endl;
    }
}


Measured memory_bytes: 4316
import java.util.*;

public class Main {
    private static int H, W;
    private static int Sx, Sy, Ex, Ey;
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        Sy = sc.nextInt()-1;
        Sx = sc.nextInt()-1;
        Ey = sc.nextInt()-1;
        Ex = sc.nextInt()-1;
        int[][] mp = new int[H][W];
        for(int y=0;y<H;y++){
            String line = sc.next();
            for(int x=0;x<W;x++){
                mp[y][x] = (line.charAt(x) == '.') ? 0 : 1;
            }
        }
        //showMap(group);
        int[] dx={-1,1,0,0};
        int[] dy={0,0,-1,1};
        PriorityQueue<State> pq = new PriorityQueue<>(Comparator.comparingInt(p->p.cnt));
        Set<Integer> visited = new HashSet<>();
        pq.add(new State(Sx, Sy,0));
        while(!pq.isEmpty()){
            State now = pq.poll();
            if(visited.contains(now.y*W+now.x)){continue;}
            visited.add(now.y*W+now.x);
            if(now.x == Ex && now.y == Ey){
                System.out.println(now.cnt);
                return;
            }
            for(int d=0;d<4;d++){
                int tx=now.x+dx[d];
                int ty=now.y+dy[d];
                if(tx < 0 || tx >= W || ty < 0 || ty >= H){continue;}
                if(visited.contains(ty*W+tx)){continue;}
                if(mp[ty][tx] == 1){continue;}
                pq.add(new State(tx,ty,now.cnt));
            }
            for(int y=-2;y<=2;y++){
                for(int x=-2;x<=2;x++){
                    int ty=now.y+y;
                    int tx=now.x+x;
                    if(tx < 0 || tx >= W || ty < 0 || ty >= H){continue;}
                    if(visited.contains(ty*W+tx)){continue;}
                    if(mp[ty][tx] == 1){continue;}
                    pq.add(new State(tx, ty, now.cnt+1));
                }
            }
        }
        System.out.println(-1);
        return;


    }

    private static void showMap(int[][] m){
        for(int y=0;y<H;y++){
            for(int x=0;x<W;x++){
                System.out.print(m[y][x]);
            }
            System.out.println();
        }
    }

    private static class State{
        int x, y;
        int cnt;
        public State(int x, int y, int cnt){
            this.x=x;
            this.y=y;
            this.cnt=cnt;
        }
    }
}


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

int main(){
	int h,w;
	while(1){
		cin >> h >> w;
		if(h == 0 and w == 0) return 0;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if( (i+j)%2 == 0){
					cout << "#";
				}else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}		

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

int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define maxn 100010

int n, ceven, A[maxn];

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

int main() {
	int sum = 0; bool has1 = 0, cur = 0;
	n = read();
	for(int i = 1; i <= n; i++) A[i] = read(), ceven += !(A[i] & 1), has1 |= (A[i] == 1), (sum += A[i] - 1) &= 1;
	
	if(has1) return puts(sum ? "First" : "Second"), 0;
	if(ceven & 1) return puts("First"), 0;
	if(n - ceven > 1) return puts("Second"), 0;
	for(; ;) {
		cur ^= 1;
		for(int i = 1; i <= n; i++) if(A[i] & 1) A[i]--;
		int g = A[1];
		for(int i = 2; i <= n; i++) g = gcd(g, A[i]);
		ceven = sum = has1 = 0;
		for(int i = 1; i <= n; i++) A[i] /= g, ceven += !(A[i] & 1), has1 |= (A[i] == 1), (sum += A[i] - 1) &= 1;
		if(has1) return puts((sum ^ cur) ? "First" : "Second"), 0;
		if(n - ceven > 1) return puts(((ceven & 1) ^ cur) ? "First" : "Second"), 0;
	}
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

typedef struct {
	int p;
	int d;
} Patient;

static const int MAX_N = 10000;

Patient P[MAX_N];

int main(int argc, char**)
{
	int n, d1, d2;

	while( 1 )
	{
		cin >> n;
		if(n==0) break;

		int idx = 0;
		for(int i=0; i<n; i++)
		{
			cin >> P[i].p; 
			cin >> d1;
			cin >> d2;
			P[i].d = d1 + d2;

			if(P[idx].d < P[i].d)
			{
				idx = i;
			}
		}

		cout << P[idx].p << " " << P[idx].d << endl;
	}
}

Measured memory_bytes: 940
while True:
    try:
        line=input()

    except:
        break

    a,b,c,d,e,f=map(int, line.strip().split())

   
    
    y=(c*d-f*a)/(b*d-a*e)
    x=(c*e-f*b)/(a*e-b*d)

    if x<=0 and x>=-0.0005:
        x=0.000
    
    if y<=0 and y>=-0.0005:
        y=0.000
        
    print('{:.3f} {:.3f}'.format(x,y))
    
    

Measured memory_bytes: 6756
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, m;
    cin >> n >> m;
    set<int> x, y;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        if(a == 1) x.insert(b);
        else if(b == n) y.insert(a);
    }
    string yes = "POSSIBLE", no = "IMPOSSIBLE";
    REP(i, 2, n) {
        if(x.count(i) && y.count(i)) {
            cout << yes << endl;
            return 0;
        }
    }
    cout << no << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
const ll mod = 1e9 + 7;
int n;
ll a[N], b[N];
map<pair<ll, ll>, ll> mp;
ll ans = 1, cnt1, cnt2, cnt;
ll ksm(ll p, ll q) {
	ll ret = 1;
	while (q) {
		if (q & 1) ret = (ret * p) % mod;
		p = (p * p) % mod;
		q = q >> 1;
	}
	return ret;
}
ll f(ll x) {
	return ksm(2, x);
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] == 0 || b[i] == 0) {
			if (a[i] == 0 && b[i] == 0) {
				cnt++;
			} else if (a[i] == 0) {
				cnt1++;
			} else if (b[i] == 0) {
				cnt2++;
			}
			continue;
		}
		ll gcd = __gcd(a[i], b[i]);
		a[i] /= gcd;
		b[i] /= gcd;
		if (a[i] < 0) a[i] = -a[i], b[i] = -b[i];
//		cout << a[i] << " " << b[i] << endl;
		mp[make_pair(a[i], b[i])]++;
	}
	for (map<pair<ll, ll>, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second == 0) continue;
		ll u = it->first.first;
		ll v = it->first.second;
//		cout << u << " " << v << endl;
		ll now = f(mp[make_pair(u, v)]);
//		cout << f(mp[make_pair(u, v)]) << endl;
//		mp[make_pair(u, v)] = 0;
		v = -v;
		if (v < 0) v = -v, u = -u;
		if (mp.count(make_pair(v, u))) {
			now = (now + f(mp[make_pair(v, u)]) - 1) % mod;
			mp[make_pair(v, u)] = 0;
		}
		now = now % mod;
//		cout << now << endl;
		ans = (ans * now) % mod;
	}
	ans = (ans * ((f(max(cnt1, cnt2)) + f(min(cnt1, cnt2)) - 1) % mod)) % mod;
	ans += cnt;
	cout << (ans - 1 + mod) % mod;
	return 0;
}

Measured memory_bytes: 19220
N,M = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)


cum = [0]
##合計を配列の中に入れていく
(0..N-1).each do |i|
    cum << cum[i] + A[i]
end

##配列の中身を全てあまりにする
cum.map!{ |c| c % M }

#余りによって何個あるかをハッシュに入れる
hash = {}
cum.each do |c|
    if hash.has_key?(c)
        hash[c] += 1
    else
        hash[c] = 1
    end
end

count = 0
hash.values.each do |v|
    next if v == 1
    ##二つの組み合わせを選ぶためnP2
    count += v * (v - 1) / 2
end
p count
 


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, m, x;
  cin >> n;
  map<ll, ll> d;
  forll(i, 0, n){
	cin >> x;
	d[x]++;
  }

  cin >> m;
  forll(i, 0, m){
	cin >> x;
	d[x]--;
	if (d[x] < 0){
	  cout << "NO" << endl;
	  return 0;
	}
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 12800
#include<iostream>
#include<string>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;

int main(){
		
	int a[4];
	
	for(int i=0;i<4;i++){
	cin>>a[i];
	}
	
	
	sort(a, a+4);

	if(a[2]==a[3]){
	cout<<"yes"<<endl;
	}else cout<<"no"<<endl;
return 0;

}




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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define all(x) x.begin(),x.end()
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

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

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

LL dp[2005][2005];
PII val[2005];
int n;

LL dfs(int id, int l, int r){
    if(l>r)return 0;
    if(dp[l][r]!=-1)return dp[l][r];
    dp[l][r]=max(dfs(id+1,l+1,r)+1ll*abs(l-val[id].sd)*val[id].fi,dfs(id+1,l,r-1)+1ll*abs(r-val[id].sd)*val[id].fi);
    return dp[l][r];
}

int main(){
    n=read();
    for(int i=1;i<=n;++i){
        val[i]=MP(read(),i);
    }
    sort(val+1,val+n+1);
    reverse(val+1,val+1+n);
    memset(dp,-1,sizeof dp);
    cout<<dfs(1,1,n);

    return 0;
}



Measured memory_bytes: 35128
/*3.2 hightierra*/
#include <stdio.h>
 
int main(void){
    //変数の定義
    int N,amari;
    scanf("%d",&N);
    //amariにNの１の位を代入
    amari = N % 10;
 
    //amariの値で場合わけ
    if(amari==2 || amari==4 || amari==5 || amari==7 || amari==9){
          printf("hon");
    }else if(amari==0 || amari==1 || amari==6 || amari==8){
          printf("pon");
    }else{
      	  printf("bon");
    }
    return 0;
}

Measured memory_bytes: 1696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC178A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            if (x == 0)
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}


Measured memory_bytes: 27460
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,a[100005],ans;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for (i=0;i<n&&i<a[i+1];i++);
	bool f=(a[i]-i+1)&1,g=1;
	for (j=i+1;j<=n;j++) if (a[j]>=i) g^=1;
	if (f&&g) cout<<"Second"; else cout<<"First";
	return 0;
}

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

int dice(int *me,int ue,int mae){
  int migi,i=0;
  
    if(ue==me[0]){
      if(mae==me[1])migi=me[2];
      if(mae==me[2])migi=me[4];
      if(mae==me[4])migi=me[3];
      if(mae==me[3])migi=me[1];
      
    }else if(ue==me[1]){
      if(mae==me[0])migi=me[3];
      if(mae==me[3])migi=me[5];
      if(mae==me[5])migi=me[2];
      if(mae==me[2])migi=me[0];
    }else if(ue==me[2]){
      if(mae==me[0])migi=me[1];
      if(mae==me[1])migi=me[5];
      if(mae==me[5])migi=me[4];
      if(mae==me[4])migi=me[0];
    }else if(ue==me[3]){
      if(mae==me[0])migi=me[4];
      if(mae==me[4])migi=me[5];
      if(mae==me[5])migi=me[1];
      if(mae==me[1])migi=me[0];
    }else if(ue==me[4]){
      if(mae==me[0])migi=me[2];
      if(mae==me[2])migi=me[5];
      if(mae==me[5])migi=me[3];
      if(mae==me[3])migi=me[0];
    }else if(ue==me[5]){
      if(mae==me[1])migi=me[3];
      if(mae==me[3])migi=me[4];
      if(mae==me[4])migi=me[2];
      if(mae==me[2])migi=me[1];
    }
  return migi;
}

int main(){
  int me[5];       //サイコロの目
  int q;          //命令の数
  int ue,mae;     //面
  int j;
  
  for(j=0;j<6;j++){
  scanf("%d",&me[j]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d %d",&ue,&mae);
    int migi=dice(me,ue,mae);
    printf("%d\n",migi);
  }
  return 0; 
}







Measured memory_bytes: 2040
from collections import defaultdict

n = int(input())
v = [int(x) for x in input().split()]

v_odd = []
v_even = []

for i in range(n//2):
    v_odd.append(v[i*2])
    v_even.append(v[i*2+1])

d_odd = defaultdict(int)
d_even = defaultdict(int)

for x in v_odd:
    d_odd[x] += 1
for x in v_even:
    d_even[x] += 1

l_odd = list(d_odd.values())
l_even = list(d_even.values())
item_odd = list(d_odd)
item_even = list(d_even)

max_odd = max(l_odd)
max_even = max(l_even)
fin_max = max_odd + max_even
max_odd_l, max_even_l = [], []

for i,x in enumerate(l_odd):
    if x == max_odd:
        max_odd_l.append(i)

for i,x in enumerate(l_even):
    if x == max_even:
        max_even_l.append(i)

if len(max_odd_l) == 1 and len(max_even_l) == 1:
    if item_odd[max_odd_l[0]] == item_even[max_even_l[0]]:
        #compare both pattern
        l_odd.pop(max_odd_l[0])
        l_even.pop(max_even_l[0])
        second_odd, second_even = 0, 0
        if l_odd:
            second_odd = max(l_odd)
        else:
            second_odd = 0
        if l_even:
            second_even = max(l_even)
        else:
            second_even = 0
        fin_max = max(max_odd+second_even, max_even+second_odd)

print(n - fin_max)

Measured memory_bytes: 20576
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> k(n),d(n);
	vector<vector<int>> v(n);
	rep(i,n){
		int w;
		cin>>w;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
		d[i]=-1;
	}

	queue<int> q;
	q.push(0);
	d[0]=0;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		rep(i,k[x]){
			if(d[v[x][i]]==-1){
				d[v[x][i]]=d[x]+1;
				q.push(v[x][i]);
			}
		}
	}
	rep(i,n){
		cout<<i+1<<" "<<d[i]<<endl;
	}
}

Measured memory_bytes: 3104
#! env/bin/local python3
# -*- coding: utf-8 -*-

sentence: str = input()
n_sentence = len(sentence)
sentence += '*'
counter = 0
results = []

ans = {i+1: 0 for i in range(n_sentence)}

for n in range(n_sentence):
    counter += 1
    if sentence[n] != sentence[n+1]:
        results += [sentence[n], counter]
        counter = 0

index = 0

for n in range(len(results)//2):

    if results[2*n] == 'R':
        index += int(results[2*n+1])
        if int(results[2*n+1]) % 2 == 0:
            evens = int(results[2*n+1]) // 2
            odds = int(results[2*n+1]) // 2
            ans[index] += odds
            ans[index+1] += evens
        else:
            evens = (int(results[2*n+1]) - 1) // 2
            odds = (int(results[2*n+1]) + 1) // 2
            ans[index] += odds
            ans[index + 1] += evens


    if results[2*n] == 'L':
        index += 1
        if int(results[2 * n + 1]) % 2 == 0:
            evens = int(results[2 * n + 1]) // 2
            odds = int(results[2 * n + 1]) // 2
            ans[index] += odds
            ans[index - 1] += evens
        else:
            evens = (int(results[2 * n + 1]) - 1) // 2
            odds = (int(results[2 * n + 1]) + 1) // 2
            ans[index] += odds
            ans[index - 1] += evens
        index += int(results[2 * n + 1]) - 1

ans = ' '.join([str(c) for c in list(ans.values())])

print(ans)


Measured memory_bytes: 26492
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

struct UnionFind {
    vector<ll> par;

    UnionFind(ll N) : par(N) {
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    int root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(ll x, ll y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll n, m;
    cin >> n >> m;

    auto uf = UnionFind(n);
    vector<ll> res(m, 0);
    vector<ll> sizes(n, 1);
    vector<ll> A(m), B(m);

    for (ll i = 0; i < m; ++i) {
        cin >> A[i] >> B[i];
        --A[i]; --B[i];
    }

    for (ll i = m-1; i >= 0; --i) {
        ll a, b;
        a = A[i];
        b = B[i];
        if (uf.root(a) != uf.root(b)) {
            res[i] = sizes[uf.root(a)] * sizes[uf.root(b)];
            auto s = sizes[uf.root(a)] + sizes[uf.root(b)];
            uf.unite(a, b);
            sizes[uf.root(a)] = s;
        }
    }

    ll cur = 0;
    for (ll i = 0; i < m; ++i) {
        cur += res[i];
        cout << cur << endl;
    }

}


Measured memory_bytes: 5248
N,M=map(int,input().split())
A=list(map(int,input().split()))
G=sum(A)/(4*M)
A.sort()
A.reverse()
m=0
i=0
while A[i]>=G:
  m+=1
  if m==M:
    print("Yes")
    exit()
  i+=1
print("No")


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int n,m,k,ans=0;
    cin>>n>>m>>k;
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        if(a<k)ans++;
    }
    cout<<min(ans,m-ans)<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <functional>
#include <string.h>

using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#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()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge{
	int dst;
	ll cost;
	edge(int dst, ll cost){
		this->dst=dst; this->cost=cost;
	}

};


 
int V,E;
typedef vector<edge> edges;
vector<edges> g;

ll dat[305][305][305];
int n, m;

vector<P> lim[305];//

bool func(int  *tmp) {
	for (auto t : lim[tmp[2]]) {
		if (t.second == 1 && tmp[1] < t.first) {
			;
		}
		//
		else if(t.second == 2 && tmp[0] < t.first && t.first <= tmp[1]){
			;
		}
		else if (t.second == 3 && t.first <= tmp[0]) {
			;
		}
		else {
			return false;
		}
	}
	return true;
}



int main(){
	cin >> n >> m;
	int x, y, z;
	rep(i, m) {
		cin >> x >> y >> z;
		lim[y].push_back(P(x, z));
	}
	dat[0][0][0] = 1;
	int m;
	int tmp[3];
	for(int i=0;i<=n;i++){
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				
				tmp[0]=i; tmp[1]=j; tmp[2]=k;
				sort(tmp, &tmp[3]);
				m = tmp[2];
#if 1
				if(!func(tmp)){
					dat[i][j][k] = 0;
				}
#endif
				dat[m + 1][j][k] = (dat[m + 1][j][k] + dat[i][j][k]) % MOD;
				dat[i][m + 1][k] = (dat[i][m + 1][k] + dat[i][j][k]) % MOD;
				dat[i][j][m + 1] = (dat[i][j][m + 1] + dat[i][j][k]) % MOD;
			}
		}
	}
	ll ans = 0;
	rep(i, n) {
		rep(j, n) {
			ans = (ans + dat[n][i][j]) % MOD;
			ans = (ans + dat[i][n][j]) % MOD;
			ans = (ans + dat[i][j][n]) % MOD;//
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 221440
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
    cin>>n;
    string s=to_string(n);
    for(int i=n;;i++)
    {
        s=to_string(i);
        if(s[0]==s[1]&&s[2]==s[1]) 
        {
            cout<<i;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	int ans = -1;
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		if (i == 0) ans = A;
		else ans = __gcd(A, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int hand(char c){
    switch(c){
        case 'q': case'w': case'e': case'r': case't':
        case 'a': case's': case'd': case'f': case'g':
        case 'z': case'x': case'c': case'v': case'b':
            return 1;
        default: return 0;
    }
    return 0;
}
int main(void){
    while(1){
        char buf[50]="";
        scanf("%s",buf);
        if(buf[0]=='#') break;
        int len=strlen(buf);
        int left=hand(buf[0]);
        int ans=0;
        for(int i=1;i<len;i++){
            if(left&&hand(buf[i])==0){
                ans++;
                left=0;
            }else if(left==0&&hand(buf[i])){
                ans++; left=1;
            }
        }
        printf("%d\n",ans);
    }
}



Measured memory_bytes: 2104
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include <string>
using namespace std;

int main(){
    int ans=1;
    int N,X;
    cin>>N>>X;

    int L[100]={0};

    for(int i=0;i<N;i++){
        int a;
        cin>>L[i];
    }
    
    int x=0;
    for(int i=0;i<N;i++){
        x+=L[i];
        if(x>X){
            break;
        }
        else{
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False
        self.ds_memo = {}
        self.ds_memo[1] = set([1])

    def is_prime(self, n):
        return self.A[n]

def main():
    x = I()
    pr = Prime(10**11)
    while not pr.is_prime(x):
        x += 1

    return x


print(main())




Measured memory_bytes: 9236
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";

	static int count(int r1, int c1, int r2, int c2)
	{
		out.printf("? %d %d %d %d\n", r1, c1, r2, c2);
		out.flush();
		return ni();
	}
	
	static void end(boolean[][] map, int mod)
	{
		long h = 0;
		long t = 1;
		for(int i = 0;i < map.length;i++){
			for(int j = 0;j < map[0].length;j++){
				h += (map[i][j] ? 1 : 0) * t;
				h %= mod;
				t = t * 2 % mod;
			}
		}
		out.println("! " + h);
		out.flush();
	}
	
	static void solve()
	{
		int h = ni(), w = ni(), n = ni(), K = ni();
		boolean[][] map = new boolean[h][w];
		dfs(0, h, 0, w, n, map);
		end(map, K);
	}
	
	static void fill(int r1, int r2, int c1, int c2, boolean[][] map)
	{
		for(int k = r1;k < r2;k++){
			for(int l = c1;l < c2;l++){
				map[k][l] = true;
			}
		}
	}
	
	static void dfs(int r1, int r2, int c1, int c2, int n, boolean[][] map)
	{
		if(n == (r2-r1)*(c2-c1)){
			fill(r1, r2, c1, c2, map);
			return;
		}
		if(r2-r1 == 1){
			dfs2(r1, r2, c1, c2, n, map);
			return;
		}
		int hr = (r1+r2)/2;
		int co = count(r1, c1, hr-1, c2-1);
		if(co > 0){
			dfs(r1, hr, c1, c2, co, map);
		}
		if(n-co > 0){
			dfs(hr, r2, c1, c2, n-co, map);
		}
	}
	
	static void dfs2(int r1, int r2, int c1, int c2, int n, boolean[][] map)
	{
		if(n == (r2-r1)*(c2-c1)){
			fill(r1, r2, c1, c2, map);
			return;
		}
		int hc = (c1+c2)/2;
		int co = count(r1, c1, r2-1, hc-1);
		if(co > 0){
			dfs2(r1, r2, c1, hc, co, map);
		}
		if(n-co > 0){
			dfs2(r1, r2, hc, c2, n-co, map);
		}
	}
	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
//	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
	static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 17712
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  	int N;
	cin >> N;
    vector<int> A(N), B(N), C(N-1);

    for(int i = 0 ; i < N ; i ++){
        cin >> A[i];
    }
    for(int i = 0 ; i < N ; i ++){
        cin >> B[i];
    }
    for(int i = 0 ; i < N-1 ; i ++){
        cin >> C[i];
    }

    int ans = 0;

    for(int i = 0 ; i < N ; i ++){
        ans += B[A[i]-1];
        if(i < N-1 && A[i] == A[i+1] - 1){
            ans += C[A[i] - 1];
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cstring>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    string a;
    cin >> a;
    for(int i = a.length()- 1; i >= 0; --i){
        cout << a[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1172
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<map>
#include<queue>


using namespace std;

using vi=vector<int>;
using vvi=vector<vi>;


int main(void)
{
	int n, m;
	vvi c;

	while(scanf("%d%d", &n, &m)==2)
	{
		c.clear();
		c.resize(n+1);
		for(int i=0;i<m;i++)
		{
			int a, b;

			scanf("%d%d", &a, &b);
			c[a].push_back(b);
			c[b].push_back(a);
		}
		for(int i=1;i<=n;i++)
		{
			printf("%d\n", c[i].size());
		}
	}

	return 0;
}


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

int mod = (int) 1e9 + 7;
long factorials[500020];

int pre_factorials(int n){

    factorials[0] = 1;

    for (int i = 0; i < n; i++) {
        factorials[i + 1] = (long)(i + 1) * factorials[i] % mod;
    }
    
    return 0;
}

long modpow(long a, long p){
    
    if (p == 0) return 1;
    
    if (p % 2 == 0) {
        return modpow(a * a % mod, p / 2);
    
    } else
        return a * modpow(a, p - 1) % mod;
}

long Comb(long a, long b){

    long af = factorials[(int) a];
    long bf = factorials[(int) b];
    long abf = factorials[(int) (a - b)];
    long res = af * modpow(bf, mod - 2) % mod * modpow(abf, mod - 2) % mod;
    return res;
}

long Perm(long a, long b){

    long af = factorials[(int) a];
    long abf = factorials[(int) (a - b)];
    long res = af * modpow(abf, mod - 2) % mod;
    return res;
}

int main(){
    
    long N, M;
    cin >> N >> M;
    
    pre_factorials(500010);
    
    long x, ans = 0;

    for (int i = 0; i <= N; i++){
        
        if (i % 2 == 0){
            x = 1;
        } else {
            x = -1;
        }
        
        ans += Comb(N, i) * x * Perm(M, i) % mod * Perm(M - i, N - i) % mod * Perm(M - i, N - i) % mod;
        ans %= mod;
    }
    
    if (ans < 0) ans += mod;
    
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 7092
s = set(input())
alp = "abcdefghijklmnopqrstuvwxyz"
alpl = [i for i in alp]
for i in s:
    if i in alp:
        alpl.remove(i)
if len(alpl) != 0:        
    print(sorted(alpl)[0])

else:
    print("None")


Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

vector<int> v;
set<int> st;
void dfs(string S, int depth = 0) {
    if(depth > 9) return;
    if(st.find(stoll(S)) == st.end()) {
        v.push_back(stoll(S)); 
        st.insert(stoll(S));
    } else {
        return;
    }
    char c = S.back();
    char c1 = c - 1;
    char c2 = c + 1;

    string S1 = S + c1;
    string S2 = S + c2;
    S = S + c;

    dfs(S, depth + 1);
    if(c1 >= '0')dfs(S1, depth + 1);
    if(c2 <= '9') dfs(S2, depth + 1);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K; cin >> K;
    rep(i, 9) {
        string S = "";
        S +=  (char)('1' + i);
        dfs(S);
    }
    sort(v.begin(), v.end());
    cout << v[K - 1] << endl;
    

    return 0;
}


Measured memory_bytes: 14256
#include<stdio.h>

int n , k;
int max = -1;
int w[100000];

int check( int P ){
	
	int i = 0;
	int s;
	
	for( int j = 0; j < k; j++ ){
		
		s = 0;
		
		while( s + w[i] <= P ){
			
			s += w[i];
			i++;
			if( i == n ) { return n; }
			
		}
		
	}
	
	return i;
	
}

int solve(){
	
	int left = 0;
	int right = n * max;
	int mid;
	int v;
	
	while( left + 1 < right ){
		
		mid = ( right + left ) / 2;
		v = check(mid);
		
		if( v >= n ){
			right = mid;
		}else{
			left = mid;
		}
		
	}
	
	return right;
	
}

int main( void ){
	
	int ans;
	
	scanf( "%d %d" , &n , &k );
	
	for( int i = 0; i < n; i++ ){
		scanf( "%d" , &w[i] );
		if( max < w[i] ){ max = w[i]; }
	}
	
	ans = solve();
	
	printf( "%d\n" , ans );
	
}


Measured memory_bytes: 2244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
int main() {
	int n;
	cin>>n;
	vector<long long>a(n);
	rep(i,n)cin>>a[i];
	sort(a.begin(),a.end());
	int kotae=0;
	rep(i,n-2){
		for(int j=i+1;j<n-1;j++){
			for(int k=j+1;k<n;k++){
				if(a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i])kotae++;
			}
		}
	}
	cout<<kotae<<endl;
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
	
	HashMap<String, Integer> cache = new HashMap<String, Integer>();
	
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int numSets = input.nextInt();
		String[] data = new String[numSets*2];
		for(int i = 0; i < numSets*2; i++) {
			data[i] = input.next();
		}
		
		for(int i = 0; i < data.length; i+=2) {
			System.out.println(solveMatrix(data[i], data[i+1]));
		}
		
		
	}
	public static int solveMatrix(String a, String b) {
		int[][] arr = new int[a.length() + 1][b.length() + 1];
		for(int i = 1; i <= a.length(); i++) {
		for(int j = 1; j <= b.length(); j++) {
		if(!a.substring(i-1, i).equals(b.substring(j-1, j))) {
		arr[i][j] = Math.max(arr[i-1][j], arr[i][j-1]);
		} else {
		arr[i][j] = 1 + arr[i-1][j-1];
		}
		}
		}
		return arr[a.length()][b.length()];
	}
}


Measured memory_bytes: 545860
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N, M;
vector<vector<int>> G;
vector<long double> DP;

long double dp(int s, int t) {
	for (int n = N - 1; n >= 1; n--) {
		int rn = G[n].size();
		if (s == n)rn--;
		if (rn == 0) {
			DP[n] = LLONG_MAX;
			continue;
		}
		DP[n] = 0;
		for (int next : G[n]) {
			if (n == s && next == t)continue;
			if (DP[next] == LLONG_MAX) {
				DP[n] = LLONG_MAX;
				continue;
			}
			DP[n] += (1 + DP[next]) / rn;
		}
	}
	return DP[1];
}

long double dpp(int s, int t) {
	vector<long double> D(N+1,0);
	for (int n = N - 1; n >= 1; n--) {
		int rn = G[n].size();
		if (s == n)rn--;
		if (rn == 0) {
			D[n] = LLONG_MAX;
			continue;
		}
		for (int next : G[n]) {
			if (n == s && next == t)continue;
			if (D[next] == LLONG_MAX) {
				D[n] = LLONG_MAX;
				continue;
			}
			D[n] += (1 + D[next]) / rn;
		}
	}
	return D[1];
}


int main() {
	cin >> N >> M;
	G.resize(N + 1);
	for (int m = 0; m < M; m++) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
	}
	DP.resize(N + 1);
	DP[N] = 0;
	long double ans = LLONG_MAX;
	ans = min(ans, dp(0, 0));
	for (int s = 1; s < N; s++) {
		//一番影響がでかい辺を探す
		long double maxe = -1;
		int maxt = 0;
		for (int t : G[s]) {
			if (maxe < DP[t]) {
				maxe = DP[t];
				maxt = t;
			}
		}
		ans = min(ans,dpp(s, maxt));
	}
	cout << setprecision(12) << ans << endl;
	return 0;
}


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N,M;
vector<int>v1,v2;
vector<int>h(N),w(M);

int main(){
  while(cin >> N >> M && N && M){
    v1.clear();
    v2.clear();
    h.resize(N+1);
    w.resize(M+1);
    rep(i,N) cin >> h[i+1];
    rep(i,M) cin >> w[i+1];
    
    rep(i,N) h[i+1] += h[i];
    rep(i,M) w[i+1] += w[i];
  
    for(int i=0;i<=N;i++){
      for(int j=i+1;j<=N;j++){
	v1.push_back(h[j]-h[i]);
      }
    }

    for(int i=0;i<=M;i++){
      for(int j=i+1;j<=M;j++){
	v2.push_back(w[j]-w[i]);
      }
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
  
    int res = 0;
    rep(i,v1.size()){
      vector<int>::iterator it = lower_bound(v2.begin(), v2.end(), v1[i]);
      while(it != v2.end() && *it == v1[i]){
	res++;
	it++;
      }
    }

    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 14880
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
#define int long long
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,a[maxn],b[maxn];
signed main(){
	n=read();
	for(int i=1;i<=n+1;i++)a[i]=read();
	for(int j=1;j<=n;j++)b[j]=read();
	int ans=0;
	int l=n+1,r=n;
	while(1){
		if(r>l)r=l;
		if(l-r>1)l--;
		if(l==0||r==0)break;
		if(b[r]>a[l]){
			ans+=a[l];
			b[r]-=a[l];
			l--;
		}
		else if(b[r]==a[l]){
			ans+=a[l];
			b[r]=a[l]=0;
			r--;l--;
		}
		else{
			ans+=b[r];
			a[l]-=b[r];
			r--;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 3003,mo=998244353;
inline void add(int &x, int y){x=x+y<mo?x+y:x+y-mo;}
inline void sub(int &x, int y){x=x-y>=0?x-y:x-y+mo;}
inline int power(int a, int n) {
	int res=1;
	while (n) {
		if (n&1) res=1LL*res*a%mo;
		a=1LL*a*a%mo; n>>=1;
	}
	return res;
}
int a,b,c,d,f[N][N],g[N][N];
int main() {
	read(a);read(b);read(c);read(d);
	f[c][d]=1;
	rep(i,c,c)per(j,d,1)f[i][j]=1ll*power(i,d-j)%mo;
	per(i,c-1,1)per(j,d,1){
		g[i][j]=1ll*(g[i][j+1]+f[i+1][j+1])*i%mo;
		//rep(k,j+1,d)add(f[i][j],1ll*f[i+1][k]*power(i,k-j)%mo);
		f[i][j]=g[i][j];
		add(f[i][j],1ll*f[i+1][j]*j%mo);
	}
//	rep(i,0,1)rep(j,0,1)cerr<<f[a][b]<<endl;
	cout<<f[a][b];
	return 0;
}


Measured memory_bytes: 73828
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
for l in range(N + 1 - K):
    r = l + K - 1
    ans = min(ans, min(abs(X[l]), abs(X[r])) + X[r] - X[l])
print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct edge{
    int to,cost;
};

const int N = 100000;
vector<edge> G[N];

const ll INF = LLONG_MAX/3;

int main(){
    int n,m,s,t;
    scanf(" %d %d %d %d", &n, &m, &s, &t);
    --s;
    --t;
    rep(i,m){
        int v[3];
        rep(j,3){
            scanf(" %d", &v[j]);
            --v[j];
        }

        int d;
        scanf(" %d", &d);

        rep(j,3){
            int x = v[j], y = v[(j+1)%3];
            G[x].pb({y,d});
            G[y].pb({x,d});
        }
    }

    using P = pair<ll,int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    vector<ll> d(n,INF);
    pq.push({0,s});
    d[s] = 0;
    while(!pq.empty()){
        P now = pq.top();
        pq.pop();
        int v = now.se;
        if(now.fi>d[v]) continue;
        for(const auto &e:G[v]){
            if(d[e.to] > d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                pq.push({d[e.to], e.to});
            }
        }
    }

    printf("%lld\n", d[t]);
    return 0;
}



Measured memory_bytes: 16760
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long ll;
ll n,a[N],sum;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  ll num=n*(n+1)/2;
  if(!(sum%num)){
    ll cnt=sum/num,ans=0;
    bool f=true;
    for(int i=0;i<n;i++){
      ll cal=a[(i+1)%n]-a[i];
      if((cnt-cal)%n)f=false;
      cal=(cnt-cal)/n;
      if(cal<0)f=false;
      else ans+=cal;
    }
    if(f&&ans==cnt)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false) , cin.tie(0) ;
#define w(x) cout << (#x) << " is " << x << "\n" ;

int main()
{
    //fast ;
//#ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//#endif
    int k,i;
    string s;
    cin >> k >> s ;
    if(s.size()<=k)
        cout << s <<"\n";
    else
    {
        for(i=0 ; i<k ; i++)
            cout << s[i];
        cout << "...\n";
    }
    return 0;
}


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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N,A,B,C,D; cin >> N >> A >> B >> C >> D;
    string S; cin >> S;
    FOR(i,A,C-1){
        if(S[i]=='#' && S[i+1]=='#'){
            cout << "No" << endl;
            return 0;
        }
    }
    FOR(i,B,D-1){
        if(S[i]=='#' && S[i+1]=='#'){
            cout << "No" << endl;
            return 0;
        }
    }

    if(D<C){
        bool flag = true;
        FOR(i,B-2,D-1){
            if(S[i]=='.' && S[i+1]=='.' && S[i+2]=='.'){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640