akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N, M;
ll A[15][15];

bool used[15][15];

void dfs(ll r, ll c, ll x) {
  if(used[r][c]) return;
  used[r][c] = true;

  A[r][c] = !A[r][c];

  ll dd[5] = { 0, 1, 0, -1, 0 };
  REP(k, 0, 4) {
    ll nr = r + dd[k];
    ll nc = c + dd[k + 1];
    if(0 <= nr && nr < N && 0 <= nc && nc < N && A[nr][nc] == x) {
      dfs(nr, nc, x);
    }
  }
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, N) REP(j, 0, N) cin >> A[i][j];

  REP(_, 0, M) {
    ll O;
    cin >> O;

    if(O == 0) {
      ll r, c, size, angle; cin >> r >> c >> size >> angle; r--; c--;
      ll B[15][15];
      while(angle > 0) {
        REP(i, 0, N) REP(j, 0, N) B[i][j] = A[i][j];
        REP(i, r, r + size) REP(j, c, c + size) {
          B[r + (j - c)][c + size - 1 - (i - r)] = A[i][j];
        }
        REP(i, 0, N) REP(j, 0, N) A[i][j] = B[i][j];
        angle -= 90;
      }
    }
    if(O == 1) {
      ll r, c, size; cin >> r >> c >> size; r--; c--;
      REP(i, r, r + size) REP(j, c, c + size) A[i][j] = !A[i][j];
    }
    if(O == 2) {
      ll r; cin >> r; r--;
      REP(i, 0, N - 1) swap(A[r][i], A[r][i + 1]);
    }
    if(O == 3) {
      ll r; cin >> r; r--;
      for(ll i = N - 1; i > 0; i--) swap(A[r][i], A[r][i - 1]);
    }
    if(O == 4) {
      ll r, c; cin >> r >> c; r--; c--;
      REP(i, 0, N) REP(j, 0, N) used[i][j] = false;
      dfs(r, c, A[r][c]);
    }
  }

  REP(i, 0, N) REP(j, 0, N) cout << A[i][j] << (j + 1 != N ? " " : "\n");
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a[10],i;
 for(i=0;i<=9;i++)
    scanf("%d",&a[i]);
 sort(a,a+10);
 printf("%d\n%d\n%d\n",a[9],a[8],a[7]);
 return 0;
}

Measured memory_bytes: 3240
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

void sieveOfEratosthenes(long n,int a){
    if(n==1){
        cout << 2 << endl;
        return;
    }
    vector<long> v;
    F(i,1,n) v.push_back(i+1);
    long index=0;
    while(v[index]<=sqrt(n)){
        long x=v[index];
        while(x<=n){
            F(i,index+1,v.size()){
                if(v[i]%x==0){
                    v.erase(v.begin()+i);
                }
            }
            x*=v[index];
        }
        ++index;
    }
    F(i,0,v.size()){
        if(v[i]>=a){
            cout << v[i] << endl;;
            break;
        }
    }
}

int main(){
    long n=1e5+5;
    int a;
    cin >> a;
    sieveOfEratosthenes(n,a);
    return 0;
}

Measured memory_bytes: 1400
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));

		String str =  br.readLine();

		int s = Integer.parseInt(str);

		int h = s / 3600;
		s = s - h * 3600;

		int m = s / 60;
		s = s - m * 60;

		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 24352
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PriorityQueue<Double> pq = new PriorityQueue<>();
		for(int i = 0; i < n; i++){
			pq.add(sc.nextDouble());
		}
		//System.out.println(pq.poll());
		//double sum = 0;
		double a,b,x;
		while(pq.size() != 1){
			a = pq.poll();
			b = pq.poll();
			x = (a + b) / 2;
			pq.add(x);
	}
		double ans = pq.peek();
	System.out.println(ans);
	}
	
	
	}

