akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    ll K, N;
    cin >> K >> N;
    vi vec(N);
    for(int i=0; i<N; i++){
        cin >> vec[i];
    }
    ll max = vec[1]-vec[0];
    for(int i=1; i<N-1; i++){
        if(vec[i+1] - vec[i] > max){
            max = vec[i+1] - vec[i];
        }
    }
    if(vec[0] + (K-vec[N-1]) > max){
        max = vec[0] + (K-vec[N-1]);
    }
    cout << K - max;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

vec l(1e5+5),r(1e5+5),w(1e5+5);

int main() {
  ll n;
  cin >> n;
  for(ll i=1;i<=n;i++) {
    ll tmp;
    cin >> tmp;
    w[tmp]=i;
    l[i]=i-1;
    r[i]=i+1;
  }
  ll ans=0;
  for(ll i=1;i<=n;i++) {
    ll b=l[w[i]],a=l[b];
    ll c=r[w[i]],d=r[c];
    if(b!=0) ans+=1LL*(b-a)*(c-w[i])*i;
    if(c!=n+1) ans+=1LL*(d-c)*(w[i]-b)*i;
    l[c]=b;
    r[b]=c;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	hs := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&hs[i])
	}

	ans := 0
	tmp := 0
	for i := 0; i < n-1; i++ {
		if hs[i] >= hs[i+1] {
			tmp++
		} else {
			ans = max(ans, tmp)
			tmp = 0
		}
	}
	fmt.Println(max(ans, tmp))
}

func max(x, y int) int {
	if x < y {
		return y
	}
	return x
}


Measured memory_bytes: 5504
#include<iostream>
#include<cstdio>
using namespace std;
int n,sum;
int a[100001];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			sum+=(a[i]*a[j]);
		}
	}
	cout<<sum;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let N = parseInt(input[0][0], 10);
    let W = parseInt(input[0][1], 10);
    let arr_wv = [];
    for (let i = 0; i < N; i++){
        arr_wv.push(input[i + 1].map(e => parseInt(e, 10)));
    }
    
    let DP = [Array.from({length: W + 1}, () => 0)];
    let tmpline;
    for (let i = 0; i < N; i++){
        tmpline = arr_wv[i];
        DP.push([]);
        for (let j = 0; j < tmpline[0]; j++){
            DP[i + 1].push(DP[i][j]);
        }
        for (let j = tmpline[0]; j <= W; j++){
            DP[i + 1].push(Math.max(DP[i][j], DP[i][j - tmpline[0]] + tmpline[1]));
        }
    }

    console.log(DP.pop().pop());
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 165828
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

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

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

using ll = long long;

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

const int INF = 1LL<<29;

//#define __DBG__

int N, K, R, S, P;
string T, MY;


void solve(void){
  
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;
  
  int M=0;
  
  MY="";
      
  REP(i,K){
    if(T[i]=='r'){MY=MY+'P'; M += P;}
    if(T[i]=='s'){MY=MY+'R'; M += R;}
    if(T[i]=='p'){MY=MY+'S'; M += S;}
  }
  
  REP2(i,K,N){
     if(T[i]=='r'){
       if(MY[i-K]!='P'){
         MY=MY+'P'; M += P;
       }
       else
       {
         if(i+K>=N){
           MY=MY+'S'; //0
         }
         else
         {
           if(T[i+K]=='r'){
             MY=MY+'S'; //0
           }
           if(T[i+K]=='s'){
             MY=MY+'S'; //0
           }
           if(T[i+K]=='p'){
             MY=MY+'R'; //0
           }
         }
       }
     }

     if(T[i]=='s'){
       if(MY[i-K]!='R'){
         MY=MY+'R'; M += R;
       }
       else
       {
         if(i+K>=N){
           MY=MY+'S'; //0
         }
         else
         {
           if(T[i+K]=='r'){
             MY=MY+'S'; //0
           }
           if(T[i+K]=='s'){
             MY=MY+'S'; //0
           }
           if(T[i+K]=='p'){
             MY=MY+'P'; //0
           }
         }
       }
     }
       
     if(T[i]=='p'){
       if(MY[i-K]!='S'){
         MY=MY+'S'; M += S;
       }
       else
       {
         if(i+K>=N){
           MY=MY+'P'; //0
         }
         else
         {
           if(T[i+K]=='r'){
             MY=MY+'R'; //0
           }
           if(T[i+K]=='s'){
             MY=MY+'P'; //0
           }
           if(T[i+K]=='p'){
             MY=MY+'R'; //0
           }
         }
       }
     }
  }
  
  cout << M << endl;
  
  
  return;
}

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


    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}





