akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAccepted solver = new AAccepted();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAccepted {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println(Arrays.stream(in.next().split("")).filter(s -> s.equals("1")).count());
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public void close() {
        }

    }
}


Measured memory_bytes: 28628
#include <iostream>

int main(void) {
    int K, A, B;
    std::cin >> K;
    std::cin >> A >> B;
    
    if((B / K * K) >= A) {
        std::cout << "OK" << std::endl;
    } else {
        std::cout << "NG" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3632
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val problem = "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".split(",\\s+")

    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val k = in.readLine().toInt

    out.println(problem(k - 1))
    out.flush()
  }
}


Measured memory_bytes: 25664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using P = pair<char,int>;

bool err;
map<char,int> sz;
map<P,int> val;

int numb(const string &s){
    int ret = 0;
    rep(i,s.size()) ret = ret*10 + (s[i]-'0');
    return ret;
}

int expr(const string &s){
    if(isdigit(s[0])) return numb(s);

    int S = s.size();
    char ar_name = s[0];
    int idx = expr(s.substr(2,S-3));

    if(sz.count(ar_name) && 0<=idx && idx<sz[ar_name] && val.count({ar_name,idx})){
        return val[{ar_name,idx}];
    }
    else{
        err = true;
        return -1;
    }
}

void assi(const string &s){
    char ar_name = s[0];
    int e_pos = s.find('=');

    int idx = expr(s.substr(2,e_pos-3));
    int t = expr(s.substr(e_pos+1));

    if(sz.count(ar_name) && 0<=idx && idx<sz[ar_name]) val[{ar_name, idx}] = t;
    else err = true;
}

void decl(const string &s){
    char ar_name = s[0];

    int S = s.size();
    int num = numb(s.substr(2,S-3));
    assert(!sz.count(ar_name));
    sz[ar_name] = num;
}

void prog(const string &s){
    if(find(all(s), '=') == s.end()) decl(s);
    else assi(s);
}

