akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
    int H,W;
    char a[300][300];
    while(1){
        cin >> H >> W;
        if(H==0 && W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((i+j)%2==0){
                    a[i][j]='#';
                }else{
                    a[i][j]='.';
                }
            }
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout << a[i][j];
            }cout << endl;
        }cout << endl;
    }return 0;
}


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

int main() {

	string s1, s2;
	cin >> s1 >> s2;

	int n = s2.size();
	int ans = 10001;
	for (int i = 0; i < s1.size() - n + 1; ++i) {

		string cand = s1.substr(i, n);
		int diff = 0;
		for (int i = 0; i < cand.size(); ++i) {
			if (cand[i] != s2[i]) {
				diff++;
			}
		}
		if (ans > diff) ans = diff;
	}
	cout << ans << "\n";
	return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for (int i = 0; i < N; i ++){
        cin >> l.at(i);
    }
    sort (l.begin(), l.end());
    reverse (l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < K; i ++){
        ans += l.at(i);
    }
    cout << ans << endl;
}
            

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

int main(){
	int h,m,s,tss,tse,tsr;
	for(int i=0;i<3;i++){
		cin>>h>>m>>s;
		tss=3600*h+60*m+s;
		cin>>h>>m>>s;
		tse=3600*h+60*m+s;
		tsr=tse-tss;
		cout<<tsr/3600<<" "<<tsr/60%60<<" "<<tsr%60<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
/* Stack */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 11
typedef struct {
    int size;
    int count;
    char data[SIZE];
    char *top;
}stack;
void initialize_stack(stack *stk);//初期化
void print_stack(stack *stk);
void push(stack *stk, char key);
void pop(stack *stk);

int main(void){
    int i;
    char input[SIZE];
    stack string;
    //入力する
    scanf("%s",input);
    initialize_stack(&string);
    //0か1だったらその数字をプッシュし、Bが出たらpopする
    for(i=0;i<SIZE;i++){
        if(input[i] == '0'){
            push(&string,'0');
        }
        else if(input[i] == '1'){
            push(&string,'1');
        }
        else if(input[i]=='B'){
            pop(&string);
        }
    }
    //結果を出力する
    print_stack(&string);
    return 0;
}

void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

void push(stack *stk, char key){
    if(stk->count < stk->size){
        //トップをひとつ上にあげる
        stk->top--;
        //データを格納する
        *(stk->top) = key;
        //現在のデータ数をひとつ増やす
        stk->count++;
    }
}
void pop(stack *stk){
    if(stk->count > 0){
        //topをひとつ下に下げる
        stk->top++;
        //データ数をひとつ減らす
        stk->count--;
    }
}
void print_stack(stack *stk){
    char *ptr;
    int i;
    //一番上の位置
    ptr = stk->top;
    //古いデータからtopに向かってprintする
    while(i<stk->count-1){
        ptr++;
        i++;
    }
    for(int i=0;i<stk->count;i++){
        printf("%c", *ptr--);
    }
    printf("\n");
}

Measured memory_bytes: 1648
function Main(input) {
    input = input.split("\n");
  	var N = Number(input[0]),
        A = input[1].split(' ').map(Number),
        B = input[2].split(' ').map(Number),
        C = input[3].split(' ').map(Number);
  	var count = 0;
  	for(var i=0; i<N; i++){
      count += B[A[i]-1];
      if(A[i] === (A[i-1] + 1)){
      	count += C[A[i]-2];
      }
    }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
n = int(input())
a = sorted(list(map(int,input().split())))
d = {}
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
for i in range(n):
  i += 1
  if i in d:
    print(d[i])
  else:
    print(0)

Measured memory_bytes: 34752
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int mod = 1000000007;
struct mint {
ll x; 
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
 }
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
 }
 mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
 mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
 mint inv() const {
return pow(mod-2);
 }
  mint& operator/=(const mint a) {
return (*this) *= a.inv();
 }
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
 }
};

string L;
mint solve(){
    ll num=0;
    mint res=0;
    rep(i,L.size()){
        int len=(int)L.size()-i-1;
        if(L[i]=='1'){

          res+=mint(2).pow(num)*mint(3).pow(len);
          num++;
        }
    }
    res+=mint(2).pow(num);
    return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

cin>>L;
mint ans=solve();
cout<<ans.x<<endl;
return 0;
}

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;

    if (a == b + c) {
      cout << "Yes" << endl;
    }
    else if (b == a + c) {
      cout << "Yes" << endl;
    }
    else if (c == a + b) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }


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

int main(){
	int n;
	int ans=0;
	cin>>n;
	vector<int>l(n);
	rep(i,n){
		cin>>l[i];
	}

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

	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			for(int k=0;k<j;k++){
				if((l[i]!=l[j])&&(l[j]!=l[k])&&(l[k]!=l[i])){
					if(l[j]+l[k]>l[i])ans++;
				}
			}
		}
	}

	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 3624
