akhauriyash/Code-Regression huggingface dataset:
let (n1, n2, n_limit) = (4, 16, 45)

let area =
  [| [1; 4]; [0; 2; 5]; [1; 3; 6]; [2; 7]
   ; [0; 5; 8]; [1; 4; 6; 9]; [2; 5; 7; 10]; [3; 6; 11]
   ; [4; 9; 12]; [5; 8; 10; 13]; [6; 9; 11; 14]; [7; 10; 15]
   ; [8; 13]; [9; 12; 14]; [10; 13; 15]; [11; 14] |]

let goal = Array.init n2 (fun i -> (i + 1) mod n2)

let md = Array.make_matrix n2 n2 0

let initialize_md () =
  for i = 0 to n2 - 2 do
    for j = 0 to n2 - 1 do
      md.(i+1).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done

let idastar a limit space_i lower =
  let rec doit i space_i moved lower =
    if i = limit then begin
      if a = goal then begin
        List.length moved - 1 |> Printf.printf "%d\n";
        exit 0;
      end
    end else
      List.iter (fun j ->
        let x = a.(j) in
        if x = List.hd moved then () else
        let lower = lower - md.(x).(j) + md.(x).(space_i) in
        if lower + i > limit then ()
        else begin
          a.(j) <- 0;
          a.(space_i) <- x;
          doit (i + 1) j (x :: moved) lower;
          a.(j) <- x;
          a.(space_i) <- 0;
        end) area.(space_i) in
  doit 0 space_i [-1] lower

let () =
  initialize_md ();
  let a = Array.init n2 (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let rec f i =
    if i = n2 then assert false
    else if a.(i) = 0 then i
    else f (i + 1) in
  let space_i = f 0 in
  let rec g i acc =
    if i = n2 then acc
    else g (i + 1) (acc + md.(a.(i)).(i)) in
  let lower = g 0 0 in
  for limit = lower to n_limit do
    idastar a limit space_i lower
  done

Measured memory_bytes: 4544
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return (a * b) // gcd(a, b)

round=lambda x:(x*2+1)//2

a, b, c, d = map(int, input().split())
a -= 1
l = lcm(c, d)
x = a - a // c - a // d + a // l
y = b - b // c - b // d + b // l
print(y - x)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;

int main(){
	int n;
	cin >> n;
	
	vector<int> A(n);
	
	for (int i=0;i<n;i++){
		cin >> A[i];
	}
	
	vector<int> DP(n,INT_MAX);
	for(int i=0;i<n;i++){
		*lower_bound(DP.begin(),DP.end(),A[i])=A[i];
	}
	
	cout << lower_bound(DP.begin(),DP.end(),INT_MAX)-DP.begin() <<endl;
	
	return 0;
}

Measured memory_bytes: 1796
n, m, c = gets.chomp.split.map(&:to_i)
b_arr = gets.chomp.split.map(&:to_i)
ans = 0
n.times do
  a_arr = gets.chomp.split.map(&:to_i)
  cnt = 0
  m.times do |i|
    cnt+=a_arr[i]*b_arr[i]
  end
  if cnt+c > 0
    ans+=1
  end
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define INF 1145141919
using namespace std;
 
int main()
{
	int n, k, a[100001];
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	int r = k;
	int ans = 0;
	while(r < n) {
		r += k - 1;
		++ans;
	}
	cout << ans + 1 << endl;
	return 0;
}

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

int h, w;
string s[20];
int dist[20][20];

const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };
int sub(int x, int y) {
  const int inf = 1e9;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      dist[i][j] = inf;
    }
  }
  
  using PP = pair<int, int>;
  queue<pair<int, PP>> que;
  que.push(make_pair(0, PP(x, y)));
  while (!que.empty()) {
    auto q = que.front(); que.pop();
    int d = q.first;
    int i = q.second.first;
    int j = q.second.second;
    if (i < 0 || i >= h) continue;
    if (j < 0 || j >= w) continue;
    if (s[i][j] == '#') continue;
    if (dist[i][j] != inf) continue;
    dist[i][j] = d;
    for (int k = 0; k < 4; ++k) {
      int ni = i + di[k];
      int nj = j + dj[k];
      que.push(make_pair(d + 1, PP(ni, nj)));
    }
  }
  
  int mx = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (dist[i][j] == inf) continue;
      mx = max(mx, dist[i][j]);
    }
  }
  
  return mx;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  
  int mx = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      mx = max(mx, sub(i, j));
    }
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
	int sum,pascal[10]={1,9,36,84,126,126,84,36,9,1};
	double t;
	char input[11];
	while (scanf(" %s",input)!=EOF) {
		sum=0;
		for (int i=0; i<10; i++) sum+=(input[i]-'0')*pascal[i];
		printf("%d\n",sum%10);
		
	}
}