int main(){
    while(1){
        vector<string> v;
        string tt;
        while(1){
            cin >>tt;
            if(tt == ".") break;
            v.pb(tt);
        }
        int n = v.size();

        if(n == 0) break;

        sz.clear();
        val.clear();
        err = false;

        int ans = 0;
        rep(i,n){
            prog(v[i]);
            if(err){
                ans = i+1;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3192
use proconio::input;

fn factorization(n: usize, v: &mut Vec<usize>) {
    fn factor_sub(n: usize, m: usize) -> (usize, usize) {
        let mut c = 0;
        let mut x = n;
        while x % m == 0 {
            c += 1;
            x /= m;
        }
        (c, x)
    }

    let (c, n) = factor_sub(n, 2);
    if c > 0 {
//		print!("({},{})", 2, c);
		v[2] += c;
	}
    let mut x = 3;
    let mut m = n;
    while x * x <= m {
        let (c, n) = factor_sub(m, x);
        if c > 0 {
//			print!("({},{})", x, c);
			v[x] += c;
		}
        m = n;
        x += 2;
    }
    if m > 1 {
//		print!("({},{})", m, 1);
		v[m] += 1;
	}
//	println!("");
}

fn main() {
	input!(n: usize);

	let mut v: Vec<usize> = vec![0; 1000+1];
	for i in 2..n+1 {
		factorization(i, &mut v);
	}
	let mut ans = 1;
//	println!("{:?}", v);
	for i in 0..1000+1 {
		if v[i] > 0 {
			ans *= v[i] + 1;
			ans %= 1000000007
		}
	}
	println!("{}", ans);
}



Measured memory_bytes: 2132
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;
int main(){
   int ia,ib;
    cin >> ia >> ib;
    double da,db,dc;
    da = ia;
    db = ib;
    dc = da/db;
    
   
    cout << ia/ib<< " " << ia%ib<< " " <<  fixed <<setprecision(9) <<dc << endl;
    
    }


Measured memory_bytes: 3284
N = int(input())
a = list(map(int, input().split()))

MAX = max(a)
MIN = min(a)

if MIN < 0:
    print(2 * N - 1)
    if abs(MAX) >= abs(MIN):
        idx = a.index(MAX) + 1
        for i in range(1, N + 1):
            print(idx, i)
        for i in range(1, N):
            print(i, i + 1)
    else:
        idx = a.index(MIN) + 1
        for i in range(1, N + 1):
            print(idx, i)
        for i in range(N, 1, -1):
            print(i, i - 1)
else:
    print(N - 1)
    for i in range(1, N):
        print(i, i + 1)

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

typedef pair<int, int> pi;

int main() {
	int M, T, P, R;
	while(cin >> M >> T >> P >> R && M){
		int m, t, p, c, wrong[64][16] = {0};
		pi team[64];
		for(int i = 0; i <= T; ++i)
			team[i] = pi(0, 0);
			
		for(int i = 0; i < R; ++i){
			scanf("%d%d%d%d", &m, &t, &p, &c);
			if(c == 0){
				team[t].first--;
				team[t].second += m + wrong[t][p];
			}
			else{
				wrong[t][p] += 20; 
			}
		}
		pi rnk[64];
		for(int i = 0; i <= T; ++i)
			rnk[i] = team[i];
			
		sort(team, team + T + 1);
		pi prev;
		bool is_out[64] = {0};
		for(int i = 0; i < T; ++i){
			for(int j = T; j >= 1; --j){
				if(rnk[j].first == team[i].first && rnk[j].second == team[i].second && !is_out[j]){
					if(i){
						if(prev.first == team[i].first && prev.second == team[i].second)
							cout << "=";
						else
							cout << ",";
					}
					cout << j;
					is_out[j] = true;
					prev = pi(team[i].first, team[i].second);
					break;
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
// E. Magical Permutation
// time limit per test1 second
// memory limit per test256 megabytes
// inputstandard input
// outputstandard output
// Kuro has just learned about permutations and he is really excited to create a
// new permutation type. He has chosen 𝑛 distinct positive integers and put all
// of them in a set 𝑆. Now he defines a magical permutation to be:

// A permutation of integers from 0 to 2𝑥−1, where 𝑥 is a non-negative integer.
// The bitwise xor of any two consecutive elements in the permutation is an
// element in 𝑆. Since Kuro is really excited about magical permutations, he
// wants to create the longest magical permutation possible. In other words, he
// wants to find the largest non-negative integer 𝑥 such that there is a magical
// permutation of integers from 0 to 2𝑥−1. Since he is a newbie in the subject,
// he wants you to help him find this value of 𝑥 and also the magical
// permutation for that 𝑥.

// Input
// The first line contains the integer 𝑛 (1≤𝑛≤2⋅105) — the number of elements in
// the set 𝑆.

// The next line contains 𝑛 distinct integers 𝑆1,𝑆2,…,𝑆𝑛 (1≤𝑆𝑖≤2⋅105) — the
// elements in the set 𝑆.

// Output
// In the first line print the largest non-negative integer 𝑥, such that there
// is a magical permutation of integers from 0 to 2𝑥−1.

// Then print 2𝑥 integers describing a magical permutation of integers from 0 to
// 2𝑥−1. If there are multiple such magical permutations, print any of them.

// Examples
// inputCopy
// 3
// 1 2 3
// outputCopy
// 2
// 0 1 3 2
// inputCopy
// 2
// 2 3
// outputCopy
// 2
// 0 2 1 3
// inputCopy
// 4
// 1 2 3 4
// outputCopy
// 3
// 0 1 3 2 6 7 5 4
// inputCopy
// 2
// 2 4
// outputCopy
// 0
// 0
// inputCopy
// 1
// 20
// outputCopy
// 0
// 0
// inputCopy
// 1
// 1
// outputCopy
// 1
// 0 1
// Note
// In the first example, 0,1,3,2 is a magical permutation since:

// 0⊕1=1∈𝑆
// 1⊕3=2∈𝑆
// 3⊕2=1∈𝑆
// Where ⊕ denotes bitwise xor operation.

#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

using namespace std;

int n, m, d;
int i, j, k;

vector<int> a;

int longest_increasing_sequences() {
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    auto it = upper_bound(v.begin(), v.end(), a[i]);
    if (it != v.end()) {
      *it = a[i];
    } else {
      v.push_back(a[i]);
    }
  }
  return v.size();
}

void solve() {
  cin >> n;
  a.resize(n);
  for (auto& x : a) cin >> x;
  reverse(a.begin(), a.end());
  cout << longest_increasing_sequences() << endl;
  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}


Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;

namespace ARC087D
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int[] input = Console.ReadLine().Split(' ').Select(ii => int.Parse(ii)).ToArray();
            int x = input[0];
            int y = input[1];

            List<int> fx = new List<int>();
            List<int> fy = new List<int>();

            bool isX = true;
            int current = 0;
            foreach (char command in s)
            {
                if (command.ToString() == "F")
                {
                    current++;
                    continue;
                }

                if (isX)
                {
                    fx.Add(current);
                }
                else
                {
                    fy.Add(current);
                }

                isX = !isX;
                current = 0;
            }

            if (isX)
            {
                fx.Add(current);
            }
            else
            {
                fy.Add(current);
            }

            int sumX = fx.Sum();
            int sumY = fy.Sum();

            if (sumX < x || sumY < y)
            {
                Console.WriteLine("No");
                return;
            }

            int subX = sumX - x;
            int subY = sumY - y;

            if (subX % 2 != 0 | subY % 2 != 0)
            {
                Console.WriteLine("No");
                return;
            }

            Solver solver = new Solver();

            fx.RemoveAt(0);
            if (solver.dp(fx, subX / 2) & solver.dp(fy, subY / 2))
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
        }
    }

    class Solver
    {
        public bool dp(List<int> list, int sum)
        {
            int[] a = list.ToArray();
            int n = a.Length;
            bool[][] dp = new bool[n + 1][];
            for (int i = 0; i < n + 1; i++)
            {
                dp[i] = new bool[sum + 1];
            }

            dp[0][0] = true;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < sum + 1; j++)
                {
                    if (a[i] <= j)
                    {
                        dp[i + 1][j] = dp[i][j - a[i]] || dp[i][j];
                    }
                    else
                    {
                        dp[i + 1][j] = dp[i][j];
                    }
                }
            }

            return dp[n][sum];
        }
    }
}

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

int n;
int main(){
	while(cin >> n){
		//vector< pair<char,int> > v(n);
		int U[4][14] = {{0}};
		for(int i=0;i<n;i++){
			char t; int a;
			cin >> t >> a;
			if(t=='S') U[0][a] = 1;
			else if(t=='H') U[1][a] = 1;
			else if(t=='C') U[2][a] = 1;
			else if(t=='D') U[3][a] = 1;
		}
		for(int i=0;i<=3;i++){
			for(int j=1;j<=13;j++){
				if(U[i][j]!=1){
					if(i==0) cout << "S" << " " << j << endl;
					else if(i==1) cout << "H" << " " << j << endl;
					else if(i==2) cout << "C" << " " << j << endl;
					else if(i==3) cout << "D" << " " << j << endl;
				}
			}
		}
	}
}


Measured memory_bytes: 3100
import java.util.*;

public class Main {
    class Card {
        String suit;
        int value;

        public Card(String suit, int value) {
            this.suit = suit;
            this.value = value;
        }
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Card[] arr = new Card[n];
        for (int i = 0; i < n; i++) {
            arr[i] = new Card(sc.next(), sc.nextInt());
        }

        Card[] mergeArr = arr.clone();

        mergeSort(mergeArr, 0, arr.length, 0);
        quickSort(arr, 0, arr.length - 1);

        boolean isStable = true;
        for (int i = 0; i < n; i++) {
            if (!mergeArr[i].equals(arr[i])) {
                isStable = false;
                break;
            }
        }
        System.out.println(isStable ? "Stable" : "Not stable");
        for (int i = 0; i < n; i++) {
            Card c = arr[i];
            System.out.println(c.suit + " " + c.value);

//            Card c2 = mergeArr[i];
//            System.out.println(c2.suit + " " + c2.value);
        }
    }

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

    static void quickSort(Card[] arr, int p, int r) {
        if (p < r) {
            int q = partition(arr, p, r);
            quickSort(arr, p, q - 1);
            quickSort(arr, q + 1, r);
        }
    }

    static int partition(Card[] arr, int p, int r) {
        Card x = arr[r];
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (arr[j].value <= x.value) {
                i = i + 1;
                Card tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
            }
        }
        Card tmp = arr[i + 1];
        arr[i + 1] = arr[r];
        arr[r] = tmp;
        return i + 1;
    }

    int merge(Card[] arr, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        Card[] l = new Card[n1 + 1];
        Card[] r = new Card[n2 + 1];
        for (int i = 0; i < n1; i++) {
            l[i] = arr[left + i];
        }
        for (int i = 0; i < n2; i++) {
            r[i] = arr[mid + i];
        }
        l[n1] = new Card("X", Integer.MAX_VALUE);
        r[n2] = new Card("x", Integer.MAX_VALUE);
        int i = 0;
        int j = 0;
        int count = 0;
        for (int k = left; k < right; k++) {
            count++;
            if (l[i].value <= r[j].value) {
                arr[k] = l[i];
                i = i + 1;
            } else {
                arr[k] = r[j];
                j = j + 1;
            }
        }
        return count;
    }

    int mergeSort(Card[] arr, int left, int right, int count) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            int x = mergeSort(arr, left, mid, count);
            int x2 = mergeSort(arr, mid, right, count);
            count = count + x + x2 + merge(arr, left, mid, right);
        }
        return count;
    }
}


