akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define BOOST        std::ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define sp           <<" "<<
#define ll           long long
#define ld           long double
#define AZI(i,x)     for(auto i=x.begin();i!=x.end();i++)
#define AZ(x)        x.begin(),x.end()
#define P(x,y)       pair < x,y >
#define V(x)         vector < x >
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define PI           3.14159265358979323846264338327950288419716939937510

// find_by_order(int k) - returns k'th smallest element (0-indexed)
// order_of_key(int k) - returns number of elements strictly smaller than k.
// using namespace __gnu_pbds;
// #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>

const ll mod=1e9+7,N=1e5+5,INF = 1e18;

ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}


/*

1. Make sure you're taking all the inputs.
2. In case of nested loops, remember to use different variables.
3. If in doubt, do int -> ll
4. Don't fight the question, try solving the next one.

*/



//  Don't code anything above this //


int main() 
{ 
    BOOST

    int n,k;
    cin>>n>>k;

    int poss = (n-1)*(n-2) / 2;
    
    if(k>poss)
        return cout<<"-1\n",0;

    int red = poss - k;

    bool graph[n+1][n+1]={};
    int edges = 0;
    
    for(int i=2;i<=n;i++)
        graph[1][i] = 1, edges++;;

    bool stop = 0;
    
    for(int i=2;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(red == 0)
            {
                stop =1;
                break;
            }
            graph[i][j] = 1;
            edges++;
            red--;
        }
        if(stop)
            break;
    }
    
    cout<<edges<<"\n";
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            if(graph[i][j])
                cout<<i<<" "<<j<<"\n";
    
    return 0;    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		long count = 0;
		count = b / x - a /x;
			if(a % x == 0){
				count++;
			}
		System.out.println(count);

	}

}


Measured memory_bytes: 22868
import sys,queue,math,copy,itertools,bisect,collections
from heapq import *

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**8
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,M,R = LI()
    r = _LI()
    root = [[] for _ in range(N)]
    for _ in range(M):
        a,b,c = LI()
        root[a-1].append((b-1,c))
        root[b-1].append((a-1,c))

    memo = [[0] * N for _ in range(N)]

    min_r = INF
    for x in itertools.permutations(r):
        it = 0
        s = x[0]
        for t in x[1:]:
            if memo[s][t]:
                it += memo[s][t]
            else:
                node = [INF] * N
                q = []
                heapify(q)
                heappush(q,(0,s))
                while q:
                    l,u = heappop(q)
                    if l >= node[u]: continue
                    node[u] = l
                    for v,m in root[u]:
                        if node[v] > l + m:
                            heappush(q,(l+m,v))
                memo[s][t] = node[t]
                memo[t][s] = node[t]
                it += node[t]
            s = t
        min_r = min(min_r,it)
    print(min_r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 75736
#include<bits/stdc++.h>
using namespace std;
//i am very dangerous
int main()
{string x;
cin>>x;
for(int i=0;i<x.size()-8;i++)
{if(x.substr(x.size()-8-i,8)=="FESTIVAL")
{cout<<x.substr(0,x.size()-8-i);
return 0;}   
}

}
//mmmm

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define ff(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)  
ll v[N];
int main(){
    //FL;
    fin;
    int n;
    cin >> n;
    fore(i, 0, n)cin >> v[i];
    int j = 0;
    ll bit = 0;
    ll sum = 0;
    ll ans = 0;
    fore(i, 0, n){
        while(j < n && (sum + v[j]) == (bit ^ v[j])){
            sum += v[j];
            bit ^= v[j];
            j++;
        }
        ans += j - i;
        if(i == j)j++;
        else{
            sum -= v[i];
            bit ^= v[i];
        }
    }
    cout << ans << '\n';
    time;
    return 0;
}   

Measured memory_bytes: 1792
r, c = map(int, raw_input().split())

line = [map(int, raw_input().split()) for i in range(r)]
foot = [0 for i in range(c+1)]

for i in range(len(line)):
	line[i].append(sum(line[i]))
	for j in range(len(line[i])):
		foot[j] += line[i][j]

line.append(foot)
for l in line:
	print " ".join(map(str, l))

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

int main()
{
    string S;
    cin >> S;
    reverse(S.begin(),S.end());
    string T;
    T = "";
    string Example[4] = {"dream","dreamer","erase","eraser"};
    for(int i = 0; i < 4; i++) reverse(Example[i].begin(),Example[i].end());
    
    int l = S.length();

    bool Judge1 = true;

    for(int i = 0; i < l;){
        bool Judge2 = false;
        for(int j = 0; j < 4; j++){
            if(S.substr(i,Example[j].size()) == Example[j]){
                Judge2 = true;
                i += Example[j].size();
            }
        }
        if (!Judge2){
            Judge1 = false;
            break;
        }
    }

    if(Judge1) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 512
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m, d;
	cin >> n >> m >> d;


	long long pairs = d ? 2 * (n-d) : n;

	double p = 1.0 * pairs / (1ll*n*n);

	cout << fixed << setprecision(10) << (m-1) * p;


	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    int n = 0;
    rep(i,s.size()){
        n += (',' - s[i]);
    }
    cout << n << endl;
}

Measured memory_bytes: 256
def priority_push(array:, num:)
  index = array.bsearch_index { |i| i <= num}
  if index.nil?
    array.push(num)
  else
    array.insert(index, num)
  end
end

N, M = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)