Measured memory_bytes: 968
import java.util.*;
import java.math.*;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
    int p = stdIn.nextInt();
    int k = 3*a;
    k = k + p;
    int u = 0;
    if(k%2==0) {
      u = k/2;
    } else {
      k = k -1;
      u = k/2;
    }
    System.out.println(u);

  }
}


Measured memory_bytes: 23892
from copy import deepcopy
def main():
    s = list(input())
    t = list(input())
    tlen = len(t)
    kohos = []
    for i1 in range(len(s) - tlen + 1):
        s_range = s[i1:i1 + tlen]
        flag = 1
        for i2 in range(tlen):
            if s_range[i2] != '?' and s_range[i2] != t[i2]:
                flag = 0
        if flag:
            s_koho = deepcopy(s)
            s_koho[i1:i1 + tlen] = t
            kohos.append(s_koho)
    if kohos:
        kohos.sort()
        koho0 = deepcopy(kohos[0])
        koho0 = ['a' if c == '?' else c for c in koho0]
        r = "".join(koho0)
        print(r)
    else:
        print('UNRESTORABLE')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <iostream>

using namespace std;

int main() {
	int a, b, c, x; cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0; i <= a; ++i)
		for (int j = 0; j <= b; ++j)
			for (int k = 0; k <= c; ++k)
				if (i * 500 + j * 100 + k * 50 == x) ans++;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
a1,a2,a3=map(int,input().split())
a4,a5,a6=map(int,input().split())
a7,a8,a9=map(int,input().split())
a=[a1,a2,a3,a4,a5,a6,a7,a8,a9]
n=int(input())
s=[]

for i in range(n):
  s.append(int(input()))
for ss in s:
  if ss in a:
    a[a.index(ss)]=-1

if a[0]+a[1]+a[2]==-3 or a[3]+a[4]+a[5]==-3 or a[6]+a[7]+a[8]==-3 or a[0]+a[3]+a[6]==-3 or a[1]+a[4]+a[7]==-3 or a[2]+a[5]+a[8]==-3 or a[0]+a[4]+a[8]==-3 or a[2]+a[4]+a[6]==-3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long all=1;
        long res;
        long zero=1;
        long nine=1;
        long zeronine=1;

  
        for(int i=0; i<N; i++){
            all = (all*10)%((long)Math.pow(10,9)+7);
        }

        for(int i=0; i<N; i++){
        zero = (zero*9)%((long)Math.pow(10,9)+7);
        }
        
        nine = zero;

        for(int i=0; i<N; i++){
            zeronine = (zeronine*8)%((long)Math.pow(10,9)+7);
        }

        res = (all -zero -nine + zeronine)%((long)Math.pow(10,9)+7);
        if(res<0){
            res = (long)Math.pow(10,9)+7+res;
        }
        
        System.out.println(res);
        
        }
    }

Measured memory_bytes: 35748
#include<iostream>
#include<string>
#include<cstdio>
#include<cctype>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<stack>
#include<map>
#include<bitset>
#include <cstdlib>
#include<cstring>
#define ll long long;
#define pb push_back
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const double eps = 1e-11;
const double pi = acos(-1.0); 
using namespace std;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
#define ma = 2147483647;
#define mi = -2147483647;

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

	string s;
	cin >> s;
	if (s == "ABC")
		cout << "ARC";
	else cout << "ABC";





	return 0;
}

Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

int const inf = (1LL<<31)-1;
int const B = 1024;
struct RMQ {
    int n;
    vector<int> Bmin;
    vector<vector<int>> dat;
    RMQ(int n_){
        n = n_;
        if(n%B) n += B-n%B;
        dat.assign(n/B,vector<int>(B,inf));
        Bmin.assign(n/B,inf);
    }
    void set(int idx, int x){
        get(idx) = x;
        Bmin[idx/B] = inf;
        for(int i=0;i<B;i++) Bmin[idx/B] = min(Bmin[idx/B], get(idx/B*B+i));
    }
    int & get(int idx){
        return dat[idx/B][idx%B];
    }
    int rmq(int l, int r){
        int res = inf;
        if(l/B != r/B){
            while(l%B){
                res = min(res, get(l));
                l++;
            }
            while(r%B){
                r--;
                res = min(res, get(r));
            }

            for(int i=l/B;i*B<r;i++){
                res = min(res, Bmin[i]);
            }
        } else {
            while(l<r){
                res = min(res, get(l));
                l++;
            }
        }
        return res;
    }
};