Measured memory_bytes: 117612
#include <stdio.h>

#define MOD 1000000007

int main(void) {
    long long N, K, x, i;
    scanf("%lld%lld", &N, &K);
    x=0;
    for (i=K; i<=N+1; i++) {
        x+=i*(2*N-i+1)/2-i*(i-1)/2+1;
        if (x>=MOD) x%=MOD;
    }
    printf("%lld", x);
    return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>

#define MAX 20000
using namespace std;



int main(){
  int W,H,x,y,r;
  std::cin >> W>>H>>x>>y>>r;
  if((x+r)<=W&&(x-r)>=0&&(y-r)>=0&&(y+r)<=H){
    std::cout << "Yes" << '\n';
  }else{
      std::cout << "No" << '\n';
  }
}

Measured memory_bytes: 3088
K = int(input())
s = input()
n=len(s)
def find_power(n,mod=10**9+7):
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist
def find_inv_power(n,mod=10**9+7):
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist
mod = 10**9+7
NUM = (2*10**6)+100
p_lis=find_power(NUM,mod)
ip_lis=find_inv_power(NUM,mod)
def comb(n,r,mod=10**9+7):
    if n<r:
        return 0
    elif n>=r:
        return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod)
ans=0
for k in range(K+1):
    ans+=(comb(n-1+K-k,n-1)* pow(25,K-k,mod)* pow(26,k,mod))
