akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	sc := NewScanner()
	A := sc.NextIntArray()
	mn := A[0] * A[1] * A[2]
	if A[2] % 2 == 0 {
		fmt.Println("0")
		return
	}
	mn = min(mn, A[0] * A[1])

	if A[1] % 2 == 0 {
		fmt.Println("0")
		return
	}
	mn = min(mn, A[0] * A[2])

	if A[0] % 2 == 0 {
		fmt.Println("0")
		return
	}
	mn = min(mn, A[1] * A[2])
	fmt.Println(mn)

}

Measured memory_bytes: 640
#

import sys
from copy import deepcopy
input=sys.stdin.readline

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    last=[[0]*27 for i in range(D+1)]
    for day in range(1,D+1):
        lastt=deepcopy(last)
        maxt=0
        maxx=0
        for t in range(1,27):
            sat=0
            for j in range(day,D+1):
                    last[j][t]=day
            sat+=S[day-1][t-1]
            for j in range(1,27):
                sat-=C[j-1]*(day-last[day][j])
            if maxx<sat:
                maxt=t
                maxx=sat
        last=deepcopy(lastt)
        for j in range(day,D+1):
            last[j][maxt]=day
        print(maxt)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 148680
package main

import (
	"fmt"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var N int
	fmt.Scan(&N)
	h := make([]int, N)

	for i := range h {
		fmt.Scan(&h[i])
	}

	dp := make([]int, N)
	dp[1] = abs(h[0] - h[1])

	for i := 2; i < N; i++ {
		dp[i] = min(
			dp[i-1]+abs(h[i-1]-h[i]),
			dp[i-2]+abs(h[i-2]-h[i]),
		)
		//fmt.Printf("i = %v, a=%v, b=%v\n", i, dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]))
	}

	/*
		for i, x := range dp {
			fmt.Printf("dp[%v]=%v\n", i, x)
		}
	*/

	fmt.Println(dp[N-1])
}


Measured memory_bytes: 7424
N, M = map(int, input().split())
a = set([int(input()) for i in range(M)])
n = [0] * (N + 1)
n[0] = 1
n[1] = 1

#listの中をinで探すのはくっそ遅い
if 1 in a:
    n[1] = 0

for i in range(2, N + 1):
    if i in a:
        continue
    else:
        n[i] = (n[i - 1] + n[i - 2]) % 1000000007

print(n[N])

Measured memory_bytes: 13192
l, r = map(int, input().split())
ans = 2019
d = 0
for i in range(l, r + 1):
    d += 1
    if d > 2019:
        break
    c = 0
    for j in range(i + 1, r + 1):
        c += 1
        if c > 2019:
            break
        ans = min(ans, i * j % 2019)
print(ans)

Measured memory_bytes: 40428
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vi = vector<int>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll k, l, m, n;
const ll M = 1e9 + 7;



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

    int h, w, n;
    cin >> h >> w >> n;

    vector<vi> table(h, vi(w));
    int a;
    int line = 0, row = 0;
    rep(i, n) {
        cin >> a;

        rep(j, a) {
            table[line][row] = i + 1;

            if(line % 2 == 0) row++;
            else row--;

            if(w <= row) {row--; line++;}
            if(row < 0) {row++; line++;}
        }
    }

    rep(i, h) {
        rep(j, w - 1) cout << table[i][j] << " ";
        cout << table[i][w - 1] << endl;
    }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int store[1000];
int main()
{
	int n;
	int min1=1e9;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>store[i];
	}
	for(int i=1;i<=n;i++)
	{
		int s1=0;
		for(int j=0;j<i;j++)
		{
			s1+=store[j];
		}
		int s2=0;
		for(int z=i;z<n;z++)
		{
			s2+=store[z];
		}
		min1=min(min1,abs(s1-s2));
	}
	cout<<min1;
}

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

bool is_prime (int n) {
    for (int i = 2; i <= pow(n, 0.5); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}


int main () {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 2; i <= pow(n, 0.5); i++) {
        if (is_prime(i)) {
            v.push_back(i);
        }
    }
    int len = v.size();
    
    cout << n << ": ";
    
    while (not is_prime(n)) {
        for (int i = 0; i < len ; i++) {
            if (n % v[i] == 0) {
                n /= v[i];
                cout << v[i] << ' ';
                break;
            }
        }
    }
    cout << n << endl;
}