Measured memory_bytes: 1056
const binarySearch = (key, arr, N) => {
  let mid;
  let left = 0;
  let right = N;
  if (key < arr[0] || arr[N-1] < key) return 0;
  while (left < right) {
    mid = Math.floor((left + right) / 2);
    if (key < arr[mid]) right = mid;
    else if (key > arr[mid]) left = mid + 1;
    else return 1;
  }
  return 0;
}


(function() {
  const input = require('fs').readFileSync('/dev/stdin', 'utf8');
  const Arr = (input.trim()).split("\n");
  const N1 = Number(Arr[0]);
  const arr1 = Arr[1].split(" ").map(Number);
  // const N2 = Number(Arr[2]);
  const arr2 = Arr[3].split(" ").map(Number);
  console.log(arr2.map(e => binarySearch(e, arr1, N1)).reduce((a, b) => a + b, 0));
})();



Measured memory_bytes: 34916
#include <stdio.h>
int main(void){
    // Your code here!
    int N,K;
    char s[100];
    scanf("%d%d",&N,&K);
    scanf("%s",s);
    if(s[K-1]=='A'){
       s[K-1]='a'; 
    }else if(s[K-1]=='B'){
       s[K-1]='b'; 
    }else if(s[K-1]=='C'){
        s[K-1]='c';
    }
    printf("%s",s);
}
//https://atcoder.jp/contests/abc126/tasks/abc126_a


Measured memory_bytes: 128
N,M=map(int,input().split())
A=[[] for _ in range(N+1)]
for _ in range(M):
    a,b=map(int,input().split())
    A[a].append(b)

ans=False
for i in A[1]:
    if i==N:
        ans=True
        break
    for j in A[i]:
        if j==N:
            ans=True
            break
print("POSSIBLE" if ans else "IMPOSSIBLE" )


Measured memory_bytes: 33304
#include<iostream>
#include<cstdio>
#include<math.h>
#define rep(i,a) for(int i = 0; i < a; i++)
using namespace std;