print(ans%mod)

Measured memory_bytes: 312624
H=int(input())
W=int(input())
N=int(input())

cnt=0
if H<=W:
    while True:
        if N>0:
            cnt+=1
            N-=W
        else:
            print(cnt)
            exit()

else:
    while True:
        if N>0:
            cnt+=1
            N-=H
        else:
            print(cnt)
            exit()


Measured memory_bytes: 2940
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] c = new int[N - 1];
		int[] s = new int[N - 1];
		int[] f = new int[N - 1];
		for (int i = 0; i < N - 1; i++) {
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}

		sc.close();

		// 各iについてしらべる
		for (int i = 0; i < N - 1; i++) {
			// aは、i+1に到着する時間
			int a = s[i] + c[i]; // iが出発地点のときのi+1の到着は、始発+走行時刻
			for (int j = i + 1; j < N - 1; j++) {
				if (a <= s[j]) {
					// jの到着がjの始発より前なら始発を待って乗る
					a = s[j];
				} else {
					// 始発よりあとなら、次の列車にのる
					int b = a - s[j]; // aは始発のb秒後
					int d = b / f[j] + (b % f[j] > 0 ? 1 : 0); // 始発からd本目に乗れる
					a = s[j] + f[j] * d;
				}

				// j->j+1の走行時間
				a += c[j];
			}
			out.println(a);
		}
		out.println(0);
	}

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


Measured memory_bytes: 25992
#include <cstdio>

int main()
{
	long a,b,c,d;
	scanf("%ld%ld%ld%ld",&a,&b,&c,&d);
	long long e,f,g,h;
	e=a*c;
	f=a*d;
	g=b*c;
	h=b*d;
	long long max=e;
	if (max < f)
		max = f;
	if (max < g)
		max = g;
	if (max < h)
		max = h;
	
	printf("%lld\n", max);

	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;


int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    cout << (a[0] + a[1] + a[2]) - *max_element(a, a+3) << endl;

    return 0;

    
}

Measured memory_bytes: 256
(locally
 (declare (optimize (speed 3) (safety 0) (compilation-speed 3) (debug 0)))
 (defun poison (a b c)
   (declare (fixnum a b c))
   (write (if (> (+ a b 1) c) (+ b c) (+ a b b 1))))
 (poison (read) (read) (read)))

Measured memory_bytes: 3432
void main()
{
    string s = readln.chomp;
    string t = readln.chomp;

    bool[26][26] table;
    foreach (i; 0 .. s.length)
    {
        table[s[i]-'a'][t[i]-'a'] = true;
    }

    bool ok = true;
    foreach (i; 0 .. 26)
    {
        long row, col;
        foreach (j; 0 .. 26)
        {
            if (table[i][j]) ++row;
            if (table[j][i]) ++col;
        }

        if (row > 1 || col > 1) ok = false;
    }

    writeln(ok ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 2872
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll x; cin>>x;
	while(1){
		for(ll i=2;i<x;i++){
			if(x%i==0)goto next;
		}
		break;
		next:
		x++;
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = [0] + A + [0]
sowa = 0
for i in range(N+1):
    sowa += abs(A[i]-A[i+1])
for i in range(1,N+1):
    print(sowa-(abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])))


Measured memory_bytes: 13920
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function root(uf::Array{Int,1},x)
	s=x
	while uf[s]>0
		s=uf[s]
	end
	s
end
function same(uf::Array{Int,1},x,y)
	root(uf,x)==root(uf,y)?true:false
end
function unite(uf::Array{Int,1},x,y)
	l = root(uf,x)
	r = root(uf,y)
	if l < r
		uf[l] += uf[r]
		uf[r] = l
	elseif l > r
		uf[r] += uf[l]
		uf[l] = r
	end
end

function main()
	n,m = readline() |> split |> parseMap
	uf = -ones(Int,n+m)
	for i in 1:n
		k = readline() |> split |> parseMap
		for j in 1:k[1]
			unite(uf,i,n+k[j+1])
		end
	end
	f = 0
	rt = root(uf,1)
	for i in 2:n
		if root(uf,i)!=rt
			f = 1
			break
		end
	end
	println(f==0?"YES":"NO")
end

main()


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

int kaisu(int x,int y){
    if(x%y==0){
        return x/y;
    }else{
        return x/y + 1;
    }
}

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    bool ok = true;
    int x = kaisu(c,b); //高橋の攻撃回数
    int y = kaisu(a,d); //青木の攻撃回数
    //cout << x << " " << y << endl;
    if(x<=y){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int K = sc.nextInt();
   double[] a = new double[N];
   for(int i=0;i<N;i++) a[i] = sc.nextDouble();
   int ans = 0;
   double mos = 0;
   for(int i=0;i<K;i++) mos+= a[i];
   double tmp =mos;
 
   for(int i =1; i<N-K+1;i++)
   {
     tmp -= a[i-1];
     tmp += a[i+K-1];
     if(tmp > mos) 
     {
       mos = tmp;
       ans = i;
     }
   }
   double answer = 0.0;
   for(int i = ans ; i < ans+K ;i++)
   {
     answer += (1+a[i])/2;
   }
   System.out.printf("%.8f",answer);
 }
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, m, c;
	cin >> n >> m >> c;
	vector<ll> b(m);
	for (int i = 0; i < m; i++)
		cin >> b[i];
	ll ct = 0;
	for (int i = 0; i < n; i++)
	{
		ll s = 0;
		for (int j = 0; j < m; j++)
		{
			ll x;
			cin >> x;
			s += x * b[j];
		}
		s += c;
		if (s > 0)
			ct++;
	}
	cout << ct;
	return 0;
}


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