// Aizu Vol-5 0546: Lining up the cards
// 2017.8.30 bal4u@uu

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

#define HASHSIZ 10007
int hash[HASHSIZ + 5], *hashend = hash + HASHSIZ;

int insert(int n)
{
	int *p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return 0;
		if (++p == hashend) p = hash;
	}
	*p = n;
	return 1;
}

int c[12];
char f[12];
int n, k, ans;

void combi(int i, int m)
{
	int j;

	if (i >= k) {
		if (insert(m)) ans++;
		return;
	}
	for (j = 0; j < n; j++) {
		if (f[j]) continue;
		f[j] = 1;
		if (c[j] < 10) combi(i+1, m*10 + c[j]);
		else           combi(i+1, m*100+ c[j]);
		f[j] = 0;
	}
}

int main()
{
	int i;

	while (scanf("%d%d", &n, &k) && n) {
		memset(hash, 0, sizeof(hash));
		for (i = 0; i < n; i++) scanf("%d", c+i), f[i] = 0;
		ans = 0;
		combi(0, 0);
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n, k;
  cin >> n >> k;

  map<int, vector<ll>> sushi;
  for (int i = 0; i < n; ++i) {
    int t;
    ll d;
    cin >> t >> d;
    sushi[t].push_back(d);
  }

  vector<ll> g1, g2;
  for (auto &p : sushi) {
    auto &vd = p.second;
    auto max_it = max_element(vd.begin(), vd.end());
    g1.push_back(*max_it);
    for (auto it = vd.begin(); it != vd.end(); it++) {
      if (it != max_it) {
        g2.push_back(*it);
      }
    }
  }

  sort(g1.begin(), g1.end(), greater<ll>());
  sort(g2.begin(), g2.end(), greater<ll>());

  vector<ll> g1_psum{0}, g2_psum{0};
  partial_sum(g1.begin(), g1.end(), back_inserter(g1_psum));
  partial_sum(g2.begin(), g2.end(), back_inserter(g2_psum));
  ll ans = 0;
  for (ll i = 1; i <= k && i <= g1.size(); ++i) {
    if (k - i >= g2_psum.size()) {
      continue;
    }

    ll sum = i * i + g1_psum[i] + g2_psum[k - i];
    ans = max(ans, sum);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 13556
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll A,B;
  cin >> A >> B;
  int K;
  cin >> K;
  set<int> s;
  int C = A;
  if(A==B)
  {
    cout << A << endl;
    return 0;
  }
  rep(i,K)
  {
    s.insert(A);
    A ++;
    if(A==B)
    {
      break;
    }
  }
  rep(i,K)
  {
    s.insert(B);
    B --;
    if(C==B)
    {
      break;
    }
  }
  int N = s.size();
  rep(i,N)
  {
    int n = *begin(s);
    cout << n << endl;
    s.erase(n);
  }
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>

using ll = long long;
using namespace std;

int main() {
    int N, l, r, s = 0;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> l >> r;
        s += r - l + 1;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val list = readLine()!!.split(" ").map(String::toInt)

    var result = mutableListOf<Int>()

    for (i in list[0]..list[1]) {

        // ロジックが汚い。やりたいことは剰余と商を求めること
        // 商と余りのPair型で返却するfunctionを作成してみる？
        // 冷静に考えると、順次割り算を再起的にする必要もなく(桁数が決まっているので)
        // 順次割って行かないと桁数おかしくなる。
        val one = devidePair(i)
        val two = devidePair(one.first)
        val three = devidePair(two.first)
        val four = devidePair(three.first)
        val five = devidePair(four.first)
        if (one.second == five.second && two.second == four.second)
            result.add(i)
    }
    println(result.size)
}

fun devidePair(num: Int): Pair<Int, Int> {

    // LOOK Pairの初期化
    return Pair(num / 10, num % 10)
}

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

int main()
{
	int N, res = 0;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] & 1) res++;
	}
	cout << (res & 1 ? "NO" : "YES") << endl;
	return 0;
}