Measured memory_bytes: 3340
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
using namespace std;
const int N = 1e5+5;
void fast(){std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
int dist[N][2],n,x[2],ans;
bool visit[N][2];
vi v[N];
void bfs(int num)
{
	queue<int>q;
	q.push(x[num]);
	while(!q.empty())
	{
		int now=q.front();q.pop();
		visit[now][num]=true;
		for(int i=0;i<v[now].size();i++)
		{
			int to=v[now][i];
			if(!visit[to][num])
			{
				dist[to][num]=dist[now][num]+1;
				q.push(to);
			}
		}
	}
}
int main()
{
	fast();
	cin>>n>>x[0]>>x[1];
	x[0]--,x[1]--;
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	bfs(0);
	bfs(1);
	for(int i=0;i<n;i++)
	{
		if(dist[i][0]<dist[i][1])
		{
//			cout<<i+1<<' '<<dist[i][0]<<' '<<dist[i][1]<<endl;
			int sum=dist[i][1]-1;
			ans=max(ans,sum);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;


int main(){

    FASTIO;
    PRECISION; 

    string s;
    cin>>s;

    int n = s.size();
    vector<int>dp(2019,0);
    ll ans = 0;
    for(int i=0;i<s.size();i++){
        int dig = s[i]-'0';
        vector<int>ndp(2019);
        for(int j=0;j<2019;j++){
            ndp[(j*10 + dig)%2019]+=dp[j];
        }
        ndp[dig]++;

        ans+=ndp[0];
        swap(dp,ndp);
    }

    cout<<ans<<"\n";

}

Measured memory_bytes: 3772
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
 
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <list>
#include <stack>
#include <bitset>
#include <ctime>
using namespace std;
 
typedef long double ld;
typedef long long int lli;
#define pb(x) push_back(x)
#define fr first
#define sc second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
const lli N = 1e6, N2 = 5e3, delta = 46639, mod = 1e9 + 7, oo = 1e16;
const ld PI = 3.141592653589793;

lli a[N];

int main(){
	lli a, b;
	cin >> a >> b;
	a -= (2 * b);
	cout << max (0ll, a);
}


Measured memory_bytes: 256
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

int A[2][110] = {};

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

  int N;
  cin >> N;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  ll m = 0;
  for (int s = 0; s < N; s++) {
    ll c = 0;
    for (int j = 0; j < N; j++) {
      if (j <= s) {
        c += A[0][j];
      }
      if (j >= s) {
        c += A[1][j];
      }
    }
    m = max(m, c);
  }

  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;

fn eat(buf:String) -> i32 {
    let mut result = 0;
    for x in buf.chars() {
        match x {
            '+' => result += 1,
            _ => result -= 1,
        }
    }

    return result;
}

fn main() {
    //test

    assert_eq!(eat("-+--".to_string()), -2);
    assert_eq!(eat("----".to_string()), -4);

    let stdin = io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).ok();
    let txt:Vec<_> = line.trim().split(' ').collect();
    let buf:String = txt[0].parse().unwrap();


    let result = eat(buf);
    println!("{}", result);
}



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

int main()
{
	string s;
	cin>>s;
	map<char,int> mp;
	int len=s.size();
	for(int i=0;i<len;i++){
		mp[s[i]]++;
	}
	for(char i='a';i<='z';i++){
		if(mp[i]==0){
			cout<<i<<'\n';
			return 0;
		}
	}
	cout<<"None"<<'\n';
	return 0;
 } 

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
    int H[1000], W[1000];
    int n = 0;
    while(true) {
        cin >> H[n] >> W[n];
        if(H[n] == 0 && W[n] == 0) break;
        ++n;
    }

    for(int i = 0; i < n; i++) {
        for (int j = 0; j < H[i]; j++)
        {
            for (int l = 0; l < W[i]; l++) {
                if(j % 2 == 0 && l % 2 == 0) cout << '#';
                if(j % 2 == 0 && l % 2 != 0) cout << '.';

                if(j % 2 != 0 && l % 2 == 0) cout << '.';
                if(j % 2 != 0 && l % 2 != 0) cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll 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 fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; ll x; cin >> n >> x;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll ans=0;
    rep(i,n-1){
        ll sum=a[i]+a[i+1];
        if(sum<=x) continue;
        if(sum-x>a[i+1]){
            a[i+1]=0;
            ans+=sum-x;
        }else{
            a[i+1]-=(sum-x);
            ans+=sum-x;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        input = Console.ReadLine().Split(' ');
        int[] buka = new int[n];
        for(int i = 0; i < n - 1; i++)
        {
           int joushi = int.Parse(input[i]);
           buka[joushi - 1] += 1;
        }
        for(int i = 0; i < n; i++) Console.WriteLine(buka[i]);
	}

}

Measured memory_bytes: 42148
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, x, m = map(int, input().split())
    ans = 0

    # pigeon hole principle
    index = [-1] * m
    now = x
    i = 0
    while index[now] == -1:
        index[now] = i
        i += 1
        ans += now
        now = now * now % m
        n -= 1
        if n == 0:
            print(ans)
            return

    l = i - index[now]
    cycle = 0
    for _ in range(l):
        cycle += now
        now = now * now % m

    q, r = divmod(n, l)
    ans += q * cycle

    for _ in range(r):
        ans += now
        now = now * now % m

    print(ans)
resolve()

Measured memory_bytes: 65332
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int C, D, W, X;	// C: 地域数 (1 ≦ C ≦ 15 ) D: ツアー数（1 ≦ D ≦ 30 ) 
			// W:負担の合計の最大値 (0 ≦ W ≦ 50 )
			// X:ツアー期間中ライブを同じ日に2度以上行える合計日数の上限 ( 0 ≦ X ≦ 5 )
int E[32][32];	// E[i][j] 地域 i で j 日目にライブを行うことで期待される利益 ( 0 ≦ E[i][j] ≦ 1000)
int F[32][32];	// F[i][j] 地域 i で j 日目にライブを行うことで掛かる負担 ( 0 ≦ F[i][j] ≦ 10 )
vector<int> G;		// 同じ日にライブを行える地域の取り方の状態
int CC;			// 同じ日にライブを行える地域の取り方の状態数

int dp[32][51][6];		// dp[日時][負担数][2度以上行える合計日数]:= 最大の利益


int solve (int d, int w, int x ){

	if (d >= D || x > X ) return 0;

	if (dp[d][w][x] != -1 ) return dp[d][w][x];

	int res = solve (d+1, w, x );
	rep (i, CC ){
		int cont = (__builtin_popcount (G[i] ) > 1 );
		if (x == X && cont ) continue;
		bool ok = true;
		int curr_e = 0, curr_w = w;
		rep (j, C ){
			if (G[i] & (1<<j ) ){
				if (E[j][d] == 0 || curr_w + F[j][d] > W  ){
					ok = false; break;
				}else{
					curr_e += E[j][d];
					curr_w += F[j][d];
				} // end if
			} // end if
		} // end rep
		if (ok ){
			res = max (res, solve (d+1, curr_w, x + cont ) + curr_e );
		} // end if
	} // end rep

	return dp[d][w][x] = res;
}

// ツアーにおける地域の可能な状態を作成する
void calc_status (int C ){
	G.clear();
	G.push_back (0 );		// この日はステージはなし
	for (int i = 1; i <= C; i++ ){
		int curr = (1<<C)-1;
		curr -= (1<<(i-1))-1;
		for (int j = 1; j <= i; j++ ){
			G.push_back(curr );
			curr >>=1;
		} // end for
	} // end for
	sort (ALL (G ) );	
	CC = G.size();			
}

int main()
{
	ios_base::sync_with_stdio(0);
	while (cin >> C >> D >> W >> X, C ){
		memset (E, 0, sizeof (E ) );
		memset (F, 0, sizeof (F ) );
		
		rep (i, C ) rep (j, D ) cin >> E[i][j];
		rep (i, C ) rep (j, D ) cin >> F[i][j];

		calc_status (C );
		memset (dp, -1, sizeof (dp ) );
		int res = solve(0, 0, 0 );
		cout << res << endl;
	} // end while
		
	return 0;
}

Measured memory_bytes: 1276
from collections import deque
N,M = [int(x) for x in input().split(" ")]
qs = []
for i in range(N):
    qs.append(deque())
lens = [0]*N
for i in range(M):
    info,num = [int(x) for x in input().split(" ")]
    if info == 0:
        print(qs[num-1].popleft())
        lens[num-1] -= 1
    elif info == 1:
        index = 0
        for j in range(N):
            if lens[index] > lens[j]:
                index = j
        qs[index].append(num)
        lens[index] += 1
        


Measured memory_bytes: 6316
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let s: Vec<_> = i.read_line().as_bytes().iter().cloned().collect();
    let t: Vec<_> = i.read_line().as_bytes().iter().cloned().collect();

    let r = if solve(&s, &t) { "Yes" } else { "No" };

    writeln!(o, "{}", r).unwrap();
}
fn solve(s: &[u8], t: &[u8]) -> bool {
    let mut s_to_t = vec![None; 26];
    let mut t_to_s = vec![None; 26];
    fn to_index(b: u8) -> usize {
        (b - b'a') as usize
    }
    fn try_add(si: usize, ti: usize, m: &mut Vec<Option<usize>>) -> bool {
        if let Some(x) = m[si] {
            if x != ti {
                return false;
            }
        } else {
            m[si] = Some(ti);
        }
        true
    }

    for i in 0..s.len() {
        let si = to_index(s[i]);
        let ti = to_index(t[i]);
        if !try_add(si, ti, &mut s_to_t) || !try_add(ti, si, &mut t_to_s) {
            return false;
        }
    }
    true
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int h,w,k;
    cin >> h >> w >> k;
    vs s(h);
    rep(i,h)cin >> s[i];
    int ans = INF;
    rep(bit, 1LL << (h-1)){
        int size = 0;
        vi ind(h,0);
        rep(i,h){
            ind[i] = size;
            if(bit & (1<<i))size++;
        }
        int cnt = 0;
        vi num(size+1,0);
        int before = 0;
        rep(i,w)rep(j,h)if(s[j][i] == '1'){
            num[ind[j]]++;
            if(num[ind[j]] > k){//iの左で縦に切る
                if(before == i)goto END;
                before = i;
                cnt++;
                rep(x,size+1)num[x] = 0;
                i--;
                break;
            }
        }
        ans = min(ans, cnt + size);
        END:;
        //cout << bit << " " << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
long long c[55][55];
double dp1[105][52],dp2[105][52];
int main()
{
    for(int i=0;i<=50;++i)
    {
        c[i][0]=c[i][i]=1;
        for(int j=1;j<i;++j) c[i][j]=(c[i-1][j]+c[i-1][j-1]);
    }
    int n,m,L,P[105],T[105],V[105];
    scanf("%d%d%d",&n,&m,&L);
    for(int i=0;i<n;++i) scanf("%d%d%d",&P[i],&T[i],&V[i]);
    for(int i=0;i<n;++i)
    {
        double p[2][55];
        p[0][0]=1.0;
        p[1][0]=1.0;
        for(int j=1;j<=m;++j)
        {
            p[0][j]=p[0][j-1]*P[i]/100;
            p[1][j]=p[1][j-1]*(100-P[i])/100;
        }
        for(int j=0;j<=m;++j)
        {
            dp1[i][j]=c[m][j]*p[0][j]*p[1][m-j];
            dp2[i][j]=L*1.0/V[i]+j*T[i];
        }
    }
    for(int i=0;i<n;++i)
    {
        double ans=0;
        for(int j=0;j<=m;++j)
        {
            double tp=dp1[i][j];
            double lim=dp2[i][j];
            for(int x=0;x<n;++x)
            {
                if(x==i) continue;
                double q=0;
                for(int y=m;y>=0;--y) if(dp2[x][y]>lim) q+=dp1[x][y];
                tp*=q;
            }
            ans+=tp;
        }
        printf("%.8lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1316
#include <stdio.h>

int count(int odd, int num, int result){
  if(result == 0 && odd == 0) return 1;
  if(num > 9) return 0;
  return (count(odd, num + 1, result) + count(odd - 1, num + 1, result - num));
}

int main(){
  int n, s;

  while(1){
    scanf("%d%d", &n, &s);
    if(!n && !s) return 0;

    printf("%d\n", count(n, 0, s));
  }
}

Measured memory_bytes: 600
// BESでとく 木構造になっておりBFS木とよぶ
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

#include <iostream>
#include <iomanip>
#include <math.h>
using ll = long long;

using namespace std;

const int INF = 1001001001;
// 10^ vector: 可変長配列
vector<int> to[100005];

int main()
{
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    // toを各頂点ごとにもっていて，配列の中にはつながっている値
    to[a].push_back(b);
    to[b].push_back(a);
  }

  // BFS
  // 待ち行列 先入れ先だしのリスト構造でデータを保持
  queue<int> q;
  // dist: 距離 pre: 直前の頂点
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  // 支点
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    // qの先頭を取り出し，隣を更新してく
    int v = q.front(); q.pop();
    // 隣の頂点はv 
    for (int u : to[v]) {
      // 距離がわかっているときはなにもしない
      if (dist[u] != INF) continue;
      // まだわかっていないときは，距離を１たし，
      // 直前の頂点(v)を記録する
      dist[u] = dist[v]+1;
      pre[u] = v;
      q.push(u);
    }
  }
 
  cout << "Yes" << endl;
  rep(i,n) {
    if (i == 0) continue;
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int main(void){
	int n; cin>>n;
	vector<int> t(n), a(n);
	for (int i = 0; i < n; i++) cin>>t[i]>>a[i];

	ll T = 1, A = 1;
	for (int i = 0; i < n; i++) {
		ll x = (T + t[i] - 1) / t[i];
		ll y = (A + a[i] - 1) / a[i];
		T = max(x, y) * t[i];
		A = max(x, y) * a[i];
	}

	cout<< T + A <<endl;
	
	return 0;
}

Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	stack < pair < int, int > > st;
	int n;
	scanf("%d", &n);
	vector < int > a(n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	ll cur = 0, ans = 0;
	st.push({-1, n});
	for (int i = n - 1; i >= 0; i--)
	{
		while(st.top().first > a[i])
		{	
			int val = st.top().first, pos = st.top().second;
			st.pop();
			cur -= 1ll * val * (st.top().second - pos);			
		}
		cur += 1ll * (st.top().second - i) * a[i];
		st.push({a[i], i});
		ans += cur;
	}
	cout << ans << endl;		

	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

#define MAX_V 10000

struct edge{ ll to,cap,rev; };
vector<edge> G[MAX_V];
ll level[MAX_V];
int iter[MAX_V];

void add_edge(ll from,ll to,ll cap){
  // printf("%lld -> %lld : %lld\n", from,to,cap);
  G[from].push_back((edge){to,cap,(ll)G[to].size()});
  G[to].push_back((edge){from,0,(ll)G[from].size()-1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<ll> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    ll v=que.front(); que.pop();
    for(int i=0;i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        que.push(e.to);
      }
    }
  }
}

ll dfs(int v,int t,ll f){
  if(v==t)return f;
  for(int &i=iter[v];i<(int)G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      ll d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(int s,int t){
  ll flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    ll f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

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

  ll H,W,C;
  cin>>H>>W>>C;
  vector<vector<ll> > B(H,vector<ll>(W,0));
  rep(i,H)rep(j,W){
    cin>>B[i][j];
  }

  int source=(H-1)*(W-1);
  int sink=source+1;
  ll res=0;
  rep(i,H-1)rep(j,W-1){
    if((i+j)%2==1)continue;

    ll sum=0;
    repl(ni,i,i+2)repl(nj,j,j+2){
      sum+=B[ni][nj];
    }

    ll prof=sum-C;
    if(prof<0)continue;
    res+=prof;
    if(i%2==0){
      add_edge(source,i*(W-1)+j,0);
      add_edge(i*(W-1)+j,sink,prof);
    }else{
      add_edge(source,i*(W-1)+j,prof);
      add_edge(i*(W-1)+j,sink,0);
    }
  }

  rep(i,H)rep(j,W){
    if((i+j)%2==0){
      ll i1=i,j1=j,i2=i-1,j2=j-1;
      if(i1<0||j1<0||i1>=H-1||j1>=W-1)continue;
      if(i2<0||j2<0||i2>=H-1||j2>=W-1)continue;
      if(i1%2==1){
        add_edge(i1*(W-1)+j1,i2*(W-1)+j2,B[i][j]);
      }else{
        add_edge(i2*(W-1)+j2,i1*(W-1)+j1,B[i][j]);
      }
    }else{
      ll i1=i,j1=j-1,i2=i-1,j2=j;
      if(i1<0||j1<0||i1>=H-1||j1>=W-1)continue;
      if(i2<0||j2<0||i2>=H-1||j2>=W-1)continue;
      if(i1%2==1){
        add_edge(i1*(W-1)+j1,i2*(W-1)+j2,B[i][j]);
      }else{
        add_edge(i2*(W-1)+j2,i1*(W-1)+j1,B[i][j]);
      }
    }
  }

  cout<<res-max_flow(source,sink)<<endl;

  return 0;
}



Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
#define deba(x) cerr << #x << endl; for (auto a : x) cerr << a << " "; cerr << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const int MOD = 1000000007;


int main() {
	fastio();
	int n, W;
	cin >> n >> W;
	ll v[n+1], w[n+1];
	v[0]=0, w[0]=0;
	for(int i=1;i<=n;i++)
		cin >> w[i] >> v[i];
	ll dp[n+1][W+1];
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=W;j++) {
			if(i==0 || j==0)
				dp[i][j] = 0;
			else {
				dp[i][j] = dp[i-1][j];
				if(w[i]<=j)
					dp[i][j] = max(dp[i][j], dp[i-1][ j-w[i] ] + v[i]);
			}
		}
	}
	cout << dp[n][W] << "\n";
	return 0;
}



Measured memory_bytes: 79232
#include <iostream>
        #include <vector>
        #include <string>
        #include <stack>
        #include <bits/stdc++.h>
        #include <algorithm>
        using namespace std;
        #define M 1000000007

        int binarySearch(vector<int> input, int target){
            int start = 0;
            int end = input.size() -1;
            int result = -1;
            while(start<=end){
                int mid = end - (end-start)/2;
                if(input[mid]==target){
                    result = mid;
                    start = mid+1;
                }else if(input[mid]>target){
                    end = mid-1;
                }else{
                    start = mid+1;
                }
            }
            return result;
        }
        int lis(vector<int> v, int n, int maxVal){
            if(n==0)
                return 0;
            if(v[n-1]<maxVal){
                return max( 1+lis(v, n-1, v[n-1]), lis(v, n-1, maxVal) );
            }else
            return lis(v, n-1, maxVal);
        }
        void sw(string &s, int i, int j){
            char temp = s[i];
            s[i] = s[j];
            s[j] = temp;
        }
        void swap(string &s, int i, int j){
            for(int l=j; l>i; l--){
                sw(s, l, l-1);
            }
        }

        int get(int n){
            if(n%2==1)
                return n;
            return get(n/2);
        }

void dfs(vector<vector<int>> &graph, vector<bool> &visited, int start, int curr, int &max){
    if(visited[start])
    return;


    visited[start] = true;
    for(auto i: graph[start]){
        dfs(graph, visited, i, curr+1, max);
    }
}


    int main(){
            #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.in", "w", stdout);
            #endif

          int n, k;
            cin>>n>>k;
            int a[n];
            for(int i=0; i<n; i++)
                cin>>a[i];
            long long dp[n+1][k+1];
            long long psum[n+1][k+1];
            for(int i=1; i<k+1; i++){
                dp[0][i] = 0;
                psum[0][i] = 1;
            }
            for(int i=0; i<n+1; i++){
                dp[i][0] = 1;
                psum[i][0] = 1;
            }

            for(int i=1; i<n+1; i++){
                for(int j=1; j<k+1; j++){
                        long long temp = j-a[i-1]; if(temp<0) temp = 0;
                        // dp[i][j] =  (psum[i-1][j]%M - psum[i-1][temp]%M +
                        // dp[i-1][temp]%M)%M ;
                        dp[i][j] =  (((psum[i-1][j]%M - psum[i-1][temp]%M) + M)%M +
                        (dp[i-1][temp]%M)) %M ;
                        psum[i][j] = (dp[i][j]%M + psum[i][j-1]%M)%M;
                }
            }
            cout<<dp[n][k]<<"\n";
   }


Measured memory_bytes: 161316
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// Not gonna give up until it's over
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 2e5 + 10;
ll seg[4*MAXN],lazy[4*MAXN];
vector<pair<ll,ll>> L[MAXN],R[MAXN];

void propogate(ll node,ll s,ll e){
    seg[node] += lazy[node];
    if(s != e){
        lazy[2*node] += lazy[node];
        lazy[2*node+1] += lazy[node];
    }

    lazy[node] = 0;
}

void update(ll node,ll s,ll e,ll qs,ll qe,ll val){
    propogate(node,s,e);
    if(s > e || qs > e || qe < s) return;

    if(qs <= s && e <= qe){
        lazy[node] += val;
        propogate(node,s,e);
        return;
    }

    ll mid = (s+e)>>1;
    update(2*node,s,mid,qs,qe,val);
    update(2*node+1,mid+1,e,qs,qe,val);
    seg[node] = max(seg[2*node],seg[2*node+1]);
}

ll query(ll node,ll s,ll e,ll qs,ll qe){
    propogate(node,s,e);
    if(s > e || qs > e || qe < s) return -1e16;

    if(qs <= s && e <= qe) return seg[node];

    ll mid = (s+e)>>1;

    return max(query(2*node,s,mid,qs,qe),query(2*node+1,mid+1,e,qs,qe));
}

void solve(){
    ll n,m; cin>>n>>m;

    FOR(i,1,m){
        ll l,r,a; cin>>l>>r>>a;
        L[l].push_back({l-1,a});
        R[r].push_back({l-1,a});
    }

    ll ans = 0;

    FOR(i,1,n){
        for(auto x:L[i]) update(1,0,n,0,x.first,x.second);
        
        ll t_ans = query(1,0,n,0,i-1);
        ans = max(ans,t_ans);
        update(1,0,n,i,i,t_ans);

        for(auto x:R[i]) update(1,0,n,0,x.first,-x.second);
    }

    cout<<ans<<endl;
}

signed main(){
 
   FastRead;    
 
    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 33280
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<int>d(N);
  for(int i=0;i<N;i++){
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  
  int M;
  cin >> M;
  
  vector<int>t(M);
  for(int i=0;i<M;i++){
    cin >> t[i];
  }
  sort(t.begin(),t.end());
  
  int p = 0;
  bool ans = true;
  
  for(int i=0;i<M;i++){
    while(d[p] != t[i] && p < N){
      p++;
    }
    if(p == N){
      ans = false;
      break;
    }
    p++;
  }
  
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 1920
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, C;
char S[int(2e5 + 5)];
int L[int(2e5 + 5)], R[int(2e5 + 5)];

int main(){
  scanf("%d%d%d", &N, &K, &C);
  scanf("%s", S + 1);

  int now = 0, cnt = 1;
  while (cnt <= K){
    now++;
    if (S[now] == 'x'){
      continue;
    }else{
      L[cnt] = now;
      now += C; cnt++;
    }
  }

  cnt = K; now = N + 1;
  while (cnt > 0){
    now--;
    if (S[now] == 'x') continue;
    R[cnt] = now;
    now -= C; cnt--;
  }

  for (int i = 1; i <= K; i++){
    if (L[i] == R[i]) cout << L[i] << endl;
  }


  return 0;
}


Measured memory_bytes: 5400
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

vector<vector<ll>> chk(20,vector<ll>(10));
int main(){
  ll k;
  cin >> k;
  vector<ll> a;
  for(int i =1; i <= 9; i++){
    a.push_back(i);
  }
  while(1){
    if(k <= a.size()){
      printf("%lld\n", a[k-1]);
      return 0;
    }
    k -= a.size();
    vector<ll> old;
    swap(a,old);
    for(ll x: old){
      for(int i = -1; i <= 1; i++){
        int d = x%10 + i;
        if(d < 0 || d > 9) continue;
        ll nx = x*10 + d;
        a.push_back(nx);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1716
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__



void solve(void){
  
  int N;
  cin >> N;
  
  vector<string> S(N);
  
  map<string, ll> A;
 
  REP(i,N){
    cin >> S[i];
    sort(ALL(S[i]));
    if(A.count(S[i])){
      A[S[i]]++;
    }
    else
    {
      A[S[i]]=1;
    }
//    cout << S[i] << " " << A[S[i]] << endl;
  }
  
  ll nc=0;
  
  for(auto v: A){
    nc += v.second*(v.second-1)/2;
  }
 
  cout << nc << endl;
  
  return;
   
}

#define TESTCASES	1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

  	REP(i,TESTCASES){
    	solve();
    } 
  
    return 0;
}



Measured memory_bytes: 16640
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int main(){
    int N,M,X,Y,maxi;
     maxi=-100000;
    cin>>N>>M>>X>>Y;
int x[N],y[M];
    rep(i,N){
   cin>>x[i];
maxi=max(maxi,x[i]);
}
maxi++;
    rep(i,M){
   cin>>y[i];
   if(y[i]<maxi){
     out("War");
   return 0;
}
}
if(maxi<=X||maxi>Y){
   out("War");
   return 0;
}
out("No War");
}


Measured memory_bytes: 256
object Main extends App {
	val N = scala.io.StdIn.readInt
	val S = scala.io.StdIn.readLine.toList.toArray

	var r = 0
	var g = 0
	var b = 0

	for(x <- S){
		x match {
			case 'R' => r += 1
			case 'G' => g += 1
			case 'B' => b += 1 
		}
	}

	var ans = r*g*b.toLong

	for(i<-0 until N){
		for(j<-i+1 until N){
			val k = 2*j - i
			if(k < N){
				if(S(i) != S(j) && S(j) != S(k) && S(i) != S(k)) ans -= 1
			}
		}
	}

//	println("r:" + r + " g:" + g + " b:" + b)

	println(ans)

}

Measured memory_bytes: 55200
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if a.count(maxa)>=2:
    for i in range(n):
        print(maxa)
else:
    maxi=a.index(maxa)
    a.remove(maxa)
    maxa2=max(a)
    for i in range(n):
        if i==maxi:
            print(maxa2)
        else:
            print(maxa)

Measured memory_bytes: 12532
N, M = map(int, input().split())
A = list(map(int, input().split()))
exc = []

for i in range(M):
  exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(M):
  e += [exc[i][1]] * exc[i][0]
  count += exc[i][0]
  if count >= N:
    break
cards = sorted(A+e, reverse=True)
print(sum(cards[:N]))
  
  


Measured memory_bytes: 37840
#include <bits/stdc++.h>
#define INF 3000
using namespace std;

int H, W;
vector<vector<char>> A(1000, vector<char>(1000));
vector<vector<int>> B(1000, vector<int>(1000, INF));

void dfs(int x, int y) {
    if (y + 1 < W && B[x][y] + 1 < B[x][y + 1]) {
        B[x][y + 1] = B[x][y] + 1;
        dfs(x, y + 1);
    }
    if (0 <= y - 1 && B[x][y] + 1 < B[x][y - 1]) {
        B[x][y - 1] = B[x][y] + 1;
        dfs(x, y - 1);
    }
}

void dfs_down(int x, int y) {
    if (x + 1 < H && B[x][y] + 1 < B[x + 1][y]) {
        B[x + 1][y] = B[x][y] + 1;
        dfs_down(x + 1, y);
    }
}

void dfs_up(int x, int y) {
    if (0 <= x - 1 && B[x][y] + 1 < B[x - 1][y]) {
        B[x - 1][y] = B[x][y] + 1;
        dfs_up(x - 1, y);
    }
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            if (A[i][j] == '#') B[i][j] = 0;
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (B[i][j] != INF) {
                dfs(i, j);
                dfs_down(i, j);
            }
        }
    }

    for (int i = H - 1; i >= 0; i--) {
        for (int j = W - 1; j >= 0; j--) {
            dfs_up(i, j);
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, B[i][j]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5248
N = int(input())
A = [list(map(int, input().split())), list(map(int, input().split()))]
# 累積和の定義
cum_abv = []
cum_blw = []
sum1 = 0
sum2 = 0
for i in range(N):
    sum1 += A[0][i]
    cum_abv.append(sum1)
    sum2 += A[1][N - i - 1]
    cum_blw.append(sum2)
 #   print(cum_blw)
cum_blw.sort(reverse=True)
# print(cum_blw)

sum = [i + k for i, k in zip(cum_blw, cum_abv)]
ans = max(sum)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ( (100*a + 10*b + c) % 4 ==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<long> p(m);
    vector<string> s(m);
    for (int i = 0; i < m; i++)
    {
        cin >> p.at(i);
        cin >> s.at(i);
    }

    vector<bool> Qs(n + 1, false);
    vector<long> penalty(n + 1, 0);
    int sumPenalty = 0;
    int ACs = 0;
    for (int i = 0; i < m; i++)
    {
        if (Qs.at(p[i]) == false)
        {
            if (s[i] == "WA")
            {
                penalty.at(p[i])++;
            }
            else if (s[i] == "AC")
            {
                Qs.at(p[i]) = true;
                sumPenalty += penalty.at(p[i]);
                ACs++;
            }
            else
            {
                cout << "error1" << endl;
            }
        }
        else if(Qs.at(p[i]) == true)
        {
            ;
        }
        else
        {
            cout << "error2" << endl;
        }
    }
    cout << ACs << " " << sumPenalty << endl;
    return 0;
}

Measured memory_bytes: 7296
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

int siz[MAX];//錬結成分のサイズ
int par[MAX];//親
int Rank[MAX];//木の深さ

//n要素で初期化
void init(int n) {
	REP(i, n) {
		par[i] = i;
		Rank[i] = 0;
		siz[i] = 1;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);//経路圧縮(根に直接つなぎなおす)もしつつ
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	//低いほうを高いほうにつなげる(効率化)
	if (Rank[x] < Rank[y]) {
		par[x] = y;
		siz[x] += siz[y];
		siz[y] = siz[x];
	}
	else {
		siz[y] += siz[x];
		siz[x] = siz[y];
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}

vector<int>G[100010];
int b[100010];
void solve() {
	int N, M, K; cin >> N >> M >> K;
	init(N);
	REP(i, M) {
		int u, v; cin >> u >> v;
		u--, v--;
		unite(u, v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	REP(i, K) {
		int u, v; cin >> u >> v; u--, v--;
		if (same(u, v)) {
			b[u]++;
			b[v]++;
		}
	}
	REP(i, N) {
		int sum = siz[find(i)];
		pe(sum - G[i].size() - b[i]-1);
	}cout << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 11636