Measured memory_bytes: 25172
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class Main{
  public static void main(String[] args) throws IOException
  {
    FastScanner fs = new FastScanner();
    String moji = fs.next();
    String a = moji.substring(0,moji.length()-2);
    int i = (a.length()%2 ==0)? 0:1;
    String str,str1;
    for(;i<a.length();i+=2){
      str = a.substring(0,(a.length()-i)/2);
      str1= a.substring((a.length()-i)/2,a.length()-i);
      if(str.equals(str1)) break;
    }

    System.out.println(a.length()-i);
  }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21332
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


A, B, C, D = map(int, input().split())
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
c_d = B // lcm(C, D) - (A - 1) // lcm(C, D)
print(B - A + 1 - c - d + c_d)


Measured memory_bytes: 3060
x,y,a,b,c=map(int,input().split())
l_r=sorted(map(int,input().split()),reverse=True)[:x]
l_b=sorted(map(int,input().split()),reverse=True)[:y]
l_w=sorted(map(int,input().split()),reverse=True)

ans=[]
ans+=l_r
ans+=l_b
ans+=l_w

print(sum(sorted(ans,reverse=True)[:x+y]))

Measured memory_bytes: 23060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, m;
int a[20];

ll dp[1<<16][17];
ll fact[(1<<16) + 10]={1};
ll frev[(1<<16) + 10];
const ll mod=7+1e9;

ll Pow(ll b, ll e){
	ll r=1;
	while(e){
		if(e&1)(r*=b)%=mod;
		(b*=b)%=mod; e>>=1;
	}
	return r;
}

ll comb(ll n, ll r){
	if(n<0 || r<0 || n<r) return 0;
	return fact[n]*frev[r]%mod*frev[n-r]%mod;
}

int main()
{
	read(n, m);
	for(int i=1; i<=(1<<n); ++i) fact[i]=fact[i-1]*i%mod;
	frev[1<<n]=Pow(fact[1<<n], mod-2);
	for(int i=(1<<n); 1<=i; --i) frev[i-1]=frev[i]*i%mod;
	
	for(int i=0; i<m; ++i) read(a[i]);
	ll ans = 0;
	dp[0][m] = 1;
	for(int mask=1; mask<(1<<n); ++mask){
		int nokori = (1<<n) - 1 - mask;
		ll coeff = fact[nokori];
		for(int i=0; i<n; ++i){
			if(1 & (nokori >> i)){
				(coeff *= frev[1<<i]) %= mod;
			}
		}
		int parity = __builtin_popcount(mask) & 1;
		for(int me=0; me<m; ++me){
			for(int place=0; place<n; ++place){
				int used = (mask ^ (1<<place));
				for(int last=me+1; last<=m; ++last){
					(dp[mask][me] += dp[used][last] *
						comb((1<<n)-a[me] - used, (1<<place)-1)) %= mod;
				}
			}
			if(parity) (ans += coeff*dp[mask][me]) %= mod;
			else (ans += mod-coeff*dp[mask][me]%mod) %= mod;
		}
	}
	ll tot = fact[(1<<n)-1];
	for(int i=0; i<n; ++i) (tot *= frev[1<<i]) %= mod;
	ans = (tot - ans + mod) % mod;
	for(int i=0; i<n; ++i) (ans *= fact[1<<i]) %= mod;
	(ans *= (1<<n)) %= mod;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	int n, k, x, y;

	cin >> n >> k >> x >> y;

	int ans;
	if (n <= k) {
		ans = n * x;
	} else {
		ans = k * x + (n - k) * y;
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<double,double> PAIR;
const int N = 5e5+5;
const int INF = 0x3f3f3f3f;

int main()
{
	std::ios::sync_with_stdio(0);cin.tie(0);
	
	string s;
	cin >> s;
	int len = s.size();
	if(len == 6 && s[2] == s[3] && s[4] == s[5]) printf("Yes\n");
	else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e4+10;
const int M=1e2+10;
const int mod=1e9+7;
int n,a[N],d,dp[2][M][2],cur,ans;char s[N];
inline void Add(int &x,int y){x+=y;x-=x>=mod? mod:0;}
inline int MOD(int x,int y){x+=y;x-=x>=mod? mod:0;return x;}
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	for(register int i=1;i<=n;i++)a[i]=s[i]-'0';
	scanf("%d",&d);dp[cur][0][1]=1;
	for(register int i=1;i<=n;i++){
		cur^=1;memset(dp[cur],0,sizeof(dp[cur]));
		for(register int j=0;j<=d;j++){
			for(register int p=0;p<=9;p++)
				Add(dp[cur][j][0],dp[cur^1][(j-p+d*9)%d][0]);
			for(register int p=0;p<a[i];p++)
				Add(dp[cur][j][0],dp[cur^1][(j-p+d*9)%d][1]);
			Add(dp[cur][j][1],dp[cur^1][(j-a[i]+d*9)%d][1]);
		}
	}
	printf("%d\n",MOD(MOD(dp[cur][0][1],dp[cur][0][0]),mod-1));
	return 0;
}

Measured memory_bytes: 256
/******Old_school_@23******/
/******Why_would_a_compiler_lie?******/
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma") 
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back 
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()) 
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){ 
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){ 
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
      string s,t; cin>>s>>t;
      lld n=s.size();
      lld m=t.size();
      lld ans=0;
          for(lld j=0;j<=n-m;j++){
              lld p=0,q=j,pp=0;
              while(p<m){
                  if(s[q]==t[p]) pp++;
                  p++,q++;
              }
              ans=max(ans,pp);
          }
     
      cout<<m-ans<<endl;
}


Measured memory_bytes: 3656
def main():
    from heapq import heappop as hpop
    from heapq import heappush as hpush
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    h = []
    for i in range(n):
        hpush(h, (-b[i], i))
    cnt = 0
    while h:
        i, j = hpop(h)
        i = -i
        jj = (j+1) % n
        temp = i-a[j]
        temp2 = b[j-1]+b[jj]
        sho = temp//temp2
        if sho == 0:
            if temp:
                print(-1)
                return 0
            continue
        cnt += sho
        b[j] -= temp2*sho
        hpush(h, (-b[j], j))
    print(cnt)
main()

Measured memory_bytes: 123804
A=int(input())
B=int(input())
if(A==1):
  if(B==2):
    print(3)
  else:
    print(2)
elif(A==2):
  if(B==1):
    print(3)
  else:
    print(1)
else:
  if(B==1):
    print(2)
  else:
    print(1)
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n;
bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p%i == 0) return false;
	}
	return true;
}
int main() {
	cin >> n;
	for (int i = 31; i <= 55555; i += 30) {
		if (isprime(i) == true) {
			if (i != 31) cout << " ";
			cout << i; 
			n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}

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

const int mxN = 105;
vector<int> adj[mxN];

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 0; i < n; ++i)
		adj[(int)s[i]].push_back(i);
	long long tot = 0;
	vector<int> :: iterator it;
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(s[i] != s[j]) {
				char c;
				for(char x : {'R', 'G', 'B'}) {
					if(x == s[i] || x == s[j])
						continue;
					c = x;
				}
				it = upper_bound(adj[(int)c].begin(), adj[(int)c].end(), j);
				if(it != adj[(int)c].end()) {
					tot += ((int)adj[(int)c].size() - (it - adj[(int)c].begin())) - 
					binary_search(adj[(int)c].begin(), adj[(int)c].end(), j + (j - i));
				}
			}	
		}
	}
	cout << tot;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    while(sc.hasNext()) {
      final long a = sc.nextInt();
      final long b = sc.nextInt();

      System.out.println(a + b);
    }
  }

  private final Scanner sc = new Scanner(System.in);
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
	long W, H;
	cin >> H >> W;
	
  	if(W == 1|| H == 1) cout << 1 << endl; else
	cout << (H * W + 1) / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 256
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var Lucas = new ulong[num+1];
        Lucas[0] = 2;
        Lucas[1] = 1;
        for(var i = 2; i <= num; i++)
        {
            Lucas[i] = Lucas[i - 1] + Lucas[i - 2];
        }
        WriteLine(Lucas[num]);
    }
}

