akhauriyash/Code-Regression huggingface dataset:
def comb(k, s, r):
    if k == n:
        r.append(s[1:])
        return
    for ai in range(s[-1], m + 1):
        comb(k + 1, s + [ai], r)
    return r

def main():
    abcd = [[int(i) for i in input().split()] for _ in range(q)]
    s = 0
    for p in comb(0, [1], []):
        t = 0
        for a, b, c, d in abcd:
            t += d * (p[b - 1] - p[a - 1] == c)
        s = max(s, t)
    print(s)

if __name__ == '__main__':
    n, m, q = map(int, input().split())
    main()

Measured memory_bytes: 23036
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		string[] s = Console.ReadLine().Split(' ');
		int[] n = new int[s.Length];
		for(int i = 0; i < s.Length; i++) {
			n[i] = int.Parse(s[i]);
		}
		
		var a = n[0];
		var b = n[1];
		var c = n[2];
		
		int num = 0;	//?´???°?????°
		
		for(int i = a; i <= b; i++){
			if( (c % i) == 0 ) num++;
		}
		
		Console.WriteLine(num);
	}
}

Measured memory_bytes: 9216
# 初期入力
A,B = (int(x) for x in input().split())

#素因数分解
def soinsu_bunkai(m):
    pf={}

    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf
# 入力値A,Bを素因数分解
A_soinsu =soinsu_bunkai(A)
B_soinsu =soinsu_bunkai(B)

#共通の素数を探す
kyotu_soinsu ={}
a_sosu ={i for i in A_soinsu.keys()}
b_sosu ={i for i in B_soinsu.keys()}
kotae = a_sosu & b_sosu

print(len(kotae)+1) # 素数「１」を足す

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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	vector<vector<int>> road(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		road[a-1].push_back(b);
		road[b-1].push_back(a);
	}

	for (int i = 0; i < road.size(); ++i) {
		cout << road[i].size() << endl;
	}
	return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
vector<vector<long>> dp;
vector<long>nums;
// int solve(int i,int j){
//     if(i>j) return 0;
//     else{
        
//     }
// }

int main(){
    int size;
    cin>>size;
    nums.resize(size,0);
    dp.resize(size,vector<long>(size));
    // dpy.resize(size,0);
    
    for(int i=0;i<size;i++){
        cin>>nums[i];
    }
    for(int i=size-1;i>=0;i--){
        
        for(int j=0;j<size;j++){
            if(i==j) dp[i][j]=nums[i];
            else dp[i][j]=max((i+1<size)?nums[i]-dp[i+1][j]:0,(j-1>=0)?nums[j]-dp[i][j-1]:0);
        }
    }
    long ans=dp[0][size-1];
    // solve(0,size-1);
    cout<<ans;
    return 0;
    
    
}

Measured memory_bytes: 70656
alp=["a", "b", "c", "d" ,"e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q","r", "s", "t", "u", "v", "w", "x", "y", "z"]

s=input()
l=len(s)

for i in range(l):
    if s[i] in alp:
        alp.remove(s[i])

if len(alp)==0:
    print("None")
else:
    print(alp[0])

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
int main(){
  int x=0,max=0,i=0,size;
  char a[102];
  scanf("%d\n",&size);
  fgets(a,sizeof(a),stdin);
  for(i=0;i<size;i++){
    if(a[i]=='I'){
      x++;
      if(x>max){max=x;}
    }else{
        x--;
      }
  }
  printf("%d",max);
  return 0;
}


Measured memory_bytes: 128
# AOJ ITP1_9_A

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

# ※大文字と小文字を区別しないので注意！！！！
# 全部大文字にしちゃえ。
def main():
    W = input().upper()  # 大文字にする
    line = ""
    count = 0
    while True:
        line = input().split(" ")
        if line[0] == "END_OF_TEXT": break
        for i in range(len(line)):
            word = line[i].upper()
            if W == word: count += 1
    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5560
#!/usr/bin/node
(function(){
  var T=[];
  var stdin = process.openStdin();
  stdin.setEncoding('utf8');
  var a=[1,1,2];
  for(var i=3;i<31;i++)a.push(a[i-1]+a[i-2]+a[i-3]);

  var input_fragment="";
  stdin.on('data', function(input) {
	var ref=(input_fragment+input).split("\n");
	input_fragment=ref.pop();
	for(var i=0;i<ref.length;i++){
		if(ref[i]=='')continue;
		T.push(ref[i]^0);
	}
  });

  stdin.on('end', function(z) {
    for(var i=0;T[i];i++){
      console.log((a[T[i]]+3649)/3650^0);
	}
  });
})();

Measured memory_bytes: 7628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int diffAB = (a > b) ? a - b : b - a;
		int diffBC = (b > c) ? b - c : c - b;
		int diffAC = (a > c) ? a - c : c - a;
		
		System.out.println(((diffAB <= d && diffBC <= d) || diffAC <= d) ? "Yes" : "No");

	}
}