Measured memory_bytes: 1148
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static int r[];
	static int x[];
	static int y[];
	static int c[];

	static int on[][];
	static boolean dp[];
	static boolean table[][];

	static void solve() {
		//int bit = 0;
		dp[0] = true;
		makeTable();
		//0の時に円盤を2枚取れるか全て計算
		//		for (int s = 0; s < n; s++) {
		//			//s + 1ビット目が0なら
		//			//System.out.println("s = " + s);
		//			for (int k = s + 1; k < n; k++) {
		//				if (canGet(bit, s, k)) {
		//					dp[(1 << s) + (1 << k)] = true;
		//				}
		//			}
		//		}
		//
		//		for (int i = 0; i < n; i++) {
		//			for (int j = i + 1; j < n; j++) {
		//				bit = (1 << i) + (1 << j);
		//
		//				if (dp[bit] == true) {
		//					for (int s = 0; s < n; s++) {
		//						if ((bit >> s & 1) == 0) {
		//							for (int k = s + 1; k < n; k++) {
		//								if ((bit >> k & 1) == 0) {
		//									if (canGet(bit, s, k)) {
		//										dp[bit + (1 << s) + (1 << k)] = true;
		//									}
		//								}
		//							}
		//						}
		//					}
		//				}
		//
		//			}
		//		}
		int len = 1 << n;
		for(int bit = 0; bit < len; bit++){
			if(dp[bit]){
				for (int s = 0; s < n; s++) {
					if ((bit >> s & 1) == 0) {
						for (int k = s + 1; k < n; k++) {
							if ((bit >> k & 1) == 0) {
								if (canGet(bit, s, k)) {
									dp[bit + (1 << s) + (1 << k)] = true;
								}
							}
						}
					}
				}	
			}
		}
		//printDP();

		printAns();
	}
	
	static void printDP(){
		for(boolean a : dp){
			System.out.print(a + " ");
		}
		System.out.println();
	}

	static void printAns() {
		int max = 0;
		for (int i = 0; i < dp.length; i++) {
			if (dp[i]) {
				// iの1の数を計算
				int count = 0;
				int k = i;
				for (int j = 0; j < n; j++) {
					if (((k & 1) == 1)) {
						count++;
					}
					k = k >> 1;
				}
				max = count > max ? count : max;
			}

		}

		System.out.println(max);
	}

	static void makeTable() {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i; j++) {
				//重なっていればtrue
				table[i][j] = d(x[i] - x[j]) + d(y[i] - y[j]) < d(r[i] + r[j]) ? true : false;
			}
		}
	}

	static int d(int a){
		return a*a;
	}

	static boolean canGet(int bit, int s, int k) {
		if (c[s] != c[k]) {
			return false;
		}

		for (int i = 0; i < n; i++) {
			if ((bit >> i & 1) == 0) {
				if (table[s][i] || table[k][i]) {
					return false;
				}
			}
		}

		return true;
	}

	static public boolean read() {
		n = sc.nextInt();
		if (n == 0) {
			return false;
		}

		on = new int[n][n];
		dp = new boolean[1 << n];
		//Arrays.fill(dp, false);
		table = new boolean[n][n];
		x = new int[n];
		y = new int[n];

		r = new int[n];
		c = new int[n];

		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			r[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		return true;
	}

	public static void test(){
		int i = 16;
		System.out.println(i);
		System.out.println(i << 2);
		System.out.println(i);
	}
	
	public static void doIt(){
		while (read())
			solve();
	}

	public static void main(String args[]) {
		//test();
		doIt();
	}
}

Measured memory_bytes: 44000
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
void a(){
   ll D,T,S;
   cin >> D >> T >> S;
   if(D<=T*S){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
}

void b(){
   
}

void c(){

}


void d(){
     
}

void e(){

}

int main(void){
    a();
    return 0;
 }

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
void haichi(void);
void Block(int,int);
int c,d,x,y,xg,yg,M,Flag;
int MAP[101][101],MF[101][101];
int main(void)
{
	int w,h,xs,ys,n;
	while(1){
		Flag=0;
		memset(MAP,0,sizeof(MAP));
		memset(MF,0,sizeof(MF));
		scanf("%d %d",&w,&h);
		if(w == 0 && h == 0) break;
		scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d %d %d %d",&c,&d,&x,&y);
			haichi();
		}
		/*for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				printf("%d",MAP[i][j]);
			}
			printf("\n");
		}*/
		M = MAP[ys][xs];//
		if(MAP[ys][xs] == MAP[yg][xg])
			Block(xs,ys);
		if(Flag==1)
			printf("OK\n");
		else
			printf("NG\n");
	}
	return 0;
}

void haichi(void)
{
	if(d==0){
		MAP[y][x]=c;MAP[y][x+1]=c;MAP[y][x+2]=c;MAP[y][x+3]=c;
		MAP[y+1][x]=c;MAP[y+1][x+1]=c;MAP[y+1][x+2]=c;MAP[y+1][x+3]=c;
	}
	else if(d==1){
		MAP[y][x]=c;MAP[y][x+1]=c;
		MAP[y+1][x]=c;MAP[y+1][x+1]=c;
		MAP[y+2][x]=c;MAP[y+2][x+1]=c;
		MAP[y+3][x]=c;MAP[y+3][x+1]=c;
	}
}