Measured memory_bytes: 13268
#include<stdio.h>

int main(){
  int r;
  int s;
  int i;
  
  scanf("%d", &r);
  
  for(i = 1; i < 1000000; i++){
    s = r*i;
    if ( s%360 == 0 ){
      printf("%d", i);
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1684
import sys
input = sys.stdin.readline
N, A, B = [int(x) for x in input().strip().split()]
X = [int(x) for x in input().strip().split()]
p = X[0]
ans = 0
for x in X[1:]:
    c = (x - p) * A
    if c <= B:
        ans += c
    else:
        ans += B
    p = x
print(ans)

Measured memory_bytes: 14480
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=3e6;
const int mo=1e9+7;
int p[maxn],id,maxx,cl,sl;
char c[maxn],s[maxn];
void init(){
   s[0]='$';
   s[1]='#';
   int i;
   cl=strlen(c);
   for (i=0;i<cl;i++){
    s[2*i+2]=c[i];
    s[2*i+3]='#';
   }
   sl=cl*2+2;
   s[sl]='*';
}

void manacher(){
  int i;
  maxx=0;p[0]=1;id=0;
  for (i=1;i<sl;i++){
    if (i<=maxx) p[i]=min(maxx-i+1,p[2*id-i]);
    else p[i]=1;
    for (;s[i+p[i]]==s[i-p[i]];p[i]++);
    if (maxx<i+p[i]-1) {
        maxx=i+p[i]-1;
        id=i;
    }
  }
}

long long h[26];
int main()
{
    int i,j;
    long long ans;
    while (scanf("%s",c)!=-1){
        init();
        manacher();
        ans=1ll*cl*(cl-1)/2+1;
        memset(h,0,sizeof(h));
        for (i=0;i<cl;i++) h[c[i]-'a']++;
        for (i=0;i<26;i++) ans-=h[i]*(h[i]-1)/2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 6784
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextInt();
		double b = sc.nextInt();
		double ave = (a + b) / 2;
		double upave = Math.ceil(ave);
		int ans = (int)upave;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
from collections import deque
h, w = map(int, input().split())
n = h*w


def to_v(i, j):
    return i*w+j


init_vs = []
for i in range(h):
    for j, x in enumerate(input()):
        if x == '#':
            init_vs.append(to_v(i, j))


INF = 10**18
dist = [INF]*n
for v in init_vs:
    dist[v] = 0


def generate_v2(v):
    i, j = divmod(v, w)
    if 0 < i:
        yield v-w
    if i < h-1:
        yield v+w
    if 0 < j:
        yield v-1
    if j < w-1:
        yield v+1


def bfs(init_vs):
    next_v = deque([*init_vs])
    while next_v:
        v = next_v.popleft()
        for v2 in generate_v2(v):
            if dist[v2] <= dist[v]+1:
                continue
            dist[v2] = dist[v]+1
            next_v.append(v2)


bfs(init_vs)
print(max(dist))

Measured memory_bytes: 160004
#include<stdio.h>
int main(void){
	char s[3];
	int i,b=0;
	for(i=0;i<3;i++){
		scanf("%c",&s[i]);
		if(s[i]=='1'){
			b++;
		}
	}
	printf("%d\n",b);
	return 0;		
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,t=MI()
    aa=LI()
    mn=10**10
    pp=[]
    for a in aa:
        pp.append(a-mn)
        mn=min(mn,a)
    #print(pp)
    ans=pp.count(max(pp))
    print(ans)

main()

Measured memory_bytes: 14624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

bool checkValidity(int a, int b, int c) 
{ 
    if (a + b <= c || a + c <= b || b + c <= a) 
        return false; 
    else
        return true; 
} 

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

    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    
    int count=0;

    for (int i = 0; i < n-2; i++)
    {
        for (int j = i+1; j < n-1; j++)
        {
            if(a[i]==a[j]) continue;
            for (int k = j+1; k < n; k++)
            {
                if(a[i]==a[k] || a[j]==a[k]) continue;
                count+=checkValidity(a[i],a[j],a[k]);
            }
            
        }
        
    }
    
    cout<<count<<endl;
}

int main()
{
    IOS;
    ll t=1; //cin>>t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> input(H);
  for(int i=0; i<H; i++){
  	cin >> input[i];
  }
  
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  
  for(int i=0; i<H; i++){
  	for(int j=0; j<W; j++){
    	if(input[i][j] == '#'){
        	row[i] = true;
          	col[j] = true;
        }
    }
  }
  
  for(int i=0; i<H; i++){
  	if(row[i]){
    	for(int j=0; j<W; j++){
        	if(col[j]) cout << input[i][j];
        }
        cout << endl;
    }
  }
  
}

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

int main(int argc, char const *argv[]) {
  char ch;
  while(1){
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch)) printf("%c", toupper(ch));
      else printf("%c", tolower(ch));
    } else {
      printf("%c", ch);
    }
    if (ch == '\n') break;
  }
  return 0;
}

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

int main(){
  
  int ans = 0;
  string s;
  
  cin >> s;
  
  for(int i = 0;i < 4;i++){
    if(s[i] == '+') ans++;
    if(s[i] == '-') ans--;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct node{
    int key;
    struct node *next;
    struct node *prev;
};
 
typedef struct node * NodePointer;
NodePointer finditem(int);
void listprint(void);
NodePointer make_1node(int,NodePointer);
void deleteFirst(void);
void deleteLast(void);
void deleteNode(NodePointer);
NodePointer head;
 
int main(void){
    int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
    if ( com[6] == 'F' ) deleteFirst();
    else if ( com[6] == 'L' ) deleteLast();
      } else {
    delete(key); nd++;
      }
      size--;
    }
  }
    
  listprint();
  return 0;
}
 
NodePointer finditem(int key){
  NodePointer x;
  x = head->next;
  while(x != head && x->key != key){
    x = x->next;
  }
  return x;
}
 
void insert(int key){
  NodePointer y;
  y = malloc(sizeof(struct node));
  y->key = key;
  y->next = head->next;
  head->next->prev = y;
  head->next = y;
  y->prev = head;
    
}
 
void listprint(){
  NodePointer cur = head->next;
  int isf = 1;
  while(1){
    if ( cur == head ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
 
void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
  
void deleteFirst(){
  NodePointer t = head->next;
  if ( t == head ) return;
  deleteNode(t);
}
  
void deleteLast(){
  NodePointer t = head->prev;
  if ( t == head ) return;
  deleteNode(t);
}
  
void delete(int key){
  NodePointer k;
  k=finditem(key);
  if(k == head) return;
    
  deleteNode(k);
    
}
void init(){
  head = malloc(sizeof(struct node));
  head->next = head;
  head->prev = head;
}

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

const int MAX_N = 2 * 1e5 + 2;

int A[MAX_N];
int cnt[MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<int> ans;
    for (int i = N - 1; i >= 0; i--) {
        if ((A[i] == 0 && cnt[i] % 2 == 1) || (A[i] == 1 && cnt[i] % 2 == 0)) {
            ans.push_back(i + 1);
            for (int j = 1; j * j <= i + 1; j++) {
                if ((i + 1) % j) continue;
                cnt[j - 1]++;
                if (j * j != i + 1) {
                    cnt[((i + 1) / j) - 1]++;
                }
            }
        }
    }
    for (int i = 0; i < N; i++) {
        if (cnt[i] % 2 != A[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " \n"[i == ans.size() - 1];
    return 0;
}

Measured memory_bytes: 3192
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

int main() {
    int n;
    unordered_map<int, int> as, bs;
    int aCount, bCount;
    aCount = bCount = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (i % 2 == 0) {
            if (as.find(a) == as.end()) {
                as[a] = 0;
            }

            as[a]++;
            aCount++;
        } else {
            if (bs.find(a) == bs.end()) {
                bs[a] = 0;
            }
            bs[a]++;
            bCount++;
        }
    }

    int aMax, aSecondMax, bMax, bSecondMax;
    int aMaxI, aSecondMaxI, bMaxI, bSecondMaxI;
    aMax = aSecondMax = bMax = bSecondMax = 0;
    for (auto aPair : as) {
        if (aPair.second > aSecondMax) {
            aSecondMax = aPair.second;
            aSecondMaxI = aPair.first;

            if (aSecondMax > aMax) {
                swap(aMax, aSecondMax);
                swap(aMaxI, aSecondMaxI);
            }
        }
    }

    for (auto bPair : bs) {
        if (bPair.second > bSecondMax) {
            bSecondMax = bPair.second;
            bSecondMaxI = bPair.first;

            if (bSecondMax > bMax) {
                swap(bMax, bSecondMax);
                swap(bMaxI, bSecondMaxI);
            }
        }
    }

    int ans;
    if (aMaxI != bMaxI) {
        ans = (aCount - aMax) + (bCount - bMax);
    } else {
        if (as.size() < 2 && bs.size() < 2) {
            ans = bCount;
        } else if (as.size() < 2) {
            ans = min(aCount + (bCount - bMax), bCount - bSecondMax);
        } else if (bs.size() < 2) {
            ans = min(bCount + (aCount - aMax), aCount - aSecondMax);
        } else {
            ans = min((aCount - aMax) + (bCount - bSecondMax),
                (aCount - aSecondMax) + (bCount - bMax));
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4200
#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)
using LL = long long;
using ULL = unsigned long long;

const int mod = 1000000007;

LL gcd(LL x, LL y) {
	return y ? gcd(y, x%y) : x;
}

int a[200123], b[200123];

int main()
{
    int n;
    cin >> n;
    rep(i, n) scanf("%d%d", a+i, b+i);
    sort(a, a+n); sort(b, b+n);
    int ans = n % 2 ? b[n/2]-a[n/2]+1 : (LL)b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1;
    printf("%d\n", ans);
}


Measured memory_bytes: 5324
// 2013/07/26 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int m;
		cin >> m;

		if(m==0)
			break;

		int n;
		cin >> n;

		int d[252] = {0};
		for(int i=1; i<=n; i++){
			cin >> d[i];
		}
/*
		for(int i=0; i<n+2; i++){
			cout << d[i] << ' ';
		}
		cout << endl;
*/
		bool G[252][252];
		for(int i=0; i<n+2; i++){
			for(int j=0; j<n+2; j++){
				if(i==j){
					G[i][j] = true;
				}
				else{
					G[i][j] = false;
				}
			}
		}

		for(int i=0; i<=n; i++){
			for(int j=1; j<=m; j++){
				int k = i+j;

				if(k>=n+1){
					G[i][n+1] = true;
					break;
				}

				int l = k+d[k];

				G[i][l] = true;
			}
		}

		for(int k=0; k<n+2; k++){
			for(int i=0; i<n+2; i++){
				for(int j=0; j<n+2; j++){
					if(G[i][k] && G[k][j]){
						G[i][j] = true;
					}
				}
			}
		}

		bool flg = true;

		for(int i=0; i<=n; i++){
			if(G[0][i] && !G[i][n+1]){
				flg = false;
				break;
			}
		}

		if(flg){
			cout << "OK" << endl;
		}
		else{
			cout << "NG" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
#include<set>
using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	if (y > x) swap(x, y);
	int r;
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	cout << x << endl;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int a;
    int b;
}no[100010];
int cmp(node n,node m)
{
    return n.a==m.a ? n.b>m.b : n.a<m.a;
}
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&no[i].a,&no[i].b);
        sort(no,no+n,cmp);
        int idx=0;
        long long int sum=0;
        while(m)
        {
            if(m>no[idx].b)
            {
                sum+=(long long)(no[idx].a)*(long long)(no[idx].b);
                m-=no[idx].b;
            }
            else
            {
                sum+=(long long)(no[idx].a)*(long long)m;
                m=0;
            }
            idx++;
        }
        printf("%lld\n",(long long)sum);
    }
    return 0;
}


Measured memory_bytes: 1024
import util.control.Breaks._

object Main extends App {
  val n = io.StdIn.readLine().toInt
  val testimony = Array.fill(n)(Array.fill(n)(-1))
  var max = 0

  for (i <- 0 until n) {
    val a = io.StdIn.readLine().toInt
    for (_ <- 0 until a) {
      val Array(x, y) = io.StdIn.readLine().split(' ').map(_.toInt)
      testimony(i)(x-1) = y
    }
  }

  for (b <- 0 until 1 << n) {
    breakable {
      var count = 0
      for (i <- 0 until n; if (b & (1 << i)) != 0) {
        testimony(i).indices.withFilter(testimony(i)(_) != -1).foreach {j =>
          val x = (1 << j) & b
          if (testimony(i)(j) == 1 && x == 0) break()
          if (testimony(i)(j) == 0 && x != 0) break()
        }
        count += 1
      }
      if (max < count) max = count
    }
  }

  println(max)
}

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

using namespace std;
void solve()
{
   string s,t;
   cin>>s>>t;
   int ans = 0;
   for(int i=0;i<s.length();++i)
   {
       if(s[i]==t[i])continue;
       else ans++;
   }
   cout<<ans;
}
int main()
{
    
    size_t  t;
    t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
   return 0;
}



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


void solve(long long N){
    cout<<1.0*(double)(N-N/2)/(double)N<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#$time_i = 0
#$time_e = 0
class Maximum
  def initialize(arr = [nil])
    @arr = arr
    @size = 0
  end
  def insert(key)
    #start = Time.now
    @arr[i = @size += 1] = key = key.to_i
    while i / 2 >= 1 and @arr[i / 2] < key
      @arr[i] = @arr[i / 2]
      i /= 2
    end
    @arr[i] = key
    #p @arr[1..@size]
    #$time_i += Time.now - start
  end
  def extract
    #start = Time.now
    puts @arr[1]
    @arr[i = 1] = @arr[@size]
    while i * 2 < @size and @arr[(@arr[i * 2] > @arr[i * 2 + 1]) ? (t = i * 2) : (t = i * 2 + 1)] > @arr[@size]
      @arr[i] = @arr[t]
      i = t
    end
    @arr[i] = @arr[@size]
    @size -= 1
    #p @arr[1..@size]
    #$time_e += Time.now - start
  end
  def to_s
    @arr.join(" ")
  end
end
def main(input = STDIN)
  heap = Maximum.new
  while (order = input.gets.chomp) != "end"
    heap.send(*order.split(" "))
  end
  #p [$time_i, $time_e]
end
#main(f = File.open('input2.txt'))
#f.close
main

Measured memory_bytes: 14032
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toInt()
    var arr = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
    var count = 0

    for(i in 0..arr.lastIndex)
    {
        for(j in i+1..arr.lastIndex)
        {
            for(k in j+1..arr.lastIndex)
            {
                var a = arr[i]
                var b = arr[j]
                var c = arr[k]

                if(arr[i]!= arr[j] && arr[j]!=arr[k] && arr[k]!=arr[i])
                {
                   if ((a + b <= c) || (a + c <= b) || (b + c <= a)) {


                   }
                    else
                       count++
                }
            }

        }
    }
    println(count)
}


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

using namespace std;

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

    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if ((i & 1) && (x & 1))
            ans++;
    }
    cout << ans;

    return 0;
}


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

int main(void){
    string s;
    cin >> s;
    if(s == "MON")cout << 6;
    else if(s == "TUE")cout << 5;
    else if(s == "WED")cout << 4;
    else if(s == "THU")cout << 3;
    else if(s == "FRI")cout << 2;
    else if(s == "SAT")cout << 1;
    else cout << 7;
    cout << endl;
    
}

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

using namespace std;

map<string, int> mp;

int main() {
    int n;
    cin >> n;
    string tmp;
    while (n--) {
        cin >> tmp;
        mp[tmp]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=200005;

ll tab[N];

ll dac(int a,int b,ll K);

 int main()
 {
	ll n,K,i;
	scanf("%lld%lld",&n,&K);

	for(i=1;i<=n;i++)
	{
		scanf("%lld",&tab[i]);
	}

	printf("%lld\n",dac(1,n,K));
 }
//////
 ll dac(int a,int b,ll K)
 {
	if(a==b) 
	{
		if(tab[a]>=K) return 1;
		return 0;
	}
	 
	int v;
	v=(a+b)/2;
	ll wn,sm;
	wn=dac(a,v,K);
	wn+=dac(v+1,b,K);

	vector<ll> srt;
	sm=0;
	
	for(int i=v;i>=a;i--)
	{
		sm+=tab[i];
		srt.push_back(sm-K*(v-i+1));
	}		

	sort(srt.begin(),srt.end());

	sm=0;
	for(int i=v+1;i<=b;i++)
	{
		sm+=tab[i];
		auto z=lower_bound(srt.begin(),srt.end(),(i-v)*K-sm);
		wn+=distance(z,srt.end());
	}

	return wn;
 } 


Measured memory_bytes: 3348
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000

struct Info{
	int M,L,K;
};

struct Data{
	Data(int arg_next_free_time){
		next_free_time = arg_next_free_time;
	}
	bool operator<(const struct Data &arg) const{
		return next_free_time > arg.next_free_time;
	}
	int next_free_time;
};

int N,T;
Info info[NUM];
bool check[NUM];

bool is_ok(int num){

	priority_queue<Data> Q;
	for(int i = 0; i < num; i++)Q.push(0);

	for(int i = 0; i < N; i++)check[i] = false;
	int count = 0,current_time,id,tmp,min_time,next_time;

	bool FLG;

	while(!Q.empty()){

		current_time = Q.top().next_free_time;
		Q.pop();

		min_time = BIG_NUM;
		FLG = false;

		for(int i = 0; i < N; i++){
			if(check[i])continue;

			tmp = current_time%(info[i].K+info[i].L);
			if(tmp >= 0 && tmp <= info[i].L){
				id = i;
				FLG = true;
				break;

			}else{
				if(min_time > current_time+(info[i].K+info[i].L)-current_time%(info[i].K+info[i].L)){
					min_time = current_time+(info[i].K+info[i].L)-current_time%(info[i].K+info[i].L);
					id = i;
				}
			}
		}
		if(FLG){

			next_time = current_time+info[id].M;

		}else{

			next_time = min_time+info[id].M;
		}
		if(next_time > T)return false;

		count++;
		if(count == N)return true;
		check[id] = true;
		Q.push(next_time);
	}
	return false;
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%d %d %d",&info[i].M,&info[i].L,&info[i].K);
	}

	for(int i = 1; i <= N; i++){
		if(is_ok(i)){
			printf("%d\n",i);
			return;
		}
	}
}

int main(){

	while(true){
		scanf("%d %d",&N,&T);
		if(N == 0 && T == 0)break;

		func();
	}
	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vll;
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define srt(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define mod 1000000007
#define pi 3.1415926535
lld a,b,c,d,e,f,g,h,i,j,k=0,l=0,m=1,n=1,o,q=0,r=0,u,v,w,x,y,z,s,t,p=0;
lld temp=0,ans=0;
double f1,f2,f3,f4,f5,f6;
char c2,c3,c4,c5,c6;
vll v11;
pair<lld,lld>p1,p2,p3;
map<lld,lld>mv;bool a12[200005],a13[200005];
bool b11[500006],c11[500006];lld a11[500006];
lld gcd(lld a, lld b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}
void dfs(lld i,vector<lld>vg[])
{
    if(b11[i]==true)    return;
    v11.pb(i);
    p++;
    b11[i]=true;
    for(auto x11:vg[i])
    {
        if(b11[x11]==false)
        {
            dfs(x11,vg);
        }
    }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  t=1;
  //cin>>t;
  while(t--)
  {
    string s3,s1,s2;
    cin>>s1;
    //lld p1,q1,a1,b1,c1,d1;
    //lld a1[n+1]={0},b1[n],c1[n+1];vector<lld>vg[n+1];
    map<lld,lld>m1,m2;queue<lld>q2;vll v1,v2;
    n=s1.size();
    p=0;
    for(i=0;i<n;i++)
    {
        p=p+int(s1[i]-'0');
    }
    if((p%9)==0)    cout<<"Yes";
    else    cout<<"No";
    cout<<endl;
  }
  return 0;
}

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

int main() {
    int A,B;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> A >> B ;
    // cout << A << " " << B << endl;

    int i;
    for(i=0; i <= 1200; i++){
        int a,b;
        a = (int)(i * 8 / 100); 
        b = (int)(i * 10 / 100);
        if (a == A & b == B){
            cout << i << endl;
            exit(0);
        }
    }
    cout << "-1" << endl;
}


Measured memory_bytes: 256
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int cnt = 0;
    REP(i, N / R + 1)
    {
        REP(j, (N - i * R) / G + 1)
        {
            if ((N - R * i - G * j) % B == 0)
                cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
// AtCoder AGC013 A - Sorted Arrays
// 2020.1.22 bal4u

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#if 1
//int getchar_unlocked(void);
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int a = 0, f = 0;
	int ans = 1;
	int N = in();
	while (N--) {
		int A = in();
		if (a > 0) {
			if (a < A) {
				if (f < 0) a = 0, f = 0, ans++;
				else f = 1;
			} else if (a > A) {
				if (f > 0) a = 0, f = 0, ans++;
				else f = -1;
			}
		}
		a = A;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
program probc
    implicit none
    integer::i,j,k,N
    integer(16)::ans,v(5)
    character(len=10)::S
    character::c(5) = (/"M","A","R","C","H"/)

    read(*,*) N
    v = 0
    do i = 1, N
        read(*,*) S
        do j = 1,5
            if(S(1:1) .eq. c(j)) then
                v(j) = v(j) + 1
            end if
        end do
    end do

    ans = 0
    do i = 1,3
        do j = 2,4
            do k = 3,5
                if(i < j .and. j < k)then
                    ans = ans + v(i)*v(j)*v(k)
                end if
            end do
        end do
    end do

    write(*,*) ans
    stop
end program

Measured memory_bytes: 2828
import math

N, D = (map(int, input().split()))
X = []
output = 0

for i in range(N):
	X.append(list(map(int, input().split())))
	
for i in range(N - 1):
	for j in range(i + 1, N):
		# X[i]とX[j]の距離を求める
		tmp = 0
		for k in range(D):
			tmp += (X[i][k] - X[j][k]) ** 2
		if math.sqrt(tmp) - int(math.sqrt(tmp)) == 0:
			output += 1
			
print(output)

Measured memory_bytes: 38404
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100
#define MAX_M 100
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N, M, X, Y;

int main(void)
{
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  REP(i, N) cin >> x[i];
  REP(i, M) cin >> y[i];

  int xmax = *max_element(x.begin(), x.end());
  int ymin = *min_element(y.begin(), y.end());

  int d = (ymin - xmax);
  int Z = xmax + d;
  if (d >= 1 && (X < Z && Z <= Y) && xmax < Z && Z <= ymin) {
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
  return 0;
}


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

using namespace std;

int n,a[Nmax];
long long sum;

int main()
{
    int i;
    //ifstream cin("boxes.in");
    //ofstream cout("boxes.out");
    cin>>n;
    for(i=1;i<=n;++i)
    {
        cin>>a[i]; sum+=a[i];
    }
    if(sum % (1LL*n*(n+1)/2))
    {
        cout<<"NO\n"; return 0;
    }

    long long x = sum / (1LL*n*(n+1)/2);
    sum=0;

    for(i=1;i<=n;++i)
        if(a[i]<x)
        {
            cout<<"NO\n"; return 0;
        }

    for(i=2;i<=n;++i)
    {
        if((x-a[i]+a[i-1])%n)
        {
            cout<<"NO\n"; return 0;
        }
        sum+=(x-a[i]+a[i-1])/n;
    }

    if((x-a[1]+a[n])%n)
    {
        cout<<"NO\n"; return 0;
    }
    sum+=(x-a[1]+a[n])/n;

    if(sum!=x)
    {
        cout<<"NO\n"; return 0;
    }

    cout<<"YES\n";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
//set<int>::iterator it
using namespace std;
typedef long long ll;
int n,m,vis[110],sum4,sum1;
char mp[110][110];
int main()
{
    scanf("%d%d",&n,&m);
    int flag=0;
    ff(i,1,n)
    {
        scanf("%s",mp[i]+1);
        ff(j,1,m)
        vis[mp[i][j]-'a']++;
    }
    ff(i,0,25)
    {
        if(vis[i]%2==0)
        sum4+=vis[i]/4;
        else if(vis[i]%2)
        {
            sum1++;
            sum4+=vis[i]/4;
        }
    }
    if(n%2==0&&m%2==0)
    {
        if(n*m/4==sum4)
            printf("Yes\n");
        else
        printf("No\n");
    }
    else if(n%2&&m%2)
    {
        if(sum1<=1&&sum4>=(n*m-n-m+1)/4)
            printf("Yes\n");
        else
        printf("No\n");
    }
    else
    {
        int kk=n*m;
        if(n%2)
            kk-=m;
        else
            kk-=n;
        if(sum1==0&&kk/4<=sum4)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
num=[0 for i in range(10**5+1)]
for i in range(n):
    num[a[i]] += 1
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += b_num
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)

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

int main (){
	int h;
	while(cin>>h && h){
		vector<vector<int>> v(h,vector<int>(5));
		for(int i=0;i<h;i++)for(int j=0;j<5;j++)cin>>v[i][j];//入力
		int ans=0;
		while(1){
			int flag=true; //消す石があったらtrueのまま
			//３個以上並ぶところを消す処理
			for(int i=0;i<h;i++){
				int chain; //同じ数字が並ぶ数
				for(int j=0;j<5;j++){
					chain=1;
					while(j+1<5 && v[i][j]!=-1 && v[i][j]==v[i][j+1]){
						chain++;
						j++;
					}
					if(chain>=3){ //3つ以上並んでいたら
						flag=false;
						ans+=chain*v[i][j];
						for(int k=0;k<chain;k++){ //その部分を-1に変える
							v[i][j-chain+k+1]=-1;
						}
						break;
					}
				}
			}
			if(flag)break; //消す石が無かったなら終了

			//石の落下処理。配列を縦に回す
			for(int p=0;p<h;p++){
				for(int i=0;i<5;i++){
					for(int j=h-1;j>=1;j--){
						if(v[j][i]==-1){
							for(int k=j;k>=1;k--)swap(v[k][i],v[k-1][i]);
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18;
const int MAX_B=45;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A; cin >> N >> A;
    ll ans=N;
    for (int i=0;i<MAX_B;++i){
        ll ub=N,lb=1;
        while(ub-lb>1){
            ll mid=(ub+lb)>>1LL,prod=1;
            int ok=0;
            for (int j=0;j<i+1;++j){
                if (prod>=INF/mid){ok=1; break;}
                prod*=mid;
            }
            if (prod>=N) ok=1;
            (ok?ub:lb)=mid;
        }
        ll prod=1,sum=0;
        for (int j=0;j<i+1;++j) prod*=ub,sum+=ub;
        for (int j=0;j<i+1;++j){
            if (prod/ub*(ub-1)>=N){
                (prod/=ub)*=ub-1;
                --sum;
            } else break;
        }
        ans=min(ans,A*i+sum);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7;

//const int maxn=

ll int gcd(ll int a,ll int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}

inline bool judge(ll int num)
{
	ll int j=(ll int)sqrt(num);
	for(ll int i=2;i<=j;i++)
		if(num%i==0)
			return false;
	return true;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    ll int a,b;
    
    cin>>a>>b;
    
    ll int yue=gcd(a,b);
    
    //cout<<yue<<endl;
    
    ll int j=(ll int)sqrt(yue);
    
    vector<ll int>v;
    
    for(ll int i=1;i<=j;i++)
    {
    	if(yue%i==0)
    	{
    		v.push_back(i);
    		
    		if(i*i!=yue)
    			v.push_back(yue/i);
		}
	}
	
	sort(v.begin(),v.end());
	
	/*
	dd;
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<" ";
	dd;
	*/
	
	vector<ll int>v1;
	vector<ll int>v2;
	
	int cnt=0;
	
	for(int i=0;i<v.size();i++)
	{
		if(judge(v[i]))
		{
			v1.push_back(v[i]);
			cnt++;
		}
		else
		{
			v2.push_back(v[i]);
		}
	}
	
	for(int i=0;i<v2.size();i++)
	{
		int flag=0;
		for(int j=0;j<v1.size();j++)
		{
			if(gcd(v2[i],v1[j])!=1)
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		{
			cnt++;
			v1.push_back(v2[i]);
		}
	}
	
	cout<<cnt<<endl;
	
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    vector<string> g(100);
    for(int i = 0; i < 100; i++) {
        string tmp = "";
        if(i < 50) {
            for(int j = 0; j < 100; j++) {
                tmp += "#";
            }
        } else {
            for(int j = 0; j < 100; j++) {
                tmp += ".";
            }
        }
        g[i] = tmp;
    }
    int h = 0, w = 1;
    while(a - 1 > 0) {
        if(w == 99) {
            h += 2;
            w = 1;
        }
        g[h][w] = '.';
        w += 2;
        a--;
    }
    h = 51, w = 1;
    while(b - 1 > 0) {
        if(w == 99) {
            h += 2;
            w = 1;
        }
        g[h][w] = '#';
        w += 2;
        b--;
    }
    cout << "100 100" << endl;
    for(int i = 0; i < 100; i++) {
        cout << g[i] << endl;
    }
}

Measured memory_bytes: 256