int main(){
	int n;
	int array[100];
	cin  >> n;
	rep(i, n){
		cin >> array[i];
	}
	for(int i = n-1; i >= 0; i--){
		cout << array[i];
		if(i != 0) cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
ll n;
vector<vector<pair<ll,ll>>> g;

int check[110000];

void dfs(int now,int c){
  if(check[now]!=-1)return;
  check[now]=c;
  for(auto v:g[now]){
   int next=v.first;
   int flag=v.second;
    dfs(next,(flag+c)%2);
  }
  return;
}

int main(){cout<<fixed<<setprecision(20);
		   //dfs
           cin>>n;
           g.resize(n,vector<pair<ll,ll>>());
           ll a,b,c;
           rep(i,0,n-1){
             cin>>a>>b>>c;
             a--;b--;c%=2;
             g[a].pb(mp(b,c));
             g[b].pb(mp(a,c));
           }
           rep(i,0,n)check[i]=-1;
           dfs(0,0);
           rep(i,0,n){
            cout<<check[i]<<endl; 
           }
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()

int main(){
    string str;cin>>str;
    string str2=str;
    reverse(ALL(str2));
    if(str==str2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define pri 1000000007
#define all(x) x.begin(),x.end()
#define mx 32
using namespace std;

void masterstroke(){
	ll n,d;cin>>n>>d;
	ll f=n/(2*d+1);
	if(n%(2*d+1ll)!=0ll)f++;
	cout<<f<<endl;
	
	
}


int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)masterstroke();
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
#define ll long long
ll b[110],c[110],d[110],a[110];
ll va[110],vb[110],vc[110],vd[110];
ll wa[110],wb[110],wc[110],wd[110];
bool cmp(ll x,ll y)
{
    return x>y;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll i,j,k,m,n,o,w;
    ll ans=1,ans1=0,ans2=0,ans3=0,sw,sv;
    ll cnt,t,maxn=0;
    cin>>n>>w;
    cin>>sw>>sv;
    t=sw;
    a[1]=sv;
    for(i=2; i<=n; i++)
    {
        cin>>sw>>sv;
        if(sw==t)
            a[++ans]=sv;
        if(sw==t+1)
            b[++ans1]=sv;
        if(sw==t+2)
            c[++ans2]=sv;
        if(sw==t+3)
            d[++ans3]=sv;
    }
    sort(a+1,a+1+ans,cmp);
    sort(b+1,b+1+ans1,cmp);
    sort(c+1,c+1+ans2,cmp);
    sort(d+1,d+1+ans3,cmp);
    va[0]=0,vb[0]=0,vc[0]=0,vd[0]=0;
    wa[0]=0,wb[0]=0,wc[0]=0,wd[0]=0;
    for(i=1; i<=ans; i++)
        va[i]=va[i-1]+a[i],wa[i]=i*t;
    for(i=1; i<=ans1; i++)
        vb[i]=vb[i-1]+b[i],wb[i]=i*(t+1);
    for(i=1; i<=ans2; i++)
        vc[i]=vc[i-1]+c[i],wc[i]=i*(t+2);
    for(i=1; i<=ans3; i++)
        vd[i]=vd[i-1]+d[i],wd[i]=i*(t+3);
    for(i=0; i<=ans; i++)
        for(j=0; j<=ans1; j++)
            for(k=0; k<=ans2; k++)
                for(o=0; o<=ans3; o++)
                    if(wa[i]+wb[j]+wc[k]+wd[o]<=w)
                        maxn=max(maxn,va[i]+vb[j]+vc[k]+vd[o]);
    cout<<maxn<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())

A, B = list(map(int, input().split()))
P = list(map(int, input().split()))

S1 = len(list(filter(lambda x : x <=A , P)))
S2 = len(list(filter(lambda x : x > A and x<= B , P)))
S3 = len(list(filter(lambda x : x > B , P)))

print("%d" % (min(S1, min(S2, S3))))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
	LL K,A,B;
	scanf("%lld %lld %lld",&K,&A,&B);
	K++;
	if(B-A<2LL)printf("%lld",K);
	else
	{
		if((K-A)%2LL==0LL)
		{
			printf("%lld",A+(((K-A)/2LL)*(B-A)));
		}
		else
		{
			printf("%lld",A+(((K-A)/2LL)*(B-A))+1LL);
		}
	}
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
    
h.sort()

min = 10**9
for i in range(N-K+1):
    if h[i+K-1] - h[i] < min:
        min = h[i+K-1] - h[i]

print(min)


Measured memory_bytes: 7384
import collections


def main():
    n = int(input())
    a = input_list()
    ac = collections.Counter(a)
    for i in range(n):
        if i+1 in ac:
            print(ac[i+1])
        else:
            print(0)


def input_list():
    return list(map(int, input().split()))


main()

Measured memory_bytes: 124160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        static void SolveA(string[] args)
        {
            int[] xyxy = ReadAndParseIntArr();
            int x1 = xyxy[0];
            int y1 = xyxy[1];
            int x2 = xyxy[2];
            int y2 = xyxy[3];
            int vx = x2 - x1;
            int vy = y2 - y1;

            // 回転行列適用
            int vx1 = -vy;
            int vy1 = vx;

            int x3 = x2 + vx1;
            int y3 = y2 + vy1;

            // さらに回転行列適用
            vx1 = -vx;
            vy1 = -vy;

            int x4 = x3 + vx1;
            int y4 = y3 + vy1;
            

            Console.WriteLine($"{x3} {y3} {x4} {y4}");
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>

using namespace std;


int main() {
	char s[5] = "NSEW";
	char str[1001] = {};
	cin >> str;
	int N = strlen(str);
	bool f[4] = { false,false,false,false };
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < 4; k++) {
			if (str[i] == s[k]) {
				f[k] = true;
				break;
			}
		}
	}
	if (f[0] == f[1] && f[2] == f[3]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int count=0,a;
  string S;
  cin>>a>>S;
  for(int i=0;i<S.size()/2;i++){
    if(S[i]==S[i+S.size()/2]){
      count++;
    }
  }
  if(count==S.size()/2&&a%2==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;

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

            final int N = fs.nextInt();
            final int M = fs.nextInt();
            final int X = fs.nextInt();

            int[] A = new int[N];

            Arrays.fill(A, 0);

            for (int i = 0; i < M; i++) {
                int m = fs.nextInt();
                A[m - 1] += 1;
            }

            for (int i = 0; i < N - 1; i++) A[i + 1] += A[i];

            System.out.println(Math.min(A[X - 1], A[N - 1] - A[X - 1]));
        }
    }
}

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: 22612
let nt = stdin.ReadLine().Split() |> Array.map int
let (n, T) = (nt.[0], nt.[1])
let cands =
    [|1..n|] |> Array.map (
        fun _ -> 
            let ct = stdin.ReadLine().Split() |> Array.map int
            let (c, t) = (ct.[0], ct.[1])
            (c, t)
    )
    |> Array.filter (fun (_, t) -> t <= T)


if cands.Length = 0 then "TLE" else cands |> Array.minBy fst |> fst |> string
|> stdout.WriteLine


Measured memory_bytes: 11476
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		int k=nextInt();
		out.println(a[k-1]);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 21460
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int a = input[0];
            int b = input[1];
            Console.WriteLine((a * b) % 2 == 0 ? "Even" : "Odd");
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int n; cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    vector<int> c(n);
    c[0] = 0;
    c[1] = abs(h[0]-h[1]);
    for (int i = 2; i < n; i++)
    {
        c[i] = min(c[i-1]+abs(h[i]-h[i-1]), c[i-2]+abs(h[i]-h[i-2]));
    }
    cout << c[n-1] << endl;
}

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

int main(){
	int n,m,x,y,i;
	
	cin>>n>>m>>x>>y;
	
	int a[n+2],b[m+2];
	
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	for(i=1;i<=m;i++){
		cin>>b[i];
	}
	if(x>y){
		cout<<"War"<<endl;
	}
	a[n+1]=x;
	b[m+1]=y;
	
	sort(a+1,a+n+2);
	sort(b+1,b+m+2);
	
	if(a[n+1]>=b[1]){
		cout<<"War"<<endl;
	}else{
		cout<<"No War"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = list( input().split() )

dict = collections.Counter(a)

x_max = 0
#mem_key = ""

for key in dict.keys():
  k = int( key )
  x_max = max(x_max, dict[str(k-1)]+dict[str(k)]+dict[str(k+1)])

    
print(x_max)

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

const int D = 80 * 160 + 10;
const int D2 = D * 2;
typedef bitset<D2> bs;

int a[100][100];
bs dp[90][90];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) rep(j, w) {
    int x;
    cin >> x;
    a[i][j] = x;
  }
  rep(i, h) rep(j, w) {
    int x;
    cin >> x;
    a[i][j] = abs(x - a[i][j]);
  }

  dp[0][0][D - a[0][0]] = 1;
  dp[0][0][D + a[0][0]] = 1;
  rep(i, h) rep(j, w) {
    if (i) {
      dp[i][j] |= dp[i - 1][j] << a[i][j];
      dp[i][j] |= dp[i - 1][j] >> a[i][j];
    }
    if (j) {
      dp[i][j] |= dp[i][j - 1] << a[i][j];
      dp[i][j] |= dp[i][j - 1] >> a[i][j];
    }
  }
  int ans = D2;
  rep(i, D2) if (dp[h - 1][w - 1][i]) { ans = min(ans, abs(i - D)); }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 24704
/// input macro from https://qiita.com/tanakh/items/1ba42c7ca36cd29d0ac8
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }
fn main() {
    input!(abc: [u64; 3], k: u64);

    let a = abc[0];
    let mut b = abc[1];
    let mut c = abc[2];

    let mut counter = 0;
    while a >= b {
        b *= 2;
        counter += 1;
    }

    while b >= c {
        c *= 2;
        counter += 1;
    }

    if counter <= k {
        println!("Yes");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

struct Mod {
    static constexpr auto kMod = 998244353L;

    Mod() : n(0) {}
    // can be implicitly converted
    Mod(int64_t n) : n(n) {}

    Mod operator*(Mod m) const { return (n * (m.n % kMod)) % kMod; }

    Mod& operator*=(Mod m) {
        *this = *this * m;
        return *this;
    }

    Mod pow(int64_t p) {
        if (p == 0) {
            return 1;
        }
        if (p == 1) {
            return n;
        }

        int64_t r = this->pow(p / 2).n;
        if (p % 2 == 0) {
            return r * r % kMod;
        } else {
            return (r * r % kMod) * n % kMod;
        }
    }

    Mod operator/(Mod m) const {
        if (n == 0) {
            return 0;
        }

        return *this * m.pow(kMod - 2);
    }

    Mod& operator/=(Mod m) {
        *this = *this / m;
        return *this;
    }

    Mod operator+(Mod m) const { return (n + m.n) % kMod; }

    Mod& operator+=(Mod m) {
        *this = *this + m;
        return *this;
    }

    Mod operator-(Mod m) const { return (kMod + n - m.n) % kMod; }

    Mod& operator-=(Mod m) {
        *this = *this - m;
        return *this;
    }

    int64_t n;
};

int main() {
    int64_t n, s;
    cin >> n >> s;

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    Mod ans;
    vector<Mod> dp(s);
    for (auto i : irange(0L, n)) {
        auto aa = a[i];
        dp[0] = i + 1;
        if (aa > s) {
            continue;
        }

        ans += dp[s - aa] * (n - i);

        for (auto j : irange(aa, s) | reversed) {
            dp[j] += dp[j - aa];
        }
    }

    cout << ans.n << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#define repe(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mst(a, b)   memset((a), (b), sizeof(a))
#define gc() gutchar()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pr;
typedef long long ll;
const double eps = 1e-5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const ll mod = 1e9+7;
const int N = 1e4+5;

map<int, bool> mp;
bool ok;

int main()
{
	int n; cin >> n;
	rep(i, 0, n){
		int x;
		scanf("%d", &x);
		if (!mp[x])	mp[x] = 1;
		else	ok = 1;
	}
	if (ok)	puts("NO");
	else	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

bool dp[82][82][25610];

int main() {
	for (int i = 0; i < 81; ++i) {
		for (int j = 0; j < 81; ++j) {
			for (int k = 0; k < 25610; ++k) { dp[i][j][k] = false; }
		}
	}

	int H, W;
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	vector<vector<int>> b(H, vector<int>(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) { cin >> a[i][j]; }
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) { cin >> b[i][j]; }
	}

	int n = 12805;
	dp[0][0][n] = true;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			int diff = abs(a[i][j] - b[i][j]);
			for (int k = 0; k < 25610; ++k) {
				if (!dp[i][j][k]) { continue; }
				if (i + 1 <= H) {
					if (k - diff >= 0) {
						dp[i + 1][j][k - diff] = true;
					}
					if (k + diff < 25610) {
						dp[i + 1][j][k + diff] = true;
					}
				}
				if (j + 1 <= W) {
					if (k - diff >= 0) {
						dp[i][j + 1][k - diff] = true;
					}
					if (k + diff < 25610) {
						dp[i][j + 1][k + diff] = true;
					}
				}
			}
		}
	}
	int ans = 1e9;
	for (int i = 0; i < 25610; ++i) {
		if (dp[H][W - 1][i]) { 
			ans = min(ans, abs(n - i));
		}
		if (dp[H - 1][W][i]) {
			ans = min(ans, abs(n - i));
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 168320
s = input()

ok = True
ok = ok and s[0] == 'A'

cs = 0
for i in range(2, len(s)-1):
    if s[i] == 'C':
        cs += 1

ok = ok and cs == 1

for i in range(1, len(s)):
    if s[i].islower():
        continue
    if s[i] == 'C':
        continue
    ok = False

print('AC' if ok else 'WA')


Measured memory_bytes: 9092
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;
 
int main() {
    while(true) {
        int n; scanf("%d", &n);
        if(n==0) break;
        int submax; scanf("%d", &submax);
        int maxval = submax;
        for(int i = 1; i < n; i++) {
            int a; scanf("%d", &a);
            submax = max(a, submax+a);
            maxval = max(maxval, submax);
        }
        printf("%d\n", maxval);
    }
    return 0;
}

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

string s;
int k;

int main() {
    cin >> k >> s;
    if (k >= (int)s.size())
        cout << s;
    else {
        for (int i = 0; i < k; ++i)
            cout << s[i];
        cout << "...";
    }
    return 0;
}

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

#define ll long long 
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

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

	int n; cin >> n;
	ll a[n], sum = 0;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	sum = a[n - 1];
	int pos = n - 2;
	int ok = 0;
	for(int i = 0; i < n - 2; i++) {
		sum += a[pos];
		ok ^= 1;
		if(ok == 0) pos--;
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 5192
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define ld long double
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

ld Input[100100];

int main() {
  int N; cin >> N;
  ld T, A; cin >> T >> A;
  rep(i, N) {
    ld x; cin >> x;
    Input[i] = T - x * 0.006;
  }

  ld m = INF;
  int ans = -1;
  rep(i, N) {
    if (m >  abs(A - Input[i])) {
      m = abs(A - Input[i]);
      ans = i;
    }
  }

  cout << ans+1 << endl;
}


Measured memory_bytes: 256
'use strict';

const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const iS = () => inputs.shift();
const sMpI = (str) => str.split(' ').map(v => parseInt(v, 10));
const sMpIS = () => sMpI(iS());
const pI = v => parseInt(v);

const price = pI(iS());

console.log(price % 1000 === 0 ? 0 : 1000 - (price % 1000));

Measured memory_bytes: 29684
#include<stdio.h>

int main()
{
int c=0,i=1,i2=1;

for(i2=1;i2<=9;i2++)
{
for(i=1;i<=9;i++)
{
c=i2*i;
printf("%d",i2);
printf("x%d",i);
printf("=%d\n",c);

}
}
return 0;

}

Measured memory_bytes: 524
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#define x first
#define y second
using namespace std;
typedef long long int ll;
vector< pair<ll, int> > edge;
ll h, w;

ll kruskal(void)
{
	ll ret=0;
	sort(edge.begin(),edge.end());
	ll a=h+1, b=w+1;
	for(int i=0 ; i<edge.size() ; i++)
	{
		if(edge[i].second==0)
		{
			ret+=edge[i].first*a;
			b--;
		}
		else if(edge[i].second==1)
		{
			ret+=edge[i].first*b;
			a--;
		}
	}
	return ret;
}
int main(void)
{
	cin>>w>>h;
	int i;
	for(i=0 ; i<=w-1 ; i++)
	{
		ll cost;
		scanf("%lld",&cost);
		edge.push_back(make_pair(cost,0));
	}
	for(i=0 ; i<=h-1 ; i++)
	{
		ll cost;
		scanf("%lld",&cost);
		edge.push_back(make_pair(cost,1));
	}
	cout<<kruskal()<<endl;
}

Measured memory_bytes: 4464
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;
}
#endif


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

    string S;  cin >> S;
    int N = S.size();
    int X, Y; cin >> X >> Y;

    vs v = split(S, 'T');

    vi vx, vy;
    int odd = true;
    for(string s : v) {
        if (odd) vx.push_back(s.size());
        else vy.push_back(s.size());
        odd = !odd;
    }

    const int VXL = vx.size(), VYL = vy.size();

    if (VXL==0 && VYL==0) {
        if (X == 0 && Y == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }

    vvb dpx(N, vb(2*N+MGN, false));
    dpx[0][N + vx[0]] = true;
    FOR(i,1,VXL) {
        REP(j,2*N+1) {
            if (dpx[i-1][j]) {
                dpx[i][j + vx[i]] = true;
                dpx[i][j - vx[i]] = true;

            }
        }
    }

    vvb dpy(N, vb(2*N+MGN, false));
    if (VYL > 0) {
        dpy[0][N + vy[0]] = true;
        dpy[0][N - vy[0]] = true;
        FOR(i,1,VYL) {
            REP(j,2*N+1) {
                if (dpy[i-1][j]){
                    dpy[i][j + vy[i]] = true;
                    dpy[i][j - vy[i]] = true;
                }
            }
        }
    }

    string ans = "No";
    if (dpx[VXL-1][N+X]) {
        if (VYL==0){
            ans = "Yes";
        } else {
            if (dpy[VYL-1][N+Y]) ans = "Yes";
        }        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 32768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

int main(){   
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    rep(i,n)cin>>h[i];
    sort(all(h));
    ll sum = 0;
    rep(i,n-k){
        sum += h[i];
    }
    cout<<sum<<endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> a(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> a[i][j];
    }
  }
  
  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(a[i][j]=='#'){
        row[i]=true;
        col[j]=true;
      }
    }
  }
   
  /*
  for(x:row){
    cout << x;
  }cout <<endl;
  */
  
  for(int i=0; i<H; i++){
    
    if(row[i]==false){
      continue;
    }
    
    for(int j=0; j<W; j++){
      
      if(col[j]==false){
        continue;
      }
      
      cout << a[i][j];
    }
    cout << endl;
  }

}


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


int main() {
    ll tmp, K;
    vector<ll> A(3);
    rep(i,3) cin >> A[i];
    cin >> K;

    sort(A.begin(), A.end(), greater<ll>());
    ll ans = A[0];
    rep(i,K) ans *= 2;
    ans += A[1] + A[2];
    cout << ans << endl;
} 


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	ll n ,a , b;
	cin >> n >> a >> b;
	ll ans = 0  ;
	if( (b - a ) % 2 == 0 ){
		ans = (b - a ) / 2 ;
		cout << ans << endl;
		return 0;
	}
	ll A = a - 1 ;
	ll B = n - b ;
	ans += min(A,B)+1;
	b--;
	//二人の距離は変わらずにans回移動した。
	ans += (b-a)/2;
	cout << ans << endl;

}





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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    for(int i=0;i<5;++i)
    {
        int x;
        cin>>x;
        if(x==0)
        {
            cout<<(i+1);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}
int n;
string memo[10000];
string bina(ll i){
    if(memo[i]!=""){
        return memo[i];
    }
    ll ii=i;
    string ans="";
    while(i>0){
        if(i%2==1){
            ans='1'+ans;
            i=i/2;
        }else{
            ans='0'+ans;
            i=i/2;
        }
    }
    while(ans.size()<n){
        ans='0'+ans;
    }
    memo[ii]=ans;
    return ans;
}

ll bi(string i){
    ll c=1;
    ll ans=0;
    for(ll j=i.size()-1;j>=0;j--){
        if(i[j]=='1'){
            ans=ans+c;
        }
        c=c*2;
    }
    return ans;
}

int main(){
    int m;cin>>n>>m;
    ll aa=pow(2,n);
    ll dp[m+1][aa];
    for(ll i=0;i<=m;i++){
        for(ll j=0;j<aa;j++){
            dp[i][j]=inf;
        }
    }
    dp[0][0]=0;
    string s;
    ll ss;
    ll a[m],b[m];
    ll c[m][n];
    for(ll i=0;i<m;i++){
        cin>>a[i]>>b[i];
        for(ll j=0;j<b[i];j++){
            cin>>c[i][j];
        }
    }
    
    for(ll i=0;i<m;i++){
        for(ll j=0;j<aa;j++){
            if(dp[i][j]!=inf){
                s=bina(j);
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
                for(ll k=0;k<b[i];k++){
                    s[c[i][k]-1]='1';
                }
                ss=bi(s);
                dp[i+1][ss]=min(dp[i+1][ss],dp[i][j]+a[i]);
            }
        }
    }
    /*for(ll i=0;i<m;i++){
        for(ll j=0;j<aa;j++){
            cout<<dp[i][j]<<' ';
        }
        cout<<endl;
    }*/
    if(dp[m][aa-1]!=inf){
        cout<<dp[m][aa-1]<<endl;
    }else{
        cout<<-1<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 32512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	string s; cin >> s;
	rep(i,s.size()){
		if (i%2 == 0){
			cout << s[i];
		}
	}
	cout << endl;
}

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

using namespace std;

class UnionFind {
 public:
  std::vector<int> parent;

  UnionFind(int n) : parent(n, -1) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    return parent[x] = root(parent[x]);
  }

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

  int size(int x) { return -parent[root(x)]; }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) std::swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  UnionFind uf(2 * N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf.unite(a, b + N);
    uf.unite(a + N, b);
  }
  if (uf.issame(0, N)) {
    cout << 1LL * N * (N - 1) / 2 - M << '\n';
  } else {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (uf.issame(0, i)) cnt++;
    }
    // cout << cnt << '\n';
    cout << 1LL * cnt * (N - cnt) - M << '\n';
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <atcoder/dsu>

int main(){
    using namespace std;
    using namespace atcoder;
    unsigned long N;
    cin >> N;
    dsu d(N);
    cout << [&N, &d]{
        unsigned long M, ans{N - 1};
        cin >> M;
        for(unsigned long i{0}, A, B; i < M; ++i){
            cin >> A >> B;
            ans -= ! d.same(--A, --B);
            d.merge(A, B);
        }
        return ans;
    }() << endl;
    return 0;
}


Measured memory_bytes: 3788
#include <iostream>

using namespace std;

int N;
long long sum;
int cnt[100005];
int Q;

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int A;
		cin >> A;
		sum += A;
		cnt[A]++;
	}
	for (cin >> Q; Q--; )
	{
		int B, C;
		cin >> B >> C;
		sum -= 1LL * B * cnt[B];
		sum += 1LL * C * cnt[B];
		cnt[C] += cnt[B];
		cnt[B] = 0;
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n, x=-1, c=0;
    cin>>n; int a[n];
    for (int i=0; i<n; i++) { cin>>a[i]; if (a[i]%2!=0) x++;}
    while (x==-1)
{
for (int i=0; i<n; i++)
{
a[i]/=2;
}
c++;
for (int i=0; i<n; i++) {  if (a[i]%2!=0) x++;}
}
    cout<<c;
    return 0;
}


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

int main(void) {
    int n;
    int s[1000] = {};
    double m, a;
    
    while(true) {
        m = 0;
        a = 0;
        cin >> n;
        
        if(n == 0)   break;
        
        for(int i = 0; i < n; ++i) {
            cin >> s[i];
            m += s[i];
        }
        m /= n;
        
        for(int i = 0; i < n; ++i) {
            a += (s[i] - m)*(s[i] - m);
        }
        a = sqrt(a / n);
        
        printf("%lf\n", a);
    }
    
    return 0;
}




Measured memory_bytes: 3220
import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toInt()}

    val ps = Array(N) {
        val (T, D) = readLine()!!.split(" ").map{it.toLong()}
        Pair(T, D)
    }

    ps.sortWith(Comparator { o1, o2 -> o2.second.compareTo(o1.second) })

    var tmp = 0L
    val st = TreeSet<Long>()
    val Q = PriorityQueue<Long>()

    ps.take(K).forEach {
        tmp += it.second
        if (st.contains(it.first)) {
            Q.add(it.second)
        } else {
            st.add(it.first)
        }
    }

    var res = tmp + st.size * st.size.toLong()

    for (p in ps.takeLast(N - K)) {
        if (st.contains(p.first)) {
            continue
        }

        if (Q.isEmpty())
            continue

        tmp -= Q.poll()

        st.add(p.first)
        tmp += p.second

        res = Math.max(res, tmp + st.size * st.size.toLong())
    }

    println(res)
}


Measured memory_bytes: 67572
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        String s = scanner.next();
        if (s.charAt(0) == 'A') {
            int count = 0;
            for (int i = 2; i < s.length() -1; i++) {
                if (s.charAt(i) == 'C') {
                    count++;
                }
            }
            if (count == 1) {
                String s3 = s.replaceAll("A","").replaceAll("C","");
                int count2 = 0;
                for (int i = 0; i < s3.length(); i++) {
                    if (s3.charAt(i) >= 'a' && s3.charAt(i) <= 'z') {
                    } else {
                        count2++;
                    }
                }
                if (count2 == 0) {
                    System.out.println("AC");
                    return;
                }
            }
        }
        System.out.println("WA");
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21460
str = input()
flg = 1
for i in str:
  if(flg==1):
    if(i=="L"):
      print("No")
      flg = 2
      break;
  else:
    if(i=="R"):
      print("No")
      flg = 2
      break;
  flg *=-1
if(flg!=2):
  print("Yes")




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

int main()
{
	int a=0;
	int b=0;
	int sum=0;
	int digit=0;
	
	while(cin >> a >> b){
		sum = a + b;
		
		while(sum){
			sum = sum / 10;
			digit++;
		}
		
		cout << digit << endl;
		digit = 0;
	}
	
	return 0;
}

Measured memory_bytes: 1160
a,b = map(int,input().split())
if a % 2 == 0:
    if (b - a + 1) % 2 == 0:
        if (b-a + 1) % 4 == 0:
            print(0)
        else:
            print(1)
    else:
        if (b - a) % 4 == 0:
            print(0^b)
        else:
            print(1^b)
else:
    if (b - a) % 2 == 0:
        if (b-a) % 4 == 0:
            print(a^0)
        else:
            print(a^1)
    else:
        if (b - a - 1) % 4 == 0:
            print(0^b^a)
        else:
            print(1^b^a)


Measured memory_bytes: 9096
#include<iostream>
#include<math.h>
using namespace std;
int main(){
    long long a,b,c;
    cin>>a>>b;
    if(a>0&&b>0){
        cout<<"Positive"<<endl;
    }else if(a>=0&&b<0||a<0&&b>=0){
        cout<<"Zero"<<endl;
    }else{
        c = abs(a-b);
        if(c%2==0){
            cout<<"Negative"<<endl;
        }else{cout<<"Positive"<<endl;}
    }
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $x, $y);
$groupA = [1, 3, 5, 7, 8, 10, 12];
$groupB = [4, 6, 9, 11];
$groupC = [2];
if(in_array($x, $groupA) && in_array($y, $groupA)){
  echo 'Yes';
}elseif(in_array($x, $groupB) && in_array($y, $groupB)){
  echo 'Yes';
}else{
  echo 'No';
}
?>

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

typedef pair<int,pair<int,int> > piii;

int main(){
    int n,m;
    cin >> n >>m;

    vector<piii> y(m);

    rep(i,m){
        int a,b;
        cin >> a >> b;
        y[i]={b,{a,i}};
    }

    sort(y.begin(),y.end());
    vector<int> p(n+1,0);
    vector<string> ans(m);
    rep(i,m){
        p[y[i].second.first]++;
        string s1 = to_string(y[i].second.first);
        while(s1.size()!=6)s1 = '0'+ s1;
        string s2 = to_string(p[y[i].second.first]);
        while(s2.size()!=6)s2 = '0'+ s2;
        ans[y[i].second.second] = s1+s2;
    }

    rep(i,m){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine();

			string s = "";

			foreach(var c in input)
			{
				if(c == 'B' && s.Length > 0)
				{
					s = s.Remove(s.Length - 1);
				}
				else if(c != 'B')
				{
					s += c;
				}
			}

			Console.WriteLine(s);
		}
	}
}


Measured memory_bytes: 13140