void Block(int X,int Y)
{
	MF[Y][X] = 1;
	//printf("%d",M);
	if(X == xg && Y == yg)
		Flag = 1;
	if(MAP[Y-1][X] == M && MF[Y-1][X] == 0) Block(X,Y-1); //???
	if(MAP[Y+1][X] == M && MF[Y+1][X] == 0) Block(X,Y+1); //???
	if(MAP[Y][X-1] == M && MF[Y][X-1] == 0) Block(X-1,Y); //???
	if(MAP[Y][X+1] == M && MF[Y][X+1] == 0) Block(X+1,Y); //???
}

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

int main()
{
int a[40];
a[1]=1; 
a[2]=1; 
a[3]=1; 
a[4]=2; 
a[5]=1;
a[6]=2; 
a[7]=1; 
a[8]=5; 
a[9]=2; 
a[10]=2; 
a[11]=1; 
a[12]=5; 
a[13]=1; 
a[14]=2; 
a[15]=1; 
a[16]=14; 
a[17]=1;
a[18]=5; 
a[19]=1; 
a[20]=5; 
a[21]=2; 
a[22]=2; 
a[23]=1; 
a[24]=15; 
a[25]=2; 
a[26]=2; 
a[27]=5; 
a[28]=4; 
a[29]=1; 
a[30]=4; 
a[31]=1;
a[32]=51;
int n;
cin>>n;
cout <<a[n];

}

Measured memory_bytes: 256
friends=input()
friends=friends.split()
friends_all=friends[0]
person=int(friends_all)+1
cakes=input()
cakes_amount=0
for a in cakes.split():
        cakes_amount+=int(a)
one_person=cakes_amount//person

if cakes_amount%person!=0:
        one_person+=1
else:
        pass
print(one_person)


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