int main(void)
{
  string s;
  cin >> s;
  string d = s;
  reverse(d.begin(), d.end());
  for(int i = 0; i < (s.size() - 1)/2; i++)
  {
    if(s[i] != s[(s.size() - 1)/2 - 1 - i])
    {
      cout << "No" <<endl;
      return (0);
    }
    if(s[(s.size() + 3)/2 - 1 + i] != s[s.size() - 1 - i])
    {
      cout << "No" <<endl;
      return (0);
    }
    if(s[i] != d[i])
    {
      cout << "No" <<endl;
      return (0);
    }
  }
  cout << "Yes" <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<int> p(m), y(m);
	vector< vector<int> > tmp(n);

	for(int i = 0; i < m; ++i) {
		cin >> p[i] >> y[i];
		p[i]--;
		
		tmp[p[i]].push_back(y[i]);
	}
	
	for(int i = 0; i < n; ++i) {
		sort(tmp[i].begin(), tmp[i].end());
		tmp[i].erase(unique(tmp[i].begin(), tmp[i].end()), tmp[i].end());
	}
	
	
	for(int i = 0; i < m; ++i) {
		int x = p[i];
		int ID = lower_bound(tmp[x].begin(), tmp[x].end(), y[i]) - tmp[x].begin();
		
		printf("%06d%06d\n", x + 1, ID + 1);
	}

	return 0;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
int main(){
    ll n,m,ans=0;cin>>n>>m;
    vector<ll> a(n);
    priority_queue<ll> s;
    For(i,0,n) {
        cin>>a.at(i);
        s.push(a.at(i));
    }
    For(i,0,m){
        ll x=s.top();
        x/=2;
        s.pop();
        s.push(x);
    }
    while(!s.empty()){
        ans+=s.top();
        s.pop();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2168
h, w = map(int, input().split())
INF = 10 ** 20
dp = [[INF] * (w + 1)] + [[INF] + [0] * w for _ in range(h)]
dp[0][1] = 0
for y in range(1, h + 1):
  line = list(map(int, list(input())))
  for x in range(1, w + 1):
    dp[y][x] = min(dp[y - 1][x], dp[y][x - 1]) + line[x - 1]
print(dp[h][w])


Measured memory_bytes: 5608
#include "bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define all(v,a,b) v.begin(a),v.end(b)
#define in cin>>
#define out cout<<
#define end <<endl
#define INF 100000000000

int main()
{
	int N;
	in N;
	if (N % 2 == 0)
	{
		N--;
	}
	out N / 2 end;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

bool nat(std::vector<int> const& p, std::vector<int> const& q) {
  int sum{};
  for(int i{}; i < p.size(); ++i) {
    sum += std::pow(p[i] - q[i], 2);
  }

//  std::cout << "###" << sum << std::endl;
  return sum == std::pow(static_cast<int>(std::sqrt(sum)), 2);
}

int main(int, char**) {
  int n, d;
  std::cin >> n >> d;

  std::vector<std::vector<int>> xs(n);
  for(int i{}; i < n; ++i) {
    for(int j{}; j < d; ++j) {
      int t;
      std::cin >> t;
      xs[i].push_back(t);
    }
  }

  int ans{};
  for(int i{}; i < n; ++i) {
    for(int j{i + 1}; j < n; ++j) {
      if(nat(xs[i], xs[j])) {
        ++ans;
      }
    }
  }

  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
from collections import Counter

N=int(input())
*d,=map(int,input().split())
mod = 998244353

if d[0]:
  print(0)
  exit()
  
dmax = max(d)
if sorted(set(d)) != list(range(dmax+1)):
  print(0)
  exit()

c = Counter(d)

if c[0]>1:
  print(0)
  exit()

ans =1
for i in range(2,dmax+1):
  ans *= pow(c[i-1],c[i],mod)
  ans %= mod
  
print(ans)

Measured memory_bytes: 25716
#include <cstdio>
#include <algorithm>

int main()
{
  int n;
  char s[5001];
  scanf("%d%s", &n, s);
  
  int pre[5000];
  pre[0] = 0;
  int ans = 0;
  for (char *p = s; p - s < n - 1; ++p)
  {
    int len = n - (p - s);
    for (int i = 1, j = 0; i < len; ++i)
    {
      if (i + pre[i - j] < j + pre[j])
      {
        pre[i] = pre[i - j];
        if (i + 1 > pre[i] && ans < pre[i]) ans = pre[i];
      }
      else
      {
        int k = std::max(0, j + pre[j] - i);
        while (i + k < len && p[k] == p[i + k]) ++k;
        pre[i] = k;
        j = i;
        if (i + 1 > pre[i] && ans < pre[i]) ans = pre[i];
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int X; cin>>X;
	for (int i=1; i<=360; i++)
		if((i*X)%360==0) {
			cout<<i<<"\n";
			return 0;
		}
	return 0;
}

Measured memory_bytes: 3644
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  vector<int>c(n);
  rep(i,n) cin >> a.at(i);
  rep(i,n) b.at(i) = 1 + a.at(i);
  rep(i,n) c.at(i) = 2 + a.at(i);
  vector<int>d(100010);
  rep(i,n) d.at(a.at(i))++;
  rep(i,n) d.at(b.at(i))++;
  rep(i,n) d.at(c.at(i))++;
  int ma = 0;
  rep(i,100010) ma = max(ma,d.at(i));
  cout << ma << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i]; cout<<endl;
ll power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
const int MX=1e5+1;
ll facti[MX],fact[MX],inv[MX];
void factorial(){
	inv[1]=1;
	facti[0]=1;
	fact[0]=1;
	for(ll i=2;i<=MX;i++)
		inv[i]=(mod-((mod/i)*inv[mod%i])%mod)%mod;
	for (ll i=1;i<=MX;i++) {
		fact[i]=(fact[i-1]*i)%mod;
		facti[i]=(facti[i-1]*inv[i])%mod;
	}
}
ll nCr(int n,int r){
	ll ans=((fact[n]*facti[n-r])%mod*facti[r])%mod;
	return ans;
} 
void solve(){
	int n,k;
	cin>>n>>k;
	ll a[n];
	ll ans=0;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(n-i-1>=k-1){
			ans=(ans-(a[i]*nCr(n-i-1,k-1))%mod+mod)%mod;
		}
		if(i>=k-1){
			ans=(ans+(a[i]*nCr(i,k-1))%mod)%mod;
		}
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	factorial();
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}


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

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

  typedef long long ll;
  ll ans = 0;
  int cur = 0;
  for(int i=0; i<s.size(); i++){
    if(s[i] == 'B') cur++;
    else ans += cur;
  }

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

Measured memory_bytes: 3748
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
long long gcd(long long a, long long b) {
  return b != 0 ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b) {
  return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
int main(void){
    ll a,b;scanf("%lld %lld",&a,&b);
    cout << lcm(a,b) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

using ll = int_fast64_t;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<T>;
using vi = vt<int>;
using vvi = vvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;
using pi = pair<int, int>;

constexpr int INF = 1 << 29; // 2倍するとオーバーフローする
// constexpr ll INFL = 1 << 58;
constexpr int dx[] = {0, 1, 0, -1};
constexpr int dy[] = {1, 0, -1, 0};

// [a, b)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); i--)
// [a, b]
#define RANGE(i, a, b) for (int i = (a); i <= (b); i++)
#define RANGER(i, a, b) for (int i = (b); i >= (a); i--)
// [0, n)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) RFOR(i, 0, (n))

#define ALL(i) i.begin(), i.end()

inline int gint() {
  int a;
  cin >> a;
  return a;
}

int main() {
  int N;
  ll X; // [1,4503599627370493]
  cin >> N >> X;
  auto all_count = vl(N);
  all_count[0] = 1;
  FOR(i, 1, N) all_count[i] = all_count[i - 1] * 2 + 3;

  auto pate_count = vl(N);
  pate_count[0] = 1;
  FOR(i, 1, N) pate_count[i] = pate_count[i - 1] * 2 + 1;

  ll result = 0;
  FORR(i, 0, N) {
    X -= 1;                  // 最下層のパン
    if (X >= all_count[i]) { // 下のレベル低いバーガーをすべて食べる
      X -= all_count[i];
      result += pate_count[i];
      cerr << "Eat 1 #" << i << " X:" << X << endl;
      if (X > 0) {
        X--; // 間のパンを食べる
        result++;
      } else
        break; // 食べきった
      cerr << "Eat 2 #" << i << " X:" << X << endl;

      if (X >= all_count[i]) { // 上のレベル低いバーガーをすべて食べる
        X -= all_count[i];
        result += pate_count[i];
        cerr << "Eat 3 #" << i << " X:" << X << endl;

        break; // Xは、1か0なはず。
      }
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repush_back(i,a,b) for(ll i=a;i>=b;i--)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define F first
#define S second
#define pi 3.14159265359
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
ll HRX=1e18;
ll INF=1e9+7;


int main()
{
 hs;
 string s,t;
 cin>>s>>t;
 ll cnt=0;
 ll n=s.length();
 f(n)
 {
  if(t[i]==s[i])
        cnt++;
 }
 cout<<cnt<<endl;
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
string S1;
vector<bool> A;




int main()
{
string S2;
	cin >> N>>S1 >> S2;

	REP(i,S1.size()){
		if(i<N-1 &&S1[i] == S1[i+1]){
			A.push_back(1);
			i++;
		}else{
			A.push_back(0);
		}
	}

	long long ans = 0;
	if(A[0]){
		ans = 6;
	} else {
		ans = 3;
	}
	FOR(i,1,A.size()){
		if(A[i-1]){
			if(A[i])
				ans = (ans * 3) % 1000000007;
		}else{
			ans = (ans * 2) % 1000000007;
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int n;
int main(void){
  while(cin>>n){
    if(n==0) break;
    double x[100],y[100];
    REP(i,n){
      scanf("%lf,%lf",x+i,y+i);
    }
    int ans = 1;
    for(int i=0; i<n; i++){
      for(int j=i+1; j<n; j++){
        double dist = sqrt( (x[j]-x[i])*(x[j]-x[i]) + (y[j]-y[i])*(y[j]-y[i]));
        if(dist>2) continue; 
        double thete = atan2(y[j]-y[i],x[j]-x[i]);
        double alpha = acos( (dist*dist)/(2*dist));
        double kx[2],ky[2];
        kx[0] = x[i] + cos(thete+alpha);
        ky[0] = y[i] + sin(thete+alpha);
        kx[1] = x[i] + cos(thete-alpha);
        ky[1] = y[i] + sin(thete-alpha);
        int tmp = 2;
        REP(k,n){
          if(i==k||j==k) continue;
          double d = sqrt((x[k]-kx[0])*(x[k]-kx[0]) + (y[k]-ky[0])*(y[k]-ky[0]));
          if(d<1+EPS) tmp++;
        }
        ans = max(tmp,ans);
        tmp = 2;
        REP(k,n){
          if(i==k||j==k) continue;
          double d = sqrt((x[k]-kx[1])*(x[k]-kx[1]) + (y[k]-ky[1])*(y[k]-ky[1]));
          if(d<1+EPS) tmp++;
        }
        ans = max(tmp,ans);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define f first  
#define s second
#define rep(i,a,b)  for(ll i=a;i<b;i++)

int main() 
{
    string s,t;
    cin>>s>>t;
    int n=s.length(),x=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]==t[i])
        {
            x++;
        }
        else
        {
            break;
        }
    }
    if(x==n)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
	return 0;
}

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

using namespace std;

typedef long long Long;

namespace {

    int N;
    vector<Long> A;

    void input() {
        cin >> N;
        A.clear(); A.resize(N);
        for (int i = 0; i < N; i++) cin >> A[i];
        sort(A.begin(), A.end());
        reverse(A.begin(), A.end());
    }

    bool comp(int x, int y) {
        return __builtin_popcount(x) < __builtin_popcount(y);
    }

    void solve() {
        vector<int> r;
        Long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += A[i];
            Long a = A[i];
            sort(r.begin(), r.end(), comp);
            int used = 0;
            vector<int> nr;
            for (int j = 0; j < r.size(); j++) {
                int x = r[j];
                if (a == 0 || (used & x)) {
                    nr.push_back(x);
                } else {
                    ans--; a--;
                    used |= x;
                    nr.push_back(x | 1 << i);
                }
            }
            for (int j = 0; j < min(Long(5), a); j++) {
                nr.push_back(1 << i);
            }
            r = nr;
        }
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 1228
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - *3 or /2
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);

    while (! (ai & 1)) ai >>= 1, cnt++;
  }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pcase printf("Case %d:\n",ca)
int ca=1;
using namespace std;
int main(){
   string a;
   cin>>a;
   ll ans= 0;
   for(int i = 0;i<a.size();i++){
    ans=(ans%9+(a[i]-'0')%9)%9;
   }
   if(ans%9 == 0){
    cout<<"Yes"<<nl;
   }else{
   cout<<"No"<<nl;
   }
}



Measured memory_bytes: 3696
#include<iostream>
#include<tuple>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

typedef tuple<int, int, vector<int>> T3;//座標、

int H, W;
char field[100 + 10][100 + 10];
bool visited[100 + 10][100 + 10];

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)cin >> field[i][j];
	}
	
	queue<T3> Q;
	vector<int> state = {1, 2, 3, 5, 4, 6};
	Q.push(make_tuple(0, 0, state));
	while (Q.size()) {
		auto now = Q.front();
		int x = get<0>(now), y = get<1>(now);
		auto ns = get<2>(now);
		Q.pop();
		if (x == H - 1 && y == W - 1) {
			cout << "YES" << endl;
			return 0;
		}

		//上向き
		if (x > 0 && field[x - 1][y] != '#' && !visited[x - 1][y]) {
			vector<int> newstate(6);
			newstate[0] = ns[1], newstate[1] = ns[5], newstate[2] = ns[2];
			newstate[3] = ns[0], newstate[4] = ns[4], newstate[5] = ns[3];
			if (newstate[5] == field[x - 1][y] - '0') {
				visited[x - 1][y] = true;
				Q.push(make_tuple(x - 1, y, newstate));
			}
		}
		
		//下向き
		if (x < H - 1 && field[x + 1][y] != '#' && !visited[x + 1][y]) {
			vector<int> newstate(6);
			newstate[0] = ns[3], newstate[1] = ns[0], newstate[2] = ns[2];
			newstate[3] = ns[5], newstate[4] = ns[4], newstate[5] = ns[1];
			if (newstate[5] == field[x + 1][y] - '0') {
				visited[x + 1][y] = true;
				Q.push(make_tuple(x + 1, y, newstate));
			}
		}
		
		//左向き
		if (y > 0 && field[x][y - 1] != '#' && !visited[x][y - 1]) {
			vector<int> newstate(6);
			newstate[0] = ns[2], newstate[1] = ns[1], newstate[2] = ns[5];
			newstate[3] = ns[3], newstate[4] = ns[0], newstate[5] = ns[4];
			if (newstate[5] == field[x][y - 1] - '0') {
				visited[x][y - 1] = true;
				Q.push(make_tuple(x, y - 1, newstate));
			}
		}
		
		//右向き
		if (y < W - 1 && field[x][y + 1] != '#' && !visited[x][y + 1]) {
			vector<int> newstate(6);
			newstate[0] = ns[4], newstate[1] = ns[1], newstate[2] = ns[0];
			newstate[3] = ns[3], newstate[4] = ns[5], newstate[5] = ns[2];
			if (newstate[5] == field[x][y + 1] - '0') {
				visited[x][y + 1] = true;
				Q.push(make_tuple(x, y + 1, newstate));
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
 int main(void) {
 int k, a, b,s;

 scanf("%d", &k);
 scanf("%d%d", &a, &b);

 s=(b / k) * k;
 if (a <= s) {
 puts("OK");
 } 
 else {
 puts("NG");
 }

 return 0;
}


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

int main(){
	int i, j;
	string s;
	while(getline(cin, s)){
		for (i = 0; i < 26; i++) {
			for(j = 0; j < s.length(); j++){
				if(s[j] != '.' && s[j] != ' '){
					s[j] = (s[j]=='a')? 'z' : s[j] - 1;
				}
			}
			if(s.find("the")!=string::npos || s.find("this")!=string::npos || s.find("that")!=string::npos){
				cout << s << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

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

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
        int k = sc.nextInt();
        int ans = 0;
        for(int i = 0; i < n; i++){
            int x = sc.nextInt();
            ans += 2 * Math.min(x, Math.abs(k-x));
        }
        sc.close();
        out.println(ans);
        out.flush();
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(){
	int H,W;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0) break;
		for(int j=1;j<=H;j++){
			for(int i=1;i<=W;i++){
				if((j%2)==1){
					if((i%2)==1)	printf("#");
					else	printf(".");
				}
				else{
					if((i%2)==1)	printf(".");
					else	printf("#");
					
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}

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


int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for(int i = 0; i < N; i++){
    cin >> V.at(i);
  }
  long long X;
  X = 0;
  for(int i = 1; i < N; i++){
    if(V.at(i-1) > V.at(i)){
      X += V.at(i-1) - V.at(i);
      V.at(i) += V.at(i-1) - V.at(i);
    }
    else{
      continue;
    }
  }
  cout << X << endl;
}

Measured memory_bytes: 4044
#include <iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a[110];
int main()
{
     int n;
     scanf("%d",&n);
     for(int i=0;i<n;i++)
     {
         scanf("%d",&a[i]);
     }
     sort(a,a+n);
     printf("%d",a[n-1]-a[0]);

     return 0;


}


Measured memory_bytes: 256
n,z,w = list(map(lambda x:int(x),input().split()))
a = list(map(lambda x: int(x),input().split()))

result1 = abs(w-a[-1])
if len(a) >= 2:
    result2 = abs(a[-2]-a[-1])
else:
    result2 = result1

print(max(result1,result2))

Measured memory_bytes: 3188
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	class DJSet {
		int n;
		int[] upper;

		public DJSet(int n_) {
			n = n_;
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		void setUnion(int x, int y) {
			x = root(x);
			y = root(y);
			if (x == y)
				return;

			if (upper[x] < upper[y]) {
				x ^= y;
				y ^= x;
				x ^= y;
			}
			upper[y] += upper[x];
			upper[x] = y;
		}
	}

	void run() {
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] p = new int[N];
		int[][] swap = new int[M][2];
		DJSet ds = new DJSet(N);
		for (int i = 0; i < N; ++i) {
			p[i] = sc.nextInt();
			--p[i];
		}
		for (int i = 0; i < M; ++i) {
			swap[i][0] = sc.nextInt() - 1;
			swap[i][1] = sc.nextInt() - 1;
			ds.setUnion(swap[i][0], swap[i][1]);
		}

		long ans = 0;
		for (int i = 0; i < N; ++i) {
			if (ds.equiv(i, p[i])) {
				++ans;
			}
		}
		System.out.println(ans);
	}
	

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

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	class Scanner {
		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;
		}

		int nextInt() {
			return (int) nextLong();
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			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();
			}
		}
	}
}


Measured memory_bytes: 25596