arr = arr.sort

cost = arr.pop
stack = [cost / 2]
stack_max = cost / 2
(M - 1).times do
  before_cost = arr.last

  if before_cost.nil? || before_cost <= stack_max
    arr = (arr + stack).sort
    after_cost = arr.pop / 2

    stack = [after_cost]
    stack_max = after_cost
  else
    stack << arr.pop / 2
  end
end

puts (arr + stack).inject(:+)

Measured memory_bytes: 15828
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n)

const int Y = 1000, M = 10, DL = 20, DS = 19;

int main()
{
    int n, y, m, d; cin >> n;
    while(n--)
    {
        cin >> y >> m >> d;
        int ans = 0;
        for(int i = y + 1; i < Y;i++)
        {
            if(i % 3 == 0) ans += DL * M;
            else ans += (DL  * 5 + DS * 5);
        }
        for(int i = m + 1; i <= M;i++)
        {
            if((y % 3 != 0) && (i % 2 == 0))ans += DS;
            else ans += DL;
        }

        if((y % 3 != 0) && (m % 2 == 0)) ans += DS;
        else ans += DL;
        ans -= d;
        ans += 1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
N = int(input())
S = input().rstrip()

L = [0] * (N + 1)  # 西向いてる人の累積(0から)
R = [0] * (N + 1)  # 東向いてる人の累積(Nから)

cnt = 0
for i in range(N):
    if S[i] == 'W':
        cnt += 1
    L[i] = cnt

cnt = 0
for i in reversed(range(N)):
    if S[i] == 'E':
        cnt += 1
    R[i] = cnt

ans = 300000
for i in range(N):
    if i == 0:
        ans = R[i + 1]
    else:
        ans = min(ans, L[i-1] + R[i+1])

print(ans)


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



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

  int h, w, n;
  cin >> h >> w >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  vii ans(h,vi(w));
  int cur = 1;
  rep(i,h) {
    if(i % 2 == 0) {
      rep(j,w) {
        ans[i][j] = cur;
        a[cur-1]--;
        if(a[cur-1] == 0) cur++; 
      }
    }
    else {
      per(j,w-1) {
        ans[i][j] = cur;
        a[cur-1]--;
        if(a[cur-1] == 0) cur++; 
      }
    }
  }
  rep(i,h) {
    rep(j,w) {
      cout << ans[i][j] << ' '; 
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
n, a, b = map(int,(input().split()))

if (a + b) % 2 == 0:
    print((a+b)//2 - a)

else:
    if a - 1 <= n - b:
        kaisuu = (a - 1) + 1 + (1 + b - a) // 2 - 1
        print(kaisuu)
    else:
        kaisuu = (n - b) + 1 + (n + (a + (n - b + 1))) // 2 - (a + n - b + 1)
        print(kaisuu)

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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

int32_t main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	int freq[200005]={0};
	int x;
	for(int i=0;i<n-1;i++)
	{	
		cin>>x;
		freq[x]++;
	}

	for(int i=1;i<=n;i++)
	{
		cout<<freq[i]<<'\n';
	}

	return 0;
}	

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

// int gcd(int x,int y){
	// if(x>y) swap(x,y);
	
	// if(y%x==0) return x;
	// else gcd(y%x,x);
// }

int main(){
	int n;
	cin>>n;
	
	vector<int> a;
	for(int i=0;i<n;++i){
		int tmp;
		cin>>tmp;
		a.push_back(tmp);
	}
	
	int ans=__gcd(a[0],a[1]);
	for(int i=2;i<n;++i){
		ans=__gcd(ans,a[i]);
	}
	
	cout<<ans<<endl;
}//abc118_c 解説参考.

Measured memory_bytes: 892
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]
maxl = max(li, key=lambda x:x[0])[0]
minr = min(li, key=lambda x:x[1])[1]
if maxl <= minr:
    print(minr-maxl+1)
else:
    print(0)

Measured memory_bytes: 27348
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;
// Californium:Paken
vector<bool> seen;
void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする
 
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
signed main() {
    int L, R; cin >> L >> R;
    int M = 2019;
    if (L / 2019 == R / 2019 && L % 2019 != 0) {
        for (int X = L; X < min(L+2019,R); X++) {
            for (int Y = X+1; Y <= min(L+2019,R); Y++) {
                M = min(M,X*Y%2019);
            }
        }
        cout << M << endl;
    }
    else {
        cout << 0 << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
int a[10000];

int main(){
    cin >> n;
    long long s = 0;
    rep(i, n){
        cin >> a[i];
        s += a[i];
    }
    int p = *min_element(a, a + n);
    int q = *max_element(a, a + n);
    cout << p << ' ' << q << ' ' << s << endl;
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(a%b==0)return b;
    else gcd(b,a%b);
}
int main()
{
    int N,I,kyori[2]={0};
    cin>>N>>I;
    int X[N]={0};
    for(int i=0;i<N;i++){
        cin>>X[i];
        X[i]-=I;
    }
    int ans=X[0];
    for(int i=0;i<N-1;i++){
        ans=gcd(ans,X[i+1]);
    }
    cout<<abs(ans)<<"\n";
}


Measured memory_bytes: 640
import sys

def resolve():
    input = sys.stdin.readline
    C=input().rstrip()
    s="abcdefghijklmnopqrstuvwxyz"

    for i in range(len(s)):
        if s[i]==C:
            print(s[i+1])
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """a"""
        output = """b"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """y"""
        output = """z"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 51564
a, b = map(int, input().split())

def calc(n):
    lst = []
    if n==-1:return '0b0'
    if n%4==1 or n%4==2:lst.append('1')
    else:lst.append('0')
      
    mm = 2
    
    while n//mm != 0:
        l = n%(2*mm)
        if l >= mm and l%2==0:
            lst.append('1')
        else:lst.append('0')
        mm *= 2
    lst.append('0b')
    lst.reverse()
    return ''.join(lst)

lsta = int(calc(a-1),0)
lstb = int(calc(b),0)

print(lsta^lstb)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
  int n,m;
  cin>>n>>m;
  vector<int>v;
  for(int i=0;i<n;i++)
  {
      int a;
      cin>>a;
      v.push_back(a);
  }
  sort(v.begin(),v.end());
  int cnt=0;
  for(int i=0;i<n;i++){
    if(v[i]<=m){
        m-=v[i];
        cnt++;
    }
  }
  for(int i=0;i<n;i++){
     int d=m/v[i];
     m%=v[i];
     cnt+=d;
  }
  cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  vector<pair<int, int>> A;
  for(int i = 0; i < N; i++){
    int a; cin>>a;
    A.push_back(make_pair(a, i+1));
  }
  sort(A.begin(), A.end());
  
  for(int i = 0; i < N; i++){
    cout << A.at(i).second << " " ;
  }
}

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

using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i].second >> a[i].first;
    }
    sort(a.begin(), a.end(), greater<pair<int, int>>());
    set<int> st;
    for (int i = 0; i <= m; i++){
        st.insert(i);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++){
        auto it = st.upper_bound(m - a[i].second);
        if (it == st.begin()) continue;
        --it;
        ans += a[i].first;
        st.erase(it);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10; 
const int INF = 2e9;
int dp[N][4],h[N][4];

int main()
{
	int n;
	cin >> n;
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=3;j++)
		cin >> h[i][j];
	}
	for(int i=1;i<=n;i++)//ith day
	{
		for(int j=1;j<=3;j++)//jth last 
		{
			for(int k=1;k<=3;k++)//before 
			{
				if(k!=j)
				{
					dp[i][j]=max(dp[i-1][k]+h[i][j],dp[i][j]);
				}
			}	
		}
	}
	int ans=0;
	for(int i=1;i<=3;i++)
	{
		ans=max(ans,dp[n][i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3328
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	for i := len(s); i >= len(t); i-- {
		temp := s[i-len(t) : i]
		ok := true
		for j := 0; j < len(t); j++ {
			if t[j] != temp[j] && temp[j] != '?' {
				ok = false
				break
			}
		}
		if ok {
			ans := s[:i-len(t)] + t + s[i:]
			fmt.Println(strings.Replace(ans, "?", "a", -1))
			return
		}
	}
	fmt.Println("UNRESTORABLE")
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;

typedef long long ll;

ll cnt;
int l;
int A[11451419];
int n;
vector<int>G;

void insertionSort(int A[],int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
    A[j+g]=v;
  }
}

void shellSort(int A[], int n){
  for(int h=1; ; ){
    if(h>n)break;
    G.push_back(h);
    h=3*h+1;
  }
  for(int i=G.size()-1;i>=0;i--){
    insertionSort(A, n, G[i]);
  }
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  cnt=0;
  shellSort(A, n);
  cout<<G.size()<<endl;
  for(int i=G.size()-1;i>=0;i--){
    cout<<G[i]<<endl;
    if(i)printf(" ");
  }
  printf("\n");
  cout<<cnt<<endl;
  for(int i=0;i<n;i++)printf("%d\n", A[i]);
  return 0;
}



Measured memory_bytes: 7140
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
    if (!v.empty())
    {
        out << '[';
        copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

/* template end */

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

    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> xs(n + 1);
    vector<int> ys(m + 1);
    for (int i = 0; i < n; i++)
    {
        cin >> xs[i];
    }
    xs[n] = x;
    for (int i = 0; i < m; i++)
    {
        cin >> ys[i];
    }
    ys[m] = y;
    int mx = *max_element(xs.begin(), xs.end());
    int my = *min_element(ys.begin(), ys.end());
#if DEBUG
    cout
        << "** RESULT **" << endl; // debug
#endif
    cout << ((mx < my) ? "No War" : "War") << endl;

    return 0;
}


Measured memory_bytes: 256
void main() {
	auto A = readAs!(int[]);
	writeln(A.reduce!max - A.reduce!min);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    ll n = s.size();
    string s1, s2;
    s1 = s.substr(0, n/2);
    ll res = 0;
    reverse(all(s1));
    if(n%2){
        rep(i,n/2)if(s1[i] != s[n/2+1+i])res++;
    }
    else{
        rep(i,n/2)if(s1[i] != s[n/2+i])res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int m,f,b;

	scanf("%d %d %d",&m,&f,&b);
	if(b-m>f){
		printf("NA\n");
	}else if(b-m<0){
		printf("0\n");
	}else{
		printf("%d\n",b-m);
	}
	return 0;
}


Measured memory_bytes: 2064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<list>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<inttypes.h>
using namespace std;
#define REP(i,m,n) for(int i = (m); i < (n);i++)
#define rep(i,n) REP(i,0,n)


int main() {
	uint64_t n,m;
	cin >> n >> m;
	if(2*n <= m) {
		uint64_t result = n;
		m-= 2*n;
		result += m/4;
		cout << result << endl;
	}else {
		uint64_t result = m/2;
		cout << result << endl;
	}
	
	return 0;
}
/*int main() {
	int n;
	cin >> n;
	cout << 800 * n - (n/15)*200 << endl;
	return 0;
}*/


Measured memory_bytes: 256
#include<stdio.h>
int n,now;
int a[100009],sum,ans;
int main(){
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		scanf("%d",&now);

		if(a[now]==0){
			a[now]=1;
			ans++;
		}
		else
			sum++;
		}
	
	printf("%d",ans-(sum%2));
}

Measured memory_bytes: 512
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    string s;
    cin >> s;

    ll count = 0;
    for(char c : s){
        if(c=='1'){
            count++;
        }
    }

    p(count);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::vector<uint64> s;
	uint64 n;
	std::cin >> n;
	uint64 ans = 0;
	uint64 t = n;
	uint64 c = 0;
	while (t) {
		s.insert(s.begin(), t % 10);
		ans += t % 10;
		t /= 10;
		++c;
	}
	uint64 cur = 0;
	for (uint32 i = 0;i < c;++i) {
		if (s[i] == 0) continue;
		ans = std::max(ans, cur + s[i] - 1 + (c - i - 1) * 9);
		cur += s[i];
	}
	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main(){
    int K,D;
    cin >> K >> D;
    int C = 2 * D + 1;
    int count = 0, A = K;
    rep(i,K){
         A -= C;
        count++;
        if(A <= 0)
        break;
    }
    cout << count << endl;
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a,b;
    cin >> a >> b;
    if(a>=10 || b>=10){
        cout << "-1";
        return 0;
    }else{
        cout << a*b;
    }



}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	long i,j;
	long long min = 1000000;
	if((a/2019)!= (b/2019))
		min = 0;
	else{
		for(i = a;i<b;i++)
		{
			for(j = a+1;j<=b;j++)
			{
				long long c = ((i*j)%2019);
				if(min > c)
					min = c;
			}
		}
	}
	printf("%ld",min);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
before = -100
for i in A:
    ans += B[i - 1]
    if i == before + 1:
        ans += C[before - 1]
    before = i

print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define ll long long int

using namespace std;
int main()
{
    ll s,f,i;
    cin>>s>>f;
    if(f>=s)
    {
        cout<<"unsafe"<<endl;
    }
    else
    {
        cout<<"safe"<<endl;
    }

    return 0;
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> S(H);
    rp(i,H){
        cin >> S.at(i);
    }
    int ans[H][W];
    rp(i,H){
        rp(j,W){
            ans[i][j]=0;
        }
    }
    rp(i,H){
        rp(j,W){
            if(S.at(i).at(j)=='#'){
                rep(k,-1,1){
                    rep(l,-1,1){
                        if(i+k>=0&&i+k<H&&j+l>=0&&j+l<W){
                            ans[i+k][j+l]++;
                        }
                    }
                }
            }
        }
    }
    rp(i,H){
        rp(j,W){
            if(S.at(i).at(j)=='#'){
                cout << '#';
            }else{
                cout << ans[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;
int arr[22];

int maxim;
int ans = 1;

int main()
{
    cin >> n;
    cin >> arr[1];
    maxim = arr[1];
    for (int i = 2; i <= n; i++)
    {
        cin >> arr[i];
        if (arr[i] >= maxim)
            maxim = arr[i], ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://beta.atcoder.jp/contests/abc073/tasks/abc073_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		
		System.out.println(s.contains("9") ? "Yes" : "No");

	}

}


Measured memory_bytes: 23508
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			String S = scan.next();
			int N = S.length();
			
			StringBuffer sb = new StringBuffer(S);
			StringBuffer sc = new StringBuffer(S);
			sc.reverse();
			//String SR =sc.toString();
			int count = 0;
			int countR = 0;
			
			if(N==1) {
				System.out.println(0);
			}else {
				
			
			for(int i = 1;i<N;i++) {
				String su = sb.substring(i-1, i);
				String sm = sb.substring(i, i+1);
				if(sm.equals(su)&&sm.equals("1")) {
					sb.replace(i, i+1, "0");
					count++;
					//System.out.println(sb);
				}else if(sm.equals(su)&&sm.equals("0")) {
					sb.replace(i, i+1, "1");
					count++;
					//System.out.println(sb);
				}
			}
			System.out.println();
				
			for(int i = 1;i<N;i++) {
				String su = sc.substring(i-1, i);
				String sm = sc.substring(i, i+1);
				if(sm.equals(su)&&sm.equals("1")) {
					sc.replace(i, i+1, "0");
					countR++;
					//System.out.println(sc);
				}else if(sm.equals(su)&&sm.equals("0")) {
					sc.replace(i, i+1, "1");
					countR++;
					//System.out.println(sc);
				}
			}
			
			System.out.println(count>countR?countR:count);
			
			
			}
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 40780
#include <iostream>
#include <cstdio>                              //scanf,printf
#include <algorithm>                           //max,min
#include <string>                              //string
#include <cstring>                             //strlen,strcat
#include <cctype>                              //isalpha,tolower
using namespace std;

int main(){
    char s[205],q[105],t[101];
    cin>>s>>q;
    strcpy(t, s);
    strcat(s, t);
    if(strstr(s, q)==NULL){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
const int INF=0x3f3f3f3f;
int d[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}};
int main()
{
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);
    x-=z;
    printf("%d",x/(y+z));
    return 0;
}


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

const int MAX = 700000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int X,Y;
  cin >> X >> Y;

  ll ans = 0;
  COMinit();

  if((X + Y) % 3 == 0){
    int N = (X + Y) / 3;
    int M = X - N;
    ans = COM(N,M) % MOD;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16640
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int N;
int a[200001];
int b[200001];
int m[200001];

void solve()
{
    int s = 0;
    FORR(i, N, 1){
        b[i] = (a[i] + m[i]) % 2;
        if(b[i] == 1) s++;
        for(int j = 1; j*j <= i; j++){
            if(i % j == 0){
                m[j] = (m[j] + b[i]) % 2;
                if(j != i/j){
                    m[i/j] = (m[i/j] + b[i]) % 2;
                }
            }
        }
    }

    cout << s << endl;
    if(s > 0){
        int i = 0;
        while(s > 1){
            if(b[i] == 1){
                s--;
                cout << i << " ";
            }
            i++;
        }
        while(true){
            if(b[i] == 1){
                cout << i << endl;
                break;
            }
            i++;
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 1, N+1) cin >> a[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e - a > k) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << 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;

int main()
{
    string S;
    cin >> S;

    string week[7] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };

    for (int i = 0; i < 7; i++) {
        if (week[i] == S) {
            cout << 7 - i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define MOD 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N;
	cin >> N;
	ll T = 1, A = 1;
	ll t, a;
	for(int i = 0; i < N; i ++){
		cin >> t >> a;
		ll n = max(ceil((long double)T / t), ceil((long double)A / a));
		T = n * t;
		A = n * a;
		//cout << "n=" << n << ", T=" << T << ", A=" << A << endl;
	}
	cout << T + A << endl;

	return 0;
}

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

int main() {
    string S;
    ll Q;
    cin >> S >> Q;
    vector<char> vec(S.size());
    for (int i = 0; i < S.size(); i++) {
        vec[i] = S[i];
    }

    bool opposite = false;

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

        int t; cin >> t;
        if (t == 1) {
            if (opposite) opposite = false;
            else if (!(opposite)) opposite = true;
        }
        else if (t == 2) {
            int f; char c; cin >> f >> c;
            if (f == 1) {
                if (opposite) vec.push_back(c);
                else vec.insert(vec.begin(), c);
            }
            else if (f == 2) {
                if (opposite) vec.insert(vec.begin(), c);
                else vec.push_back(c);
            }
        }
    }

    if (opposite) reverse(vec.begin(), vec.end());

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

Measured memory_bytes: 1084
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
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);}

int main(){
    ll n,m,a,b,s=0;
    cin>>n>>m;
    vector<pair<ll,ll>> v(n);
    for(ll i=0;i<n;i++){
        cin>>a>>b;
        v[i]=make_pair(a,b);
    }
    sort(all(v));
    for(ll i=0;;i++){
        if(m>=v[i].second){
            s+=v[i].first*v[i].second;
            m-=v[i].second;
        }else{
            s+=v[i].first*m;
            break;
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,dp[1000005],mod=1e9+7,sum,ans;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    dp[n]=sum=n;
    for(ll i=n-1;i>0;i--){
      dp[i]=sum - dp[i+2] + ( (n-1)*(n-1))%mod + mod;
      dp[i]%=mod;
      dp[i]+=min(n-1,i+1);
      dp[i]%=mod;
      sum+=dp[i];
    }
    cout<<dp[1];
}

Measured memory_bytes: 8064
from collections import Counter
N, = list(map(int,input().split()))
S = input()
cx = Counter(S)
cy = Counter()
cm = 0
r = 0
for c in S:
    cx[c] -= 1
    cy[c] += 1
    if cy[c]==1 and cx[c]>=1:
        cm += 1
    elif cy[c]>=2 and cx[c]==0:
        cm -= 1
    r = max(r, cm)
print(r)

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

bool canTriangle(long long first, long long second, long long third) {
  if(first < third && second < third) {
   	return (first + second) > third;
  } else if(first > second && first > third) {
    return first < (second + third); 
  } else {
   return (first + third) > second; 
  }
}

int main () {
  int num; cin >> num;
  if(num < 3) {
    cout << 0 << endl;
    return 0;
  }
  
  vector<long long> sticks(num);
  for(int i = 0; i < num; i++) {
	long long temp; cin >> temp;
    sticks.at(i) = temp;
  }

  int ans = 0;
  for(int i = 0; i < num - 2; i++) {
    long long first = sticks.at(i);
    for(int j = i + 1; j < num - 1; j++) {
      long long second = sticks.at(j);
        if(first != second) {
     		for(int k = j + 1; k < num; k++) {
              long long third = sticks.at(k);
            	if(first != third && second != third) {
                   if(canTriangle(first, second, third)) {
                     ans++;
                   }
                }
            }
        }
    }
  }
  
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

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

int paint(vector<string> &field, int x, int y) {
    int cnt = 0;

    for(int i = 0; i < 4; ++i) {
        int xx = x + dx[i];
        int yy = y + dy[i];

        if(xx < 0 || field[0].size() <= xx || yy < 0 || field.size() <= yy) continue;

        if(field[yy][xx] == '.') {
            field[yy][xx] = '#';
            cnt += paint(field, xx, yy)+1;
        }
    }
    return cnt;
}

int main() {
    while(true) {
        int W, H;
        cin >> W >> H;

        if(!W && !H) break;

        int sx, sy;
        vector<string> field(H);
        for(int i = 0; i < H; ++i) {
            cin >> field[i];
            for(int x = 0; x < W; ++x) {
                if(field[i][x] == '@') {
                    sx = x;
                    sy = i;
                }
            }
        }

        cout << paint(field, sx, sy)+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(void){
  int n,i,a[105],sum=0;
  vector<P> ay;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  
  for (i=0;i<n;i++) ay.push_back(P(abs(sum-a[i]*n),i));
  
  sort(ay.begin(),ay.end());
  
  cout << ay[0].second << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>

using namespace std;

#define int long long
#define ll long long
#define double long double
#define pii pair<int, int>
#define vec vector
#define u_map unordered_map
#define u_set unordered_set
#define str string
#define all(el) el.begin(), el.end()
#define allr(el) el.rbegin(), el.rend()
#define sz(el) (int)el.size()
#define f first
#define s second
#define pb push_back
#define in insert
#define mp make_pair
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)

inline int maxi(int &a, int b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(int &a, int b) { if (b < a) { a = b; return 1; } return 0; }

inline int maxi(double &a, double b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(double &a, double b) { if (b < a) { a = b; return 1; } return 0; }

int bin_pow(int x, int p) {
    if (p < 0) {
        return 0;
    }
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int ans = bin_pow(x, p / 2);
        return ans * ans;
    }
    return x * bin_pow(x, p - 1);
}

int gcd(int a, int b) {
    if (!b) {
        return a;
    }
    return gcd(b, a % b);
}

int n, k;
vec<int> a;

int check(int ans) {
    int need = 0;
    for (int i = 0; i < n; i++) {
        need += (a[i] - 1) / ans;
    }
    return need <= k;
}

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int l = 0, r = *max_element(all(a));
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r;

    return 0;
}

Measured memory_bytes: 4776
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var d = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var result = 0L;

            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    result += d[i] * d[j];
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

double w, h;
int x, y;

int main(){
    cin >> w >> h >> x >> y;
    double ans = w * h / 2;
    int d = ((x*2LL == (LL)w && y*2LL == (LL)h) ? 1 : 0);
    cout << fixed << setprecision(12) << ans << " " << d << endl;
}

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

//flagを用いたバブルソート
int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;

    for (int i = 0; flag; i++){
        flag = 0;
        for (int j = N - 1; j >= i+1; j--){
            if(A[j]<A[j-1]){
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }

        }
    }
    return sw;
}

int main(){
    int A[100], N, sw;
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> A[i];

    sw = bubbleSort(A, N);

    for (int i = 0; i < N; i++){
        if(i)
            cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  REP(i, n) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(ALL(a));

  REP(i, n) { cout << a[i].second << ' '; }
  return 0;
}


Measured memory_bytes: 1664
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
dp = [0] * (N)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        dp[i+1] = dp[i] + 1
    else:
        dp[i+1] = dp[i]

for l, r in LR:
    print(dp[r-1] - dp[l-1])


Measured memory_bytes: 30664