int main(void){
  int n; cin >> n;
  int v[n],c[n];
  rep(i,n){
    cin >> v[i];
  }
  rep(i,n){
    cin >> c[i];
  }
  int a[n];
  rep(i,n){
    a[i] = 0;
    if(v[i] > c[i]){
      a[i] = 1;
    }
  }
  int ans = 0;
  rep(i,n){
    if(a[i]){
      ans += v[i] - c[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    sc.close();
    selectionSort(A, N);
  }

  static void selectionSort(int[] A, int N) {
    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      int minj = i;
      for (int j = i; j < N ; j++) {
        if (A[j] < A[minj])
          minj = j;
      }
      if (i != minj) {
        swap(A, i, minj);
        count++;
      }
    }
    printArray(A);
    System.out.println(count);
  }

  static void swap(int[] A, int i, int j) {
    int tmp = A[i];
    A[i] = A[j];
    A[j] = tmp;
  }

  static void printArray(int[] A) {
    int n = A.length;
    for (int i = 0; i < n - 1; i++) {
      System.out.printf("%d ", A[i]);
    }
    System.out.print(A[n - 1] + "\n");
  }
}


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

using namespace std;
bool isint(float k)
{
  int l=sqrt(k);
  if(l*l==k)
  return true;
  else return false;
}

int main()
{
    int n,d,ans=0;
    cin>>n;
    cin>>d;
    vector<vector<int>>p(n,vector<int>(d,0));
    for(int i=0;i<n;i++)
    {
     for(int j=0;j<d;j++)
     {
      cin>>p[i][j];
     }
    }
    for(int i=0;i<n;i++)
    {
     for(int j=i+1;j<n;j++)
     { float dist  = 0.0;
      for(int k=0;k<d;k++)
      {
             dist+=(p[i][k]-p[j][k])*(p[i][k]-p[j][k]);
      }
      if(isint(dist))ans++;
     }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int N;
    std::cin >> N;
    int cnt = 0;
    for(int i = 1; i <= N; i++){
        int keta = 0;
        int num = i;
        while(num > 0){
            keta++;
            num /= 10;
        }
        if(keta % 2 != 0) cnt++;
    }

    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    in_list = list(map(int,input().split()))
    result = 1
    if in_list.count(0)>0:
        print(0)
        return

    for i in range(n):
        result = result*in_list[i]
        if result > 10**18:
            print(-1)
            return
    print(result)

main()

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

using namespace std;
using ll = long long;

int main() {
	int k; scanf("%d", &k);
	for (int i = 1, cur = 7 % k; i <= k; ++i, cur = ((cur * 10) + 7) % k) {
		if (cur == 0) {
			printf("%d\n", i);
			return 0;
		}
	}
	printf("-1\n");
}


Measured memory_bytes: 3824
#include <iostream>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if (a <= b)
		cout << a << endl;
	else
		cout << a - 1 << endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    for(int i = 0; i < n; i++)
        cin >> h[i];
    if(k >= n)
        cout << 0;
    else {
        sort(h, h + n);
        long long ans = 0;
        for(int i = 0; i < (n - k); i++)
            ans += h[i];
        cout << ans;
    }
    return 0;
}

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

int main() {
	string str;
	cin >> str;
	int sum = 0;
	for (int i = 0; i < str.length(); i++) {
		char a = str[i];
		int n = int(str[i] - '0');
		int amari = n % 10;

		sum = (sum + amari) % 9;
	}

	if (sum == 0) {
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}


	return 0;

}


Measured memory_bytes: 3740
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from itertools import permutations
from math import factorial

def main():
	n=II()
	li=[TI() for _ in range(n)]
	ans=0
	for p in permutations(range(n),n):
		tmp=0
		px=py=1001
		for i in p:
			x,y=li[i][0],li[i][1]
			if px==1001:
				px,py=x,y
			else:
				tmp+=((px-x)**2+(py-y)**2)**0.5
				px,py=x,y
		ans+=tmp

	ans/=factorial(n)
	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int cnt[13];
bool visit[24];
int best = 0;

void search(int now) {
  if (now == 13) {
    int cur = INF;
    for (int i = 0; i < 23; ++i) {
      if (!visit[i]) continue;
      for (int j = i + 1; j < 23; ++j) {
        if (!visit[j]) continue;
        cur = min(cur, min(j - i, 24 - (j - i)));
      }
    }
    best = max(best, cur);
    return;
  }
  if (cnt[now] == 0) {
    search(now + 1);
  } else if (cnt[now] == 1) {
    visit[now] = true;
    search(now + 1);
    visit[now] = false;
    visit[24 - now] = true;
    search(now + 1);
    visit[24 - now] = false;
  } else {
    visit[now] = visit[24 - now] = true;
    search(now + 1);
    visit[now] = visit[24 - now] = false;
  }
}

int main() {
  int n, x;
  cin >> n;
  cnt[0] = 1;
  while (n--) {
    cin >> x;
    cnt[x]++;
  }
  for (int i = 0; i <= 12; ++i) {
    if ((i % 12 == 0 && cnt[i] >= 2) || cnt[i] >= 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  visit[0] = true;
  best = 0;
  search(1);
  cout << best << endl;
  return 0;
}


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

int ABS(int a){
	return a >= 0 ? a : -a;
}

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, i, Cx, Cy, H, f;
	scanf("%d", &N);
	int *x = (int *)malloc(sizeof(int) * N);
	int *y = (int *)malloc(sizeof(int) * N);
	int *h = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d%d%d", &x[i], &y[i], &h[i]);
	}
	for(Cx = 0; Cx <= 100; Cx++){
		for(Cy = 0; Cy <= 100; Cy++){
			for(i = 0; h[i] == 0; i++);
			H = h[i] + ABS(x[i] - Cx) + ABS(y[i] - Cy);
			for(i = 0, f = 1; i < N; i++){
				if(h[i] != max(H - ABS(x[i] - Cx) - ABS(y[i] - Cy), 0)){
					f = 0;
					break;
				}
			}
			if(f == 1){
				printf("%d %d %d\n", Cx, Cy, H);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int restricted[K];
    for (int i=0; i<K; i++) {
        cin >> restricted[i];
    }
    while (true) {
        bool flag = true;
        string str = to_string(N);
        for (int i=0; i<str.length(); i++) {
            for (int j=0; j<K; j++) {
                int value = str[i]-'0';
                if (value==restricted[j]) {
                    flag = false;
                }
            }
        }
        if (flag) {
            cout << N << endl;
            return 0;
        } else {
            N++;
        }
    }
}

Measured memory_bytes: 256
INF=float('inf')
n,m=map(int,input().split())
a=[0]*m
c=[0]*m
for i in range(m):
    a[i],_=map(int,input().split())
    c[i]=sum(map(lambda x:2**(int(x)-1),input().split()))
dp=[INF]*(2**n)
for i in range(m):
    for j in range(2**n):
        if j|c[i]==c[i]:
            dp[j]=min(dp[j],a[i])
        dp[c[i]|j]=min(dp[c[i]|j],dp[j]+a[i])
print(-1 if dp[-1]==INF else dp[-1])

Measured memory_bytes: 47832
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    t = [[0,0,0]]
    for _ in range(n):
        t.append(list(map(int,input().split())))
    for i in range(n):
        time = t[i+1][0] - t[i][0]
        distance = abs(t[i+1][1] - t[i][1]) + abs(t[i+1][2] - t[i][2])
        if time < distance or (time-distance) % 2 == 1:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

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

int main()
{
    int h, w; cin >> h >> w;

    string s(w + 2, '#');

    cout << s << endl;

    for(int i = 0; i < h; i++)
    {
        string x; cin >> x;

        cout << '#';
        cout << x;
        cout << '#' << endl;
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int func(int a){
    if(a<10){
        return a;
    }
    return  a%10+func(a/10);
}

int main(){
    int N;
    cin >> N;
    int s=func(N);
    if(N%s==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

const int MAX_N = 100000;

vector<bool> prime(100001, true);
vector<int> sum(100002, 0);

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // Seive
    prime[0] = prime[1] = false;
    for (int i = 2; i*i <= MAX_N; i++)
        if (prime[i])
            for (int j = i*i; j <= MAX_N; j += i)
                prime[j] = false;

    for (int i = 3; i <= MAX_N; i++, sum[i] += sum[i-1])
        if (prime[((i+1)/2)] && prime[i])
            sum[i]++;

    int Q; cin >> Q;
    while(Q--) {
        int l, r; cin >> l >> r;
        cout << sum[r]-sum[l-1] << "\n";
    }

    return 0;
}


Measured memory_bytes: 1024
num = gets.to_i
b_array = gets.split.map(&:to_i)
a_array = []
num.times do
  a_array << 'a'
end

hash = {}
b_array.each.with_index do |n, i|
  hash[i] = n
end

b_hash = Hash[ hash.sort_by{ |_, v| v } ]

b_hash.each do |i, v|
  a_array[i] = v if a_array[i] == 'a'
  a_array[i + 1] = v if a_array[i + 1] == 'a'
end

p a_array.inject(:+)


Measured memory_bytes: 1916
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


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


























int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    ll down = 0, up = INF;
    while(up - down > 1){
        ll mid = (up + down) / 2;
        ll cnt = 0;
        REP(i, n){
            cnt += ((a[i] % mid == 0)? a[i] / mid : a[i] / mid + 1) - 1;
        }
        ((cnt > k)? down : up) = mid;
    }
    cout << up << endl;
}

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

int main(){
    int n;
    int* p;

    cin >> n;

    p = new int[n];

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

    int count = 0;
    for(int i = 2; i < n; i++){
        if(p[i-2] < p[i-1] && p[i-1] < p[i]) count++;
        else if(p[i-2] > p[i-1] && p[i-1] > p[i]) count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<vector<int>>		G(N);
	vector<pair<int, int>>	paramList;
	REP(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
		paramList.emplace_back(a, b);
	}

	int				ansMax = 0;
	queue<int>		que;
	vector<int>		parentCol(N, 0);
	vector<bool>	nodeUsed(N, false);
	map<pair<int, int>, int>	resMap;
	que.push(0);
	nodeUsed[0] = true;
	while (!que.empty()) {
		int nodeNoFrom = que.front();
		que.pop();

		ansMax = max(ansMax, (int)G[nodeNoFrom].size());
		int colNo = 1;
		for (auto nodeNoTo : G[nodeNoFrom]) {
			if (nodeUsed[nodeNoTo]) {
				continue;
			}
			
			// 親の色だけさける
			if (parentCol[nodeNoFrom] == colNo) {
				colNo++;
			}
			
			// 色を更新
			parentCol[nodeNoTo] = colNo;
			resMap[make_pair(nodeNoTo, nodeNoFrom)] = colNo; 
			resMap[make_pair(nodeNoFrom, nodeNoTo)] = colNo; 
			colNo++;
			
			// 次の対象
			nodeUsed[nodeNoTo] = true;
			que.push(nodeNoTo);
		}
	}

	cout << ansMax << endl;
	for (auto param : paramList) {
		cout << resMap[param] << endl;
	}
	return 0;
}



Measured memory_bytes: 19700
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int INF=1e9;

int main(){
    string s;
    cin >> s;
    int a=(s[0]-'0')*10;
    int b=(s[1]-'0');
    int c=(s[2]-'0')*10;
    int d=(s[3]-'0');
    if(a+b<=12&&c+d<=12){
        if(a+b>0&&c+d>0){
            cout << "AMBIGUOUS" << endl;
            return 0;
        }
    }
    if(a+b<=99&&c+d<=12){
        if(c+d>0){
            cout << "YYMM" << endl;
            return 0;
        }
    }
    if(a+b<=12&&c+d<=99){
        if(a+b>0){
            cout << "MMYY" << endl;
            return 0;
        }
    }
    cout << "NA" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    string s,t,u;
    cin>>s>>t;
    int n=s.size(),c=0;
    bool flag=false;
    u=s;
    if(s==t) flag=true;
    if(!flag){
    while(c<n){
        string v;
        v+=u[n-1];
        rep(i,n-1) v+=u[i];
        if(v==t){
            flag=true;
            break;
        }
        u=v;
        c++;
    }
    }
    if(flag) cout<<"Yes";
    else cout<<"No";
}

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

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

	if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) cout << "Bad" << endl;
	else cout << "Good" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
int main(void)
{
  char S[1100],str1[]="es",str2[]="s";
  int i;
  
  scanf("%s",S);
  
  for(i=0; S[i]!='\0'; ++i);

  if(S[i-1]=='s')
  {
    strcat(S,str1);
  	printf("%s",S);
  }else{
    strcat(S,str2);
    printf("%s",S);
  }
  
  return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
int main(){
  string t,s;
  cin>>s>>t;
  int n=t.size();
  int ma=0;
  for(int i=0;i<n;i++){
    if(s[i]!=t[i])
      ma++;
  }
  for(int i=n;i<s.size();i++){
    int c=0;
    for(int j=0;j<n;j++){
      if(t[j]!=s[i-n+1+j]){
        c++;
      }
    }
    ma=min(ma,c);
  }
  cout<<ma;
  return 0;
}

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

int main() {
    //
    int num, x;
    int sum = 0;

    cin >> num >> x;

    int index = 1;
    while (sum <= x && index <= num) {
        int tmp;
        cin >> tmp;
        sum += tmp;

        if (sum > x) break;
        index++;
    }

    cout << index;
    //
}


Measured memory_bytes: 3632
import math
a, b, C = map(int,input().split())
C = math.radians(C)
S = 1/2 * a * b * math.sin(C)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
h = 2*S/a
L = a + b + c
print(S,L,h)


Measured memory_bytes: 5704
# https://atcoder.jp/contests/abc125/tasks/abc125_b

import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        ans += (V[i] - C[i]) if V[i] - C[i] > 0 else 0
    print(ans)

if __name__ == '__main__':
    main()


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    ll n; cin >> n;

    cout << ((1 + (n - 1)) * (n - 1)) / 2 << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<string> vs;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

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

  while(true) {
		int n;
		cin >> n;
		if(n == 0) break;

		vi k(n);
		rep(i,0,n) cin >> k[i];
		string s;
		cin >> s;

		string ans = "";
		string a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		rep(i,0,s.size()) {
			int num = a.find(s[i]) - k[i%n]%a.size();
			if(num < 0) num += a.size();
			ans += a[num];
		}
		cout << ans << endl;
  }

	return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
typedef long long ll;

int main(){
	int n;
	scanf("%d", &n);
	if (n % 2 == 0)	n /= 2;
	else n = n / 2 + 1;
	printf("%d", n);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
 
using namespace std ;
 
typedef tree<pair<pll,lli>,null_type,less<pair<pll,lli>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
#define MAXN 200000
 
int main()
{
    
/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////  
  
	lli n;
	cin>>n;
	lli k=n/2,cnt=0;

	loopl(i,1,n+1)
	{
		if(i!=n-i) cnt++;
	}
cout<<cnt/2<<endl;
}

        
 


Measured memory_bytes: 256
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
	int n,q;
	cin>>n>>q;
	int a[n];
	Query queries[q];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		queries[i].l=x-1;
		queries[i].r=y-1;
		queries[i].idx=i;
	}
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


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

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  for(int i = 0; i < n; ++i) cin >> w[i];
  
  int ans = 9999999;
  int sum = 0;
  for(int i = 0;i < n; ++i){
	sum += w[i];
  }
  
  int l = 0;
  int r = sum;
  int anko = min(ans,abs(l-r));
  
  for(int i = 0;i < n; ++i){
	l += w[i];
	r -= w[i];
	anko = min(anko,abs(l-r));
  }
  
  cout << anko << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<math.h>
#include<string>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;

int main()
{
	int n;
	std::cin >> n;
	int* arr = new int[n];
	for (int i = 0; i < n; i++)
	{
		std::cin >> arr[i];
	}
	int* dp = new int[n];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for (int i = 2; i < n; i++)
	{
		int x1 = abs(arr[i] - arr[i - 1]) + dp[i - 1];
		int x2 = abs(arr[i] - arr[i - 2]) + dp[i - 2];
		dp[i] = x1 < x2 ? x1 : x2;
	}
	std::cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 4308
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
using namespace std;
const int MAXN = 1e5 + 7;
set<int>ans;
vector<pii>G[MAXN];
vector<int>vec;
pii A[MAXN];
bool B[MAXN], vis[MAXN];
void dfs(int u)
{
    vis[u] = 1;
    for (pii v : G[u]) if (!vis[v.fir])
    {
        dfs(v.fir);
        if (B[v.fir]) 
        {
            B[u] ^= 1; B[v.fir] ^= 1;
            ans.insert(v.sec);
        }
    }
}
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) 
    {
        scanf("%d%d", &A[i].fir, &A[i].sec); 
        vec.push_back(A[i].fir);
    }
    sort(A + 1, A + 1 + n);
    sort(vec.begin(), vec.end());
    B[1] = A[1].sec;
    for (int i = 1; i < n; i++) B[i + 1] = A[i].sec ^ A[i + 1].sec;
    B[n + 1] = A[n].sec;
    for (int i = 1, l, r; i <= m; i++)
    {
        scanf("%d%d", &l, &r);
        l = lower_bound(vec.begin(), vec.end(), l) - vec.begin() + 1;
        r = upper_bound(vec.begin(), vec.end(), r) - vec.begin() + 1;
        G[l].emplace_back(r, i);
        G[r].emplace_back(l, i);
    }
    for (int i = 1; i <= n + 1; i++) if (!vis[i])
    {
        dfs(i);
        if (B[i]) {puts("-1"); return 0;}
    }
    printf("%d\n", (int)ans.size());
    for (int x : ans) printf("%d ", x);
    return 0;
}

Measured memory_bytes: 15992
import itertools
import copy
H, W, K = map(int, input().split())

cells_org = []
CH = [()]
CW = [()]
ans = 0

for i in range(1, H+1) :
  CH = CH + list(itertools.combinations(range(H),i))

for i in range(1, W+1) :
  CW = CW + list(itertools.combinations(range(W),i))

for i in range(H) :  
  cells_org.append(list(str(input())))
  
cells = copy.deepcopy(cells_org)

for i, j in itertools.product(CH, CW):
  for k in list(i) :
    for l in range(W):
      cells[k][l] = "x"
  
  for m in list(j) :
    for n in range(H):
      cells[n][m] = "x"
  
  num = 0
  for x in range(H) :
    num += cells[x].count("#")
   
  if K == num :
    ans += 1

  cells = copy.deepcopy(cells_org)
  
print(ans)

Measured memory_bytes: 9308
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a=0,n,m;
    cin>>n;
    m=n;
    for(int i=1000000000;i>=1;i/=10){
        a+=m/i;
        m-=(m/i)*i;
    }
    if(n%a==0)cout<<"Yes";
    if(n%a!=0)cout<<"No";
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)

int main(){
    string s;
    int n;
    cin >> s;
    n = s.size();

    vector<int> a(4);
    
    rep(i,n){
        if(s[i]=='N') a[0]++;
        if(s[i]=='S') a[1]++;
        if(s[i]=='W') a[2]++;
        if(s[i]=='E') a[3]++;
    }

    if(a[0]!=0 && a[1]!=0 && a[2]!=0 && a[3]!=0) cout << "Yes" << endl;
    else if(a[0]!=0 && a[1]!=0 && a[2]==0 && a[3]==0) cout << "Yes" << endl;
    else if(a[0]==0 && a[1]==0 && a[2]!=0 && a[3]!=0) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ for (int i = 0; i < min(n, c.size()); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }

int main()
{
    // eratosthenes
    int P_MAX=100000;
    char p[P_MAX+1];
    memset(p, 1, sizeof p);
    p[0] = p[1] = 0;
    for (int i = 4; i <= P_MAX; i+=2)
        p[i] = 0;
    for (int i = 3; i*i <= P_MAX; i+=2) {
        if (!p[i]) continue;
        for (int j = i*i; j <= P_MAX; j += i)
            p[j] = 0;
    }

    // 2017-like number
    char n2017[P_MAX+1];
    memset(n2017, 0, sizeof n2017);
    for (int i = 2; i <= P_MAX; i++) {
        if (!p[i]) continue;
        int n = 2 * i - 1;
        if (n > P_MAX) break;
        if (p[n]) n2017[n] = 1;
    }

    // cumulative sum
    int s[P_MAX+1];
    s[0] = 0;
    for (int i = 1; i <= P_MAX; i++) {
        s[i] = s[i-1] + n2017[i];
    }

    int Q; cin >>Q;
    rep(i, Q) {
        int l, r; cin >> l >> r;
        cout << (s[r] - s[l-1]) << endl;
    }
}



Measured memory_bytes: 1280
import collections
n=int(input())
v=list(map(int,input().split()))
v0=[]
v1=[]
for i in range(n//2):
    v0.append(v[2*i])
    v1.append(v[2*i+1])
if collections.Counter(v0).most_common()[0][0] == collections.Counter(v1).most_common()[0][0]:
    if collections.Counter(v0).most_common()[0][1] == len(v0):
        if collections.Counter(v1).most_common()[0][1] == len(v1):
            print(len(v0))
        else:
            print(len(v1)-collections.Counter(v1).most_common()[1][1])
    else:
        if collections.Counter(v1).most_common()[0][1] == len(v1):
            print(len(v0)-collections.Counter(v0).most_common()[0][1])
        else:
            print(min(len(v)-collections.Counter(v0).most_common()[1][1]-collections.Counter(v1).most_common()[0][1],\
                     len(v)-collections.Counter(v0).most_common()[0][1]-collections.Counter(v1).most_common()[1][1]))
else:
    print(len(v)-collections.Counter(v0).most_common()[0][1]-collections.Counter(v1).most_common()[0][1])
    

Measured memory_bytes: 17548