int main(){
    int n,q;
    cin >> n >> q;
    RMQ rmq(n);
    rep(i,q){
        int c, x, y;
        cin >> c >> x >> y;
        if(c) cout << rmq.rmq(x,y+1) << endl;
        else rmq.set(x,y);
    }
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void printArray(const int *arr, int n);
void printArray(const vector<int> &arr);

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;

int main(){
	scanf("%d %d", &n, &k);
    double ans = 0;
    for(int i=1;i<=n;++i){
        double tmp = ceil(log2(1.0*k/i));
        if(tmp <= 0) tmp = 0;
        ans += pow(0.5, tmp);
    }
    ans /= n;
    printf("%.10lf\n", ans);
	return 0;
}

/* Template Function */
void printArray(const int * a, int n){
	for(int i=0;i<n;++i){
		printf("%d ", a[i]);
	}
	puts("");
}

void printArray(const vector<int> &arr){
	for(int x : arr){
		printf("%d ", x);
	}
	puts("");
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

main(){
    INCANT;
    int x, y, res = 0;
    double a, b;
    string s;
    in(a, b, x, y);
    out(a * b / 2), space();
    if(2 * x == a && 2 * y == b){
        print(1);
    }else{
        print(0);
    }
}


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

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

    vector<ll> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        b.at(i) = a.at(i);
    }
    sort(b.begin(), b.end());
    ll mid = b.at(n/2);
    for(auto x: a){
        if(mid<=x) cout << b.at(n/2-1) << endl;
        else cout << mid << endl;
    }
}

Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){   
   int n;
   cin>>n;
   int a[n];
      for (int i = 0; i < n; i++)
      {
         cin>>a[i];
      }
      int count=0;
      for(int i=0;i<n-2;i++){
         if(a[i]<a[i+1] && a[i+1]<a[i+2]) count++;
         if(a[i]>a[i+1] && a[i+1]>a[i+2]) count++;
      }
   cout<<count;
   

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int a, b, c = 0;
    cin >> a >> b;
    if(a > b){
    	c += a;
    	a--;
    }else{
    	c += b;
    	b--;
    }
    c += max(a, b);
    cout << c << endl;;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <bitset>
#include <regex>
#include <cassert>
#include <set>
#include <map>
using namespace std;
#define inf 2000000000
#define mod 1000000007

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k, a, b;
	cin >> k;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if ((i % k) == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}

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

const int N = 200010;

typedef long long LL;

int fa[N], p[N], c0[N], c1[N];

struct node {

int u, c0, c1;

bool operator < (const node &b) const {
    LL t1 = (LL)c1 * b.c0, t2 = (LL)c0 * b.c1;
    if (t1 != t2) return t1 < t2;
    return u < b.u;
}

};

int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

set<node> s;

int main() {
    int n; scanf("%d", &n);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]);
    for (int i = 1, a; i <= n; i++) {
        scanf("%d", &a), c0[i] = a == 0, c1[i] = a == 1, fa[i] = i;
        if (i != 1) s.insert((node){i, c0[i], c1[i]});
    }
    LL res = 0;
    while (!s.empty()) {
        int u = s.begin()->u; s.erase(s.begin());
        int t = find(p[u]); 
        if (t != 1) s.erase((node){t, c0[t], c1[t]});
        res += (LL)c1[t] * c0[u], c1[t] += c1[u], c0[t] += c0[u];
        fa[u] = t;
        if (t != 1) s.insert((node){t, c0[t], c1[t]});
    }
    printf("%lld\n", res);
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
# define LL          long long
# define pr          pair
# define mkp         make_pair
# define lowbit(x)   ((x)&(-x))
# define PI          acos(-1.0)
# define INF         0x3f3f3f3f3f3f3f3f
# define eps         1e-6
# define MOD         1000000007

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
# define MX 100005
/**************************/

int n, m;