Measured memory_bytes: 20820
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(){
    string s; cin>>s;
    bool ans=true;
    int count=0;
    int num=0;
    int size=s.length();
    int size1=size-1;
    //cout<<size<<endl;
    if(s[0]!='A') ans=false;
    else{
        //cout<<0;
        for(int i=2;i<size1;i++){
            //int num=0;
            if(s[i]=='C'){
                count++;
                num=i;
            }
        }
        //cout<<num<<endl;
        if(count!=1) ans=false;
        else{
            for(int i=1;i<s.length();i++){
                if(i!=num){
                    if(isupper(s[i])){
                        ans=false;
                        break;
                    } 
                }
            }
        }
    }
    if(ans) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

def p(n,r,mod):
    return fact[n]*factinv[n-r] % mod
mod = 10 ** 9 + 7
maxi = 5*10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, maxi + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

N,M=map(int,input().split())    
    
ans=0
for i in range(N+1):
    ans += cmb(N,i,mod) * (-1)**i * p(M,i,mod) * (p(M-i,N-i,mod))**2
    ans %= mod
print(ans)

Measured memory_bytes: 163060
#include<bits/stdc++.h>
using namespace std;
typedef	    long long       ll;
typedef	    vector<ll>      vll;
#define     pb              push_back
#define	    PB              pop_back
#define	    nn              "\n"
#define	    all(p)          p.begin(),p.end()
#define	    zz(v)           (ll)v.size()
#define	    mms(ar,a)       memset(ar,a,sizeof(ar))
#define	    ss              ' '
#define     S(a)            scanf("%lld",&a)
#define     SS(a,b)         scanf("%lld %lld",&a,&b)
#define     SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define     yes             printf("YES\n")
#define     no              printf("NO\n")
#define     P(a)            printf("%lld\n",a)
#define     PP(a,b)         printf("%lld %lld\n",a,b)
#define	    gcd(a,b)        __gcd(a,b)
#define	    lcm(a,b)        (a*b)/gcd(a,b)
#define	    pi              acos(-1.0)
#define	    OO              1000000007

void solve(){
    ll a,b,i,j,t,k,lie,m,n,o,x,y,z,ar[2010];
    ll p=0,sm=0,cnt=0;
    char c;
    cin>>c;
    if(c<='Z') printf("A\n");
    else printf("a\n");
}

int main(){
//	freopen("input.txt", "r", stdin);
    ll i,t;
//    S(t);
//    while(t--){
        solve();
//    }

    return 0;
}



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

int main() {
  int N;
  cin >> N ; 
  vector <int> A(N);
  for (int i=0 ; i <N ; i++){
  cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  int sum=1 ;
  for ( int i=0 ; i<N-1 ; i++){
  if (A.at(i)<A.at(i+1)){
    sum ++ ;
  }
  }
    cout << sum << endl;
}


Measured memory_bytes: 3608
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    print(' '.join(map(str, A)))
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(' '.join(map(str, A)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5604
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()
time = T.pop(0)
people = 1
ans = 1
for t in T:
    if t <= time + K and people < C:
        people += 1
    else:
        time = t
        people = 1
        ans += 1
print(ans)


Measured memory_bytes: 7384
def f(x,y,x1,y1,x2,y2):
    return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1

while True:
    try:
        ax,ay,bx,by,cx,cy,dx,dy = map(float, raw_input().split(","))
        if f(ax,ay,bx,by,dx,dy)*f(cx,cy,bx,by,dx,dy) < 0 and f(dx,dy,ax,ay,cx,cy)*f(bx,by,ax,ay,cx,cy) < 0:
            print "YES"
        else: print "NO"
    except:
        break

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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int ans = 0;
    for(int i = 1;i <= N;i++){
        if(i > K){
            ans += Y;
        }
        else{
            ans += X;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int N;
    cin >> N;
    int M = 55555;

    bool B[M+1] = {};
    B[0] = B[1] = true;
    for(int i=2;i<=M;i++){
        if(!B[i]) for(int j=2;i*j<=M;j++) B[i*j] = true;
    }

    int n = 0;
    rep(i,M){
        if(!B[i] && i % 5 == 1){
            n++;
            cout << i << " ";
        }
        if(n == N) break;
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
ab_list=[list(map(int,input().split())) for _ in range(m)]

count_list = [0 for i in range(n)]

for j in range(len(ab_list)):
    index_from = ab_list[j][0]
    index_to = ab_list[j][1]
    if h_list[index_from - 1] < h_list[index_to - 1]:
        count_list[index_from - 1] += 1
    elif h_list[index_from - 1] > h_list[index_to - 1]:
        count_list[index_to - 1] += 1
    else:
        count_list[index_from - 1] += 1
        count_list[index_to - 1] += 1

print(count_list.count(0))

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

ull len(ull a){ // string length of [1,a]
	ull res=0;
	for(ull x=1;x<=a;x*=10){
		ull aa=min(x*10-1,a);
		ull num3=aa/3-(x-1)/3,num5=aa/5-(x-1)/5,num15=aa/15-(x-1)/15;
		res+=(num3+num5)*4+to_string(x).length()*(aa-x+1-(num3+num5-num15));
	}
	return res;
}

ull s;

int main(){
	cin.sync_with_stdio(false);
	cin>>s;
	ull lb=0,ub=1e19;
	while(ub-lb>1){
		ull mid=(ub+lb)/2;
		if(len(mid)<s)lb=mid;
		else ub=mid;
	}
	string ans;
	rep(i,100){
		ull num=ub+i;
		if(num%3==0&&num%5==0)ans+="FizzBuzz";
		else if(num%3==0)ans+="Fizz";
		else if(num%5==0)ans+="Buzz";
		else ans+=to_string(num);
	}
	cout<<ans.substr(s-len(lb)-1,20)<<endl;
	return 0;
}

Measured memory_bytes: 3280
using System;
using System.Collections.Generic;
using System.Linq;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var r = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();
            var ret = new List<long>();
            for (int i = 0; i < N - 1; i++)
            {
                if (r[i] == r[i + 1])
                {
                    ret.Add(r[i]);
                    i ++;
                    if (ret.Count == 2)
                    {
                        Console.WriteLine(ret[0] * ret[1]);
                        return;
                    }
                }
            }
            Console.WriteLine(0);
        }
    }
}

Measured memory_bytes: 24032
import sys,math

A = [int(i) for i in input().split(' ')]
N,K = A[0], A[1]

ans = math.floor(N/K) ** 3

if (K%2 == 1):
  print(ans)
  sys.exit()

res = 0
half = math.floor(K/2)
cnt = (math.floor((N - half)/K)+1)** 3
print(cnt+ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define loopj(n) for(int j=0;j<n;j++)
#define loopi(a,b,k) for(int i=a;i<b;i=i+k)
#define  deb(x) cout<<#x<<"  "<<x<<endl
#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main()
{
	int n{0};
	cin>>n;
	ll a[n];
	ll sum=0;
	loopj(n)
	{
		cin>>a[j];
		sum+=a[j];
	}
	ll k=1e9+7;
	ll sum2=0;
	loopj(n)
	{
		sum=sum-a[j];
		
		sum2=((sum2%k)+((a[j]%k)*(sum%k)))%k;
	}
	cout<<sum2;
}

Measured memory_bytes: 5208
//mangesh2102000

#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000000

void solve(int t)
{
    int n;
    cin >> n;

    int a[n+1][3];
    for(int i=1;i<=n;i++)
    {
    	cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    int dp[n+1][3];
    dp[1][0] = a[1][0];
    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];

    for(int i=2;i<=n;i++)
    {
    	dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1] = a[i][1] + max(dp[i-1][2],dp[i-1][0]);
    	dp[i][2] = a[i][2] + max(dp[i-1][1],dp[i-1][0]);
    }

    cout << max( max(dp[n][0],dp[n][1]), dp[n][2]);
    //cout << "Case #" << t << ": " << ;
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 4992
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int k = parseInt(sc.next());
		long[] h = new long[n];
		for (i = 0; i < h.length; i++) {
			h[i] = parseInt(sc.next());
		}
		sc.close();
		Arrays.parallelSort(h);
		long sum=0;
		for (i = n-k-1; i >= 0; i--) {
			sum+=h[i];
		}
		out.println(sum);
	}
}


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

#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define forn(i, n) for(int i = 0; i < int(n); ++i)
typedef long long ll;

const ll E=(ll)1e9+7;
const int N=100001;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        int n,min_sum=INT_MAX;
        cin>>n;
        for(int j=1;j<n;j++)
        {
            int a=j,b=n-j;
            int sum=0;
            while(a)
            {
                sum+=a%10;
                a/=10;
            }
            while(b)
            {
                sum+=b%10;
                b/=10;
            }
            min_sum=min(sum,min_sum);
        }
        cout<<min_sum;
    }
    return 0;
}


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

bool binSearch(int l[],int b,int e,int x){
    
    //cout<<b<<" "<<e<<endl;
    
    if(e-b<5){
        int i;
        for(i=b;i<e;i++){
            if(l[i]==x)return 1;
        }
        return 0;
    }
    
    int c=b+(e-b)/2;
    if(l[c]>x){
        return binSearch(l,b,c,x);
    }
    else{
        return binSearch(l,c,e,x);
    }
}

int main(void){
    int ans=0,i,p,q,s[100000],t[50000];
    cin>>p;
    for(i=0;i<p;i++)cin>>s[i];
    cin>>q;
    for(i=0;i<q;i++)cin>>t[i];
    
    sort(s,s+q);
    
    for(i=0;i<q;i++){
        if(binSearch(s,0,p,t[i]))ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
#define ck(a,b) (0<=(a)&&(a)<b)
typedef long long ll;
using namespace std;
const int inf=1e9;


int main(){

	int N;
	while(cin>>N,N){
		//---init & input---
		int ans=0;
		string S[12];
		vector<int> vt;//exist
		set<int> s;
		bool notZero[30];
		ll w[30]; //keisu
		REP(i,0,N) 	cin>>S[i];
		REP(i,0,30) {
			w[i]=0;
			notZero[i]=false;
		}
		//---calc keisu---
		REP(i,0,N){
			if(S[i].size()>1) notZero[S[i][0]-'A'] = true;
			REP(j,0,S[i].size()){
				if(s.find(S[i][j]-'A')==s.end())  {
					vt.push_back(S[i][j]-'A');
					s.insert(S[i][j]-'A');
				}
				if(i==N-1) w[S[i][j]-'A']-=pow(10,S[i].size()-1-j);
				else w[S[i][j]-'A']+=pow(10,S[i].size()-1-j);
			}
		}
		unsigned int kind = vt.size();
		vector<int> select(10);
		REP(i,0,kind) select[i]=1;
		REP(i,kind+1,10) select[i]=0;
		do{
			vector<ll> next;
			REP(i,0,10)		if(select[i]) next.push_back(i);

			do{
				ll sum=0;
				REP(i,0,kind){
					if(next[i]==0 && notZero[vt[i]]){
						sum=1;
						break;
					}
					sum += w[vt[i]]*next[i];
				}
				if(sum==0) ans++;
			}while(next_permutation(next.begin(),next.end()));
		}while(prev_permutation(select.begin(),select.end()));
		p(ans);
	}
	return 0;
}

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

int find(int X,vector<int> &P){
  if(P.at(X)<0){
    return X;
  }
  return P.at(X)=find(P.at(X),P);
}

void unite(int X,int Y,vector<int> &P){
  X=find(X,P);
  Y=find(Y,P);
  if(X==Y){
    return;
  }
  P.at(X)+=P.at(Y);
  P.at(Y)=X;
  return;
}
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> P(N,-1);
  for(int i=0;i<M;i++){
    int A,B;
    cin >> A >> B;
    unite(A-1,B-1,P);
  }
  sort(P.begin(),P.end());
  cout << (-1)*P.at(0) << endl;
}
    

Measured memory_bytes: 4052
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

const int dy[]={-1,0,1,0},dx[]={0,-1,0,1},dy2[]={1,-1,-1,1},dx2[]={1,1,-1,-1};
int m,n,d,s[25][25];
int main()
{
	while(scanf("%d%d%d",&n,&m,&d),m){
		int N=m*n;
		vector<vi> a(N,vi(N+1,0));
		rep(i,m)rep(j,n)scanf("%d",s[i]+j), a[i*n+j][N]=s[i][j];
		rep(i,N)(a[i][i]+=1)%=2;
		rep(i,m)rep(j,n)rep(dir,4)rep(k,d){
			int y=i+dy[dir]*d+dy2[dir]*k, x=j+dx[dir]*d+dx2[dir]*k;
			if(0<=y&&y<m&&0<=x&&x<n){
				(a[y*n+x][i*n+j]+=1)%=2;
			}
		}
		int j=0;
		rep(i,N){
			int mi=i;
			if(!a[mi][j])for(int k=i+1;k<N;k++)if(a[mi]<a[k]){
				mi=k;
				if(a[mi][j])break;
			}
			swap(a[i],a[mi]);
			for(;j<N&&a[i][j]==0;j++);
			if(j>=N)break;
			assert(a[i][j]);
			rep(k,N)if(i<k&&a[k][j])for(int l=j;l<=N;l++)(a[k][l]+=a[i][l])%=2;
			j++;
		}
		bool ok=1; j=0;
		rep(i,N)if(ok&&a[i][N]){
			for(;j<N&&a[i][j]==0;j++);
			if(j>=N)ok=0;
		}
		printf("%d\n",(int)ok);
	}
	return 0;
}

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

using i64 = long long int;

i64 acc[5003]={0};

int main(){
    int n;
    while(cin >> n, n != 0){
        vector<i64> v;
        for(int i=0;i<n;++i){
            i64 a;
            cin >> a;
            v.push_back(a);
        }
        for(int i=0;i<n;++i){
            acc[i+1] = acc[i] + v[i];
        }

        i64 ans = LLONG_MIN;
        for(int i=1;i<=n;++i){
            for(int j=i;j<=n;++j){
                ans = max(ans, acc[j] - acc[i-1]);
            }
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int f(string s1, string s2)
{
    sort(begin(s1), end(s1));
    sort(begin(s2), end(s2));
    auto s1end = unique(begin(s1), end(s1));
    auto s2end = unique(begin(s2), end(s2));

    string result;
    set_intersection(
        begin(s1), s1end,
        begin(s2), s2end,
        back_inserter(result));
    return result.size();
}
void main_()
{
    ll N;
    string S;
    cin >> N >> S;

    int ans;
    for (int i = 1; i < N; ++i) {
        ans = max(ans, f(S.substr(0, i), S.substr(i, N)));
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>


using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef map<string,int> si;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
#define int long long


int n,m;
int tfs[]={3,5,7};

int keta(int n,int m){
    if(n<pow(10,m-1)) return -1;
    int tmp = n/pow(10,m-1);
    tmp %= 10;
    return tmp;
}

int dfs(int now) {
    int ret=0;

    queue<int> st;
    st.emplace(now);
    while(st.size()>0){
        int e = st.front();
        st.pop();
        REP(i,0,3) if(10*e+tfs[i]<=n) st.push(10*e+tfs[i]);
        
        set<int> s;
        for(int i=1 ;i<=log10(e)+1 ;++i){
            s.insert(keta(e,i));
        }
        if(s.size()==3) ret++;
    }

    return ret;
}

int atcoder() {
    cin >> n;
    int ans=0;
    
    ans=dfs(0);
    cout << ans << ENT;

    return 0;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


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

int p[1010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &p[i]);
	int q;
	scanf("%d", &q);
	for(int i = 0; i < q; i++) {
		int a, b, k;
		scanf("%d%d%d", &a, &b, &k);
		printf("%d\n", (int)count(p+a, p+b, k));
	}
}



Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll  N,K;
    cin >> N >> K;
    ll amari = N % K;
    ll ans = min(amari, K - amari);
    cout << ans << endl;
}

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

int main(){
    string S;
    cin>>S;
    
    string ans=S;
    int t=0,tt=0;
    for(int i=0;i<S.length();++i){
        if(S[i]=='B'){
            if(i+t<=0){
                t-=1;
            }else{
                t-=2;
            }
        }else{
            ans[i+t]=S[i];
        }
    }
    ans = ans.substr(0,max(1,(int)ans.length()+t+tt));
    cout<<ans;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
long long moder = 1000000007;
long long fac(long long n){
	long long ret = 1;
	for(long long i = 1; i<=n; i++){
		ret*=i;
		ret%=moder;
	}
	return ret;
}
long long multi(long long a,long long b){
	if(b==0) return 1;
	if(b==1) return a;
	long long ret = multi(a,b/2);
	ret*=ret;
	ret%=moder;
	if(b%2) ret*=a;
	return (ret%moder);
}
long long solve(long long a,long long b){
	long long up = fac(a+b);
	long long down = fac(a)*fac(b);
	down%=moder;
	return (up*multi(down,moder-2))%moder;
}
int main(){
	long long x,y;
	cin>>x>>y;
	if(x<y) swap(x,y);
	if(x>2*y) cout<<0;
	else if(x==2*y) cout<<1;
	else{
		long long diff = x-y;
		long long fir = diff;
		x-=2*diff;
		y-=diff;
		if(x%3) cout<<0;
		else{
			long long sec = x/3;
			fir+=x/3;
			cout<<solve(fir,sec);
		}
	}
}

Measured memory_bytes: 3580
#include<stdio.h>
int replace(  int number)
{

if (number == 0)
return 0;


int digit = number % 10;
if (digit == 1)
digit = 9;
else if (digit == 9)
digit = 1;



return replace(number/10) * 10 + digit;
}
int Convert(  int number)
{
if (number == 0)
return 1;
else
return replace(number);
}
int main()
{
  int number;
scanf("%d", &number);
printf("%d\n", Convert(number));
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;

int main(void){
  ll n;
  cin >> n;
  typedef pair<ll, ll> pair;
  vector<vector<ll>> g(n+1);
  vector<pair> vp;
  for(ll i = 0; i < n-1; i++){
    ll a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
    vp.push_back(pair(a, b));
  }
  map<pair, ll> I{};
  vector<ll> use(n+1, -1);
  vector<ll> check(n+1, 0);
  queue<ll> que;
  que.push(1);
  ll ans = 0;
  ll count = 1;
  while(!que.empty()){
    ll v = que.front();
    que.pop();
    count = 1;
    for(ll nv : g[v]){
      if(check[v]==count) count++;
      if(use[nv]!= -1) continue;
      if(ans < g[v].size())
        ans = g[v].size();
        check[nv] = I[pair(v, nv)] = I[pair(nv, v)] = count;
        count++;
        que.push(nv);
    }
    use[v] = 1;
  }
  cout << ans << endl;
  for(pair p : vp)
    cout << I[p] << endl;
  return 0;
}


Measured memory_bytes: 22128
//Keep working hard :)
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const int N = 1e5+5;
int bit[N],a[N],n;//N is the size of array + 1

void update(int x, int delta)
{
	for(;x <= n; x += x&(-x))
	{
		bit[x] += delta;
	}
}

int query(int x)
{
	int sum = 0;
	for(;x > 0;x -= x&(-x))
	{
		sum += bit[x];
	}
	return sum;
}
void fileIO()
{
        #ifndef ONLINE_JUDGE
        freopen("int.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
}
int main()
{
	IOS;
        //fileIO();
        int m;
        cin >> n >> m;
        for(int i = 0; i < m; i++)
        {
                int l,r;
                cin >> l >> r;
                update(l,1);
                update(r+1,-1);
        }
        int cnt = 0;
        for(int i = 1; i <= n; i++)
        {
                if(query(i)== m)cnt++;
        }
        cout << cnt;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

int main() {
    string s;
    cin >> s;
    long long k;
    cin >> k;
    if (s[0] != '1') {
        cout << s[0];
        return 0;
    }
    else {
        int tc = 0;
        char fa;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '1') {
                tc++;
            }
            else {
                fa = s[i];
                break;
            }
        }
        if (k <= tc) {
            cout << '1';
        }
        else {
            cout << fa;
        }
    }
}


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

void swap(int *x,int *y){
	int tmp;
	if(*x > *y){
		tmp = *y;
		*y = *x;
		*x = tmp;
	}
}

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	swap(&a,&b);
	swap(&a,&c);
	swap(&b,&c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}	

Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i=0; i<=n; i++)

using namespace std;

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  // 入力終了

  // ボタンを押す順はなんでもいい
  // i回行ボタンを押した後，j回列ボタンを押す全探索をする
  // 最初に行ボタンによりMi個のマスが黒くなる
  // 次に，列ボタンでNj個のマスを黒くすると考えると，
  // 交差部分のij個のマスを2回黒とカウントしてしまうので引く
  
  rep(i, N){
    rep(j, M){
      if(M*i + N*j - 2*i*j == K){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }

  // 上のループを抜けたら無理
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int gdc(int i, int j, int k) {

	int c = 0;
	int tmp = 0;

	/*iが大きくなるように並び替える*/
	if (i < j) {

		tmp = i;
		i = j;
		j = tmp;
	}

	c = i % j;
	/*iとjの最大公約数を求める*/

	while (c > 0) {

		i = j;

		j = c;
		c = i % j;

	}



	/*i,jの最大公約数jと,kから、これらの最大公約数を求める*/

	/*kの方が大きければ入れ替える*/
	if (j < k) {

		tmp = j;
		j = k;
		k = tmp;


	}

	int d = j % k;


	while (d > 0) {

		j=k;
		k = d;
		d= j%k;

	}

	

	return k;
}


int main(void) {

	int i = 0;
	int j = 0;
	int k = 0;
	int n = 0;

	int c = 0;
	int sum = 0;



	scanf("%d", &n);

	for (i = 1; i <= n; i++) {

		for (j = 1; j <= n; j++) {

			for (k = 1; k <= n; k++) {


				c = gdc(i, j, k);

				sum = sum + c;



			}


		}

	}


	printf("%d", sum);
	return 0;


}


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

using ll = long long;

int main() {
	ll n; cin >> n;
	vector<ll>a(n + 1); rep(i, n + 1) { cin >> a[i]; }
	vector<ll>b(n); rep(i, n) { cin >> b[i]; }

	ll c = 0LL;
	for (ll i = n; i >= 1; i--) {
		if (b[i - 1] > a[i]) {
			b[i - 1] -= a[i]; c += a[i];
			a[i] = 0LL;
			if (b[i - 1] > a[i - 1]) {
				b[i - 1] = 0LL; c += a[i - 1];
				a[i - 1] = 0LL;
			}
			else {
				a[i - 1] -= b[i - 1]; c += b[i - 1];
				b[i - 1] = 0LL;
			}
		}
		else {
			a[i] -= b[i - 1]; c += b[i - 1];
			b[i - 1] = 0LL;
		}
	}

	cout << c << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
	int x1,x2,y1,y2,x3,x4,y3,y4;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	int dx,dy;
	dx=x2-x1;
	dy=y2-y1;
	y4=dx+y1;
	y3=y2+dx;
	x4=x1-dy;
	x3=x2-dy;
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long mmax(long a,long b,long c){
  if(a<b){
    return max(b,c);
  }else{
    return max(a,c);
  }
}

long mmin(long a,long b,long c){
  if(a<b){
    return min(a,c);
  }else{
    return min(b,c);
  }
}

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

long long moddevide(long long a,long long b){return (a*modinv(b))%mod;}

long long modncr(long long n,long long r){
  long long i,plus=1;
  for(i=0;i<r;i++){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

long long euclidean_gcd(long long a, long long b) {
  if(a < b) return euclidean_gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  long i,H,W,a,b,c,cnt=0;
  scanf("%ld",&H);
  scanf("%ld",&W);
  vector<long> ans((H+W-2)*2);
  for(i=1;i<H;i++){
    a=i*W;
    if(W%2==0){
      b=(H-i)*W/2;
      c=b;
    }else{
      b=W/2;
      b=b*(H-i);
      c=H*W-a-b;
    }
    ans[cnt++]=mmax(a,b,c)-mmin(a,b,c);
    if((H-i)%2==0){
      b=(H-i)*W/2;
      c=b;
    }else{
      b=(H-i)/2;
      b=b*W;
      c=H*W-a-b;
    }
    ans[cnt++]=mmax(a,b,c)-mmin(a,b,c);
  }
  for(i=1;i<W;i++){
    a=i*H;
    if(H%2==0){
      b=(W-i)*H/2;
      c=b;
    }else{
      b=H/2;
      b=b*(W-i);
      c=H*W-a-b;
    }
    ans[cnt++]=mmax(a,b,c)-mmin(a,b,c);
    if((W-i)%2==0){
      b=(W-i)*H/2;
      c=b;
    }else{
      b=(W-i)/2;
      b=b*H;
      c=H*W-a-b;
    }
    ans[cnt++]=mmax(a,b,c)-mmin(a,b,c);
  }
  sort(ans.begin(),ans.end());
  cout << ans[0] <<endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};


int main() {
    int N, M; cin >> N >> M;
    UnionFind<int> UF(N);
    rep(i,M) {
        int L,R,D; cin >> L >> R >> D;
        if (UF.issame(L,R)) {
            if (UF.diff(L,R) != D) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            UF.merge(L,R,D);
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 4564
#include <iostream>

using namespace std;
using ll = long long;

int main()
{
    ll n, a, b; cin >> n >> a >> b;
    ll ab = a + b;
    ll t_ab = n / ab;
    ll blue = a * t_ab;
    ll sa = n - ab * t_ab;
    if (sa >= a) blue += a;
    else blue += sa;

    cout << blue << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define NMAX 100010
using namespace std;
long long n, i, rez, x;
struct elem_poz
{
    long long val;
    int poz_initial;
    int poz_schimbat;
}v[1000005];
bool Sortare(elem_poz A, elem_poz B)
{
    return A.val<B.val;
}
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>x;
        v[i].val=x;
        v[i].poz_initial=i;
    }
    sort(v+1, v+n+1, Sortare);


    for (int i=1; i<=n; i++)
        v[i].poz_schimbat=i;

    for (int i=1; i<=n; i++)
        if (v[i].poz_initial%2!=v[i].poz_schimbat%2)
            rez++;
    cout<<rez/2;
    return 0;
}

Measured memory_bytes: 1920
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
    int a;
    int b;
    int c;
 
   cin >> a >> b >> c;
  
   if(a*c <= b){
      cout << c << endl;
   }else{
     
      cout << b/a << endl;
     
   }

  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
#define mod 1000000007
int main(void){
    int k, x; cin >> k >> x;
    int l = (x-k+1);
    int r = (x+k-1);
    for(int i=l;i<=r;i++) cout << i << endl;
}


Measured memory_bytes: 256
#include <iostream>
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;
    int flag=1;
    while (flag==1){
        flag=0;
        for (int j=n-1; j>=1; j--){
            if (a[j]<a[j-1]){
                count++;
                int v=a[j];
                a[j]=a[j-1];
                a[j-1]=v;
                flag=1;
            }
        }
    }
    for (int i=0; i<n; i++){
        if (i==n-1){
            cout << a[i] <<endl;
        }
        else {
            cout << a[i] << " " ;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3072
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


ll Largest_Rectangle(const vector<vector<bool>> &A){
    vector<vector<ll>> a(A.size(),vector<ll>(A[0].size(),0));
    ll count;
    for(int i=0;i<A[0].size();i++){
        count=0;
        for(ll h=0;h<A.size();h++){
            if(A[h][i]){count++;}
            else{count=0;}
            a[h][i]=count;
        }
    }
    ll mx=0;
    stack<pll> s;
    for(int i=0;i<A.size();i++){
        for(int t=0;t<A[0].size();t++){
            ll mi=t;
            while(!s.empty() && s.top().F>a[i][t]){
                pll w=s.top(); s.pop();
                mx=max(mx,w.F*(t-w.S));
                mi=w.S;
            }
            s.push({a[i][t],mi});
        }
        while(!s.empty()){
            pll w=s.top(); s.pop();
            mx=max(mx,w.F*((ll)A[0].size()-w.S));
        }
    }
    return mx;
}


int main(){
    ll h,w;
    cin>>h>>w;
    vector<vector<bool>> a(h,vector<bool>(w));
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            ll b;
            cin>>b; a[i][t]=b==0;
        }
    }
    cout<<Largest_Rectangle(a)<<endl;
    
    
    return 0;
}



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

using namespace std;
// a+t>0, t>-a;   a-t>0, t<a
int main()
{
    int n, m, a, b, s, L=1, R=2000000000, Tt=-1, a1, a2;
    cin >> n >> m;
    vector <pair<int,int>> D[n+1];
    vector <int> T;
    int A1[n+1], A2[n+1], g1[n+1], g2[n+1];
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b >> s;
        D[a].push_back({b,s});
        D[b].push_back({a,s});
    }
    for (int i = 0; i <= n; i++)
    {
        A1[i] = -1;
        A2[i] = -1;
        g1[i] = 1;
        g2[i] = 1;
    }
    g1[1] = 0;
    A1[1] = 0;
    T.push_back(1);
    for (int i = 0; i < T.size(); i++)
    {
        a = T[i];
        for (int y = 0; y < D[a].size(); y++)
        {
            b = D[a][y].first;
            s = D[a][y].second;
            if (g1[a] == 0)
            {
                a2 = s-A1[a];
                R = min(R, a2-1);
                if (g2[b] == 1)
                {
                    g2[b] = 0;
                    A2[b] = a2;
                    T.push_back(b);
                }
                else if (A2[b] != a2)
                {
                    cout << 0;
                    return 0;
                }
            }
            if (g2[a] == 0)
            {
                a1 = s-A2[a];
                L = max(L, -1*a1+1);
                if (g1[b] == 1)
                {
                    g1[b] = 0;
                    A1[b] = a1;
                    T.push_back(b);
                }
                else if (A1[b] != a1)
                {
                    cout << 0;
                    return 0;
                }
            }
        }
        if (g1[a] == 0 && g2[a] == 0)
        {
            if ((A2[a]-A1[a]) % 2 == 1)
            {
                cout << 0;
                return 0;
            }
            if (Tt == -1)
            {
                Tt = (A2[a]-A1[a])/2;
            }
            else if (Tt != (A2[a]-A1[a])/2)
            {
                cout << 0;
                return 0;
            }
        }
    }
    if (L > R)
    {
        cout << 0;
        return 0;
    }
    if (Tt != -1)
    {
        cout << 1;
        return 0;
    }
    cout << R - L + 1;
    return 0;
}


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9) cout << -1 << endl;
    else cout << a * b << endl;
    
    return 0;
}



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

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int maxv = max(a, c);
	int minv = min(b, d);
	if(maxv > minv) cout << 0 << endl;
	else cout << minv - maxv << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int je(char s[],char a[],int b,int n,int c){
  int i,k=0;
  for(i=b;i<n/2;i++){
    if(a[i]!=s[c-i]) k=1;
  }
return k;
}
int main(void){
 char s[100],a[100];
 int i,n,k=0;
 scanf("%s",s);
 n=strlen(s);
 for(i=0;i<n;i++){
 a[i]=s[i];
 }
   if(k==0)  k=je(s,a,0        ,n,n-1);
   if(k==0)  k=je(s,a,0        ,n,(n-1)/2-1);
   if(k==0)  k=je(s,a,(n+3)/2-1,n,n-1);

 if(k==1) puts("No");
 else puts("Yes");
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
    int n, x, y, b, p;
    int db, dp, normal, discount;
    int i;

    scanf("%d", &n);

    for (i=0; i<n; i++) {
        scanf("%d %d %d %d", &x, &y, &b, &p);

        if (b > 5) {
            db = b;
        }
        else {
            db = 5;
        }

        if (p > 2) {
            dp = p;
        }
        else {
            dp = 2;
        }

        normal = x*b + y*p;
        discount = (x*db + y*dp) * 0.8;

        if (normal <= discount) {
            printf("%d\n", normal);
        }
        else {
            printf("%d\n", discount);
        }
    }

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>; //to, cost
using WeightedGraph = vector<vector <P>>; //to cost
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    int ans = 0;
    if(k == 0) {cout<<n*n<<endl; return 0;}
    for(int i=k+1;i<=n;i++){//iはb
        int p = i - k;
        int x = n/i;
        int rest = n % i;
        int l = k-1;
        int r = min(rest, (i-k) + l);
        ans += p * x + max(0LL, r-l);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, t;
  cin >> n >> t;
  vector<ll> a(n);

  REP(i, n) { cin >> a[i]; }
  ll ans = 0;
  a.push_back(1e15);
  REP(i, n) { ans += min(a[i + 1] - a[i], t); }
  cout << ans << endl;
}

Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	int n[4]={};
	
	for(int i=0;i<3;i++)
	{
		int x,y;
		cin >> x >> y;
		n[x-1]++;
		n[y-1]++;
	}
	sort(n,n+4);
	
	if(n[0]==1 && n[1]==1 && n[2]==2 && n[3]==2)cout << "YES";
	else cout << "NO";
	cout << endl;
	return 0;
}



Measured memory_bytes: 256