int main()
{
    scanf("%d%d",&n,&m);
    double p = 1.0/pow(2.0,m);
    double base = 1;
    double tis = 0;
    for (int i=1;i<=100000;i++)
    {
        tis = tis + base * p * i;
        base *= (1-p);
    }
    int ans = floor(tis+eps);
    printf("%d\n",ans*((n-m)*100+m*1900));
    return 0;
}


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

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

    long long present_min = nums[0];
    long long acc = 0;
    for (auto k : nums){
        if (k <= present_min){
            acc++;
        }
        if (k < present_min){
            present_min = k;
        }
    }
    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<complex>
#define EPS 10e-9
using namespace std;
typedef complex<double> p;
int main()
{
	p a,b,c,d;
	while(cin>>a.real()>>a.imag()>>b.real()>>b.imag()>>c.real()>>c.imag()>>d.real()>>d.imag())
	{
		if( abs((b-a).real()*(d-c).real()+(b-a).imag()*(d-c).imag()) < EPS ) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
  return 0;
}

Measured memory_bytes: 1216
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// Effective std
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }

template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }

template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }

template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }

template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }

template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }


// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int arr[4][3][10];
int main() {
  int n;
  cin>>n;
  for(int i=0; i<n; i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    arr[a-1][b-1][c-1]+=d;
    }
   for(int i=0; i<4; i++){
       for(int j=0; j<3; j++){
           for(int k=0; k<10; k++){
             cout<<" "<<arr[i][j][k];
        }
             cout<<endl;
      }
      if(i==3){
        continue;
      }cout<<"####################"<<endl;
    }
}

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

const int N = 512;

int h, w, a[N][N];
vector<tuple<int, int, int, int>> ps;

int main() {
  scanf("%d%d", &h, &w);
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 1; i < h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (a[i][j] & 1) {
        ps.emplace_back(i, j, i + 1, j);
        ++a[i + 1][j];
      }
    }
  }
  for (int j = 1; j < w; ++j) {
    if (a[h][j] & 1) {
      ps.emplace_back(h, j, h, j + 1);
      ++a[h][j + 1];
    }
  }
  printf("%d\n", int(ps.size()));
  for (const auto& t : ps) {
    int y, x, y2, x2;
    tie(y, x, y2, x2) = t;
    printf("%d %d %d %d\n", y, x, y2, x2);
  }
  return 0;
}


Measured memory_bytes: 5232
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
	int n;

	cin >> n;

	if (n % 2 == 0) {
		cout << n / 2;
	}
	else {
		cout << (n + 1) / 2;
	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace ALDS1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] R = new int[n];

            for (int t = 0; t < R.Length; t++)
            {
                R[t] = int.Parse(Console.ReadLine());
            }

            int max = int.MinValue;
            int min = R[0];

            
                for (int j = 1; j < R.Length; j++)
                {
                    if (R[j]-min  >max )
                    {
                    max = R[j] - min;
                    }
                if (R[j] < min)
                {
                    min = R[j];
                }
                }
                
            Console.WriteLine(max);
        }
    }
}

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

const int MAXN = 100100;
int n;
char s[MAXN];
int main() {
	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j <= i + 2 && j < n; ++j) {
			if (s[i] == s[j]) {
				cout << i + 1 << " " << j + 1 << "\n";
				return 0;
			}
		}
	cout << -1 << " " << -1 << "\n";
	return 0;
}




Measured memory_bytes: 384
// C - Green Bin
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	sort(s.begin(), s.end());
	long long ans = 0;
	for (int i = 0, j = 0; i < s.size(); i++) {
		if (i + 1 == n || s[i + 1] != s[j]) {
			ans += (long long) (i + 1 - j) * (i - j) / 2;
			j = i + 1;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
# coding: utf-8
# Your code here!

import math

d,g = map(int,input().split())
pl = []
cl = []

for i in range(d):
    p,c = map(int,input().split())
    pl.append(p)
    cl.append(c)
    

ans = float('inf')
for i in range(2 ** d):
    op = [0] * d
    for j in range(d):
        if ((i >> j) & 1):
            op[j] = 1  # フラグが立っていた箇所を "+" で上書き

    tmp_ans = 0
    tmp_point = 0
    
    for idx, (o,p,c) in enumerate(zip(op, pl, cl)):
        tmp_ans += o*p
        tmp_point += o*c + (idx+1) * 100 * p*o
        
    
    for k in range(d-1, -1, -1):
        if (i >> k) & 1: 
            continue
        if tmp_point >= g:
            break
        for l in range(pl[k] + 1):
            tmp_point += 100 * (k + 1)
            tmp_ans += 1
            if tmp_point >= g:
                break
    if ans > tmp_ans:
        ans = tmp_ans
print(ans)
    
        

Measured memory_bytes: 43504
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A.reverse()
B.reverse()

inc = 0
for i in range(N):
    A[i] += inc

    # 不足分
    x = A[i]%B[i]
    if x == 0:
        continue

    diff = B[i] - x
    inc += diff

print(inc)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll n, d;
    cin >> n >> d;
    int cnt = 0;
    for (i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#define loop(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int a=0, b=0, temp;
  loop(i,4){
    cin>>temp;
    a+=temp;
  }
  loop(i,4){
    cin>>temp;
    b+=temp;
  }
  cout<<max(a,b)<<endl;
  return 0;
}

Measured memory_bytes: 3092
n,k=map(int,input().split())
INF=10**18
sushi=[[-INF] for _ in range(n)]
for _ in range(n):
  t,d=map(int,input().split())
  sushi[t-1].append(d)
for i in range(n):
  sushi[i].sort(reverse=True)
sushi.sort(key=lambda x:x[0],reverse=True)
q=[]
res=0
for i in range(k):
  res+=sushi[i][0]
  for j in sushi[i][1:]:
    q.append(j)
q.sort()
cur=res
res+=k**2
for var in range(1,k)[::-1]:
  a=q.pop()
  b=sushi[var][0]
  cur+=a-b
  res=max(res,cur+var**2)
print(res)

Measured memory_bytes: 23036
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(5,2,mod)


X, Y = map(int, input().split())

a = (2*X-Y)/3.0
b = (2*Y-X)/3.0

if a.is_integer() == True and b.is_integer() == True:

    print(cmb(int(a)+int(b),int(a), mod))

else:
    print(0)

Measured memory_bytes: 127816
/// Bismillahir Rahmanir Rahim
/* Author: Mohammad Morsalin (aka white_space)
    Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    ms(arr);
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int x;
            cin>>x;
            arr[x]++;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(arr[i]==0)cnt++;
    }
    cout << cnt <<endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3616
from heapq import heappop, heapify, heappush


x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = [-i for i in C]
A.sort(reverse=True)
B.sort(reverse=True)
AB = A[:x] + (B[:y])

heapify(AB)
heapify(D)
ans = 0
for _ in range(c):
    d = -heappop(D)
    ab = heappop(AB)
    if ab > d:
        heappush(AB, ab)
        break
    heappush(AB, d)
ans = sum(AB)
print(ans)


Measured memory_bytes: 116816
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  int s;
  for(int i = 1; i < N + 2; i++){
    s = i * 1.08;
    if(s == N){
      cout<<i<<endl;
      break;
    }
    else if(i == N + 1){
      cout<<":("<<endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue
#define    nl           "\n"
#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mpi map<int,int>
#define mpl map<ll,ll>
#define umpi unordered_map<int,int>
#define umpl unordered_map<ll,ll>
#define si set<int>
#define sl set<ll>
#define msi multi_set<int>
#define msl multi_set<ll>

#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)
#define tc int t;cin>>t;while(t--)
template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}

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

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................


int main()
{   
     auto start = chrono::high_resolution_clock::now();
    fast
    ll n;
    cin>>n;
    vll a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    ll ans=0;
    ll k=n-2;
    ans+=a[n-1];
    for(ll i=n-2;i>=0;i--){
        if(k==0)
        break;
        if(k>1){
            ans+=2*a[i];
            k-=2;
        }
        else if(k>0){
            ans+=a[i];
            k--;
        }
        
    }
    cout<<ans<<nl;
    auto end = chrono::high_resolution_clock::now();
    TIME(start, end);
    return 0;
}

Measured memory_bytes: 4768
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    int a,b,c=1,d;
    cin>>a>>b;
    d=(a*2)-1;
    for(int i=0; i<d; i++){
    cout<<b-(a-c)<<" ";
    c++;
    }
    cout<<'\n';
    return(0);
    }


Measured memory_bytes: 256
A,B = map(int, input().split())
def cf(A,B):
    Af = []
    Bf = []
    for i in range(1,round(A**0.5)+1):
        if A % i == 0:
            Af.append(i)
            Af.append(A//i)
    for i in range(1,round(B**0.5)+1):
        if B % i == 0:
            Bf.append(i)
            Bf.append(B//i)
    cf = list(set(Af).intersection(Bf))
    return cf
L = cf(A,B)
ans = 0
def is_prime(n):
    cd = []
    for i in range(1,round(n**0.5)+1):
        if n % i == 0:
            cd.append(i)
    if cd == [1]:
        return True
    else:
        return False
for i in L:
    if is_prime(i):
        ans += 1
print(ans)

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

using namespace std;

typedef pair<double,double> dd;

int n;
dd a[9];
int p[9];

double cal(int x,int y)
{
	return sqrt((a[x].first - a[y].first)*(a[x].first - a[y].first) + (a[x].second - a[y].second)*(a[x].second - a[y].second));
}

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

	cin >> n;
	for (int i=1;i<=n;i++)
		cin >> a[i].first >> a[i].second;
  	for (int i=1;i<=n;i++)
  		p[i] = i;             
	int cnt = 0;
	double res = 0;
  	do
  	{
  		cnt++;
		for (int i=2;i<=n;i++)  		
			res += cal(p[i],p[i-1]);
  	} while(next_permutation(p+1,p+1+n));	
	cout << setprecision(6) << fixed << res/cnt;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>


using namespace std;

int main(){

 int a[5];

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

 for(int i=0;i<4;i++){
     cout << a[i] << " " ;
 }
  cout << a[4] << endl;

 











    return 0;



}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}


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

    int n;
    double sum = 0.0;
    double a;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a;
        sum += 1/a;
    }
    printf("%.7lf", 1/sum);
    return 0;
}

Measured memory_bytes: 256
int main(){
  int i;
  char A[1002];
  int dir[4] = {};
  scanf("%s",A);
  for(i = 0; A[i] != '\0'; i++){
    if(A[i] == 'N')dir[0]++;
    if(A[i] == 'W')dir[1]++;
    if(A[i] == 'S')dir[2]++;
    if(A[i] == 'E')dir[3]++;
  }
  if(dir[0] != 0){
    if(dir[2] == 0)printf("No\n");
    else if((dir[1] == 0 && dir[3] == 0) || (dir[1] != 0 && dir[3] != 0))printf("Yes\n");
    else printf("No\n");
  }
  else if(dir[2] != 0){
    if(dir[0] == 0)printf("No\n");
    else if((dir[1] == 0 && dir[3] == 0) || (dir[1] != 0 && dir[3] != 0))printf("Yes\n");
    else printf("No\n");
  }
  else if(dir[1] != 0){
    if(dir[3] == 0)printf("No\n");
    else if((dir[0] == 0 && dir[2] == 0) || (dir[0] != 0 && dir[2] != 0))printf("Yes\n");
    else printf("No\n");
  }
  else if(dir[3] != 0){
    if(dir[1] == 0)printf("No\n");
    else if((dir[0] == 0 && dir[2] == 0) || (dir[0] != 0 && dir[2] != 0))printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}
  


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

ll N, K;
ll a[1010];
vector<ll> cand;

ll countMask(ll a) {
    ll ret = 0;
    for (ll x : cand) {
        if ((x & a) == a) { 
            ret++;
        }
    }
    return ret;
}

int main() {
    cin >> N >> K;
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
    }

    for (ll i = 0; i < N; i++) {
        ll sum = 0;
        for (ll j = i; j < N; j++) {
            sum += a[j];
            cand.push_back(sum);
        }
    }

    ll mask = 0;
    for (ll i = 40; i >= 0; i--) {
        if (countMask(mask | (1LL << i)) >= K) {
            mask |= (1LL << i);
        }
    }

    cout << mask << endl;

    return 0;
}


Measured memory_bytes: 6128
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String S = br.readLine();
		int LEN = S.length()/2;
		
		int ans = 0;
		for(int i=LEN-1; i>0; i--) {
			if (S.substring(0, i).contentEquals(S.substring(i, 2*i))) {
				ans = 2 * i;
				break;
			}
		}
		System.out.println(ans);	
	}
}

Measured memory_bytes: 32660
#include<stdio.h>
#include<algorithm>
using namespace std;
struct S
{
	int solve,time,wa[10],ID;
	S():solve(0),time(0),ID(-1){fill_n(wa,10,0);}
	bool operator <(const S&s)const
	{
		if(solve!=s.solve)
			return solve>s.solve;
		if(time!=s.time)
			return time<s.time;
		return ID<s.ID;
	}
};
int main()
{
	int T,P,R,tID,pID,time;
	char msg[64];
	while(scanf("%d%d%d",&T,&P,&R),T)
	{
		S s[50];
		for(int i=0;i<T;++i)
			s[i].ID=i+1;
		while(R--)
		{
			scanf("%d%d%d%s",&tID,&pID,&time,msg);
			--tID, --pID;
			if(msg[0]=='C')
			{
				++s[tID].solve;
				s[tID].time += time + s[tID].wa[pID]*1200;
			}
			else
				++s[tID].wa[pID];
		}
		stable_sort(s,s+T);
		for(int i=0;i<T;++i)
			printf("%d %d %d\n",s[i].ID,s[i].solve,s[i].time);
	}
	return 0;
}

Measured memory_bytes: 1052
def make_divisors(n,m):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if m % i == 0:
                divisors.append(i)
            div = n//i
            if i != div:
                if m % div == 0:
                    divisors.append(div)

    # divisors.sort()
    return divisors

def eratosthenes(divs):
    dn = len(divs)
    array = [1 for _ in range(dn)]
    for i in range(1,dn):
        if array[i] == 0:
            continue
        for j in range(i+1, dn):
            if divs[j] % divs[i] == 0:
                array[j] = 0
    return array

from fractions import gcd
a,b = map(int, input().split())
divs = sorted(make_divisors(min(a,b), max(a,b)))
array = eratosthenes(divs)

print(sum(array))
# print(divs)
# print(array)

Measured memory_bytes: 5332
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MAXN = 5 + 400;

int N;
int arr[MAXN];
ll memo[MAXN][MAXN], pref[MAXN];

ll query(int i, int j) {
    return pref[j] - (i == 0 ? 0LL : pref[i - 1]);
}

ll dp(int i, int j) {
    if(i >= j) return 0LL;
    ll& ans = memo[i][j];
    if(ans == -1) {
        ans = numeric_limits<ll>::max();
        for(int k = i; k < j; ++k) {
            ans = min(ans, query(i,j) + dp(i,k) + dp(1 + k, j));
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N;
    foi(i,0,N) {
        cin >> arr[i];
        pref[i] = arr[i];
        if(i) pref[i] += pref[i - 1];
    }
    memset(memo, -1, sizeof memo);
    cout << dp(0,N - 1) << '\n';
    return 0;
}


Measured memory_bytes: 1536
def resolve():
    import itertools
    n, m, q = map(int, input().split())
    cond = [list(map(int, input().split())) for _ in range(q)]
    pos = list(itertools.combinations_with_replacement(range(1, m+1), n))
    ans = 0
    for i in range(len(pos)):
        test = list(pos[i])
        point = 0
        for j in range(q):
            if test[cond[j][1]-1] - test[cond[j][0]-1] == cond[j][2]:
                point += cond[j][3]
        ans = max(ans, point)
    print(ans)
resolve()

Measured memory_bytes: 84804
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};
const main=()=>{
  let n=tn(),a=tnn(n),b=[0]
  for(let i=0;i<n;i++){
    b.push(a[i]+b[i])
  }
  b.sort()
  let s=b[0],c=1,ans=0
  for(let i=1;i<n+1;i++){
    if(s==b[i]){
      c++
    }else if(c>1){
      ans+=c*(c-1)/2
      c=1
    }
    s=b[i]
  }
  if(c>1){
    ans+=c*(c-1)/2
  }
  to(ans)
}
main()


Measured memory_bytes: 154436
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[] kumo = new char[W];
		int[][] ans = new int [H][W];
		int count = 0;
		int no = 0;
		for(int k = 0; k < H; k++){
			kumo = sc.next().toCharArray();
			for(int j = 0; j < W; j++){
				for(int l = j; l >= 0; l--){
					if(kumo[l] == 'c'){
						ans[k][j] = count;
						no = 1;
						break;
					}else if(kumo[l] == '.'){
						count = count + 1;
					}
				}
				if(no == 0){
					ans[k][j] = -1;
				}
				count = 0;
				no = 0;
			}
		}
		for(int i = 0; i < H; i++){
			for(int k = 0; k < W; k++){
				System.out.print(ans[i][k]);
				if(k != W - 1){
					System.out.print(" ");
				}
			}
		System.out.println("");
		}

	}

}

Measured memory_bytes: 36576
#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const int mod = 1000000007;
const int inf = (1<<30);
const ll infll = (1ll<<60);
using namespace std;

int n;
ll st[500000];

void init( int n_ ){
	n = 1;
	while( n < n_ ) n = 2*n;
	// for( int i = 0; i < 2*n; ++i ) st[i] = 0;
}

void update( int k, ll a ){
	k += n-1; st[k] = a;
	while( k ){
		k = (k-1)/2;
		st[k] = max( st[2*k+1], st[2*k+2] );
	}
}

ll query( int a, int b, int k, int l, int r ){
	if( b <= l || r <= a ){
		return 0;
	} else if( a <= l && r <= b) {
		return st[k];
	} else {
		return max(
			query( a, b, 2*k+1, l, (l+r)/2 ),
			query( a, b, 2*k+2, (l+r)/2, r )
		);
	}
}

int main(){
	cin >> n;
	vector<int> h(n);
	vector<ll> a(n);
	for( auto &k : h ) cin >> k;
	for( auto &k : a ) cin >> k;
	int sz = n;
	init(n+1);
	for( int i = 0; i < sz; ++i ){
		update( h[i], query(0, h[i], 0, 0, n)+a[i] );
	}
	cout << query(0, sz+1, 0, 0, n) << endl;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    
    if((a==b && b !=c)||(a==c && b!=c)||(b==c && a !=b))  cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

    return 0;
}


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

int main(void){
	string s;
	cin >> s;
	int b=0, w=0;
	for(int i = 0; i < s.size(); ++i){
		if(i%2==0){
			if(s[i]=='0'){
				b++;
			}else{
				w++;
			}
		}else{
			if(s[i]=='1'){
				b++;
			}else{
				w++;
			}
		}
	}
	cout << min(b, w) << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    //Hashtable ht = new Hashtable();
    static List<int> s = new List<int>();
    static double result;
    static decimal N,K;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく


    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node<> no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation<> pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap<> tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        //PriorityQueue<int,int> pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read3();
double a,b,x;
      a=s[0];b=s[1];x=s[2];
      if(x<=a*a*b/2){
      double y=(double)2*x/(a*b);
        result=90-Math.Atan2(y,b)* 180 / Math.PI;
      }else{
      double y=(double)2*b-(double)2*x/(a*a);
              result=90-Math.Atan2(a,y)* 180 / Math.PI;
      }
      
      
        Console.WriteLine(result.ToString());

    }
  
    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = decimal.Parse(tmp);
    }

    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
      static void Read3()//1行複数項
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{

  int num;
  vector<int> k_num;
  vector<int> w_num;

  for(int i=0;i<20;i++)
    {
      cin >> num;
      
      if(i<10)
	k_num.push_back(num);

      else
	w_num.push_back(num);
    }

  sort(k_num.begin(),k_num.end(),greater<int>());
  sort(w_num.begin(),w_num.end(),greater<int>());

  cout << k_num[0]+k_num[1]+k_num[2] << " " << w_num[0]+w_num[1]+w_num[2] << endl;
  
  return 0;

}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<cctype>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

  ll D,T,S;
  ll ans = 0;

  cin >> D >> T >> S;

  while(D > 0){
    D -= S;
    ans ++;
  }

  if(ans <= T)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;


  return 0;

}   


Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int S,h,m,s;
    scanf("%d",&S);
	h=0; m=0; s=0;
	h=S/3600; m=(S-h*3600)/60; s=S-h*3600-m*60; 
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
		int ah = ni();
		int aw = ni();
		int h = ni();
		int w = ni();
		System.out.println(ah * aw - h * aw - w * ah + h * w);
	}

    //Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
                scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23124
R,G,B,N = map(int,input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        bB = N - r*R - g*G
        if bB%B == 0 and 0<=(bB//B):
            ans += 1
print(ans)

Measured memory_bytes: 40812
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>	

#define PI 3.14159265359
using namespace std;

int main(){
	double avg, sum;
	int n;
	while (cin >> n && n){
		sum = 0;
		vector<double> s(n);
		for (int i = 0; i < n; i++){
			cin >> s[i];
			sum += s[i];
		}
		avg = sum / n;
		sum = 0;
		for (int i = 0; i < n; i++) sum += (s[i] - avg) * (s[i] - avg);
		cout << fixed << setprecision(9) << sqrt(sum / n) << endl;
	}
}

Measured memory_bytes: 3224